-
-
Notifications
You must be signed in to change notification settings - Fork 323
Fail when reading private key for selected certificate fails. #17659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dkocher
wants to merge
4
commits into
master
Choose a base branch
from
bugfix/GH-17657-certificate-privatekey
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| import ch.cyberduck.core.exception.LocalAccessDeniedException; | ||
| import ch.cyberduck.core.exception.LoginCanceledException; | ||
| import ch.cyberduck.core.exception.LoginFailureException; | ||
| import ch.cyberduck.core.ssl.X509KeyManager; | ||
| import ch.cyberduck.core.threading.CancelCallback; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
|
|
@@ -35,84 +36,95 @@ public class KeychainLoginService implements LoginService { | |
|
|
||
| private final HostPasswordStore keychain; | ||
|
|
||
| public KeychainLoginService() { | ||
| this(PasswordStoreFactory.get()); | ||
| } | ||
|
|
||
| public KeychainLoginService(final HostPasswordStore keychain) { | ||
| this.keychain = keychain; | ||
| } | ||
|
|
||
| @Override | ||
| public void validate(final Host bookmark, final LoginCallback prompt, final LoginOptions options) throws ConnectionCanceledException, LoginFailureException { | ||
| log.debug("Validate login credentials for {}", bookmark); | ||
| final Credentials credentials = bookmark.getCredentials(); | ||
| public void validate(final Host host, final X509KeyManager keys, final LoginCallback prompt, final LoginOptions options) throws ConnectionCanceledException, LoginFailureException { | ||
| log.debug("Validate login credentials for {}", host); | ||
| final Host jumphost = host.getJumphost(); | ||
| if(null != jumphost) { | ||
| this.validate(jumphost, keys, prompt, new LoginOptions(jumphost.getProtocol())); | ||
| } | ||
| final Credentials credentials = host.getCredentials(); | ||
| if(credentials.isPublicKeyAuthentication()) { | ||
| if(!credentials.getIdentity().attributes().getPermission().isReadable()) { | ||
| log.warn("Prompt to select identity file not readable {}", credentials.getIdentity()); | ||
| credentials.setIdentity(prompt.select(credentials.getIdentity())); | ||
| } | ||
| } | ||
| if(options.keychain) { | ||
| log.debug("Lookup credentials in keychain for {}", bookmark); | ||
| log.debug("Lookup credentials in keychain for {}", host); | ||
| if(options.password) { | ||
| if(StringUtils.isBlank(credentials.getPassword())) { | ||
| final String password = keychain.findLoginPassword(bookmark); | ||
| final String password = keychain.findLoginPassword(host); | ||
| if(StringUtils.isNotBlank(password)) { | ||
| log.info("Fetched password from keychain for {}", bookmark); | ||
| log.info("Fetched password from keychain for {}", host); | ||
| // No need to reinsert found password to the keychain. | ||
| credentials.setPassword(password).setSaved(false); | ||
| } | ||
| } | ||
| } | ||
| if(options.token) { | ||
| if(StringUtils.isBlank(credentials.getToken())) { | ||
| final String token = keychain.findLoginToken(bookmark); | ||
| final String token = keychain.findLoginToken(host); | ||
| if(StringUtils.isNotBlank(token)) { | ||
| log.info("Fetched token from keychain for {}", bookmark); | ||
| log.info("Fetched token from keychain for {}", host); | ||
| // No need to reinsert found token to the keychain. | ||
| credentials.setToken(token).setSaved(false); | ||
| } | ||
| } | ||
| } | ||
| if(options.publickey) { | ||
| final String passphrase = keychain.findPrivateKeyPassphrase(bookmark); | ||
| final String passphrase = keychain.findPrivateKeyPassphrase(host); | ||
| if(StringUtils.isNotBlank(passphrase)) { | ||
| log.info("Fetched private key passphrase from keychain for {}", bookmark); | ||
| log.info("Fetched private key passphrase from keychain for {}", host); | ||
| // No need to reinsert found token to the keychain. | ||
| credentials.setIdentityPassphrase(passphrase).setSaved(false); | ||
| } | ||
| } | ||
| if(options.oauth) { | ||
| final OAuthTokens tokens = keychain.findOAuthTokens(bookmark); | ||
| final OAuthTokens tokens = keychain.findOAuthTokens(host); | ||
| if(tokens.validate()) { | ||
| log.info("Fetched OAuth tokens {} from keychain for {}", tokens, bookmark); | ||
| log.info("Fetched OAuth tokens {} from keychain for {}", tokens, host); | ||
| // No need to reinsert found token to the keychain. | ||
| credentials.setOauth(tokens).setSaved(tokens.isExpired()); | ||
| } | ||
| } | ||
| if(options.certificate) { | ||
| final String alias = host.getCredentials().getCertificate(); | ||
| if(StringUtils.isNotBlank(alias)) { | ||
| if(keys != null) { | ||
| if(null == keys.getPrivateKey(alias)) { | ||
| log.warn("No private key found for alias {} in keychain", alias); | ||
| throw new LoginFailureException(LocaleFactory.localizedString("Provide additional login credentials", "Credentials")); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+95
to
+105
|
||
| } | ||
| if(!credentials.validate(bookmark.getProtocol(), options)) { | ||
| if(!credentials.validate(host.getProtocol(), options)) { | ||
| log.warn("Failed validation of credentials {} with options {}", credentials, options); | ||
| final CredentialsConfigurator configurator = CredentialsConfiguratorFactory.get(bookmark.getProtocol()); | ||
| final CredentialsConfigurator configurator = CredentialsConfiguratorFactory.get(host.getProtocol()); | ||
| log.debug("Auto configure credentials with {}", configurator); | ||
| final Credentials configuration = configurator.configure(bookmark); | ||
| if(configuration.validate(bookmark.getProtocol(), options)) { | ||
| bookmark.setCredentials(configuration); | ||
| log.info("Auto configured credentials {} for {}", configuration, bookmark); | ||
| final Credentials configuration = configurator.configure(host); | ||
| if(configuration.validate(host.getProtocol(), options)) { | ||
| host.setCredentials(configuration); | ||
| log.info("Auto configured credentials {} for {}", configuration, host); | ||
| return; | ||
| } | ||
| final StringAppender message = new StringAppender(); | ||
| if(options.password) { | ||
| message.append(MessageFormat.format(LocaleFactory.localizedString( | ||
| "Login {0} with username and password", "Credentials"), BookmarkNameProvider.toString(bookmark))); | ||
| "Login {0} with username and password", "Credentials"), BookmarkNameProvider.toString(host))); | ||
| } | ||
| if(options.publickey) { | ||
| message.append(LocaleFactory.localizedString( | ||
| "Select the private key in PEM or PuTTY format", "Credentials")); | ||
| } | ||
| message.append(LocaleFactory.localizedString("No login credentials could be found in the Keychain", "Credentials")); | ||
| this.prompt(bookmark, message.toString(), prompt, options); | ||
| this.prompt(host, message.toString(), prompt, options); | ||
| } | ||
| log.debug("Validated credentials {} with options {}", credentials, options); | ||
| } | ||
|
|
@@ -205,9 +217,12 @@ public boolean authenticate(final Session<?> session, final ProgressListener lis | |
| public void save(final Host bookmark) { | ||
| final Credentials credentials = bookmark.getCredentials(); | ||
| if(credentials.isSaved()) { | ||
| // Write credentials to keychain | ||
| // Write credentials to the password store | ||
| try { | ||
| keychain.save(bookmark); | ||
| if(bookmark.getJumphost() != null) { | ||
| keychain.save(bookmark.getJumphost()); | ||
| } | ||
| } | ||
| catch(LocalAccessDeniedException e) { | ||
| log.error("Failure saving credentials for {} in keychain. {}", bookmark, e); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.