Esempio n. 1
0
 private void mTableWidget_DropEvent(object aSender,
                                     QEventArgs <QDropEvent> aEventArgs)
 {
     if (aEventArgs.Event.MimeData.HasUrls)
     {
         foreach (var url in aEventArgs.Event.MimeData.Urls)
         {
             if (url.IsLocalFile)
             {
                 var localFile = url.ToLocalFile();
                 if (File.Exists(localFile))
                 {
                     try {
                         mAgent.AddKeyFromFile(localFile, null, null);
                     } catch (Exception ex) {
                         Debug.Fail(ex.ToString());
                     }
                 }
             }
         }
         aEventArgs.Event.AcceptProposedAction();
         aEventArgs.Handled = true;
         if (mAgent is AgentClient)
         {
             ReloadData();
         }
     }
 }
Esempio n. 2
0
        protected void OnMAddButtonClicked(object sender, EventArgs e)
        {
            // TODO - fix strings
            var dialog = new Gtk.FileChooserDialog(
                "Select private key files",
                null,
                FileChooserAction.Open,
                "Cancel", ResponseType.Cancel,
                "Open", ResponseType.Accept);

            dialog.SelectMultiple = true;
            var response = (ResponseType)dialog.Run();

            if (response == ResponseType.Accept)
            {
                foreach (var file in dialog.Filenames)
                {
                    try {
                        mAgent.AddKeyFromFile(file, null, null);
                    } catch (Exception ex) {
                        Debug.Fail(ex.ToString());
                    }
                }
            }
            dialog.Destroy();
            if (!(mAgent is Agent))
            {
                ReloadKeyListView();
            }
        }
Esempio n. 3
0
 public static void AddKeysFromFiles(this IAgent agent, string[] fileNames,
                                     ICollection <Agent.KeyConstraint> constraints = null)
 {
     KeyFormatter.GetPassphraseCallback getPassword = null;
     foreach (var fileName in fileNames)
     {
         try {
             try {
                 // try using the previous passphrase
                 if (getPassword == null)
                 {
                     throw new Exception("No previous passphrase.");
                 }
                 agent.AddKeyFromFile(fileName, constraints, getPassword);
             } catch {
                 // if the previous passphrase does not work, ask for a new passphrase
                 getPassword = PasswordCallbackFactory(
                     string.Format(Strings.msgEnterPassphrase, Path.GetFileName(fileName)));
                 agent.AddKeyFromFile(fileName, constraints, getPassword);
             }
         } catch (PpkFormatterException) {
             MessageBox.Show(string.Format(
                                 "Error opening file '{0}'\n" +
                                 "Possible causes:\n" +
                                 "\n" +
                                 "- Passphrase was entered incorrectly\n" +
                                 "- File is corrupt",
                                 fileName), Util.AssemblyTitle, MessageBoxButtons.OK,
                             MessageBoxIcon.Error);
         } catch (AgentNotRunningException) {
             MessageBox.Show("Could not add key because no SSH agent was found." +
                             " Please make sure your SSH agent program is running (e.g. Pageant).",
                             Util.AssemblyTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
         } catch (Exception ex) {
             MessageBox.Show(string.Format(Strings.errFileOpenFailed,
                                           fileName, ex.Message), Util.AssemblyTitle, MessageBoxButtons.OK,
                             MessageBoxIcon.Error);
         }
         // TODO may want to return ICollection<ISshKey> with added keys
         // to be more like other Add* methods
     }
 }
Esempio n. 4
0
 public static ISshKey AddKeyFromFile(this IAgent agent, string fileName,
                                      ICollection <Agent.KeyConstraint> constraints,
                                      KeyFormatter.GetPassphraseCallback getPassword = null)
 {
     if (getPassword == null)
     {
         getPassword = PasswordCallbackFactory(
             string.Format(Strings.msgEnterPassphrase, Path.GetFileName(fileName)));
     }
     return(agent.AddKeyFromFile(fileName, getPassword, constraints));
 }