Exemple #1
0
        async void EnrollClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                ActionstextBox.Text = "";
                var server = new U2FServerReferenceImpl(
                    new ChallengeGenerator(),
                    dataStore,
                    new BouncyCastleServerCrypto(),
                    new[] { "http://example.com", "https://example.com" });

                var myClient = new U2FClient(
                    new DummySender("http://example.com", new JObject()),
                    keyFactory);

                var signRequests = server.GetSignRequests(EnrollUserName.Text, EnrollAppId.Text);
                var regRequest   = server.GetRegistrationRequest(EnrollUserName.Text, EnrollAppId.Text);
                var cts          = new CancellationTokenSource(TimeSpan.FromMinutes(1));

                ActionstextBox.Text += "Register...\r\n";
                var x = await myClient.Register(new[] { regRequest }, signRequests, cts.Token);

                ActionstextBox.Text += "Register done, sending to server\r\n";

                var serverResp = server.ProcessRegistrationResponse(x, ToUnixTimeMilliseconds(SystemClock.Instance.Now));
                ActionstextBox.Text += "Server OK\r\n";
                ActionstextBox.Text += $"{serverResp}\r\n";
            }
            catch (Exception exception)
            {
                ActionstextBox.Text += "\r\n\r\n" + exception.ToString();
            }
        }
        public virtual void TestProcessRegistrationResponse_MultipleTransports()
        {
            mockDataStore.Setup(x => x.GetEnrollSessionData(SESSION_ID))
            .Returns(new EnrollSessionData(ACCOUNT_NAME, APP_ID_ENROLL, SERVER_CHALLENGE_ENROLL));
            var trustedCertificates = new List <X509Certificate>();

            trustedCertificates.Add(TRUSTED_CERTIFICATE_MULTIPLE_TRANSPORTS);
            mockDataStore.Setup(x => x.GetTrustedCertificates()).Returns(trustedCertificates);
            var u2FServer = new U2FServerReferenceImpl(mockChallengeGenerator.Object, mockDataStore.Object, crypto,
                                                       TRUSTED_DOMAINS);

            var registrationResponse = new RegisterResponse(REGISTRATION_RESPONSE_DATA_MULTIPLE_TRANSPORTS_BASE64,
                                                            BROWSER_DATA_ENROLL_BASE64, SESSION_ID);

            u2FServer.ProcessRegistrationResponse(registrationResponse, 0L);

            var transports = new List <SecurityKeyDataTransports>();

            transports.Add(SecurityKeyDataTransports.BluetoothRadio);
            transports.Add(SecurityKeyDataTransports.BluetoothLowEnergy);
            transports.Add(SecurityKeyDataTransports.Nfc);
            var expectedKeyData = new SecurityKeyData(0L, transports, KEY_HANDLE, USER_PUBLIC_KEY_ENROLL_HEX,
                                                      TRUSTED_CERTIFICATE_MULTIPLE_TRANSPORTS, 0);

            mockDataStore.Verify(x => x.AddSecurityKeyData(ACCOUNT_NAME, expectedKeyData));
        }
