-
Notifications
You must be signed in to change notification settings - Fork 18
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
Support EcDSA Keys with Named Curves #47
base: master
Are you sure you want to change the base?
Conversation
Hi, Great work! First, please do not mark as fix #17 as I already explained to you that the problem there was the existence of EC certificate which caused the RSA certificates not to be accepted. Please refactor/rename the entire struct keyinfo_s;
typedef struct keyinfo_s *keyinfo;
struct key_data_list_s {
struct key_data_list_s *next;
char *type;
char *value;
}
keyinfo keyinfo_new();
void keyinfo_free(keyinfo keyinfo);
int keyinfo_get_type(keyinfo keyinfo);
int keyinfo_from_der(keyinfo keyinfo, unsigned char *der, size_t len);
gcry_sexp_t *keyinfo_to_sexp(keyinfo keyinfo);
key_data_list *keyinfo_get_key_data(keyinfo keyinfo);
void key_data_free(key_data_list list); What do you think? This way we focus in the key logic within the Thank you for your help! |
I'm not sure I understand the |
all that needed in order to provide the key to assuan socket without the code that within For RSA (and current implementation) it will be: - type: KEY-DATA
value: hex(n)
- type: KEY-DATA
value: hex(e) Not sure how we transmit the key type, but what I would like to achieve is a |
I refactored the code. |
@alonbl I'm trying to add I'm guessing that something similar needs to be done for EcDSA for |
Based on some postings I found online, it looks like the "KEY-DATA" for "q" (as hex-encoded integer) and "curve" as DER-encoded OID (minus tag) is what's needed. |
This functionality is almost entirely working:
|
I think the remaining issues are with In |
You will need to reverse engineer gnupg own scd and see what you get for each case. As there is no formal spec for the IPC this is the only way to make it work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
In order to push this forward, please prepare a set of pull requests of cleanups, each per something we can quickly merge, so that it will be simpler to digest the remaining EC only related additions.
@@ -30,6 +30,7 @@ | |||
|
|||
#include "common.h" | |||
#include "strgetopt.h" | |||
#include <pkcs11-helper-1.0/pkcs11.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this for things like CKR_OK
because it wasn't clear it would otherwise be included.
} | ||
|
||
if (_pkcs11_keyinfo_mechanism(keyinfo, &pkcs11_mechanism) != CKR_OK) { | ||
goto cleanup; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please focus in EC in this thread, any other change such as rename of the variables or modifying any behavior should go to other pull request.
In this case you assume that the problem is something within the token to select the hash, while as far as I remember the gnupg is the one that decides in some cases to pass the entire blob forcing us to guess what hash did he wish use to use.
anyway, in order to discuss it better please move this into other pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean.
The highlighted change is regarding selecting the mechanism for asking the PKCS#11 module to sign using the correct mechanism, as well as ensuring PKCS padding is only used when using (CKM_RSA_PKCS
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I do not understand the code, this is why it is better to do this in steps each change own pull request...
gnupg provides data which may or may not include the hash packaging, the fixup should be done in any case.
you assume that this fixup should be done only if key type is rsa, correct? have you looked at the scd sources to see if this is correct and hash never provided in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The encoding specified by PKCS#1 would only be there for RSA -- EcDSA keys simply aren't large enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't ec also signs hashes? as far as I know it does. how will the peer know what hash was used in the signature? the hash name/oid must be signed as well for this to be secure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EcDSA keys for NIST P-256 are 33 bytes (257 bits) long (in compressed mode) with 64 byte signatures.
The CKM_ECDSA
mechanism expects the input to already be hashed (https://www.cryptsoft.com/pkcs11doc/v220/group__SEC__12__3__6__ECDSA__WITHOUT__HASHING.html) and encoded to fit within 2*keyLength.
The padding/encoding for PKCS#1 isn't needed since the keys are so much smaller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the digest algorithm id is not signed then I may modify the digest id in the unauthenticated message to less secure digest that its value matches the more secure so validate process will validate less secure digest without being aware of the switch. anyway, it is not that important as long as if you sign the gnupg peer will be able to verify.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code now removes any found prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @rkeene, having support for ec25519/ecdsa keys would be really awesome.
I'm almost done with this. |
use_pkcs1 = 1; | ||
break; | ||
case CKM_ECDSA: | ||
use_pkcs1 = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need this variable? can't you ask below if mechanism is RSA_PKCS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future there may be other mechanisms that do or do not use PKCS#1 padding.
} | ||
|
||
if (_pkcs11_keyinfo_mechanism(keyinfo, &pkcs11_mechanism) != CKR_OK) { | ||
goto cleanup; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I do not understand the code, this is why it is better to do this in steps each change own pull request...
gnupg provides data which may or may not include the hash packaging, the fixup should be done in any case.
you assume that this fixup should be done only if key type is rsa, correct? have you looked at the scd sources to see if this is correct and hash never provided in this case?
I'm making progress here, creating subkeys is working but signing is not yet working.
There are bugs in GPG when dealing with EcDSA keys that reside on cards. |
there usually are... very frustrating to chase non-standard non-cooperative undocumented unstable proprietary non-modular project to provide standard interface. thank your help, in the meanwhile I think you have done many good cleanups, if we review them one by one we may reach to a point in which the EC part will be left more or less ready until gnupg support will be sorted out. |
This appears to be working now.
|
GPG Patch added to this bug report: https://dev.gnupg.org/T5555 |
Great. Please split review to multiple requests so we can review each,
start with trivial renames, then refactor.
…On Wed, 2 Nov 2022 at 22:41 Roy Keene ***@***.***> wrote:
GPG Patch added to this bug report: https://dev.gnupg.org/T5555
—
Reply to this email directly, view it on GitHub
<#47 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJURLPK4GGVV3GEUZZ7QM3WGLGXJANCNFSM6AAAAAARHMGCWQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@alonbl There aren't any trivial renames as part of this PR aside from the refactor of "keyutil" leading to |
I'm eagerly awaiting support of curves being supported. However last activity in either PR was in 2022 and I'm having the feeling things moved on - without this getting merged anytime soon. Lot's of effort was put into adding this functionality, the pre-work was split up into its own atomic PRs, reviewed, approved, and closed - yet not merged (because those PRs were just intended for review?). Is there anything one (me?) can do to push things further? |
If it makes any difference, I've been using the patched SCD for about 2 years without any problems |
It does to me! Is this branch of your still the current state? Also, is https://dev.gnupg.org/T5555 still necessary? I tried to comment on the ticket, but the GnuPG "community" is an absolute nightmare. Account creation is necessary, but disabled. One has to register to their mailing list and send credentials to all members to maybe eventually get an account in order to be able to comment on tickets. Is there any chance to also support ed25519 curves - which the YubiKey's retired slots are now also capable of (I think since YubiKey firmware version 5.7.x or something)? |
The changes are still required to GnuPG as far as I know. Ed25519 isn't significantly different from EcDSA so support for an SCD isn't hard (it's a bit easier, since no hashing has to be done)... however, I'm not sure about support from the GnuPG side through an SCD. Oops, I accidentally closed it. |
This changeset adds support for EcDSA Keys with Named Curves. Additionally, it may make it easier to add other kinds of keys in the future.
Not done as part of this change:
Support GnuTLS