Cyberduck Mountain Duck CLI

Changeset 43407


Ignore:
Timestamp:
Nov 21, 2017 8:39:05 PM (7 months ago)
Author:
dkocher
Message:

Remove password prompt for public key authentication. Fix #10148.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property subgit:lock changed from commit:70c387ebe5448ba2c1c5df27a68c2a46e2b31dbc timestamp:2017-11-21T21:12:47.206 to commit:58fd917d5c36404829b39e956367751f2f0480a3 timestamp:2017-11-21T21:12:49.419
  • trunk/core/src/main/java/ch/cyberduck/core/HostPasswordStore.java

    r35652 r43407  
    1818 */
    1919
     20import ch.cyberduck.core.preferences.Preferences;
     21import ch.cyberduck.core.preferences.PreferencesFactory;
     22
    2023import org.apache.commons.lang3.StringUtils;
    2124import org.apache.log4j.Logger;
     
    2427    private static final Logger log = Logger.getLogger(HostPasswordStore.class);
    2528
     29    private final Preferences preferences
     30        = PreferencesFactory.get();
     31
    2632    /**
    2733     * @param host Hostname
     
    2935     */
    3036    public String find(final Host host) {
     37        if(preferences.getBoolean("connection.login.keychain")) {
     38            log.warn("Keychain disabled in preferences");
     39            return null;
     40        }
    3141        if(log.isInfoEnabled()) {
    3242            log.info(String.format("Fetching password from keychain for %s", host));
     
    5666        else {
    5767            p = this.getPassword(host.getProtocol().getScheme(), host.getPort(),
    58                     host.getHostname(), credentials.getUsername());
     68                host.getHostname(), credentials.getUsername());
    5969        }
    6070        if(null == p) {
     
    103113        if(credentials.isPublicKeyAuthentication()) {
    104114            this.addPassword(host.getHostname(), credentials.getIdentity().getAbbreviatedPath(),
    105                     credentials.getPassword());
     115                credentials.getPassword());
    106116        }
    107117        else {
    108118            this.addPassword(host.getProtocol().getScheme(), host.getPort(),
    109                     host.getHostname(), credentials.getUsername(), credentials.getPassword());
     119                host.getHostname(), credentials.getUsername(), credentials.getPassword());
    110120        }
    111121    }
  • trunk/core/src/main/java/ch/cyberduck/core/KeychainLoginService.java

    r42631 r43407  
    3434
    3535    private final Preferences preferences
    36             = PreferencesFactory.get();
     36        = PreferencesFactory.get();
    3737
    3838    private final LoginCallback callback;
     
    5151            // Warning if credentials are sent plaintext.
    5252            callback.warn(bookmark, MessageFormat.format(LocaleFactory.localizedString("Unsecured {0} connection", "Credentials"),
    53                     bookmark.getProtocol().getName()),
    54                     MessageFormat.format("{0} {1}.", MessageFormat.format(LocaleFactory.localizedString("{0} will be sent in plaintext.", "Credentials"),
    55                             bookmark.getProtocol().getPasswordPlaceholder()),
    56                             LocaleFactory.localizedString("Please contact your web hosting service provider for assistance", "Support")),
    57                     LocaleFactory.localizedString("Continue", "Credentials"),
    58                     LocaleFactory.localizedString("Disconnect", "Credentials"),
    59                     String.format("connection.unsecure.%s", bookmark.getHostname()));
     53                bookmark.getProtocol().getName()),
     54                MessageFormat.format("{0} {1}.", MessageFormat.format(LocaleFactory.localizedString("{0} will be sent in plaintext.", "Credentials"),
     55                    bookmark.getProtocol().getPasswordPlaceholder()),
     56                    LocaleFactory.localizedString("Please contact your web hosting service provider for assistance", "Support")),
     57                LocaleFactory.localizedString("Continue", "Credentials"),
     58                LocaleFactory.localizedString("Disconnect", "Credentials"),
     59                String.format("connection.unsecure.%s", bookmark.getHostname()));
    6060        }
    6161        listener.message(MessageFormat.format(LocaleFactory.localizedString("Authenticating as {0}", "Status"),
    62                 StringUtils.isEmpty(bookmark.getCredentials().getUsername()) ? LocaleFactory.localizedString("Unknown") : bookmark.getCredentials().getUsername()));
     62            StringUtils.isEmpty(bookmark.getCredentials().getUsername()) ? LocaleFactory.localizedString("Unknown") : bookmark.getCredentials().getUsername()));
    6363        try {
    6464            if(log.isDebugEnabled()) {
     
    8080            listener.message(LocaleFactory.localizedString("Login failed", "Credentials"));
    8181            bookmark.setCredentials(callback.prompt(bookmark, bookmark.getCredentials().getUsername(),
    82                     LocaleFactory.localizedString("Login failed", "Credentials"), e.getDetail(),
    83                     new LoginOptions(bookmark.getProtocol())));
     82                LocaleFactory.localizedString("Login failed", "Credentials"), e.getDetail(),
     83                new LoginOptions(bookmark.getProtocol())));
    8484            throw e;
    8585        }
     
    9898            }
    9999        }
    100         if(!credentials.validate(bookmark.getProtocol(), options)
    101                 || credentials.isPublicKeyAuthentication()) {
    102             // Lookup password if missing. Always lookup password for public key authentication. See #5754.
     100        if(!credentials.validate(bookmark.getProtocol(), options)) {
    103101            if(StringUtils.isNotBlank(credentials.getUsername())) {
    104                 if(preferences.getBoolean("connection.login.keychain")) {
    105                     final String password = keychain.find(bookmark);
    106                     if(StringUtils.isBlank(password)) {
    107                         if(!credentials.isPublicKeyAuthentication()) {
    108                             final StringAppender appender = new StringAppender();
    109                             appender.append(message);
    110                             appender.append(LocaleFactory.localizedString("No login credentials could be found in the Keychain", "Credentials"));
    111                             bookmark.setCredentials(callback.prompt(bookmark, credentials.getUsername(),
    112                                     String.format("%s %s", LocaleFactory.localizedString("Login", "Login"), bookmark.getHostname()),
    113                                     appender.toString(),
    114                                     options));
    115                         }
    116                         // We decide later if the key is encrypted and a password must be known to decrypt.
    117                     }
    118                     else {
    119                         credentials.setPassword(password);
    120                         // No need to reinsert found password to the keychain.
    121                         credentials.setSaved(false);
    122                     }
     102                final String password = keychain.find(bookmark);
     103                if(StringUtils.isBlank(password)) {
     104                    final StringAppender appender = new StringAppender();
     105                    appender.append(message);
     106                    appender.append(LocaleFactory.localizedString("No login credentials could be found in the Keychain", "Credentials"));
     107                    bookmark.setCredentials(callback.prompt(bookmark, credentials.getUsername(),
     108                        String.format("%s %s", LocaleFactory.localizedString("Login", "Login"), bookmark.getHostname()),
     109                        appender.toString(),
     110                        options));
    123111                }
    124112                else {
    125                     if(!credentials.isPublicKeyAuthentication()) {
    126                         final StringAppender appender = new StringAppender();
    127                         appender.append(message);
    128                         appender.append(LocaleFactory.localizedString("The use of the Keychain is disabled in the Preferences", "Credentials"));
    129                         bookmark.setCredentials(callback.prompt(bookmark, credentials.getUsername(),
    130                                 String.format("%s %s", LocaleFactory.localizedString("Login", "Login"), bookmark.getHostname()),
    131                                 appender.toString(), options));
    132                     }
    133                     // We decide later if the key is encrypted and a password must be known to decrypt.
     113                    credentials.setPassword(password);
     114                    // No need to reinsert found password to the keychain.
     115                    credentials.setSaved(false);
    134116                }
    135117            }
     
    141123                appender.append(LocaleFactory.localizedString("No login credentials could be found in the Keychain", "Credentials"));
    142124                bookmark.setCredentials(callback.prompt(bookmark, credentials.getUsername(),
    143                         String.format("%s %s", LocaleFactory.localizedString("Login", "Login"), bookmark.getHostname()),
    144                         appender.toString(), options));
     125                    String.format("%s %s", LocaleFactory.localizedString("Login", "Login"), bookmark.getHostname()),
     126                    appender.toString(), options));
    145127            }
    146128        }
    147129        else {
    148130            if(!credentials.isPassed()) {
    149                 if(preferences.getBoolean("connection.login.keychain")) {
    150                     final String password = keychain.find(bookmark);
    151                     if(StringUtils.isNotBlank(password)) {
    152                         if(log.isInfoEnabled()) {
    153                             log.info(String.format("Fetched password from keychain for %s", bookmark));
    154                         }
    155                         credentials.setPassword(password);
    156                         // No need to reinsert found password to the keychain.
    157                         credentials.setSaved(false);
     131                final String password = keychain.find(bookmark);
     132                if(StringUtils.isNotBlank(password)) {
     133                    if(log.isInfoEnabled()) {
     134                        log.info(String.format("Fetched password from keychain for %s", bookmark));
    158135                    }
     136                    credentials.setPassword(password);
     137                    // No need to reinsert found password to the keychain.
     138                    credentials.setSaved(false);
    159139                }
    160140            }
Note: See TracChangeset for help on using the changeset viewer.
swiss made software