Exemple #3
0
        private static async Task TestNew2()
        {
            var hidFactory = Win32HidDeviceFactory.Instance;
            var keyFactory = new U2FHidKeyFactory(hidFactory);

            var dataStore = new InMemoryServerDataStore(new GuidSessionIdGenerator());

            LoadDataStore(dataStore);
            var server = new U2FServerReferenceImpl(
                new ChallengeGenerator(),
                dataStore,
                new BouncyCastleServerCrypto(),
                new[] { "http://example.com", "https://example.com" });

            var myClient = new U2FClient(
                new DummySender("http://example.com", new JObject()),
                keyFactory);

            Console.WriteLine("Register or Sign ? (r/s)");
            var mode = Console.ReadLine();

            if (mode == "s")
            {
                var signRequests = server.GetSignRequests("vbfox", "http://example.com");
                Console.WriteLine("Sign requests obtained ({0})", signRequests.Count);
                var cts = new CancellationTokenSource(TimeSpan.FromMinutes(10));
                var x   = await myClient.Sign(signRequests, cts.Token);

                Console.WriteLine("Signature done {0}", x);
                if (x != null)
                {
                    var serverResp = server.ProcessSignResponse(x);
                    Console.WriteLine("Server ok: {0}", serverResp);
                    SaveDataStore(dataStore);
                }
            }
            else if (mode == "r")
            {
                var signRequests = server.GetSignRequests("vbfox", "http://example.com");
                var regRequest   = server.GetRegistrationRequest("vbfox", "http://example.com");
                var cts          = new CancellationTokenSource(TimeSpan.FromMinutes(10));
                var x            = await myClient.Register(new[] { regRequest }, signRequests, cts.Token);

                Console.WriteLine("Authentication done {0}", x);
                if (x != null)
                {
                    var serverResp = server.ProcessRegistrationResponse(x, ToUnixTimeMilliseconds(SystemClock.Instance.Now));
                    Console.WriteLine("Server ok: {0}", serverResp);
                    SaveDataStore(dataStore);
                }
            }
            else
            {
                Console.WriteLine("???");
            }

            Console.ReadLine();
            return;
        }
        public virtual void TestProcessRegistrationResponse_NoTransports()
        {
            mockDataStore.Setup(x => x.GetEnrollSessionData(SESSION_ID))
                .Returns(new EnrollSessionData(ACCOUNT_NAME, APP_ID_ENROLL, SERVER_CHALLENGE_ENROLL));
            var u2FServer = new U2FServerReferenceImpl(mockChallengeGenerator.Object, mockDataStore.Object, crypto,
                TRUSTED_DOMAINS);

            var registrationResponse = new RegisterResponse(REGISTRATION_DATA_BASE64, BROWSER_DATA_ENROLL_BASE64,
                SESSION_ID);
            u2FServer.ProcessRegistrationResponse(registrationResponse, 0L);

            var expectedKeyData = new SecurityKeyData(0L, KEY_HANDLE, USER_PUBLIC_KEY_ENROLL_HEX, VENDOR_CERTIFICATE, 0);
            mockDataStore.Verify(x => x.AddSecurityKeyData(ACCOUNT_NAME, expectedKeyData));
        }
        public virtual void TestProcessRegistrationResponse_NoTransports()
        {
            mockDataStore.Setup(x => x.GetEnrollSessionData(SESSION_ID))
            .Returns(new EnrollSessionData(ACCOUNT_NAME, APP_ID_ENROLL, SERVER_CHALLENGE_ENROLL));
            var u2FServer = new U2FServerReferenceImpl(mockChallengeGenerator.Object, mockDataStore.Object, crypto,
                                                       TRUSTED_DOMAINS);

            var registrationResponse = new RegisterResponse(REGISTRATION_DATA_BASE64, BROWSER_DATA_ENROLL_BASE64,
                                                            SESSION_ID);

            u2FServer.ProcessRegistrationResponse(registrationResponse, 0L);

            var expectedKeyData = new SecurityKeyData(0L, KEY_HANDLE, USER_PUBLIC_KEY_ENROLL_HEX, VENDOR_CERTIFICATE, 0);

            mockDataStore.Verify(x => x.AddSecurityKeyData(ACCOUNT_NAME, expectedKeyData));
        }
        public virtual void TestProcessRegistrationResponse2()
        {
            mockDataStore.Setup(x => x.GetEnrollSessionData(SESSION_ID))
            .Returns(new EnrollSessionData(ACCOUNT_NAME, APP_ID_ENROLL, SERVER_CHALLENGE_ENROLL));
            var trustedCertificates = new List <X509Certificate>();

            trustedCertificates.Add(VENDOR_CERTIFICATE);
            trustedCertificates.Add(TRUSTED_CERTIFICATE_2);
            mockDataStore.Setup(x => x.GetTrustedCertificates()).Returns(trustedCertificates);
            var u2FServer = new U2FServerReferenceImpl(mockChallengeGenerator.Object, mockDataStore.Object, crypto,
                                                       TRUSTED_DOMAINS);
            var registrationResponse = new RegisterResponse(REGISTRATION_DATA_2_BASE64, BROWSER_DATA_2_BASE64,
                                                            SESSION_ID);

            u2FServer.ProcessRegistrationResponse(registrationResponse, 0L);
            var expectedKeyData = new SecurityKeyData(0L, null, KEY_HANDLE_2, USER_PUBLIC_KEY_2, TRUSTED_CERTIFICATE_2,
                                                      0);

            mockDataStore.Verify(x => x.AddSecurityKeyData(ACCOUNT_NAME, expectedKeyData));
        }
        public virtual void TestProcessRegistrationResponse_OneTransport()
        {
            mockDataStore.Setup(x => x.GetEnrollSessionData(SESSION_ID))
                .Returns(new EnrollSessionData(ACCOUNT_NAME, APP_ID_ENROLL, SERVER_CHALLENGE_ENROLL));
            var trustedCertificates = new List<X509Certificate>();
            trustedCertificates.Add(TRUSTED_CERTIFICATE_ONE_TRANSPORT);
            mockDataStore.Setup(x => x.GetTrustedCertificates()).Returns(trustedCertificates);
            var u2FServer = new U2FServerReferenceImpl(mockChallengeGenerator.Object, mockDataStore.Object, crypto,
                TRUSTED_DOMAINS);

            var registrationResponse = new RegisterResponse(REGISTRATION_RESPONSE_DATA_ONE_TRANSPORT_BASE64,
                BROWSER_DATA_ENROLL_BASE64, SESSION_ID);
            u2FServer.ProcessRegistrationResponse(registrationResponse, 0L);

            var transports = new List<SecurityKeyDataTransports>();
            transports.Add(SecurityKeyDataTransports.BluetoothRadio);
            var expectedKeyData = new SecurityKeyData(0L, transports, KEY_HANDLE, USER_PUBLIC_KEY_ENROLL_HEX,
                TRUSTED_CERTIFICATE_ONE_TRANSPORT, 0);
            mockDataStore.Verify(x => x.AddSecurityKeyData(ACCOUNT_NAME, expectedKeyData));
        }
 public virtual void TestProcessRegistrationResponse2()
 {
     mockDataStore.Setup(x => x.GetEnrollSessionData(SESSION_ID))
         .Returns(new EnrollSessionData(ACCOUNT_NAME, APP_ID_ENROLL, SERVER_CHALLENGE_ENROLL));
     var trustedCertificates = new List<X509Certificate>();
     trustedCertificates.Add(VENDOR_CERTIFICATE);
     trustedCertificates.Add(TRUSTED_CERTIFICATE_2);
     mockDataStore.Setup(x => x.GetTrustedCertificates()).Returns(trustedCertificates);
     var u2FServer = new U2FServerReferenceImpl(mockChallengeGenerator.Object, mockDataStore.Object, crypto,
         TRUSTED_DOMAINS);
     var registrationResponse = new RegisterResponse(REGISTRATION_DATA_2_BASE64, BROWSER_DATA_2_BASE64,
         SESSION_ID);
     u2FServer.ProcessRegistrationResponse(registrationResponse, 0L);
     var expectedKeyData = new SecurityKeyData(0L, null, KEY_HANDLE_2, USER_PUBLIC_KEY_2, TRUSTED_CERTIFICATE_2,
         0);
     mockDataStore.Verify(x => x.AddSecurityKeyData(ACCOUNT_NAME, expectedKeyData));
 }
