Ejemplo n.º 1
0
 public void Close()
 {
     if (yk != IntPtr.Zero)
     {
         bool ret = YubiWrapper.yk_close_key(yk) == 1;
         if (!ret || YubiWrapper.yk_release() != 1)
         {
             throw new Exception("Error closing Yubikey");
         }
     }
 }
Ejemplo n.º 2
0
        private void OnFormLoad(object sender, EventArgs e)
        {
            ControlBox = false;

            progressBar.Maximum = 15;
            progressBar.Minimum = 0;
            progressBar.Value   = 15;

            yubi = new YubiWrapper();
            try
            {
                while (!yubi.Init())
                {
                    YubiPrompt   prompt = new YubiPrompt();
                    DialogResult res    = prompt.ShowDialog();
                    if (res != DialogResult.Retry)
                    {
                        RecoveryMode = prompt.RecoveryMode;
                        DialogResult = DialogResult.Abort;
                        return;
                    }
                }
            }
            catch (PlatformNotSupportedException err)
            {
                Debug.Assert(false);
                MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK);
                return;
            }
            //spawn background countdown timer
            countdown          = new Timer();
            countdown.Tick    += Countdown;
            countdown.Interval = 1000;
            countdown.Enabled  = true;

            keyWorker                     = new BackgroundWorker();
            keyWorker.DoWork             += YubiChallengeResponse;
            keyWorker.RunWorkerCompleted += KeyWorkerDone;
            keyWorker.RunWorkerAsync();
        }
Ejemplo n.º 3
0
        private void YubiChallengeResponse(object sender, DoWorkEventArgs e) //Should terminate in 15seconds worst case
        {
            //Send the challenge to yubikey and get response
            if (Challenge == null)
            {
                return;
            }

            if (yubiSlot == YubiSlot.AUTO)
            {
                //Code to automatically check which slot the hmac is setup
                YubiWrapper y = new YubiWrapper();
                if (y.Init())
                {
                    int ySlot = y.DetectSlot();
                    if (ySlot > 0)
                    {
                        yubiSlot = (YubiSlot)(ySlot);
                    }
                }
            }
            int slot = (int)yubiSlot;

            slot = 2;
            if (slot == 0)
            {
                MessageBox.Show("Error, no Challenge Response Config Detected", "Error");
                return;
            }
            success = yubi.ChallengeResponse(slot - 1, Challenge, out m_response);
            if (!success)
            {
                MessageBox.Show("Error getting response from Yubikey", "Error");
            }

            return;
        }