use of com.google.u2f.U2FException in project OpenUnison by TremoloSecurity.
the class RawMessageCodec method decodeAuthenticateResponse.
public static AuthenticateResponse decodeAuthenticateResponse(byte[] data) throws U2FException {
try {
DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(data));
byte userPresence = inputStream.readByte();
int counter = inputStream.readInt();
byte[] signature = new byte[inputStream.available()];
inputStream.readFully(signature);
if (inputStream.available() != 0) {
throw new U2FException("Message ends with unexpected data");
}
return new AuthenticateResponse(userPresence, counter, signature);
} catch (IOException e) {
throw new U2FException("Error when parsing raw AuthenticateResponse", e);
}
}
use of com.google.u2f.U2FException in project OpenUnison by TremoloSecurity.
the class SerialCodec method sendRequest.
private static void sendRequest(OutputStream outputStream, byte command, byte[] encodedBytes) throws U2FException, IOException {
if (encodedBytes.length > 65535) {
throw new U2FException("Message is too long to be transmitted over this protocol");
}
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
dataOutputStream.write(VERSION);
dataOutputStream.write(command);
dataOutputStream.writeShort(encodedBytes.length);
dataOutputStream.write(encodedBytes);
dataOutputStream.flush();
}
use of com.google.u2f.U2FException in project OpenUnison by TremoloSecurity.
the class SerialCodec method sendResponse.
private static void sendResponse(OutputStream outputStream, byte[] encodedBytes) throws U2FException, IOException {
if (encodedBytes.length > 65535) {
throw new U2FException("Message is too long to be transmitted over this protocol");
}
DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
dataOutputStream.writeShort(encodedBytes.length);
dataOutputStream.write(encodedBytes);
dataOutputStream.flush();
}
use of com.google.u2f.U2FException in project OpenUnison by TremoloSecurity.
the class BouncyCastleCrypto method sign.
@Override
public byte[] sign(byte[] signedData, PrivateKey privateKey) throws U2FException {
try {
Signature signature = Signature.getInstance("SHA256withECDSA");
signature.initSign(privateKey);
signature.update(signedData);
return signature.sign();
} catch (NoSuchAlgorithmException e) {
throw new U2FException("Error when signing", e);
} catch (SignatureException e) {
throw new U2FException("Error when signing", e);
} catch (InvalidKeyException e) {
throw new U2FException("Error when signing", e);
}
}
use of com.google.u2f.U2FException in project OpenUnison by TremoloSecurity.
the class U2FKeyReferenceImpl method register.
@Override
public RegisterResponse register(RegisterRequest registerRequest) throws U2FException {
Log.info(">> register");
byte[] applicationSha256 = registerRequest.getApplicationSha256();
byte[] challengeSha256 = registerRequest.getChallengeSha256();
Log.info(" -- Inputs --");
Log.info(" applicationSha256: " + Hex.encodeHexString(applicationSha256));
Log.info(" challengeSha256: " + Hex.encodeHexString(challengeSha256));
byte userPresent = userPresenceVerifier.verifyUserPresence();
if ((userPresent & UserPresenceVerifier.USER_PRESENT_FLAG) == 0) {
throw new U2FException("Cannot verify user presence");
}
KeyPair keyPair = keyPairGenerator.generateKeyPair(applicationSha256, challengeSha256);
byte[] keyHandle = keyHandleGenerator.generateKeyHandle(applicationSha256, keyPair);
dataStore.storeKeyPair(keyHandle, keyPair);
byte[] userPublicKey = keyPairGenerator.encodePublicKey(keyPair.getPublic());
byte[] signedData = RawMessageCodec.encodeRegistrationSignedBytes(applicationSha256, challengeSha256, keyHandle, userPublicKey);
Log.info("Signing bytes " + Hex.encodeHexString(signedData));
byte[] signature = crypto.sign(signedData, certificatePrivateKey);
Log.info(" -- Outputs --");
Log.info(" userPublicKey: " + Hex.encodeHexString(userPublicKey));
Log.info(" keyHandle: " + Hex.encodeHexString(keyHandle));
Log.info(" vendorCertificate: " + vendorCertificate);
Log.info(" signature: " + Hex.encodeHexString(signature));
Log.info("<< register");
return new RegisterResponse(userPublicKey, keyHandle, vendorCertificate, signature);
}
Aggregations