mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-07 15:50:57 +03:00
Add extra logging in OpenSSHKnownHosts and extra test
This commit is contained in:
@@ -85,7 +85,7 @@ class ECDSAVariationsAdapter {
|
||||
X9ECParameters ecParams = NISTNamedCurves.getByName(name);
|
||||
ECNamedCurveSpec ecCurveSpec = new ECNamedCurveSpec(name, ecParams.getCurve(), ecParams.getG(), ecParams.getN());
|
||||
ECPoint p = new ECPoint(bigX, bigY);
|
||||
ECPublicKeySpec publicKeySpec = new java.security.spec.ECPublicKeySpec(p, ecCurveSpec);
|
||||
ECPublicKeySpec publicKeySpec = new ECPublicKeySpec(p, ecCurveSpec);
|
||||
|
||||
KeyFactory keyFactory = KeyFactory.getInstance("ECDSA");
|
||||
return keyFactory.generatePublic(publicKeySpec);
|
||||
|
||||
@@ -197,6 +197,12 @@ final class KeyExchanger
|
||||
if (hkv.verify(transport.getRemoteHost(), transport.getRemotePort(), key))
|
||||
return;
|
||||
}
|
||||
log.error("Disconnecting because none of the configured Host key verifiers ({}) could verify '{}' host key with fingerprint {} for {}:{}",
|
||||
hostVerifiers,
|
||||
KeyType.fromKey(key),
|
||||
SecurityUtils.getFingerprint(key),
|
||||
transport.getRemoteHost(),
|
||||
transport.getRemotePort());
|
||||
|
||||
throw new TransportException(DisconnectReason.HOST_KEY_NOT_VERIFIABLE,
|
||||
"Could not verify `" + KeyType.fromKey(key)
|
||||
|
||||
@@ -340,7 +340,7 @@ public class OpenSSHKnownHosts
|
||||
|
||||
@Override
|
||||
public boolean verify(PublicKey key) throws IOException {
|
||||
return key.equals(this.key) && marker != Marker.REVOKED;
|
||||
return getKeyString(key).equals(getKeyString(this.key)) && marker != Marker.REVOKED;
|
||||
}
|
||||
|
||||
public String getLine() {
|
||||
@@ -350,12 +350,12 @@ public class OpenSSHKnownHosts
|
||||
|
||||
line.append(getHostPart());
|
||||
line.append(" ").append(type.toString());
|
||||
line.append(" ").append(getKeyString());
|
||||
line.append(" ").append(getKeyString(key));
|
||||
return line.toString();
|
||||
}
|
||||
|
||||
private String getKeyString() {
|
||||
final Buffer.PlainBuffer buf = new Buffer.PlainBuffer().putPublicKey(key);
|
||||
private String getKeyString(PublicKey pk) {
|
||||
final Buffer.PlainBuffer buf = new Buffer.PlainBuffer().putPublicKey(pk);
|
||||
return Base64.encodeBytes(buf.array(), buf.rpos(), buf.available());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user