Skip to content

wincng: reuse ECDSA key loading/parsing code from pem.c - #2279

Closed
vszakats wants to merge 2 commits into
libssh2:masterfrom
vszakats:wincng-reuse-pem
Closed

vszakats wants to merge 2 commits into
libssh2:masterfrom
vszakats:wincng-reuse-pem

Conversation

@vszakats

@vszakats vszakats commented Jul 12, 2026 •

Copy link
Copy Markdown
Member
  • reuse pem.c/ssh2_openssh_pem_parse() in ssh2_ecdsa_new_private(),
    replacing the generic PEM parser used prior to this patch.

  • reuse pem.c/ssh2_openssh_pem_parse_memory() in
    ssh2_ecdsa_new_private_frommemory().

  • optimize out local wcng_load_pem().

  • move ECDSA key macros to from crypto.h to pem.c.

To avoid code duplication, and also to hopefully enable support for
passphrased OpenSSH-format ECDSA private keys with WinCNG.

Build tested only.

Fixes #1517
Follow-up to 3e72343 #1315


It surpised me why libssh2 has a parallel key-loading implementation
for keys from file and from memory buffers, down to line level. Was
the reason historical, first loading from file, then adding from-memory,
and instead of making the former reuse that code, it just stayed on its
own path? Also why not just load the whole key to memory, then parse
instead of going line-by-line? These files are typically small, and their
size is capped to sane sizes since (maybe not everywhere though and
could maybe be smaller)

@vszakats vszakats changed the title wincng: rework ECDSA key loading/parsing wincng: reuse ECDSA key loading/parsing code from pem.c Jul 12, 2026
@vszakats
vszakats requested a review from Copilot July 12, 2026 17:57

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.

Pull request overview

This pull request refactors WinCNG ECDSA private-key loading to reuse the shared OpenSSH PEM parsing/decryption logic from pem.c, reducing duplication and enabling passphrase-handling via the common parser.

Changes:

  • Reworked WinCNG ECDSA key loading to use ssh2_openssh_pem_parse() / _memory() instead of bespoke parsing paths.
  • Removed the WinCNG-local PEM loading helper and consolidated parsing responsibilities into the shared PEM module.
  • Relocated OpenSSH private key marker macros from crypto.h into pem.c where they’re used.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/wincng.c Switch ECDSA key loading/parsing to shared OpenSSH PEM parse helpers; removes duplicate parsing code paths.
src/pem.c Adds OpenSSH private key header/footer/auth-magic defines used by OpenSSH PEM parsing.
src/crypto.h Removes OpenSSH private key marker defines that are now local to pem.c.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/wincng.c Resolved
Comment thread src/wincng.c Resolved
Comment thread src/wincng.c Resolved

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@vszakats
vszakats force-pushed the wincng-reuse-pem branch 2 times, most recently from 473a1f0 to 0f75320 Compare July 14, 2026 11:53
@vszakats
vszakats requested a review from Copilot July 14, 2026 11:54

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread src/wincng.c Resolved
Comment thread src/wincng.c Resolved
Comment thread src/wincng.c Resolved

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment thread src/wincng.c Resolved
Comment thread src/wincng.c Resolved
Comment thread src/wincng.c Resolved
Comment thread src/wincng.c Resolved
@vszakats
vszakats force-pushed the wincng-reuse-pem branch 2 times, most recently from 4027ae5 to 5b6e9e0 Compare July 14, 2026 12:15
@vszakats
vszakats requested a review from Copilot July 14, 2026 12:16

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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

vszakats added 2 commits July 17, 2026 16:32
…te()

Also to automagically support passphrased ECDSA keys.

wincng.c optimize out wcng_load_pem

also reuse pem.c/ssh2_openssh_pem_parse_memory() in ssh2_ecdsa_new_private_frommemory()

And unlock passphrased key support.

propagate low-level error codes

align more with rsa/dsa

align name more with rsa/dsa
@vszakats vszakats closed this in 035d28c Jul 19, 2026
@vszakats
vszakats deleted the wincng-reuse-pem branch July 19, 2026 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libssh2_userauth_publickey_fromfile_ex not working on Windows

2 participants