Search in sources :

Example 11 with U2FException

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);
    }
}
Also used : AuthenticateResponse(com.google.u2f.key.messages.AuthenticateResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) U2FException(com.google.u2f.U2FException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 12 with U2FException

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();
}
Also used : DataOutputStream(java.io.DataOutputStream) U2FException(com.google.u2f.U2FException)

Example 13 with U2FException

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();
}
Also used : DataOutputStream(java.io.DataOutputStream) U2FException(com.google.u2f.U2FException)

Example 14 with U2FException

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);
    }
}
Also used : Signature(java.security.Signature) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) U2FException(com.google.u2f.U2FException) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException)

Example 15 with U2FException

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);
}
Also used : KeyPair(java.security.KeyPair) RegisterResponse(com.google.u2f.key.messages.RegisterResponse) U2FException(com.google.u2f.U2FException)

Aggregations

U2FException (com.google.u2f.U2FException)21 SecurityKeyData (com.google.u2f.server.data.SecurityKeyData)6 IOException (java.io.IOException)6 DataInputStream (java.io.DataInputStream)5 JsonParser (com.google.gson.JsonParser)4 RegisterResponse (com.google.u2f.key.messages.RegisterResponse)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 X509Certificate (java.security.cert.X509Certificate)4 AuthenticateResponse (com.google.u2f.key.messages.AuthenticateResponse)3 U2FServer (com.google.u2f.server.U2FServer)3 AuthController (com.tremolosecurity.proxy.auth.AuthController)3 AuthInfo (com.tremolosecurity.proxy.auth.AuthInfo)3 Attribute (com.tremolosecurity.saml.Attribute)3 InvalidKeyException (java.security.InvalidKeyException)3 SignatureException (java.security.SignatureException)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 HashMap (java.util.HashMap)3 JsonObject (com.google.gson.JsonObject)2 EnrollSessionData (com.google.u2f.server.data.EnrollSessionData)2