Exemplo n.º 1
0
        public void RawRegisterResponse_Equals()
        {
            RegisterResponse    registerResponse         = new RegisterResponse(TestConts.REGISTRATION_RESPONSE_DATA_BASE64, TestConts.CLIENT_DATA_REGISTER_BASE64);
            RawRegisterResponse rawAuthenticateResponse1 = RawRegisterResponse.FromBase64(registerResponse.RegistrationData);
            RawRegisterResponse rawAuthenticateResponse  = RawRegisterResponse.FromBase64(registerResponse.RegistrationData);

            Assert.IsTrue(rawAuthenticateResponse.Equals(rawAuthenticateResponse1));
        }
Exemplo n.º 2
0
        public void RawRegisterResponse_FromBase64()
        {
            RegisterResponse    registerResponse        = new RegisterResponse(TestConts.REGISTRATION_RESPONSE_DATA_BASE64, TestConts.CLIENT_DATA_REGISTER_BASE64);
            RawRegisterResponse rawAuthenticateResponse = RawRegisterResponse.FromBase64(registerResponse.RegistrationData);

            Assert.IsNotNull(rawAuthenticateResponse);
            Assert.IsNotNull(rawAuthenticateResponse.CreateDevice());
            Assert.IsTrue(rawAuthenticateResponse.GetHashCode() != 0);
        }
Exemplo n.º 3
0
        private void CreateResponses()
        {
            _registerResponse = new RegisterResponse(TestConts.REGISTRATION_RESPONSE_DATA_BASE64,
                                                     TestConts.CLIENT_DATA_REGISTER_BASE64);
            _rawAuthenticateResponse = RawRegisterResponse.FromBase64(_registerResponse.RegistrationData);
            _deviceRegistration      = _rawAuthenticateResponse.CreateDevice();

            _authenticateResponse = new AuthenticateResponse(TestConts.CLIENT_DATA_AUTHENTICATE_BASE64,
                                                             TestConts.SIGN_RESPONSE_DATA_BASE64,
                                                             TestConts.KEY_HANDLE_BASE64);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Finishes a previously started registration.
        /// </summary>
        /// <param name="startedRegistration">started registration response.</param>
        /// <param name="tokenResponse">tokenResponse the response from the token/client.</param>
        /// <param name="facets">A list of valid facets to verify against. (note: optional)</param>
        /// <returns>a DeviceRegistration object, holding information about the registered device. Servers should persist this.</returns>
        public static DeviceRegistration FinishRegistration(StartedRegistration startedRegistration,
                                                            RegisterResponse tokenResponse, HashSet <string> facets = null)
        {
            ClientData clientData = tokenResponse.GetClientData();

            clientData.CheckContent(RegisterType, startedRegistration.Challenge, facets);

            RawRegisterResponse rawRegisterResponse = RawRegisterResponse.FromBase64(tokenResponse.RegistrationData);

            rawRegisterResponse.CheckSignature(startedRegistration.AppId, clientData.AsJson());

            return(rawRegisterResponse.CreateDevice());
        }
Exemplo n.º 5
0
        public void U2F_StartAuthentication()
        {
            RegisterResponse    registerResponse        = new RegisterResponse(TestConts.REGISTRATION_RESPONSE_DATA_BASE64, TestConts.CLIENT_DATA_REGISTER_BASE64);
            RawRegisterResponse rawAuthenticateResponse = RawRegisterResponse.FromBase64(registerResponse.RegistrationData);
            DeviceRegistration  deviceRegistration      = rawAuthenticateResponse.CreateDevice();

            var results = U2F.Core.Crypto.U2F.StartAuthentication(TestConts.APP_ID_ENROLL, deviceRegistration);

            Assert.NotNull(results);
            Assert.NotNull(results.AppId);
            Assert.NotNull(results.Challenge);
            Assert.NotNull(results.KeyHandle);
            Assert.NotNull(results.Version);
        }
        public void RawRegisterResponse_PackBytesToSign()
        {
            RegisterResponse    registerResponse        = new RegisterResponse(TestConts.REGISTRATION_RESPONSE_DATA_BASE64, TestConts.CLIENT_DATA_REGISTER_BASE64);
            RawRegisterResponse rawAuthenticateResponse = RawRegisterResponse.FromBase64(registerResponse.RegistrationData);

            byte[] packedBytes = rawAuthenticateResponse.PackBytesToSign(
                U2F.Crypto.Hash("appid"),
                U2F.Crypto.Hash(TestConts.CLIENT_DATA_REGISTER),
                TestConts.KEY_HANDLE_BASE64_BYTE,
                TestConts.USER_PUBLIC_KEY_AUTHENTICATE_HEX);

            Assert.IsNotNull(packedBytes);
            Assert.IsTrue(packedBytes.Length > 0);
        }
Exemplo n.º 7
0
        private void CreateResponses()
        {
            _startedRegistration = new StartedRegistration(TestConts.SERVER_CHALLENGE_REGISTER_BASE64, TestConts.APP_ID_ENROLL);
            _registerResponse    = new RegisterResponse(TestConts.REGISTRATION_RESPONSE_DATA_BASE64,
                                                        TestConts.CLIENT_DATA_REGISTER_BASE64);
            _rawAuthenticateResponse = RawRegisterResponse.FromBase64(_registerResponse.RegistrationData);
            _deviceRegistration      = _rawAuthenticateResponse.CreateDevice();

            _authenticateResponse = new AuthenticateResponse(TestConts.CLIENT_DATA_AUTHENTICATE_BASE64,
                                                             TestConts.SIGN_RESPONSE_DATA_BASE64,
                                                             TestConts.KEY_HANDLE_BASE64);

            _startedAuthentication = new StartedAuthentication(TestConts.SERVER_CHALLENGE_SIGN_BASE64, TestConts.APP_ID_ENROLL,
                                                               TestConts.KEY_HANDLE_BASE64);
        }
Exemplo n.º 8
0
        public void U2F_FinishAuthentication()
        {
            StartedAuthentication startedAuthentication =
                new StartedAuthentication(TestConts.SERVER_CHALLENGE_SIGN_BASE64, TestConts.APP_ID_ENROLL,
                                          TestConts.KEY_HANDLE_BASE64);
            AuthenticateResponse authenticateResponse = new AuthenticateResponse(TestConts.CLIENT_DATA_AUTHENTICATE_BASE64,
                                                                                 TestConts.SIGN_RESPONSE_DATA_BASE64,
                                                                                 TestConts.KEY_HANDLE_BASE64);
            RegisterResponse    registerResponse        = new RegisterResponse(TestConts.REGISTRATION_RESPONSE_DATA_BASE64, TestConts.CLIENT_DATA_REGISTER_BASE64);
            RawRegisterResponse rawAuthenticateResponse = RawRegisterResponse.FromBase64(registerResponse.RegistrationData);
            DeviceRegistration  deviceRegistration      = rawAuthenticateResponse.CreateDevice();
            uint orginalValue = deviceRegistration.Counter;

            U2F.FinishAuthentication(startedAuthentication, authenticateResponse, deviceRegistration);

            Assert.IsTrue(deviceRegistration.Counter != 0);
            Assert.AreNotEqual(orginalValue, deviceRegistration.Counter);
        }