Skip to content

openssl: fix misleading error message if wrong passphrase - #789

Merged
vszakats merged 6 commits into
libssh2:masterfrom
Zenju:patch-2
Apr 25, 2023
Merged

vszakats merged 6 commits into
libssh2:masterfrom
Zenju:patch-2

Conversation

@Zenju

@Zenju Zenju commented Jan 16, 2023

Copy link
Copy Markdown
Contributor

Hi,

if a wrong passphrase is entered by the user, libssh2_userauth_publickey_frommemory fails with:

LIBSSH2_ERROR_PROTO: Error parsing PEM: offset out of bounds

Since this is a common error case, and errors are ultimately propagated to the end user, I believe an explicit error mentioning "wrong passphrase" should be returned instead.

Best, Zenju


PS:

  1. Perhaps error handling should be even more detailed, and the full OpenSSL message should be returned?

ERR_error_string_n(ERR_get_error(), errorBuf, sizeof(errorBuf));

But it seems, _libssh2_error() cannot handle a non-static error message at this time.

  1. Because of the OpenSSH format fallback, currently either the OpenSSH, or the OpenSSL error code is dismissed:
    => Ideally, libssh2 would search for OPENSSH_HEADER_BEGIN in "privatekeydata", and only then try the OpenSSH format. For a quick check, this would require something like strnstr() because "privatekeydata" is not null-terminated. e.g. https://opensource.apple.com/source/Libc/Libc-1158.30.7/string/FreeBSD/strnstr.c.auto.html

Comment thread src/openssl.c Resolved
Co-authored-by: Viktor Szakats <[email protected]>
@vszakats
vszakats requested a review from willco007 April 9, 2023 16:18
@vszakats vszakats changed the title Fix misleading error message if wrong passphrase openssl: fix misleading error message if wrong passphrase Apr 15, 2023
@vszakats

Copy link
Copy Markdown
Member

@libssh2/dev-team This is technically ready to merge. Any objection, opinion or review if we are good to go along with it?

@vszakats

Copy link
Copy Markdown
Member

Fixes #608

@vszakats
vszakats merged commit 097c8f0 into libssh2:master Apr 25, 2023
@vszakats vszakats mentioned this pull request Apr 26, 2023
vszakats pushed a commit that referenced this pull request Apr 26, 2023
- openssl: fix potentially missing `ERR_*` constants by including
  `openssl/err.h`. This could happen with recent version of Xcode
  or when building against OpenSSL built with the `OPENSSL_NO_ENGINE`
  option.

  Regression from 097c8f0 (#789)

- channel: fix an issue that would corrupt the data stream when
  attempting to initialize the agent in non-blocking mode, as it is
  necessary to propagate the `EAGAIN` signal upstream when the transport
  returns `EAGAIN`.

  Regression from bc4e619 (#752)

- packet: the current code does not set the state machine upon reaching
  this point which means that if the code is suspended due to the
  transport returning an `EAGAIN`, this will re-initialize the structure
  every time.

  The issue is that this keeps assigning a new channel-id downstream,
  which does not match the initial channel-id that is initially
  generated, causing a lookup later to fail as there is no matching
  channel.

  Regression from bc4e619 (#752)
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
agreppin pushed a commit to agreppin/libssh2 that referenced this pull request Jul 14, 2024
- openssl: fix potentially missing `ERR_*` constants by including
  `openssl/err.h`. This could happen with recent version of Xcode
  or when building against OpenSSL built with the `OPENSSL_NO_ENGINE`
  option.

  Regression from 097c8f0 (libssh2#789)

- channel: fix an issue that would corrupt the data stream when
  attempting to initialize the agent in non-blocking mode, as it is
  necessary to propagate the `EAGAIN` signal upstream when the transport
  returns `EAGAIN`.

  Regression from bc4e619 (libssh2#752)

- packet: the current code does not set the state machine upon reaching
  this point which means that if the code is suspended due to the
  transport returning an `EAGAIN`, this will re-initialize the structure
  every time.

  The issue is that this keeps assigning a new channel-id downstream,
  which does not match the initial channel-id that is initially
  generated, causing a lookup later to fail as there is no matching
  channel.

  Regression from bc4e619 (libssh2#752)
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.

2 participants