Repository navigation
Agent forwarding implementation - #752
Conversation
src\packet.c(1215,59): warning C4267: 'function': conversion from 'size_t' to 'unsigned long', possible loss of data
9849954 to
1f6706b
Compare
1f6706b to
8eb4da5
Compare
|
@MichaelBuckley Thank you for your update! |
| #define LIBSSH2_AUTHAGENT_SIGN_FUNC(name) \ | ||
| int name(LIBSSH2_SESSION* session, \ | ||
| unsigned char *blob, unsigned int blen, \ | ||
| const unsigned char *data, unsigned int dlen, \ |
There was a problem hiding this comment.
@MichaelBuckley I've added const here. Do you think this is okay?
There was a problem hiding this comment.
Yes, good catch. However, we will also need to add const to libssh2_agent_sign() to match. The agent_sign() function already marks the data parameter const.
There was a problem hiding this comment.
Yep, added that one already. Though we still need to sync the man page with this.
| void sign(LIBSSH2_SESSION *session, | ||
| unsigned char **sig, size_t *sig_len, | ||
| const unsigned char *data, size_t data_len, | ||
| void **abstract); |
There was a problem hiding this comment.
The callback arguments here (LIBSSH2_CALLBACK_AUTHAGENT_IDENTITIES and LIBSSH2_CALLBACK_AUTHAGENT_SIGN) seem to differ from the ones in the code, or am I misreading?
For example from the SIGN callback, blob seems to be missing and sign comes before data here, but after in the code.
There was a problem hiding this comment.
You're right about LIBSSH2_CALLBACK_AUTHAGENT_SIGN. I think it was changed after I last edited the man page.
It should be int sign(LIBSSH2_SESSION* session, unsigned int flags, unsigned char *blob, unsigned int blen, unsigned char *data, const unsigned int dlen, unsigned char **sig, unsigned int *sig_len, const char *agent_path, void **abstract);
I'll update the man page in a bit here.
LIBSSH2_CALLBACK_AUTHAGENT_IDENTITIES looks correct to me though, unless I'm missing something.
There was a problem hiding this comment.
sign() will be fine then, thanks for looking into it.
As for identities, I'm looking at this code in include/libssh2.h:
#define LIBSSH2_ADD_IDENTITIES_FUNC(name) \
void name(LIBSSH2_SESSION *session, LIBSSH2_CHANNEL *channel, \
void **abstract)This doesn't match LIBSSH2_CALLBACK_AUTHAGENT_IDENTITIES in
the manual or LIBSSH2_ADD_IDENTITIES() from libssh2_priv.h. They
look like the same callback, though I may be wrong.
There was a problem hiding this comment.
Oops, I was looking at the wrong branch. The identities in the man file was correct, but it was incorrect in the header. I was looking at a branch where it was correct in the header.
Both problems should now be fixed. The man file was updated with the correct sign(), and the header was updated to match identities() in the man file.
There was a problem hiding this comment.
Thanks, no worries. We're good to merge once the CI tests finished.
|
Merged now, thank you @MichaelBuckley! |
- 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)
This PR contains a series of patches that date back many years and I believe were discussed on the mailing list, but never merged. We have been using these in our local copy of libssh2 without issue since 2015, if not earlier. I believe this is the full set of changes, as we tried to use comments to mark where our copy of libssh2 differs from the canonical version. This also contains changes I made earlier this year, but which were not discussed on the mailing list, to support certificates and FIDO2 keys with agent forwarding. Note that this is not a complete implementation of agent forwarding, as that is outside the scope of libssh2. Clients still need to provide their own implementation that parses ssh-agent methods after calling libssh2_channel_read() and calls the appropriate callback messages in libssh2. See the man page changes in this PR for more details. Integration-patches-by: Viktor Szakats * prefer size_t * prefer unsigned int over u_int in public function * add const * docs, indent, checksrc, debug call, compiler warning fixes
- 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)
| method, | ||
| method_len)) { | ||
| const char *new_method = "[email protected]"; | ||
| memcpy(method, new_method, strlen(new_method)); |
There was a problem hiding this comment.
@MichaelBuckley clang-tidy and Copilot draw attention to the line above,
and the similar one in the if following. The new string is copied over the
input one, but without a zero-terminator. Is it intended that these two inputs
get overwritten, while the others don't? If so, wouldn't we need to copy the
NUL byte too?
(It also confused me why these two values overwrite the input, and return the
full length, while pre-existing ones return the length of the prefix without
touching the buffer.)
https://github.com/libssh2/libssh2/security/quality/ai-findings (may disappear from this page):
"The memcpy operation copies exactly strlen(new_method) bytes without null-termination. The comment suggests this is intentional, but the function returns strlen(new_method) which doesn't account for a null terminator. If the caller expects a null-terminated string (which the 'char *method' parameter suggests), this could lead to issues. Either ensure null-termination or document that the returned buffer is not null-terminated."
clang-tidy output can be seen by dropping the NOLINTLINT comments, I did
not save them unfortunately.
There was a problem hiding this comment.
I double-checked and the code is fine. That's assuming all callers honor the returned length, and never consider the buffer as nul-terminated. Which was already an assumption made before this patch.
Thus, sorry about the noise and disregard the message above.
…key_sk()` This code section was merged as part of PR #752, which seems to me unrelated to the intent of the patch, and also possibly unrelated to the description of its subcommit: "Add support for certificate signing with ssh-agent" 55abcb0#diff-8213ab9c800f30c1a7aff37863954e756f946a3b3f6bd7be376d634fd9beb9f4R2369 "`session->userauth_pblc_method` is allocated in the ecdsa/ed25519 branches (lines 2393-2416), but then `userauth_read_blob_pubkey` is called immediately afterward with `&session->userauth_pblc_method` as an output parameter. Inside `userauth_read_blob_pubkey`, `*method` is unconditionally overwritten with a newly allocated buffer (see the `*method = pubkey` assignment), causing the allocation made just above to be leaked. The allocation in the ecdsa/ed25519 branches should be removed since `userauth_read_blob_pubkey` will derive and allocate the method from the public key data itself." Reported by GitHub Code Quality Follow-up to bc4e619 #752 Follow-up to ed439a2 #698 Closes #2294
This reverts an earlier change doing the opposite. `sizeof()` determines length at build-time, while `strlen()` does the same at runtime. In case of literals the results are identical, but the build-time option does it with zero runtime overhead. Also: - fix typo in literal used for determining length. (length was correct.) Follow-up to bc4e619 #752 - move literals to the right-side of comparisons, where missing. Follow-up to 88c5fd9 #2400 Follow-up to af1b501 #2224 Follow-up to 88a960a #1179 Closes #2432
This PR contains a series of patches that date back many years and I believe were discussed on the mailing list, but never merged. We have been using these in our local copy of libssh2 without issue since 2015, if not earlier. I believe this is the full set of changes, as we tried to use comments to mark where our copy of libssh2 differs from the canonical version.
This also contains changes I made earlier this year, but which were not discussed on the mailing list, to support certificates and FIDO2 keys with agent forwarding.
Note that this is not a complete implementation of agent forwarding, as that is outside the scope of libssh2. Clients still need to provide their own implementation that parses ssh-agent methods after calling libssh2_channel_read() and calls the appropriate callback messages in libssh2. See the man page changes in this PR for more details.