U2fPrimitives { public DeviceRegistration finishRegistration(RegisterRequest registerRequest, RegisterResponse response) throws U2fRegistrationException { return finishRegistration(registerRequest, response, null); } U2fPrimitives(Crypto crypto, ChallengeGenerator challengeGenerator);  U2fPrimitives(); RegisterRequest startRegistration(String appId); RegisterRequest startRegistration(String appId, byte[] challenge); DeviceRegistration finishRegistration(RegisterRequest registerRequest, RegisterResponse response); DeviceRegistration finishRegistration(RegisterRequest registerRequest,
                                                 RegisterResponse response,
                                                 Set<String> facets); SignRequest startSignature(String appId, DeviceRegistration deviceRegistration); SignRequest startSignature(String appId, DeviceRegistration deviceRegistration, byte[] challenge); void finishSignature(SignRequest signRequest,
                                SignResponse response,
                                DeviceRegistration deviceRegistration); void finishSignature(SignRequest signRequest,
                                SignResponse response,
                                DeviceRegistration deviceRegistration,
                                Set<String> facets); static final String U2F_VERSION; }
@Test public void finishRegistration() throws Exception { RegisterRequest registerRequest = new RegisterRequest(SERVER_CHALLENGE_REGISTER_BASE64, APP_ID_ENROLL); DeviceRegistration response = u2f.finishRegistration(registerRequest, new RegisterResponse(TestVectors.REGISTRATION_DATA_BASE64, CLIENT_DATA_REGISTRATION_BASE64), TRUSTED_DOMAINS); assertEquals(KEY_HANDLE_BASE64, response.getKeyHandle()); }
@Test public void finishRegistration2() throws Exception { RegisterRequest registerRequest = new RegisterRequest(SERVER_CHALLENGE_REGISTER_BASE64, APP_ID_ENROLL); DeviceRegistration deviceRegistration = u2f.finishRegistration(registerRequest, new RegisterResponse(AcmeKey.REGISTRATION_DATA_BASE64, AcmeKey.CLIENT_DATA_BASE64), TRUSTED_DOMAINS); assertEquals(new DeviceRegistration(AcmeKey.KEY_HANDLE, AcmeKey.USER_PUBLIC_KEY_B64, AcmeKey.ATTESTATION_CERTIFICATE, 0), deviceRegistration); }
@Test public void finishRegistrationWithoutAllowedAppIds() throws Exception { RegisterRequest registerRequest = new RegisterRequest(SERVER_CHALLENGE_REGISTER_BASE64, APP_ID_ENROLL); DeviceRegistration response = u2f.finishRegistration( registerRequest, new RegisterResponse( TestVectors.REGISTRATION_DATA_BASE64, CLIENT_DATA_REGISTRATION_BASE64 ) ); assertEquals(KEY_HANDLE_BASE64, response.getKeyHandle()); }
@Test public void finishRegistrationShouldDetectIncorrectAppId() throws Exception { expectedException.expectCause(isA(U2fBadInputException.class)); RegisterRequest registerRequest = new RegisterRequest(SERVER_CHALLENGE_REGISTER_BASE64, APP_ID_ENROLL); DeviceRegistration response = u2f.finishRegistration( registerRequest, new RegisterResponse( TestVectors.REGISTRATION_DATA_WITH_DIFFERENT_APP_ID_BASE64, CLIENT_DATA_REGISTRATION_BASE64 ) ); fail("finishRegistration did not detect incorrect app ID"); }
@Test public void finishRegistrationShouldDetectIncorrectChallenge() throws Exception { expectedException.expectCause(isA(U2fBadInputException.class)); RegisterRequest registerRequest = new RegisterRequest(SERVER_CHALLENGE_REGISTER_BASE64, APP_ID_ENROLL); String clientDataBase64 = U2fB64Encoding.encode("{\"typ\":\"navigator.id.finishEnrollment\",\"challenge\":\"ARGHABLARGHLER\",\"origin\":\"http: u2f.finishRegistration( registerRequest, new RegisterResponse( TestVectors.REGISTRATION_DATA_BASE64, clientDataBase64 ) ); fail("finishRegistration did not detect incorrect challenge"); }
@Test public void finishRegistrationShouldDetectIncorrectClientDataType() throws Exception { expectedException.expectCause(isA(U2fBadInputException.class)); RegisterRequest registerRequest = new RegisterRequest(SERVER_CHALLENGE_REGISTER_BASE64, APP_ID_ENROLL); String clientDataBase64 = U2fB64Encoding.encode("{\"typ\":\"navigator.id.launchNukes\",\"challenge\":\"vqrS6WXDe1JUs5_c3i4-LkKIHRr-3XVb3azuA5TifHo\",\"origin\":\"http: u2f.finishRegistration( registerRequest, new RegisterResponse( TestVectors.REGISTRATION_DATA_WITH_DIFFERENT_CLIENT_DATA_TYPE_BASE64, clientDataBase64 ) ); fail("finishRegistration did not detect incorrect type in client data"); }
@Test public void finishRegistrationShouldDetectIncorrectClientDataOrigin() throws Exception { expectedException.expectCause(isA(U2fBadInputException.class)); RegisterRequest registerRequest = new RegisterRequest(SERVER_CHALLENGE_REGISTER_BASE64, APP_ID_ENROLL); String clientDataBase64 = U2fB64Encoding.encode("{\"typ\":\"navigator.id.finishEnrollment\",\"challenge\":\"vqrS6WXDe1JUs5_c3i4-LkKIHRr-3XVb3azuA5TifHo\",\"origin\":\"http: u2f.finishRegistration( registerRequest, new RegisterResponse( TestVectors.REGISTRATION_DATA_BASE64, clientDataBase64 ) ); fail("finishRegistration did not detect incorrect origin in client data"); }