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>
tags/v5.3.0.201901161700-m1
Thomas Wolf 5 years ago
parent
commit
5663b67575

+ 1
- 0
org.eclipse.jgit.ssh.apache/resources/org/eclipse/jgit/internal/transport/sshd/SshdText.properties View File

@@ -13,6 +13,7 @@ gssapiUnexpectedMessage=Received unexpected ssh message {1} in {0} authenticatio
identityFileCannotDecrypt=Given passphrase cannot decrypt identity {0}
identityFileNoKey=No keys 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}
kexServerKeyInvalid=Server key did not validate
keyEncryptedMsg=Key ''{0}'' is encrypted. Enter the passphrase to decrypt it.

+ 5
- 0
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/CachingKeyPairProvider.java View File

@@ -45,6 +45,7 @@ package org.eclipse.jgit.internal.transport.sshd;
import static java.text.MessageFormat.format;

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

+ 1
- 0
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/SshdText.java View File

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

+ 7
- 5
org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/transport/sshd/SshdSessionFactory.java View File

@@ -161,7 +161,7 @@ public class SshdSessionFactory extends SshSessionFactory implements Closeable {
private static final class Tuple {
private Object[] objects;

public Tuple(Object... objects) {
public Tuple(Object[] objects) {
this.objects = objects;
}

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


Loading…
Cancel
Save