Repository navigation
Conversation
vszakats
marked this pull request as draft
July 6, 2026 22:54
vszakats
force-pushed
the
pubisvalid
branch
2 times, most recently
from
July 8, 2026 13:03
c7860e8 to
c35962c
Compare
vszakats
marked this pull request as ready for review
July 8, 2026 13:19
There was a problem hiding this comment.
Pull request overview
This PR adds validation for Diffie-Hellman public values in the OpenSSL and mbedTLS backends (mitigating GHSA-m9rg-h9jv-9gvh) and introduces a simple unit test to exercise the new validation helper.
Changes:
- Add
ssh2_dh_is_valid()helper for OpenSSL and mbedTLS and enforce it inssh2_dh_secret(). - Add unit coverage in
tests/test_simple.cfor DH public-value validation error cases. - Expose
ssh2_dh_is_valid()insrc/crypto.hand annotate an internal header used by unit tests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_simple.c | Adds unit test cases for DH public-value validation across supported crypto backends. |
| src/userauth_kbd_packet.h | Adds a comment clarifying the function is used by unit tests. |
| src/openssl.c | Implements DH public-value validation for OpenSSL/WolfSSL and enforces it before computing the shared secret. |
| src/mbedtls.c | Implements DH public-value validation for mbedTLS and enforces it before computing the shared secret. |
| src/crypto.h | Declares ssh2_dh_is_valid() for internal use (tests + backend code path). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
vszakats
added a commit
to vszakats/libssh2
that referenced
this pull request
Jul 23, 2026
To reflect that the return value is not a boolean. Reported-by: Patrick Monnerat Bug: libssh2#2402 (comment) Follow-up to fcf8307 libssh2#2239
This was referenced Jul 23, 2026
vszakats
added a commit
that referenced
this pull request
Jul 23, 2026
To reflect that the return value is not a boolean. Reported-by: Patrick Monnerat Bug: #2402 (comment) Follow-up to fcf8307 #2239 Closes #2406
vszakats
added a commit
that referenced
this pull request
Jul 23, 2026
Fixing:
```
tests/test_simple.c:84:56: error: operand of ? changes signedness: 'int' to 'unsigned long' [clang-diagnostic-sign-conversion]
84 | gcry_mpi_t f = gcry_mpi_set_ui(NULL, fi >= 0 ? fi : -fi);
| ~~~~~~~~~~~~~~~ ^~
tests/test_simple.c:84:61: error: operand of ? changes signedness: 'int' to 'unsigned long' [clang-diagnostic-sign-conversion]
84 | gcry_mpi_t f = gcry_mpi_set_ui(NULL, fi >= 0 ? fi : -fi);
| ~~~~~~~~~~~~~~~ ^~~
tests/test_simple.c:85:46: error: implicit conversion changes signedness: 'int' to 'unsigned long' [clang-diagnostic-sign-conversion]
85 | gcry_mpi_t p = gcry_mpi_set_ui(NULL, atoi(tests[i].p));
| ~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~
```
Ref: https://github.com/libssh2/libssh2/actions/runs/30043871895/job/89330114459#step:24:124
Also add intermediate current test holder var to keep code readable.
Follow-up to 76d30e5 #2417
Follow-up to fcf8307 #2239
Closes #2418
vszakats
added a commit
that referenced
this pull request
Jul 27, 2026
vszakats
pushed a commit
that referenced
this pull request
Jul 27, 2026
We consider parameters as valid if 2 <= f <= p-2 and if f has at least 4 bits set. I had to undo some tidy-up that broke compilation on os400: `((ptr)->connect)(...)` instead of `(ptr)->connect(...)` is intentional since` connect()` is a macro and extra-parentheses avoid its expansion. The same applies to `send()` and `recv()`. OS400 has no `uintptr_t`. Ref: GHSA-m9rg-h9jv-9gvh Follow-up to fcf8307 #2239 Closes #2402
vszakats
added a commit
that referenced
this pull request
Sep 7, 2026
Omit direct backend-specific API use. Drop one test using negative input, that's impossible with the internal crypto API. Using backend-specific code in tests is highly undesired. It's also discouraged to special-case any, in this case WinCNG had to be because it does not implement the DH validation function. Also: - mbedtls: fix an internal API type difference with a cast. - unfold a line. Follow-up to fcf8307 #2239 Closes #2595
vszakats
pushed a commit
that referenced
this pull request
Oct 4, 2026
ssh2_dh_secret() in the Windows CNG backend uses the server's Diffie-Hellman public value f without the range check the other four backends apply through ssh2_dh_validate(), so a malicious server can send f of 0, 1 or p-1 and push the shared secret into a trivial subgroup that openssl, libgcrypt, mbedtls and os400qc3 all reject with LIBSSH2_ERROR_PROTO. This adds a WinCNG ssh2_dh_validate() that enforces 1 < f < p-1 and the same minimum-set-bits check on the big-endian value, and calls it at the top of ssh2_dh_secret() like the other backends do. The shared test_ssh2_dh_validate() in tests/test_simple.c was stubbed out on WinCNG only because the function did not exist, so it now runs against the real implementation too. Reported-by: yaotushaozhu on github Ref: GHSA-m9rg-h9jv-9gvh Follow-up to fcf8307 #2239 Closes #2645
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
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.
Also add tests.
Reported-by: yaotushaozhu on github
Ref: GHSA-m9rg-h9jv-9gvh
Refs:
https://github.com/gpg/libgcrypt/blob/master/tests/mpitests.c
https://www.gnupg.org/%28en%29/documentation/manuals/gcrypt/Bit-manipulations.html
https://os.mbed.com/teams/sandbox/code/mbedtls/docs/tip/bignum_8h.html