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

libykcs11 fails to load key into Windows 11 native ssh-agent #527

Open
jplejacq-quoininc-com opened this issue Jan 8, 2025 · 7 comments

Comments

@jplejacq-quoininc-com
Copy link

OS: Windows 11 Pro 24H2
openssh: OpenSSH_for_Windows_9.5p1, LibreSSL 3.8.2 (native package that is part of Windows)
libykcs11: Yubico.Piv-Tool 2.5.1
opensc-pkcs11.dll: OpenSC.OpenSC 0.23.0.0

If I follow the instructions provided by Yubico [1] or the substantially better instructions provided by [2], I always get the following error:

> ssh-add -v -v -v -s "C:\Program Files\Yubico\Yubico PIV Tool\bin\libykcs11.dll"
Enter passphrase for PKCS#11:
Could not add card "C:\Program Files\Yubico\Yubico PIV Tool\bin\libykcs11.dll": agent refused operation

The Window event log show two messages:

ssh-pkcs11-helper: error: dlopen C:/Program Files/Yubico/Yubico PIV Tool/bin/libykcs11.dll failed: The specified module could not be found.
ssh-agent: error: process_add_smartcard_key: failed to add key to store. count:-1

I tried numerous variations on forward/backward slashes for directory separators. I always get the same result. The path is correct as well as the permissions.

The Windows native ssh works fine with libykcs11.dll, it's only ssh-add that fails.

ssh-add works fine with OpenSC library, opensc-pkcs11.dll.

[1] https://support.yubico.com/hc/en-us/articles/360021606180-Using-YubiKey-PIV-with-Windows-native-SSH-client
[2] https://gist.github.com/daemonhorn/a6af1b76457b2c10b8058d0a2c919bc3

@wampum
Copy link

wampum commented Jan 13, 2025

I get the same output / error as you with an invalid path to libykcs11.dll.

My guess is that you have installed the x86 32 bit version of yubico-piv-tool. If not, the dll is probably installed somewhere non-standard

@jplejacq-quoininc-com
Copy link
Author

jplejacq-quoininc-com commented Jan 13, 2025 via email

@ian-harwood
Copy link

ian-harwood commented Jan 15, 2025

I hit the same problem. The fix for me was to put C:\Program Files\Yubico\Yubico PIV Tool\bin on the System Path, not the User Path. It also needs to be ahead of %SYSTEMROOT%\System32\OpenSSH\ on the System Path.

Restart the OpenSSH Authentication Agent service after updating the System Path.

@aveenismail
Copy link
Member

The YKCS11 module has dependency on libykpiv and libcrypto, so they both need to be in PATH for the YKCS11 to work. The easiest solution is the one @ian-harwood wrote.

@jplejacq-quoininc-com
Copy link
Author

jplejacq-quoininc-com commented Jan 15, 2025 via email

@aveenismail
Copy link
Member

aveenismail commented Jan 16, 2025

I see two occurrences of C:\Program Files\FireDaemon OpenSSL 3\bin before the Yubico PIV Tool path in the output of $env:Path. From what I can tell, it looks like FireDaemon OpenSSL would have a libcrypto.dll. The Yubico PIV Tool is shipped with the libcrypto.dll it depends on. So if the libcrypto.dll in C:\Program Files\FireDaemon OpenSSL 3\bin has a different version than the one on C:\Program Files\Yubico\Yubico PIV Tool\bin, this could cause a clash that causes ykcs11 not finding the right dependency since only the first libcrypto in the path gets loaded.

Can we try the following two workarounds to see if my theory that it's about the libcrypto version is correct or if we're looking in the wrong direction?

1- Navigate to C:\Program Files\Yubico\Yubico PIV Tool\bin then run the ssh-add command from there as follows
ssh-add -v -v -v -s ./libykcs11.dll

2- Put C:\Program Files\Yubico\Yubico PIV Tool\bin first in the path, then run the ssh-add command the way it is in the question of the issue.

@jplejacq-quoininc-com
Copy link
Author

jplejacq-quoininc-com commented Jan 16, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants