aboutsummaryrefslogtreecommitdiff
path: root/src
AgeCommit message (Collapse)AuthorFilesLines
2023-12-15libcrypto: Report errors from OpenSSL key import and exportJakub Jelen2-0/+6
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-12-15pki: Unbreak key comparison of Ed25519 keys imported from PEM or OpenSSH ↵Jakub Jelen1-0/+19
container Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-12-15packet_cb: Reformat remaining functionsJakub Jelen1-125/+144
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-12-05Handle automatic certificate authenticationJakub Jelen4-33/+321
This involves reading the certificates from configuration files through options and handling them similarly as the OpenSSH does when doing the auto pubkey authentication, also in combination with agent or identities only. Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com>
2023-12-05Reformat auth.cJakub Jelen1-48/+64
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com>
2023-12-05auth: Reformat ssh_userauth_agentJakub Jelen1-13/+14
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com>
2023-12-05pki: Make sure public keys match when adding certificate dataJakub Jelen1-1/+7
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com>
2023-12-05pki: Make sure imported certificate is certificateJakub Jelen1-1/+12
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com>
2023-12-05pki: Support comparing keys with certificatesJakub Jelen4-13/+14
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com>
2023-12-05pki: Add support for comparing certificatesJakub Jelen2-0/+20
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com>
2023-12-05pki: Avoid needless cast to voidJakub Jelen1-1/+1
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com>
2023-12-05bignum: Avoid trailing newline in log messageJakub Jelen1-1/+1
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com>
2023-12-05Remove binary include dir from PRIVATE_INCLUDE_DIRSSven Fischer1-1/+0
Signed-off-by: Sven Fischer <sven@leiderfischer.de> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-12-05Add binary dir to target include directoriesSven Fischer1-0/+2
Build binary dir contains the libssh_version.h file. By adding the binary dir to the target include path, the include file can be found by projects which use libssh as a sub-project by add_subdirectory(). Signed-off-by: Sven Fischer <sven@leiderfischer.de> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-12-05Fix typoJamesWrigley1-1/+1
Signed-off-by: James Wrigley <james@puiterwijk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-12-04Introduce sftp async i/o (aio) apiEshan Kelkar3-0/+496
The existing sftp async read api has two problems : 1. sftp_async_read() assumes that the value of the third parameter count is same as the number of bytes requested to read in the corresponding call to sftp_async_read_begin(). But the documentation of sftp_async_read() allows the value of count parameter to be more than that requested length. If value of count parameter is more than that requested length then sftp_async_read() updates the file->offset incorrectly which leads to further read/writes occuring from incorrect offsets. The problem here is that sftp_async_read() doesn't know about the number of bytes requested to read specified in the call to sftp_async_read_begin(), and it wrongly assumes the value of its count parameter (which is actually the size of the buffer to store the read data) to be the same as the number of bytes requested to read. 2. sftp_async_read_begin() returns an uint32_t type value type casted to int as a request identifier, whereas sftp_async_read() expects an uint32_t type value as a request identifier. Due to this the user has to typecast the identifier returned by sftp_async_read_begin() from int to uint32_t and then pass it to sftp_async_read(). This type casting is cumbersome for the user and hence the approach is not user-friendly. This commit solves the above two problems by introducing a new sftp aio api. The sftp_aio_begin_*() functions in the api send an i/o request to the sftp server and provide the caller a dynamically allocated structure storing information about the sent request. Information like number of bytes requested for i/o, id of sent request etc is stored in the structure. That structure should be provided to the sftp_aio_wait_*() functions in the api which wait for the response corresponding to the request whose info is stored in the provided structure. The libssh user is supposed to handle that structure through an opaque type sftp_aio. Since the structure stores the number of bytes requested for i/o, sftp_aio_wait_*() knows about the number of bytes requested for i/o (specified in the call to sftp_aio_begin_*()) and hence updates the file->offset correctly solving problem #1 present in the existing async api. Since the structure provided by sftp_aio_begin_*() (containing the request id) is supplied to sftp_aio_wait_*(), no casting of id's needs to be done by the user solving problem #2 of the existing async api. Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Sahana Prasad <sahana@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-12-04Reformat sftp_common.c according to current coding style.Eshan Kelkar1-347/+370
Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Sahana Prasad <sahana@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-12-04Move certain functions from sftp.c to a new file sftp_common.cEshan Kelkar3-867/+891
Currently the sftp api code is limited to sftp.c, sftpserver.c In future it can be required to add new sftp related APIs which are present in their own separate source files instead of adding their code to the already large sftp.c file. Those new hypothetical or existing (in sftpserver.c) sftp API functions present in the source files other than sftp.c will need to call certain functions present in sftp.c which are not provided in the public api as they are for internal use (by other sftp related functions) only. Some of these sftp.c functions have external linkage, some of them don't and cannot be currently accessed outside sftp.c This commit : 1. Moves such functions along with the functions they depend on from sftp.c to a new file sftp_common.c, to seperate them out from other sftp api functions. 2. Makes necessary changes to make required functions visible outside sftp_common.c 3. Uses the header file sftp_priv.h for necessary declarations (and not sftp.h) since these functions are not to be provided in the public sftp api. Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Sahana Prasad <sahana@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-11-22Adding expand-path@openssh.com extension for clientanshul agrawal1-0/+94
Signed-off-by: anshul agrawal <anshulagrawal2902@gmail.com> Reviewed-by: Sahana Prasad <sahana@redhat.com> Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-11-22pki: Initialize pointers and avoid buffer overrunJakub Jelen1-3/+7
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com> Reviewed-by: Eshan Kelkar <eshankelkar@galorithm.com>
2023-10-31session: Free agent state on windowsJakub Jelen1-5/+1
Fixes: #220 Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com>
2023-09-25Adding support for limits@openssh.com on client sideanfanite3961-0/+116
Signed-off-by: anfanite396 <dipamt1729@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-09-15sftp: Cap maximum SFTP writeJakub Jelen1-0/+11
The curl does not do any (or enough) chunking when writing large files using the sftp_write() function which causes some servers to choke [1]. The simplest solution is to limit the SFTP packet size according the SFTP specification recommendation which is 32768 B and not write more. This means the function will not write the whole amount of data it was asked to write and the calling applications are required to handle the return values correctly. More complicated solution would be to send several SFTP packet from the single sftp_write() function by iterating over the all data passed. The next improvement in the long term should be respecting the value reported by the server in the limits@openssh.com extension, which specifies the maximum packet size and reads/writes explicitly (if supported). [1] https://github.com/curl/curl/pull/11804 Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-09-13poll: Avoid passing other events to callbacks when called recursivelyJakub Jelen1-2/+9
Some architectures (s390x) provide different poll events such as POLLHUP in case the remote end closed the connection (and they keep reporting this forever). This is an issue when the user provided callback registering this event as an error and tries to send some reply (for example EOF) using `ssh_channel_send_eof()` which will lead to infinite recursion and sefgaults. This was not solved by the 30b5a2e33bf260062dd31c9c0e98cf9982b08961 because the POLLHUP event is not provided by the poll in events bitfield, but only reported by the poll in revents bit field thus we need to filter these events later on when the poll is recursively. Fixes #202 Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-09-13poll: Drop all events except POLLOUT when called recursivelyJakub Jelen1-3/+3
The FD locking was modified in 30b5a2e33bf260062dd31c9c0e98cf9982b08961 but it caused some weird issues on s390x in Debian tests, which were getting POLLHUP, causing infinite recursion while the callback tried to close socket. Previously, the lock blocked only the POLLIN events as we believed these were the only events we could get recursively that could cause issues. But it looks like more sane behavior will be blocking everything but POLLOUT to allow the buffers to be flushed. Fixes #202 Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-09-08Revert the control flow callback in commitSahana Prasad1-0/+25
https://gitlab.com/libssh/libssh-mirror/-/commit/6f029598c78dd999b3773ce1bc54e390d5b7ec57 Signed-off-by: Sahana Prasad <sahana@redhat.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-09-08Allow sending data payloads of remote_maxpacket length.Tom Deseyn1-8/+5
Signed-off-by: Tom Deseyn <tom.deseyn@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-09-01channel: use a larger window size to increase receive throughput.Tom Deseyn1-53/+55
The window size controls how much data the peer can send before we send back a message to to increase the window. This changes the default window from 1.28MB to 2MiB. 2MiB matches the OpenSSH default session size. The code is also refactored to grow the windows on code paths where data is consumed, and move the condition that checks if the growing the window is needed into the grow method. Signed-off-by: Tom Deseyn <tom.deseyn@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2023-08-25crypto: Add ssh_crypto_free().Simon Josefsson3-9/+3
The intention is that this releases memory allocated by the crypto library, for functions like bignum_bn2hex() and bignum_bn2dec(). Consequently, ssh_gcry_bn2dec and ssh_mbedcry_bn2num should use gcry_malloc() and mbedtls_calloc() respectively to allocate memory since it will/should be released by ssh_crypto_free() so that the internal APIs are consistent between crypto libraries. Signed-off-by: Simon Josefsson <simon@josefsson.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-08-22misc.c : Introduce ssh_writen()Eshan Kelkar1-0/+51
A call to write() may perform a short write on a local file. To avoid short writes, ssh_writen() can be used. Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-08-22misc.c : Introduce ssh_readn()Eshan Kelkar1-0/+60
A call to read() may peform a short read from a local file even when sufficient data is present in the file. ssh_readn() can be used instead of read() to avoid such short reads. Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-08-22mbedcrypto: Make bignum_bn2dec() return char*.Simon Josefsson1-2/+2
This aligns it with libgcrypt/OpenSSL backends which uses char*. It also aligns mbedcrypto's bignum_bn2hex() to use an unsigned cast just like OpenSSL backend. Signed-off-by: Simon Josefsson <simon@josefsson.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-08-07channels: Do not be so picky about the extended data typeJakub Jelen1-3/+2
assume stderr by default and log only warning in case the data type is non-standard. Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-08-07channels: Fix reading stderr from channelsJakub Jelen1-1/+2
broken in 4b8db203b00a5b80191d95e4a6eb6a3159a918b0 Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-08-02add control master and path optionAhsen Kamal3-2/+115
Signed-off-by: Ahsen Kamal <itsahsenkamal@gmail.com> Reviewed-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-07-11priv.h : Add compatibility code for WindowsEshan Kelkar4-43/+1
Compatibility code for mapping open, read, write, close and unlink to _open, _read, _write, _close and _unlink respectively on Windows was repeated in a lot of .c files. This commit adds that compatibility code to include/libssh/priv.h and removes it from the .c files (while ensuring that those .c files include priv.h) so that the compatibility code stays in one place, can be maintained easily and can be added easily to another source file by including priv.h in that file. Signed-off-by: Eshan Kelkar <eshankelkar@galorithm.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Jakub Jelen <jjelen@redhat.com>
2023-07-11sftpserver: Add missing allocation check that might cause NULL dereferenceJakub Jelen1-0/+6
Originally reported by Wei Chong Tan <shellcurity at protonmail.com> Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-07-11gssapi: Rewrite allocation check to avoid zero_structptJakub Jelen1-3/+2
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-07-11misc: Reformat allocation checksJakub Jelen1-3/+5
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-07-11pcap: ReformatJakub Jelen1-113/+144
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-06-28ecdh_crypto: Avoid memory leak on error conditionJakub Jelen1-0/+1
CID 1034574 Thanks coverity Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-06-28scp: Make sure arguments are saneJakub Jelen1-1/+1
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-06-28channels: Avoid out-of-bounds writesJakub Jelen1-3/+9
CID 1470005 Thanks coverity Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-06-28session: Avoid potential null dereference on low-memory conditionsJakub Jelen1-0/+4
CID 1500478 Thanks coverity Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-06-28sftpserver: Check return value ssh_buffer_get_u32Jakub Jelen1-1/+4
CID 1513157 Thanks coverity Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-06-28sftpserver: Reformat remaining conditionJakub Jelen1-1/+1
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-06-28sftpserver: Set OOM only if allocation failsJakub Jelen1-3/+2
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-06-28sftpserver: Initialize pointersJakub Jelen1-2/+2
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-06-26Deprecate SSH_BIND_OPTIONS_{RSA,ECDSA}KEY in favor of generic HOSTKEYJakub Jelen1-17/+8
Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Norbert Pocs <npocs@redhat.com>
2023-06-22sftpserver: Avoid unreachable code lineJakub Jelen1-3/+1
CID 1513155 Thanks coverity Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Sahana Prasad <sahana@redhat.com>