This commit is contained in:
David Kocher
2014-05-14 11:06:33 +02:00
parent 5c540b6889
commit 08d0e59b6b

View File

@@ -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;
} }
}; };