提交 f8a2881e 编写于 作者: S serge-rider

#1115 Check for cert encryption before password check


Former-commit-id: 76aa7564
上级 859e51e0
......@@ -693,10 +693,12 @@ public class DataSourceDescriptor
try {
if (!tunnelConfiguration.isSavePassword()) {
DBWTunnel.AuthCredentials rc = tunnel.getRequiredCredentials(tunnelConfiguration);
if (!DataSourceHandler.askForPassword(this, tunnelConfiguration, rc == DBWTunnel.AuthCredentials.PASSWORD)) {
DataSourceHandler.updateDataSourceObject(this);
tunnel = null;
return false;
if (rc != DBWTunnel.AuthCredentials.NONE) {
if (!DataSourceHandler.askForPassword(this, tunnelConfiguration, rc == DBWTunnel.AuthCredentials.PASSWORD)) {
DataSourceHandler.updateDataSourceObject(this);
tunnel = null;
return false;
}
}
}
......
......@@ -34,6 +34,7 @@ import org.jkiss.utils.IOUtils;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;
/**
......@@ -227,7 +228,30 @@ public class SSHTunnelImpl implements DBWTunnel {
if (sshAuthType != null) {
authType = SSHConstants.AuthType.valueOf(sshAuthType);
}
return authType == SSHConstants.AuthType.PUBLIC_KEY ? AuthCredentials.PASSWORD : AuthCredentials.CREDENTIALS;
if (authType == SSHConstants.AuthType.PUBLIC_KEY) {
// Check whether this key is encrypted
String privKeyPath = configuration.getProperties().get(SSHConstants.PROP_KEY_PATH);
if (privKeyPath != null) {
// Determine whether public key is encrypted
try {
JSch testSch = new JSch();
testSch.addIdentity(privKeyPath);
IdentityRepository ir = testSch.getIdentityRepository();
List<Identity> identities = ir.getIdentities();
for (Identity identity : identities) {
if (identity.isEncrypted()) {
return AuthCredentials.PASSWORD;
}
}
} catch (JSchException e) {
// Something went wrong
log.debug("Can't check private key encryption: " + e.getMessage());
}
}
return AuthCredentials.NONE;
}
return AuthCredentials.CREDENTIALS;
}
@Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册