Skip to content

ecx_keys: Handle weak x keys as insufficient_security alert#27597

Closed
jogme wants to merge 1 commit into
openssl:masterfrom
jogme:handle_bad_x_keyshare
Closed

ecx_keys: Handle weak x keys as insufficient_security alert#27597
jogme wants to merge 1 commit into
openssl:masterfrom
jogme:handle_bad_x_keyshare

Conversation

@jogme
Copy link
Copy Markdown
Contributor

@jogme jogme commented May 11, 2025

OpenSSL handles this issue with internal_error which is not giving a proper explanation of the issue.

Thank you for the report @GeorgePantelakis!

Resolves: #27531

Checklist
  • documentation is added or updated
  • tests are added or updated

@openssl-machine openssl-machine added the hold: cla required The contributor needs to submit a license agreement label May 11, 2025
@github-actions github-actions Bot added the severity: fips change The pull request changes FIPS provider sources label May 11, 2025
@jogme jogme force-pushed the handle_bad_x_keyshare branch from 83d69a5 to d3a5580 Compare May 11, 2025 15:39
Comment thread ssl/s3_lib.c Outdated
@jogme jogme force-pushed the handle_bad_x_keyshare branch from d3a5580 to 2dbdc05 Compare May 12, 2025 07:06
@openssl-machine openssl-machine removed the hold: cla required The contributor needs to submit a license agreement label May 12, 2025
Copy link
Copy Markdown
Contributor

@Sashan Sashan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just fix the cstyle and you'll be good to go. thanks.

Comment thread crypto/ec/ecx_key.c Outdated
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
return 0;
}
ERR_raise(ERR_LIB_PROV, ERR_LIB_EC);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the indentation here is of. it needs to be moved by 4 spaces left. So it is aligned with ossl_
cstyle here is hard.

Comment thread crypto/ec/ecx_key.c Outdated
& S390X_CAPBIT(S390X_SCALAR_MULTIPLY_X448)) {
if (s390x_x448_mul(secret, peer->pubkey, priv->privkey) == 0) {
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
ERR_raise(ERR_LIB_PROV, ERR_LIB_EC);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c-style here is OK

Comment thread crypto/ec/ecx_key.c Outdated
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
return 0;
}
ERR_raise(ERR_LIB_PROV, ERR_LIB_EC);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here is off again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason the style check did detect issues here and this was the solution. I might check the style-checker for some errors

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style checker has to be taken with grain of salt. It is not and cannot be perfect. We have the style: waived label that can be added after manual review of the style checker report.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason the style check did detect issues here and this was the solution. I might check the style-checker for some errors

I think c-style checker is confused by errors which exists in the file already

Copy link
Copy Markdown
Contributor Author

@jogme jogme May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I changed it back to normal and then deleted as seen below

@t8m t8m added branch: master Applies to master branch approval: review pending This pull request needs review by a committer labels May 12, 2025
Comment thread crypto/ec/ecx_key.c Outdated
& S390X_CAPBIT(S390X_SCALAR_MULTIPLY_X25519)) {
if (s390x_x25519_mul(secret, peer->pubkey, priv->privkey) == 0) {
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_DURING_DERIVATION);
ERR_raise(ERR_LIB_PROV, ERR_LIB_EC);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you changing the reason code? That does not make sense to me. You can test for ERR_LIB_PROV && PROV_R_FAILED_DURING_DERIVATION in libssl with no issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the first time it looked like there are more paths this error code can happen, but now I searched it up and it's used only in one place of hpke code and here. So it doesn't make sense to use a different error code here. Changed back.

Comment thread ssl/s3_lib.c Outdated
Comment on lines +5039 to +5047
/*
* the public key probably was a weak key
*/
if (ERR_GET_REASON(ERR_peek_last_error()) == ERR_LIB_EC) {
SSLfatal(s, SSL_AD_INSUFFICIENT_SECURITY, SSL_R_BAD_ECPOINT);
} else {
SSLfatal(s, SSL_AD_INTERNAL_ERROR, ERR_R_INTERNAL_ERROR);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not check the reason code at all and used SSL_AD_ILLEGAL_PARAMETER instead as suggested in #27531. The returned reason code should be SSL_R_BAD_KEY_SHARE.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The EVP_PKEY_derive can fail on many different reasons; would it be good to report all of them as ILLEGAL_PARAMETER?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is IMO OK. The alert is just an alert. This is the most common case of the failure.

@t8m t8m added triaged: bug The issue/pr is/fixes a bug tests: exempted The PR is exempt from requirements for testing labels May 12, 2025
@jogme jogme force-pushed the handle_bad_x_keyshare branch from 2dbdc05 to 56be945 Compare May 12, 2025 09:47
@github-actions github-actions Bot removed the severity: fips change The pull request changes FIPS provider sources label May 12, 2025
@jogme jogme force-pushed the handle_bad_x_keyshare branch from 56be945 to 3228720 Compare May 12, 2025 11:13
Comment thread ssl/s3_lib.c Outdated
Comment thread ssl/s3_lib.c Outdated
Comment thread ssl/s3_lib.c Outdated
@jogme jogme force-pushed the handle_bad_x_keyshare branch from 3228720 to 33fa9ac Compare May 12, 2025 14:32
t8m
t8m previously approved these changes May 12, 2025
@t8m
Copy link
Copy Markdown
Member

t8m commented May 12, 2025

There is also #25781 which is related to this PR.

@t8m t8m added branch: 3.0 Applies to openssl-3.0 branch branch: 3.2 Applies to openssl-3.2 (EOL) branch: 3.3 Applies to openssl-3.3 (EOL) branch: 3.4 Applies to openssl-3.4 branch: 3.5 Applies to openssl-3.5 labels May 12, 2025
Sashan
Sashan previously approved these changes May 13, 2025
Copy link
Copy Markdown
Contributor

@Sashan Sashan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me

@Sashan Sashan added approval: done This pull request has the required number of approvals and removed approval: review pending This pull request needs review by a committer labels May 13, 2025
@openssl-machine openssl-machine added approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: done This pull request has the required number of approvals labels May 14, 2025
@openssl-machine
Copy link
Copy Markdown
Collaborator

This pull request is ready to merge

@jogme jogme dismissed stale reviews from Sashan and t8m via a8192c4 May 15, 2025 07:58
@jogme jogme force-pushed the handle_bad_x_keyshare branch from 33fa9ac to a8192c4 Compare May 15, 2025 07:58
@jogme
Copy link
Copy Markdown
Contributor Author

jogme commented May 15, 2025

There is also #25781 which is related to this PR.

I updated the PR with the new commit partly (the key share part) resolving issue #25781. PTAL

moved to the PR #27627

@jogme jogme changed the title ecx_keys: Handle weak x keys as insufficient_security alert Handle weak x keys and mlkem failed encapsulation as illegal_parameter alert May 15, 2025
@jogme jogme force-pushed the handle_bad_x_keyshare branch from a8192c4 to cc2c9e6 Compare May 15, 2025 08:13
@jogme jogme changed the title Handle weak x keys and mlkem failed encapsulation as illegal_parameter alert ecx_keys: Handle weak x keys as insufficient_security alert May 15, 2025
openssl-machine pushed a commit that referenced this pull request May 15, 2025
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #27597)
openssl-machine pushed a commit that referenced this pull request May 15, 2025
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #27597)

(cherry picked from commit 5da4ea1)
openssl-machine pushed a commit that referenced this pull request May 15, 2025
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #27597)

(cherry picked from commit 5da4ea1)
openssl-machine pushed a commit that referenced this pull request May 15, 2025
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #27597)

(cherry picked from commit 5da4ea1)
openssl-machine pushed a commit that referenced this pull request May 15, 2025
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #27597)

(cherry picked from commit 5da4ea1)
openssl-machine pushed a commit that referenced this pull request May 15, 2025
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from #27597)

(cherry picked from commit 5da4ea1)
@t8m
Copy link
Copy Markdown
Member

t8m commented May 15, 2025

Merged to all the active branches. Thank you.

@t8m t8m closed this May 15, 2025
The-Mule pushed a commit to The-Mule/openssl that referenced this pull request May 16, 2025
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl#27597)
Sashan pushed a commit to Sashan/openssl that referenced this pull request May 16, 2025
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl#27597)
DDvO pushed a commit to siemens/openssl that referenced this pull request Jun 16, 2025
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl#27597)
MichaelA-Fireblocks pushed a commit to MichaelA-Fireblocks/openssl that referenced this pull request Jul 15, 2025
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl#27597)
MichaelA-Fireblocks pushed a commit to MichaelA-Fireblocks/openssl that referenced this pull request Jul 15, 2025
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl#27597)
bernd-edlinger pushed a commit to bernd-edlinger/openssl that referenced this pull request Aug 9, 2025
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from openssl#27597)

(cherry picked from commit 5da4ea1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch branch: 3.0 Applies to openssl-3.0 branch branch: 3.2 Applies to openssl-3.2 (EOL) branch: 3.3 Applies to openssl-3.3 (EOL) branch: 3.4 Applies to openssl-3.4 branch: 3.5 Applies to openssl-3.5 tests: exempted The PR is exempt from requirements for testing triaged: bug The issue/pr is/fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

internal_error instead of illegal_parameter for improper key share value

5 participants