Skip to content

GHA: test WinCNG SCP/SFTP via curl runtests - #2590

Closed
vszakats wants to merge 37 commits into
libssh2:masterfrom
vszakats:gha-wincng-curl
Closed

vszakats wants to merge 37 commits into
libssh2:masterfrom
vszakats:gha-wincng-curl

Conversation

@vszakats

@vszakats vszakats commented Sep 5, 2026 •

Copy link
Copy Markdown
Member

The WinCNG backend has been missing runtime tests for a while. To
restore some level of testing, this PR make use of curl's regression
test suite (runtests) to run SCP/SFTP-specific tests with the
master/PR libssh2 revision at hand. Some tests need to be disabled when
using the built-in Windows OpenSSH server.

The current CI jobs reproduce the long-running WinCNG flaky failure
reported in #804 reliability.

Note, if these CI jobs make libssh2 CI a pain to use, they will be
removed. This has a reasonably fair chance to happen, based on the
experience with curl CI with Windows.

Also:

  • test both ECDH and non-ECDH builds.
  • test build on x64 and ARM64.
  • test with both Windows built-in OpenSSH port and MSYS2's sshd.
  • enable debug logging in libssh2 while running the tests.
  • for extra stress, run each of the 56-57 tests 6 times.
    This may be lowered in a future commit to avoid flakiness and reduce
    CI load and job times.

Caveats:

Ref: #2049
Ref: #2583


TODO:

  • perhaps switch to MSYS2 toolchain to avoid the MSBuild issue. (Or keep MSVC and apply the complex workaround used for curl) [MAYBE IN A FUTURE COMMIT]
  • perhaps run tests with MS OpenSSH port.
  • perhaps run on ARM64.
  • finalize workflow name and id.

@vszakats
vszakats marked this pull request as draft September 5, 2026 12:38
Comment thread .github/workflows/ci.yml Resolved
@vszakats vszakats changed the title GHA: try running curl tests GHA: test WinCNG SCP/SFTP via curl's runtest Sep 5, 2026
@vszakats
vszakats marked this pull request as ready for review September 6, 2026 06:30
@Lv2dev

Lv2dev commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

While looking into the test 621 hang, I found busy loops in SCP error cleanup. Both scp_recv() and scp_send() keep calling libssh2_channel_free() when it returns LIBSSH2_ERROR_EAGAIN, even in non-blocking mode. This can keep the call from returning to curl.

I reproduced this with synthetic I/O callbacks, though I haven't confirmed whether it explains the original CI hang.

I have a local patch using the existing error_closing state to resume cleanup across calls and preserve the original error. The bounded regression test fails on the original code on Windows and passes with the patch on Windows/WinCNG and Linux/OpenSSL.

Would you like me to open a separate PR for the SCP fix?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new CI job’s overall timeout is currently set such that it can terminate the test step prematurely after earlier build/install work consumes part of the budget.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR extends Windows WinCNG validation by adding a CI job that builds libssh2 with MSVC and runs curl’s runtest SCP/SFTP tests against it, and adjusts WinCNG big-number handling to ensure normalized (no leading-zero) representations in key exchange outputs.

Changes:

  • Add wcng_bn_normalize() and apply it to WinCNG BN outputs (ECDH secret, DH public key, DH shared secret) to produce normalized big-number byte strings.
  • Add a new GitHub Actions job (build_msvc_curl) that builds libssh2 (WinCNG) and curl from source on Windows, then runs curl’s SCP/SFTP runtests.
File summaries
File Description
src/wincng.c Normalizes WinCNG big-number buffers after key/secret generation to avoid leading-zero artifacts.
.github/workflows/ci.yml Adds a Windows MSVC+MSYS2-based CI job to build curl against libssh2 and run SCP/SFTP runtests.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .github/workflows/ci.yml Resolved
@vszakats vszakats changed the title GHA: test WinCNG SCP/SFTP via curl's runtest GHA: test WinCNG SCP/SFTP via curl runtests Sep 7, 2026
@vszakats

vszakats commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

While looking into the test 621 hang, I found busy loops in SCP error cleanup. Both scp_recv() and scp_send() keep calling libssh2_channel_free() when it returns LIBSSH2_ERROR_EAGAIN, even in non-blocking mode. This can keep the call from returning to curl.

I reproduced this with synthetic I/O callbacks, though I haven't confirmed whether it explains the original CI hang.

I have a local patch using the existing error_closing state to resume cleanup across calls and preserve the original error. The bounded regression test fails on the original code on Windows and passes with the patch on Windows/WinCNG and Linux/OpenSSL.

Would you like me to open a separate PR for the SCP fix?

Certainly!

