Example #1
0
        private void RefreshInsertedKeyInfo()
        {
            string devName   = YubikeyPivManager.Instance.ListDevices().FirstOrDefault();
            bool   hasDevice = !string.IsNullOrEmpty(devName);

            foreach (Control control in gbInsertedYubikey.Controls)
            {
                if (control.Name.StartsWith("lbl"))
                {
                    control.Visible = hasDevice;
                }
            }

            if (!hasDevice)
            {
                return;
            }

            lblAlreadyEnrolled.Visible = _hasBeenEnrolled;

            using (YubikeyPivDevice dev = YubikeyPivManager.Instance.OpenDevice(devName))
            {
                string serial = dev.GetSerialNumber().ToString();

                var  yi      = new YubikeyInfo();
                bool success = yi.GetYubikeyInfo(serial);

                /* Get currently only CCID enabled Yubikeys
                 * if (HasCcid)
                 *  lblInsertedMode.ForeColor = Color.Black;
                 * else
                 *  lblInsertedMode.ForeColor = Color.Red;
                 */
                lblInsertedTyp.Text      = yi.devicetype;
                lblInsertedSerial.Text   = yi.serial;
                lblInsertedMode.Text     = yi.usbinterface;
                lblInsertedFirmware.Text = yi.firmware;
            }
        }
Example #2
0
        private void RefreshInsertedKey()
        {
            List <string> listDevices = YubikeyPivManager.Instance.ListDevices().ToList();
            string        devName     = listDevices.FirstOrDefault();
            bool          hasDevice   = !string.IsNullOrEmpty(devName);

            foreach (Control control in gbInsertedKey.Controls)
            {
                if (control.Name.StartsWith("lbl"))
                {
                    control.Visible = (hasDevice);
                }
            }

            if (hasDevice)
            {
                using (YubikeyPivDevice dev = YubikeyPivManager.Instance.OpenDevice(devName))
                {
                    int serialNumber = (int)dev.GetSerialNumber();   // uint
                    var yi           = new YubikeyInfo();
                    yi.GetYubikeyInfo(serialNumber.ToString());
                    lblDevType.Text                 = yi.devicetype;
                    lblInsertedSerial.Text          = yi.serial;
                    lblInsertedFirmware.Text        = yi.firmware;
                    lblInsertedMode.Text            = yi.usbinterface;
                    lblInsertedHasBeenEnrolled.Text = _dataStore.Search(serialNumber).Any().ToString();
                }
            }

            if (listDevices.Count > 1)
            {
                lblMultipleKeys.Text = $"{listDevices.Count:N0} keys inserted";
            }
            else
            {
                lblMultipleKeys.Text = "";
            }
        }
Example #3
0
        private void RefreshInsertedKey()
        {
            List <string> listDevices = YubikeyPivManager.Instance.ListDevices().ToList();
            string        devName     = listDevices.FirstOrDefault();
            bool          hasDevice   = !string.IsNullOrEmpty(devName);

            foreach (Control control in gbInsertedKey.Controls)
            {
                if (control.Name.StartsWith("lbl"))
                {
                    control.Visible = (hasDevice);
                }
            }

            if (hasDevice)
            {
                using (YubikeyPivDevice dev = YubikeyPivManager.Instance.OpenDevice(devName))
                {
                    int serialNumber = (int)dev.GetSerialNumber();   // uint
                    var yi           = new YubikeyInfo();
                    yi.GetYubikeyInfo(serialNumber.ToString());
                    lblDevType.Text          = yi.devicetype;
                    lblInsertedSerial.Text   = yi.serial;
                    lblInsertedFirmware.Text = yi.firmware;
                    lblInsertedMode.Text     = yi.usbinterface;

                    X509Certificate2 cert  = null;  //Standard Cert
                    X509Certificate2 cert2 = null;  //Admin Cert



                    _hasBeenEnrolled = _dataStore.Search((int)dev.GetSerialNumber()).Any();


                    cert  = dev.GetCertificate9a();
                    cert2 = dev.GetCertificate9d();

                    if ((cert != null || cert2 != null) && _hasBeenEnrolled == true)
                    {
                        lblInsertedHasBeenEnrolled.Text      = "Enrolled!";
                        lblInsertedHasBeenEnrolled.ForeColor = Color.Green;
                    }
                    else if ((cert != null || cert2 != null) && _hasBeenEnrolled == false)
                    {
                        lblInsertedHasBeenEnrolled.Text      = "YubiKey is not empty!";
                        lblInsertedHasBeenEnrolled.ForeColor = Color.Red;
                    }
                    else if ((cert == null || cert2 == null) && _hasBeenEnrolled == true)
                    {
                        lblInsertedHasBeenEnrolled.Text      = "YubiKey is empty! Please revoke Certificate!";
                        lblInsertedHasBeenEnrolled.ForeColor = Color.Red;
                    }
                    else if ((cert == null || cert2 == null) && _hasBeenEnrolled == false)
                    {
                        lblInsertedHasBeenEnrolled.Text      = "YubiKey can be enrolled!";
                        lblInsertedHasBeenEnrolled.ForeColor = Color.DarkOrange;
                    }
                }
            }

            if (listDevices.Count > 1)
            {
                lblMultipleKeys.Text    = $"{listDevices.Count:N0} keys inserted";
                btnResetYubiKey.Enabled = false;
                btnViewCert.Enabled     = false;
                btnEnableCCID.Enabled   = false;
                btnExportCert.Enabled   = false;
                tsbEnroll.Enabled       = false;
                tsbAbout.Enabled        = false;
                tsbSettings.Enabled     = false;
            }
            else
            {
                lblMultipleKeys.Text = "";
            }
        }
Example #4
0
        private void RefreshInsertedKeyInfo()
        {
            string devName   = YubikeyPivManager.Instance.ListDevices().FirstOrDefault();
            bool   hasDevice = !string.IsNullOrEmpty(devName);

            foreach (Control control in gbInsertedYubikey.Controls)
            {
                if (control.Name.StartsWith("lbl"))
                {
                    control.Visible = hasDevice;
                }
            }

            if (!hasDevice)
            {
                return;
            }

            using (YubikeyPivDevice dev = YubikeyPivManager.Instance.OpenDevice(devName))
            {
                X509Certificate2 cert  = null;  //Standard Cert
                X509Certificate2 cert2 = null;  //Admin Cert

                cert  = dev.GetCertificate9a();
                cert2 = dev.GetCertificate9d();

                if ((cert != null || cert2 != null) && _hasBeenEnrolled == true)
                {
                    lblAlreadyEnrolled.Text      = "Enrolled!";
                    lblAlreadyEnrolled.ForeColor = Color.Green;
                }
                else if ((cert != null || cert2 != null) && _hasBeenEnrolled == false)
                {
                    lblAlreadyEnrolled.Text      = "YubiKey is not empty!";
                    lblAlreadyEnrolled.ForeColor = Color.Red;
                }
                else if ((cert == null || cert2 == null) && _hasBeenEnrolled == true)
                {
                    lblAlreadyEnrolled.Text      = "YubiKey is empty! Please revoke Certificate!";
                    lblAlreadyEnrolled.ForeColor = Color.Red;
                }
                else if ((cert == null || cert2 == null) && _hasBeenEnrolled == false)
                {
                    lblAlreadyEnrolled.Text      = "YubiKey can be enrolled!";
                    lblAlreadyEnrolled.ForeColor = Color.DarkOrange;
                }
            }

            using (YubikeyPivDevice dev = YubikeyPivManager.Instance.OpenDevice(devName))
            {
                string serial = dev.GetSerialNumber().ToString();

                var  yi      = new YubikeyInfo();
                bool success = yi.GetYubikeyInfo(serial);

                /* Get currently only CCID enabled Yubikeys
                 * if (HasCcid)
                 *  lblInsertedMode.ForeColor = Color.Black;
                 * else
                 *  lblInsertedMode.ForeColor = Color.Red;
                 */
                lblInsertedTyp.Text      = yi.devicetype;
                lblInsertedSerial.Text   = yi.serial;
                lblInsertedMode.Text     = yi.usbinterface;
                lblInsertedFirmware.Text = yi.firmware;
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            // PIV
            List <string> devices = YubikeyPivManager.Instance.ListDevices(false).ToList();

            Console.WriteLine($"[PIV] Found {devices.Count:N0} devices");

            foreach (string device in devices)
            {
                PrintPiv(device);
            }

            bool   success;
            bool   ccid, otp, fido;
            string errmsg;
            string serial;
            string mode;

            YubmanConsole.setYKManPath(@"E:\proj\EnrollmentStation-master\EnrollmentStation\bin\Release\Binaries\YubikeyManager\ykman.exe", @"E:\proj\EnrollmentStation-master\EnrollmentStation\bin\Release\Binaries\YubikeyManager");

            // Using XKMAN Tool
            Console.WriteLine($"[YKMAN] Cmdline {YubmanConsole.Cmdline}");
            Console.WriteLine($"[YKMAN] CmdWorkDir {YubmanConsole.Workdir}");

            var y = new YubmanUtil();

            int ybdevcount = y.CheckYubikeyPresent();

            Console.WriteLine($"[YKMAN] Yubikey present: {ybdevcount}");

            if (ybdevcount >= 1)
            {
                if (y.GetFirstorDefaultYubikeySerial(out serial))
                {
                    Console.WriteLine($"[YKMAN] First Serial is: {serial}");
                }
            }

            bool present = y.CheckOneYubikeyPresent(out errmsg);

            Console.WriteLine($"[YKMAN] One Yubikey present: {present} {errmsg}");

            if (present)
            {
                success = y.GetYubikeySerial(out serial);
                Console.WriteLine($"[YKMAN] Serial : {serial}");
                mode = y.GetYubikeyMode(serial);
                Console.WriteLine($"[YKMAN] Current Mode : {mode}");
                success = y.GetYubikeyMode(serial, out otp, out ccid, out fido, out mode);
                Console.WriteLine($"[YKMAN] Current Mode : {mode} OTP:{otp} CCID {ccid} FIDO:{fido}");
            }
            else
            {
                if (!(string.IsNullOrEmpty(errmsg)) && (errmsg.Contains("Multiple Yubikeys found")))
                {
                    Console.WriteLine("Multiple Yubikeys found");
                    success = y.ListYubikey(out string info);
                    success = y.GetYubikeySerial(out serial);
                    StringReader strReader1 = new StringReader(info);
                    StringReader strReader2 = new StringReader(serial);
                    string       devtype, devserial = null;
                    int          devnr = 0;
                    while (true)
                    {
                        devtype   = strReader1.ReadLine();
                        devserial = strReader2.ReadLine();
                        if ((devtype != null) && (devserial != null))
                        {
                            devnr++;
                            Console.WriteLine($"Device: {devnr}");
                            Console.WriteLine($"Type  : {devtype}");
                            Console.WriteLine($"Serial: {devserial}");
                            Console.WriteLine($"Mode  : {y.GetYubikeyMode(devserial)}\r\n");
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            string[] serialnumbers;

            success = y.GetYubikeySerial(out serialnumbers);
            if (success)
            {
                foreach (string s in serialnumbers)
                {
                    var yi = new YubikeyInfo();
                    yi.GetYubikeyInfo(s);
                    yi.print();
                    Console.WriteLine();
                }
            }
        }