Exemple #1
0
        static void PrintPiv(string name)
        {
            Console.WriteLine($"[PIV] Device: {name}");

            if (!YubikeyPivManager.Instance.IsValidDevice(name))
            {
                Console.WriteLine("      Not a valid PIV device");
            }
            else
            {
                using (YubikeyPivDevice device = YubikeyPivManager.Instance.OpenDevice(name))
                {
                    Console.WriteLine($"      Version : {device.GetVersion()}");

                    byte[] chuid;
                    if (device.GetCHUID(out chuid))
                    {
                        Console.WriteLine($"      CHUID   : {BitConverter.ToString(chuid).Replace("-", "")}");
                    }
                    else
                    {
                        Console.WriteLine("      CHUID   : N/A");
                    }

                    Console.WriteLine($"      PinTries: {device.GetPinTriesLeft():N0}");

                    X509Certificate2 cert = device.GetCertificate9a();

                    if (cert != null)
                    {
                        Console.WriteLine($"      Cert 9A, Subject: {cert.SubjectName}");
                        Console.WriteLine($"               Issuer : {cert.IssuerName}");
                        Console.WriteLine($"               Start  : {cert.NotBefore.ToUniversalTime():O}");
                        Console.WriteLine($"               Expiry : {cert.NotAfter.ToUniversalTime():O}");
                        Console.WriteLine($"               Serial : {cert.SerialNumber}");
                        Console.WriteLine($"               Finger : {cert.Thumbprint}");
                    }
                    else
                    {
                        Console.WriteLine("      Cert 9A : N/A");
                    }
                }
            }

            Console.WriteLine();
        }