vszakats pushed a commit to vszakats/libssh2 that referenced this pull request Sep 7, 2026
SCP receive and send error cleanup currently keeps retrying
`libssh2_channel_free()` when it returns `LIBSSH2_ERROR_EAGAIN`,
including in non-blocking mode.

Use the existing `ssh2_NB_state_error_closing` state to return control
to the caller and resume cleanup on the next call. Preserve the original
error code, message, and ownership flags until cleanup finishes. Release
a saved heap-owned message if the session is freed before cleanup
completes.

Add a bounded, network-free standalone regression covering receive/send
cleanup across calls, restoration of the original error, and
saved-message lifetime through completion or session teardown. It uses
the common SCP/channel code and does not require a particular crypto
backend.

Follow-up to libssh2#2590 (comment). I
have not established whether this explains the original test 621 CI
hang. The curl runtime suite and upstream CI matrix have not been run
for this branch.

2591
@vszakats

vszakats commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

@Lv2dev I run it with #2591, and it run fine. But, the hang only happened once,
so this doesn't necessary mean a proof.

vszakats pushed a commit to vszakats/libssh2 that referenced this pull request Sep 7, 2026
SCP receive and send error cleanup currently keeps retrying
`libssh2_channel_free()` when it returns `LIBSSH2_ERROR_EAGAIN`,
including in non-blocking mode.

Use the existing `ssh2_NB_state_error_closing` state to return control
to the caller and resume cleanup on the next call. Preserve the original
error code, message, and ownership flags until cleanup finishes. Release
a saved heap-owned message if the session is freed before cleanup
completes.

Add a bounded, network-free standalone regression covering receive/send
cleanup across calls, restoration of the original error, and
saved-message lifetime through completion or session teardown. It uses
the common SCP/channel code and does not require a particular crypto
backend.

Follow-up to libssh2#2590 (comment). I
have not established whether this explains the original test 621 CI
hang. The curl runtime suite and upstream CI matrix have not been run
for this branch.

2591
@vszakats
vszakats force-pushed the gha-wincng-curl branch 2 times, most recently from 7e4e23b to 8897542 Compare September 7, 2026 14:59
vszakats pushed a commit that referenced this pull request Sep 8, 2026
- normalize fixed-width WinCNG bignums before SSH `mpint` serialization
- apply the normalization to DH public values and DH/ECDH shared secrets
- zero the removed tail bytes and add common bignum conversion tests

WinCNG returns DH public values and raw DH/ECDH shared secrets in
fixed-width buffers. The WinCNG bignum retained that buffer width as its
numeric length. When a value started with `0x00`, libssh2 included the
redundant byte in the exchange hash even though RFC 4251 requires a
canonical `mpint` representation.

The peer hashes the normalized integer, so the exchange hashes differ
and a valid server host-key signature is rejected. This appeared
intermittently as `LIBSSH2_ERROR_KEY_EXCHANGE_FAILURE` because it
depends on the generated value.

The helper introduced here moves significant bytes to the start of the
existing allocation, explicitly clears the removed tail, and updates
only the logical length. It does not add an allocation or a new failure
path.

Reported-by: Dan Fandrich
Fixes #804
Ref: #2590 (tests)

Closes #2583
@vszakats vszakats closed this in bb8e095 Sep 8, 2026
@vszakats
vszakats deleted the gha-wincng-curl branch September 8, 2026 18:42
vszakats added a commit to vszakats/curl that referenced this pull request Oct 4, 2026
From `CURL_VERSION`. To avoid confusion with the non-debug
`CURL_VERSION` macro, and to avoid possible, difficult-to-track-down
collision when `CURL_VERSION` is legitimately used for something else.

Refs:
libssh2/libssh2@51333f9
libssh2/libssh2#2590
libssh2/libssh2@bb8e095
vszakats added a commit to curl/curl that referenced this pull request Oct 4, 2026
From `CURL_VERSION`. To avoid confusion with the non-debug
`CURL_VERSION` macro, and to avoid possible, difficult-to-track-down
fallouts when `CURL_VERSION` is legitimately used for something else.

Refs:
libssh2/libssh2@51333f9
libssh2/libssh2#2590
libssh2/libssh2@bb8e095

Closes #23252
vszakats added a commit that referenced this pull request Oct 13, 2026
In an attempt to improve stability / reduce flakiness of these tests.
Especially the ECDSA-enable ones were prone to mass fail.

```
22:49:30.110000 * Failure establishing ssh session: -43, Failed getting banner
```
Ref: https://github.com/libssh2/libssh2/actions/runs/38480041149/job/115580107883#step:11:1034

This is a different failure than the long-chased flaky -8 kex failures,
which was fixed earlier and did not reoccur since then.

Follow-up to 5bfa574 #2603
Follow-up to f216bbe #2583
Follow-up to bb8e095 #2590

Closes #2666
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants