mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-07 15:50:57 +03:00
Logging
This commit is contained in:
@@ -28,6 +28,7 @@ import java.security.*;
|
|||||||
import java.security.interfaces.*;
|
import java.security.interfaces.*;
|
||||||
import java.security.spec.DSAPublicKeySpec;
|
import java.security.spec.DSAPublicKeySpec;
|
||||||
import java.security.spec.RSAPublicKeySpec;
|
import java.security.spec.RSAPublicKeySpec;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/** Type of key e.g. rsa, dsa */
|
/** Type of key e.g. rsa, dsa */
|
||||||
public enum KeyType {
|
public enum KeyType {
|
||||||
@@ -101,7 +102,8 @@ public enum KeyType {
|
|||||||
|
|
||||||
/** SSH identifier for ECDSA keys */
|
/** SSH identifier for ECDSA keys */
|
||||||
ECDSA("ecdsa-sha2-nistp256") {
|
ECDSA("ecdsa-sha2-nistp256") {
|
||||||
private final Logger LOG = LoggerFactory.getLogger(getClass());
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PublicKey readPubKeyFromBuffer(String type, Buffer<?> buf)
|
public PublicKey readPubKeyFromBuffer(String type, Buffer<?> buf)
|
||||||
throws GeneralSecurityException {
|
throws GeneralSecurityException {
|
||||||
@@ -114,17 +116,19 @@ public enum KeyType {
|
|||||||
final byte[] y = new byte[(keyLen - 1) / 2];
|
final byte[] y = new byte[(keyLen - 1) / 2];
|
||||||
buf.readRawBytes(x);
|
buf.readRawBytes(x);
|
||||||
buf.readRawBytes(y);
|
buf.readRawBytes(y);
|
||||||
LOG.debug(String.format("Key algo: %s, Key curve: %s, Key Len: %s, 0x04: %s\nx: %s\ny: %s",
|
if(log.isDebugEnabled()) {
|
||||||
type,
|
log.debug(String.format("Key algo: %s, Key curve: %s, Key Len: %s, 0x04: %s\nx: %s\ny: %s",
|
||||||
curveName,
|
type,
|
||||||
keyLen,
|
curveName,
|
||||||
x04,
|
keyLen,
|
||||||
x,
|
x04,
|
||||||
y)
|
Arrays.toString(x),
|
||||||
);
|
Arrays.toString(y))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!NISTP_CURVE.equals(curveName)) {
|
if (!NISTP_CURVE.equals(curveName)) {
|
||||||
throw new GeneralSecurityException("Unknown curve name");
|
throw new GeneralSecurityException(String.format("Unknown curve %s", curveName));
|
||||||
}
|
}
|
||||||
|
|
||||||
BigInteger bigX = new BigInteger(1, x);
|
BigInteger bigX = new BigInteger(1, x);
|
||||||
@@ -137,9 +141,7 @@ public enum KeyType {
|
|||||||
ECPublicKeySpec publicSpec = new ECPublicKeySpec(pPublicPoint, spec);
|
ECPublicKeySpec publicSpec = new ECPublicKeySpec(pPublicPoint, spec);
|
||||||
|
|
||||||
KeyFactory keyFactory = KeyFactory.getInstance("ECDSA");
|
KeyFactory keyFactory = KeyFactory.getInstance("ECDSA");
|
||||||
|
return keyFactory.generatePublic(publicSpec);
|
||||||
PublicKey pubKey = keyFactory.generatePublic(publicSpec);
|
|
||||||
return pubKey;
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
throw new GeneralSecurityException(ex);
|
throw new GeneralSecurityException(ex);
|
||||||
}
|
}
|
||||||
@@ -159,7 +161,6 @@ public enum KeyType {
|
|||||||
.putRawBytes(new byte[] { (byte) 0x04 })
|
.putRawBytes(new byte[] { (byte) 0x04 })
|
||||||
.putRawBytes(x)
|
.putRawBytes(x)
|
||||||
.putRawBytes(y)
|
.putRawBytes(y)
|
||||||
.compact()
|
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,7 +181,6 @@ public enum KeyType {
|
|||||||
System.arraycopy(in, i, out, 0, out.length);
|
System.arraycopy(in, i, out, 0, out.length);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/** Unrecognized */
|
/** Unrecognized */
|
||||||
@@ -200,7 +200,6 @@ public enum KeyType {
|
|||||||
protected boolean isMyType(Key key) {
|
protected boolean isMyType(Key key) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user