-
Notifications
You must be signed in to change notification settings - Fork 44
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
Allow generated EVP_PKEY to be used to verify operation #479
base: main
Are you sure you want to change the base?
Conversation
becbf86
to
e8144a2
Compare
This proposed change has several problems. First of all, could you open an issue describing what problem you encountered ? Second, please do not mix extraneous changes (like the clang warning) or other reformatting with feature changes in the same commit. Third, I do not understand the point of the code you are proposing. But this is failing because, due to how OpenSSL magaes key generation we can only return a single key type and you are left w/o the public key pair part. If this is the case please clearly state it in the issue you need to open, because if that is the case I need to think about a different architecture, probably a new key abstraction that can hold a public and a private key pair and chose based on operation, in either case the kind of change you are proposing won't be acceptable, as it is a hack that falls short in other areas. |
Also a change like this must come with tests to be acceptable. |
|
e8144a2
to
bf702a5
Compare
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.
It is a good start, some minor changes are required.
that said there is more needed to make this properly functional.
EVP_PKEY_generate returns only one EVP_PKEY instance for private and public keys. This requires storing the public key object in the private key object in order to use it for operations that using the public key Signed-off-by: latal-1 <[email protected]>
Signed-off-by: latal-1 <[email protected]>
Signed-off-by: latal-1 <[email protected]>
Signed-off-by: latal-1 <[email protected]>
Signed-off-by: latal-1 <[email protected]>
bf702a5
to
f5f049d
Compare
Done |
Can someone solve these problems? Authorship of pull request and commits is not important for me |
|
||
done: | ||
if (ret != CKR_OK) { | ||
p11prov_obj_free(pub_key); |
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.
This is wrong now because the next line will already free the pub_key you set on it.
After you set the pub key on the priv key you need to set pub_key = NULL;
This is may be one of the segfault issue, because you are causing a double-free here.
p11prov_obj_free(priv_key); | ||
priv_key = NULL; | ||
pub_key = priv_key = NULL; |
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.
This become useless once you correctly zero the pub_key right after you pass ownership of it to the priv_key object.
@@ -440,6 +440,9 @@ void p11prov_obj_free(P11PROV_OBJ *obj) | |||
if (obj == NULL) { | |||
return; | |||
} | |||
|
|||
p11prov_obj_free(obj->pub_key_obj); | |||
|
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.
This is wrong, all freeing MUST happen after the refcounting reaches 0.
Move it after the following block and you'll solve most of your segfaults.
sigctx->operation = operation; | ||
|
||
if (digest) { | ||
ret = p11prov_digest_get_by_name(digest, &sigctx->digest); | ||
if (ret != CKR_OK) { | ||
p11prov_obj_free(sigctx->key); |
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.
This is wrong, if you free the key here you also need to NULL the pointer or we will get a double free in p11prov_sig_freectx(), but you do not have to null anything here exactly because p11prov_sig_freectx() already takes care of this.
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 you are concerned about someone potentially calling the init operation multiple times, just check if the sigctx->key is not NULL at the start of the function and immediately error if that is the case. But there is no need to add that, it is an application error to try to initialize multiple times and the worst case is some memory leakage.
Note that DCO is missing in some commit and this will prevent merging until fixed (no exceptions) I also recommend you rebase interactively and edit each commit by running |
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 fix the errors I identified and all the CI failures regarding Copyright headers, commit signatures and styles.
We are almost there.
Description
Previously generated EVP_PKEY could be used for operations that only require a private key
Fixes #480
Checklist
Test suite updated with negative testsDocumentation updatedReviewer's checklist: