Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Robust, optional remembering of SSH passphrases
Existing logic for remembering SSH passphrases was extremely fragile and complicated due to SSH_ASKPASS not working on Windows, because we weren't detaching the process correctly. Now that we do detach correctly, we can get rid of the existing complicated machinery and replace it with something much simpler, more robust, and optional.

Previously we used GIT_SSH to intercept calls to SSH, then we'd preemptively start ssh-agent and add what we thought was the key the user would need to use. If that key was encrypted with a passphrase, we used an SSH_ASKPASS override (that worked for ssh-add, but not ssh, due to differing logic between them for when they would invoke SSH_ASKPASS).

Now we no longer set GIT_SSH, but rather rely solely on SSH_ASKPASS. If the passphrase prompt we're given looks like it's for a key file, then we ask the user for a passphrase and also ask if the passphrase should be remembered. If so, we run ssh-agent (if it's not already running) and persist the key, this time overriding SSH_ASKPASS to a different script that just outputs the passphrase.
  • Loading branch information
jcheng5 committed Nov 14, 2011
1 parent 0f3e804 commit 1d3a666
Show file tree
Hide file tree
Showing 20 changed files with 313 additions and 183 deletions.
16 changes: 15 additions & 1 deletion src/cpp/desktop/DesktopGwtCallback.cpp
Expand Up @@ -470,6 +470,8 @@ QVariant GwtCallback::promptForText(QString title,
QString caption,
QString defaultValue,
bool usePasswordMask,
QString rememberPasswordPrompt,
bool rememberByDefault,
bool numbersOnly,
int selectionStart,
int selectionLength)
Expand All @@ -479,6 +481,11 @@ QVariant GwtCallback::promptForText(QString title,
dialog.setCaption(caption);
if (usePasswordMask)
dialog.setEchoMode(QLineEdit::Password);
if (!rememberPasswordPrompt.isEmpty())
{
dialog.setRememberPasswordPrompt(rememberPasswordPrompt);
dialog.setRemember(rememberByDefault);
}
if (numbersOnly)
dialog.setNumbersOnly(true);
if (!defaultValue.isEmpty())
Expand All @@ -495,7 +502,14 @@ QVariant GwtCallback::promptForText(QString title,
}

if (dialog.exec() == QDialog::Accepted)
return QVariant(dialog.textValue());
{
QString value = dialog.textValue();
bool remember = dialog.remember();
QMap<QString, QVariant> values;
values.insert(QString::fromAscii("value"), value);
values.insert(QString::fromAscii("remember"), remember);
return values;
}
else
return QVariant();
}
Expand Down
2 changes: 2 additions & 0 deletions src/cpp/desktop/DesktopGwtCallback.hpp
Expand Up @@ -87,6 +87,8 @@ public slots:
QString caption,
QString defaultValue,
bool usePasswordMask,
QString rememberPasswordPrompt,
bool rememberByDefault,
bool numbersOnly,
int selectionStart,
int selectionLength);
Expand Down
22 changes: 19 additions & 3 deletions src/cpp/desktop/DesktopInputDialog.cpp
Expand Up @@ -41,7 +41,7 @@ QString InputDialog::caption()
return ui->label->text();
}

void InputDialog::setCaption(QString caption)
void InputDialog::setCaption(const QString& caption)
{
ui->label->setText(caption);
}
Expand All @@ -51,7 +51,7 @@ QString InputDialog::textValue()
return ui->lineEdit->text();
}

void InputDialog::setTextValue(QString value)
void InputDialog::setTextValue(const QString& value)
{
ui->lineEdit->setText(value);
}
Expand All @@ -65,7 +65,7 @@ void InputDialog::setSelection(int offset, int length)
ui->lineEdit->setSelection(offset, length);
}

void InputDialog::setOkButtonLabel(QString label)
void InputDialog::setOkButtonLabel(const QString& label)
{
pOK_->setText(label);
}
Expand All @@ -82,3 +82,19 @@ void InputDialog::setNumbersOnly(bool numbersOnly)
else
ui->lineEdit->setInputMask(QString());
}

void InputDialog::setRememberPasswordPrompt(const QString& prompt)
{
ui->remember->setVisible(!prompt.isEmpty());
ui->remember->setText(prompt);
}

void InputDialog::setRemember(bool remember)
{
ui->remember->setCheckState(Qt::Checked);
}

bool InputDialog::remember()
{
return ui->remember->checkState() == Qt::Checked;
}
10 changes: 7 additions & 3 deletions src/cpp/desktop/DesktopInputDialog.hpp
Expand Up @@ -30,13 +30,17 @@ class InputDialog : public QDialog
~InputDialog();

QString caption();
void setCaption(QString caption);
void setCaption(const QString& caption);
QString textValue();
void setTextValue(QString value);
void setTextValue(const QString& value);
void setSelection(int offset, int length);
void setOkButtonLabel(QString label);
void setOkButtonLabel(const QString& label);
void setEchoMode(QLineEdit::EchoMode mode);
void setNumbersOnly(bool numbersOnly);
void setRememberPasswordPrompt(const QString& prompt);

void setRemember(bool remember);
bool remember();

private:
Ui::InputDialog *ui;
Expand Down
7 changes: 7 additions & 0 deletions src/cpp/desktop/DesktopInputDialog.ui
Expand Up @@ -36,6 +36,13 @@
<item>
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QCheckBox" name="remember">
<property name="text">
<string>Remember</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down

0 comments on commit 1d3a666

Please sign in to comment.