Fix generateChallenge
Make getHostname more robust