Skip to content

ensure to clear openssl3 PEM reading errors - #1652

Closed
MartinNowak wants to merge 1 commit into
libssh2:masterfrom
MartinNowak:fix-openssl-errors-openssh-priv-key
Closed

MartinNowak wants to merge 1 commit into
libssh2:masterfrom
MartinNowak:fix-openssl-errors-openssh-priv-key

Conversation

@MartinNowak

Copy link
Copy Markdown
  • errors were left on openssl's error stack when reading OpenSSH private keys
    (e.g. in sign_frommemory → _libssh2_rsa_new_private_frommemory)
  • moved all private key reading to central read_private_key_from_bio method
    to consistently read and handle (passphrase) errors

@MartinNowak
MartinNowak force-pushed the fix-openssl-errors-openssh-priv-key branch from 29ad38a to c277595 Compare September 10, 2025 06:52
@MartinNowak
MartinNowak marked this pull request as draft September 10, 2025 07:43
@MartinNowak
MartinNowak force-pushed the fix-openssl-errors-openssh-priv-key branch from c277595 to 7c0ce8d Compare September 10, 2025 08:46
@MartinNowak
MartinNowak marked this pull request as ready for review September 10, 2025 09:56
Comment thread src/openssl.c Resolved
@MartinNowak
MartinNowak force-pushed the fix-openssl-errors-openssh-priv-key branch 3 times, most recently from 1fadad1 to 1fb0906 Compare September 11, 2025 08:48
Comment thread src/openssl.c Resolved
Comment thread src/openssl.c Resolved
@MartinNowak
MartinNowak force-pushed the fix-openssl-errors-openssh-priv-key branch from 1fb0906 to 71e2dbc Compare September 17, 2025 11:49
- errors were left on openssl's error stack when reading OpenSSH private keys
  (e.g. in sign_frommemory → _libssh2_rsa_new_private_frommemory)
- moved all private key reading to central read_private_key_from_bio method
  to consistently read and handle (passphrase) errors
@MartinNowak
MartinNowak force-pushed the fix-openssl-errors-openssh-priv-key branch from 71e2dbc to 6c32b09 Compare September 17, 2025 11:51
@MartinNowak

Copy link
Copy Markdown
Author

Updated @vszakats

@willco007

Copy link
Copy Markdown
Member

@MartinNowak Sorry this is taking so long, I'm finally getting to this, any chance you could push an updated MR with the conflicts resolved? Thanks.

@vszakats vszakats left a comment

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.

Formatting nits. Also needs rebasing on master.

Comment thread src/openssl.c
Comment on lines +1203 to +1204
*key_ctx = read_private_key(bp, NULL, (pem_password_cb *) passphrase_cb,
(void *) LIBSSH2_UNCONST(passphrase));

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.

Suggested change
*key_ctx = read_private_key(bp, NULL, (pem_password_cb *) passphrase_cb,
(void *) LIBSSH2_UNCONST(passphrase));
*key_ctx = read_private_key(bp, NULL, (pem_password_cb *)passphrase_cb,
(void *)LIBSSH2_UNCONST(passphrase));

Comment thread src/openssl.c
EVP_PKEY* pk;
int pktype;
int rc;
pem_read_bio_func read_pem = (pem_read_bio_func) &PEM_read_bio_PrivateKey;

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.

Suggested change
pem_read_bio_func read_pem = (pem_read_bio_func) &PEM_read_bio_PrivateKey;
pem_read_bio_func read_pem = (pem_read_bio_func)&PEM_read_bio_PrivateKey;

Comment thread src/openssl.c
#ifdef HAVE_SSLERROR_BAD_DECRYPT
unsigned long sslError;
#endif
pem_read_bio_func read_pem = (pem_read_bio_func) &PEM_read_bio_PrivateKey;

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.

Suggested change
pem_read_bio_func read_pem = (pem_read_bio_func) &PEM_read_bio_PrivateKey;
pem_read_bio_func read_pem = (pem_read_bio_func)&PEM_read_bio_PrivateKey;

@vszakats

vszakats commented Jul 21, 2026 •

Copy link
Copy Markdown
Member

master diverged quite a bit since then, but this issue got
(I believe) fixed in a separate patch merging file/blob
codepaths in most places in the codebase: #2379

Thanks for the patch, and let me know or feel free to open
a PR if there is still something to fix.

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