Exemple #9
0
        private static async Task TestNew2()
        {
            var hidFactory = Win32HidDeviceFactory.Instance;
            var keyFactory = new U2FHidKeyFactory(hidFactory);

            var dataStore = new InMemoryServerDataStore(new GuidSessionIdGenerator());
            LoadDataStore(dataStore);
            var server = new U2FServerReferenceImpl(
                new ChallengeGenerator(),
                dataStore,
                new BouncyCastleServerCrypto(),
                new[] {"http://example.com", "https://example.com"});

            var myClient = new U2FClient(
                new DummySender("http://example.com", new JObject()),
                keyFactory);

            Console.WriteLine("Register or Sign ? (r/s)");
            var mode = Console.ReadLine();

            if (mode == "s")
            {
                var signRequests = server.GetSignRequests("vbfox", "http://example.com");
                Console.WriteLine("Sign requests obtained ({0})", signRequests.Count);
                var cts = new CancellationTokenSource(TimeSpan.FromMinutes(10));
                var x = await myClient.Sign(signRequests, cts.Token);

                Console.WriteLine("Signature done {0}", x);
                if (x != null)
                {
                    var serverResp = server.ProcessSignResponse(x);
                    Console.WriteLine("Server ok: {0}", serverResp);
                    SaveDataStore(dataStore);
                }
            }
            else if (mode == "r")
            {
                var signRequests = server.GetSignRequests("vbfox", "http://example.com");
                var regRequest = server.GetRegistrationRequest("vbfox", "http://example.com");
                var cts = new CancellationTokenSource(TimeSpan.FromMinutes(10));
                var x = await myClient.Register(new[] { regRequest }, signRequests, cts.Token);

                Console.WriteLine("Authentication done {0}", x);
                if (x != null)
                {
                    var serverResp = server.ProcessRegistrationResponse(x, ToUnixTimeMilliseconds(SystemClock.Instance.Now));
                    Console.WriteLine("Server ok: {0}", serverResp);
                    SaveDataStore(dataStore);
                }
            }
            else
            {
                Console.WriteLine("???");
            }

            Console.ReadLine();
            return;
        }
Exemple #10
0
        async void EnrollClicked(object sender, RoutedEventArgs e)
        {
            var keyDict = new ConcurrentDictionary<IKeyId, bool>();
            textBox.Text = "";
            var hidFactory = new UwpHidDeviceFactory(Dispatcher);
            var keyFactory = new U2FHidKeyFactory(hidFactory);

            var dataStore = new InMemoryServerDataStore(new GuidSessionIdGenerator());
            var server = new U2FServerReferenceImpl(
                new ChallengeGenerator(),
                dataStore,
                new BouncyCastleServerCrypto(),
                new[] { "http://example.com", "https://example.com" });

            var myClient = new U2FClient(
                new DummySender("http://example.com", new JObject()),
                keyFactory);

            var signRequests = server.GetSignRequests("vbfox", "http://example.com");
            var regRequest = server.GetRegistrationRequest("vbfox", "http://example.com");
            var cts = new CancellationTokenSource(TimeSpan.FromMinutes(10));

            textBox.Text += "Register...\r\n";
            var x = await myClient.Register(new[] { regRequest }, signRequests, cts.Token);
            textBox.Text += "Register done, sending to server\r\n";

            var serverResp = server.ProcessRegistrationResponse(x, ToUnixTimeMilliseconds(SystemClock.Instance.Now));
            textBox.Text += "Server OK\r\n";
            textBox.Text += $"{serverResp}\r\n";
        }