public virtual void Setup()
		{
		    mockU2FKey = new Mock<IU2FKey>(MockBehavior.Strict);
		    mockU2FServer = new Mock<IU2FServer>(MockBehavior.Strict);
		    mockOriginVerifier = new Mock<IOriginVerifier>(MockBehavior.Strict);
		    mockChannelIdProvider = new Mock<IChannelIdProvider>(MockBehavior.Strict);

		    var mockClock = new Mock<IClock>(MockBehavior.Strict);
		    mockClock.Setup(x => x.Now).Returns(Instant.FromMillisecondsSinceUnixEpoch(0));
            u2FClient = new U2FClientReferenceImpl(BouncyCastleClientCrypto.Instance, mockOriginVerifier.Object,
                mockChannelIdProvider.Object, mockU2FServer.Object, mockU2FKey.Object, mockClock.Object);

		    mockChannelIdProvider.Setup(x => x.GetJsonChannelId()).Returns(CHANNEL_ID_JSON);
		}
Exemplo n.º 2
0
        private static void TestSoftwareOnly()
        {
            var key = new U2FKeyReferenceImpl(
                TestVectors.VENDOR_CERTIFICATE,
                TestVectors.VENDOR_CERTIFICATE_PRIVATE_KEY,
                new TestKeyPairGenerator(),
                new GuidKeyHandleGenerator(),
                new InMemoryKeyDataStore(),
                new ConsolePresenceVerifier(),
                new BouncyCastleKeyCrypto());

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

            var client = new U2FClientReferenceImpl(
                BouncyCastleClientCrypto.Instance,
                new SimpleOriginVerifier(new[] {"http://example.com", "https://example.com"}),
                new ChannelProvider(),
                server,
                key,
                SystemClock.Instance);

            client.Register("http://example.com", "vbfox");
            client.Authenticate("http://example.com", "vbfox");
            Console.WriteLine("Done.");
            Console.ReadLine();
        }
Exemplo n.º 3
0
        private static async Task TestDual()
        {
            var hidFactory = Win32HidDeviceFactory.Instance;
            var keyFactory = new U2FHidKeyFactory(hidFactory);
            var keyIds = await keyFactory.FindAllAsync();
            var keyId = keyIds.First();
            using (var u2f = await keyId.OpenAsync())
            {
                var key = new U2FDeviceKey(u2f);

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

                var client = new U2FClientReferenceImpl(
                    BouncyCastleClientCrypto.Instance,
                    new SimpleOriginVerifier(new[] {"http://example.com", "https://example.com"}),
                    new ChannelProvider(),
                    server,
                    key,
                    SystemClock.Instance);

                LoadDataStore(dataStore);
                //client.Register("http://example.com", "vbfox");
                //SaveDataStore(dataStore);

                client.Authenticate("http://example.com", "vbfox");
                SaveDataStore(dataStore);
            }

            Console.WriteLine("Done.");
            Console.ReadLine();
        }
Exemplo n.º 4
0
        private static async Task TestNew()
        {
            var hidFactory = Win32HidDeviceFactory.Instance;
            var keyFactory = new U2FHidKeyFactory(hidFactory);
            var keyIds = await keyFactory.FindAllAsync();
            var keyId = keyIds.First();

            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()),
                (o, a, ct) => Task.FromResult(true),
                (o, a, ct) => Task.FromResult(true),
                keyFactory,
                BouncyCastleClientCrypto.Instance);

            var signRequests = server.GetSignRequests("vbfox", "http://example.com");

            var x = await myClient.Sign(signRequests, CancellationToken.None);
            return;


            var origin = "http://example.com";
            var channelId = new JObject();

            

            var requestAndClientDatas = signRequests
                .Select(signRequest =>
                {
                    string clientDataB64;
                    var authRequest = U2FClientReferenceImpl.SignRequestToAuthenticateRequest("http://example.com", signRequest, new JObject(),
                        out clientDataB64, BouncyCastleClientCrypto.Instance);
                    return Tuple.Create(signRequest, clientDataB64, authRequest);
                })
                .ToList();

            new U2FClient(
                new DummySender("http://example.com", new JObject()),
                (o, a, ct) => Task.FromResult(true),
                (o, a, ct) => Task.FromResult(true),
                keyFactory,
                BouncyCastleClientCrypto.Instance);



            using (var u2f = await keyId.OpenAsync())
            {
                var key = new U2FDeviceKey(u2f);



                var client = new U2FClientReferenceImpl(
                    BouncyCastleClientCrypto.Instance,
                    new SimpleOriginVerifier(new[] { "http://example.com", "https://example.com" }),
                    new ChannelProvider(),
                    server,
                    key,
                    SystemClock.Instance);

                
                //client.Register("http://example.com", "vbfox");
                //SaveDataStore(dataStore);

                client.Authenticate("http://example.com", "vbfox");
                SaveDataStore(dataStore);
            }

            Console.WriteLine("Done.");
            Console.ReadLine();
        }