Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a SSH agent option to use both Pageant and OpenSSH agent simultaneously in Windows #6288

Merged
merged 1 commit into from
Aug 22, 2021

Conversation

FischLu
Copy link
Contributor

@FischLu FischLu commented Mar 15, 2021

OpenSSH is already supported in Windows 10. In some situations, I really need to use both Pageant and OpenSSH agent at the same time. Therefore, I have modified the SSH Agent setting which is able to choice to use both agent simultaneously. As the result, the SSH key can be added/ removed from both agent by KeePassXC.

Screenshots

image

Testing strategy

  • Choose "use Pageant", lock and unlock database, SSH keys appear in Pageant. OpenSSH command ssh-add -L outputs nothing.
  • Choose "use OpenSSH", lock and unlock database, Pageant is empty. OpenSSH command ssh-add -L outputs SSH key list.
  • Choose "use both", lock and unlock database, SSH keys appear in Pageant. OpenSSH command ssh-add -L outputs SSH key list.

Type of change

  • ✅ New feature (change that adds functionality)

Possible issues

Currently, the stable OpenSSH version for Win10 is 7.7.2.1. However, I got error message agent returned different signature type ssh-rsa (expected rsa-sha2-512). when I use ssh.exe command to connect my server. The problem can be solved by updating OpenSSH to 8.1.0.0 Beta.

@droidmonkey
Copy link
Member

Why not just use both at all times and only error if we find neither?

@FischLu
Copy link
Contributor Author

FischLu commented Mar 15, 2021

This design gives users more choices, perhaps more secure? Maybe some windows users never use openssh agent, they may not realize that their keys have been added to the openssh agent. Although I'm not sure whether this can cause security issues.

@hifi
Copy link
Member

hifi commented Mar 17, 2021

There are already bridge solutions for Windows that allow you to forward requests to another agent. There's also implementations that provide most if not all of the common ones in the same software.

See https://github.com/buptczq/WinCryptSSHAgent for example for complete replacement.

@FischLu
Copy link
Contributor Author

FischLu commented Mar 17, 2021

There are already bridge solutions for Windows that allow you to forward requests to another agent. There's also implementations that provide most if not all of the common ones in the same software.

See https://github.com/buptczq/WinCryptSSHAgent for example for complete replacement.

I have spent hours on WinCryptSSHAgent, but I am not possible to use it to connect remote Linux via ssh, only WSL2 working.
Currently, the only working software for me is https://github.com/benpye/wsl-ssh-pageant

However, both WinCryptSSHAgent and wsl-ssh-pageant are identified as malware by Windows Security application, although it is maybe a problem for Windows itself.

If OpenSSH agent for Windows isn't implemented by KeepassXC, it is reasonable to use other software. Since both agent methods are already available, why not just simply provide a decision interface to users, and additional software is unneeded.

@droidmonkey
Copy link
Member

I am not a fan of the UI/UX of this change, we don't use radio lists (with exception to the TOTP setup dialog). Also the option for "both" is not necessary. Two checkboxes, one for Pageant and one for OpenSSH agent would be sufficient.

@FischLu
Copy link
Contributor Author

FischLu commented Mar 18, 2021

I am not a fan of the UI/UX of this change, we don't use radio lists (with exception to the TOTP setup dialog). Also the option for "both" is not necessary. Two checkboxes, one for Pageant and one for OpenSSH agent would be sufficient.

It is also a good idea, it just needs a little bit more logic control once both agent checkbox are unchecked, but "Enable SSH Agent integration" is checked. It's not complicated, i have created a new PR #6302 (comment) for such design.

@droidmonkey
Copy link
Member

You should just push the changes to this PR...

@FischLu FischLu closed this Mar 18, 2021
@FischLu FischLu reopened this Mar 18, 2021
@droidmonkey
Copy link
Member

Thank you

@FischLu
Copy link
Contributor Author

FischLu commented Mar 18, 2021

add a screenshot for changes

image

Copy link
Member

@hifi hifi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the changes requested you need to change isAgentRunning to check both agents separately and return false if either of them seems unreachable. We really don't want silent failures to happen more than they already do as it makes understanding problems even harder than it currently is.

We can merge this after fixing up the raised issues and if nothing comes up in testing as the changes are quite small and there have been multiple requests for something like this so it would be a workable middle ground.

Thanks.

@@ -120,30 +130,37 @@ bool SSHAgent::isAgentRunning() const
bool SSHAgent::sendMessage(const QByteArray& in, QByteArray& out)
{
#ifdef Q_OS_WIN
if (!useOpenSSH()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section needs to be rewritten.

It would probably clean this logic up a lot if the OpenSSH stuff is moved under a new function sendMessageOpenSSH which always exists and sendMessage only has the selection logic in. You also need to change it so that if either of them return false you return false immediately without calling the other so the error is handled properly by the caller.

You can also set an error and return false here if both agents are disabled as it's a configuration error and would otherwise be a silent fail.

Additionally run the format target of CMake to make sure the code adheres to the formatting standards we have.

@@ -449,7 +466,7 @@ void SSHAgent::databaseLocked(QSharedPointer<Database> db)

void SSHAgent::databaseUnlocked(QSharedPointer<Database> db)
{
if (!db || !isEnabled()) {
if (!db || !isEnabled() || (!useOpenSSH() && !usePageant())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wouldn't compile on any other platform than Windows. Though you could just remove this logic completely as we can return an error later, see previous comment.

@FischLu
Copy link
Contributor Author

FischLu commented Apr 1, 2021

isAgentRunning

In addition to the changes requested you need to change isAgentRunning to check both agents separately and return false if either of them seems unreachable. We really don't want silent failures to happen more than they already do as it makes understanding problems even harder than it currently is.

We can merge this after fixing up the raised issues and if nothing comes up in testing as the changes are quite small and there have been multiple requests for something like this so it would be a workable middle ground.

Thanks.

@hifi
In the function isAgentRunning , what should it returns in case both usePageant() and useOpenSSH() return false? For the case if we return false, then user will see an error message "No agent running, cannot add identity." during unlocking database, if "Enable SSH Agent" is checked and none of two agents check box is checked.

If return true for this case, the subsequent adding-key functions will be called. Though in the function SSHAgent::sendMessage, usePageant() and useOpenSSH() will be checked again, so not thing will happen actually.

@hifi
Copy link
Member

hifi commented Apr 3, 2021

If either of them return false you need to return false so the error is shown. We must not add any keys if either of them is unreachable and both enabled.

FischLu added a commit to FischLu/keepassxc that referenced this pull request Apr 3, 2021
@droidmonkey droidmonkey removed this from the v2.6.5 milestone Apr 4, 2021
@FischLu
Copy link
Contributor Author

FischLu commented Apr 9, 2021

I don't know why the last commit cannot build on Teamcity win10, I cannot see details, but it is fine on my win10 computer.

@droidmonkey
Copy link
Member

Just ignore we are having issues with that CI machine

@FischLu FischLu requested a review from hifi April 27, 2021 08:19
@droidmonkey
Copy link
Member

@hifi does this need more work or is it able to be merged?

@hifi
Copy link
Member

hifi commented Aug 9, 2021

SSHAgent::isAgentRunning() has some repeat but the changes look fine overall. 👍

@droidmonkey droidmonkey merged commit d2c7434 into keepassxreboot:develop Aug 22, 2021
@FischLu FischLu deleted the newSSH branch April 7, 2022 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants