public bool CompleteRegistration(string userName, string deviceResponse)
        {
            if (string.IsNullOrWhiteSpace(deviceResponse))
            {
                return(false);
            }

            var user = _userRepository.FindUser(userName);

            if (user == null ||
                user.AuthenticationRequest == null ||
                user.AuthenticationRequest.Count == 0)
            {
                return(false);
            }


            RegisterResponse registerResponse = RegisterResponse.FromJson <RegisterResponse>(deviceResponse);

            // When the user is registration they should only ever have one auth request.
            AuthenticationRequest authenticationRequest = user.AuthenticationRequest.First();

            StartedRegistration startedRegistration = new StartedRegistration(authenticationRequest.Challenge, authenticationRequest.AppId);
            DeviceRegistration  registration        = U2F.FinishRegistration(startedRegistration, registerResponse);

            _userRepository.RemoveUsersAuthenticationRequests(userName);
            _userRepository.AddDeviceRegistration(userName, registration.AttestationCert, registration.Counter, registration.KeyHandle, registration.PublicKey);

            return(true);
        }
        public void U2F_FinishRegistrationNoFacets()
        {
            StartedRegistration startedRegistration = new StartedRegistration(TestConts.SERVER_CHALLENGE_REGISTER_BASE64, TestConts.APP_ID_ENROLL);
            RegisterResponse    registerResponse    = new RegisterResponse(TestConts.REGISTRATION_RESPONSE_DATA_BASE64, TestConts.CLIENT_DATA_REGISTER_BASE64);

            var results = U2F.FinishRegistration(startedRegistration, registerResponse);

            Assert.IsNotNull(results);
            Assert.IsNotNull(results.KeyHandle);
            Assert.IsNotNull(results.PublicKey);
            Assert.IsNotNull(results.GetAttestationCertificate());
        }
Exemplo n.º 3
0
        public static async Task <DeviceRegistration> RegisterAsync(IHidDevice hidDevice, string appId, string facet, CancellationToken?cancellationToken = null)
        {
            cancellationToken = cancellationToken ?? CancellationToken.None;

            if (hidDevice == null || !hidDevice.IsConnected)
            {
                throw new ArgumentException("Hid device not connected", nameof(hidDevice));
            }

            using (var u2fHidDevice = await U2FHidDevice.OpenAsync(hidDevice))
            {
                var startRegistration = U2F.StartRegistration(appId);

                Log.Debug("Touch token to register");
                var registerResponse = await WaitForTokenInputAsync(() => U2Fv2.RegisterAsync(u2fHidDevice, startRegistration, facet), cancellationToken.Value);

                var deviceRegistration = U2F.FinishRegistration(startRegistration, registerResponse);
                Log.Debug("Registered");

                return(deviceRegistration);
            }
        }
Exemplo n.º 4
0
        public bool CompleteRegistration(string userName, string deviceResponse)
        {
            if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(deviceResponse))
            {
                return(false);
            }

            RegisterResponse registerResponse = RegisterResponse.FromJson(deviceResponse);

            var user = _userRepository.FindUser(userName);

            if (user == null || user.AuthenticationRequest == null)
            {
                return(false);
            }

            StartedRegistration startedRegistration = new StartedRegistration(user.AuthenticationRequest.Challenge, user.AuthenticationRequest.AppId);
            DeviceRegistration  registration        = U2F.FinishRegistration(startedRegistration, registerResponse);

            _userRepository.RemoveUsersAuthenticationRequest(userName);
            _userRepository.AddDeviceRegistration(userName, registration.AttestationCert, registration.Counter, registration.KeyHandle, registration.PublicKey);

            return(true);
        }