Ejemplo n.º 1
0
        public override bool Equals(Object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (GetType() != obj.GetType())
            {
                return(false);
            }

            AuthenticateResponse other = (AuthenticateResponse)obj;

            if (ClientData == null)
            {
                if (other.ClientData != null)
                {
                    return(false);
                }
            }
            else if (!ClientData.Equals(other.ClientData))
            {
                return(false);
            }

            if (KeyHandle == null)
            {
                if (other.KeyHandle != null)
                {
                    return(false);
                }
            }
            else if (!KeyHandle.Equals(other.KeyHandle))
            {
                return(false);
            }

            if (SignatureData == null)
            {
                if (other.SignatureData != null)
                {
                    return(false);
                }
            }
            else if (!SignatureData.Equals(other.SignatureData))
            {
                return(false);
            }

            return(true);
        }
        public void AuthenticateResponse_Equals()
        {
            AuthenticateResponse authenticateResponse = AuthenticateResponse.FromJson<AuthenticateResponse>(JsonData);
            AuthenticateResponse sameAuthenticateResponse = new AuthenticateResponse(
                TestConts.CLIENT_DATA_AUTHENTICATE_BASE64,
                TestConts.SIGN_RESPONSE_DATA_BASE64,
                TestConts.KEY_HANDLE_BASE64);

            Assert.IsNotNull(authenticateResponse);
            Assert.IsNotNull(sameAuthenticateResponse);
            Assert.IsTrue(authenticateResponse.Equals(sameAuthenticateResponse));
        }
        public void Setup()
        {
            StartedAuthentication startedAuthentication =
                new StartedAuthentication(TestConts.SERVER_CHALLENGE_SIGN_BASE64, TestConts.APP_ID_ENROLL,
                                          TestConts.KEY_HANDLE_BASE64);
            _authenticateResponse = new AuthenticateResponse(TestConts.CLIENT_DATA_AUTHENTICATE_BASE64,
                                                                                 TestConts.SIGN_RESPONSE_DATA_BASE64,
                                                                                 TestConts.KEY_HANDLE_BASE64);

            clientData = _authenticateResponse.GetClientData();
            clientData.CheckContent(AuthenticateTyp, startedAuthentication.Challenge, null);
        }
        public void AuthenticateResponse_ConstructsProperly()
        {
            AuthenticateResponse authenticateResponse = new AuthenticateResponse(TestConts.CLIENT_DATA_AUTHENTICATE_BASE64,
                                                                                 TestConts.SIGN_RESPONSE_DATA_BASE64,
                                                                                 TestConts.KEY_HANDLE_BASE64);

            Assert.IsNotNull(authenticateResponse);
            Assert.IsNotNull(authenticateResponse.ToJson());
            Assert.IsNotNull(authenticateResponse.GetClientData());
            Assert.IsTrue(authenticateResponse.GetHashCode() != 0);
            Assert.AreEqual(JsonData, authenticateResponse.ToJson());
            Assert.AreEqual(TestConts.SIGN_RESPONSE_DATA_BASE64, authenticateResponse.SignatureData);
            Assert.AreEqual(TestConts.KEY_HANDLE_BASE64, authenticateResponse.KeyHandle);
        }
Ejemplo n.º 5
0
        /**
        * Finishes a previously started authentication.
        *
        * @param startedAuthentication
        * @param response the response from the token/client.
        * @return the new value of the DeviceRegistration's counter.
        */
        public static void FinishAuthentication(StartedAuthentication startedAuthentication,
                                                              AuthenticateResponse response,
                                                              DeviceRegistration deviceRegistration,
                                                              HashSet<String> facets = null)
        {
            ClientData clientData = response.GetClientData();
            clientData.CheckContent(AuthenticateTyp, startedAuthentication.Challenge, facets);

            RawAuthenticateResponse authenticateResponse = RawAuthenticateResponse.FromBase64(response.SignatureData);
            authenticateResponse.CheckSignature(startedAuthentication.AppId, clientData.AsJson(), deviceRegistration.PublicKey);
            authenticateResponse.CheckUserPresence();

            deviceRegistration.CheckAndUpdateCounter(authenticateResponse.Counter);
        }
Ejemplo n.º 6
0
        public void U2F_FinishAuthentication()
        {
            StartedAuthentication startedAuthentication = new StartedAuthentication(
                TestConts.SERVER_CHALLENGE_SIGN_BASE64,
                TestConts.APP_SIGN_ID,
                TestConts.KEY_HANDLE_BASE64);

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

            DeviceRegistration deviceRegistration = new DeviceRegistration(TestConts.KEY_HANDLE_BASE64_BYTE, TestConts.USER_PUBLIC_KEY_AUTHENTICATE_HEX,
                Utils.Base64StringToByteArray(TestConts.ATTESTATION_CERTIFICATE), 0);

            uint orginalValue = deviceRegistration.Counter;

            U2F.FinishAuthentication(startedAuthentication, authenticateResponse, deviceRegistration);

            Assert.IsTrue(deviceRegistration.Counter != 0);
            Assert.AreNotEqual(orginalValue, deviceRegistration.Counter);
        }
Ejemplo n.º 7
0
        private void CreateResponses()
        {
            _deviceRegistration = new DeviceRegistration(
                TestConts.KEY_HANDLE_BASE64_BYTE,
                TestConts.USER_PUBLIC_KEY_AUTHENTICATE_HEX,
                Utils.Base64StringToByteArray(TestConts.ATTESTATION_CERTIFICATE),
                0);

            _authenticateResponse = new AuthenticateResponse(
                TestConts.CLIENT_DATA_AUTHENTICATE_BASE64,
                TestConts.SIGN_RESPONSE_DATA_BASE64,
                TestConts.KEY_HANDLE_BASE64);
        }
Ejemplo n.º 8
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);

            _deviceRegistration = new DeviceRegistration(
                TestConts.KEY_HANDLE_BASE64_BYTE,
                TestConts.USER_PUBLIC_KEY_AUTHENTICATE_HEX,
                Utils.Base64StringToByteArray(TestConts.ATTESTATION_CERTIFICATE),
                0);

            _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_SIGN_ID,
                    TestConts.KEY_HANDLE_BASE64);
        }
Ejemplo n.º 9
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);
        }