示例#1
0
        public U2FDeviceKey([NotNull] U2FHidKey key)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            this.key = key;
        }
示例#2
0
        async Task <U2FHidKey> OpenDeviceAsync()
        {
            var hidDevice = await info.OpenDeviceAsync();

            try
            {
                return(await U2FHidKey.OpenAsync(hidDevice));
            }
            catch
            {
                hidDevice.Dispose();
                throw;
            }
        }
示例#3
0
        public static async Task <U2FHidKey> OpenAsync([NotNull] IHidDevice device, bool closeDeviceOnDispose = true)
        {
            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            var instance = new U2FHidKey(device, closeDeviceOnDispose);

            try
            {
                await instance.InitAsync();

                return(instance);
            }
            catch
            {
                instance.Dispose();
                throw;
            }
        }
示例#4
0
        public static async Task<U2FHidKey> OpenAsync([NotNull] IHidDevice device, bool closeDeviceOnDispose = true)
        {
            if (device == null) throw new ArgumentNullException(nameof(device));

            var instance = new U2FHidKey(device, closeDeviceOnDispose);
            try
            {
                await instance.InitAsync();
                return instance;
            }
            catch
            {
                instance.Dispose();
                throw;
            }
        }
示例#5
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();
            }
        }
示例#6
0
        public async Task <U2FHidKey> OpenAsync(CancellationToken cancellationToken = new CancellationToken())
        {
            var device = await HidDeviceInformation.OpenDeviceAsync();

            return(await U2FHidKey.OpenAsync(device));
        }