Exemplo n.º 1
0
 private void mUnlockButton_Clicked()
 {
     using (var dialog = new PassphraseDialog()) {
         dialog.Exec();
         if (dialog.Result == (int)QDialog.DialogCode.Rejected)
         {
             return;
         }
         var passphrase = dialog.GetPassphrase();
         try {
             mAgent.Unlock(passphrase);
         } catch (AgentLockedException) {
             QMessageBox.Critical(this, Tr("Error"), Tr("Agent is already locked"));
             Debug.Fail("Unlock button should have been disabled");
         } catch (AgentFailureException) {
             QMessageBox.Critical(this, Tr("Agent Failure"),
                                  Tr("Possible causes:") +
                                  "<ul>" +
                                  "<li>" + Tr("Passphrase was incorrect") + "</li>" +
                                  "<li>" + Tr("Agent is already unlocked") + "</li>" +
                                  "<li>" + Tr("Agent does not support locking") + "</li>" +
                                  "</ul>"
                                  );
         } catch (Exception ex) {
             Debug.Fail(ex.ToString());
         }
     }
     if (mAgent is Agent)
     {
         UpdateUIState();
     }
     else
     {
         ReloadData();
     }
 }
Exemplo n.º 2
0
 private void mUnlockButton_Clicked()
 {
     using (var dialog = new PassphraseDialog ()) {
     dialog.Exec ();
     if (dialog.Result == (int)QDialog.DialogCode.Rejected) {
       return;
     }
     var passphrase = dialog.GetPassphrase();
     try {
       mAgent.Unlock (passphrase);
     } catch (AgentLockedException) {
       QMessageBox.Critical (this, Tr("Error"), Tr("Agent is already locked"));
       Debug.Fail ("Unlock button should have been disabled");
     } catch (AgentFailureException) {
       QMessageBox.Critical (this, Tr("Agent Failure"),
                         Tr("Possible causes:") +
                         "<ul>" +
                         "<li>" + Tr("Passphrase was incorrect") + "</li>" +
                         "<li>" + Tr("Agent is already unlocked") + "</li>" +
                         "<li>" + Tr("Agent does not support locking") + "</li>" +
                         "</ul>"
       );
     } catch (Exception ex) {
       Debug.Fail (ex.ToString ());
     }
       }
       if (mAgent is Agent) {
     UpdateUIState ();
       } else {
     ReloadData ();
       }
 }
Exemplo n.º 3
0
 private void mAddButton_Clicked()
 {
     // TODO - persist start directory (and possibly viewMode)
       using (var dialog = new KeyFileDialog()) {
     dialog.SetDirectory (Environment.GetFolderPath(
                      Environment.SpecialFolder.Personal));
     dialog.Exec ();
     if (dialog.Result  == (int)QDialog.DialogCode.Accepted) {
       var constraints = dialog.GetConstraints ();
       foreach (var file in dialog.SelectedFiles) {
     try {
       KeyFormatter.GetPassphraseCallback passphraseCallback = () =>
       {
         var passphraseDialog = new PassphraseDialog();
         passphraseDialog.Exec();
         if (passphraseDialog.Result == (int)QDialog.DialogCode.Rejected) {
           return null;
         }
         using (var passphrase =
                new PinnedArray<byte>(passphraseDialog.GetPassphrase()))
         {
           var securePassphrase = new SecureString();
           foreach (var b in passphrase.Data) {
             securePassphrase.AppendChar((char)b);
           }
           return securePassphrase;
         }
       };
       mAgent.AddKeyFromFile (file, passphraseCallback, constraints);
     } catch (AgentFailureException) {
       QMessageBox.Critical (this,
                             Tr("Agent Failure"),
                             Tr("Possible causes:") +
                             "<ul>" + "</li>" +
                             "<li>" + Tr("Agent is locked") + "</li>" +
                             "<li>" + Tr("Agent does not support this key type") +
                             "</ul>");
     } catch (KeyFormatterException) {
       QMessageBox.Critical (this,
                             Tr("File format error"),
                             Tr("This file not a recognized private key file") +
                             "<br><br>" +
                             file);
     } catch (Exception ex) {
       Debug.Fail (ex.ToString ());
     }
       }
     }
       }
       if (mAgent is Agent) {
     UpdateUIState ();
       } else {
     ReloadData ();
       }
 }
Exemplo n.º 4
0
 private void mAddButton_Clicked()
 {
     // TODO - persist start directory (and possibly viewMode)
     using (var dialog = new KeyFileDialog()) {
         dialog.SetDirectory(Environment.GetFolderPath(
                                 Environment.SpecialFolder.Personal));
         dialog.Exec();
         if (dialog.Result == (int)QDialog.DialogCode.Accepted)
         {
             var constraints = dialog.GetConstraints();
             foreach (var file in dialog.SelectedFiles)
             {
                 try {
                     KeyFormatter.GetPassphraseCallback passphraseCallback = () =>
                     {
                         var passphraseDialog = new PassphraseDialog();
                         passphraseDialog.Exec();
                         if (passphraseDialog.Result == (int)QDialog.DialogCode.Rejected)
                         {
                             return(null);
                         }
                         using (var passphrase =
                                    new PinnedArray <byte>(passphraseDialog.GetPassphrase()))
                         {
                             var securePassphrase = new SecureString();
                             foreach (var b in passphrase.Data)
                             {
                                 securePassphrase.AppendChar((char)b);
                             }
                             return(securePassphrase);
                         }
                     };
                     mAgent.AddKeyFromFile(file, passphraseCallback, constraints);
                 } catch (AgentFailureException) {
                     QMessageBox.Critical(this,
                                          Tr("Agent Failure"),
                                          Tr("Possible causes:") +
                                          "<ul>" + "</li>" +
                                          "<li>" + Tr("Agent is locked") + "</li>" +
                                          "<li>" + Tr("Agent does not support this key type") +
                                          "</ul>");
                 } catch (KeyFormatterException) {
                     QMessageBox.Critical(this,
                                          Tr("File format error"),
                                          Tr("This file not a recognized private key file") +
                                          "<br><br>" +
                                          file);
                 } catch (Exception ex) {
                     Debug.Fail(ex.ToString());
                 }
             }
         }
     }
     if (mAgent is Agent)
     {
         UpdateUIState();
     }
     else
     {
         ReloadData();
     }
 }