Improved hostname handling for keychain