-
Notifications
You must be signed in to change notification settings - Fork 37
Validate DH peer public key subgroup before key agreement #460
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
Open
aidangarske
wants to merge
4
commits into
wolfSSL:master
Choose a base branch
from
aidangarske:worktree-dh-subgroup-check
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1d87f46
F-5914 - Validate DH peer public key subgroup before key agreement
aidangarske e22b86c
Harden DH subgroup regression coverage
aidangarske e7dcc23
Tighten DH subgroup rejection tests
aidangarske 9f773cf
Preserve DH subgroup checks on older wolfSSL
aidangarske File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -254,6 +254,55 @@ static int wp_dh_kdf_derive(wp_DhCtx* ctx, unsigned char* key, | |
| return ok; | ||
| } | ||
|
|
||
| /** | ||
| * Validate the peer's public key against our domain parameters. | ||
| * | ||
| * @param [in] key DH key object holding the domain parameters. | ||
| * @param [in] pub Peer's public key data. | ||
| * @param [in] pubSz Length of peer's public key data in bytes. | ||
| * @return 1 on success. | ||
| * @return 0 on failure. | ||
| */ | ||
| static int wp_dh_check_peer_pub(DhKey* key, const unsigned char* pub, | ||
| word32 pubSz) | ||
| { | ||
| int ok = 1; | ||
| int rc; | ||
| unsigned char* q = NULL; | ||
| word32 qSz; | ||
|
|
||
| WOLFPROV_ENTER(WP_LOG_COMP_DH, "wp_dh_check_peer_pub"); | ||
|
|
||
| if (!mp_iszero(&key->q)) { | ||
| /* q must be passed explicitly for the y^q test to be performed. */ | ||
| qSz = mp_unsigned_bin_size(&key->q); | ||
| q = OPENSSL_malloc(qSz); | ||
| if (q == NULL) { | ||
| ok = 0; | ||
| } | ||
| if (ok) { | ||
| rc = mp_to_unsigned_bin(&key->q, q); | ||
| if (rc != 0) { | ||
| WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_LEVEL_DEBUG, | ||
| "mp_to_unsigned_bin", rc); | ||
| ok = 0; | ||
| } | ||
| } | ||
| if (ok) { | ||
| rc = wc_DhCheckPubKey_ex(key, pub, pubSz, q, qSz); | ||
| if (rc != 0) { | ||
| WOLFPROV_MSG_DEBUG_RETCODE(WP_LOG_LEVEL_DEBUG, | ||
| "wc_DhCheckPubKey_ex", rc); | ||
| ok = 0; | ||
| } | ||
| } | ||
| OPENSSL_free(q); | ||
| } | ||
|
|
||
| WOLFPROV_LEAVE(WP_LOG_COMP_DH, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok); | ||
| return ok; | ||
| } | ||
|
|
||
| /** | ||
| * Derive secret from DH keys. | ||
| * | ||
|
|
@@ -288,6 +337,10 @@ static int wp_dh_derive_secret(wp_DhCtx* ctx, unsigned char* secret, | |
| if (ok && (!wp_dh_get_pub(ctx->peer, &pub, &pubSz))) { | ||
| ok = 0; | ||
| } | ||
| /* Reject small subgroup peer keys before using our private key. */ | ||
| if (ok && (!wp_dh_check_peer_pub(wp_dh_get_key(ctx->key), pub, pubSz))) { | ||
| ok = 0; | ||
| } | ||
| if (ok) { | ||
| int rc; | ||
|
|
||
|
|
@@ -708,4 +761,3 @@ const OSSL_DISPATCH wp_dh_keyexch_functions[] = { | |
| }; | ||
|
|
||
| #endif /* WP_HAVE_DH */ | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: the empty trailing line is dropped. Can we keep it? |
||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.