Open phiekl opened 3 months ago
ED25519 should now be supported by YKCS11.
Can you please set the YKCS11_DBG
environment variable to any value higher than 0, then run the ssh-keygen
command and post the output here?
Sure, this is after I generated an ed25519 key once more:
user@priv-yubi571:~/yubico-piv-tool/build$ tool/yubico-piv-tool -a status
Version: 5.7.1
Serial Number: 29173624
CHUID: No data available
CCC: No data available
Slot 9a:
Algorithm: ED25519
Subject DN: CN=SSH key
Issuer DN: CN=SSH key
Fingerprint: 105210594355ed93a62dcaff32b38a38d4fc2b904468cde4cecb51b4bfe8dc5d
Not Before: Aug 21 19:21:02 2024 GMT
Not After: Aug 21 19:21:02 2025 GMT
PIN tries left: 3
The output of YKCS11_DBG=9 ssh-keygen -D ykcs11/libykcs11.so -e
is found in ssh-keygen.1724268294.log
OK, I can re-produce the error.
As far as I can see, YKCS11 does return the correct key type, and the error message "skipping unsupported key type" seems to be produced by the ssh-key command, not YKCS11.
I did some googling and found, among others, this ticket that seems to indicate that OpenSSH does not support ED25519 via PKCS11: https://github.com/OpenSC/OpenSC/issues/2824. It's from last year but it references a PR with a patch that looks to be still open
Ohhh :unamused:
Well, I compiled that old referenced version and branch of openssh. I had to do that on debian 12 since it didn't really work with the openssl version in debian testing. Also recompiled yubico-piv-tool on that same system. No luck, but it outputs "C_GetAttributeValue failed: 18" instead of "skipping unsupported key type".
Here's the complete debug output: ssh-keygen.1724273754.log
diff to previous log file is basically:
-skipping unsupported key type
+DBG ykcs11.c:1834 (C_GetAttributeValue): In
+DBG objects.c:842 (get_puoa): For public key object 111, get
+DBG objects.c:931 (get_puoa): ID
+DBG objects.c:842 (get_puoa): For public key object 111, get
+DBG objects.c:1022 (get_puoa): EC_POINT
+DBG ykcs11.c:1871 (C_GetAttributeValue): Unable to get attribute 0x181 of object 111
+DBG objects.c:842 (get_puoa): For public key object 111, get
+DBG objects.c:1039 (get_puoa): EC_PARAMS
+DBG ykcs11.c:1871 (C_GetAttributeValue): Unable to get attribute 0x180 of object 111
+DBG ykcs11.c:1880 (C_GetAttributeValue): Out
+C_GetAttributeValue failed: 18
So, although YKCS11 supports ed25519 now, is there some way you could actually use with SSH?
I've done some tweaks. Can you try to build yubico-piv-tool from this branch and see if it works better with your patched OpenSSH? https://github.com/Yubico/yubico-piv-tool/tree/ed_ykcs11
I rebuilt it using
$ git log -1 --oneline
b0084c3 (HEAD -> ed_ykcs11, origin/ed_ykcs11) YKCS11: Return CKA_EC_PARAMS for ED keys
It seems to behave the same as before, unfortunately. ssh-keygen.1724325580.log
I guess we'll simply have to wait for the official support in openssh then.
Unrelated to this repo, but I forked and patched piv-go and yubikey-agent, and now I've got a working ssh setup using ed25519 keys in PIV mode. :grinning:
Thanks you for the tip. I'm glad you got it to work 😀
I have made another tweek to add support for another missing attribute. Also on this branch https://github.com/Yubico/yubico-piv-tool/tree/ed_ykcs11. Feel free to try it out and please let me know the result if you do.
Looks better!
$ ~/x/opt/bin/ssh-keygen -D ~/yubico-piv-tool/build/ykcs11/libykcs11.so -e
unknown certificate key type
failed to fetch key
unknown certificate key type
failed to fetch key
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICe0fEqZ23Qf5n95WIoSrDf4kfj4NHig+8JiCvKYwgwa Public key for PIV Authentication
ssh-rsa **snip** Public key for PIV Attestation
$ ~/x/opt/bin/ssh-keygen -D ~/yubico-piv-tool/build/ykcs11/libykcs11.so -e | grep ^ssh-ed25519 | sudo tee /root/.ssh/authorized_keys > /dev/null
$ ~/x/opt/bin/ssh -I ~/yubico-piv-tool/build/ykcs11/libykcs11.so root@localhost
unknown certificate key type
failed to fetch key
unknown certificate key type
failed to fetch key
sign_and_send_pubkey: signing failed for ED25519 "Public key for PIV Authentication": invalid argument
root@localhost: Permission denied (publickey).
with -vv you can see that it indeed tries to use the ed25519 key:
debug1: Next authentication method: publickey
debug1: Offering public key: Public key for PIV Authentication ED25519 SHA256:oAr/OaaY3YG21ztDVUEb05zAomYr+ETaNEJtiqkmgGo token
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: Public key for PIV Authentication ED25519 SHA256:oAr/OaaY3YG21ztDVUEb05zAomYr+ETaNEJtiqkmgGo token
debug1: identity_sign: sshkey_sign: invalid argument
sign_and_send_pubkey: signing failed for ED25519 "Public key for PIV Authentication": invalid argument
And with YKCS11_DBG=9: ssh.1724407670.log
Thank you for trying it out.
I'm afraid I'm not sure what the debug output after the PKCS11 session has ended mean. Does this mean that YKCS11 side of things now works with the patched version of OpenSSH? I am currently unable to test this setup here.
Yeah, it might mean that the YKCS11 part does work, and then it's simply the openssh patch that doesn't work all the way. While running pcscd in debug mode I'm noticing that it returns SW: 6A 80
during the signing operation, which is, AFAIK, an error code for "invalid parameter". I got the same code while using yubikey-agent prior to patching it properly.
What part returns SW: 6A 80
?
I combined the logs with timestamps and it seems like 6A 80 isn't related to "sign_and_send_pubkey: signing failed for ED25519 "Public key for PIV Authentication": invalid argument". I believe that error is related to the openssh patches. ssh_pcscd_combined.1724420566.log
OK. Thank you for looking into it.
In this case, we'll make sure to come out with a patch release soon. I'm sorry it won't help much with your issue but hopefully it'll work better in other settings
@aveenismail I tried your branch https://github.com/Yubico/yubico-piv-tool/tree/ed_ykcs11 in a different context - using https://github.com/latchset/pkcs11-provider - as I was running into the same Unable to get attribute 0x180
/ Unable to get attribute 0x181
. While the branch did get me past that, I ran into another issue:
[../src/objects.c:1071] p11prov_obj_find(): Error: 0x00000067; Failed to store object
[../src/objects.c:1077] p11prov_obj_find(): Find objects: found 1 objects; Returning 67
[../src/store.c:143] store_fetch(): Error: 0x00000067; Failed to load keys from slot (0)
After digging into it a bit more this appears to be because you're returning the raw public key here https://github.com/Yubico/yubico-piv-tool/blob/ed_ykcs11/ykcs11/openssl_utils.c#L699, while pkcs11-provider is expecting it to be a DER octet string with the tag and length, like what's done for EVP_PKEY_EC here: https://github.com/Yubico/yubico-piv-tool/blob/ed_ykcs11/ykcs11/openssl_utils.c#L686-L687. I tried a quick patch and it seemed to clear up that error, though I'm still running into other issues. I suspect they may not be ykcs11 issues, though I don't really understand what's going on yet.
@Pythoner6 Thank you for the report.
Can you please try the https://github.com/Yubico/yubico-piv-tool/tree/ed_ykcs11 branch again now? The encoding should be fixed now
Yep, that solves the failed to store issue!
Yep, that solves the failed to store issue!
Were you able to get past identity_sign: sshkey_sign: invalid argument
?
BR
Since #308 was merged yesterday, I figured YKCS11 would support ed25519 keys, but I can't get it to work.
And then semi-according to https://developers.yubico.com/PIV/Guides/SSH_with_PIV_and_PKCS11.html
At this point I expected an ed25519 public key to show up.
The same procedure works fine using ecdsa:
Are ed25519 keys simply not supported yet or did I do something wrong?