Search in sources :

Example 1 with AuthenticateRequest

use of com.google.u2f.key.messages.AuthenticateRequest in project OpenUnison by TremoloSecurity.

the class RawMessageCodec method decodeAuthenticateRequest.

public static AuthenticateRequest decodeAuthenticateRequest(byte[] data) throws U2FException {
    try {
        DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(data));
        byte controlByte = inputStream.readByte();
        byte[] challengeSha256 = new byte[32];
        inputStream.readFully(challengeSha256);
        byte[] appIdSha256 = new byte[32];
        inputStream.readFully(appIdSha256);
        byte[] keyHandle = new byte[inputStream.readUnsignedByte()];
        inputStream.readFully(keyHandle);
        if (inputStream.available() != 0) {
            throw new U2FException("Message ends with unexpected data");
        }
        return new AuthenticateRequest(controlByte, challengeSha256, appIdSha256, keyHandle);
    } catch (IOException e) {
        throw new U2FException("Error when parsing raw AuthenticateRequest", e);
    }
}
Also used : AuthenticateRequest(com.google.u2f.key.messages.AuthenticateRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) U2FException(com.google.u2f.U2FException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Aggregations

U2FException (com.google.u2f.U2FException)1 AuthenticateRequest (com.google.u2f.key.messages.AuthenticateRequest)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1