-
Notifications
You must be signed in to change notification settings - Fork 50
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
Improve handling of public keys #516
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Feb 5, 2025
Jakuje
previously approved these changes
Feb 6, 2025
tests/tpkey.c
Outdated
@@ -0,0 +1,135 @@ | |||
/* Copyright (C) 2022 Simo Sorce <[email protected]> |
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.
2025
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.
heh
Signed-off-by: Simo Sorce <[email protected]>
In a few case we need to keep track of associated objects in order to be compatible with the way OpenSSL deals with key pairs. The EVP_PKEY object can reference both a private and a public key at the same time. Storing an "associated object" (generally a public key associated to the private key) allows the code to perform operations wth a public key where the EVP_PKEY primary object is actually a private key. The key pair generation code now always stores the public key as an associated object so that generating a keypair and then immediately testing it with a pair of sign/verify operations can be accomplished. Signed-off-by: Simo Sorce <[email protected]>
Signed-off-by: Simo Sorce <[email protected]>
In the ECDH case import involves these steps: - create new empty key - set EC domain parameters, by copying them from the server key - set EC Public key from the peer The previous code was messing the second step by completely copying the server public key if one was found on the system. This is because both on export and import we did not look at the selection and always exported/imported both parameters and the public key. As we now retain the public key object we generate with keygen, instead of discarding it, the export function would export also the public point and the import would find the server public key cached and import it fully in the empty shell reservd for the public key. Later setting the peer public key would then fail as the object was considered a complete key already. Signed-off-by: Simo Sorce <[email protected]>
Signed-off-by: Simo Sorce <[email protected]>
Signed-off-by: Simo Sorce <[email protected]>
Thanks for the review @Jakuje |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR improves pkcs11-provider's handling of public keys in three related and interconnected areas by creating a first class association between private and public keys.
In OpenSSL, the EVP_PKEY type can carry both public and private key information in a single structure, and this is reflected sometimes heavily in the APIs and application usge of this type. The most glaring case is key pair generation.
To better handle cases where a private key i sourced but information about the public key is requested we allow a private key object to carry a refcounted pointer to the corresponding public key object.
The three main changes in this PR are:
A new pkey test has been added to check basic keygen and printing aspects, the existing CMS and ECDH tests fully exercise the EC public key export/import changes, and the edwards tests exercise the ED export changes.
Fixes #480
Checklist
[ ] Documentation updatedReviewer's checklist: