U2F { public DeviceRegistration finishSignature(SignRequestData signRequestData, SignResponse response, Iterable<? extends DeviceRegistration> devices) throws U2fAuthenticationException { return finishSignature(signRequestData, response, devices, null); } U2F(); private  U2F(boolean validateAppId); static U2F withoutAppIdValidation(); RegisterRequestData startRegistration(String appId, Iterable<? extends DeviceRegistration> devices); SignRequestData startSignature(String appId, Iterable<? extends DeviceRegistration> devices); DeviceRegistration finishRegistration(RegisterRequestData registerRequestData, RegisterResponse response); DeviceRegistration finishRegistration(RegisterRequestData registerRequestData, RegisterResponse response, Set<String> facets); DeviceRegistration finishSignature(SignRequestData signRequestData, SignResponse response, Iterable<? extends DeviceRegistration> devices); DeviceRegistration finishSignature(SignRequestData signRequestData, SignResponse response, Iterable<? extends DeviceRegistration> devices, Set<String> facets);  }
@Test(expected = DeviceCompromisedException.class) public void finishSignature_compromisedDevice() throws Exception { DeviceRegistration deviceRegistration = new DeviceRegistration(KEY_HANDLE_BASE64, USER_PUBLIC_KEY_SIGN_HEX, ATTESTATION_CERTIFICATE, 0); SignRequest request = SignRequest.builder() .challenge(SERVER_CHALLENGE_SIGN_BASE64) .appId(APP_ID_SIGN) .keyHandle(KEY_HANDLE_BASE64) .build(); SignResponse tokenResponse = new SignResponse(CLIENT_DATA_SIGN_BASE64, SIGN_RESPONSE_DATA_BASE64, KEY_HANDLE_BASE64); SignRequestData requestData = mock(SignRequestData.class); when(requestData.getSignRequest(tokenResponse)).thenReturn(request); deviceRegistration.markCompromised(); u2f.finishSignature(requestData, tokenResponse, ImmutableList.of(deviceRegistration)); }
@Test public void finishSignature_invalidFacet() throws Exception { expectedException.expectCause(isA(U2fBadInputException.class)); DeviceRegistration deviceRegistration = new DeviceRegistration(KEY_HANDLE_BASE64, USER_PUBLIC_KEY_SIGN_HEX, ATTESTATION_CERTIFICATE, 0); SignRequest request = SignRequest.builder() .challenge(SERVER_CHALLENGE_SIGN_BASE64) .appId(APP_ID_SIGN) .keyHandle(KEY_HANDLE_BASE64) .build(); SignResponse tokenResponse = new SignResponse(CLIENT_DATA_SIGN_BASE64, SIGN_RESPONSE_DATA_BASE64, KEY_HANDLE_BASE64); SignRequestData requestData = mock(SignRequestData.class); when(requestData.getSignRequest(tokenResponse)).thenReturn(request); u2f.finishSignature(requestData, tokenResponse, ImmutableList.of(deviceRegistration), ImmutableSet.of("https: }
@Test public void finishSignatureShouldReturnAMatchedDevice() throws Exception { DeviceRegistration deviceRegistration = new DeviceRegistration(KEY_HANDLE_BASE64, USER_PUBLIC_KEY_SIGN_HEX, ATTESTATION_CERTIFICATE, 0); DeviceRegistration deviceRegistration2 = new DeviceRegistration(KEY_HANDLE_BASE64, USER_PUBLIC_KEY_SIGN_HEX, ATTESTATION_CERTIFICATE, 0); SignRequest request = SignRequest.builder() .challenge(SERVER_CHALLENGE_SIGN_BASE64) .appId(APP_ID_SIGN) .keyHandle(KEY_HANDLE_BASE64) .build(); SignResponse tokenResponse = new SignResponse(CLIENT_DATA_SIGN_BASE64, SIGN_RESPONSE_DATA_BASE64, KEY_HANDLE_BASE64); SignRequestData requestData = new SignRequestData( APP_ID_SIGN, SERVER_CHALLENGE_SIGN_BASE64, ImmutableList.of(request) ); DeviceRegistration device = u2f.finishSignature(requestData, tokenResponse, ImmutableList.of(deviceRegistration), ImmutableSet.of(APP_ID_ENROLL)); DeviceRegistration overloadDevice = u2f.finishSignature(requestData, tokenResponse, ImmutableList.of(deviceRegistration2)); assertEquals(KEY_HANDLE_BASE64, device.getKeyHandle()); assertEquals(device, overloadDevice); }