Example #1
0
        private static void TestHardwareOnly()
        {
            var factory  = (IHidDeviceFactory)Win32HidDeviceFactory.Instance;
            var devices  = factory.FindAllAsync().Result;
            var fidoInfo = devices.Where(FidoU2FIdentification.IsFidoU2F).FirstOrDefault();

            Console.WriteLine("Devices found:");
            ShowDevices(devices);
            Console.WriteLine();

            if (fidoInfo == null)
            {
                Console.WriteLine("Can't find FIDO device :-(");
                Console.ReadLine();
                return;
            }

            Console.WriteLine(fidoInfo.Id);
            Console.WriteLine(fidoInfo.Manufacturer);
            Console.WriteLine(fidoInfo.Product);
            Console.WriteLine(fidoInfo.SerialNumber);
            Console.WriteLine("VID = 0x{0:X4}", fidoInfo.VendorId);
            Console.WriteLine("PID = 0x{0:X4}", fidoInfo.ProductId);

            using (var device = (Win32HidDevice)fidoInfo.OpenDeviceAsync().Result)
            {
                device.SetNumInputBuffers(64);
                var caps = device.Information.Capabilities;
                Console.WriteLine(caps.NumberFeatureButtonCaps);

                //Test(device);

                Console.WriteLine("Using high level API");

                var u2f = new U2FHidKey(device, false);

                var init = u2f.InitAsync().Result;

                var pongShort = u2f.Ping(Encoding.UTF8.GetBytes("Pong !!").Segment()).Result;
                WriteBuffer(pongShort);

                var pong =
                    u2f.Ping(
                        Encoding.UTF8.GetBytes(
                            "abcdefgh1-abcdefgh2-abcdefgh3-abcdefgh4-abcdefgh5-abcdefgh6-abcdefgh7-abcdefgh8-").Segment())
                    .Result;

                WriteBuffer(pong);

                if (init.Capabilities.HasFlag(U2FDeviceCapabilities.Wink))
                {
                    Console.WriteLine("Winking");
                    u2f.WinkAsync().Wait();
                }
                Console.ReadLine();
            }
        }
Example #2
0
        static U2FHidDeviceInfo InitDevice(Mock <IHidDevice> hid, U2FHidKey device)
        {
            // Setup
            var scenario = HidScenario.Build();
            var nonce    = new BytesHolder(8);

            scenario.Write(report => AssertWriteInitPacket(report.Data, 0xffffffff, U2FHidCommand.Init, nonce));
            scenario.Read(() => new HidInputReport(BuildInitPacket(
                                                       0xffffffff,
                                                       U2FHidCommand.Init,
                                                       nonce,
                                                       (uint)TestChannel,
                                                       (byte)1,
                                                       (byte)2,
                                                       (byte)3,
                                                       (byte)4,
                                                       (byte)U2FDeviceCapabilities.Wink)));

            scenario.Run(hid);
            var init = device.InitAsync().Result;

            scenario.End();
            return(init);
        }