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