Browse Source

Apache MINA sshd client: less aggressive key file name caching

Don't use the ~/.ssh directory as cache key for the key provider
but the configured paths of the default keys. Otherwise changes
in that list of paths are not picked up.

This is in particular a problem for EGit, where the user can modify
this list of keys interactively in the preferences. Without this
change, Eclipse needs to be restarted to pick up such changes.

Bug: 542845
Change-Id: I63432fb10729a90b3c5e14f13e39bf482aef811b
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
stable-5.3
Thomas Wolf 6 years ago
parent
commit
5663b67575
  1. 1
      org.eclipse.jgit.ssh.apache/resources/org/eclipse/jgit/internal/transport/sshd/SshdText.properties
  2. 5
      org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/CachingKeyPairProvider.java
  3. 1
      org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/SshdText.java
  4. 12
      org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSessionFactory.java

1
org.eclipse.jgit.ssh.apache/resources/org/eclipse/jgit/internal/transport/sshd/SshdText.properties

@ -13,6 +13,7 @@ gssapiUnexpectedMessage=Received unexpected ssh message {1} in {0} authenticatio
identityFileCannotDecrypt=Given passphrase cannot decrypt identity {0} identityFileCannotDecrypt=Given passphrase cannot decrypt identity {0}
identityFileNoKey=No keys found in identity {0} identityFileNoKey=No keys found in identity {0}
identityFileMultipleKeys=Multiple key pairs found in identity {0} identityFileMultipleKeys=Multiple key pairs found in identity {0}
identityFileNotFound=Skipping identity ''{0}'': file not found
identityFileUnsupportedFormat=Unsupported format in identity {0} identityFileUnsupportedFormat=Unsupported format in identity {0}
kexServerKeyInvalid=Server key did not validate kexServerKeyInvalid=Server key did not validate
keyEncryptedMsg=Key ''{0}'' is encrypted. Enter the passphrase to decrypt it. keyEncryptedMsg=Key ''{0}'' is encrypted. Enter the passphrase to decrypt it.

5
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/CachingKeyPairProvider.java

@ -45,6 +45,7 @@ package org.eclipse.jgit.internal.transport.sshd;
import static java.text.MessageFormat.format; import static java.text.MessageFormat.format;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.security.KeyPair; import java.security.KeyPair;
@ -92,6 +93,10 @@ public class CachingKeyPairProvider extends EncryptedFileKeyPairProvider {
@Override @Override
protected KeyPair doLoadKey(Path resource) protected KeyPair doLoadKey(Path resource)
throws IOException, GeneralSecurityException { throws IOException, GeneralSecurityException {
if (!Files.exists(resource)) {
log.warn(format(SshdText.get().identityFileNotFound, resource));
return null;
}
// By calling doLoadKey(String, Path, FilePasswordProvider) instead of // By calling doLoadKey(String, Path, FilePasswordProvider) instead of
// super.doLoadKey(Path) we can bypass the key caching in // super.doLoadKey(Path) we can bypass the key caching in
// AbstractResourceKeyPairProvider, over which we have no real control. // AbstractResourceKeyPairProvider, over which we have no real control.

1
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/SshdText.java

@ -33,6 +33,7 @@ public final class SshdText extends TranslationBundle {
/***/ public String identityFileCannotDecrypt; /***/ public String identityFileCannotDecrypt;
/***/ public String identityFileNoKey; /***/ public String identityFileNoKey;
/***/ public String identityFileMultipleKeys; /***/ public String identityFileMultipleKeys;
/***/ public String identityFileNotFound;
/***/ public String identityFileUnsupportedFormat; /***/ public String identityFileUnsupportedFormat;
/***/ public String kexServerKeyInvalid; /***/ public String kexServerKeyInvalid;
/***/ public String keyEncryptedMsg; /***/ public String keyEncryptedMsg;

12
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSessionFactory.java

@ -161,7 +161,7 @@ public class SshdSessionFactory extends SshSessionFactory implements Closeable {
private static final class Tuple { private static final class Tuple {
private Object[] objects; private Object[] objects;
public Tuple(Object... objects) { public Tuple(Object[] objects) {
this.objects = objects; this.objects = objects;
} }
@ -351,7 +351,7 @@ public class SshdSessionFactory extends SshSessionFactory implements Closeable {
private HostConfigEntryResolver getHostConfigEntryResolver( private HostConfigEntryResolver getHostConfigEntryResolver(
@NonNull File homeDir, @NonNull File sshDir) { @NonNull File homeDir, @NonNull File sshDir) {
return defaultHostConfigEntryResolver.computeIfAbsent( return defaultHostConfigEntryResolver.computeIfAbsent(
new Tuple(homeDir, sshDir), new Tuple(new Object[] { homeDir, sshDir }),
t -> new JGitSshConfig(homeDir, t -> new JGitSshConfig(homeDir,
new File(sshDir, SshConstants.CONFIG), new File(sshDir, SshConstants.CONFIG),
getLocalUserName())); getLocalUserName()));
@ -375,7 +375,7 @@ public class SshdSessionFactory extends SshSessionFactory implements Closeable {
private ServerKeyVerifier getServerKeyVerifier(@NonNull File homeDir, private ServerKeyVerifier getServerKeyVerifier(@NonNull File homeDir,
@NonNull File sshDir) { @NonNull File sshDir) {
return defaultServerKeyVerifier.computeIfAbsent( return defaultServerKeyVerifier.computeIfAbsent(
new Tuple(homeDir, sshDir), new Tuple(new Object[] { homeDir, sshDir }),
t -> new OpenSshServerKeyVerifier(true, t -> new OpenSshServerKeyVerifier(true,
getDefaultKnownHostsFiles(sshDir))); getDefaultKnownHostsFiles(sshDir)));
} }
@ -403,8 +403,10 @@ public class SshdSessionFactory extends SshSessionFactory implements Closeable {
*/ */
@NonNull @NonNull
private KeyPairProvider getDefaultKeysProvider(@NonNull File sshDir) { private KeyPairProvider getDefaultKeysProvider(@NonNull File sshDir) {
return defaultKeys.computeIfAbsent(new Tuple(sshDir), List<Path> defaultIdentities = getDefaultIdentities(sshDir);
t -> new CachingKeyPairProvider(getDefaultIdentities(sshDir), return defaultKeys.computeIfAbsent(
new Tuple(defaultIdentities.toArray(new Path[0])),
t -> new CachingKeyPairProvider(defaultIdentities,
getKeyCache())); getKeyCache()));
} }

Loading…
Cancel
Save