U2F { public RegisterRequestData startRegistration(String appId, Iterable<? extends DeviceRegistration> devices) throws U2fBadConfigurationException { if(validateAppId) { AppId.checkIsValid(appId); } return new RegisterRequestData(appId, devices, primitives, challengeGenerator); } 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 public void startRegistration_compromisedDevice() throws Exception { DeviceRegistration deviceRegistration = new DeviceRegistration(KEY_HANDLE_BASE64, USER_PUBLIC_KEY_SIGN_HEX, ATTESTATION_CERTIFICATE, 0); deviceRegistration.markCompromised(); u2f.startRegistration(APP_ID_ENROLL, ImmutableList.of(deviceRegistration)); }
@Test(expected = U2fBadConfigurationException.class) public void defaultConstructedU2FstartRegistrationShouldRefuseInvalidAppId() throws U2fBadInputException, U2fBadConfigurationException { DeviceRegistration deviceRegistration = new DeviceRegistration(KEY_HANDLE_BASE64, USER_PUBLIC_KEY_SIGN_HEX, ATTESTATION_CERTIFICATE, 0); deviceRegistration.markCompromised(); new U2F().startRegistration("example.com", ImmutableList.of(deviceRegistration)); fail("startRegistration did not refuse an invalid app ID."); }
@Test public void startRegistrationShouldReturnARandomChallenge() throws U2fBadInputException, U2fBadConfigurationException { DeviceRegistration deviceRegistration = new DeviceRegistration(KEY_HANDLE_BASE64, USER_PUBLIC_KEY_SIGN_HEX, ATTESTATION_CERTIFICATE, 0); RegisterRequestData data = u2f.startRegistration("example.com", ImmutableList.of(deviceRegistration)); RegisterRequestData data2 = u2f.startRegistration("example.com", ImmutableList.of(deviceRegistration)); assertEquals(1, data.getRegisterRequests().size()); assertEquals(1, data2.getRegisterRequests().size()); assertNotEquals( "startRegistration must not return the same challenge twice in a row.", data.getRegisterRequests().get(0).getChallenge(), data2.getRegisterRequests().get(0).getChallenge() ); }