diff options
Diffstat (limited to 'libs')
45 files changed, 2971 insertions, 7110 deletions
diff --git a/libs/libssh2/docs/NEWS b/libs/libssh2/docs/NEWS index 4c7f1eacf3..f48ae35713 100644 --- a/libs/libssh2/docs/NEWS +++ b/libs/libssh2/docs/NEWS @@ -1,5941 +1,3 @@ - Changelog for the libssh2 project. Generated with git2news.pl +The old NEWS file. -GitHub (19 Jun 2019) -- [Will Cosgrove brought this change] - - 1.9 Formatting - -- [Will Cosgrove brought this change] - - 1.9 Release notes - -Will Cosgrove (17 May 2019) -- [Alexander Curtiss brought this change] - - libgcrypt.c : Fixed _libssh2_rsa_sha1_sign memory leak. (#370) - - File: libgcrypt.c - - Notes : Added calls to gcry_sexp_release to free memory allocated by gcry_sexp_find_token - - Credit : - Reporter : beckmi - PR by: Alexander Curtiss - -- [Orivej Desh brought this change] - - libssh2_priv.h : Fix musl build warning on sys/poll.h (#346) - - File : libssh2_priv.h - - Notes : - musl prints `redirecting incorrect #include <sys/poll.h> to <poll.h>` - http://git.musl-libc.org/cgit/musl/commit/include/sys/poll.h?id=54446d730cfb17c5f7bcf57f139458678f5066cc - - poll is defined by POSIX to be in poll.h: - http://pubs.opengroup.org/onlinepubs/7908799/xsh/poll.html - - Credit : Orivej Desh - -GitHub (1 May 2019) -- [Will Cosgrove brought this change] - - kex.c : additional bounds checks in diffie_hellman_sha1/256 (#361) - - Files : kex.c, misc.c, misc.h - - Notes : - Fixed possible out of bounds memory access when reading malformed data in diffie_hellman_sha1() and diffie_hellman_sha256(). - - Added _libssh2_copy_string() to misc.c to return an allocated and filled char buffer from a string_buf offset. Removed no longer needed s var in kmdhgGPshakex_state_t. - -Will Cosgrove (26 Apr 2019) -- [Tseng Jun brought this change] - - sftp.c : sftp_bin2attr() Correct attrs->gid assignment (#366) - - Regression with fix for #339 - - Credit : Tseng Jun - -- [Tseng Jun brought this change] - - kex.c : Correct type cast in curve25519_sha256() (#365) - -GitHub (24 Apr 2019) -- [Will Cosgrove brought this change] - - transport.c : scope local total_num var (#364) - - file : transport.c - notes : move local `total_num` variable inside of if block to prevent scope access issues which caused #360. - -Will Cosgrove (24 Apr 2019) -- [doublex brought this change] - - transport.c : fixes bounds check if partial packet is read - - Files : transport.c - - Issue : #360 - - Notes : - 'p->total_num' instead of local value total_num when doing bounds check. - - Credit : Doublex - -GitHub (23 Apr 2019) -- [Will Cosgrove brought this change] - - Editor config file for source files (#322) - - Simple start to an editor config file when editing source files to make sure they are configured correctly. - -- [Will Cosgrove brought this change] - - misc.c : String buffer API improvements (#332) - - Files : misc.c, hostkey.c, kex.c, misc.h, openssl.c, sftp.c - - Notes : - * updated _libssh2_get_bignum_bytes and _libssh2_get_string. Now pass in length as an argument instead of returning it to keep signedness correct. Now returns -1 for failure, 0 for success. - - _libssh2_check_length now returns 0 on success and -1 on failure to match the other string_buf functions. Added comment to _libssh2_check_length. - - Credit : Will Cosgrove - -Will Cosgrove (19 Apr 2019) -- [doublex brought this change] - - mbedtls.c : _libssh2_mbedtls_rsa_new_private_frommemory() allow private-key from memory (#359) - - File : mbedtls.c - - Notes: _libssh2_mbedtls_rsa_new_private_frommemory() fixes private-key from memory reading to by adding NULL terminator before parsing; adds passphrase support. - - Credit: doublex - -- [Ryan Kelley brought this change] - - Session.c : banner_receive() from leaking when accessing non ssh ports (#356) - - File : session.c - - Release previous banner in banner_receive() if the session is reused after a failed connection. - - Credit : Ryan Kelley - -GitHub (11 Apr 2019) -- [Will Cosgrove brought this change] - - Formatting in agent.c - - Removed whitespace. - -- [Will Cosgrove brought this change] - - Fixed formatting in agent.c - - Quiet linter around a couple if blocks and pointer. - -Will Cosgrove (11 Apr 2019) -- [Zhen-Huan HWANG brought this change] - - sftp.c : discard and reset oversized packet in sftp_packet_read() (#269) - - file : sftp.c - - notes : when sftp_packet_read() encounters an sftp packet which exceeds SFTP max packet size it now resets the reading state so it can continue reading. - - credit : Zhen-Huan HWANG - -GitHub (11 Apr 2019) -- [Will Cosgrove brought this change] - - Add agent functions libssh2_agent_get_identity_path() and libssh2_agent_set_identity_path() (#308) - - File : agent.c - - Notes : - Libssh2 uses the SSH_AUTH_SOCK env variable to read the system agent location. However, when using a custom agent path you have to set this value using setenv which is not thread-safe. The new functions allow for a way to set a custom agent socket path in a thread safe manor. - -- [Will Cosgrove brought this change] - - Simplified _libssh2_check_length (#350) - - * Simplified _libssh2_check_length - - misc.c : _libssh2_check_length() - - Removed cast and improved bounds checking and format. - - Credit : Yuriy M. Kaminskiy - -- [Will Cosgrove brought this change] - - _libssh2_check_length() : additional bounds check (#348) - - Misc.c : _libssh2_check_length() - - Ensure the requested length is less than the total length before doing the additional bounds check - -Daniel Stenberg (25 Mar 2019) -- misc: remove 'offset' from string_buf - - It isn't necessary. - - Closes #343 - -- sftp: repair mtime from e1ead35e475 - - A regression from e1ead35e4759 broke the SFTP mtime logic in - sftp_bin2attr - - Also simplified the _libssh2_get_u32/u64 functions slightly. - - Closes #342 - -- session_disconnect: don't zero state, just clear the right bit - - If we clear the entire field, the freeing of data in session_free() is - skipped. Instead just clear the bit that risk making the code get stuck - in the transport functions. - - Regression from 4d66f6762ca3fc45d9. - - Reported-by: dimmaq on github - Fixes #338 - Closes #340 - -- libssh2_sftp.h: restore broken ABI - - Commit 41fbd44 changed variable sizes/types in a public struct which - broke the ABI, which breaks applications! - - This reverts that change. - - Closes #339 - -- style: make includes and examples code style strict - - make travis and the makefile rule verify them too - - Closes #334 - -GitHub (21 Mar 2019) -- [Daniel Stenberg brought this change] - - create a github issue template - -Daniel Stenberg (21 Mar 2019) -- stale-bot: activated - - The stale bot will automatically mark stale issues (inactive for 90 - days) and if still untouched after 21 more days, close them. - - See https://probot.github.io/apps/stale/ - -- libssh2_session_supported_algs.3: fix formatting mistakes - - Reported-by: Max Horn - Fixes #57 - -- [Zenju brought this change] - - libssh2.h: Fix Error C2371 'ssize_t': redefinition - - Closes #331 - -- travis: add code style check - - Closes #324 - -- code style: unify code style - - Indent-level: 4 - Max columns: 79 - No spaces after if/for/while - Unified brace positions - Unified white spaces - -- src/checksrc.pl: code style checker - - imported as-is from curl - -Will Cosgrove (19 Mar 2019) -- Merge branch 'MichaelBuckley-michaelbuckley-security-fixes' - -- Silence unused var warnings (#329) - - Silence warnings about unused variables in this test - -- Removed unneeded > 0 check - - When checking `userauth_kybd_num_prompts > 100` we don't care if it's also above zero. - -- [Matthew D. Fuller brought this change] - - Spell OpenSS_H_ right when talking about their specific private key (#321) - - Good catch, thanks. - -GitHub (19 Mar 2019) -- [Will Cosgrove brought this change] - - Silence unused var warnings (#329) - - Silence warnings about unused variables in this test - -Michael Buckley (19 Mar 2019) -- Fix more scope and printf warning errors - -- Silence unused variable warning - -GitHub (19 Mar 2019) -- [Will Cosgrove brought this change] - - Removed unneeded > 0 check - - When checking `userauth_kybd_num_prompts > 100` we don't care if it's also above zero. - -Will Cosgrove (19 Mar 2019) -- [Matthew D. Fuller brought this change] - - Spell OpenSS_H_ right when talking about their specific private key (#321) - - Good catch, thanks. - -Michael Buckley (18 Mar 2019) -- Fix errors identified by the build process - -- Fix casting errors after merge - -GitHub (18 Mar 2019) -- [Michael Buckley brought this change] - - Merge branch 'master' into michaelbuckley-security-fixes - -Michael Buckley (18 Mar 2019) -- Move fallback SIZE_MAX and UINT_MAX to libssh2_priv.h - -- Fix type and logic issues with _libssh2_get_u64 - -Daniel Stenberg (17 Mar 2019) -- examples: fix various compiler warnings - -- lib: fix various compiler warnings - -- session: ignore pedantic warnings for funcpointer <=> void * - -- travis: add a build using configure - - Closes #320 - -- configure: provide --enable-werror - -- appveyor: remove old builds that mostly cause failures - - ... and only run on master branch. - - Closes #323 - -- cmake: add two missing man pages to get installed too - - Both libssh2_session_handshake.3 and - libssh2_userauth_publickey_frommemory.3 were installed by the configure - build already. - - Reported-by: Arfrever on github - Fixes #278 - -- include/libssh2.h: warning: "_WIN64" is not defined, evaluates to 0 - - We don't use #if for defines that might not be defined. - -- pem: //-comments are not allowed - -Will Cosgrove (14 Mar 2019) -- [Daniel Stenberg brought this change] - - userauth: fix "Function call argument is an uninitialized value" (#318) - - Detected by scan-build. - -- fixed unsigned/signed issue - -Daniel Stenberg (15 Mar 2019) -- session_disconnect: clear state - - If authentication is started but not completed before the application - gives up and instead wants to shut down the session, the '->state' field - might still be set and thus effectively dead-lock session_disconnect. - - This happens because both _libssh2_transport_send() and - _libssh2_transport_read() refuse to do anything as long as state is set - without the LIBSSH2_STATE_KEX_ACTIVE bit. - - Reported in curl bug https://github.com/curl/curl/issues/3650 - - Closes #310 - -Will Cosgrove (14 Mar 2019) -- Release notes from 1.8.1 - -Michael Buckley (14 Mar 2019) -- Use string_buf in sftp_init(). - -- Guard against out-of-bounds reads in publickey.c - -- Guard against out-of-bounds reads in session.c - -- Guard against out-of-bounds reads in userauth.c - -- Use LIBSSH2_ERROR_BUFFER_TOO_SMALL instead of LIBSSH2_ERROR_OUT_OF_BOUNDARY in sftp.c - -- Additional bounds checking in sftp.c - -- Additional length checks to prevent out-of-bounds reads and writes in _libssh2_packet_add(). https://libssh2.org/CVE-2019-3862.html - -- Add a required_size parameter to sftp_packet_require et. al. to require callers of these functions to handle packets that are too short. https://libssh2.org/CVE-2019-3860.html - -- Check the length of data passed to sftp_packet_add() to prevent out-of-bounds reads. - -- Prevent zero-byte allocation in sftp_packet_read() which could lead to an out-of-bounds read. https://libssh2.org/CVE-2019-3858.html - -- Sanitize padding_length - _libssh2_transport_read(). https://libssh2.org/CVE-2019-3861.html - - This prevents an underflow resulting in a potential out-of-bounds read if a server sends a too-large padding_length, possibly with malicious intent. - -- Defend against writing beyond the end of the payload in _libssh2_transport_read(). - -- Defend against possible integer overflows in comp_method_zlib_decomp. - -GitHub (14 Mar 2019) -- [Will Cosgrove brought this change] - - Security fixes (#315) - - * Bounds checks - - Fixes for CVEs - https://www.libssh2.org/CVE-2019-3863.html - https://www.libssh2.org/CVE-2019-3856.html - - * Packet length bounds check - - CVE - https://www.libssh2.org/CVE-2019-3855.html - - * Response length check - - CVE - https://www.libssh2.org/CVE-2019-3859.html - - * Bounds check - - CVE - https://www.libssh2.org/CVE-2019-3857.html - - * Bounds checking - - CVE - https://www.libssh2.org/CVE-2019-3859.html - - and additional data validation - - * Check bounds before reading into buffers - - * Bounds checking - - CVE - https://www.libssh2.org/CVE-2019-3859.html - - * declare SIZE_MAX and UINT_MAX if needed - -- [Will Cosgrove brought this change] - - fixed type warnings (#309) - -- [Will Cosgrove brought this change] - - Bumping version number for pending 1.8.1 release - -Will Cosgrove (4 Mar 2019) -- [Daniel Stenberg brought this change] - - _libssh2_string_buf_free: use correct free (#304) - - Use LIBSSH2_FREE() here, not free(). We allow memory function - replacements so free() is rarely the right choice... - -GitHub (26 Feb 2019) -- [Will Cosgrove brought this change] - - Fix for building against libreSSL #302 - - Changed to use the check we use elsewhere. - -- [Will Cosgrove brought this change] - - Fix for when building against LibreSSL #302 - -Will Cosgrove (25 Feb 2019) -- [gartens brought this change] - - docs: update libssh2_hostkey_hash.3 [ci skip] (#301) - -GitHub (21 Feb 2019) -- [Will Cosgrove brought this change] - - fix malloc/free mismatches #296 (#297) - -- [Will Cosgrove brought this change] - - Replaced malloc with calloc #295 - -- [Will Cosgrove brought this change] - - Abstracted OpenSSL calls out of hostkey.c (#294) - -- [Will Cosgrove brought this change] - - Fix memory dealloc impedance mis-match #292 (#293) - - When using ed25519 host keys and a custom memory allocator. - -- [Will Cosgrove brought this change] - - Added call to OpenSSL_add_all_digests() #288 - - For OpenSSL 1.0.x we need to call OpenSSL_add_all_digests(). - -Will Cosgrove (12 Feb 2019) -- [Zhen-Huan HWANG brought this change] - - SFTP: increase maximum packet size to 256K (#268) - - to match implementations like OpenSSH. - -- [Zenju brought this change] - - Fix https://github.com/libssh2/libssh2/pull/271 (#284) - -GitHub (16 Jan 2019) -- [Will Cosgrove brought this change] - - Agent NULL check in shutdown #281 - -Will Cosgrove (15 Jan 2019) -- [Adrian Moran brought this change] - - mbedtls: Fix leak of 12 bytes by each key exchange. (#280) - - Correctly free ducts by calling _libssh2_mbedtls_bignum_free() in dtor. - -- [alex-weaver brought this change] - - Fix error compiling on Win32 with STDCALL=ON (#275) - -GitHub (8 Nov 2018) -- [Will Cosgrove brought this change] - - Allow default permissions to be used in sftp_mkdir (#271) - - Added constant LIBSSH2_SFTP_DEFAULT_MODE to use the server default permissions when making a new directory - -Will Cosgrove (13 Sep 2018) -- [Giulio Benetti brought this change] - - openssl: fix dereferencing ambiguity potentially causing build failure (#267) - - When dereferencing from *aes_ctr_cipher, being a pointer itself, - ambiguity can occur; fixed possible build errors. - -Viktor Szakats (12 Sep 2018) -- win32/GNUmakefile: define HAVE_WINDOWS_H - - This macro was only used in test/example code before, now it is - also used in library code, but only defined automatically by - automake/cmake, so let's do the same for the standalone win32 - make file. - - It'd be probably better to just rely on the built-in _WIN32 macro - to detect the presence of windows.h though. It's already used - in most of libssh2 library code. There is a 3rd, similar macro - named LIBSSH2_WIN32, which might also be replaced with _WIN32. - - Ref: https://github.com/libssh2/libssh2/commit/8b870ad771cbd9cd29edbb3dbb0878e950f868ab - Closes https://github.com/libssh2/libssh2/pull/266 - -Marc Hoersken (2 Sep 2018) -- Fix conditional check for HAVE_DECL_SECUREZEROMEMORY - - "Unlike the other `AC_CHECK_*S' macros, when a symbol is not declared, - HAVE_DECL_symbol is defined to `0' instead of leaving HAVE_DECL_symbol - undeclared. When you are sure that the check was performed, - use HAVE_DECL_symbol in #if." - - Source: autoconf documentation for AC_CHECK_DECLS. - -- Fix implicit declaration of function 'SecureZeroMemory' - - Include window.h in order to use SecureZeroMemory on Windows. - -- Fix implicit declaration of function 'free' by including stdlib.h - -GitHub (27 Aug 2018) -- [Will Cosgrove brought this change] - - Use malloc abstraction function in pem parse - - Fix warning on WinCNG build. - -- [Will Cosgrove brought this change] - - Fixed possible junk memory read in sftp_stat #258 - -- [Will Cosgrove brought this change] - - removed INT64_C define (#260) - - No longer used. - -- [Will Cosgrove brought this change] - - Added conditional around engine.h include - -Will Cosgrove (6 Aug 2018) -- [Alex Crichton brought this change] - - Fix OpenSSL link error with `no-engine` support (#259) - - This commit fixes linking against an OpenSSL library that was compiled with - `no-engine` support by bypassing the initialization routines as they won't be - available anyway. - -GitHub (2 Aug 2018) -- [Will Cosgrove brought this change] - - ED25519 Key Support #39 (#248) - - OpenSSH Key and ED25519 support #39 - Added _libssh2_explicit_zero() to explicitly zero sensitive data in memory #120 - - * ED25519 Key file support - Requires OpenSSL 1.1.1 or later - * OpenSSH Key format reading support - Supports RSA/DSA/ECDSA/ED25519 types - * New string buffer reading functions - These add build-in bounds checking and convenance methods. Used for OpenSSL PEM file reading. - * Added new tests for OpenSSH formatted Keys - -- [Will Cosgrove brought this change] - - ECDSA key types are now explicit (#251) - - * ECDSA key types are now explicit - - Issue was brough up in pull request #248 - -Will Cosgrove (2 May 2018) -- [Jakob Egger brought this change] - - Add Instructions for building from Master (#249) - -GitHub (27 Apr 2018) -- [Will Cosgrove brought this change] - - Initialize sb_intl #226 - -Will Cosgrove (19 Apr 2018) -- [doublex brought this change] - - buffer overflow (valgrind) (#159) - -- [Brendan Shanks brought this change] - - mbedTLS: Remove some C99-style intermingled variable declarations (#196) - -GitHub (18 Apr 2018) -- [Will Cosgrove brought this change] - - fix for #160 - -Will Cosgrove (18 Apr 2018) -- [doublex brought this change] - - fix memory leak when using mbedtls backend (#158) - - _libssh2_bn_init_from_bin/_libssh2_bn_free would leak bignum from mbedtls_calloc(). - -- [Brendan Shanks brought this change] - - mbedTLS: Avoid multiple definition errors for context handles (#197) - -- [Tseng Jun brought this change] - - Fix the EVP cipher meth memory leakage problem (#244) - - * Fix the EVP cipher meth memory leakage problem - - Looks good, thanks for the fixes. - -Marc Hörsken (31 Mar 2018) -- [Will Cosgrove brought this change] - - Added ECDSA defines for WinCNG (#245) - - Fixed missing defines preventing building using WinCNG - -GitHub (30 Mar 2018) -- [Will Cosgrove brought this change] - - Fix for _libssh2_rsa_new with OpenSSL 1.0.x - - missing d value assignment. - -Will Cosgrove (20 Mar 2018) -- [Etienne Samson brought this change] - - A collection of small fixes (#198) - - * tests: Remove if-pyramids - - * tests: Switch run_command arguments - - * tests: Make run_command a vararg function - - * tests: Xcode doesn't obey CMake's test working directory - - * openssl: move manual AES-CTR cipher into crypto init - - * cmake: Move our include dir before all other include paths - -GitHub (15 Mar 2018) -- [Will Cosgrove brought this change] - - Fixes incorrect indexing of KEX prefs string - - After stripping out an invalid KEX pref entry, it would incorrectly advance again leaving invalid values in the list. - -Viktor Szakats (13 Mar 2018) -- tests: fix checksrc warnings - - Also: - * add 'static' qualifier to file-wide const buffers - * fix a non-ANSI C89 comment - * silence a mismatched fprintf() mask warning by adding a cast - -- cmake: recognize OpenSSL 1.1 .dll names - - Also fix some comment typos and a stray tab. - -- docs: update an URL [ci skip] - -Daniel Stenberg (12 Mar 2018) -- docs/SECURITY: the max embargo is 14 days now - -Viktor Szakats (12 Mar 2018) -- docs: spelling fixes [ci skip] - - Closes https://github.com/libssh2/libssh2/pull/222 - -GitHub (12 Mar 2018) -- [Will Cosgrove brought this change] - - Fixed minor tabs/spacing issues - -- [Will Cosgrove brought this change] - - Update kex.c - -- [Will Cosgrove brought this change] - - Added basic bounds checking #206 - - Basic bounds checking in ecdh_sha2_nistp() - -- [Will Cosgrove brought this change] - - Fixed Clang warning #206 - - Fixed possible garbage value for secret in an error case - -- [Will Cosgrove brought this change] - - Fixed incorrect #if to #ifdef #206 - - When checking HAVE_OPAQUE_STRUCTS. - -Viktor Szakats (12 Mar 2018) -- src: suppress two checksrc warnings - - Ref: https://github.com/libssh2/libssh2/pull/235 - -- src: address fopen() warnings, add missing copyright headers - - Ref: https://github.com/libssh2/libssh2/pull/235 - -- src: replace sprintf() with snprintf() - - Ref: https://github.com/libssh2/libssh2/pull/235 - -- src: fix checksrc warnings - - Use checksrc.pl from the curl project, with (for now) - suppressed long line warnings and indentation set to - 4 spaces. Fixes are whitespace for the most part. - - Warning count went down from 2704 to 12. - - Also fix codespell typos, two non-ANSI C89 comments - and a stray tab in include/libssh2.h. - - Ref: https://github.com/libssh2/libssh2/pull/235 - -- checksrc: add source style checker - - This is a slightly extended version of this original source - from the curl project: - https://github.com/curl/curl/blob/8b754c430b9a4c51aa606c687ee5014faf7c7b06/lib/checksrc.pl - - This version adds the following options to customize it for - libssh2 (plus some whitespace formatting): - - `-i<n>` to override indentation spaces (2) - `-m<n>` to override maximum line length (79) - - Command-line used to check libssh2 sources: - - $ ./checksrc.pl -i4 -m500 *.c *.h - - Closes https://github.com/libssh2/libssh2/pull/236 - -- src: add static qualifier - - To private, const strings. - - Closes https://github.com/libssh2/libssh2/pull/237 - -- [Will Cosgrove brought this change] - - Add support for ECDSA keys and host keys (#41) - - This commit lands full ECDSA key support when using the OpenSSL - backend. Which includes: - - New KEX methods: - ecdsa-sha2-nistp256, ecdsa-sha2-nistp384, ecdsa-sha2-nistp521 - - Can now read OpenSSL formatted ECDSA key files. - - Now supports known host keys of type ecdsa-sha2-nistp256. - - New curve types: - NID_X9_62_prime256v1, NID_secp384r1, NID_secp521r1 - - Default host key preferred ordering is now nistp256, nistp384, - nistp521, rsa, dss. - - Ref: https://github.com/libssh2/libssh2/issues/41 - - Closes https://github.com/libssh2/libssh2/pull/206 - -GitHub (15 Dec 2017) -- [Will Cosgrove brought this change] - - Fixed possible crash when decoding invalid data - - When trying to decode invalid data, it frees the buffer but doesn't nil it so the caller gets a junk memory pointer which they could potentially double free. - -- [Will Cosgrove brought this change] - - Remove call to OpenSSL_add_all_ciphers() - - Now lives in libssh2 init() from PR #189 - -- [Will Cosgrove brought this change] - - Fixed incorrect reference to decrypted block - - Fixed incorrectly copied memory from p->buf into init instead of from the decrypted buffer block. The only reason this worked was because the crypt() function decrypts the value in-place and overwrites p->buf. I'm working on a fork that no longer does this and exposed this bug. - -Will Cosgrove (20 Oct 2017) -- [Pan brought this change] - - Fix typo in crypt.c (#218) - -Kamil Dudka (17 Oct 2017) -- session: avoid printing misleading debug messages - - ... while throwing LIBSSH2_ERROR_EAGAIN out of session_startup() - - If the session runs in blocking mode, LIBSSH2_ERROR_EAGAIN never reaches - the libssh2 API boundary and, in non-blocking mode, these messages are - suppressed by the condition in _libssh2_error_flags() anyway. - - Closes #211 - -Viktor Szakats (15 Oct 2017) -- win32/GNUmakefile: allow customizing dll suffixes - - - New `LIBSSH2_DLL_SUFFIX` envvar will add a suffix to the generated - libssh2 dll name. Useful to add `-x64` to 64-bit builds so that - it can live in the same directory as the 32-bit one. By default - this is empty. - - - New `LIBSSH2_DLL_A_SUFFIX` envvar to customize the suffix of the - generated import library (implib) for libssh2 .dll. It defaults - to `dll`, and it's useful to modify that to `.dll` to have the - standard naming scheme for mingw-built .dlls, i.e. `libssh2.dll.a`. - - Ref: https://github.com/curl/curl/commit/aaa16f80256abc1463fd9374815130a165222257 - - Closes https://github.com/libssh2/libssh2/pull/215 - -- makefile.m32: allow to override gcc, ar and ranlib - - Allow to ovverride certain build tools, making it possible to - use LLVM/Clang to build libssh2. The default behavior is unchanged. - To build with clang (as offered by MSYS2), these settings can - be used: - - LIBSSH2_CC=clang - LIBSSH2_AR=llvm-ar - LIBSSH2_RANLIB=llvm-ranlib - - Also adjust ranlib parameters to be compatible with LLVM/Clang's - ranlib tool. - - Closes https://github.com/libssh2/libssh2/pull/214 - -GitHub (27 Sep 2017) -- [Will Cosgrove brought this change] - - Fixes out of bounds memory access (#210) - - If an invalid PEM file is read and the lines are longer than 128 characters it will go out of bounds and crash on line 91. - -Will Cosgrove (11 Sep 2017) -- [Kamil Dudka brought this change] - - scp: do not NUL-terminate the command for remote exec (#208) - - It breaks SCP download/upload from/to certain server implementations. - - The bug does not manifest with OpenSSH, which silently drops the NUL - byte (eventually with any garbage that follows the NUL byte) before - executing it. - - Bug: https://bugzilla.redhat.com/1489736 - -GitHub (21 Aug 2017) -- [Viktor Szakats brought this change] - - openssl.c: remove no longer used variable (#204) - - after e378d2e30a40bd9bcee06dc3a4250f269098e200 - -- [Will Cosgrove brought this change] - - Fix for #188 (#189) - - * Update openssl.c - - * Create openssl.h - -Will Cosgrove (24 May 2017) -- [Marcel Raad brought this change] - - openssl: fix build with OpenSSL 1.1 API (#176) - - When building with OPENSSL_API_COMPAT=0x10100000L, OpenSSL_add_all_algorithms - and OpenSSL_add_all_ciphers don't exist. The corresponding functionality is - handled automatically with OpenSSL 1.1. - -- [Sune Bredahl brought this change] - - Add support for SHA256 hostkey fingerprints (#180) - - Looks good, thanks! - -GitHub (12 May 2017) -- [Will Cosgrove brought this change] - - Fix memory leak of crypt_ctx->h using openSSL 1.1+ (#177) - - Need to use EVP_CIPHER_CTX_free instead of EVP_CIPHER_CTX_reset. - -Marc Hoersken (2 Mar 2017) -- tests/openssh_server/authorized_keys: add key_rsa_encrypted.pub - -- tests: add simple test for passphrase-protected PEM file support - -- os400qc3: enable passphrase-protected PEM file support using pem.c - -- pem: fix indentation and replace assert after 386e012292 - -- [Keno Fischer brought this change] - - pem: add passphrase-protected PEM file support for libgcrypt and wincng - - Since they use our own PEM parser which did not support encrypted - PEM files, trying to use such files on these backends failed. - Fix that by augmenting the PEM parser to support encrypted PEM files. - -- [Thomas brought this change] - - misc: use time constant implementation for AES CTR increment - -- [Thomas brought this change] - - wincng: add AES CTR mode support (aes128-ctr, aes192-ctr, aes256-ctr) - -- [Thomas brought this change] - - openssl: move shared AES-CTR code into misc - -Daniel Stenberg (20 Dec 2016) -- [Alex Crichton brought this change] - - kex: acknowledge error code from libssh2_dh_key_pair() - - Fixes a segfault using ssh-agent on Windows - - This commit fixes a segfault seen dereferencing a null pointer on - Windows when using ssh-agent. The problem ended up being that errors - weren't being communicated all the way through, causing null pointers to - be used when functions should have bailed out sooner. - - The `_libssh2_dh_key_pair` function for WinCNG was modified to propagate - errors, and then the two callsites in kex.c of - `diffie_hellman_sha{1,256}` were updated to recognize this error and - bail out. - - Fixes #162 - Closes #163 - -Alexander Lamaison (27 Nov 2016) -- [monnerat brought this change] - - Implement Diffie-Hellman computations in crypto backends. (#149) - - Not all backends feature the low level API needed to compute a Diffie-Hellman - secret, but some of them directly implement Diffie-Hellman support with opaque - private data. The later approach is now generalized and backends are - responsible for all Diffie Hellman computations. - As a side effect, procedures/macros _libssh2_bn_rand and _libssh2_bn_mod_exp - are no longer needed outside the backends. - -Peter Stuge (16 Nov 2016) -- acinclude.m4: The mbedtls crypto backend actually requires libmbedcrypto - - Examples can't be linked with libmbedtls but need libmbedcrypto, and - any users of libssh2 which use libtool and libssh2.la would encounter - the same problem. - - This changes the mbedtls detection to search for libmbedcrypto, which - is the actual dependency for the backend. - -- acinclude.m4: Add CPPFLAGS=-I$prefix-dir/include in LIBSSH2_LIB_HAVE_LINKFLAGS - - This is absolutely neccessary for header files to be found when - AC_LIB_HAVE_LINKFLAGS searches for libraries. - -- acinclude.m4: Make saved variables in LIBSSH2_LIB_HAVE_LINKFLAGS uniform - -- docs/HACKING.CRYPTO: Improve documentation for autoconf build system - -Alexander Lamaison (16 Nov 2016) -- [Alex Arslan brought this change] - - Check for netinet/in.h in the tests cmake file (#148) - -- [Patrick Monnerat brought this change] - - Define new Diffie-Hellman context for mbedTLS - -- [monnerat brought this change] - - Make libssh2 work again on os400. (#118) - - * os400: minimum supported OS version is now V6R1. - Do not log compiler informational messages. - - * Implement crypto backend specific Diffie-Hellman computation. - - This feature is now needed on os400 because the QC3 library does not - implement bn_mod_exp() natively. Up to now, this function was emulated using - an RSA encryption, but commits ca5222ea819cc5ed797860070b4c6c1aeeb28420 and - 7934c9ce2a029c43e3642a492d3b9e494d1542be (CVE-2016-0787) broke the emulation - because QC3 only supports RSA exponents up to 512 bits. - - Happily, QC3 supports a native API for Diffie-Hellman computation, with - opaque random value: this commit implements the use of this API and, as a - side effect, enables support of this feature for any other crypto backend that - would use it. - - A "generic" Diffie-Hellman computation internal API supports crypto backends - not implementing their own: this generic API uses the same functions as before. - - * Fix typos in docs/HACKING.CRYPTO. - -- [Peter Stuge brought this change] - - acinclude.m4: Fixup OpenSSL EVP_aes_128_ctr() detection - -- [Peter Stuge brought this change] - - configure.ac: Add --with-crypto= instead of many different --with-$backend - - The new --with-crypto option replaces the previous backend-specific - --with-{openssl,libgcrypt,mbedtls,wincng} options and fixes some issues. - - * libgcrypt or mbedtls would previously be used whenever found, even - if configure was passed --without-libgcrypt or --without-mbedtls. - - * If --with-$backend was specified then configure would not fail even - if that library could not be found, and would instead use whichever - crypto library was found first. - - The new option defaults to `auto`, which makes configure check for all - supported crypto libraries in turn, choosing the first one found, or - exiting with an error if none can be found. - -- [Tony Kelman brought this change] - - Build mbedtls from source on Travis (#133) - - * Revert "Revert "travis: Test mbedtls too"" - - This reverts commit c4c60eac5ca756333034b07dd9e0b97741493ed3. - - * travis: Build mbedtls from source on Travis - - Use TOOLCHAIN_OPTION when calling cmake on mbedtls - - * tests: only run DSA tests for non-mbedtls - - crypto backends - -- [Peter Stuge brought this change] - - configure.ac src/Makefile.am: Remove dead AM_CONDITIONAL(OS400QC3) - - According to os400/README400 this backend can not be built - with configure+make, and the conditional is hard coded to false. - -- [Peter Stuge brought this change] - - configure.ac: Add -DNDEBUG to CPPFLAGS in non-debug builds - - There are a few uses of assert() in channel.c, sftp.c and transport.c. - -- [Peter Stuge brought this change] - - src/global.c: Fix conditional AES-CTR support - - Most of libssh2 already has conditional support for AES-CTR according to - the LIBSSH2_AES_CTR crypto backend #define, but global.c needed fixing. - -- [Peter Stuge brought this change] - - src/crypto.h src/userauth.c: Fix conditional RSA support - - Most of libssh2 already has conditional support for RSA according to - the LIBSSH2_RSA crypto backend #define, but crypto.h and userauth.c - needed a few small fixes. - -- [Peter Stuge brought this change] - - src/kex.c: Cast libssh2_sha{1,256}_update data arguments properly - - The update functions take a const unsigned char * but were called - with (const) char * in some places, causing unneccessary warnings. - -- [Peter Stuge brought this change] - - docs/HACKING.CRYPTO: Fix two type typos - -- [Sergei Trofimovich brought this change] - - acinclude.m4: fix ./configure --with-libgcrypt - - The change fixes passing of bogus gcrypt prefix. - Reproducible as: - - $ ./configure --with-libgcrypt - $ make V=1 - ... - /bin/sh ../libtool --tag=CC --mode=link gcc -g -O2 -Iyes/include -version-info 1:1:0 -no-undefined -export-symbols-regex '^libssh2_.*' -lgcrypt -lz -Lyes/lib -o libssh2.la -rpath /usr/local/lib channel.lo comp.lo crypt.lo hostkey.lo kex.lo mac.lo misc.lo packet.lo publickey.lo scp.lo session.lo sftp.lo userauth.lo transport.lo version.lo knownhost.lo agent.lo libgcrypt.lo pem.lo keepalive.lo global.lo -lgcrypt - ../libtool: line 7475: cd: yes/lib: No such file or directory - libtool: error: cannot determine absolute directory name of 'yes/lib' - - These - -Iyes/include - -Lyes/lib - come from libgcrypt code autodetection: - if test -n "$use_libgcrypt" && test "$use_libgcrypt" != "no"; then - LDFLAGS="$LDFLAGS -L$use_libgcrypt/lib" - CFLAGS="$CFLAGS -I$use_libgcrypt/include" - - I assume it's a typo to use yes/no flag as a prefix and changed - it to '$with_libgcrypt_prefix'. - - Reported-by: Mikhail Pukhlikov <cynede@gentoo.org> - Signed-off-by: Sergei Trofimovich <siarheit@google.com> - -- [Zenju brought this change] - - libssh2_sftp_init hang: last error not set - - The problem is that the original if statement simply returns NULL, but does not set the session last error code. The consequence is that libssh2_sftp_init() also returns NULL and libssh2_session_last_errno(sshSession) == LIBSSH2_ERROR_NONE. - - In my test the LIBSSH2_ERROR_EAGAIN is coming from sftp.c row 337: - if(4 != sftp->partial_size_len) - /* we got a short read for the length part */ - return LIBSSH2_ERROR_EAGAIN; - - with "partial_size_len == 0". Not sure if this is expected. - -- [Aidan Hobson Sayers brought this change] - - docs: correctly describe channel_wait_eof - - channel_wait_eof waits for channel->remote.eof, which is set on - receiving a `SSH_MSG_CHANNEL_EOF` message. This message is sent - when a party has no more data to send on a channel. - -- [Zenju brought this change] - - Fix MSVC 14 compilation warning (#92) - - 1> sftp.c - 1>libssh2-files\src\sftp.c(3393): warning C4456: declaration of 'retcode' hides previous local declaration - 1> libssh2-files\src\sftp.c(3315): note: see declaration of 'retcode' - -- [Salvador Fandino brought this change] - - LIBSSH2_ERROR_CHANNEL_WINDOW_FULL: add new error code - - In order to signal that the requested operation can not succeed - because the receiving window had been exhausted, the error code - LIBSSH2_ERROR_BUFFER_TOO_SMALL has been reused but I have found - that in certain context it may be ambigous. - - This patch introduces a new error code, - LIBSSH2_ERROR_CHANNEL_WINDOW_FULL, exclusive to signal that condition. - -- [Salvador Fandino brought this change] - - channel_wait_eof: handle receive window exhaustion - - Until now, in blocking mode, if the remote receiving window is - exhausted this function hangs forever as data is not read and the - remote side just keeps waiting for the window to grow before sending - more data. - - This patch, makes this function check for that condition and abort - with an error when it happens. - -- [Salvador Fandino brought this change] - - channel_wait_closed: don't fail when unread data is queued - - This function was calling channel_wait_eof to ensure that the EOF - packet has already been received, but that function also checks that - the read data queue is empty before reporting the EOF. That caused - channel_wait_closed to fail with a LIBSSH2_ERROR_INVAL when some data - was queued even after a successful call to libssh2_channel_wait_eof. - - This patch changes libssh2_channel_wait_closed to look directly into - channel->remote.eof so that both libssh2_channel_wait_eof and - libssh2_channel_wait_closed bahave consistently. - -- [Salvador Fandino brought this change] - - channel_wait_eof: fix debug message - -Daniel Stenberg (25 Oct 2016) -- libssh2.h: start working on 1.8.1 - -Version 1.8.0 (25 Oct 2016) - -Daniel Stenberg (25 Oct 2016) -- RELEASE-NOTES: adjusted for 1.8.0 - -Kamil Dudka (20 Oct 2016) -- Revert "aes: the init function fails when OpenSSL has AES support" - - This partially reverts commit f4f2298ef3635acd031cc2ee0e71026cdcda5864 - because it caused the compatibility code to call initialization routines - redundantly, leading to memory leakage with OpenSSL 1.1 and broken curl - test-suite in Fedora: - - 88 bytes in 1 blocks are definitely lost in loss record 5 of 8 - at 0x4C2DB8D: malloc (vg_replace_malloc.c:299) - by 0x72C607D: CRYPTO_zalloc (mem.c:100) - by 0x72A2480: EVP_CIPHER_meth_new (cmeth_lib.c:18) - by 0x4E5A550: make_ctr_evp.isra.0 (openssl.c:407) - by 0x4E5A8E8: _libssh2_init_aes_ctr (openssl.c:471) - by 0x4E5BB5A: libssh2_init (global.c:49) - -Daniel Stenberg (19 Oct 2016) -- [Charles Collicutt brought this change] - - libssh2_wait_socket: Fix comparison with api_timeout to use milliseconds (#134) - - Fixes #74 - -- [Charles Collicutt brought this change] - - Set err_msg on _libssh2_wait_socket errors (#135) - -- Revert "travis: Test mbedtls too" - - This reverts commit 3e6de50a24815e72ec5597947f1831f6083b7da8. - - Travis doesn't seem to support the mbedtls-dev package - -- maketgz: support "only" to only update version number locally - - and fix the date output locale - -- configure: make the --with-* options override the OpenSSL default - - ... previously it would default to OpenSSL even with the --with-[crypto] - options used unless you specificly disabled OpenSSL. Now, enabling another - backend will automatically disable OpenSSL if the other one is found. - -- [Keno Fischer brought this change] - - docs: Add documentation on new cmake/configure options - -- [Keno Fischer brought this change] - - configure: Add support for building with mbedtls - -- [wildart brought this change] - - travis: Test mbedtls too - -- [wildart brought this change] - - crypto: add support for the mbedTLS backend - - Closes #132 - -- [wildart brought this change] - - cmake: Add CLEAR_MEMORY option, analogously to that for autoconf - -- README.md: fix link typo - -- README: markdown version to look nicer on github - -Viktor Szakats (5 Sep 2016) -- [Taylor Holberton brought this change] - - openssl: add OpenSSL 1.1.0 compatibility - -Daniel Stenberg (4 Sep 2016) -- [Antenore Gatta brought this change] - - tests: HAVE_NETINET_IN_H was not defined correctly (#127) - - Fixes #125 - -- SECURITY: fix web site typo - -- SECURITY: security process - -GitHub (14 Aug 2016) -- [Alexander Lamaison brought this change] - - Basic dockerised test suite. - - This introduces a test suite for libssh2. It runs OpenSSH in a Docker - container because that works well on Windows (via docker-machine) as - well as Linux. Presumably it works on Mac too with docker-machine, but - I've not tested that. - - Because the test suite is docker-machine aware, you can also run it - against a cloud provider, for more realistic network testing, by setting - your cloud provider as your active docker machine. The Appveyor CI setup - in this commit does that because Appveyor doesn't support docker - locally. - -Kamil Dudka (3 Aug 2016) -- [Viktor Szakats brought this change] - - misc.c: Delete unused static variables - - Closes #114 - -Daniel Stenberg (9 Apr 2016) -- [Will Cosgrove brought this change] - - Merge pull request #103 from willco007/patch-2 - - Fix for security issue CVE-2016-0787 - -Alexander Lamaison (2 Apr 2016) -- [Zenju brought this change] - - Fix MSVC 14 compilation errors - - For _MSC_VER == 1900 these macros are not needed and create problems: - - - - 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdio.h(1925): warning C4005: 'snprintf': macro redefinition (compiling source file libssh2-files\src\mac.c) - - 1> \win32\libssh2_config.h(27): note: see previous definition of 'snprintf' (compiling source file libssh2-files\src\mac.c) - - 1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdio.h(1927): fatal error C1189: #error: Macro definition of snprintf conflicts with Standard Library function declaration (compiling source file libssh2-files\src\mac.c) - -Daniel Stenberg (26 Mar 2016) -- [Brad Harder brought this change] - - _libssh2_channel_open: speeling error fixed in channel error message - -Alexander Lamaison (15 Mar 2016) -- Link with crypt32.lib on Windows. - - Makes linking with static OpenSSL work again. Although it's not - required for dynamic OpenSSL, it does no harm. - - Fixes #98. - -- [Craig A. Berry brought this change] - - Tweak VMS help file building. - - Primarily this is handling cases where top-level files moved into - the docs/ directory. I also corrected a typo and removed the - claim that libssh2 is public domain. - -- [Craig A. Berry brought this change] - - Build with standard stat structure on VMS. - - This gets us large file support, is available on any VMS release - in the last decade and more, and gives stat other modern features - such as 64-bit ino_t. - -- [Craig A. Berry brought this change] - - Update vms/libssh2_config.h. - - VMS does have stdlib.h, gettimeofday(), and OpenSSL. The latter - is appropriate to hard-wire in the configuration because it's - installed by default as part of the base operating system and - there is currently no libgcrypt port. - -- [Craig A. Berry brought this change] - - VMS can't use %zd for off_t format. - - %z is a C99-ism that VMS doesn't currently have; even though the - compiler is C99-compliant, the library isn't quite. The off_t used - for the st_size element of the stat can be 32-bit or 64-bit, so - detect what we've got and pick a format accordingly. - -- [Craig A. Berry brought this change] - - Normalize line endings in libssh2_sftp_get_channel.3. - - Somehow it got Windows-style CRLF endings so convert to just LF, - for consistency as well as not to confuse tools that will regard - the \r as content (e.g. the OpenVMS help librarian). - -Dan Fandrich (29 Feb 2016) -- libgcrypt: Fixed a NULL pointer dereference on OOM - -Daniel Stenberg (24 Feb 2016) -- [Viktor Szakats brought this change] - - url updates, HTTP => HTTPS - - Closes #87 - -Dan Fandrich (23 Feb 2016) -- RELEASE-NOTES: removed some duplicated names - -Version 1.7.0 (23 Feb 2016) - -Daniel Stenberg (23 Feb 2016) -- web: the site is now HTTPS - -- RELEASE-NOTES: 1.7.0 release - -- diffie_hellman_sha256: convert bytes to bits - - As otherwise we get far too small numbers. - - Reported-by: Andreas Schneider - - CVE-2016-0787 - -Alexander Lamaison (18 Feb 2016) -- Allow CI failures with VS 2008 x64. - - Appveyor doesn't support this combination. - -Daniel Stenberg (16 Feb 2016) -- [Viktor Szakats brought this change] - - GNUmakefile: list system libs after user libs - - Otherwise some referenced WinSock functions will fail to - resolve when linking against LibreSSL 2.3.x static libraries - with mingw. - - Closes #80 - -- [Viktor Szakats brought this change] - - openssl: apply new HAVE_OPAQUE_STRUCTS macro - - Closes #81 - -- [Viktor Szakats brought this change] - - openssl: fix LibreSSL support after OpenSSL 1.1.0-pre1/2 support - -Alexander Lamaison (14 Feb 2016) -- sftp.h: Fix non-C90 type. - - uint64_t does not exist in C90. Use libssh2_uint64_t instead. - -- Exclude sshd tests from AppVeyor. - - They fail complaining that sshd wasn't invoked with an absolute path. - -- Test on more versions of Visual Studio. - -- Fix Appveyor builds. - -Daniel Stenberg (14 Feb 2016) -- [Viktor Szakats brought this change] - - openssl: add OpenSSL 1.1.0-pre3-dev compatibility - - by using API instead of accessing an internal structure. - - Closes #83 - -- RELEASE-NOTES: synced with 996b04ececdf - -- include/libssh2.h: next version is 1.7.0 - -- configure: build "silent" if possible - -- sftp: re-indented some minor stuff - -- [Jakob Egger brought this change] - - sftp.c: ensure minimum read packet size - - For optimum performance we need to ensure we don't request tiny packets. - -- [Jakob Egger brought this change] - - sftp.c: Explicit return values & sanity checks - -- [Jakob Egger brought this change] - - sftp.c: Check Read Packet File Offset - - This commit adds a simple check to see if the offset of the read - request matches the expected file offset. - - We could try to recover, from this condition at some point in the future. - Right now it is better to return an error instead of corrupted data. - -- [Jakob Egger brought this change] - - sftp.c: Don't return EAGAIN if data was written to buffer - -- [Jakob Egger brought this change] - - sftp.c: Send at least one read request before reading - - This commit ensures that we have sent at least one read request before - we try to read data in sftp_read(). - - Otherwise sftp_read() would return 0 bytes (indicating EOF) if the - socket is not ready for writing. - -- [Jakob Egger brought this change] - - sftp.c: stop reading when buffer is full - - Since we can only store data from a single chunk in filep, - we have to stop receiving data as soon as the buffer is full. - - This adresses the following bug report: - https://github.com/libssh2/libssh2/issues/50 - -Salvador Fandiño (21 Jan 2016) -- agent_disconnect_unix: unset the agent fd after closing it - - "agent_disconnect_unix", called by "libssh2_agent_disconnect", was - leaving the file descriptor in the agent structure unchanged. Later, - "libssh2_agent_free" would call again "libssh2_agent_disconnect" under - the hood and it would try to close again the same file descriptor. In - most cases that resulted in just a harmless error, but it is also - possible that the file descriptor had been reused between the two - calls resulting in the closing of an unrelated file descriptor. - - This patch sets agent->fd to LIBSSH2_INVALID_SOCKET avoiding that - issue. - - Signed-off-by: Salvador Fandiño <sfandino@yahoo.com> - -Daniel Stenberg (18 Jan 2016) -- [Patrick Monnerat brought this change] - - os400qc3: support encrypted private keys - - PKCS#8 EncryptedPrivateKeyinfo structures are recognized and decoded to get - values accepted by the Qc3 crypto library. - -- [Patrick Monnerat brought this change] - - os400qc3: New PKCS#5 decoder - - The Qc3 library is not able to handle PKCS#8 EncryptedPrivateKeyInfo structures - by itself. It is only capable of decrypting the (encrypted) PrivateKeyInfo - part, providing a key encryption key and an encryption algorithm are given. - Since the encryption key and algorithm description part in a PKCS#8 - EncryptedPrivateKeyInfo is a PKCS#5 structure, such a decoder is needed to - get the derived key method and hash, as well as encryption algorith and - initialisation vector. - -- [Patrick Monnerat brought this change] - - os400qc3: force continuous update on non-final hash/hmac computation - -- [Patrick Monnerat brought this change] - - os400qc3: Be sure hmac keys have a minimum length - - The Qc3 library requires a minimum key length depending on the target - hash algorithm. Append binary zeroes to the given key if not long enough. - This matches RFC 2104 specifications. - -- [Patrick Monnerat brought this change] - - os400qc3: Slave descriptor for key encryption key - - The Qc3 library requires the key encryption key to exist as long as - the encrypted key is used. Its descriptor token is then kept as an - "encrypted key slave" for recursive release. - -- [Patrick Monnerat brought this change] - - os400qc3.c: comment PEM/DER decoding - -- [Patrick Monnerat brought this change] - - os400qc3.c: improve ASN.1 header byte checks - -- [Patrick Monnerat brought this change] - - os400qc3.c: improve OID matching - -- [Patrick Monnerat brought this change] - - os400: os400qc3.c: replace malloc by LIBSSH2_ALLOC or alloca where possible - -- [Patrick Monnerat brought this change] - - os400: asn1_new_from_bytes(): use data from a single element only - -- [Patrick Monnerat brought this change] - - os400: fix an ILE/RPG prototype - -- [Patrick Monnerat brought this change] - - os400: implement character encoding conversion support - -- [Patrick Monnerat brought this change] - - os400: do not miss some external prototypes - - Build procedure extproto() did not strip braces from header files, thus - possibly prepended them to true prototypes. This prevented the prototype to - be recognized as such. - The solution implemented here is to map braces to semicolons, effectively - considering them as potential prototype delimiters. - -- [Patrick Monnerat brought this change] - - os400: Really add specific README - -- [Patrick Monnerat brought this change] - - os400: Add specific README and include new files in dist tarball - -- [Patrick Monnerat brought this change] - - os400: add compilation scripts - -- [Patrick Monnerat brought this change] - - os400: include files for ILE/RPG - - In addition, file os400/macros.h declares all procedures originally - defined as macros. It must not be used for real inclusion and is only - intended to be used as a `database' for macro wrapping procedures generation. - -- [Patrick Monnerat brought this change] - - os400: add supplementary header files/wrappers. Define configuration. - -- [Patrick Monnerat brought this change] - - Protect callback function calls from macro substitution - - Some structure fields holding callback addresses have the same name as the - underlying system function (connect, send, recv). Set parentheses around - their reference to suppress a possible macro substitution. - - Use a macro for connect() on OS/400 to resolve a const/nonconst parameter - problem. - -- [Patrick Monnerat brought this change] - - Add interface for OS/400 crypto library QC3 - -- [Patrick Monnerat brought this change] - - misc: include stdarg.h for debug code - -- [Patrick Monnerat brought this change] - - Document crypto library interface - -- [Patrick Monnerat brought this change] - - Feature an optional crypto-specific macro to rsa sign a data fragment vector - - OS/400 crypto library is unable to sign a precomputed SHA1 hash: however - it does support a procedure that hashes data fragments and rsa signs. - If defined, the new macro _libssh2_rsa_sha1_signv() implements this function - and disables use of _libssh2_rsa_sha1_sign(). - - The function described above requires that the struct iovec unused slacks are - cleared: for this reason, macro libssh2_prepare_iovec() has been introduced. - It should be defined as empty for crypto backends that are not sensitive - to struct iovec unused slack values. - -- [Patrick Monnerat brought this change] - - Fold long lines in include files - -- [Viktor Szakats brought this change] - - kex.c: fix indentation - - Closes #71 - -- [Viktor Szakats brought this change] - - add OpenSSL-1.1.0-pre2 compatibility - - Closes #70 - -- [Viktor Szakats brought this change] - - add OpenSSL 1.1.0-pre1 compatibility - - * close https://github.com/libssh2/libssh2/issues/69 - * sync a declaration with the rest of similar ones - * handle EVP_MD_CTX_new() returning NULL with OpenSSL 1.1.0 - * fix potential memory leak with OpenSSL 1.1.0 in - _libssh2_*_init() functions, when EVP_MD_CTX_new() succeeds, - but EVP_DigestInit() fails. - -Marc Hoersken (22 Dec 2015) -- wincng.c: fixed _libssh2_wincng_hash_final return value - - _libssh2_wincng_hash_final was returning the internal BCRYPT - status code instead of a valid libssh2 return value (0 or -1). - - This also means that _libssh2_wincng_hash never returned 0. - -- wincng.c: fixed possible memory leak in _libssh2_wincng_hash - - If _libssh2_wincng_hash_update failed _libssh2_wincng_hash_final - would never have been called before. - - Reported by Zenju. - -Kamil Dudka (15 Dec 2015) -- [Paul Howarth brought this change] - - libssh2.pc.in: fix the output of pkg-config --libs - - ... such that it does not include LDFLAGS used to build libssh2 itself. - There was a similar fix in the curl project long time ago: - - https://github.com/bagder/curl/commit/curl-7_19_7-56-g4c8adc8 - - Bug: https://bugzilla.redhat.com/1279966 - Signed-off-by: Kamil Dudka <kdudka@redhat.com> - -Marc Hoersken (6 Dec 2015) -- hostkey.c: align code path of ssh_rsa_init to ssh_dss_init - -- hostkey.c: fix invalid memory access if libssh2_dsa_new fails - - Reported by dimmaq, fixes #66 - -Daniel Stenberg (3 Nov 2015) -- [Will Cosgrove brought this change] - - gcrypt: define libssh2_sha256_ctx - - Looks like it didn't make it into the latest commit for whatever reason. - - Closes #58 - -- [Salvador Fandino brought this change] - - libssh2_session_set_last_error: Add function - - Net::SSH2, the Perl wrapping module for libssh2 implements several features* - on top of libssh2 that can fail and so need some mechanism to report the error - condition to the user. - - Until now, besides the error state maintained internally by libssh2, another - error state was maintained at the Perl level for every session object and then - additional logic was used to merge both error states. That is a maintenance - nighmare, and actually there is no way to do it correctly and consistently. - - In order to allow the high level language to add new features to the library - but still rely in its error reporting features the new function - libssh2_session_set_last_error (that just exposses _libssh2_error_flags) is - introduced. - - *) For instance, connecting to a remote SSH service giving the hostname and - port. - - Signed-off-by: Salvador Fandino <sfandino@yahoo.com> - Signed-off-by: Salvador Fandiño <sfandino@yahoo.com> - -- [Salvador Fandino brought this change] - - _libssh2_error: Support allocating the error message - - Before this patch "_libssh2_error" required the error message to be a - static string. - - This patch adds a new function "_libssh2_error_flags" accepting an - additional "flags" argument and specifically the flag - "LIBSSH2_ERR_FLAG_DUP" indicating that the passed string must be - duplicated into the heap. - - Then, the method "_libssh2_error" has been rewritten to use that new - function under the hood. - - Signed-off-by: Salvador Fandino <sfandino@yahoo.com> - Signed-off-by: Salvador Fandiño <sfandino@yahoo.com> - -- [Will Cosgrove brought this change] - - added engine.h include to fix warning - -- [sune brought this change] - - kex.c: removed dupe entry from libssh2_kex_methods[] - - Closes #51 - -- [Salvador Fandiño brought this change] - - userauth: Fix off by one error when reading public key file - - After reading the public key from file the size was incorrectly - decremented by one. - - This was usually a harmless error as the last character on the public - key file is an unimportant EOL. But if due to some error the public key - file is empty, the public key size becomes (uint)(0 - 1), resulting in - an unrecoverable out of memory error later. - - Signed-off-by: Salvador Fandi??o <sfandino-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> - -- [Salvador Fandino brought this change] - - channel: Detect bad usage of libssh2_channel_process_startup - - A common novice programmer error (at least among those using the - wrapping Perl module Net::SSH2), is to try to reuse channels. - - This patchs detects that incorrect usage and fails with a - LIBSSH2_ERROR_BAD_USE error instead of hanging. - - Signed-off-by: Salvador Fandino <sfandino-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> - -- [Will Cosgrove brought this change] - - kex: Added diffie-hellman-group-exchange-sha256 support - - ... and fixed HMAC_Init depricated usage - - Closes #48 - -Alexander Lamaison (21 Sep 2015) -- Prefixed new #defines to prevent collisions. - - Other libraries might have their own USE_WIN32_*FILES. - -- [keith-daigle brought this change] - - Update examples/scp.c to fix bug where large files on win32 would cause got to wrap and go negative - -- [David Byron brought this change] - - add libssh2_scp_recv2 to support large (> 2GB) files on windows - -Daniel Stenberg (17 Sep 2015) -- [sune brought this change] - - WinCNG: support for SHA256/512 HMAC - - Closes #47 - -- [brian m. carlson brought this change] - - Add support for HMAC-SHA-256 and HMAC-SHA-512. - - Implement support for these algorithms and wire them up to the libgcrypt - and OpenSSL backends. Increase the maximum MAC buffer size to 64 bytes - to prevent buffer overflows. Prefer HMAC-SHA-256 over HMAC-SHA-512, and - that over HMAC-SHA-1, as OpenSSH does. - - Closes #40 - -- [Zenju brought this change] - - kex: free server host key before allocating it (again) - - Fixes a memory leak when Synology server requests key exchange - - Closes #43 - -- [Viktor Szakats brought this change] - - GNUmakefile: up OpenSSL version - - closes #23 - -- [Viktor Szakats brought this change] - - GNUmakefile: add -m64 CFLAGS when targeting mingw64, add -m32/-m64 to LDFLAGS - - libssh2 equivalent of curl patch https://github.com/bagder/curl/commit/d21b66835f2af781a3c2a685abc92ef9f0cd86be - - This allows to build for the non-default target when using a multi-target mingw distro. - Also bump default OpenSSL dependency path to 1.0.2c. - -- [Viktor Szakats brought this change] - - GNUmakefile: add support for LIBSSH2_LDFLAG_EXTRAS - - It is similar to existing LIBSSH2_CFLAG_EXTRAS, but for - extra linker options. - - Also delete some line/file ending whitespace. - - closes #27 - -- [nasacj brought this change] - - hostkey.c: Fix compiling error when OPENSSL_NO_MD5 is defined - - Closes #32 - -- [Mizunashi Mana brought this change] - - openssl.h: adjust the rsa/dsa includes - - ... to work when built without DSA support. - - Closes #36 - -Alexander Lamaison (26 Jul 2015) -- Let CMake build work as a subproject. - - Patch contributed by JasonHaslam. - -- Fix builds with Visual Studio 2015. - - VS2015 moved stdio functions to the header files as inline function. That means check_function_exists can't detect them because it doesn't use header files - just does a link check. Instead we need to use check_symbol_exists with the correct headers. - -Kamil Dudka (2 Jul 2015) -- cmake: include CMake files in the release tarballs - - Despite we announced the CMake support in libssh2-1.6.0 release notes, - the files required by the CMake build system were not included in the - release tarballs. Hence, the only way to use CMake for build was the - upstream git repository. - - This commit makes CMake actually supported in the release tarballs. - -- tests/mansyntax.sh: fix 'make distcheck' with recent autotools - - Do not create symbolic links off the build directory. Recent autotools - verify that out-of-source build works even if the source directory tree - is not writable. - -- openssl: fix memleak in _libssh2_dsa_sha1_verify() - -Daniel Stenberg (12 Jun 2015) -- openssl: make libssh2_sha1 return error code - - - use the internal prefix _libssh2_ for non-exported functions - - - removed libssh2_md5() since it wasn't used - - Reported-by: Kamil Dudka - -- [LarsNordin-LNdata brought this change] - - SFTP: Increase speed and datasize in SFTP read - - The function sftp_read never return more then 2000 bytes (as it should - when I asked Daniel). I increased the MAX_SFTP_READ_SIZE to 30000 but - didn't get the same speed as a sftp read in SecureSSH. I analyzed the - code and found that a return always was dona when a chunk has been read. - I changed it to a sliding buffer and worked on all available chunks. I - got an increase in speed and non of the test I have done has failed - (both local net and over Internet). Please review and test. I think - 30000 is still not the optimal MAX_SFTP_READ_SIZE, my next goal is to - make an API to enable changing this value (The SecureSSH sftp_read has - more complete filled packages when comparing the network traffic) - -- bump: start working on 1.6.1 - -Version 1.6.0 (5 Jun 2015) - -Daniel Stenberg (5 Jun 2015) -- RELEASE-NOTES: synced with 858930cae5c6a - -Marc Hoersken (19 May 2015) -- wincng.c: fixed indentation - -- [sbredahl brought this change] - - wincng.c: fixed memleak in (block) cipher destructor - -Alexander Lamaison (6 May 2015) -- [Jakob Egger brought this change] - - libssh2_channel_open: more detailed error message - - The error message returned by libssh2_channel_open in case of a server side channel open failure is now more detailed and includes the four standard error conditions in RFC 4254. - -- [Hannes Domani brought this change] - - kex: fix libgcrypt memory leaks of bignum - - Fixes #168. - -Marc Hoersken (3 Apr 2015) -- configure.ac: check for SecureZeroMemory for clear memory feature - -- Revert "wincng.c: fix clear memory feature compilation with mingw" - - This reverts commit 2d2744efdd0497b72b3e1ff6e732aa4c0037fc43. - - Autobuilds show that this did not solve the issue. - And it seems like RtlFillMemory is defined to memset, - which would be optimized out by some compilers. - -- wincng.c: fix clear memory feature compilation with mingw - -Alexander Lamaison (1 Apr 2015) -- [LarsNordin-LNdata brought this change] - - Enable use of OpenSSL that doesn't have DSA. - - Added #if LIBSSH2_DSA for all DSA functions. - -- [LarsNordin-LNdata brought this change] - - Use correct no-blowfish #define with OpenSSL. - - The OpenSSL define is OPENSSL_NO_BF, not OPENSSL_NO_BLOWFISH. - -Marc Hoersken (25 Mar 2015) -- configure: error if explicitly enabled clear-memory is not supported - - This takes 22bd8d81d8fab956085e2079bf8c29872455ce59 and - b8289b625e291bbb785ed4add31f4759241067f3 into account, - but still makes it enabled by default if it is supported - and error out in case it is unsupported and was requested. - -Daniel Stenberg (25 Mar 2015) -- configure: make clear-memory default but only WARN if backend unsupported - - ... instead of previous ERROR. - -Marc Hoersken (24 Mar 2015) -- wincng.h: fix warning about computed return value not being used - -- nonblocking examples: fix warning about unused tvdiff on Mac OS X - -Daniel Stenberg (24 Mar 2015) -- openssl: fix compiler warnings - -- cofigure: fix --disable-clear-memory check - -Marc Hoersken (23 Mar 2015) -- scp.c: improved command length calculation - - Reduced number of calls to strlen, because shell_quotearg already - returns the length of the resulting string (e.q. quoted path) - which we can add to the existing and known cmd_len. - Removed obsolete call to memset again, because we can put a final - NULL-byte at the end of the string using the calculated length. - -- scp.c: improved and streamlined formatting - -- scp.c: fix that scp_recv may transmit not initialised memory - -- scp.c: fix that scp_send may transmit not initialised memory - - Fixes ticket 244. Thanks Torsten. - -- kex: do not ignore failure of libssh2_sha1_init() - - Based upon 43b730ce56f010e9d33573fcb020df49798c1ed8. - Fixes ticket 290. Thanks for the suggestion, mstrsn. - -- wincng.h: fix return code of libssh2_md5_init() - -- openssl.c: fix possible segfault in case EVP_DigestInit fails - -- wincng.c: fix possible use of uninitialized variables - -- wincng.c: fix unused argument warning if clear memory is not enabled - -- wincng: Added explicit clear memory feature to WinCNG backend - - This re-introduces the original feature proposed during - the development of the WinCNG crypto backend. It still needs - to be added to libssh2 itself and probably other backends. - - Memory is cleared using the function SecureZeroMemory which is - available on Windows systems, just like the WinCNG backend. - -- wincng.c: fixed mixed line-endings - -- wincng.c: fixed use of invalid parameter types in a8d14c5dcf - -- wincng.c: only try to load keys corresponding to the algorithm - -- wincng.c: moved PEM headers into definitions - -- wincng.h: fixed invalid parameter name - -- wincng: fixed mismatch with declarations in crypto.h - -- userauth.c: fixed warning C6001: using uninitialized sig and sig_len - -- pem.c: fixed warning C6269: possible incorrect order of operations - -- wincng: add support for authentication keys to be passed in memory - - Based upon 18cfec8336e and daa2dfa2db. - -- pem.c: add _libssh2_pem_parse_memory to parse PEM from memory - - Requirement to implement 18cfec8336e for Libgcrypt and WinCNG. - -- pem.c: fix copy and paste mistake from 55d030089b8 - -- userauth.c: fix another possible dereference of a null pointer - -- userauth.c: fix possible dereference of a null pointer - -- pem.c: reduce number of calls to strlen in readline - -Alexander Lamaison (17 Mar 2015) -- [Will Cosgrove brought this change] - - Initialise HMAC_CTX in more places. - - Missed a couple more places we init ctx to avoid openssl threading crash. - -- Build build breakage in WinCNG backend caused when adding libssh2_userauth_publickey_frommemory. - - The new feature isn't implemented for the WinCNG backend currently, but the WinCNG backend didn't contain any implementation of the required backend functions - even ones that returns an error. That caused link errors. - - This change fixes the problem by providing an implementation of the backend functions that returns an error. - -- Fix breakage in WinCNG backend caused by introducing libssh2_hmac_ctx_init. - - The macro was defined to nothing for the libgcrypt backend, but not for WinCNG. This brings the latter into line with the former. - -Daniel Stenberg (15 Mar 2015) -- userauth_publickey_frommemory.3: add AVAILABILITY - - ... it will be added in 1.6.0 - -- libssh2: next version will be called 1.6.0 - - ... since we just added a new function. - -- docs: add libssh2_userauth_publickey_frommemory.3 to dist - - The function and man page were added in commit 18cfec8336e - -- [Jakob Egger brought this change] - - direct_tcpip: Fixed channel write - - There were 3 bugs in this loop: - 1) Started from beginning after partial writes - 2) Aborted when 0 bytes were sent - 3) Ignored LIBSSH2_ERROR_EAGAIN - - See also: - https://trac.libssh2.org/ticket/281 - https://trac.libssh2.org/ticket/293 - -Alexander Lamaison (15 Mar 2015) -- [Will Cosgrove brought this change] - - Must init HMAC_CTX before using it. - - Must init ctx before using it or openssl will reuse the hmac which is not thread safe and causes a crash. - Added libssh2_hmac_ctx_init macro. - -- Add continuous integration configurations. - - Linux-based CI is done by Travis CI. Windows-based CI is done by Appveyor. - -- [David Calavera brought this change] - - Allow authentication keys to be passed in memory. - - All credits go to Joe Turpin, I'm just reaplying and cleaning his patch: - http://www.libssh2.org/mail/libssh2-devel-archive-2012-01/0015.shtml - - * Use an unimplemented error for extracting keys from memory with libgcrypt. - -Daniel Stenberg (14 Mar 2015) -- docs: include the renamed INSTALL* files in dist - -Alexander Lamaison (13 Mar 2015) -- Prevent collisions between CMake and Autotools in examples/ and tests/. - -- Avoid clash between CMake build and Autotools. - - Autotools expects a configuration template file at src/libssh2_config.h.in, which buildconf generates. But the CMake build system has its CMake-specific version of the file at this path. This means that, if you don't run buildconf, the Autotools build will fail because it configured the wrong header template. - - See https://github.com/libssh2/libssh2/pull/8. - -- Merge pull request #8 from alamaison/cmake - - CMake build system. - -- CMake build system. - - Tested: - - Windows: - - Visual C++ 2005/2008/2010/2012/2013/MinGW-w64 - - static/shared - - 32/64-bit - - OpenSSL/WinCNG - - Without zlib - - Linux: - - GCC 4.6.3/Clang 3.4 - - static/shared - - 32/64-bit - - OpenSSL/Libgcrypt - - With/Without zlib - - MacOS X - - AppleClang 6.0.0 - - static - - 64-bit - - OpenSSL - - Without zlib - - Conflicts: - README - -- Man man syntax tests fail gracefully if man version is not suitable. - -- Return valid code from test fixture on failure. - - The sshd test fixture was returning -1 if an error occurred, but negative error codes aren't technically valid (google it). Bash on Windows converted them to 0 which made setup failure look as though all tests were passing. - -- Let mansyntax.sh work regardless of where it is called from. - -Daniel Stenberg (12 Mar 2015) -- [Viktor Szakáts brought this change] - - mingw build: allow to pass custom CFLAGS - - Allow to pass custom `CFLAGS` options via environment variable - `LIBSSH2_CFLAG_EXTRAS`. Default and automatically added options of - `GNUmakefile` have preference over custom ones. This addition is useful - for passing f.e. custom CPU tuning or LTO optimization (`-flto - -ffat-lto-objects`) options. The only current way to do this is to edit - `GNUmakefile`. This patch makes it unnecessary. - - This is a mirror of similar libcurl patch: - https://github.com/bagder/curl/pull/136 - -- [Will Cosgrove brought this change] - - userauth: Fixed prompt text no longer being copied to the prompts struct - - Regression from 031566f9c - -- README: update the git repo locations - -- wait_socket: wrong use of difftime() - - With reversed arguments it would always return a negative value... - - Bug: https://github.com/bagder/libssh2/issues/1 - -- bump: start working toward 1.5.1 now - -Version 1.5.0 (11 Mar 2015) - -Daniel Stenberg (11 Mar 2015) -- RELEASE-NOTES: 1.5.0 release - -- [Mariusz Ziulek brought this change] - - kex: bail out on rubbish in the incoming packet - - CVE-2015-1782 - - Bug: http://www.libssh2.org/adv_20150311.html - -- docs: move INSTALL, AUTHORS, HACKING and TODO to docs/ - - And with this, cleanup README to be shorter and mention the new source - code home. - -- .gitignore: don't ignore INSTALL - -Dan Fandrich (4 Mar 2015) -- examples/x11.c: include sys/select.h for improved portability - -Daniel Stenberg (4 Mar 2015) -- RELEASE-NOTES: synced with a8473c819bc068 - - In preparation for the upcoming 1.5.0 release. - -Guenter Knauf (8 Jan 2015) -- NetWare build: added some missing exports. - -Marc Hoersken (29 Dec 2014) -- knownhost.c: fix use of uninitialized argument variable wrote - - Detected by clang scan in line 1195, column 18. - -- examples/x11.c: fix result of operation is garbage or undefined - - Fix use of uninitialized structure w_size_bck. - Detected by clang scan in line 386, column 28. - -- examples/x11.c: remove dead assigments of some return values - - Detected by clang scan in line 212, column 9. - Detected by clang scan in line 222, column 13. - Detected by clang scan in line 410, column 13. - -- examples/x11.c: fix possible memory leak if read fails - - Detected by clang scan in line 224, column 21. - -- examples/x11.c: fix invalid removal of first list element - - Fix use of memory after it was being freed. - Detected by clang scan in line 56, column 12. - -- userauth.c: make sure that sp_len is positive and avoid overflows - - ... if the pointer subtraction of sp1 - pubkey - 1 resulted in a - negative or larger value than pubkey_len, memchr would fail. - - Reported by Coverity CID 89846. - -- channel.c: remove logically dead code, host cannot be NULL here - - ... host cannot be NULL in line 525, because it is always - valid (e.g. at least set to "0.0.0.0") after lines 430 and 431. - - Reported by Coverity CID 89807. - -- session.c: check return value of session_nonblock during startup - - Reported by Coverity CID 89803. - -- session.c: check return value of session_nonblock in debug mode - - Reported by Coverity CID 89805. - -- pem.c: fix mixed line-endings introduced with 8670f5da24 - -- pem.c: make sure there's a trailing zero and b64data is not NULL - - ... if there is no base64 data between PEM header and footer. - Reported by Coverity CID 89823. - -- kex.c: make sure mlist is not set to NULL - - ... if the currently unsupported LANG methods are called. - Reported by Coverity CID 89834. - -- packet.c: i < 256 was always true and i would overflow to 0 - - Visualize that the 0-termination is intentional, because the array - is later passed to strlen within _libssh2_packet_askv. - -- silence multiple data conversion warnings - -Daniel Stenberg (23 Dec 2014) -- agent_connect_unix: make sure there's a trailing zero - - ... if the path name was too long. Reported by Coverity CID 89801. - -Marc Hoersken (22 Dec 2014) -- examples on Windows: use native SOCKET-type instead of int - - And check return values accordingly. - -- userauth.c: improve readability and clarity of for-loops - -Daniel Stenberg (22 Dec 2014) -- calloc: introduce LIBSSH2_CALLOC() - - A simple function using LIBSSH2_ALLOC + memset, since this pattern was - used in multiple places and this simplies code in general. - -Marc Hoersken (15 Dec 2014) -- libssh2_priv.h: Ignore session, context and format parameters - -- x11 example: check return value of socket function - -- examples: fixed mixed line-endings introduced with aedfba25b8 - -- wincng.c: explicitly ignore BCrypt*AlgorithmProvider return codes - - Fixes VS2012 code analysis warning C6031: - return value ignored: <function> could return unexpected value - -- wincng.c: fix possible invalid memory write access - - Fixes VS2012 code analysis warning C6386: - buffer overrun: accessing 'pbOutput', the writable size is - 'cbOutput' bytes, but '3' bytes may be written: libssh2 wincng.c 610 - -- tests on Windows: check for WSAStartup return code - - Fixes VS2012 code analysis warning C6031: - return value ignored: <function> could return unexpected value - -- wincng.c: fix possible NULL pointer de-reference of bignum - - Fixes VS2012 code analysis warning C6011: - dereferencing NULL pointer 'bignum'. libssh2 wincng.c 1567 - -- wincng.c: fix possible use of uninitialized memory - - Fixes VS2012 code analysis warning C6001: - using uninitialized memory 'cbDecoded'. libssh2 wincng.c 553 - -- packet.c: fix possible NULL pointer de-reference within listen_state - - Fixes VS2012 code analysis warning C6011: - dereferencing NULL pointer 'listen_state->channel'. libssh2 packet.c 221 - -- kex.c: fix possible NULL pointer de-reference with session->kex - - Fixes VS2012 code analysis warning C6011: - dereferencing NULL pointer 'session->kex'. libssh2 kex.c 1761 - -- agent.c: check return code of MapViewOfFile - - Fixes VS2012 code analysis warning C6387: 'p+4' may be '0': - this does not adhere to the specification for the function - 'memcpy': libssh2 agent.c 330 - - Fixes VS2012 code analysis warning C6387: 'p' may be '0': - this does not adhere to the specification for the function - 'UnmapViewOfFile': libssh2 agent.c 333 - -- examples on Windows: check for socket return code - - Fixes VS2012 code analysis warning C28193: - The variable holds a value that must be examined - -- examples on Windows: check for WSAStartup return code - - Fixes VS2012 code analysis warning C6031: - return value ignored: <function> could return unexpected value - -Guenter Knauf (11 Dec 2014) -- wincng.c: silent some more gcc compiler warnings. - -- wincng.c: silent gcc compiler warnings. - -- Watcom build: added support for WinCNG build. - -- build: updated dependencies in makefiles. - -Daniel Stenberg (4 Dec 2014) -- configure: change LIBS not LDFLAGS when checking for libs - - Closes #289 - - Patch-by: maurerpe - -Guenter Knauf (3 Dec 2014) -- MinGW build: some more GNUMakefile tweaks. - - test/GNUmakefile: added architecture autodetection; added switches to - CFLAGS and RCFLAGS to make sure that the right architecture is used. - Added support to build with WinCNG. - -- sftpdir.c: added authentication method detection. - - Stuff copied over from ssh2.c to make testing a bit easier. - -- NMake build: fixed LIBS settings. - -- NMake build: added support for WinCNG build. - -- MinGW build: some GNUMakefile tweaks. - - Added architecture autodetection; added switches to CFLAGS and - RCFLAGS to make sure that the right architecture is used. - Added support to build with WinCNG. - -- MinGW build: Fixed redefine warnings. - -- Updated copyright year. - -Daniel Stenberg (31 Aug 2014) -- COPYING: bump the copyright year - -Dan Fandrich (28 Jul 2014) -- docs: fixed a bunch of typos - -- docs: added missing libssh2_session_handshake.3 file - -Marc Hoersken (19 May 2014) -- wincng.c: specify the required libraries for dependencies using MSVC - - Initially reported by Bob Kast as "for MS VS builds, specify the - libraries that are required so they don't need to go into all - project files that may use this library". Thanks a lot. - -- [Bob Kast brought this change] - - windows build: do not export externals from static library - - If you are building a DLL, then you need to explicitly export each - entry point. When building a static library, you should not. - - libssh2 was exporting the entry points whether it was building a DLL or a - static library. To elaborate further, if libssh2 was used as a static - library, which was being linked into a DLL, the libssh2 API would be - exported from that separate DLL. - -Daniel Stenberg (19 May 2014) -- [Mikhail Gusarov brought this change] - - Fix typos in manpages - -Marc Hoersken (18 May 2014) -- wincng.c: Fixed memory leak in case of an error during ASN.1 decoding - -- configure: Display individual crypto backends on separate lines - - This avoids line-wrapping in between parameters and makes the - error message look like the following: - - configure: error: No crypto library found! - Try --with-libssl-prefix=PATH - or --with-libgcrypt-prefix=PATH - or --with-wincng on Windows - -- [Bob Kast brought this change] - - libssh2_priv.h: a 1 bit bit-field should be unsigned - - some compilers may not like this - -- knownhost.c: Fixed warning that pointer targets differ in signedness - -- wincng.c: Fixed warning about pointer targets differing in signedness - -- tcpip-forward.c: Fixed warning that pointer targets differ in signedness - - libssh2_channel_forward_listen_ex uses ints instead of unsigned ints. - -- misc.c: Fixed warning about mixed declarations and code - -- libgcrypt.h: Fixed warning about pointer targets differing in signedness - -- wincng.h: Fixed warning about pointer targets differing in signedness - -- misc.c: Fixed warning about unused parameter abstract - -- tcpip-forward.c: Removed unused variables shost, sport and sockopt - -- wincng.h: Added forward declarations for all WinCNG functions - - Initially reported by Bob Kast as "Wincng - define function - prototypes for wincng routines". Thanks a lot. - - Also replaced structure definitions with type definitions. - -- [Bob Kast brought this change] - - libssh2.h: on Windows, a socket is of type SOCKET, not int - -- win32: Added WinCNG targets to generated Visual Studio project - - Inspired by Bob Kast's reports, this commit enables the compilation - of libssh2 with WinCNG using the generated Visual Studio project files. - This commit adds WinCNG support to parts of the existing Win32 build - infrastructure, until new build systems, like pre-defined VS project - files or CMake files may be added. - - This commit and b20bfeb3e519119a48509a1099c06d65aa7da1d7 raise one - question: How to handle build systems, like VS project files, that - need to include all source files regardless of the desired target, - including all supported crypto backends? For now the mentioned commit - added a check for LIBSSH2_OPENSSL to openssl.c and with this commit - the supported crypto backends are hardcoded within Makefile.am. - -- libssh2_priv msvc: Removed redundant definition of inline keyword - - Initially reported by Bob Kast as "Remove redundant 'inline' define". - Thanks a lot. - -- wincng: Made data parameter to hash update function constant - - Initially reported by Bob Kast as "formal parameter must be const - since it is used in contexts where the actual parameter may be const". - Thanks a lot. - -- wincng: fix cross-compilation against the w64 mingw-runtime package - -- openssl: Check for LIBSSH2_OPENSSL in order to compile with openssl - -- wincng: Fixed use of possible uninitialized variable pPaddingInfo - - Reported by Bob Kast, thanks a lot. - -- wincng: Added cast for double to unsigned long conversion - -- wincng: Cleaned up includes and check NTSTATUS using macro - - Removed header file combination that is not supported on a real - Windows platform and can only be compiled using MinGW. Replaced - custom NTSTATUS return code checks with BCRYPT_SUCCESS macro. - -Daniel Stenberg (16 Mar 2014) -- userauth_hostbased_fromfile: zero assign to avoid uninitialized use - - Detected by clang-analyze - -- channel_receive_window_adjust: store windows size always - - Avoid it sometimes returning without storing it, leaving calling - functions with unknown content! - - Detected by clang-analyzer - -- publickey_packet_receive: avoid junk in returned pointers - - clang-analyzer found this risk it would return a non-initialized pointer - in a success case - -Peter Stuge (16 Mar 2014) -- [Marc Hoersken brought this change] - - Added Windows Cryptography API: Next Generation based backend - -- [Marc Hoersken brought this change] - - knownhost.c: fixed that 'key_type_len' may be used uninitialized - - ../src/knownhost.c: In function 'libssh2_knownhost_readline': - ../src/knownhost.c:651:16: warning: 'key_type_len' may be used - uninitialized in this function [-Wmaybe-uninitialized] - rc = knownhost_add(hosts, hostbuf, NULL, - ^ - ../src/knownhost.c:745:12: note: 'key_type_len' was declared here - size_t key_type_len; - ^ - -- [Marc Hoersken brought this change] - - pem.c: always compile pem.c independently of crypto backend - -- Fix non-autotools builds: Always define the LIBSSH2_OPENSSL CPP macro - - Commit d512b25f69a1b6778881f6b4b5ff9cfc6023be42 introduced a crypto - library abstraction in the autotools build system, to allow us to more - easily support new crypto libraries. In that process it was found that - all other build system which we support are hard-coded to build with - OpenSSL. Commit f5c1a0d98bd51aeb24aca3d49c7c81dcf8bd858d fixes automake - introduced into non-autotools build systems but still overlooked the - CPP macro saying that we are using OpenSSL. - - Thanks to Marc Hörsken for identifying this issue and proposing a fix - for win32/{GNUmakefile,config.mk}. This commit uses a slightly different - approach but the end result is the same. - -Dan Fandrich (15 Mar 2014) -- channel_close: Close the channel even in the case of errors - -- sftp_close_handle: ensure the handle is always closed - - Errors are reported on return, but otherwise the close path is - completed as much as possible and the handle is freed on exit. - -Alexander Lamaison (6 Mar 2014) -- knownhost: Restore behaviour of `libssh2_knownhost_writeline` with short buffer. - - Commit 85c6627c changed the behaviour of `libssh2_knownhost_writeline` so that it stopped returning the number of bytes needed when the given buffer was too small. Also, the function changed such that is might write to part of the buffer before realising it is too small. - - This commit restores the original behaviour, whilst keeping the unknown-key-type functionality that 85c6627c. Instead of writing to the buffer piecemeal, the length of the various parts is calculated up front and the buffer written only if there is enough space. The calculated necessary size is output in `outlen` regardless of whether the buffer was written to. - - The main use-case for the original behaviour that this commit restores is to allow passing in a NULL buffer to get the actual buffer size needed, before calling the function again with the buffer allocated to the exact size required. - -- knownhost: Fix DSS keys being detected as unknown. - - I missing `else` meant ssh-dss format keys were being re-detected as unknown format. - -Dan Fandrich (6 Mar 2014) -- knownhosts: Abort if the hosts buffer is too small - - This could otherwise cause a match on the wrong host - -- agent_list_identities: Fixed memory leak on OOM - -- Fixed a few typos - -- userauth: Fixed an attempt to free from stack on error - -- Fixed a few memory leaks in error paths - -- Fixed two potential use-after-frees of the payload buffer - - The first might occur if _libssh2_packet_add returns an error, as - fullpacket_state wasn't reset to idle so if it were possible for - fullpacket to be called again, it would return to the same state - handler and re-use the freed p->packet buffer. - - The second could occur if decrypt returned an error, as it freed the - packet buffer but did not clear total_num, meaning that freed buffer - could be written into again later. - -Alexander Lamaison (28 Nov 2013) -- Fix missing `_libssh2_error` in `_libssh2_channel_write`. - - In one case, the error code from `_libssh2_transport_read` was being returned from `_libssh2_channel_write` without setting it as the last error by calling `_libssh2_error`. This commit fixes that. - - Found when using a session whose socket had been inadvertently destroyed. The calling code got confused because via `libssh2_session_last_error` it appeared no error had occurred, despite one being returned from the previous function. - -Kamil Dudka (21 Nov 2013) -- [Mark McPherson brought this change] - - openssl: initialise the digest context before calling EVP_DigestInit() - - When using the OpenSSL libraries in FIPS mode, the function call - EVP_DigestInit() is actually #defined to FIPS_digestinit(). - Unfortunately wheres EVP_DigestInit() initialises the context and then - calls EVP_DigestInit_ex(), this function assumes that the context has - been pre-initialised and crashes when it isn't. - - Bug: https://trac.libssh2.org/ticket/279 - - Fixes #279 - -- [Marc Hörsken brought this change] - - .gitignore: Ignore files like src/libssh2_config.h.in~ - -Peter Stuge (13 Nov 2013) -- Move automake conditionals added by commit d512b25f out of Makefile.inc - - Commit d512b25f69a1b6778881f6b4b5ff9cfc6023be42 added automake - conditionals to Makefile.inc but since Makefile.inc is included - from Makefile for all other build systems that does not work. - - This commit instead adds Makefile.OpenSSL.inc and Makefile.libgcrypt.inc - and moves the automake conditional to its proper place, src/Makefile.am. - - The automake conditional includes the correct Makefile.$name.inc per - the crypto library selection/detection done by configure. - - All non-autotools build system files in libssh2 are hardcoded to use - OpenSSL and do not get a conditional but at least there is some reuse - because they can all include the new Makefile.OpenSSL.inc. - -Daniel Stenberg (27 Oct 2013) -- [Salvador Fandino brought this change] - - Set default window size to 2MB - - The default channel window size used until now was 256KB. This value is - too small and results on a bottleneck on real-life networks where - round-trip delays can easily reach 300ms. - - The issue was not visible because the configured channel window size - was being ignored and a hard-coded value of ~22MB being used instead, - but that was fixed on a previous commit. - - This patch just changes the default window size - (LIBSSH2_CHANNEL_WINDOW_DEFAULT) to 2MB. It is the same value used by - OpenSSH and in our opinion represents a good compromise between memory - used and transfer speed. - - Performance tests were run to determine the optimum value. The details - and related discussion are available from the following thread on the - libssh2 mailing-list: - - http://www.libssh2.org/mail/libssh2-devel-archive-2013-10/0018.shtml - http://article.gmane.org/gmane.network.ssh.libssh2.devel/6543 - - An excerpt follows: - - "I have been running some transfer test and measuring their speed. - - My setup was composed of a quad-core Linux machine running Ubuntu 13.10 - x86_64 with a LXC container inside. The data transfers were performed - from the container to the host (never crossing through a physical - network device). - - Network delays were simulated using the tc tool. And ping was used to - verify that they worked as intended during the tests. - - The operation performed was the equivalent to the following ssh command: - - $ ssh container "dd bs=16K count=8K if=/dev/zero" >/dev/null - - Though, establishment and closing of the SSH connection was excluded - from the timings. - - I run the tests several times transferring files of sizes up to 128MB - and the results were consistent between runs. - - The results corresponding to the 128MB transfer are available here: - - https://docs.google.com/spreadsheet/ccc?key=0Ao1yRmX6PQQzdG5wSFlrZl9HRWNET3ZyN0hnaGo5ZFE&usp=sharing - - It clearly shows that 256KB is too small as the default window size. - Moving to a 512MB generates a great improvement and after the 1MB mark - the returns rapidly diminish. Other factors (TCP window size, probably) - become more limiting than the channel window size - - For comparison I also performed the same transfers using OpenSSH. Its - speed is usually on par with that of libssh2 using a window size of 1MB - (even if it uses a 2MB window, maybe it is less aggressive sending the - window adjust msgs)." - - Signed-off-by: Salvador Fandino <sfandino@yahoo.com> - -- [Salvador brought this change] - - _libssh2_channel_read: Honour window_size_initial - - _libssh2_channel_read was using an arbitrary hard-coded limit to trigger - the window adjusting code. The adjustment used was also hard-coded and - arbitrary, 15MB actually, which would limit the usability of libssh2 on - systems with little RAM. - - This patch, uses the window_size parameter passed to - libssh2_channel_open_ex (stored as remote.window_size_initial) plus the - buflen as the base for the trigger and the adjustment calculation. - - The memory usage when using the default window size is reduced from 22MB - to 256KB per channel (actually, if compression is used, these numbers - should be incremented by ~50% to account for the errors between the - decompressed packet sizes and the predicted sizes). - - My tests indicate that this change does not impact the performance of - transfers across localhost or a LAN, being it on par with that of - OpenSSH. On the other hand, it will probably slow down transfers on - networks with high bandwidth*delay when the default window size - (LIBSSH2_CHANNEL_WINDOW_DEFAULT=256KB) is used. - - Signed-off-by: Salvador Fandino <sfandino@yahoo.com> - -- [Salvador Fandino brought this change] - - knownhosts: handle unknown key types - - Store but don't use keys of unsupported types on the known_hosts file. - - Currently, when libssh2 parses a known_host file containing keys of some - type it doesn't natively support, it stops reading the file and returns - an error. - - That means, that the known_host file can not be safely shared with other - software supporting other key types (i.e. OpenSSH). - - This patch adds support for handling keys of unknown type. It can read - and write them, even if they are never going to be matched. - - At the source level the patch does the following things: - - - add a new unknown key type LIBSSH2_KNOWNHOST_KEY_UNKNOWN - - - add a new slot (key_type_name) on the known_host struct that is - used to store the key type in ascii form when it is not supported - - - parse correctly known_hosts entries with unknown key types and - populate the key_type_name slot - - - print correctly known_hosts entries of unknown type - - - when checking a host key ignore keys that do not match the key - - Fixes #276 - -- windows build: fix build errors - - Fixes various link errors with VS2010 - - Reported-by: "kdekker" - Fixes #272 - -- man page: add missing function argument - - for libssh2_userauth_publickey_fromfile_ex() - - Reported-by: "pastey" - - Fixes #262 - -- [Salvador brought this change] - - Fix zlib deflate usage - - Deflate may return Z_OK even when not all data has been compressed - if the output buffer becomes full. - - In practice this is very unlikely to happen because the output buffer - size is always some KBs larger than the size of the data passed for - compression from the upper layers and I think that zlib never expands - the data so much, even on the worst cases. - - Anyway, this patch plays on the safe side checking that the output - buffer is not exhausted. - - Signed-off-by: Salvador <sfandino@yahoo.com> - -- [Salvador brought this change] - - comp_method_zlib_decomp: Improve buffer growing algorithm - - The old algorithm was O(N^2), causing lots and lots of reallocations - when highly compressed data was transferred. - - This patch implements a simpler one that just doubles the buffer size - everytime it is exhausted. It results in O(N) complexity. - - Also a smaller inflate ratio is used to calculate the initial size (x4). - - Signed-off-by: Salvador <sfandino@yahoo.com> - -- [Salvador brought this change] - - Fix zlib usage - - Data may remain in zlib internal buffers when inflate() returns Z_OK - and avail_out == 0. In that case, inflate has to be called again. - - Also, once all the data has been inflated, it returns Z_BUF_ERROR to - signal that the input buffer has been exhausted. - - Until now, the way to detect that a packet payload had been completely - decompressed was to check that no data remained on the input buffer - but that didn't account for the case where data remained on the internal - zlib buffers. - - That resulted in packets not being completely decompressed and the - missing data reappearing on the next packet, though the bug was masked - by the buffer allocation algorithm most of the time and only manifested - when transferring highly compressible data. - - This patch fixes the zlib usage. - - Signed-off-by: Salvador <sfandino@yahoo.com> - -- [Salvador brought this change] - - _libssh2_channel_read: fix data drop when out of window - - After filling the read buffer with data from the read queue, when the - window size was too small, "libssh2_channel_receive_window_adjust" was - called to increase it. In non-blocking mode that function could return - EAGAIN and, in that case, the EAGAIN was propagated upwards and the data - already read on the buffer lost. - - The function was also moving between the two read states - "libssh2_NB_state_idle" and "libssh2_NB_state_created" both of which - behave in the same way (excepting a debug statment). - - This commit modifies "_libssh2_channel_read" so that the - "libssh2_channel_receive_window_adjust" call is performed first (when - required) and if everything goes well, then it reads the data from the - queued packets into the read buffer. - - It also removes the useless "libssh2_NB_state_created" read state. - - Some rotted comments have also been updated. - - Signed-off-by: Salvador <sfandino@yahoo.com> - -- [Salvador Fandino brought this change] - - window_size: redid window handling for flow control reasons - - Until now, the window size (channel->remote.window_size) was being - updated just after receiving the packet from the transport layer. - - That behaviour is wrong because the channel queue may grow uncontrolled - when data arrives from the network faster that the upper layer consumes - it. - - This patch adds a new counter, read_avail, which keeps a count of the - bytes available from the packet queue for reading. Also, now the window - size is adjusted when the data is actually read by an upper layer. - - That way, if the upper layer stops reading data, the window will - eventually fill and the remote host will stop sending data. When the - upper layers reads enough data, a window adjust packet is delivered and - the transfer resumes. - - The read_avail counter is used to detect the situation when the remote - server tries to send data surpassing the window size. In that case, the - extra data is discarded. - - Signed-off-by: Salvador <sfandino@yahoo.com> - -Peter Stuge (15 Sep 2013) -- configure.ac: Call zlib zlib and not libz in text but keep option names - -- configure.ac: Reorder --with-* options in --help output - -- configure.ac: Rework crypto library detection - - This further simplifies adding new crypto libraries. - -- Clean up crypto library abstraction in build system and source code - - libssh2 used to explicitly check for libgcrypt and default to OpenSSL. - - Now all possible crypto libraries are checked for explicitly, making - the addition of further crypto libraries both simpler and cleaner. - -- configure.ac: Add zlib to Requires.private in libssh2.pc if using zlib - -- Revert "Added Windows Cryptography API: Next Generation based backend" - - This reverts commit d385230e15715e67796f16f3e65fd899f21a638b. - -Daniel Stenberg (7 Sep 2013) -- [Leif Salomonsson brought this change] - - sftp_statvfs: fix for servers not supporting statfvs extension - - Fixes issue arising when server does not support statfvs and or fstatvfs - extensions. sftp_statvfs() and sftp_fstatvfs() after this patch will - handle the case when SSH_FXP_STATUS is returned from server. - -- [Marc Hoersken brought this change] - - Added Windows Cryptography API: Next Generation based backend - -- [Kamil Dudka brought this change] - - partially revert "window_size: explicit adjustments only" - - This partially reverts commit 03ca9020756a4e16f0294e5b35e9826ee6af2364 - in order to fix extreme slowdown when uploading to localhost via SFTP. - - I was able to repeat the issue on RHEL-7 on localhost only. It did not - occur when uploading via network and it did not occur on a RHEL-6 box - with the same version of libssh2. - - The problem was that sftp_read() used a read-ahead logic to figure out - the window_size, but sftp_packet_read() called indirectly from - sftp_write() did not use any read-ahead logic. - -- _libssh2_channel_write: client spins on write when window full - - When there's no window to "write to", there's no point in waiting for - the socket to become writable since it most likely just will continue to - be. - - Patch-by: ncm - Fixes #258 - -- _libssh2_channel_forward_cancel: avoid memory leaks on error - - Fixes #257 - -- _libssh2_packet_add: avoid using uninitialized memory - - In _libssh2_packet_add, called by _libssh2_packet_read, a call to - _libssh2_packet_send that is supposed to send a one-byte message - SSH_MSG_REQUEST_FAILURE would send an uninitialized byte upon re-entry - if its call to _send returns _EAGAIN. - - Fixes #259 - -- _libssh2_channel_forward_cancel: accessed struct after free - - ... and the assignment was pointless anyway since the struct was about - to be freed. Bug introduced in dde2b094. - - Fixes #268 - -Peter Stuge (2 Jun 2013) -- [Marc Hoersken brought this change] - - Fixed compilation using mingw-w64 - -- [Marc Hoersken brought this change] - - knownhost.c: use LIBSSH2_FREE macro instead of free - - Use LIBSSH2_FREE instead of free since - _libssh2_base64_encode uses LIBSSH2_ALLOC - -Daniel Stenberg (18 May 2013) -- [Matthias Kerestesch brought this change] - - libssh2_agent_init: init ->fd to LIBSSH2_INVALID_SOCKET - - ... previously it was left at 0 which is a valid file descriptor! - - Bug: https://trac.libssh2.org/ticket/265 - - Fixes #265 - -- userauth_password: pass on the underlying error code - - _libssh2_packet_requirev() may return different errors and we pass that - to the parent instead of rewriting it. - - Bug: http://libssh2.org/mail/libssh2-devel-archive-2013-04/0029.shtml - Reported by: Cosmin - -Peter Stuge (9 May 2013) -- [Marc Hoersken brought this change] - - libcrypt.c: Fix typo in _libssh2_rsa_sha1_sign() parameter type - -Kamil Dudka (4 May 2013) -- configure.ac: replace AM_CONFIG_HEADER with AC_CONFIG_HEADERS - - Reported by: Quintus - Bug: https://trac.libssh2.org/ticket/261 - -Guenter Knauf (12 Apr 2013) -- Fixed copyright string for NetWare build. - -Daniel Stenberg (9 Apr 2013) -- [Richard W.M. Jones brought this change] - - sftp: Add support for fsync (OpenSSH extension). - - The new libssh2_sftp_fsync API causes data and metadata in the - currently open file to be committed to disk at the server. - - This is an OpenSSH extension to the SFTP protocol. See: - - https://bugzilla.mindrot.org/show_bug.cgi?id=1798 - -- [Richard W.M. Jones brought this change] - - sftp: statvfs: Along error path, reset the correct 'state' variable. - -- [Richard W.M. Jones brought this change] - - sftp: seek: Don't flush buffers on same offset - - Signed-off-by: Richard W.M. Jones <rjones@redhat.com> - -Guenter Knauf (9 Feb 2013) -- Updated dependency libs. - -- Fixed tool macro names. - -Daniel Stenberg (29 Nov 2012) -- [Seth Willits brought this change] - - compiler warnings: typecast strlen in macros - - ... in macro parameters to avoid compiler warnings about lost precision. - - Several macros in libssh2.h call strlen and pass the result directly to - unsigned int parameters of other functions, which warns about precision - loss because strlen returns size_t which is unsigned long on at least - some platforms (such as OS X). The fix is to simply typecast the - strlen() result to unsigned int. - -- libssh2.h: bump version to 1.4.4-DEV - -Version 1.4.3 (27 Nov 2012) - -Daniel Stenberg (27 Nov 2012) -- RELEASE-NOTES: fixed for 1.4.3 - -- sftp_read: return error if a too large package arrives - -Peter Stuge (13 Nov 2012) -- Only define _libssh2_dsa_*() functions when building with DSA support - -Guenter Knauf (8 Nov 2012) -- Added .def file to output. - -Kamil Dudka (1 Nov 2012) -- libssh2_hostkey_hash.3: update the description of return value - - The function returns NULL also if the hash algorithm is not available. - -Guenter Knauf (24 Oct 2012) -- Fixed mode acciedently committed. - -- Ignore generated file. - -- Added hack to make use of Makefile.inc. - - This should avoid further maintainance of the objects list. - -- Fixed MSVC NMakefile. - - Added missing source files; added resource for DLL. - -Kamil Dudka (22 Oct 2012) -- examples: use stderr for messages, stdout for data - - Reported by: Karel Srot - Bug: https://bugzilla.redhat.com/867462 - -- openssl: do not leak memory when handling errors - - ,.. in aes_ctr_init(). Detected by Coverity. - -- channel: fix possible NULL dereference - - ... in libssh2_channel_get_exit_signal(). Detected by Coverity. - -- Revert "aes: the init function fails when OpenSSL has AES support" - - This partially reverts commit f4f2298ef3635acd031cc2ee0e71026cdcda5864. - - We need to use the EVP_aes_???_ctr() functions in FIPS mode. - -- crypt: use hard-wired cipher block sizes consistently - -- openssl: do not ignore failure of EVP_CipherInit() - -- kex: do not ignore failure of libssh2_md5_init() - - The MD5 algorithm is disabled when running in FIPS mode. - -Daniel Stenberg (21 Aug 2012) -- [Peter Krempa brought this change] - - known_hosts: Fail when parsing unknown keys in known_hosts file. - - libssh2_knownhost_readfile() silently ignored problems when reading keys - in unsupported formats from the known hosts file. When the file is - written again from the internal structures of libssh2 it gets truntcated - to the point where the first unknown key was located. - - * src/knownhost.c:libssh2_knownhost_readfile() - return error if key - parsing fails - -- AUTHORS: synced with 42fec44c8a4 - - 31 recent authors added - -- [Dave Hayden brought this change] - - compression: add support for zlib@openssh.com - - Add a "use_in_auth" flag to the LIBSSH2_COMP_METHOD struct and a - separate "zlib@openssh.com" method, along with checking session->state - for LIBSSH2_STATE_AUTHENTICATED. Appears to work on the OpenSSH servers - I've tried against, and it should work as before with normal zlib - compression. - -- [Dmitry Smirnov brought this change] - - configure: gcrypt doesn't come with pkg-config support - - ... so use plain old -lgcrypt to the linker to link with it. - - Fixes #225 - -- sftp_read: Value stored to 'next' is never read - - Detected by clang-analyzer - -- publickey_init: errors are negative, fix check - - Detected by clang-analyzer. - -- [Maxime Larocque brought this change] - - session_free: wrong variable used for keeping state - - If libssh2_session_free is called without the channel being freed - previously by libssh2_channel_free a memory leak could occur. - - A mismatch of states variables in session_free() prevent the call to - libssh2_channel_free function. session->state member is used instead of - session->free_state. - - It causes a leak of around 600 bytes on every connection on my systems - (Linux, x64 and PPC). - - (Debugging done under contract for Accedian Networks) - - Fixes #246 - -Guenter Knauf (29 Jun 2012) -- Small NetWare makefile tweak. - -- Some small Win32 makefile fixes. - -Daniel Stenberg (19 Jun 2012) -- libssh2_userauth_publickey_fromfile_ex.3: mention publickey == NULL - -- comp_method_zlib_decomp: handle Z_BUF_ERROR when inflating - - When using libssh2 to perform an SFTP file transfer from the "JSCAPE MFT - Server" (http://www.jscape.com) the transfer failed. The default JSCAPE - configuration is to enforce zlib compression on SSH2 sessions so the - session was compressed. The relevant part of the debug trace contained: - - [libssh2] 1.052750 Transport: unhandled zlib error -5 - [libssh2] 1.052750 Failure Event: -29 - decompression failure - - The trace comes from comp_method_zlib_decomp() in comp.c. The "unhandled - zlib error -5" is the status returned from the zlib function - inflate(). The -5 status corresponds to "Z_BUF_ERROR". - - The inflate() function takes a pointer to a z_stream structure and - "inflates" (decompresses) as much as it can. The relevant fields of the - z_stream structure are: - - next_in - pointer to the input buffer containing compressed data - avail_in - the number of bytes available at next_in - next_out - pointer to the output buffer to be filled with uncompressed - data - avail_out - how much space available at next_out - - To decompress data you set up a z_stream struct with the relevant fields - filled in and pass it to inflate(). On return the fields will have been - updated so next_in and avail_in show how much compressed data is yet to - be processed and next_out and avail_out show how much space is left in - the output buffer. - - If the supplied output buffer is too small then on return there will be - compressed data yet to be processed (avail_in != 0) and inflate() will - return Z_OK. In this case the output buffer must be grown, avail_out - updated and inflate() called again. - - If the supplied output buffer was big enough then on return the - compressed data will have been exhausted (avail_in == 0) and inflate() - will return Z_OK, so the data has all been uncompressed. - - There is a corner case where inflate() makes no progress. That is, there - may be unprocessed compressed data and space available in the output - buffer and yet the function does nothing. In this case inflate() will - return Z_BUF_ERROR. From the zlib documentation and the source code it - is not clear under what circumstances this happens. It could be that it - needs to write multiple bytes (all in one go) from its internal state to - the output buffer before processing the next chunk of input but but - can't because there is not enough space (though my guesses as to the - cause are not really relevant). Recovery from Z_BUF_ERROR is pretty - simple - just grow the output buffer, update avail_out and call - inflate() again. - - The comp_method_zlib_decomp() function does not handle the case when - inflate() returns Z_BUF_ERROR. It treats it as a non-recoverable error - and basically aborts the session. - - Fixes #240 - -Guenter Knauf (12 Jun 2012) -- MinGW makefile tweaks. - - Use GNU tools when compiling on Linux. - Fixed dist and dev targets. - -- NetWare makefile tweaks. - - Changed to use Windows commandline tools instead of - GNU tools when compiling on Windows. Fixed dist and - dev targets. Enabled nlmconv error for unresolved - symbols. - -Daniel Stenberg (11 Jun 2012) -- Revert "config.rpath: generated file, no need to keep in git" - - This reverts commit 1ac7bd09cc685755577fb2c8829adcd081e7ab3c. - - This file still used by lib/*m4 functions so we need to keep the file - around. - -- BINDINGS: added PySsh2, a Python-ctypes binding - -Guenter Knauf (8 Jun 2012) -- Fixed MinGW debug build. - -Daniel Stenberg (5 Jun 2012) -- BINDINGS: Added the Cocoa/Objective-C one - - ... and sorted the bindings after the languages, alphabetically - - Reported by: Mike Abdullah - -- BINDINGS: document the bindings we know of - -Guenter Knauf (4 Jun 2012) -- Fixed LIBSSH2_INT64_T_FORMAT macro. - - Usually a format macro should hold the whole format, otherwise - it should be named a prefix. Also fixed usage of this macro in - scp.c for a signed var where it was used as prefix for unsigned. - -- Removed obsolete define from makefiles. - -- Renamed NetWare makefiles. - -- Renamed NetWare makefiles. - -- Synced MinGW makefiles with 56c64a6..39e438f. - - Also synced MinGW test makefile with b092696..f8cb874. - -Peter Stuge (30 May 2012) -- Revert "sftp: Don't send attrs.permissions on read-only SSH_FXP_OPEN" - - This reverts commit 04e79e0c798674a0796be8a55f63dd92e6877790. - -- sftp: Don't send attrs.permissions on read-only SSH_FXP_OPEN - - This works around a protocol violation in the ProFTPD 1.3.4 mod_sftp - server, as reported by Will Cosgrove in: - - http://libssh2.org/mail/libssh2-devel-archive-2012-05/0079.shtml - - Based on a suggested fix by TJ Saunders in: - - http://libssh2.org/mail/libssh2-devel-archive-2012-05/0104.shtml - -Guenter Knauf (28 May 2012) -- Try to detect OpenSSL build type automatically. - - Also fixed recently added libgdi32 linkage which is only - required when OpenSSL libs are linked statically. - -Daniel Stenberg (25 May 2012) -- config.rpath: generated file, no need to keep in git - -Guenter Knauf (22 May 2012) -- Updated dependency libary versions. - -Daniel Stenberg (18 May 2012) -- 1.4.3: towards the future - -Version 1.4.2 (18 May 2012) - -Daniel Stenberg (18 May 2012) -- RELEASE-NOTES: synced with 92a9f952794 - -Alexander Lamaison (15 May 2012) -- win32/libssh2_config.h: Remove hardcoded #define LIBSSH2_HAVE_ZLIB. - - Rationale: Everything else in this file states a fact about the win32 - platform that is unconditional for that platform. There is nothing - unconditional about the presence of zlib. It is neither included with - Windows nor with the platform SDK. Therefore, this is not an appropriate - place to assert its presence. Especially as, once asserted, it cannot be - overridden using a compiler flag. - - In contrast, if it is omitted, then it can easily be reasserted by adding - a compiler flag defining LIBSSH2_HAVE_ZLIB. - -Daniel Stenberg (14 May 2012) -- RELEASE-NOTES: synced with 69a3354467c - -- _libssh2_packet_add: SSH_MSG_CHANNEL_REQUEST default to want_reply - - RFC4254 says the default 'want_reply' is TRUE but the code defaulted to - FALSE. Now changed. - - Fixes #233 - -- gettimeofday: no need for a replacement under cygwin - - Fixes #224 - -Alexander Lamaison (13 May 2012) -- Prevent sftp_packet_read accessing freed memory. - - sftp_packet_add takes ownership of the packet passed to it and (now that we - handle zombies) might free the packet. sftp_packet_read uses the packet type - byte as its return code but by this point sftp_packet_add might have freed - it. This change fixes the problem by caching the packet type before calling - sftp_packet_add. - - I don't understand why sftp_packet_read uses the packet type as its return - code. A future change might get rid of this entirely. - -Daniel Stenberg (12 May 2012) -- sftp_packet_flush: flush zombies too - - As this function is called when the SFTP session is closed, it needs to - also kill all zombies left in the SFTP session to avoid leaking memory - just in case some zombie would still be in there. - -- sftp_packetlist_flush: zombies must not have responses already - - When flushing the packetlist, we must only add the request as a zombie - if no response has already been received. Otherwise we could wrongly - make it a zombie even though the response was already received and then - we'd get a zombie stuck there "forever"... - -- sftp_read: on EOF remove packet before flush - - Since the sftp_packetlist_flush() function will move all the existing - FXP_READ requests in this handle to the zombie list we must first remove - this just received packet as it is clearly not a zombie. - -- sftp_packet_require: sftp_packet_read() returning 0 is not an error - - Exactly as the comment in the code said, checking the return code from - sftp_packet_read() with <= was wrong and it should be < 0. With the new - filtering on incoming packets that are "zombies" we can now see this - getting zero returned. - -- sftp_packetlist_flush: only make it zombie if it was sent - - The list of outgoing packets may also contain packets that never were - sent off and we better not make them zombies too. - -- [Alexander Lamaison brought this change] - - Mark outstanding read requests after EOF as zombies. - - In order to be fast, sftp_read sends many read requests at once. With a small - file, this can mean that when EOF is received back, many of these requests are - still outstanding. Responses arriving after we close the file and abandon the - file handle are queued in the SFTP packet queue and never collected. This - causes transfer speed to drop as a progressively longer queue must be searched - for every packet. - - This change introduces a zombie request-ID list in the SFTP session that is - used to recognise these outstanding requests and prevent them being added to - the queue. - -Peter Stuge (23 Apr 2012) -- [Rafael Kitover brought this change] - - Update win32/GNUmakefile to use OpenSSL 1.0.1a - - libcrypto on win32 now depends on gdi32.dll, so move the OpenSSL LDLIBS - block to before the compiler definitions, so that libcrypto gets added - first, and then add -lgdi32 into the following common LDLIBS for gcc. - -Guenter Knauf (23 Apr 2012) -- Changed 'Requires' to 'Requires.private'. - - Only static builds need to link against the crypto libs. - -- Fixed 'Requires:' names. - - The 'Requires:' line lists the names of the .pc files. - -- Added 'Requires:' line to libssh2.pc. - - This is necessary so that other libs which lookup libssh2 info - via pkg-config can add the right crypto lib dependencies. - -- Updated dependency lib versions. - -Peter Stuge (18 Apr 2012) -- configure.ac: Add option to disable build of the example applications - - Examples are built by default. Any of the following options on the - configure command line will skip building them: - - --disable-examples-build - --enable-examples-build=no - --enable-examples-build=false - -- userauth.c: fread() from public key file to correctly detect any errors - - If the filename parameter for file_read_publickey() was the name of a - directory instead of a file then libssh2 would spin trying to fgetc() - from the FILE * for the opened directory when trying to determine the - length of the encoded public key, since fgetc() can't report errors. - - Use fread() instead to correctly detect this error condition along - with many others. - - This fixes the problem reported in - http://www.libssh2.org/mail/libssh2-devel-archive-2012-04/0021.shtml - - Reported-by: Oleksiy Zagorskyi <zalex_ua@i.ua> - -- Return LIBSSH2_ERROR_SOCKET_DISCONNECT on EOF when reading banner - -Guenter Knauf (17 Apr 2012) -- Fixed copyright year. - -- Updated dependency lib versions in static makefiles. - -Daniel Stenberg (6 Apr 2012) -- version: bump to 1.4.2 - - We're on the 1.4.2 track now (at least) - -Version 1.4.1 (4 Apr 2012) - -Daniel Stenberg (4 Apr 2012) -- RELEASE-NOTES: updated for 1.4.1 release - -- always do "forced" window updates - - When calling _libssh2_channel_receive_window_adjust() internally, we now - always use the 'force' option to prevent libssh2 to avoid sending the - update if the update isn't big enough. - - It isn't fully analyzed but we have seen corner cases which made a - necessary window update not get send due to this and then the other side - doesn't send data our side then sits waiting for forever. - -- channel_read: force window adjusts! - - if there's not enough room to receive the data that's being requested, - the window adjustment needs to be sent to the remote and thus the force - option has to be used. _libssh2_channel_receive_window_adjust() would - otherwise "queue" small window adjustments for a later packet but that - is really terribly for the small buffer read that for example is the - final little piece of a very large file as then there is no logical next - packet! - - Reported by: Armen Babakhanian - Bug: http://www.libssh2.org/mail/libssh2-devel-archive-2012-03/0130.shtml - -- [Paul Howarth brought this change] - - aes: the init function fails when OpenSSL has AES support - - The internal init function only worked fine when the configure script - didn't detect the OpenSSL AES_CTR function! - - Bug: http://www.libssh2.org/mail/libssh2-devel-archive-2012-03/0111.shtml - Reported by: Paul Howarth - -- [Matthew Booth brought this change] - - transport_send: Finish in-progress key exchange before sending data - - _libssh2_channel_write() first reads outstanding packets before writing - new data. If it reads a key exchange request, it will immediately start - key re-exchange, which will require sending a response. If the output - socket is full, this will result in a return from - _libssh2_transport_read() of LIBSSH2_ERROR_EAGAIN. In order not to block - a write because there is no data to read, this error is explicitly - ignored and the code continues marshalling a packet for sending. When it - is sent, the remote end immediately drops the connection because it was - expecting a continuation of the key exchange, but got a data packet. - - This change adds the same check for key exchange to - _libssh2_transport_send() that is in _libssh2_transport_read(). This - ensures that key exchange is completed before any data packet is sent. - -- channel_write: acknowledge transport errors - - When draining data off the socket with _libssh2_transport_read() (which - in turn has to be done so that we can be sure to have read any possible - window-increasing packets), this code previously ignored errors which - could lead to nasty loops. Now all error codes except EAGAIN will cause - the error to be returned at once. - - Bug: http://www.libssh2.org/mail/libssh2-devel-archive-2012-03/0068.shtml - Reported by: Matthew Booth - -- [Steven Dake brought this change] - - In examples/x11.c, Make sure sizeof passed to read operation is correct - - sizeof(buf) expands to 8 or 4 (since its a pointer). This variable may - have been static in the past, leading to this error. - - Signed-off-by: Steven Dake <sdake@redhat.com> - -- [Steven Dake brought this change] - - Fix suspicious sizeof usage in examples/x11.c - - In the x11 example, sizeof(buf) = 8UL (on x86_64), when this should - probably represent the buffer size available. I am not sure how to - test that this change is actually correct, however. - - Signed-off-by: Steven Dake <sdake@redhat.com> - -- sftp_packet_read: follow-up fix for EAGAIN/window adjust - - The commit in 7194a9bd7ba45 wasn't complete. This change makes sure - variables are initialized properly before used in the EAGAIN and window - adjust cases. - -- sftp_packet_add: use named error code instead of number - -- sftp_packet_add: verify the packet before accepting it - - In order to bail out as quickly as possible when things are wrong and - out of sync, make sure the SFTP message is one we understand. - -- SFTP: preserve the original error code more - - Lots of places in the code translated the original error into the more - generic LIBSSH2_ERROR_SOCKET_TIMEOUT but this turns out to distort the - original error reason a lot and makes tracking down the real origin of a - problem really hard. This change makes the original error code be - preserved to a larger extent when return up to the parent function. - -- sftp_packet_read: adjust window size as necessary - - Commit 03ca9020756 tried to simplify the window sizing logic but broke - SFTP readdir as there was no window sizing code left there so large - directory listings no longer worked. - - This change introduces window sizing logic to the sftp_packet_read() - function so that it now tells the remote about the local size having a - window size that suffice when it is about to ask for directory data. - - Bug: http://www.libssh2.org/mail/libssh2-devel-archive-2012-03/0069.shtml - Reported by: Eric - -- [Steven Dake brought this change] - - Tell C compiler we don't care about return code of libssh2_init - - The call of libssh2_init returns a return code, but nothing could be done - within the _libssh2_init_if_needed execution path. - - Signed-off-by: Steven Dake <sdake@redhat.com> - -- [Steven Dake brought this change] - - Add comment indicating a resource leak is not really a resource leak - - While possibly obvious to those investigating the code, coverity complains - about this out of scope leak. - - Signed-off-by: Steven Dake <sdake@redhat.com> - -- [Steven Dake brought this change] - - Use safer snprintf rather then sprintf in scp_send() - - Signed-off-by: Steven Dake <sdake@redhat.com> - -- [Steven Dake brought this change] - - Use safer snprintf rather then sprintf in scp_recv() - - While the buffer is indeed allocated to a safe length, better safe then sorry. - - Signed-off-by: Steven Dake <sdake@redhat.com> - -- [Steven Dake brought this change] - - use snprintf in knownhost_writeline() rather then sprintf - - Although the function checks the length, if the code was in error, there - could potentially be a buffer overrun with the use of sprintf. Instead replace - with snprintf. - - Signed-off-by: Steven Dake <sdake@redhat.com> - -- [Steven Dake brought this change] - - Add tracing to print packets left on session at libssh2_session_free - - Signed-off-by: Steven Dake <sdake@redhat.com> - -Peter Stuge (2 Mar 2012) -- Define and use LIBSSH2_INVALID_SOCKET instead of INVALID_SOCKET - - INVALID_SOCKET is a special value in Windows representing a - non-valid socket identifier. We were #defining this to -1 on - non-Windows platforms, causing unneccessary namespace pollution. - Let's have our own identifier instead. - - Thanks to Matt Lawson for pointing this out. - -- nw/Makefile.netware: Fix project name typo to avoid needless confusion - -- example/x11: Set raw terminal mode manually instead of with cfmakeraw() - - OpenSolaris has no cfmakeraw() so to make the example more portable - we simply do the equivalent operations on struct termios ourselves. - - Thanks to Tom Weber for reporting this problem, and finding a solution. - -Daniel Stenberg (17 Feb 2012) -- sftp_write: cannot return acked data *and* EAGAIN - - Whenever we have acked data and is about to call a function that *MAY* - return EAGAIN we must return the number now and wait to get called - again. Our API only allows data *or* EAGAIN and we must never try to get - both. - -Peter Stuge (13 Feb 2012) -- example/x11: Build only when sys/un.h is found by configure - - The example can't be built on systems without AF_UNIX sockets. - -Daniel Stenberg (10 Feb 2012) -- [Alexander Lamaison brought this change] - - Simplified sftp_read. - - Removed the total_read variable that originally must have tracked how - much data had been written to the buffer. With non-blocking reads, we - must return straight away once we have read data into the buffer so this - variable served not purpose. - - I think it was still hanging around in case the initial processing of - 'leftover' data meant we wrote to the buffer but this case, like the - others, must return immediately. Now that it does, the last remaining - need for the variable is gone. - -- [Alexander Lamaison brought this change] - - Cleaned up sftp_read and added more explanation. - - Replaced the gotos which were implementing the state machine with - a switch statement which makes the states more explicit. - -- sftp_read: avoid data *and* EAGAIN - - Whenever we have data and is about to call a function that *MAY* return - EAGAIN we must return the data now and wait to get called again. Our API - only allows data *or* EAGAIN and we must never try to get both. - -Peter Stuge (2 Feb 2012) -- Add a tcpip-forward example which demonstrates remote port forwarding - -- libssh2.h: Add missing prototype for libssh2_session_banner_set() - -- example/subsystem_netconf.c: Return error when read buffer is too small - - Also remove a little redundancy in the read loop condition. - -- example/subsystem_netconf.c: Add a missing newline in an error message - -- Fix undefined reference to _libssh_error in libgcrypt backend - - Commit 209de22299b4b58e582891dfba70f57e1e0492db introduced a function - call to a non-existing function, and since then the libgcrypt backend - has not been buildable. - -Version 1.4.0 (31 Jan 2012) - -Daniel Stenberg (31 Jan 2012) -- RELEASE-NOTES: synced with 6bd584d29 for 1.4.0 - -- s/1.3.1/1.4.0 - - We're bumping the minor number - -- [Jernej Kovacic brought this change] - - libssh2_session_supported_algs: fix compiler warning - -- [Jernej Kovacic brought this change] - - session_supported_algs docs: added an example - -- [Gellule Xg brought this change] - - sftp-seek: clear EOF flag - - Set the EOF flag to False when calling seek64 to be able to get some - data back on a following read - -- [Peter Krempa brought this change] - - userauth: Provide more informations if ssh pub key extraction fails - - If the function that extracts/computes the public key from a private key - fails the errors it reports were masked by the function calling it. This - patch modifies the key extraction function to return errors using - _libssh_error() function. The error messages are tweaked to contain - reference to the failed operaton in addition to the reason. - - * AUTHORS: - add my name - * libgcrypt.c: _libssh2_pub_priv_keyfile(): - return a more verbose - error using - _libssh2_error() func. - * openssl.c: - modify call graph of _libssh2_pub_priv_keyfile() to use - _libssh2_error for error reporting(); - * userauth.c: - tweak functions calling _libssh2_pub_priv_keyfile() not - to shadow error messages - -- TODO: remove issues we (sort of) did already - -- ssh2_exec: skip error outputs for EAGAIN - - Since the example uses non-blocking mode, it will just flood the output - with this "nonsense" error. - -Guenter Knauf (30 Nov 2011) -- Some NetWare makefile tweaks. - -Daniel Stenberg (18 Nov 2011) -- LIBSSH2_SFTP_PACKET_MAXLEN: increase to 80000 - - Some SFTP servers send SFTP packets larger than 40000. Since the limit - is only present to avoid insane sizes anyway, we can easily bump it. - - The define was formerly in the public header libssh2_sftp.h but served - no external purpose and was moved into the source dir. - - Bug: http://www.libssh2.org/mail/libssh2-devel-archive-2011-11/0004.shtml - Reported by: Michael Harris - -Alexander Lamaison (18 Nov 2011) -- [Peter Krempa brought this change] - - knownhost_check(): Don't dereference ext if NULL is passed - - Documentation for libssh2_knownhost_checkp() and related functions - states that the last argument is filled with data if non-NULL. - - "knownhost if set to non-NULL, it must be a pointer to a 'struct - libssh2_knownhost' pointer that gets filled in to point to info about a - known host that matches or partially matches." - - In this function ext is dereferenced even if set to NULL, causing - segfault in applications not needing the extra data. - -Daniel Stenberg (11 Nov 2011) -- [Peter Krempa brought this change] - - knownhost_add: Avoid dereferencing uninitialized memory on error path. - - In function knownhost_add, memory is alocated for a new entry. If normal - alocation is used, memory is not initialized to 0 right after, but a - check is done to verify if correct key type is passed. This test is done - BEFORE setting the memory to null, and on the error path function - free_host() is called, that tries to dereference unititialized memory, - resulting into a glibc abort(). - - * knownhost.c - knownhost_add(): - move typemask check before alloc - -- windows build: add define to avoid compiler warning - - A recent mingw compiler has started to complain on "#warning Please - include winsock2.h before windows.h" unless the magic define is set - first. - - Reported by: Vincent Torri - Bug: http://www.libssh2.org/mail/libssh2-devel-archive-2011-10/0064.shtml - -Henrik Nordstrom (31 Oct 2011) -- [Vincent Torri brought this change] - - Correct Windows include file name case, simplifying cross-compilation - - When cross compiling to Windows, libssh2.h include Windows header files - with upper case filenames : BaseTsd.h and WinSock2.h. - - These files have lowercase names with mingw-w64 (iirc, it's the same with - mingw). And as on Windows, being lowercase or uppercase does not matter. - -Daniel Stenberg (25 Oct 2011) -- [Jernej Kovacic brought this change] - - libssh2_session_supported_algs: added - -- [Kamil Dudka brought this change] - - example/sftp_RW_nonblock: do not ignore LIBSSH2_ERROR_EAGAIN - - Bug: https://bugzilla.redhat.com/745420 - -Peter Stuge (5 Oct 2011) -- example/ssh2_agent: Print host key fingerprint before authentication - - Also moves the comment about not being authenticated to before the - agent authentication takes place, so that it better matches the code. - -Daniel Stenberg (29 Sep 2011) -- OpenSSL EVP: fix threaded use of structs - - Make sure we don't clear or reset static structs after first init so - that they work fine even when used from multiple threads. Init the - structs in the global init. - - Help and assistance by: John Engstrom - - Fixes #229 (again) - -- openssl: don't init static structs differently - - make_ctr_evp() is changed to take a struct pointer, and then each - _libssh2_EVP_aes_[keylen]_ctr function is made to pass in their own - static struct - - Reported by: John Engstrom - Fixes #229 - -Guenter Knauf (27 Sep 2011) -- Removed obsolete include path. - -Daniel Stenberg (21 Sep 2011) -- read_state: clear the state variable better - - Set read_state back to idle before trying to send anything so that if - the state somehow is wrongly set. - - Also, avoid such a case of confusion by resetting the read_state when an - sftp handle is closed. - -- sftp_read: remove leftover fprintf - - Reported by: Alexander Lamaison - -- sftp.h: fix the #ifdef to prevent multiple inclusions - -- sftp_read: use a state variable to avoid bad writes - - When a channel_write call has gotten an EAGAIN back, we try harder to - continue the same write in the subsequent invoke. - -- window_size: explicit adjustments only - - Removed the automatic window_size adjustments from - _libssh2_channel_read() and instead all channel readers must now make - sure to enlarge the window sizes properly themselves. - - libssh2_channel_read_ex() - the public function, now grows the window - size according to the requested buffer size. Applications can still opt - to grow the window more on demand. Larger windows tend to give higher - performance. - - sftp_read() now uses the read-ahead logic to figure out a window_size. - -- libssh2.h: bump the default window size to 256K - -- libssh2_userauth_keyboard_interactive.3: fix man warning - - It seemed to occur due to the excessive line length - -- [Mikhail Gusarov brought this change] - - Add missing .gitignore entries - -- [Mikhail Gusarov brought this change] - - Add manpage syntax checker to 'check' target - - In virtually every libssh2 release Debian's lintian catches syntax errors in - manpages. Prevent it by checking manpages as a part of testsuite. - -- libssh2_banner_set.3: fix nroff syntax mistake - -Guenter Knauf (10 Sep 2011) -- Use predefined resource compiler macro. - -- Added casts to silent compiler warnings. - -- Fixed uint64_t printf. - -- Fixed macro function signatures. - -- NetWare makefile tweaks. - -- Removed unused var. - -- Added 2 samples not mentioned. - -- Dont build x11 sample with MinGW. - -- Fixed executable file description. - -- Removed unused var. - -- Kill stupid gcc 3.x uninitialized warning. - -- Build all examples. - -- More MinGW makefile tweaks. - - Renamed *.mingw makefiles to GNUmakefile since GNU make picks these - up automatically, and therefore win32/Makefile removed. - -- Removed forgotten WINSOCK_VERSION defines. - -Daniel Stenberg (9 Sep 2011) -- libssh2_session_startup(3) => libssh2_session_handshake(3) - - Propagate for the current function in docs and examples. - libssh2_session_startup() is deprecated. - -- libssh2_banner_set => libssh2_session_banner_get - - Marked the old function as deprecated. Added the new name in the correct - name space with the same arguments and functionality. - -- new function: libssh2_session_banner_get - - Returns the banner from the server handshake - - Fixes #226 - -- libssh2.h: bump version to 1.4.0 for new function(s) - -- remove embedded CVS/svn tags - -- [liuzl brought this change] - - API add:libssh2_sftp_get_channel - - Return the channel of sftp, then caller can - control the channel's behavior. - - Signed-off-by: liuzl <xieepp@gmail.com> - -- _libssh2_channel_read: react on errors from receive_window_adjust - - Previously the function would ignore all errors except for EAGAIN. - -- sftp_read: extend and clarify the documentation - -- sftp_read: cap the read ahead maximum amount - - Now we only go up to LIBSSH2_CHANNEL_WINDOW_DEFAULT*30 bytes SFTP read - ahead, which currently equals 64K*30 == 1966080 bytes. - -- _libssh2_channel_read: fix non-blocking window adjusting - - If EAGAIN is returned when adjusting the receive window, we must not - read from the transport directly until we've finished the adjusting. - -Guenter Knauf (8 Sep 2011) -- Fix for systems which need sys/select.h. - -- The files were not gone but renamed ... - -Daniel Stenberg (6 Sep 2011) -- sftp_read: added documenting comment - - Taken from some recent email conversations I added some descriptions of - the logic in sftp_read() to aid readers. - -- 1.3.1: start the work - -Version 1.3.0 (6 Sep 2011) - -Daniel Stenberg (6 Sep 2011) -- Makefile.am: the Makefile.win32 files are gone - -- RELEASE-NOTES: updated for 1.3.0 - -- sftp_read: a short read is not end of file - - A returned READ packet that is short will now only reduce the - offset. - - This is a temporary fix as it is slightly better than the previous - approach but still not very good. - -- [liuzl brought this change] - - _libssh2_packet_add: adjust window size when truncating - - When receiving more data than what the window size allows on a - particular channel, make sure that the window size is adjusted in that - case too. Previously it would only adjust the window in the non-error - case. - -Guenter Knauf (29 Aug 2011) -- Silent compiler warning with MinGW64. - -- Fixed link to native Win32 awk tool. - -- Renamed MinGW makefiles. - -- Some MinGW makefile tweaks. - - Enable build without GNU tools and with MinGW64 compiler. - -- Fixed aes_ctr_do_cipher() signature. - -Daniel Stenberg (26 Aug 2011) -- [liuzl brought this change] - - libssh2_sftp_seek64: flush packetlist and buffered data - - When seeking to a new position, flush the packetlist and buffered data - to prevent already received or pending data to wrongly get used when - sftp-reading from the new offset within the file. - -- sftp_read: advance offset correctly for buffered copies - - In the case where a read packet has been received from the server, but - the entire contents couldn't be copied to the user-buffer, the data is - instead buffered and copied to the user's buffer in the next invocation - of sftp_read(). When that "extra" copy is made, the 'offset' pointer was - not advanced accordingly. - - The biggest impact of this flaw was that the 'already' variable at the - top of the function that figures out how much data "ahead" that has - already been asked for would slowly go more and more out of sync, which - could lead to the file not being read all the way to the end. - - This problem was most noticable in cases where the application would - only try to read the exact file size amount, like curl does. In the - examples libssh2 provides the sftp read function is most often called - with a fixed size large buffer and then the bug would not appear as - easily. - - This bug was introduced in the SFTP rewrite in 1.2.8. - - Bug: http://curl.haxx.se/mail/lib-2011-08/0305.html - http://www.libssh2.org/mail/libssh2-devel-archive-2011-08/0085.shtml - -- wrap some long lines < 80 columns - -- LIBSSH2_RECV: fix typo, use the RECV_FD macro - -- subsystem_netconf.c: fix compiler warnings - -- [Henrik Nordstrom brought this change] - - Custom callbacks for performing low level socket I/O - -- version bump: start working towards 1.3.0 - -Version 1.2.9 (16 Aug 2011) - -Daniel Stenberg (16 Aug 2011) -- RELEASE-NOTES: synced with 95d69d3a81261 - -- [Henrik Nordstrom brought this change] - - Document prototypes for macro defined functions - -- [Henrik Nordstrom brought this change] - - Avoid reuse after free when closing X11 channels - -- _libssh2_channel_write: handle window_size == 0 better - - When about to send data on the channel and the window size is 0, we must - not just return 0 if the transport_read() function returned EAGAIN as it - then causes a busy-loop. - - Bug: http://libssh2.org/mail/libssh2-devel-archive-2011-08/0011.shtml - -- gettimeofday: fix name space pollution - - For systems without its own gettimeofday() implementation, we still must - not provide one outside our namespace. - - Reported by: Bill Segall - -Dan Fandrich (5 Aug 2011) -- libssh2.pc.in: Fixed spelling in pkgconfig file - -Peter Stuge (17 Jul 2011) -- example/subsystem_netconf.c: Add missing #include <string.h> - -- example/subsystem_netconf.c: Discard ]]>]]> and return only XML response - -- example/subsystem_netconf.c: Fix uninitialized variable bug - -- example: Add subsystem_netconf.c - - This example demonstrates how to use libssh2 to send a request to - the NETCONF subsystem available e.g. in JunOS. - - See also http://tools.ietf.org/html/draft-ietf-netconf-ssh-06 - -Daniel Stenberg (16 Jul 2011) -- man page cleanups: non-existing functions need no man pages - -- libssh2_new_host_entry.3: removed - - This is just junk leftovers. - -- userauth_keyboard_interactive: fix buffer overflow - - Partly reverse 566894494b4972ae12 which was simplifying the code far too - much and ended up overflowing a buffer within the LIBSSH2_SESSION - struct. Back to allocating the buffer properly like it used to do. - - Bug: http://www.libssh2.org/mail/libssh2-devel-archive-2011-06/0032.shtml - Reported by: Alfred Gebert - -- keyboard-interactive man page: cleaned up - -- [Alfred Gebert brought this change] - - _libssh2_recv(): handle ENOENT error as EAGAIN - - A sftp session failed with error "failure establishing ssh session" on - Solaris and HP-UX. Sometimes the first recv() function call sets errno - to ENOENT. In the man pages for recv of Solaris and HP-UX the error - ENOENT is not documented. - - I tested Solaris SPARC and x86, HP-UX i64, AIX, Windows and Linux. - -- agent_list_identities: fix out of scope access - - An auto variable out of scope was being referenced and used. - - fixes #220 - -- _libssh2_wait_socket: fix timeouts for poll() uses - -- windows: inclusion fix - - include winsock2.h for all windows compilers - -- keyb-interactive: add the fixed buffer - - Belongs to commit 5668944 - -- code cleanup: don't use C99/c++ comments - - We aim for C89 compliance - -- keyb-interactive: allow zero length fields - - Allow zero length fields so they don't cause malloc(0) calls - - Avoid free()ing NULL pointers - - Avoid a malloc of a fixed 5 byte buffer. - -- libssh2_channel_process_startup.3: clean up - - Remove the references to the macro-fied shortcuts as they have their own - individual man pages. - - Made the prototype different and more readable. - -- man page: fix .BR lines - - We don't use \fI etc on .BR lines - -- userauth_keyboard_interactive: skip code on zero length auth - -- libssh2_channel_forward_accept.3: mention how to get error - - Since this returns a pointer, libssh2_session_last_errno() must be used - to get the actual error code and it wasn't that clear before. - -- timeout docs: mention they're added in 1.2.9 - -- sftp_write_sliding.c: indent fix - - Use the standard indenting and removed CVS leftover comment - -- [zl liu brought this change] - - sftp_write_sliding: send the complete file - - When reaching the end of file there can still be data left not sent. - -- [Douglas Masterson brought this change] - - session_startup: init state properly - - libssh2_session_startup() didn't set the state correctly so it could get - confused. - - Fixes #218 - -- timeout: added man pages - -- BLOCK_ADJUST_ERRNO: move rc to right level - - We can't declare the variable within the block and use it in the final - do-while() expression to be properly portable C89. - -- [Matt Lilley brought this change] - - adds a timeout to blocking calls - - Fixes bug #160 as per Daniel's suggestion - - Adds libssh2_session_set_timeout() and libssh2_session_get_timeout() - -- SCP: fix incorrect error code - - After an error occurs in libssh2_scp_recv() or libssh2_scp_send(), the - function libssh2_session_last_error() would return - LIBSSH2_ERROR_SOCKET_NONE on error. - - Bug: http://trac.libssh2.org/ticket/216 - Patch by: "littlesavage" - - Fixes #216 - -Guenter Knauf (19 Apr 2011) -- Updated default (recommended) dependency versions. - -Daniel Stenberg (17 Apr 2011) -- libssh2_session_block_directions: fix mistake - - The last LIBSSH2_SESSION_BLOCK_INBOUND should be - LIBSSH2_SESSION_BLOCK_OUTBOUND - - And I shortened the short description - - Reported by: "drswinghead" - -- msvcproj: added libs and debug stuff - - Added libraries needed to link whether using openssl dynamically or - statically - - Added LIBSSH2DEBUG define to debug versions to enable tracing - - URL: http://trac.libssh2.org/ticket/215 - Patch by: Mark Smith - -- sftp_write: clean offsets on error - - When an error has occurred on FXP_WRITE, we must make sure that the - offset, sent offset and acked counter are reset properly. - -- example/.gitignore: ignore built binaries - -- sftp_write: flush the packetlist on error - - When an error occurs during write, flush the entire list of pending - outgoing SFTP packets. - -- keepalive: add first basic man pages - - Someone on IRC pointed out that we don't have these documented so I - wrote up a first set based on the information in the wiki: - http://trac.libssh2.org/wiki/KeepAlive - -- scp_write_nonblock.c: remove pointless check - - libssh2_channel_write() cannot return a value that is larger than the - input length value - -Mikhail Gusarov (9 Apr 2011) -- s/\.NF/.nf/ to fix wrong macro name caught by man --warnings - -Daniel Stenberg (6 Apr 2011) -- version: bump to 1.2.9_dev - - Also update the copyright year range to include 2011 - -- configure: fix $VERSION - - Stop using the $VERSION variable as it seems to be magically used by - autoconfig itself and thus gets set to the value set in AC_INIT() - without us wanting that. $LIBSSH2VER is now the libssh2 version as - detected. - - Reported by: Paul Howarth - Bug: http://www.libssh2.org/mail/libssh2-devel-archive-2011-04/0008.shtml - -- maketgz: use git2news.pl by the correct name - -Version 1.2.8 (4 Apr 2011) - -Daniel Stenberg (4 Apr 2011) -- RELEASE-NOTES: synced with fabf1a45ee - -- NEWS: auto-generated from git - - Starting now, the NEWS file is generated from git using the git2news.pl - script. This makes it always accurate and up-to-date, even for daily - snapshots etc. - -- sftp_write: handle FXP_WRITE errors - - When an sftp server returns an error back on write, make sure the - function bails out and returns the proper error. - -- configure: stop using the deprecated AM_INIT_AUTOMAKE syntax - -Alexander Lamaison (13 Mar 2011) -- Support unlimited number of host names in a single line of the known_hosts file. - - Previously the code assumed either a single host name or a hostname,ip-address pair. However, according to the spec [1], there can be any number of comma separated host names or IP addresses. - - [1] http://www.openbsd.org/cgi-bin/man.cgi?query=sshd&sektion=8 - -Daniel Stenberg (26 Feb 2011) -- libssh2_knownhost_readfile.3: clarify return value - - This function returns the number of parsed hosts on success, not just - zero as previously documented. - -Peter Stuge (26 Feb 2011) -- Don't save allocated packet size until it has actually been allocated - - The allocated packet size is internal state which needs to match reality - in order to avoid problems. This commit fixes #211. - -Daniel Stenberg (21 Feb 2011) -- [Alfred Gebert brought this change] - - session_startup: manage server data before server identification - - Fix the bug that libssh2 could not connect if the sftp server - sends data before sending the version string. - - http://tools.ietf.org/html/rfc4253#section-4.2 - - "The server MAY send other lines of data before sending the version - string. Each line SHOULD be terminated by a Carriage Return and Line - Feed. Such lines MUST NOT begin with "SSH-", and SHOULD be encoded - in ISO-10646 UTF-8 [RFC3629] (language is not specified). Clients - MUST be able to process such lines." - -- [Alfred Gebert brought this change] - - fullpacket: decompression only after init - - The buffer for the decompression (remote.comp_abstract) is initialised - in time when it is needed. With this fix decompression is disabled when - the buffer (remote.comp_abstract) is not initialised. - - Bug: http://trac.libssh2.org/ticket/200 - -- _libssh2_channel_read: store last error - - When the transport layer returns EAGAIN this function didn't call - _libssh2_error() which made the last_error not get set. - -- sftp_write: clarified the comment header - -- sftp_read: avoid wrapping counter to insanity - - As pointed out in bug #206, if a second invoke of libssh2_sftp_read() - would shrink the buffer size, libssh2 would go nuts and send out read - requests like crazy. This was due to an unsigned variable turning - "negative" by some wrong math, and that value would be the amount of - data attempt to pre-buffer! - - Bug: http://trac.libssh2.org/ticket/206 - -- sftp_packet_read: use 32bit variables for 32bit data - -- libssh2_sftp_stat_ex.3: cleaned up, extended - - Removed the macros from it as they have their own man pages. - - Added the LIBSSH2_SFTP_ATTRIBUTES struct in here for easier reference. - -- sftp_readdir: return error if buffer is too small - - If asked to read data into a buffer and the buffer is too small to hold - the data, this function now returns an error instead of as previously - just copy as much as fits. - -- sftp_symlink: return error if receive buffer too small - - and clean up some variable type mismatches - - Discussion: http://www.libssh2.org/mail/libssh2-devel-archive-2011-01/0001.shtml - -- docs: clarify what happens with a too small buffer - - This flaw is subject to change, but I figured it might be valuable to - users of existing code to know how it works. - -- channel_request_pty_size: fix reqPTY_state - - The state variable isn't properly set so every other call to the - function fails! - - Bug: http://libssh2.org/mail/libssh2-devel-archive-2010-12/0096.shtml - Reported by: Steve Legg - -- data size: cleanup - - Fix 64bit warnings by using (s)size_t and dedicated uint32_t types more. - -- [Pierre Joye brought this change] - - ssize_t: proper typedef with MSVC compilers - - As discussed on the mailing list, it was wrong for win64 and using the - VC-provided type is the safest approach instead of second- guessing - which one it should be. - -Guenter Knauf (22 Dec 2010) -- Updated OpenSSL version. - -- Expanded tabs to spaces. - -Peter Stuge (21 Dec 2010) -- [Joey Degges brought this change] - - _libssh2_ntohu64: fix conversion from network bytes to uint64 - - Cast individual bytes to uint64 to avoid overflow in arithmetic. - -Daniel Stenberg (20 Dec 2010) -- libssh2_userauth_list: language fix - - "faily" is not a good English word, and I also cleaned up some other minor - mistakes - -- crypto: unify the generic functions - - Added crypto.h that is the unified header to include when using crypto - functionality. It should be the only header that needs to adapt to the - underlying crypto library in use. It provides the set of prototypes that - are library agnostic. - -- [Mark Smith brought this change] - - userauth: derive publickey from private - - Pass a NULL pointer for the publickey parameter of - libssh2_userauth_publickey_fromfile and - libssh2_userauth_hostbased_fromfile functions. In this case, the - functions recompute the public key from the private key file data. - - This is work done by Jean-Louis CHARTON - <Jean-Louis.CHARTON@oikialog.com>, then adapted by Mark Smith and - slightly edited further by me Daniel. - - WARNING: this does leave the feature NOT WORKING when libssh2 is built - to use libgcrypt instead of OpenSSL simply due to lack of - implementation. - -- ssh2_echo: Value stored to 'exitcode' is never read - -- _libssh2_packet_add: fix SSH_MSG_DEBUG weirdness - - I believe I may have caused this weird typo style error when I cleaned - up this function a while ago. Corrected now. - -- uint32: more longs converted to proper types - - I also moved the MAC struct over to the mac.h header file and made sure - that the users of that struct include that file. - -- SFTP: more types to uint32_t - - The 'num_names' field in the SSH_FXP_NAME response is an unsigned 32bit - value so we make sure to treat it like that. - -- SFTP: request_ids are uint32_t - - I went over the code and made sure we use uint32_t all over for the - request_id data. It is an unsigned 32bit value on the wire. - -- SFTP: store request_id separately in packets - - By using a new separate struct for incoming SFTP packets and not sharing - the generic packet struct, we can get rid of an unused field and add a - new one dedicated for holding the request_id for the incoming - package. As sftp_packet_ask() is called fairly often, a "mere" integer - comparison is MUCH faster than the previous memcmp() of (typically) 5 - bytes. - -- libssh2_sftp_open_ex: man page extended and cleaned up - - I added the missing documentation for the 'flags' argument. - -- SFTP: unify the READ/WRITE chunk structs - -- SFTP: fix memory leaks - - Make sure that we cleanup remainders when the handle is closed and when - the subsystem is shutdown. - - Existing flaw: if a single handle sends packets that haven't been - replied to yet at the time when the handle is closed, those packets will - arrive later and end up in the generic packet brigade queue and they - will remain in there until flushed. They will use unnecessary memory, - make things slower and they will ruin the SFTP handling if the - request_id counter ever wraps (highly unlikely to every happen). - -- sftp_close_handle: packet list is generic - - Fix comment, simplify the loop logic - -- sftp_read: pipeline reads - - The SFTP read function now does transfers the same way the SFTP write - function was made to recently: it creates a list of many outgoing - FXP_READ packets that each asks for a small data chunk. The code then - tries to keep sending read request while collecting the acks for the - previous requests and returns the received data. - -- sftp_write: removed unused variable - -- _libssh2_channel_close: don't call transport read if disconnected - - The loop that waits for remote.close to get set may end up looping - forever since session->socket_state gets set to - LIBSSH2_SOCKET_DISCONNECTED by the packet_add() function called from the - transport_read() function and after having been set to - LIBSSH2_SOCKET_DISCONNECTED, the transport_read() function will only - return 0. - - Bug: http://trac.libssh2.org/ticket/198 - -- libssh2_sftp_seek64: new man page - - Split off libssh2_sftp_seek64 from the libssh2_sftp_seek man page, and - mentioned that we consider the latter deprecated. Also added a mention - about the dangers of doing seek during writing or reading. - -- sftp_seek: fix - - The new SFTP write code caused a regression as the seek function no - longer worked as it didn't set the write position properly. - - It should be noted that seeking is STRONGLY PROHIBITED during upload, as - the upload magic uses two different offset positions and the multiple - outstanding packets etc make them sensitive to change in the midst of - operations. - - This functionality was just verified with the new example code - sftp_append. This bug was filed as bug #202: - - Bug: http://trac.libssh2.org/ticket/202 - -- sftp_append: new example doing SFTP append - -- MAX_SFTP_OUTGOING_SIZE: 30000 - - I ran SFTP upload tests against localhost. It showed that to make the - app reach really good speeds, I needed to do a little code tweak and - change MAX_SFTP_OUTGOING_SIZE from 4000 to 30000. The tests I did before - with the high latency tests didn't show any real difference whatever I - had that size set to. - - This number is the size in bytes that libssh2 cuts off the large input - buffer and sends off as an individual sftp packet. - -- sftp_write_sliding.c: new example - - This is an example that is very similar to sftp_write_nonblock.c, with - the exception that this uses - - 1 - a larger upload buffer - - 2 - a sliding buffer mechnism to allow the app to keep sending lots of - data to libssh2 without having to first drain the buffer. - - These are two key issues to make libssh2 SFTP uploads really perform - well at this point in time. - -- cpp: s/#elsif/#elif - - This looks like a typo as #elsif is not really C... - -- _libssh2_channel_write: revert channel_write() use - - The attempts made to have _libssh2_channel_write() accept larger pieces - of data and split up the data by itself into 32700 byte chunks and pass - them on to channel_write() in a loop as a way to do faster operations on - larger data blocks was a failed attempt. - - The reason why it is difficult: - - The API only allows EAGAIN or a length to be returned. When looping over - multiple blocks to get sent, one block can get sent and the next might - not. And yet: when transport_send() has returned EAGAIN we must not call - it again with new data until it has returned OK on the existing data it - is still working on. This makes it a mess and we do get a much easier - job by simply returning the bytes or EAGAIN at once, as in the EAGAIN - case we can assume that we will be called with the same arguments again - and transport_send() will be happy. - - Unfortunately, I think we take a small performance hit by not being able - to do this. - -- ssh2_echo: new example - - This is a new example snippet. The code is largely based on ssh2_exec, - and is written by Tommy Lindgren. I edited it into C90 compliance and to - conform to libssh2 indent style and some more. - -- send_existing: return after send_existing - - When a piece of data is sent from the send_existing() function we must - make the parent function return afterwards. Otherwise we risk that the - parent function tries to send more data and ends up getting an EGAIN for - that more data and since it can only return one return code it doesn't - return info for the successfully sent data. - - As this change is a regression I now added a larger comment explaining - why it has to work like this. - -- _libssh2_channel_write: count resent data as written - - In the logic that resends data that was kept for that purpose due to a - previous EAGAIN, the data was not counted as sent causing badness. - -Peter Stuge (13 Nov 2010) -- Use fprintf(stderr, ) instead of write(2, ) for debugging - -- session/transport: Correctly handle when _libssh2_send() returns -EAGAIN - -- src/agent.c: Simplify _libssh2_send() error checking ever so slightly - -Daniel Stenberg (12 Nov 2010) -- send/recv: use _libssh2_recv and _libssh2_send now - - Starting now, we unconditionally use the internal replacement functions - for send() and recv() - creatively named _libssh2_recv() and - _libssh2_send(). - - On errors, these functions return the negative 'errno' value instead of - the traditional -1. This design allows systems that have no "natural" - errno support to not have to invent it. It also means that no code - outside of these two transfer functions should use the errno variable. - -- channel_write: move some logic to _libssh2_channel_write - - Some checks are better done in _libssh2_channel_write just once per - write instead of in channel_write() since the looping will call the - latter function multiple times per _libssh2_channel_write() invoke. - -- sftp_write: handle "left over" acked data - - The SFTP handle struct now buffers number of acked bytes that haven't - yet been returned. The way this is used is as following: - - 1. sftp_write() gets called with a buffer of let say size 32000. We - split 32000 into 8 smaller packets and send them off one by one. One of - them gets acked before the function returns so 4000 is returned. - - 2. sftp_write() gets called again a short while after the previous one, - now with a much smaller size passed in to the function. Lets say 8000. - In the mean-time, all of the remaining packets from the previous call - have been acked (7*4000 = 28000). This function then returns 8000 as all - data passed in are already sent and it can't return any more than what - it got passed in. But we have 28000 bytes acked. We now store the - remaining 20000 in the handle->u.file.acked struct field to add up in - the next call. - - 3. sftp_write() gets called again, and now there's a backlogged 20000 - bytes to return as fine and that will get skipped from the beginning - of the buffer that is passed in. - -- sftp_write: polished and simplified - - Removed unnecessary struct fields and state changes within the function. - - Made the loop that checks for ACKs only check chunks that were fully - sent. - -- SCP: on failure, show the numerical error reason - - By calling libssh2_session_last_errno() - -- SFTP: provide the numerical error reason on failure - -- SCP: clean up failure treatment - - When SCP send or recv fails, it gets a special message from the server - with a warning or error message included. We have no current API to - expose that message but the foundation is there. Removed unnecessary use - of session struct fields. - -- sftp_write: enlarge buffer to perform better - -- packets: code cleanup - - I added size checks in several places. I fixed the code flow to be easier - to read in some places. - - I removed unnecessary zeroing of structs. I removed unused struct fields. - -- LIBSSH2_CALLBACK_MACERROR: clarify return code use - -- _libssh2_userauth_publickey: avoid shadowing - -- packet: avoid shadowing global symbols - -- sftp_readdir: avoid shadowing - -- shadowing: don't shadow the global compress - -- _libssh2_packet_add: turn ifs into a single switch - -- _libssh2_packet_add: check SSH_MSG_GLOBAL_REQUEST packet - -- _libssh2_packet_add: SSH_MSG_DEBUG length checks - - Verify lengths before using them. Read always_display from the correct - index. Don't copy stuff around just to provide zero-termination of the - strings. - -- _libssh2_packet_add: SSH_MSG_IGNORE skip memmove - - There's no promise of a zero termination of the data in the callback so - no longer perform ugly operation in order to provide it. - -- _libssh2_packet_add: SSH_MSG_DISCONNECT length checks - - Verify lengths before trying to read data. - -- indent: break lines at 80 columns - -- SSH_MSG_CHANNEL_OPEN_FAILURE: used defined values - - We don't like magic numbers in the code. Now the acceptable failure - codes sent in the SSH_MSG_CHANNEL_OPEN_FAILURE message are added as - defined values in the private header file. - -- sftp_write: don't return EAGAIN if no EAGAIN was received - - This function now only returns EAGAIN if a lower layer actually returned - EAGAIN to it. If nothing was acked and no EAGAIN was received, it will - now instead return 0. - -- _libssh2_wait_socket: detect nothing-to-wait-for - - If _libssh2_wait_socket() gets called but there's no direction set to - wait for, this causes a "hang". This code now detects this situation, - set a 1 second timeout instead and outputs a debug output about it. - -- decomp: remove the free_dest argument - - Since the decompress function ALWAYS returns allocated memory we get a - lot simpler code by removing the ability to return data unallocated. - -- decomp: cleaned off old compression stuff - - I cleared off legacy code from when the compression and decompression - functions were a single unified function. Makes the code easier to read - too. - -- [TJ Saunders brought this change] - - decomp: increase decompression buffer sizes - -- [TJ Saunders brought this change] - - zlib: Add debug tracing of zlib errors - -- sftp_packet_read: handle partial reads of the length field - - SFTP packets come as [32 bit length][payload] and the code didn't - previously handle that the initial 32 bit field was read only partially - when it was read. - -- [Jasmeet Bagga brought this change] - - kex_agree_hostkey: fix NULL pointer derefence - - While setting up the session, ssh tries to determine the type of - encryption method it can use for the session. This requires looking at - the keys offered by the remote host and comparing these with the methods - supported by libssh2 (rsa & dss). To do this there is an iteration over - the array containing the methods supported by libssh2. - - If there is no agreement on the type of encryption we come to the 3rd - entry of the hostkeyp array. Here hostkeyp is valid but *hostkep is - NULL. Thus when we dereference that in (*hostkeyp)->name there is a - crash - -- _libssh2_transport_send: remove dead assignment - - 'data' isn't accessed beyond this point so there's no need to assign it. - -- scp_recv: remove dead assignment - - Instead of assigning a variable we won't read, we now use the more - explicit (void) prefix. - -- sftp_write: removed superfluous assignment - -- bugfix: avoid use of uninitialized value - -- sftp_packet_require: propagate error codes better - - There were some chances that they would cause -1 to get returned by - public functions and as we're hunting down all such occurances and since - the underlying functions do return valuable information the code now - passes back proper return codes better. - -- [Alfred Gebert brought this change] - - fix memory leaks (two times cipher_data) for each sftp session - -- libssh2_userauth_authenticated: make it work as documented - - The man page clearly says it returns 1 for "already authenticated" but - the code said non-zero. I changed the code to use 1 now, as that is also - non-zero but it gets the benefit that it now matches the documentation. - - Using 1 instead of non-zero is better for two reasons: - - 1. We have the opportunity to introduce other return codes in the future for - things like error and what not. - 2. We don't expose the internal bitmask variable value. - -- userauth_keyboard_interactive: fix indent - -- [Alfred Gebert brought this change] - - fix memory leak in userauth_keyboard_interactive() - - First I wanted to free the memory in session_free() but then - I had still memory leaks because in my test case the function - userauth_keyboard_interactive() is called twice. It is called - twice perhaps because the server has this authentication - methods available: publickey,gssapi-with-mic,keyboard-interactive - The keyboard-interactive method is successful. - -- dist: include sftp.h in dist archives - -Simon Josefsson (27 Oct 2010) -- Update header to match new function prototype, see c48840ba88. - -Daniel Stenberg (26 Oct 2010) -- bugfixes: the transport rearrange left some subtle flaws now gone - -- libssh2_userauth_publickey_fromfile_ex.3: cleaned up looks - -- libssh2_userauth_publickey: add man page - - I found an undocumented public function and we can't have it like - that. The description here is incomplete, but should serve as a template - to allow filling in... - -- libssh2_sftp_write.3: added blurb about the "write ahead" - - Documented the new SFTP write concept - -- sftp_close_handle: free any trailing write chunks - -- _libssh2_channel_write: fix warnings - -- SFTP: bufgix, move more sftp stuff to sftp.h - - The sftp_write function shouldn't assume that the buffer pointer will be - the same in subsequent calls, even if it assumes that the data already - passed in before haven't changed. - - The sftp structs are now moved to sftp.h (which I forgot to add before) - -- SFTP: use multiple outgoing packets when writing - - sftp_write was rewritten to split up outgoing data into multiple packets - and deal with the acks in a more asynchronous manner. This is meant to - help overcome latency and round-trip problems with the SFTP protocol. - -- TODO: implemented a lot of the ideas now - -- _libssh2_channel_write: removed 32500 size limit - - Neither _libssh2_channel_write nor sftp_write now have the 32500 size - limit anymore and instead the channel writing function now has its own - logic to send data in multiple calls until everything is sent. - -- send_existing: don't tell parent to return when drained - - That will just cause unnecessary code execution. - -- _libssh2_channel_write: general code cleanup - - simplified the function and removed some unused struct fields - -- _libssh2_transport_send: replaces _libssh2_transport_write - - The new function takes two data areas, combines them and sends them as a - single SSH packet. This allows several functions to allocate and copy - less data. - - I also found and fixed a mixed up use of the compression function - arguments that I introduced in my rewrite in a recent commit. - -- scp_write_nonblock: use select() instead of busyloop - - Make this example nicer by not busylooping. - -- send_existing: clear olen when the data is sent off - -- _libssh2_transport_write: allow 256 extra bytes around the packet - -- _libssh2_transport_write: remade to send without malloc - -- compress: compression disabled by default - - We now allow libssh2_session_flag() to enable compression with a new - flag and I added documentation for the previous LIBSSH2_FLAG_SIGPIPE - flag which I wasn't really aware of! - -- comp: split the compress function - - It is now made into two separate compress and decompress functions. In - preparation for upcoming further modficications. - -Dan Fandrich (20 Oct 2010) -- Added header file to allow compiling in older environments - -Daniel Stenberg (20 Oct 2010) -- TODO: add a possible new API for SFTP transfers - -- TODO: "New Transport API" added - -- TODO: add buffering plans - -Simon Josefsson (13 Oct 2010) -- Mention libssh2_channel_get_exit_signal and give kudos. - -- [Tommy Lindgren brought this change] - - Add libssh2_channel_get_exit_signal man page. - - Signed-off-by: Simon Josefsson <simon@josefsson.org> - -- [Tommy Lindgren brought this change] - - Add libssh2_channel_get_exit_signal. - - Signed-off-by: Simon Josefsson <simon@josefsson.org> - -- Add libssh2_free man page and fix typo. - -- Add libssh2_free. - -Daniel Stenberg (11 Oct 2010) -- scp_recv: improved treatment of channel_read() returning zero - - As a zero return code from channel_read() is not an error we must make - sure that the SCP functions deal with that properly. channel_read() - always returns 0 if the channel is EOFed already so we check for EOF - after 0-reads to be able to return error properly. - -- libssh2_session_methods.3: detail what can be asked for - -- compression: send zlib before none - - As the list of algorithms in a preferred order we should send zlib - before none to increase the chances that the server will let us do - compression. - -- compress: faster check, better return codes - - In the transport functions we avoid a strcmp() now and just check a - boolean instead. - - The compress/decompress function's return code is now acknowledged and - used as actual return code in case of failures. - -- libssh2_session_handshake: replaces libssh2_session_startup() - - The function libssh2_session_startup() is now considered deprecated due - to the portability issue with the socket argument. - libssh2_session_handshake() is the name of the replacement. - -- libssh2_socket_t: now externally visible - - In preparation for upcominig changes, the libssh2_socket_t type is now - typedef'ed in the public header. - -- _libssh2_transport_drain: removed - - This function proved not to be used nor useful. - -- _libssh2_channel_write: don't iterate over transport writes - - When a call to _libssh2_transport_write() succeeds, we must return from - _libssh2_channel_write() to allow the caller to provide the next chunk - of data. - - We cannot move on to send the next piece of data that may already have - been provided in this same function call, as we risk getting EAGAIN for - that and we can't return information both about sent data as well as - EAGAIN. So, by returning short now, the caller will call this function - again with new data to send. - -- _libssh2_transport_write: updated documentation blurb - -- _libssh2_transport_write: remove fprintf remainder - - Mistake from previous debugging - -- session: improved errors - - Replaced -1/SOCKET_NONE errors with appropriate error defines instead. - - Made the verbose trace output during banner receiving less annoying for - non-blocking sessions. - -- crypt_init: use correct error define - -- _libssh2_error: hide EAGAIN for non-blocking sessions - - In an attempt to make the trace output less cluttered for non-blocking - sessions the error function now avoids calling the debug function if the - error is the EAGAIN and the session is non-blocking. - -- agent: use better error defines - -- comp_method_zlib_init: use correct error defines - -- transport: better error codes - - LIBSSH2_SOCKET_NONE (-1) should no longer be used as error code as it is - (too) generic and we should instead use specific and dedicated error - codes to better describe the error. - -- channel: return code and _libssh2_error cleanup - - Made sure that all transport_write() call failures get _libssh2_error - called. - -- _libssh2_channel_write: limit to 32700 bytes - - The well known and used ssh server Dropbear has a maximum SSH packet - length at 32768 by default. Since the libssh2 design current have a - fixed one-to-one mapping from channel_write() to the packet size created - by transport_write() the previous limit of 32768 in the channel layer - caused the transport layer to create larger packets than 32768 at times - which Dropbear rejected forcibly (by closing the connection). - - The long term fix is of course to remove the hard relation between the - outgoing SSH packet size and what the input length argument is in the - transport_write() function call. - -- libssh.h: add more dedicated error codes - -- SCP: allow file names with bytes > 126 - - When parsing the SCP protocol and verifying that the data looks like a - valid file name, byte values over 126 must not be consider illegal since - UTF-8 file names will use such codes. - - Reported by: Uli Zappe - Bug: http://www.libssh2.org/mail/libssh2-devel-archive-2010-08/0112.shtml - -Dan Fandrich (25 Aug 2010) -- Document the three sftp stat constants - -Guenter Knauf (18 Aug 2010) -- Fixed Win32 makefile which was now broken at resource build. - -- It is sufficient to pipe stderr to NUL to get rid of the nasty messages. - -- [Author: Guenter Knauf brought this change] - - Removed Win32 ifdef completely for sys/uio.h. - - No idea why we had this ifdef at all but MSVC, MingW32, Watcom - and Borland all have no sys/uio.h header; so if there's another - Win32 compiler which needs it then it should be added explicitely - instead of this negative list. - -- New files should also be added to Makefile.am. - - Otherwise they will never be included with release and snapshot tarballs ... - -Daniel Stenberg (18 Aug 2010) -- version: bump to 1.2.8_DEV - -Version 1.2.7 (17 Aug 2010) - -Daniel Stenberg (17 Aug 2010) -- release: updated to hold 1.2.7 info - -Guenter Knauf (17 Aug 2010) -- Use the new libssh2.rc file. - -- Added resource file for libssh2.dll (shamelessly stolen from libcurl). - -- Updated Win32 MSVC dependencies versions. - -- Added include for sys/select.h to get fd.set on some platforms. - -- Added Watcom makefile borrowed from libcurl. - - This makefile compiles already all files fine for static lib, but needs - final touch when I have OpenSSL fully working with shared libs and Watcom. - -- Added copyright define to libssh2.h and use it for binary builds. - -- Moved version defines up in order to include from .rc file. - - Blocked rest of header with ifndef so its possible to let - the rc compiler only use the version defines. - -- Some minor makefile tweaks. - -Daniel Stenberg (2 Aug 2010) -- example: treat the libssh2_channel_read() return code properly - - A short read is not an error. Only negative values are errors! - -- libssh2_wait_socket: reset error code to "leak" EAGAIN less - - Since libssh2 often sets LIBSSH2_ERROR_EAGAIN internally before - _libssh2_wait_socket is called, we can decrease some amount of - confusion in user programs by resetting the error code in this function - to reduce the risk of EAGAIN being stored as error when a blocking - function returns. - -- _libssh2_wait_socket: poll needs milliseconds - - As reported on the mailing list, the code path using poll() should - multiple seconds with 1000 to get milliseconds, not divide! - - Reported by: Jan Van Boghout - -- typedef: make ssize_t get typedef without LIBSSH2_WIN32 - - The condition around the ssize_t typedef depended on both LIBSSH2_WIN32 - *and* _MSC_VER being defined when it should be enough to depend on - _MSC_VER only. It also makes it nicer so libssh2-using code builds fine - without having custom defines. - -- [John Little brought this change] - - session_free: free more data to avoid memory leaks - -- channel_free: ignore problems with channel_close() - - As was pointed out in bug #182, we must not return failure from - _libssh2_channel_free() when _libssh2_channel_close() returns an error - that isn't EAGAIN. It can effectively cause the function to never go - through, like it did now in the case where the socket was actually - closed but socket_state still said LIBSSH2_SOCKET_CONNECTED. - - I consider this fix the right thing as it now also survives other - errors, even if making sure socket_state isn't lying is also a good - idea. - -- publickey_list_free: no return value from a void function - - Fixed a compiler warning I introduced previously when checking input - arguments more. I also added a check for the other pointer to avoid NULL - pointer dereferences. - -- [Lars Nordin brought this change] - - openssl: make use of the EVP interface - - Make use of the EVP interface for the AES-funktion. Using this method - supports the use of different ENGINES in OpenSSL for the AES function - (and the direct call to the AES_encrypt should not be used according to - openssl.org) - -Peter Stuge (23 Jun 2010) -- [Tor Arntsen brought this change] - - Don't overflow MD5 server hostkey - - Use SHA_DIGEST_LENGTH and MD5_DIGEST_LENGTH in memcpy instead of hardcoded - values. An incorrect value was used for MD5. - -- Fix message length bugs in libssh2_debug() - - There was a buffer overflow waiting to happen when a debug message was - longer than 1536 bytes. - - Thanks to Daniel who spotted that there was a problem with the message - length passed to a trace handler also after commit - 0f0652a3093111fc7dac0205fdcf8d02bf16e89f. - -- Make libssh2_debug() create a correctly terminated string - - Also use FILE *stderr rather than fd 2, which can very well be something - completely different. - -Daniel Stenberg (23 Jun 2010) -- [TJ Saunders brought this change] - - handshake: Compression enabled at the wrong time - - In KEXINIT messages, the client and server agree on, among other - things, whether to use compression. This method agreement occurs - in src/kex.c's kex_agree_methods() function. However, if - compression is enabled (either client->server, server->client, or - both), then the compression layer is initialized in - kex_agree_methods() -- before NEWKEYS has been received. - - Instead, the initialization of the compression layer should - happen after NEWKEYS has been received. This looks to occur - insrc/kex.c's diffie_hellman_sha1(), which even has the comment: - - /* The first key exchange has been performed, - - switch to active crypt/comp/mac mode */ - - There, after NEWKEYS is received, the cipher and mac algorithms - are initialized, and that is where the compression should be - initialized as well. - - The current implementation fails if server->client compression is - enabled because most server implementations follow OpenSSH's - lead, where compression is initialized after NEWKEYS. Since the - server initializes compression after NEWKEYS, but libssh2 - initializes compression after KEXINIT (i.e. before NEWKEYS), they - are out of sync. - - Reported in bug report #180 - -- [TJ Saunders brought this change] - - userauth_hostbased_fromfile: packet length too short - - The packet length calculated in src/userauth.c's - userauth_hostbased_fromfile() function is too short by 4 bytes; - it forgets to add four bytes for the length of the hostname. - This causes hostbased authentication to fail, since the server - will read junk data. - - verified against proftpd's mod_sftp module - -- _libssh2_userauth_publickey: reject method names longer than the data - - This functions get the method length by looking at the first 32 - bit of data, and I now made it not accept method lengths that are - longer than the whole data set is, as given in the dedicated - function argument. - - This was detected when the function was given bogus public key - data as an ascii string, which caused the first 32bits to create - a HUGE number. - -- NULL resistance: make more public functions survive NULL pointer input - - Sending in NULL as the primary pointer is now dealt with by more - public functions. I also narrowed the userauth.c code somewhat to - stay within 80 columns better. - -- agent: make libssh2_agent_userauth() work blocking properly - - previously it would always work in a non-blocking manner - -Peter Stuge (17 Jun 2010) -- Fix underscore typo for 64-bit printf format specifiers on Windows - - Commit 49ddf447ff4bd80285f926eac0115f4e595f9425 was missing underscores. - -Daniel Stenberg (16 Jun 2010) -- libssh2_session_callback_set: extended the man page - -- [John brought this change] - - LIBSSH2_DEBUG: macro uses incorrect function variable - - The LIBSSH2_DEBUG macro, defined in libssh2_priv.h, incorrectly uses the - function variable ssh_msg_disconnect when it should use ssh_msg_debug. - - This shows that the LIBSSH2_CALLBACK_DEBUG callback never has worked... - -- warning: fix a compiler warning 'pointer differs in signedness' - - As reported in bug #177 - -- portability: introduce LIBSSH2_INT64_T_FORMAT for 64bit printf()s - - As pointed out in bug #177, some of the Windows compilers use - %I64 to output 64 bit variables with the printf family. - -- debug: avoid sending NULL to sprintf %s - - Via the _libssh2_debug() macro/function. Pointed out by john in bug report - -- sftp docs: show macro on macro page, only function on function page - - The individual man pages for macros now show the full convenience - macro as defined, and then the man page for the actual function - only shows the function. - -- code police: make the code use less than 80 columns - -- libssh2_channel_write_ex: remove macros, added wording on buffer size - -- libssh2_sftp_write: document buffer size and changed some ordering - -- libssh2_channel_write_stderr: show how the macro is defined - -- libssh2_channel_write: show how the macro is defined - -- SFTP: limit write() to not produce overly large packets - - sftp_write() now limits how much data it gets at a time even more - than before. Since this function creates a complete outgoing - packet based on what gets passed to it, it is crucial that it - doesn't create too large packets. - - With this method, there's also no longer any problem to use very - large buffers in your application and feed that to libssh2. I've - done numerous tests now with uploading data over SFTP using 100K - buffers and I've had no problems with that. - -- scp_write_nonblock: add transfer time info - - Using the same timing logic and output format as - sftp_write_nonblock allows us to very easily run benchmarks on - SCP vs SFTP uploads using libssh2. - -- sftp_write_nonblock: select() on socket, use *BIG* buffer, time transfer - - The select() is just to make it nicer so that it doesn't - crazy-loop on EAGAIN. The buffer size thing is mostly to verify - that this really work as supposed. - - Transfer timing is just a minor thing, but it can just as well be - there and help us time and work on performance easier using out - of the box examples. - -- agent: use _libssh2_error() when returning errors - - As pointed out in bug report #173, this module basically never - used _libssh2_error() which made it work inconstently with other - parts of the libssh2 code base. This is my first take at making - this code more in line with the rest. - -- inputchecks: make lots of API functions check for NULL pointers - - If an application accidentally provides a NULL handle pointer to - the channel or sftp public functions, they now return an error - instead of segfaulting. - -- libssh2_channel_eof: clarify that it returns negative on errors - -- SFTP: keep the sftp error code as 32 bit - - 'last_errno' holds to the error code from the SFTP protocol and - since that is 32 bits on the wire there's no point in using a - long for this internally which is larger on some platforms. - -- agent: make the code better deal with unexpected code flows - - agent->ops gets initialized by the libssh2_agent_connect() call - but we need to make sure that we don't segfault even if a bad - sequence of function calls is used. - -Alexander Lamaison (10 Jun 2010) -- Better handling of invalid key files. - - Passing an invalid public key to libssh2_userauth_publickey_fromfile_ex - triggered an assertion. Replaced this with a runtime check that rejects - obviously invalid key data. - -Daniel Stenberg (10 Jun 2010) -- version: we start working on 1.2.7 now - -Version 1.2.6 (10 Jun 2010) - -Daniel Stenberg (10 Jun 2010) -- NEWS: add the 1.2.6 release details - -- RELEASE-NOTES: 1.2.6 details added - -Guenter Knauf (10 Jun 2010) -- fixed libssh2.dsw to use the generated libssh2.dsp; removed old *.dsp files. - -- moved MSVC strdup define to libssh2_config.h which we include already. - -- added missing source files to src/NMakefile. - -Daniel Stenberg (8 Jun 2010) -- libssh2_poll: refer to poll(3) and select(3) instead - -- example: fix strdup() for MSVC compiles - - MSVC has a _strdup() that we better use. This was reported in bug - -- SFTP: fail init SFTP if session isn't authenticated - - Alexander Lamaison filed bug #172 - (http://trac.libssh2.org/ticket/172), and pointed out that SFTP - init would do bad if the session isn't yet authenticated at the - time of the call, so we now check for this situation and returns - an error if detected. Calling sftp_init() at this point is bad - usage to start with. - -- direct_tcpip: bring back inclusion of libssh2_config.h - - In order to increase portability of this example, I'm bringing - the inclusion of libssh2_config.h back, and I also added an - require that header for this example to compile. - - I also made all code lines fit within 80 columns. - -Guenter Knauf (3 Jun 2010) -- cast away a warning. - -- moved CRT_SECURE_NO_DEPRECATE define up so its defined before the winsock headers are included. - -- fixed platform detection for MingW32 test makefile. - -- MingW32 has gettimeofday() implemented, so proper ifdef this function here. - -- removed MSVC ifdef since seems we can use __int64 still with latest headers. - -- changed copyright notice for MinW32 and NetWare binaries. - -- cleaned up MSVC ifdefs which where spreaded over 3 places. - -- added uint8_t typedef for NetWare CLIB platform. - -- if the function declaration gets changed the header should be changed too. - -- this is MSVC specific and doesnt apply for all Win32 compilers; - the uint8_t typedef clashes with MingW32 headers. - -- updated MingW32 makefiles for latest dependency lib versions. - -- updated NetWare makefiles for latest dependency lib versions. - -Dan Fandrich (30 May 2010) -- Fixed compiling with libgcrypt - - A change of parameter types from unsigned long to size_t was - missed in the prototype in libgcrypt.h - -Daniel Stenberg (28 May 2010) -- statvfs: use libssh2_sftp_statvfs only, no "_ex" - - As the long-term goal is to get rid of the extensive set of - macros from the API we can just as well start small by not adding - new macros when we add new functions. Therefore we let the - function be libssh2_sftp_statvfs() plainly without using an _ex - suffix. - - I also made it use size_t instead of unsigned int for the string - length as that too is a long-term goal for the API. - -- [Grubsky Grigory brought this change] - - DSP: output lib name typo - -- [Grubsky Grigory brought this change] - - win32: provide a uint8_t typedef for better building on windows - -- agent: win32: fix bad _libssh2_store_str call - - As pointed out by Grubsky Grigory <g.grubsky@securitycode.ru>, I - made a mistake when I added the _libssh2_store_str() call before - and I made a slightly different patch than what he suggested. - Based purely on taste. - -Peter Stuge (24 May 2010) -- [Joey Degges brought this change] - - Add libssh2_sftp_statvfs() and libssh2_sftp_fstatvfs() - - These can be used to get file system statistics from servers that - support the statvfs@openssh.com and fstatvfs@openssh.com extensions. - -Alexander Lamaison (22 May 2010) -- [Jose Baars brought this change] - - VMS specific: make sure final release can be installed over daily build - -- [Jose Baars brought this change] - - VMS: small improvement to the man2help utilities - -Peter Stuge (22 May 2010) -- [Joey Degges brought this change] - - libssh2_exit and libssh2_sftp_readdir man page fixes - -Daniel Stenberg (21 May 2010) -- spelling: s/sue/use - -Alexander Lamaison (21 May 2010) -- Change magic port number for generic knownhost check. - - libssh2_knownhost_checkp took 0 as a magic port number that indicated - a 'generic' check should be performed. However, 0 is a valid port - number in its own right so this commit changes the magic value to any - negative int. - -Mikhail Gusarov (5 May 2010) -- Add re-discovered copyright holders to COPYING - -- Restoring copyright statements from pre-git era - - Eli Fant has contributed fragmenting SFTP requests - -- Restoring my copyright statements from pre-git era - - keyboard_interactive, 'exit-status' information packet, non-atomic read/write - under FreeBSD, multi-channel operation bugfixes. - -Daniel Stenberg (3 May 2010) -- pedantic: make the code C90 clean - -Peter Stuge (3 May 2010) -- Do proper keyboard-interactive user dialog in the sftp.c example - -Daniel Stenberg (3 May 2010) -- added to tarball: libssh2_knownhost_checkp.3 - -- knownhost: support [host]:port in knownhost file - - OpenSSH has ways to add hosts to the knownhosts file that include - a specific port number which makes the key associated with only - that specific host+port pair. libssh2 previously did not support - this, and I was forced to add a new function to the API to - properly expose this ability to applications: - libssh2_knownhost_checkp() - - To *add* such hosts to the knownhosts file, you make sure to pass - on the host name in that manner to the libssh2_knownhost_addc() - function. - -- init/exit: mention these were added in 1.2.5 - -- libssh2_knownhost_check docs: correct the prototype - -- examples: avoid use of uninitialized variable 'sock' - -- KEX: stop pretending we negotiate language - - There was some stub-like parts of an implementation for - implementing kex language negotiation that caused clang-analyzer - to warn and as it did nothing I've now removed the dead code. - -- Uninitialized argument - -- sftpdir: removed dead assignment - -- Makefile.am: include the VMS-specific config header as well - -- [Jose Baars brought this change] - - Add VMS specific libssh2_config.h - -- fix Value stored to 's' is never read warning - - and moved variable declaration of s to be more local - -- kexinit: simplify the code and avoid scan-build warning - - Previously it would say "Value stored to 's' is never read" due - fourth increment of 's'. - -Alexander Lamaison (28 Apr 2010) -- Removed unecessary brackets. - -- Changed sftp_attrsize macro to a static function. - -Daniel Stenberg (28 Apr 2010) -- release: include the VMS-specific files - -- sftp_attrsize: protect the macro argument with proper parentheses - -- ssh2_agent: avoid using 'session' uninitialized on failures - -- examples: remove assignments of variable rc that's never used - -- publickey_init: remove useless variable increment - -- hostkey_method_ssh_rsa_init: remove useless variable increment - -- packet_x11_open: removed useless variable increment - - and made the declaration of a variable more local - -- packet_queue_listener: removed useless variable increment - - and made the declaration of a variable more local - -- sftp_read: move a read_responses array to where its used - - I find that this increases readability since the array is used - only in the function call just immediately below and nowhere - else. - -- sftp_readdir: turn a small array static const and move it - -- sftp_attrsize: converted function to a macro - - This way, the macro can evaluate a static number at compile time - for two out of four uses, and it probably runs faster for the - other two cases too. - -- sftp_open: deal with short channel_write calls - - This was an old TODO that just wasn't done before. If - channel_write returns short, that is not an error. - -- sftp_open: clean up, better check of input data - - The clang-analyzer report made it look into this function and - I've went through it to remove a potential use of an - uninitialized variable and I also added some validation of input - data received from the server. - - In general, lots of more code in this file need to validate the - input before assuming it is correct: there are servers out there - that have bugs or just have another idea of how to do the SFTP - protocol. - -- bugfix: avoid using the socket if it failed to create one - -- bugfix: potential use of NULL pointer - -- libssh2_userauth_password_ex: clarify errors somewhat - - The errors mentioned in this man page are possible return codes - but not necessarily the only return codes that this can return. - - Also reformatted the typ prototypes somewhat. - -- examples: fixed and made them more similar - - The channel read/write functions can return 0 in legitimate cases - without it being an error, and we need to loop properly if they - return short. - -- [Jose Baars brought this change] - - VMS port of libssh2; changes in the libssh2 common code - -- Makefile: added the two news headers userauth.h and session.h - -- cleanup: prefer the internal functions - - To get the blocking vs non-blocking to work as smooth as possible - and behave better internally, we avoid using the external - interfaces when calling functions internally. - - Renamed a few internal functions to use _libssh2 prefix when not - being private within a file, and removed the libssh2_ for one - that was private within the file. - -- session_free: remove dead code - -- libssh2_publickey_init: fixed to work better non-blocking - - This was triggered by a clang-analyzer complaint that turned out - to be valid, and it made me dig deeper and fix some generic non- - blocking problems I disovered in the code. - - While cleaning this up, I moved session-specific stuff over to a - new session.h header from the libssh2_priv.h header. - -- channel: reduce duplicated free and returns - - Simplified the code by trying to free data and return on a single - spot. - -- channel: make variables more local - - By making 'data' and 'data_len' more local in several places in - this file it will be easier to spot how they are used and we'll - get less risks to accidentally do bad things with them. - -Mikhail Gusarov (24 Apr 2010) -- Fix typos in manpages, catched by Lintian - -Daniel Stenberg (24 Apr 2010) -- channel_request_pty: simplify the code - - clang-analyzer pointed out how 'data' could be accessed as a NULL - pointer if the wrong state was set, and while I don't see that - happen in real-life the code flow is easier to read and follow by - moving the LIBSSH2_FREE() call into the block that is supposed to - deal with the data pointer anyway. - -- libssh2_channel_process_startup: simplify the code - - clang-analyzer pointed out how 'data' could be accessed as a NULL - pointer if the wrong state was set, and while I don't see that - happen in real-life the code flow is easier to read and follow by - moving the LIBSSH2_FREE() call into the block that is supposed to - deal with the data pointer anyway. - -- sftp_close_handle: add precation to not access NULL pointer - - clang-analyzer pointed this out as a "Pass-by-value argument in - function call is undefined" but while I can't see exactly how - this can ever happen in reality I think a little check for safety - isn't such a bad thing here. - -- scp_write_nonblock: Value stored to 'nread' is never read - -- scp_write: Value stored to 'ptr' is never read - -- scp_write_nonblock: Value stored to 'ptr' is never read - -- sftp_mkdir: less silly output but show failures - -- [Jose Baars brought this change] - - VMS port of libssh2 including VMS specific build procedures - -- two variable types changes, made lines less than 80 columns - - The two variable type changes are only to match type variable - fields actually read from the binary protocol. - -- remove check for negative padding_length - - It was silly, since it is read as an unsigned char... - -- hostkey_method_ssh_dss_init: Value stored to 's' is never read - -- libssh2_banner_set: avoid unnecessary increment and explain code - -- agent_transact_unix: remove unused variable - -- remove two unnecessary increments - -- more code converted to use _libssh2_store_*() - -- libssh2_publickey_list_fetch: removed unused variables - -- libssh2_publickey_init: remove unused variables - -- libssh2_scp_send64: added to API to provide large file transfers - - The previously existing libssh2_scp_send_ex() function has no way - to send files that are larger than 'size_t' which on 32bit - systems mean 4GB. This new API uses a libssh2_int64_t type and - should thus on most modern systems be able to send enormous - files. - -- sftp_init: remove unused variables and assignments - -- libssh2_knownhost_check: Value stored to 'keylen' is never read - -- hostkey: fix compiler warning +NEWS is now generated from git and put into the release tarballs. diff --git a/libs/libssh2/docs/README b/libs/libssh2/docs/README index 8a148568cf..fca539dbbc 100644 --- a/libs/libssh2/docs/README +++ b/libs/libssh2/docs/README @@ -4,9 +4,9 @@ libssh2 - SSH2 library libssh2 is a library implementing the SSH2 protocol, available under the revised BSD license. -Web site: https://www.libssh2.org/ +Web site: https://libssh2.org/ -Mailing list: https://cool.haxx.se/mailman/listinfo/libssh2-devel +Mailing list: https://lists.haxx.se/listinfo/libssh2-devel License: see COPYING diff --git a/libs/libssh2/docs/RELEASE-NOTES b/libs/libssh2/docs/RELEASE-NOTES index 98cb8033b6..c5f478d89d 100644 --- a/libs/libssh2/docs/RELEASE-NOTES +++ b/libs/libssh2/docs/RELEASE-NOTES @@ -1,44 +1,219 @@ -libssh2 1.9.0 +libssh2 1.11.1_DEV + +Deprecation notices: + +- Starting June 2024, the following algos go deprecated and will be + disabled in default builds (with an option to enable them): + + - DSA: `ssh-dss` hostkeys. + You can disable it now with `-DLIBSSH2_NO_DSA`. + Disabled by default in OpenSSH 7.0 (2015-08-11). + - MD5-based MACs and hashes: `hmac-md5`, `hmac-md5-96`, + `LIBSSH2_HOSTKEY_HASH_MD5` + You can disable it now with `-DLIBSSH2_NO_MD5`. + Disabled by default since OpenSSH 7.2 (2016-02-29). + - 3DES cipher: `3des-cbc` + You can disable it now with `-DLIBSSH2_NO_3DES`. + Disabled by default since OpenSSH 7.4 (2016-12-19). + - RIPEMD-160 MACs: `hmac-ripemd160`, `hmac-ripemd160@openssh.com` + You can disable it now with `-DLIBSSH2_NO_HMAC_RIPEMD`. + Removed in OpenSSH 7.6 (2017-10-03). + - Blowfish cipher: `blowfish-cbc` + You can disable it now with `-DLIBSSH2_NO_BLOWFISH`. + Removed in OpenSSH 7.6 (2017-10-03). + - RC4 ciphers: `arcfour`, `arcfour128` + You can disable it now with `-DLIBSSH2_NO_RC4`. + Removed in OpenSSH 7.6 (2017-10-03). + - CAST cipher: `cast128-cbc` + You can disable it now with `-DLIBSSH2_NO_CAST`. + Removed in OpenSSH 7.6 (2017-10-03). + +- Starting January 2025, above options will be deleted from the + libssh2 codebase. + + - Default builds will also disable support for old-style, MD5-based + encrypted private keys. + You can disable it now with `-DLIBSSH2_NO_MD5_PEM`. This release includes the following enhancements and bugfixes: - - o adds ECDSA keys and host key support when using OpenSSL - o adds ED25519 key and host key support when using OpenSSL 1.1.1 - o adds OpenSSH style key file reading - o adds AES CTR mode support when using WinCNG - o adds PEM passphrase protected file support for Libgcrypt and WinCNG - o adds SHA256 hostkey fingerprint - o adds libssh2_agent_get_identity_path() and libssh2_agent_set_identity_path() - o adds explicit zeroing of sensitive data in memory - o adds additional bounds checks to network buffer reads - o adds the ability to use the server default permissions when creating sftp directories - o adds support for building with OpenSSL no engine flag - o adds support for building with LibreSSL - o increased sftp packet size to 256k - o fixed oversized packet handling in sftp - o fixed building with OpenSSL 1.1 - o fixed a possible crash if sftp stat gets an unexpected response - o fixed incorrect parsing of the KEX preference string value - o fixed conditional RSA and AES-CTR support - o fixed a small memory leak during the key exchange process - o fixed a possible memory leak of the ssh banner string - o fixed various small memory leaks in the backends - o fixed possible out of bounds read when parsing public keys from the server - o fixed possible out of bounds read when parsing invalid PEM files - o no longer null terminates the scp remote exec command - o now handle errors when diffie hellman key pair generation fails - o fixed compiling on Windows with the flag STDCALL=ON - o improved building instructions - o improved unit tests - + +- autotools: delete `--disable-tests` option, fix CI tests (e051ae34 #1271 revert: 7483edfa) +- autotools: show the default for `hidden-symbols` option (a3f5594a #1269) +- autotools: enable `-Wunused-macros` with gcc (ecdf5199 #1262 #1227 #1224) +- autotools: fix dotless gcc and Apple clang version detections (89ccc83c #1232 #1187) +- autotools: show more clang/gcc version details (fb580161 #1230) +- autotools: avoid warnings in libtool stub code (96682bd5 #1227 #1224) +- autotools: sync warning enabler code with curl (5996fefe #1223) +- autotools: rename variable (ce5f208a #1222) +- autotools: picky warning options tidy-up (cdca8cff #1221) +- autotools: fix selecting WinCNG in cross-builds (and more) (00a3b88c #1187 #1186) +- autotools: use comma separator in `Requires.private` of `libssh2.pc` (7f83de14 #1124) +- autotools: improve libz position (c89174a7 #1077 #1075 #1013 regr: 4f0f4bff) +- autotools: skip tests requiring static lib if `--disable-static` (572c57c9 #1072 #1056 regr: 83853f8a) +- build: enable `-pedantic-errors` (3ec53f3e #1286) +- build: add mingw-w64 support to `LIBSSH2_PRINTF()` attribute (f8c45794 #1287) +- build: add `LIBSSH2_NO_DEPRECATED` option (b1414503 #1267 #1266 #1260 #1259) +- build: enable missing OpenSSF-recommended warnings, with fixes (afa6b865 #1257) +- build: enable more compiler warnings and fix them (7ecc309c #1224) +- build: picky warning updates (328a96b3 #1219) +- build: revert: respect autotools `DLL_EXPORT` in `libssh2.h` (481be044 #1141 revert: fb1195cf) +- build: stop requiring libssl from openssl (c84745e3 #1128) +- build: tidy-up `libssh2.pc.in` variable names (5720dd9f #1125) +- build: add/fix `Requires.private` packages in `libssh2.pc` (ef538069 #1123) +- checksrc: sync with curl (8cd473c9 #1272) +- checksrc: fix spelling in comment (a95d401f) +- checksrc: modernise perl file open (3d309f9b) +- checksrc: switch to dot file (d67a91aa #1052) +- ci: add FreeBSD 14 job, fix issues (46333adf #1277) +- ci: add OmniOS job, fix issues (5e0ec991) +- ci: show compiler in cross/cygwin job names (c9124088) +- ci: add OpenBSD (v7.4) job + fix build error in example (0c9a8e35 #1250) +- ci: add NetBSD (v9.3) job (65c7a7a5) +- ci: update and speed up FreeBSD job (eee4e805) +- ci: use absolute path in `CMAKE_INSTALL_PREFIX` (74948816 #1247) +- ci: boost mbedTLS build speed (236e79a1 #1245) +- ci: add BoringSSL job (cmake, gcc, amd64) (c9dd3566 #1233) +- ci: fixup FreeBSD version, bump mbedTLS (fea6664e #1217) +- ci: add FreeBSD 13.2 job (a7d2a573 #1215) +- ci: mbedTLS 3.5.0 (5e190442 #1202) +- ci: update actions, use shallow clones with appveyor (d468a33f #1199) +- ci: replace `mv` + `chmod` with `install` in `Dockerfile` (5754fed6 #1175) +- ci: set file mode early in `appveyor_docker.yml` (633db55f) +- ci: add spellcheck (codespell) (a79218d3) +- ci: add MSYS builds (autotools and cmake) (d43b8d9b #1162) +- ci: add Cygwin builds (autotools and cmake) (f1e96e73 #1161) +- ci: add mingw-w64 UWP build (1215aa5f #1155 #1147) +- ci: add missing timeout to 'autotools distcheck' step (6265ffdb) +- ci: add non-static autotools i386 build, ignore GHA updates on AppVeyor (c6e137f7 #1074 #1072) +- ci: prefer `=` operator in shell snippets (e5c03043 #1073) +- ci: drop redundant/unused vars, sync var names (ab8e95bc #1059) +- ci: add i386 Linux build (with mbedTLS) (abdf40c7 #1057 #1053) +- ci/appveyor: re-enable parallel mode (e190e5b2 #1294) +- ci/appveyor: delete UWP job broken since Visual Studio upgrade (d0a7f1da #1275) +- ci/appveyor: YAML/PowerShell formatting, shorten variable name (06fd721f #1200) +- ci/appveyor: move to pure PowerShell (8a081fd9 #1197) +- ci/GHA: review/fixup auto-cancel settings (b08cfbc9 #1292) +- ci/GHA: restore curly braces in `if` (36748270 #1145) +- ci/GHA: simplify `if` strings (cab3db58 #1140) +- cmake: rename picky warnings script (64d6789f #1225) +- cmake: fix multiple include of libssh2 package (932d6a32 #1216) +- cmake: show crypto backend in feature summary (20387285 #1211) +- cmake: simplify showing CMake version (fc00bdd7 #1203) +- cmake: cleanup mbedTLS version detection more (4c241d5c #1196 #1192) +- cmake: delete duplicate `include()` (30eef0a6) +- cmake: improve/fix mbedTLS detection (41594675 #1192 #1191) +- cmake: tidy-up `foreach()` syntax (4a64ca14 #1180) +- cmake: verify `libssh2_VERSION` in integration tests (a20572e9) +- cmake: show cmake versions in ci (87f5769b) +- cmake: quote more strings (e9c7d3af #1173) +- cmake: add `ExternalProject` integration test (aeaefaf6 #1171) +- cmake: add integration tests (8715c3d5 #1170) +- cmake: (re-)add aliases for `add_subdirectory()` builds (4ff64ae3 #1169) +- cmake: style tidy-up (3fa5282d #1166) +- cmake: add `LIB_NAME` variable (5453fc80 #1159) +- cmake: tidy-up concatenation in `CMAKE_MODULE_PATH` (ae7d5108 #1157) +- cmake: replace `libssh2` literals with `PROJECT_NAME` variable (72fd2595 #1152) +- cmake: fix `STREQUAL` check in error branch (42d3bf13 #1151) +- cmake: cache more config values on Windows (11a03690 #1142) +- cmake: streamline invocation (f58f77b5 #1138) +- cmake: merge `set_target_properties()` calls (a9091007 #1132) +- cmake: (re-)add zlib to `Libs.private` in `libssh2.pc` (64643018 #1131) +- cmake: use `wolfssl/options.h` for detection, like autotools (c5ec6c49 #1130) +- cmake: add openssl libs to `Libs.private` in `libssh2.pc` (5cfa59d3 #1127) +- cmake: bump minimum CMake version to v3.7.0 (9cd18f45 #1126) +- cmake: CMAKE_SOURCE_DIR -> PROJECT_SOURCE_DIR (0f396aa9 #1121) +- cmake: tidy-ups (2fc36790 #1122) +- cmake: re-add `Libssh2:libssh2` for compatibility + lowercase namespace (2da13c13 #1104 #1103) +- configure.ac: remove AB_INIT (f4f52ccc) +- copyright: remove years from copyright headers (187d89bb #1082) +- docs: replace SHA1 with SHA256 in CMake example (766bde9f) +- drop `www.` from `www.libssh2.org` (6e3e8839 #1172) +- example: use `libssh2_socket_t` in X11 example (3f60ccb7) +- example: replace remaining libssh2_scp_recv with libssh2_scp_recv2 in output messages (8d69e63d #1258 follow: 6c84a426) +- example: fix regression in `ssh2_exec.c` (279a2e57 #1106 #1105 regr: b13936bd) +- example, tests: call `WSACleanup()` for each `WSAStartup()` (94b6bad3 #1283) +- example, tests: fix/silence `-Wformat-truncation=2` gcc warnings (744e059f) +- hostkey: do not advertise ssh-rsa when SHA1 is disabled (82d1b8ff #1093 #1092) +- libssh2.h: add deprecated function warnings (9839ebe5 #1289 #1260) +- libssh2.h: add portable `LIBSSH2_SOCKET_CLOSE()` macro (28dbf016 #1278) +- libssh2.h: use `_WIN32` for Windows detection instead of rolling our own (631e7734 #1238) +- libssh2.pc: re-add & extend support for static-only libssh2 builds (624abe27 #1119 #1114) +- libssh2.pc: don't put `@LIBS@` in pc file (1209c16d) +- mac: handle low-level errors (f64885b6 #1297) +- Makefile.am: fix `cp` to preserve attributes and timestamp (f64e6318) +- Makefile.mk: delete Windows-focused raw GNU Make build (43485579 #1204) +- man: fix double spaces and dash escaping (a3ffc422 #1210) +- man: add description to `libssh2_session_get_blocking.3` (67e39091 #1185) +- mbedtls: improve disabling `-Wredundant-decls` (ecec68a2 #1226 #1224) +- mbedtls: include `version.h` for `MBEDTLS_VERSION_NUMBER` (9d7bc253 #1095 #1094) +- mbedtls: use more `size_t` to sync up with `crypto.h` (1153ebde #1054 #1053) +- md5: allow disabling old-style encrypted private keys at build-time (eb9f9de2 #1181) +- mingw: fix printf mask for 64-bit integers (36c1e1d1 #1091 #1090) +- misc: flatten `_libssh2_explicit_zero` if tree (74e74288 #1149) +- NMakefile: delete (c515eed3 #1134 #1129) +- openssl: fix cppcheck found NULL dereferences (f2945905 #1304) +- openssl: delete internal `read_openssh_private_key_from_memory()` (34aff5ff #1306) +- openssl: use OpenSSL 3 HMAC API, add `no-deprecated` CI job (363dcbf4 #1243 #1235 #1207) +- openssl: make a function static, add `#ifdef` comments (efee9133 #1246 follow: 03092292) +- openssl: fix DSA code to use OpenSSL 3 API (82581941 #1244 #1207) +- openssl: fix `EC_KEY` reference with OpenSSL 3 `no-deprecated` build (487152f4 #1236 #1235 #1207) +- openssl: use non-deprecated APIs with OpenSSL 3.x (b0ab005f #1207) +- openssl: silence `-Wunused-value` warnings (bf285500 #1205) +- openssl: use automatic initialization with LibreSSL 2.7.0+ (d79047c9 #1146) +- openssl: add missing check for `LIBRESSL_VERSION_NUMBER` before use (4a42f42e #1117 #1115) +- os400: maintain up to date (8457c37a #1309) +- packet: properly bounds check packet_authagent_open() (88a960a8 #1179) +- pem: fix private keys encrypted with AES-GCM methods (e87bdefa #1133) +- reuse: fix duplicate copyright warning (b9a4ed83) +- reuse: comply with 3.1 spec and 2.0.0 checker (fe6239a1 #1102 #1101 #1098) +- reuse: provide SPDX identifiers (f6aa31f4 #1084) +- scp: fix missing cast for targets without large file support (c317e06f #1060 #1057 #1002 regr: 5db836b2) +- session: add `libssh2_session_callback_set2()` (c0f69548 #1285) +- session: handle EINTR from send/recv/poll/select to try again as the error is not fatal (798ed4a7 #1058) +- src: check hash update/final success (4718ede4 #1303 #1301) +- src: check hash init success (2ed9eb92 #1301) +- src: add 'strict KEX' to fix CVE-2023-48795 "Terrapin Attack" (d34d9258 #1291 #1290) +- src: disable `-Wsign-conversion` warnings, add option to re-enable (6e451669 #1284 #1257) +- src: fix gcc 13 `-Wconversion` warning on Darwin (8cca7b77 #1209 follow: 08354e0a) +- src: drop a redundant `#include` (1f0174d0 #1153) +- src: improve MSVC C4701 warning fix (8b924999 #1086 #1083) +- src: bump `hash_len` to `size_t` in `LIBSSH2_HOSTKEY_METHOD` (8b917d76 #1076) +- src: bump DSA and ECDSA sign `hash_len` to `size_t` (7b8e0225 #1055) +- stop using leading underscores in macro names (c6589b88 #1248) +- tests: sync port number type with the rest of codebase (eb996af8) +- tests: fall back to `$LOGNAME` for username (5326a5ce #1241 #1240) +- tests: show cmake version used in integration tests (2cd2f40e #1201) +- tests: formatting and tidy-ups (e61987a3) +- tests: replace FIXME with comments (1a99a86a) +- tests: add aes256-gcm encrypted key test (802336cf #1135 #1133) +- tests: trap signals in scripts (b2916b28 #1098) +- tests: cast to avoid `-Wchar-subscripts` with Cygwin (43df6a46 #1081 #1080) +- test_read: make it run without Docker (57e9d18e #1139) +- test_sshd.test: show sshd and test connect logs on harness failure (299c2040 #1097) +- test_sshd.test: set a safe PID directory (e8cabdcf #1089) +- test_sshd.test: minor cleanups (d29eea1d) +- tidy-up: bump casts from int to long for large C99 types in printfs (2e5a8719 #1264 #1257) +- tidy-up: `unsigned` -> `unsigned int` (b136c379) +- tidy-up: around `stdint.h` (bfa00f1b #1212) +- tidy-up: fix typo in `readme.vms` (a9a79e7a) +- tidy-up: delete duplicate word from comment (76307435) +- tidy-up: avoid exclamations, prefer single quotes, in outputs (003fb454 #1079) +- TODO: disable or drop weak algos (0b4bdc85 #1261) +- transport: fix incorrect byte offset in debug message (2388a3aa #1096) +- userauth: add a new structure to separate memory read and file read (63b4c20e) +- userauth: check whether `*key_method` is a NULL pointer instead of `key_method` (bec57c40) +- wincng: prefer `ULONG`/`DWORD` over `unsigned long` (186c1d63 #1165) +- wincng: tidy-ups (7bb669b5 #1164) +- windows: use built-in `_WIN32` macro to detect Windows (6fbc9505 #1195) +- wolfssl: enable debug logging in wolfSSL when compiled in (76e7a68a #1310) + This release would not have looked like this without help, code, reports and advice from friends like these: - Peter Surge, Will Cosgrove, Daniel Stenberg, Alex Arslan, Alex Crichton, - Thomas Bleeker, Keno Fischer, Marc Hörsken, Marcel Raad, Viktor Szakats, - Kamil Dudka, Panos, Etienne Samson, Tseng Jun, Brendan Shanks, doublex, - Erik B, Jakob Egger, Thomas Lochmatter, alex-weaver, Adrian Moran, Zenju, - gartens, Matthew D. Fuller, Ryan Kelley, Zhen-Huan HWANG, Orivej Desh, - Alexander Curtiss - - (29 contributors) + Viktor Szakats, Michael Buckley, Ren Mingshuai, Daniel Stenberg, + Patrick Monnerat, Aaron Stone, Brian Inglis, concussious on GitHub, + Dan Fandrich, Haowei Hsu, Harmen Stoppels, Harry Mallon, Jack L, Jakob Egger, + João M. S. Silva, Joel Depooter, Juliusz Sosinowicz, Kai Pastor, + Kenneth Davidson, mike-jumper, monnerat, naddy, Nicolas Mora, Nursan Valeyev, + Paul Howarth, PewPewPew, Radek Brich, rahmanih on GitHub, Ryan Kelley, + Steve McIntyre, Will Cosgrove, Xi Ruoyao diff --git a/libs/libssh2/include/libssh2.h b/libs/libssh2/include/libssh2.h index fb760dd2fb..8bc8a1380e 100644 --- a/libs/libssh2/include/libssh2.h +++ b/libs/libssh2/include/libssh2.h @@ -90,11 +90,7 @@ extern "C" { #endif -#if defined(_WIN32) || defined(WIN32) -#define LIBSSH2_WIN32 -#endif - -#ifdef LIBSSH2_WIN32 +#ifdef _WIN32 # include <basetsd.h> # include <winsock2.h> #endif @@ -106,8 +102,8 @@ extern "C" { /* Allow alternate API prefix from CFLAGS or calling app */ #ifndef LIBSSH2_API -# ifdef LIBSSH2_WIN32 -# if defined(LIBSSH2_EXPORTS) || defined(DLL_EXPORT) || defined(_WINDLL) +# ifdef _WIN32 +# if defined(LIBSSH2_EXPORTS) || defined(_WINDLL) # ifdef LIBSSH2_LIBRARY # define LIBSSH2_API __declspec(dllexport) # else @@ -116,9 +112,9 @@ extern "C" { # else # define LIBSSH2_API # endif -# else /* !LIBSSH2_WIN32 */ +# else /* !_WIN32 */ # define LIBSSH2_API -# endif /* LIBSSH2_WIN32 */ +# endif /* _WIN32 */ #endif /* LIBSSH2_API */ #ifdef HAVE_SYS_UIO_H @@ -144,13 +140,44 @@ typedef unsigned long long libssh2_uint64_t; typedef long long libssh2_int64_t; #endif -#ifdef LIBSSH2_WIN32 +#ifdef _WIN32 typedef SOCKET libssh2_socket_t; #define LIBSSH2_INVALID_SOCKET INVALID_SOCKET -#else /* !LIBSSH2_WIN32 */ +#define LIBSSH2_SOCKET_CLOSE(s) closesocket(s) +#else /* !_WIN32 */ typedef int libssh2_socket_t; #define LIBSSH2_INVALID_SOCKET -1 -#endif /* LIBSSH2_WIN32 */ +#define LIBSSH2_SOCKET_CLOSE(s) close(s) +#endif /* _WIN32 */ + +/* Compile-time deprecation macros */ +#if !defined(LIBSSH2_DISABLE_DEPRECATION) && !defined(LIBSSH2_LIBRARY) +# if defined(_MSC_VER) +# if _MSC_VER >= 1400 +# define LIBSSH2_DEPRECATED(version, message) \ + __declspec(deprecated("since libssh2 " # version ". " message)) +# elif _MSC_VER >= 1310 +# define LIBSSH2_DEPRECATED(version, message) \ + __declspec(deprecated) +# endif +# elif defined(__GNUC__) && !defined(__INTEL_COMPILER) +# if (defined(__clang__) && __clang_major__ >= 3) || \ + (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) +# define LIBSSH2_DEPRECATED(version, message) \ + __attribute__((deprecated("since libssh2 " # version ". " message))) +# elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0) +# define LIBSSH2_DEPRECATED(version, message) \ + __attribute__((deprecated)) +# endif +# elif defined(__SUNPRO_C) && __SUNPRO_C >= 0x5130 +# define LIBSSH2_DEPRECATED(version, message) \ + __attribute__((deprecated)) +# endif +#endif + +#ifndef LIBSSH2_DEPRECATED +#define LIBSSH2_DEPRECATED(version, message) +#endif /* * Determine whether there is small or large file support on windows. @@ -176,7 +203,7 @@ typedef int libssh2_socket_t; # undef LIBSSH2_USE_WIN32_LARGE_FILES #endif -#if defined(LIBSSH2_WIN32) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES) && \ +#if defined(_WIN32) && !defined(LIBSSH2_USE_WIN32_LARGE_FILES) && \ !defined(LIBSSH2_USE_WIN32_SMALL_FILES) # define LIBSSH2_USE_WIN32_SMALL_FILES #endif @@ -283,6 +310,7 @@ typedef struct _LIBSSH2_SK_SIG_INFO { const unsigned char *data, size_t data_len, void **abstract) /* 'keyboard-interactive' authentication callback */ +/* FIXME: name_len, instruction_len -> size_t, num_prompts -> unsigned int? */ #define LIBSSH2_USERAUTH_KBDINT_RESPONSE_FUNC(name_) \ void name_(const char *name, int name_len, const char *instruction, \ int instruction_len, int num_prompts, \ @@ -302,6 +330,8 @@ typedef struct _LIBSSH2_SK_SIG_INFO { #define LIBSSH2_SK_PRESENCE_REQUIRED 0x01 #define LIBSSH2_SK_VERIFICATION_REQUIRED 0x04 +/* FIXME: update lengths to size_t (or ssize_t): */ + /* Callbacks for special SSH packets */ #define LIBSSH2_IGNORE_FUNC(name) \ void name(LIBSSH2_SESSION *session, const char *message, int message_len, \ @@ -557,6 +587,9 @@ typedef struct _LIBSSH2_POLLFD { #define LIBSSH2_ERROR_RANDGEN -49 #define LIBSSH2_ERROR_MISSING_USERAUTH_BANNER -50 #define LIBSSH2_ERROR_ALGO_UNSUPPORTED -51 +#define LIBSSH2_ERROR_MAC_FAILURE -52 +#define LIBSSH2_ERROR_HASH_INIT -53 +#define LIBSSH2_ERROR_HASH_CALC -54 /* this is a define to provide the old (<= 1.2.7) name */ #define LIBSSH2_ERROR_BANNER_NONE LIBSSH2_ERROR_BANNER_RECV @@ -617,14 +650,25 @@ libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)), LIBSSH2_API void **libssh2_session_abstract(LIBSSH2_SESSION *session); +typedef void (libssh2_cb_generic)(void); + +LIBSSH2_API libssh2_cb_generic * +libssh2_session_callback_set2(LIBSSH2_SESSION *session, int cbtype, + libssh2_cb_generic *callback); + +LIBSSH2_DEPRECATED(1.11.1, "Use libssh2_session_callback_set2()") LIBSSH2_API void *libssh2_session_callback_set(LIBSSH2_SESSION *session, int cbtype, void *callback); LIBSSH2_API int libssh2_session_banner_set(LIBSSH2_SESSION *session, const char *banner); +#ifndef LIBSSH2_NO_DEPRECATED +LIBSSH2_DEPRECATED(1.4.0, "Use libssh2_session_banner_set()") LIBSSH2_API int libssh2_banner_set(LIBSSH2_SESSION *session, const char *banner); +LIBSSH2_DEPRECATED(1.2.8, "Use libssh2_session_handshake()") LIBSSH2_API int libssh2_session_startup(LIBSSH2_SESSION *session, int sock); +#endif LIBSSH2_API int libssh2_session_handshake(LIBSSH2_SESSION *session, libssh2_socket_t sock); LIBSSH2_API int libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, @@ -911,12 +955,13 @@ libssh2_channel_window_read_ex(LIBSSH2_CHANNEL *channel, #define libssh2_channel_window_read(channel) \ libssh2_channel_window_read_ex((channel), NULL, NULL) -/* libssh2_channel_receive_window_adjust() is DEPRECATED, do not use! */ +#ifndef LIBSSH2_NO_DEPRECATED +LIBSSH2_DEPRECATED(1.1.0, "Use libssh2_channel_receive_window_adjust2()") LIBSSH2_API unsigned long libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel, unsigned long adjustment, unsigned char force); - +#endif LIBSSH2_API int libssh2_channel_receive_window_adjust2(LIBSSH2_CHANNEL *channel, unsigned long adjustment, @@ -955,12 +1000,15 @@ LIBSSH2_API void libssh2_session_set_read_timeout(LIBSSH2_SESSION* session, long timeout); LIBSSH2_API long libssh2_session_get_read_timeout(LIBSSH2_SESSION* session); -/* libssh2_channel_handle_extended_data() is DEPRECATED, do not use! */ +#ifndef LIBSSH2_NO_DEPRECATED +LIBSSH2_DEPRECATED(1.1.0, "libssh2_channel_handle_extended_data2()") LIBSSH2_API void libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode); +#endif LIBSSH2_API int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel, int ignore_mode); +#ifndef LIBSSH2_NO_DEPRECATED /* libssh2_channel_ignore_extended_data() is defined below for BC with version * 0.1 * @@ -968,11 +1016,12 @@ LIBSSH2_API int libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel, * LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE is passed, extended data will be read * (FIFO) from the standard data channel */ -/* DEPRECATED */ +/* DEPRECATED since 0.3.0. Use libssh2_channel_handle_extended_data2(). */ #define libssh2_channel_ignore_extended_data(channel, ignore) \ libssh2_channel_handle_extended_data((channel), (ignore) ? \ LIBSSH2_CHANNEL_EXTENDED_DATA_IGNORE : \ LIBSSH2_CHANNEL_EXTENDED_DATA_NORMAL) +#endif #define LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA -1 #define LIBSSH2_CHANNEL_FLUSH_ALL -2 @@ -997,10 +1046,12 @@ LIBSSH2_API int libssh2_channel_close(LIBSSH2_CHANNEL *channel); LIBSSH2_API int libssh2_channel_wait_closed(LIBSSH2_CHANNEL *channel); LIBSSH2_API int libssh2_channel_free(LIBSSH2_CHANNEL *channel); -/* libssh2_scp_recv is DEPRECATED, do not use! */ +#ifndef LIBSSH2_NO_DEPRECATED +LIBSSH2_DEPRECATED(1.7.0, "Use libssh2_scp_recv2()") LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv(LIBSSH2_SESSION *session, const char *path, struct stat *sb); +#endif /* Use libssh2_scp_recv2() for large (> 2GB) file support on windows */ LIBSSH2_API LIBSSH2_CHANNEL *libssh2_scp_recv2(LIBSSH2_SESSION *session, const char *path, @@ -1420,7 +1471,7 @@ libssh2_agent_get_identity_path(LIBSSH2_AGENT *agent); */ LIBSSH2_API void libssh2_keepalive_config(LIBSSH2_SESSION *session, int want_reply, - unsigned interval); + unsigned int interval); /* * libssh2_keepalive_send() diff --git a/libs/libssh2/include/libssh2_sftp.h b/libs/libssh2/include/libssh2_sftp.h index 8b41f1d7f1..9d7a8fbb66 100644 --- a/libs/libssh2/include/libssh2_sftp.h +++ b/libs/libssh2/include/libssh2_sftp.h @@ -42,7 +42,7 @@ #include "libssh2.h" -#ifndef LIBSSH2_WIN32 +#ifndef _WIN32 #include <unistd.h> #endif diff --git a/libs/libssh2/src/CMakeLists.txt b/libs/libssh2/src/CMakeLists.txt index 3a2077d06b..bca1b23d5b 100644 --- a/libs/libssh2/src/CMakeLists.txt +++ b/libs/libssh2/src/CMakeLists.txt @@ -36,9 +36,13 @@ # # SPDX-License-Identifier: BSD-3-Clause +set(LIBSSH2_SOVERSION 1) +set(LIBSSH2_LIBVERSION 1.0.1) + if(CRYPTO_BACKEND) list(APPEND PRIVATE_COMPILE_DEFINITIONS ${CRYPTO_BACKEND_DEFINE}) list(APPEND PRIVATE_INCLUDE_DIRECTORIES ${CRYPTO_BACKEND_INCLUDE_DIR}) + add_feature_info("Crypto backend" ON "${CRYPTO_BACKEND}") else() message(FATAL_ERROR "No suitable cryptography backend found.") endif() @@ -47,10 +51,10 @@ endif() option(CLEAR_MEMORY "Enable clearing of memory before being freed" ON) if(NOT CLEAR_MEMORY) - list(APPEND libssh2_DEFINITIONS LIBSSH2_NO_CLEAR_MEMORY) + list(APPEND libssh2_DEFINITIONS "LIBSSH2_NO_CLEAR_MEMORY") endif() -option(ENABLE_ZLIB_COMPRESSION "Use zlib for compression") +option(ENABLE_ZLIB_COMPRESSION "Use zlib for compression" OFF) add_feature_info(Compression ENABLE_ZLIB_COMPRESSION "using zlib for compression") if(ENABLE_ZLIB_COMPRESSION) @@ -58,16 +62,17 @@ if(ENABLE_ZLIB_COMPRESSION) list(APPEND libssh2_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS}) list(APPEND LIBRARIES ${ZLIB_LIBRARIES}) - list(APPEND PC_REQUIRES_PRIVATE zlib) + list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-lz") + list(APPEND LIBSSH2_PC_REQUIRES_PRIVATE "zlib") if(ZLIB_FOUND) - list(APPEND libssh2_DEFINITIONS LIBSSH2_HAVE_ZLIB) + list(APPEND libssh2_DEFINITIONS "LIBSSH2_HAVE_ZLIB") endif() endif() list(APPEND LIBRARIES ${SOCKET_LIBRARIES}) if(WIN32) - list(APPEND PC_LIBS -lws2_32) + list(APPEND LIBSSH2_PC_LIBS_PRIVATE "-lws2_32") endif() # to find generated header @@ -83,7 +88,7 @@ endif() include(GNUInstallDirs) transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") # Get 'CSOURCES' and 'HHEADERS' variables -include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake) +include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") set(SOURCES ${CSOURCES} ${HHEADERS}) ## Library definition @@ -102,55 +107,62 @@ endif() if(BUILD_STATIC_LIBS) list(APPEND libssh2_export ${LIB_STATIC}) add_library(${LIB_STATIC} STATIC ${SOURCES}) + add_library(${PROJECT_NAME}::${LIB_STATIC} ALIAS ${LIB_STATIC}) target_compile_definitions(${LIB_STATIC} PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS}) target_link_libraries(${LIB_STATIC} PRIVATE ${LIBRARIES}) - set_target_properties(${LIB_STATIC} PROPERTIES PREFIX "" OUTPUT_NAME "libssh2") - set_target_properties(${LIB_STATIC} PROPERTIES SUFFIX "${STATIC_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}") + set_target_properties(${LIB_STATIC} PROPERTIES + PREFIX "" OUTPUT_NAME "libssh2" SOVERSION "${LIBSSH2_SOVERSION}" VERSION "${LIBSSH2_LIBVERSION}" + SUFFIX "${STATIC_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}") target_include_directories(${LIB_STATIC} PRIVATE "${PROJECT_SOURCE_DIR}/include/" ${libssh2_INCLUDE_DIRS} ${PRIVATE_INCLUDE_DIRECTORIES} PUBLIC - $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> - $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>) + "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>" + "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>") endif() if(BUILD_SHARED_LIBS) list(APPEND libssh2_export ${LIB_SHARED}) add_library(${LIB_SHARED} SHARED ${SOURCES}) + add_library(${PROJECT_NAME}::${LIB_SHARED} ALIAS ${LIB_SHARED}) if(WIN32) - set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES libssh2.rc) + set_property(TARGET ${LIB_SHARED} APPEND PROPERTY SOURCES "libssh2.rc") endif() target_compile_definitions(${LIB_SHARED} PRIVATE ${PRIVATE_COMPILE_DEFINITIONS} ${libssh2_DEFINITIONS} ${LIB_SHARED_DEFINITIONS}) target_compile_options(${LIB_SHARED} PRIVATE ${LIB_SHARED_C_FLAGS}) target_link_libraries(${LIB_SHARED} PRIVATE ${LIBRARIES}) - set_target_properties(${LIB_SHARED} PROPERTIES PREFIX "" IMPORT_PREFIX "" OUTPUT_NAME "libssh2") - set_target_properties(${LIB_SHARED} PROPERTIES IMPORT_SUFFIX "${IMPORT_LIB_SUFFIX}${CMAKE_IMPORT_LIBRARY_SUFFIX}") - set_target_properties(${LIB_SHARED} PROPERTIES POSITION_INDEPENDENT_CODE ON) + set_target_properties(${LIB_SHARED} PROPERTIES + PREFIX "" OUTPUT_NAME "libssh2" SOVERSION "${LIBSSH2_SOVERSION}" VERSION "${LIBSSH2_LIBVERSION}" + IMPORT_PREFIX "" IMPORT_SUFFIX "${IMPORT_LIB_SUFFIX}${CMAKE_IMPORT_LIBRARY_SUFFIX}" + POSITION_INDEPENDENT_CODE ON) target_include_directories(${LIB_SHARED} PRIVATE "${PROJECT_SOURCE_DIR}/include/" ${libssh2_INCLUDE_DIRS} ${PRIVATE_INCLUDE_DIRECTORIES} PUBLIC - $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include> - $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>) + "$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>" + "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>") endif() +add_library(${PROJECT_NAME}::${LIB_NAME} ALIAS ${LIB_SELECTED}) +add_library(${LIB_NAME} ALIAS ${LIB_SELECTED}) + ## Installation install(FILES - ${PROJECT_SOURCE_DIR}/include/libssh2.h - ${PROJECT_SOURCE_DIR}/include/libssh2_publickey.h - ${PROJECT_SOURCE_DIR}/include/libssh2_sftp.h + "${PROJECT_SOURCE_DIR}/include/libssh2.h" + "${PROJECT_SOURCE_DIR}/include/libssh2_publickey.h" + "${PROJECT_SOURCE_DIR}/include/libssh2_sftp.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) if(BUILD_STATIC_LIBS) install(TARGETS ${LIB_STATIC} - EXPORT Libssh2Config + EXPORT "${PROJECT_NAME}-targets" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() if(BUILD_SHARED_LIBS) install(TARGETS ${LIB_SHARED} - EXPORT Libssh2Config + EXPORT "${PROJECT_NAME}-targets" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) @@ -163,55 +175,54 @@ set(RUNTIME_DEPENDENCIES ${_RUNTIME_DEPENDENCIES} CACHE INTERNAL # Package config -## During package installation, install Libssh2Config.cmake -install(EXPORT Libssh2Config - NAMESPACE Libssh2:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libssh2) +## During package installation, install libssh2-targets.cmake +install(EXPORT "${PROJECT_NAME}-targets" + NAMESPACE "${PROJECT_NAME}::" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") ## During build, register directly from build tree -# create Libssh2Config.cmake -export(TARGETS ${libssh2_export} NAMESPACE Libssh2:: FILE Libssh2Config.cmake) -export(PACKAGE Libssh2) # register it +# create libssh2-targets.cmake +export(TARGETS ${libssh2_export} NAMESPACE "${PROJECT_NAME}::" FILE "${PROJECT_NAME}-targets.cmake") +export(PACKAGE ${PROJECT_NAME}) # register it + +# Generate libssh2-config.cmake into build tree and install it +configure_file("${PROJECT_SOURCE_DIR}/cmake/libssh2-config.cmake.in" "${PROJECT_NAME}-config.cmake" @ONLY) +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") ## Export a .pc file for client projects not using CMaek -if(PC_REQUIRES_PRIVATE) - string(REPLACE ";" "," PC_REQUIRES_PRIVATE "${PC_REQUIRES_PRIVATE}") +if(LIBSSH2_PC_REQUIRES_PRIVATE) + string(REPLACE ";" "," LIBSSH2_PC_REQUIRES_PRIVATE "${LIBSSH2_PC_REQUIRES_PRIVATE}") +endif() +if(LIBSSH2_PC_LIBS_PRIVATE) + list(REMOVE_DUPLICATES LIBSSH2_PC_LIBS_PRIVATE) + string(REPLACE ";" " " LIBSSH2_PC_LIBS_PRIVATE "${LIBSSH2_PC_LIBS_PRIVATE}") endif() -if(PC_LIBS) - string(REPLACE ";" " " PC_LIBS "${PC_LIBS}") +# merge the pkg-config private fields into public ones when static-only +if(BUILD_SHARED_LIBS) + set(LIBSSH2_PC_REQUIRES "") + set(LIBSSH2_PC_LIBS "") +else() + set(LIBSSH2_PC_REQUIRES "${LIBSSH2_PC_REQUIRES_PRIVATE}") + set(LIBSSH2_PC_LIBS "${LIBSSH2_PC_LIBS_PRIVATE}") endif() -set(LIBSSH2VER ${LIBSSH2_VERSION}) -set(LIBSREQUIRED ${PC_REQUIRES_PRIVATE}) -set(LIBS ${PC_LIBS}) set(prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix "\${prefix}") set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") -configure_file(${CMAKE_SOURCE_DIR}/libssh2.pc.in libssh2.pc @ONLY) +configure_file("${PROJECT_SOURCE_DIR}/libssh2.pc.in" "libssh2.pc" @ONLY) install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/libssh2.pc - DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + FILES "${CMAKE_CURRENT_BINARY_DIR}/libssh2.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") -## Versioning - -set(LIBSSH2_SOVERSION 1) -set(LIBSSH2_VERSION 1.0.1) -if(BUILD_STATIC_LIBS) - set_target_properties(${LIB_STATIC} PROPERTIES - SOVERSION ${LIBSSH2_SOVERSION} - VERSION ${LIBSSH2_VERSION}) -endif() -if(BUILD_SHARED_LIBS) - set_target_properties(${LIB_SHARED} PROPERTIES - SOVERSION ${LIBSSH2_SOVERSION} - VERSION ${LIBSSH2_VERSION}) -endif() +# include(CMakePackageConfigHelpers) write_basic_package_version_file( - ${CMAKE_CURRENT_BINARY_DIR}/Libssh2ConfigVersion.cmake + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" VERSION "${LIBSSH2_VERSION_MAJOR}.${LIBSSH2_VERSION_MINOR}.${LIBSSH2_VERSION_PATCH}" COMPATIBILITY SameMajorVersion) install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/Libssh2ConfigVersion.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libssh2) + FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") diff --git a/libs/libssh2/src/Makefile.am b/libs/libssh2/src/Makefile.am index bd7b8de8ea..45b7a17275 100644 --- a/libs/libssh2/src/Makefile.am +++ b/libs/libssh2/src/Makefile.am @@ -19,6 +19,9 @@ lib_LTLIBRARIES = libssh2.la # tree AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/include +# This might hold -Werror +CFLAGS += @LIBSSH2_CFLAG_EXTRAS@ + VERSION=-version-info 1:1:0 # This flag accepts an argument of the form current[:revision[:age]]. So, diff --git a/libs/libssh2/src/Makefile.inc b/libs/libssh2/src/Makefile.inc index a1876daceb..9133819a62 100644 --- a/libs/libssh2/src/Makefile.inc +++ b/libs/libssh2/src/Makefile.inc @@ -29,6 +29,7 @@ HHEADERS = \ channel.h \ comp.h \ crypto.h \ + crypto_config.h \ libgcrypt.h \ libssh2_priv.h \ libssh2_setup.h \ diff --git a/libs/libssh2/src/agent.c b/libs/libssh2/src/agent.c index d99a319550..dd709eb1fc 100644 --- a/libs/libssh2/src/agent.c +++ b/libs/libssh2/src/agent.c @@ -53,13 +53,14 @@ #undef PF_UNIX #endif -#if defined(WIN32) && !defined(LIBSSH2_WINDOWS_UWP) +#if defined(_WIN32) && !defined(LIBSSH2_WINDOWS_UWP) #define HAVE_WIN32_AGENTS #endif #include "userauth.h" #include "session.h" +#if 0 /* Requests from client to agent for protocol 1 key operations */ #define SSH_AGENTC_REQUEST_RSA_IDENTITIES 1 #define SSH_AGENTC_RSA_CHALLENGE 3 @@ -67,10 +68,12 @@ #define SSH_AGENTC_REMOVE_RSA_IDENTITY 8 #define SSH_AGENTC_REMOVE_ALL_RSA_IDENTITIES 9 #define SSH_AGENTC_ADD_RSA_ID_CONSTRAINED 24 +#endif /* Requests from client to agent for protocol 2 key operations */ #define SSH2_AGENTC_REQUEST_IDENTITIES 11 #define SSH2_AGENTC_SIGN_REQUEST 13 +#if 0 #define SSH2_AGENTC_ADD_IDENTITY 17 #define SSH2_AGENTC_REMOVE_IDENTITY 18 #define SSH2_AGENTC_REMOVE_ALL_IDENTITIES 19 @@ -91,13 +94,14 @@ #define SSH_AGENT_RSA_IDENTITIES_ANSWER 2 #define SSH_AGENT_RSA_RESPONSE 4 -/* Replies from agent to client for protocol 2 key operations */ -#define SSH2_AGENT_IDENTITIES_ANSWER 12 -#define SSH2_AGENT_SIGN_RESPONSE 14 - /* Key constraint identifiers */ #define SSH_AGENT_CONSTRAIN_LIFETIME 1 #define SSH_AGENT_CONSTRAIN_CONFIRM 2 +#endif + +/* Replies from agent to client for protocol 2 key operations */ +#define SSH2_AGENT_IDENTITIES_ANSWER 12 +#define SSH2_AGENT_SIGN_RESPONSE 14 /* Signature request methods */ #define SSH_AGENT_RSA_SHA2_256 2 @@ -559,7 +563,7 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Agent sign method %.*s", - method_len, method_name)); + (int)method_len, method_name)); rc = LIBSSH2_ERROR_ALGO_UNSUPPORTED; goto error; diff --git a/libs/libssh2/src/bcrypt_pbkdf.c b/libs/libssh2/src/bcrypt_pbkdf.c index d088587873..414c5e4e36 100644 --- a/libs/libssh2/src/bcrypt_pbkdf.c +++ b/libs/libssh2/src/bcrypt_pbkdf.c @@ -127,9 +127,12 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, memcpy(countsalt, salt, saltlen); /* collapse password */ - (void)libssh2_sha512_init(&ctx); - libssh2_sha512_update(ctx, pass, passlen); - libssh2_sha512_final(ctx, sha2pass); + if(!libssh2_sha512_init(&ctx) || + !libssh2_sha512_update(ctx, pass, passlen) || + !libssh2_sha512_final(ctx, sha2pass)) { + free(countsalt); + return -1; + } /* generate key, sizeof(out) at a time */ for(count = 1; keylen > 0; count++) { @@ -139,18 +142,26 @@ bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, countsalt[saltlen + 3] = count & 0xff; /* first round, salt is salt */ - (void)libssh2_sha512_init(&ctx); - libssh2_sha512_update(ctx, countsalt, saltlen + 4); - libssh2_sha512_final(ctx, sha2salt); + if(!libssh2_sha512_init(&ctx) || + !libssh2_sha512_update(ctx, countsalt, saltlen + 4) || + !libssh2_sha512_final(ctx, sha2salt)) { + _libssh2_explicit_zero(out, sizeof(out)); + free(countsalt); + return -1; + } bcrypt_hash(sha2pass, sha2salt, tmpout); memcpy(out, tmpout, sizeof(out)); for(i = 1; i < rounds; i++) { /* subsequent rounds, salt is previous output */ - (void)libssh2_sha512_init(&ctx); - libssh2_sha512_update(ctx, tmpout, sizeof(tmpout)); - libssh2_sha512_final(ctx, sha2salt); + if(!libssh2_sha512_init(&ctx) || + !libssh2_sha512_update(ctx, tmpout, sizeof(tmpout)) || + !libssh2_sha512_final(ctx, sha2salt)) { + _libssh2_explicit_zero(out, sizeof(out)); + free(countsalt); + return -1; + } bcrypt_hash(sha2pass, sha2salt, tmpout); for(j = 0; j < sizeof(out); j++) diff --git a/libs/libssh2/src/channel.c b/libs/libssh2/src/channel.c index c35658a04e..2f7d162c72 100644 --- a/libs/libssh2/src/channel.c +++ b/libs/libssh2/src/channel.c @@ -84,7 +84,7 @@ _libssh2_channel_nextid(LIBSSH2_SESSION * session) */ session->next_channel = id + 1; _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Allocated new channel ID#%lu", id)); + "Allocated new channel ID#%u", id)); return id; } @@ -265,8 +265,8 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type, session->open_channel->local.packet_size = _libssh2_ntohu32(session->open_data + 13); _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Connection Established - ID: %lu/%lu win: %lu/%lu" - " pack: %lu/%lu", + "Connection Established - ID: %u/%u win: %u/%u" + " pack: %u/%u", session->open_channel->local.id, session->open_channel->remote.id, session->open_channel->local.window_size, @@ -902,7 +902,7 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel, _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Setting remote environment variable: %s=%s on " - "channel %lu/%lu", + "channel %u/%u", varname, value, channel->local.id, channel->remote.id)); s = channel->setenv_packet = @@ -1036,7 +1036,7 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel, sizeof(channel->reqPTY_packet_requirev_state)); _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Allocating tty on channel %lu/%lu", channel->local.id, + "Allocating tty on channel %u/%u", channel->local.id, channel->remote.id)); s = channel->reqPTY_packet; @@ -1139,7 +1139,7 @@ static int channel_request_auth_agent(LIBSSH2_CHANNEL *channel, sizeof(channel->req_auth_agent_requirev_state)); _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Requesting auth agent on channel %lu/%lu", + "Requesting auth agent on channel %u/%u", channel->local.id, channel->remote.id)); /* @@ -1303,7 +1303,7 @@ channel_request_pty_size(LIBSSH2_CHANNEL * channel, int width, sizeof(channel->reqPTY_packet_requirev_state)); _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "changing tty size on channel %lu/%lu", + "changing tty size on channel %u/%u", channel->local.id, channel->remote.id)); @@ -1392,7 +1392,7 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection, sizeof(channel->reqX11_packet_requirev_state)); _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Requesting x11-req for channel %lu/%lu: single=%d " + "Requesting x11-req for channel %u/%u: single=%d " "proto=%s cookie=%s screen=%d", channel->local.id, channel->remote.id, single_connection, @@ -1550,7 +1550,7 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, channel->process_packet_len += + 4; _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "starting request(%s) on channel %lu/%lu, message=%s", + "starting request(%s) on channel %u/%u, message=%s", request, channel->local.id, channel->remote.id, message ? message : "<null>")); s = channel->process_packet = @@ -1719,9 +1719,9 @@ _libssh2_channel_flush(LIBSSH2_CHANNEL *channel, int streamid) packet->data_head; _libssh2_debug((channel->session, LIBSSH2_TRACE_CONN, - "Flushing %d bytes of data from stream " - "%lu on channel %lu/%lu", - bytes_to_flush, packet_stream_id, + "Flushing %ld bytes of data from stream " + "%d on channel %u/%u", + (long)bytes_to_flush, packet_stream_id, channel->local.id, channel->remote.id)); /* It's one of the streams we wanted to flush */ @@ -1882,8 +1882,8 @@ _libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL * channel, && (adjustment + channel->adjust_queue < LIBSSH2_CHANNEL_MINADJUST)) { _libssh2_debug((channel->session, LIBSSH2_TRACE_CONN, - "Queueing %lu bytes for receive window adjustment " - "for channel %lu/%lu", + "Queueing %u bytes for receive window adjustment " + "for channel %u/%u", adjustment, channel->local.id, channel->remote.id)); channel->adjust_queue += adjustment; return 0; @@ -1901,8 +1901,8 @@ _libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL * channel, _libssh2_htonu32(&channel->adjust_adjust[1], channel->remote.id); _libssh2_htonu32(&channel->adjust_adjust[5], adjustment); _libssh2_debug((channel->session, LIBSSH2_TRACE_CONN, - "Adjusting window %lu bytes for data on " - "channel %lu/%lu", + "Adjusting window %u bytes for data on " + "channel %u/%u", adjustment, channel->local.id, channel->remote.id)); channel->adjust_state = libssh2_NB_state_created; @@ -1930,10 +1930,9 @@ _libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL * channel, return 0; } +#ifndef LIBSSH2_NO_DEPRECATED /* - * libssh2_channel_receive_window_adjust - * - * DEPRECATED + * libssh2_channel_receive_window_adjust (DEPRECATED, DO NOT USE!) * * Adjust the receive window for a channel by adjustment bytes. If the amount * to be adjusted is less than LIBSSH2_CHANNEL_MINADJUST and force is 0 the @@ -1963,6 +1962,7 @@ libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL *channel, kept for backwards compatibility */ return rc ? (unsigned long)rc : window; } +#endif /* * libssh2_channel_receive_window_adjust2 @@ -1998,7 +1998,7 @@ _libssh2_channel_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode) { if(channel->extData2_state == libssh2_NB_state_idle) { _libssh2_debug((channel->session, LIBSSH2_TRACE_CONN, - "Setting channel %lu/%lu handle_extended_data" + "Setting channel %u/%u handle_extended_data" " mode to %d", channel->local.id, channel->remote.id, ignore_mode)); channel->remote.extended_data_ignore_mode = (char)ignore_mode; @@ -2038,10 +2038,9 @@ libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL *channel, return rc; } +#ifndef LIBSSH2_NO_DEPRECATED /* - * libssh2_channel_handle_extended_data - * - * DEPRECATED DO NOTE USE! + * libssh2_channel_handle_extended_data (DEPRECATED, DO NOT USE!) * * How should extended data look to the calling app? Keep it in separate * channels[_read() _read_stdder()]? (NORMAL) Merge the extended data to the @@ -2054,7 +2053,7 @@ libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel, { (void)libssh2_channel_handle_extended_data2(channel, ignore_mode); } - +#endif /* @@ -2081,9 +2080,9 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id, LIBSSH2_PACKET *read_next; _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "channel_read() wants %d bytes from channel %lu/%lu " + "channel_read() wants %ld bytes from channel %u/%u " "stream #%d", - (int) buflen, channel->local.id, channel->remote.id, + (long)buflen, channel->local.id, channel->remote.id, stream_id)); /* expand the receiving window first if it has become too narrow */ @@ -2178,8 +2177,8 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id, } _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "channel_read() got %d of data from %lu/%lu/%d%s", - bytes_want, channel->local.id, + "channel_read() got %ld of data from %u/%u/%d%s", + (long)bytes_want, channel->local.id, channel->remote.id, stream_id, unlink_packet?" [ul]":"")); @@ -2356,8 +2355,8 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, unsigned char *s = channel->write_packet; _libssh2_debug((channel->session, LIBSSH2_TRACE_CONN, - "Writing %d bytes on channel %lu/%lu, stream #%d", - (int) buflen, channel->local.id, channel->remote.id, + "Writing %ld bytes on channel %u/%u, stream #%d", + (long)buflen, channel->local.id, channel->remote.id, stream_id)); if(channel->local.close) @@ -2405,16 +2404,16 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, /* REMEMBER local means local as the SOURCE of the data */ if(channel->write_bufwrite > channel->local.window_size) { _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Splitting write block due to %lu byte " - "window_size on %lu/%lu/%d", + "Splitting write block due to %u byte " + "window_size on %u/%u/%d", channel->local.window_size, channel->local.id, channel->remote.id, stream_id)); channel->write_bufwrite = channel->local.window_size; } if(channel->write_bufwrite > channel->local.packet_size) { _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Splitting write block due to %lu byte " - "packet_size on %lu/%lu/%d", + "Splitting write block due to %u byte " + "packet_size on %u/%u/%d", channel->local.packet_size, channel->local.id, channel->remote.id, stream_id)); channel->write_bufwrite = channel->local.packet_size; @@ -2425,8 +2424,8 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, channel->write_packet_len = s - channel->write_packet; _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Sending %d bytes on channel %lu/%lu, stream_id=%d", - (int) channel->write_bufwrite, channel->local.id, + "Sending %ld bytes on channel %u/%u, stream_id=%d", + (long)channel->write_bufwrite, channel->local.id, channel->remote.id, stream_id)); channel->write_state = libssh2_NB_state_created; @@ -2500,7 +2499,7 @@ static int channel_send_eof(LIBSSH2_CHANNEL *channel) int rc; _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Sending EOF on channel %lu/%lu", + "Sending EOF on channel %u/%u", channel->local.id, channel->remote.id)); packet[0] = SSH_MSG_CHANNEL_EOF; _libssh2_htonu32(packet + 1, channel->remote.id); @@ -2590,7 +2589,7 @@ static int channel_wait_eof(LIBSSH2_CHANNEL *channel) if(channel->wait_eof_state == libssh2_NB_state_idle) { _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Awaiting EOF for channel %lu/%lu", channel->local.id, + "Awaiting EOF for channel %u/%u", channel->local.id, channel->remote.id)); channel->wait_eof_state = libssh2_NB_state_created; @@ -2671,7 +2670,7 @@ int _libssh2_channel_close(LIBSSH2_CHANNEL * channel) late for us to wait for it. Continue closing! */ if(channel->close_state == libssh2_NB_state_idle) { - _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Closing channel %lu/%lu", + _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Closing channel %u/%u", channel->local.id, channel->remote.id)); channel->close_packet[0] = SSH_MSG_CHANNEL_CLOSE; @@ -2762,7 +2761,7 @@ static int channel_wait_closed(LIBSSH2_CHANNEL *channel) if(channel->wait_closed_state == libssh2_NB_state_idle) { _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Awaiting close of channel %lu/%lu", channel->local.id, + "Awaiting close of channel %u/%u", channel->local.id, channel->remote.id)); channel->wait_closed_state = libssh2_NB_state_created; @@ -2825,7 +2824,7 @@ int _libssh2_channel_free(LIBSSH2_CHANNEL *channel) if(channel->free_state == libssh2_NB_state_idle) { _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Freeing channel %lu/%lu resources", channel->local.id, + "Freeing channel %u/%u resources", channel->local.id, channel->remote.id)); channel->free_state = libssh2_NB_state_created; diff --git a/libs/libssh2/src/channel.h b/libs/libssh2/src/channel.h index 6d03550164..709ec0615f 100644 --- a/libs/libssh2/src/channel.h +++ b/libs/libssh2/src/channel.h @@ -1,5 +1,5 @@ -#ifndef __LIBSSH2_CHANNEL_H -#define __LIBSSH2_CHANNEL_H +#ifndef LIBSSH2_CHANNEL_H +#define LIBSSH2_CHANNEL_H /* Copyright (C) Daniel Stenberg * * All rights reserved. @@ -139,4 +139,4 @@ int _libssh2_channel_close(LIBSSH2_CHANNEL * channel); */ int _libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener); -#endif /* __LIBSSH2_CHANNEL_H */ +#endif /* LIBSSH2_CHANNEL_H */ diff --git a/libs/libssh2/src/comp.c b/libs/libssh2/src/comp.c index 55ddb85a48..ecfb28a315 100644 --- a/libs/libssh2/src/comp.c +++ b/libs/libssh2/src/comp.c @@ -208,7 +208,7 @@ comp_method_zlib_comp(LIBSSH2_SESSION *session, } _libssh2_debug((session, LIBSSH2_TRACE_TRANS, - "unhandled zlib compression error %d, avail_out", + "unhandled zlib compression error %d, avail_out %u", status, strm->avail_out)); return _libssh2_error(session, LIBSSH2_ERROR_ZLIB, "compression failure"); } diff --git a/libs/libssh2/src/comp.h b/libs/libssh2/src/comp.h index cce113b2bc..6a35d69494 100644 --- a/libs/libssh2/src/comp.h +++ b/libs/libssh2/src/comp.h @@ -1,5 +1,5 @@ -#ifndef __LIBSSH2_COMP_H -#define __LIBSSH2_COMP_H +#ifndef LIBSSH2_COMP_H +#define LIBSSH2_COMP_H /* Copyright (C) Daniel Stenberg * * Redistribution and use in source and binary forms, @@ -42,4 +42,4 @@ const LIBSSH2_COMP_METHOD **_libssh2_comp_methods(LIBSSH2_SESSION *session); -#endif /* __LIBSSH2_COMP_H */ +#endif /* LIBSSH2_COMP_H */ diff --git a/libs/libssh2/src/crypto.h b/libs/libssh2/src/crypto.h index 561cd96e2b..487444145d 100644 --- a/libs/libssh2/src/crypto.h +++ b/libs/libssh2/src/crypto.h @@ -1,5 +1,5 @@ -#ifndef __LIBSSH2_CRYPTO_H -#define __LIBSSH2_CRYPTO_H +#ifndef LIBSSH2_CRYPTO_H +#define LIBSSH2_CRYPTO_H /* Copyright (C) Simon Josefsson * Copyright (C) The Written Word, Inc. * Copyright (C) Daniel Stenberg @@ -55,70 +55,26 @@ #error "no cryptography backend selected" #endif -#ifdef LIBSSH2_NO_MD5 -#undef LIBSSH2_MD5 -#define LIBSSH2_MD5 0 +/* return: success = 1, error = 0 */ +int _libssh2_hmac_ctx_init(libssh2_hmac_ctx *ctx); +#if LIBSSH2_MD5 +int _libssh2_hmac_md5_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen); #endif - -#ifdef LIBSSH2_NO_HMAC_RIPEMD -#undef LIBSSH2_HMAC_RIPEMD -#define LIBSSH2_HMAC_RIPEMD 0 -#endif - -#ifdef LIBSSH2_NO_DSA -#undef LIBSSH2_DSA -#define LIBSSH2_DSA 0 -#endif - -#ifdef LIBSSH2_NO_RSA -#undef LIBSSH2_RSA -#define LIBSSH2_RSA 0 -#endif - -#ifdef LIBSSH2_NO_RSA_SHA1 -#undef LIBSSH2_RSA_SHA1 -#define LIBSSH2_RSA_SHA1 0 -#endif - -#ifdef LIBSSH2_NO_ECDSA -#undef LIBSSH2_ECDSA -#define LIBSSH2_ECDSA 0 -#endif - -#ifdef LIBSSH2_NO_ED25519 -#undef LIBSSH2_ED25519 -#define LIBSSH2_ED25519 0 -#endif - -#ifdef LIBSSH2_NO_AES_CTR -#undef LIBSSH2_AES_CTR -#define LIBSSH2_AES_CTR 0 -#endif - -#ifdef LIBSSH2_NO_AES_CBC -#undef LIBSSH2_AES_CBC -#define LIBSSH2_AES_CBC 0 -#endif - -#ifdef LIBSSH2_NO_BLOWFISH -#undef LIBSSH2_BLOWFISH -#define LIBSSH2_BLOWFISH 0 -#endif - -#ifdef LIBSSH2_NO_RC4 -#undef LIBSSH2_RC4 -#define LIBSSH2_RC4 0 -#endif - -#ifdef LIBSSH2_NO_CAST -#undef LIBSSH2_CAST -#define LIBSSH2_CAST 0 -#endif - -#ifdef LIBSSH2_NO_3DES -#undef LIBSSH2_3DES -#define LIBSSH2_3DES 0 +#if LIBSSH2_HMAC_RIPEMD +int _libssh2_hmac_ripemd160_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen); #endif +int _libssh2_hmac_sha1_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen); +int _libssh2_hmac_sha256_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen); +int _libssh2_hmac_sha512_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen); +int _libssh2_hmac_update(libssh2_hmac_ctx *ctx, + const void *data, size_t datalen); +int _libssh2_hmac_final(libssh2_hmac_ctx *ctx, void *data); +void _libssh2_hmac_cleanup(libssh2_hmac_ctx *ctx); #define LIBSSH2_ED25519_KEY_LEN 32 #define LIBSSH2_ED25519_PRIVATE_KEY_LEN 64 @@ -146,16 +102,16 @@ int _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa, const char *filename, unsigned const char *passphrase); #if LIBSSH2_RSA_SHA1 -int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa, - const unsigned char *sig, - size_t sig_len, - const unsigned char *m, size_t m_len); int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, libssh2_rsa_ctx * rsactx, const unsigned char *hash, size_t hash_len, unsigned char **signature, size_t *signature_len); +int _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa, + const unsigned char *sig, + size_t sig_len, + const unsigned char *m, size_t m_len); #endif #if LIBSSH2_RSA_SHA2 int _libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session, @@ -398,4 +354,4 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, unsigned char *key_method, size_t key_method_len); -#endif /* __LIBSSH2_CRYPTO_H */ +#endif /* LIBSSH2_CRYPTO_H */ diff --git a/libs/libssh2/src/crypto_config.h b/libs/libssh2/src/crypto_config.h new file mode 100644 index 0000000000..5934e140b6 --- /dev/null +++ b/libs/libssh2/src/crypto_config.h @@ -0,0 +1,76 @@ +/* Copyright (C) Viktor Szakats + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#define LIBSSH2_MD5_PEM LIBSSH2_MD5 + +#ifdef LIBSSH2_NO_MD5 +#undef LIBSSH2_MD5 +#define LIBSSH2_MD5 0 +#endif + +#ifdef LIBSSH2_NO_MD5_PEM +#undef LIBSSH2_MD5_PEM +#define LIBSSH2_MD5_PEM 0 +#endif + +#ifdef LIBSSH2_NO_HMAC_RIPEMD +#undef LIBSSH2_HMAC_RIPEMD +#define LIBSSH2_HMAC_RIPEMD 0 +#endif + +#ifdef LIBSSH2_NO_DSA +#undef LIBSSH2_DSA +#define LIBSSH2_DSA 0 +#endif + +#ifdef LIBSSH2_NO_RSA +#undef LIBSSH2_RSA +#define LIBSSH2_RSA 0 +#endif + +#ifdef LIBSSH2_NO_RSA_SHA1 +#undef LIBSSH2_RSA_SHA1 +#define LIBSSH2_RSA_SHA1 0 +#endif + +#ifdef LIBSSH2_NO_ECDSA +#undef LIBSSH2_ECDSA +#define LIBSSH2_ECDSA 0 +#endif + +#ifdef LIBSSH2_NO_ED25519 +#undef LIBSSH2_ED25519 +#define LIBSSH2_ED25519 0 +#endif + +#ifdef LIBSSH2_NO_AES_CTR +#undef LIBSSH2_AES_CTR +#define LIBSSH2_AES_CTR 0 +#endif + +#ifdef LIBSSH2_NO_AES_CBC +#undef LIBSSH2_AES_CBC +#define LIBSSH2_AES_CBC 0 +#endif + +#ifdef LIBSSH2_NO_BLOWFISH +#undef LIBSSH2_BLOWFISH +#define LIBSSH2_BLOWFISH 0 +#endif + +#ifdef LIBSSH2_NO_RC4 +#undef LIBSSH2_RC4 +#define LIBSSH2_RC4 0 +#endif + +#ifdef LIBSSH2_NO_CAST +#undef LIBSSH2_CAST +#define LIBSSH2_CAST 0 +#endif + +#ifdef LIBSSH2_NO_3DES +#undef LIBSSH2_3DES +#define LIBSSH2_3DES 0 +#endif diff --git a/libs/libssh2/src/hostkey.c b/libs/libssh2/src/hostkey.c index 56eee369f5..b28b4e6995 100644 --- a/libs/libssh2/src/hostkey.c +++ b/libs/libssh2/src/hostkey.c @@ -106,7 +106,7 @@ hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session, #endif { _libssh2_debug((session, LIBSSH2_TRACE_ERROR, - "unexpected rsa type: %.*s", type_len, type)); + "unexpected rsa type: %.*s", (int)type_len, type)); return -1; } @@ -242,11 +242,18 @@ hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION * session, unsigned char hash[SHA_DIGEST_LENGTH]; libssh2_sha1_ctx ctx; - (void)libssh2_sha1_init(&ctx); + if(!libssh2_sha1_init(&ctx)) { + return -1; + } for(i = 0; i < veccount; i++) { - libssh2_sha1_update(ctx, datavec[i].iov_base, datavec[i].iov_len); + if(!libssh2_sha1_update(ctx, + datavec[i].iov_base, datavec[i].iov_len)) { + return -1; + } + } + if(!libssh2_sha1_final(ctx, hash)) { + return -1; } - libssh2_sha1_final(ctx, hash); ret = _libssh2_rsa_sha1_sign(session, rsactx, hash, SHA_DIGEST_LENGTH, signature, signature_len); @@ -316,9 +323,14 @@ hostkey_method_ssh_rsa_sha2_256_signv(LIBSSH2_SESSION * session, return -1; } for(i = 0; i < veccount; i++) { - libssh2_sha256_update(ctx, datavec[i].iov_base, datavec[i].iov_len); + if(!libssh2_sha256_update(ctx, + datavec[i].iov_base, datavec[i].iov_len)) { + return -1; + } + } + if(!libssh2_sha256_final(ctx, hash)) { + return -1; } - libssh2_sha256_final(ctx, hash); ret = _libssh2_rsa_sha2_sign(session, rsactx, hash, SHA256_DIGEST_LENGTH, signature, signature_len); @@ -386,9 +398,14 @@ hostkey_method_ssh_rsa_sha2_512_signv(LIBSSH2_SESSION * session, return -1; } for(i = 0; i < veccount; i++) { - libssh2_sha512_update(ctx, datavec[i].iov_base, datavec[i].iov_len); + if(!libssh2_sha512_update(ctx, + datavec[i].iov_base, datavec[i].iov_len)) { + return -1; + } + } + if(!libssh2_sha512_final(ctx, hash)) { + return -1; } - libssh2_sha512_final(ctx, hash); ret = _libssh2_rsa_sha2_sign(session, rsactx, hash, SHA512_DIGEST_LENGTH, signature, signature_len); @@ -659,6 +676,12 @@ hostkey_method_ssh_dss_signv(LIBSSH2_SESSION * session, libssh2_sha1_ctx ctx; int i; + if(!libssh2_sha1_init(&ctx)) { + *signature = NULL; + *signature_len = 0; + return -1; + } + *signature = LIBSSH2_CALLOC(session, 2 * SHA_DIGEST_LENGTH); if(!*signature) { return -1; @@ -666,11 +689,15 @@ hostkey_method_ssh_dss_signv(LIBSSH2_SESSION * session, *signature_len = 2 * SHA_DIGEST_LENGTH; - (void)libssh2_sha1_init(&ctx); for(i = 0; i < veccount; i++) { - libssh2_sha1_update(ctx, datavec[i].iov_base, datavec[i].iov_len); + if(!libssh2_sha1_update(ctx, + datavec[i].iov_base, datavec[i].iov_len)) { + return -1; + } + } + if(!libssh2_sha1_final(ctx, hash)) { + return -1; } - libssh2_sha1_final(ctx, hash); if(_libssh2_dsa_sha1_sign(dsactx, hash, SHA_DIGEST_LENGTH, *signature)) { LIBSSH2_FREE(session, *signature); @@ -909,20 +936,33 @@ hostkey_method_ssh_ecdsa_sig_verify(LIBSSH2_SESSION * session, } -#define LIBSSH2_HOSTKEY_METHOD_EC_SIGNV_HASH(digest_type) \ - do { \ - unsigned char hash[SHA##digest_type##_DIGEST_LENGTH]; \ - libssh2_sha##digest_type##_ctx ctx; \ - int i; \ - (void)libssh2_sha##digest_type##_init(&ctx); \ - for(i = 0; i < veccount; i++) { \ - libssh2_sha##digest_type##_update(ctx, datavec[i].iov_base, \ - datavec[i].iov_len); \ - } \ - libssh2_sha##digest_type##_final(ctx, hash); \ - ret = _libssh2_ecdsa_sign(session, ec_ctx, hash, \ - SHA##digest_type##_DIGEST_LENGTH, \ - signature, signature_len); \ +#define LIBSSH2_HOSTKEY_METHOD_EC_SIGNV_HASH(digest_type) \ + do { \ + unsigned char hash[SHA##digest_type##_DIGEST_LENGTH]; \ + libssh2_sha##digest_type##_ctx ctx; \ + int i; \ + if(!libssh2_sha##digest_type##_init(&ctx)) { \ + ret = -1; \ + break; \ + } \ + for(i = 0; i < veccount; i++) { \ + if(!libssh2_sha##digest_type##_update(ctx, \ + datavec[i].iov_base, \ + datavec[i].iov_len)) { \ + ret = -1; \ + break; \ + } \ + } \ + if(ret == -1) { \ + break; \ + } \ + if(!libssh2_sha##digest_type##_final(ctx, hash)) { \ + ret = -1; \ + break; \ + } \ + ret = _libssh2_ecdsa_sign(session, ec_ctx, hash, \ + SHA##digest_type##_DIGEST_LENGTH, \ + signature, signature_len); \ } while(0) @@ -1224,7 +1264,8 @@ hostkey_method_ssh_ed25519_signv(LIBSSH2_SESSION * session, } return _libssh2_ed25519_sign(ctx, session, signature, signature_len, - datavec[0].iov_base, datavec[0].iov_len); + (const uint8_t *)datavec[0].iov_base, + datavec[0].iov_len); } @@ -1326,18 +1367,15 @@ libssh2_hostkey_hash(LIBSSH2_SESSION * session, int hash_type) return (session->server_hostkey_md5_valid) ? (char *) session->server_hostkey_md5 : NULL; - break; #endif /* LIBSSH2_MD5 */ case LIBSSH2_HOSTKEY_HASH_SHA1: return (session->server_hostkey_sha1_valid) ? (char *) session->server_hostkey_sha1 : NULL; - break; case LIBSSH2_HOSTKEY_HASH_SHA256: return (session->server_hostkey_sha256_valid) ? (char *) session->server_hostkey_sha256 : NULL; - break; default: return NULL; } diff --git a/libs/libssh2/src/keepalive.c b/libs/libssh2/src/keepalive.c index 54fddb060f..489a1daaa9 100644 --- a/libs/libssh2/src/keepalive.c +++ b/libs/libssh2/src/keepalive.c @@ -45,7 +45,7 @@ LIBSSH2_API void libssh2_keepalive_config(LIBSSH2_SESSION *session, int want_reply, - unsigned interval) + unsigned int interval) { if(interval == 1) session->keepalive_interval = 2; diff --git a/libs/libssh2/src/kex.c b/libs/libssh2/src/kex.c index 8972d44bb3..8c65a0fee6 100644 --- a/libs/libssh2/src/kex.c +++ b/libs/libssh2/src/kex.c @@ -55,6 +55,7 @@ /* Helper macro called from kex_method_diffie_hellman_group1_sha1_key_exchange */ +#if LIBSSH2_ECDSA #define LIBSSH2_KEX_METHOD_EC_SHA_VALUE_HASH(value, reqlen, version) \ do { \ if(type == LIBSSH2_EC_CURVE_NISTP256) { \ @@ -67,6 +68,7 @@ LIBSSH2_KEX_METHOD_SHA_VALUE_HASH(512, value, reqlen, version); \ } \ } while(0) +#endif #define LIBSSH2_KEX_METHOD_SHA_VALUE_HASH(digest_type, value, \ reqlen, version) \ @@ -79,22 +81,40 @@ do { \ } \ if(value) \ while(len < (size_t)reqlen) { \ - (void)libssh2_sha##digest_type##_init(&hash); \ - libssh2_sha##digest_type##_update(hash, \ - exchange_state->k_value, \ - exchange_state->k_value_len); \ - libssh2_sha##digest_type##_update(hash, \ - exchange_state->h_sig_comp, \ - SHA##digest_type##_DIGEST_LENGTH); \ + if(!libssh2_sha##digest_type##_init(&hash) || \ + !libssh2_sha##digest_type##_update(hash, \ + exchange_state->k_value, \ + exchange_state->k_value_len) || \ + !libssh2_sha##digest_type##_update(hash, \ + exchange_state->h_sig_comp, \ + SHA##digest_type##_DIGEST_LENGTH)) { \ + LIBSSH2_FREE(session, value); \ + value = NULL; \ + break; \ + } \ if(len > 0) { \ - libssh2_sha##digest_type##_update(hash, value, len); \ + if(!libssh2_sha##digest_type##_update(hash, value, len)) { \ + LIBSSH2_FREE(session, value); \ + value = NULL; \ + break; \ + } \ } \ else { \ - libssh2_sha##digest_type##_update(hash, (version), 1); \ - libssh2_sha##digest_type##_update(hash, session->session_id,\ - session->session_id_len); \ + if(!libssh2_sha##digest_type##_update(hash, \ + (version), 1) || \ + !libssh2_sha##digest_type##_update(hash, \ + session->session_id, \ + session->session_id_len)) { \ + LIBSSH2_FREE(session, value); \ + value = NULL; \ + break; \ + } \ + } \ + if(!libssh2_sha##digest_type##_final(hash, (value) + len)) { \ + LIBSSH2_FREE(session, value); \ + value = NULL; \ + break; \ } \ - libssh2_sha##digest_type##_final(hash, (value) + len); \ len += SHA##digest_type##_DIGEST_LENGTH; \ } \ } while(0) @@ -106,75 +126,80 @@ do { \ * don't allow it so we have to wrap them up in helper functions */ -static void _libssh2_sha_algo_ctx_init(int sha_algo, void *ctx) +static int _libssh2_sha_algo_ctx_init(int sha_algo, void *ctx) { if(sha_algo == 512) { - (void)libssh2_sha512_init((libssh2_sha512_ctx*)ctx); + return libssh2_sha512_init((libssh2_sha512_ctx*)ctx); } else if(sha_algo == 384) { - (void)libssh2_sha384_init((libssh2_sha384_ctx*)ctx); + return libssh2_sha384_init((libssh2_sha384_ctx*)ctx); } else if(sha_algo == 256) { - (void)libssh2_sha256_init((libssh2_sha256_ctx*)ctx); + return libssh2_sha256_init((libssh2_sha256_ctx*)ctx); } else if(sha_algo == 1) { - (void)libssh2_sha1_init((libssh2_sha1_ctx*)ctx); + return libssh2_sha1_init((libssh2_sha1_ctx*)ctx); } else { +#ifdef LIBSSH2DEBUG assert(0); +#endif } + return 0; } -static void _libssh2_sha_algo_ctx_update(int sha_algo, void *ctx, - void *data, size_t len) +static int _libssh2_sha_algo_ctx_update(int sha_algo, void *ctx, + void *data, size_t len) { if(sha_algo == 512) { libssh2_sha512_ctx *_ctx = (libssh2_sha512_ctx*)ctx; - libssh2_sha512_update(*_ctx, data, len); + return libssh2_sha512_update(*_ctx, data, len); } else if(sha_algo == 384) { libssh2_sha384_ctx *_ctx = (libssh2_sha384_ctx*)ctx; - libssh2_sha384_update(*_ctx, data, len); + return libssh2_sha384_update(*_ctx, data, len); } else if(sha_algo == 256) { libssh2_sha256_ctx *_ctx = (libssh2_sha256_ctx*)ctx; - libssh2_sha256_update(*_ctx, data, len); + return libssh2_sha256_update(*_ctx, data, len); } else if(sha_algo == 1) { libssh2_sha1_ctx *_ctx = (libssh2_sha1_ctx*)ctx; - libssh2_sha1_update(*_ctx, data, len); + return libssh2_sha1_update(*_ctx, data, len); } else { #ifdef LIBSSH2DEBUG assert(0); #endif } + return 0; } -static void _libssh2_sha_algo_ctx_final(int sha_algo, void *ctx, - void *hash) +static int _libssh2_sha_algo_ctx_final(int sha_algo, void *ctx, + void *hash) { if(sha_algo == 512) { libssh2_sha512_ctx *_ctx = (libssh2_sha512_ctx*)ctx; - libssh2_sha512_final(*_ctx, hash); + return libssh2_sha512_final(*_ctx, hash); } else if(sha_algo == 384) { libssh2_sha384_ctx *_ctx = (libssh2_sha384_ctx*)ctx; - libssh2_sha384_final(*_ctx, hash); + return libssh2_sha384_final(*_ctx, hash); } else if(sha_algo == 256) { libssh2_sha256_ctx *_ctx = (libssh2_sha256_ctx*)ctx; - libssh2_sha256_final(*_ctx, hash); + return libssh2_sha256_final(*_ctx, hash); } else if(sha_algo == 1) { libssh2_sha1_ctx *_ctx = (libssh2_sha1_ctx*)ctx; - libssh2_sha1_final(*_ctx, hash); + return libssh2_sha1_final(*_ctx, hash); } else { #ifdef LIBSSH2DEBUG assert(0); #endif } + return 0; } static void _libssh2_sha_algo_value_hash(int sha_algo, @@ -300,8 +325,8 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, exchange_state->e_packet + 6); } - _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Sending KEX packet %d", - (int) packet_type_init)); + _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Sending KEX packet %u", + (unsigned int) packet_type_init)); exchange_state->state = libssh2_NB_state_created; } @@ -355,6 +380,7 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, struct string_buf buf; size_t host_key_len; int err; + int hok; rc = _libssh2_packet_require(session, packet_type_reply, &exchange_state->s_packet, @@ -397,11 +423,11 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, { libssh2_md5_ctx fingerprint_ctx; - if(libssh2_md5_init(&fingerprint_ctx)) { - libssh2_md5_update(fingerprint_ctx, session->server_hostkey, - session->server_hostkey_len); - libssh2_md5_final(fingerprint_ctx, - session->server_hostkey_md5); + if(libssh2_md5_init(&fingerprint_ctx) && + libssh2_md5_update(fingerprint_ctx, session->server_hostkey, + session->server_hostkey_len) && + libssh2_md5_final(fingerprint_ctx, + session->server_hostkey_md5)) { session->server_hostkey_md5_valid = TRUE; } else { @@ -425,11 +451,11 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, { libssh2_sha1_ctx fingerprint_ctx; - if(libssh2_sha1_init(&fingerprint_ctx)) { - libssh2_sha1_update(fingerprint_ctx, session->server_hostkey, - session->server_hostkey_len); - libssh2_sha1_final(fingerprint_ctx, - session->server_hostkey_sha1); + if(libssh2_sha1_init(&fingerprint_ctx) && + libssh2_sha1_update(fingerprint_ctx, session->server_hostkey, + session->server_hostkey_len) && + libssh2_sha1_final(fingerprint_ctx, + session->server_hostkey_sha1)) { session->server_hostkey_sha1_valid = TRUE; } else { @@ -452,11 +478,11 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, { libssh2_sha256_ctx fingerprint_ctx; - if(libssh2_sha256_init(&fingerprint_ctx)) { - libssh2_sha256_update(fingerprint_ctx, session->server_hostkey, - session->server_hostkey_len); - libssh2_sha256_final(fingerprint_ctx, - session->server_hostkey_sha256); + if(libssh2_sha256_init(&fingerprint_ctx) && + libssh2_sha256_update(fingerprint_ctx, session->server_hostkey, + session->server_hostkey_len) && + libssh2_sha256_final(fingerprint_ctx, + session->server_hostkey_sha256)) { session->server_hostkey_sha256_valid = TRUE; } else { @@ -532,59 +558,66 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, } exchange_state->exchange_hash = (void *)&exchange_hash_ctx; - _libssh2_sha_algo_ctx_init(sha_algo_value, exchange_hash_ctx); - + if(!_libssh2_sha_algo_ctx_init(sha_algo_value, exchange_hash_ctx)) { + ret = _libssh2_error(session, LIBSSH2_ERROR_HASH_INIT, + "Unable to initialize hash context"); + goto clean_exit; + } + hok = 1; if(session->local.banner) { _libssh2_htonu32(exchange_state->h_sig_comp, (uint32_t)(strlen((char *) session->local.banner) - 2)); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - exchange_state->h_sig_comp, 4); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - session->local.banner, + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, + exchange_hash_ctx, + exchange_state->h_sig_comp, 4); + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, + exchange_hash_ctx, + session->local.banner, strlen((char *) session->local.banner) - 2); } else { _libssh2_htonu32(exchange_state->h_sig_comp, sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - exchange_state->h_sig_comp, 4); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - (unsigned char *) - LIBSSH2_SSH_DEFAULT_BANNER, + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, + exchange_hash_ctx, + exchange_state->h_sig_comp, 4); + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, + exchange_hash_ctx, + (unsigned char *)LIBSSH2_SSH_DEFAULT_BANNER, sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); } _libssh2_htonu32(exchange_state->h_sig_comp, (uint32_t)strlen((char *) session->remote.banner)); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - exchange_state->h_sig_comp, 4); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - session->remote.banner, - strlen((char *) session->remote.banner)); + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, + exchange_state->h_sig_comp, 4); + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, + session->remote.banner, + strlen((char *)session->remote.banner)); _libssh2_htonu32(exchange_state->h_sig_comp, (uint32_t)session->local.kexinit_len); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - exchange_state->h_sig_comp, 4); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - session->local.kexinit, - session->local.kexinit_len); + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, + exchange_state->h_sig_comp, 4); + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, + session->local.kexinit, + session->local.kexinit_len); _libssh2_htonu32(exchange_state->h_sig_comp, (uint32_t)session->remote.kexinit_len); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - exchange_state->h_sig_comp, 4); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - session->remote.kexinit, - session->remote.kexinit_len); + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, + exchange_state->h_sig_comp, 4); + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, + session->remote.kexinit, + session->remote.kexinit_len); _libssh2_htonu32(exchange_state->h_sig_comp, session->server_hostkey_len); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - exchange_state->h_sig_comp, 4); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - session->server_hostkey, - session->server_hostkey_len); + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, + exchange_state->h_sig_comp, 4); + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, + session->server_hostkey, + session->server_hostkey_len); if(packet_type_init == SSH_MSG_KEX_DH_GEX_INIT) { /* diffie-hellman-group-exchange hashes additional fields */ @@ -594,33 +627,41 @@ static int diffie_hellman_sha_algo(LIBSSH2_SESSION *session, LIBSSH2_DH_GEX_OPTGROUP); _libssh2_htonu32(exchange_state->h_sig_comp + 8, LIBSSH2_DH_GEX_MAXGROUP); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - exchange_state->h_sig_comp, 12); + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, + exchange_hash_ctx, + exchange_state->h_sig_comp, + 12); } if(midhash) { - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - midhash, midhash_len); + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, + exchange_hash_ctx, + midhash, midhash_len); } - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - exchange_state->e_packet + 1, - exchange_state->e_packet_len - 1); + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, + exchange_state->e_packet + 1, + exchange_state->e_packet_len - 1); _libssh2_htonu32(exchange_state->h_sig_comp, (uint32_t)exchange_state->f_value_len); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - exchange_state->h_sig_comp, 4); - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - exchange_state->f_value, - exchange_state->f_value_len); - - _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, - exchange_state->k_value, - exchange_state->k_value_len); - - _libssh2_sha_algo_ctx_final(sha_algo_value, exchange_hash_ctx, - exchange_state->h_sig_comp); + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, + exchange_state->h_sig_comp, 4); + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, + exchange_state->f_value, + exchange_state->f_value_len); + + hok &= _libssh2_sha_algo_ctx_update(sha_algo_value, exchange_hash_ctx, + exchange_state->k_value, + exchange_state->k_value_len); + + if(!hok || + !_libssh2_sha_algo_ctx_final(sha_algo_value, exchange_hash_ctx, + exchange_state->h_sig_comp)) { + ret = _libssh2_error(session, LIBSSH2_ERROR_HASH_CALC, + "kex: failed to calculate hash"); + goto clean_exit; + } err = session->hostkey->sig_verify(session, exchange_state->h_sig, @@ -1568,6 +1609,7 @@ dh_gex_clean_exit: return ret; } +#if LIBSSH2_ECDSA /* LIBSSH2_KEX_METHOD_EC_SHA_HASH_CREATE_VERIFY * @@ -1585,101 +1627,104 @@ dh_gex_clean_exit: * mpint K, shared secret * */ - #define LIBSSH2_KEX_METHOD_EC_SHA_HASH_CREATE_VERIFY(digest_type) \ do { \ libssh2_sha##digest_type##_ctx ctx; \ + int hok; \ + if(!libssh2_sha##digest_type##_init(&ctx)) { \ + rc = -1; \ + break; \ + } \ exchange_state->exchange_hash = (void *)&ctx; \ - (void)libssh2_sha##digest_type##_init(&ctx); \ + hok = 1; \ if(session->local.banner) { \ _libssh2_htonu32(exchange_state->h_sig_comp, \ (uint32_t)(strlen((char *) session->local.banner) - 2)); \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - (char *) session->local.banner, \ - strlen((char *) \ - session->local.banner) \ - - 2); \ + hok &= libssh2_sha##digest_type##_update(ctx, \ + exchange_state->h_sig_comp, \ + 4); \ + hok &= libssh2_sha##digest_type##_update(ctx, \ + (char *)session->local.banner, \ + strlen((char *)session->local.banner) \ + - 2); \ } \ else { \ _libssh2_htonu32(exchange_state->h_sig_comp, \ sizeof(LIBSSH2_SSH_DEFAULT_BANNER) - 1); \ - libssh2_sha##digest_type##_update(ctx, \ + hok &= libssh2_sha##digest_type##_update(ctx, \ exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - LIBSSH2_SSH_DEFAULT_BANNER, \ + hok &= libssh2_sha##digest_type##_update(ctx, \ + LIBSSH2_SSH_DEFAULT_BANNER, \ sizeof(LIBSSH2_SSH_DEFAULT_BANNER) \ - 1); \ } \ \ _libssh2_htonu32(exchange_state->h_sig_comp, \ (uint32_t)strlen((char *) session->remote.banner)); \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - session->remote.banner, \ - strlen((char *) \ - session->remote.banner)); \ + hok &= libssh2_sha##digest_type##_update(ctx, \ + exchange_state->h_sig_comp, 4); \ + hok &= libssh2_sha##digest_type##_update(ctx, session->remote.banner, \ + strlen((char *)session->remote.banner)); \ \ _libssh2_htonu32(exchange_state->h_sig_comp, \ (uint32_t)session->local.kexinit_len); \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - session->local.kexinit, \ - session->local.kexinit_len); \ + hok &= libssh2_sha##digest_type##_update(ctx, \ + exchange_state->h_sig_comp, 4); \ + hok &= libssh2_sha##digest_type##_update(ctx, \ + session->local.kexinit, \ + session->local.kexinit_len); \ \ _libssh2_htonu32(exchange_state->h_sig_comp, \ (uint32_t)session->remote.kexinit_len); \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - session->remote.kexinit, \ - session->remote.kexinit_len); \ + hok &= libssh2_sha##digest_type##_update(ctx, \ + exchange_state->h_sig_comp, 4); \ + hok &= libssh2_sha##digest_type##_update(ctx, \ + session->remote.kexinit, \ + session->remote.kexinit_len); \ \ _libssh2_htonu32(exchange_state->h_sig_comp, \ session->server_hostkey_len); \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - session->server_hostkey, \ - session->server_hostkey_len); \ + hok &= libssh2_sha##digest_type##_update(ctx, \ + exchange_state->h_sig_comp, 4); \ + hok &= libssh2_sha##digest_type##_update(ctx, \ + session->server_hostkey, \ + session->server_hostkey_len); \ \ _libssh2_htonu32(exchange_state->h_sig_comp, \ (uint32_t)public_key_len); \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - public_key, \ - public_key_len); \ + hok &= libssh2_sha##digest_type##_update(ctx, \ + exchange_state->h_sig_comp, 4); \ + hok &= libssh2_sha##digest_type##_update(ctx, \ + public_key, \ + public_key_len); \ \ _libssh2_htonu32(exchange_state->h_sig_comp, \ (uint32_t)server_public_key_len); \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->h_sig_comp, 4); \ - libssh2_sha##digest_type##_update(ctx, \ - server_public_key, \ - server_public_key_len); \ + hok &= libssh2_sha##digest_type##_update(ctx, \ + exchange_state->h_sig_comp, 4); \ + hok &= libssh2_sha##digest_type##_update(ctx, \ + server_public_key, \ + server_public_key_len); \ \ - libssh2_sha##digest_type##_update(ctx, \ - exchange_state->k_value, \ - exchange_state->k_value_len); \ + hok &= libssh2_sha##digest_type##_update(ctx, \ + exchange_state->k_value, \ + exchange_state->k_value_len); \ \ - libssh2_sha##digest_type##_final(ctx, exchange_state->h_sig_comp); \ + if(!hok || \ + !libssh2_sha##digest_type##_final(ctx, exchange_state->h_sig_comp)) { \ + rc = -1; \ + break; \ + } \ \ if(session->hostkey-> \ - sig_verify(session, exchange_state->h_sig, \ - exchange_state->h_sig_len, exchange_state->h_sig_comp, \ - SHA##digest_type##_DIGEST_LENGTH, \ - &session->server_hostkey_abstract)) { \ + sig_verify(session, exchange_state->h_sig, \ + exchange_state->h_sig_len, exchange_state->h_sig_comp, \ + SHA##digest_type##_DIGEST_LENGTH, \ + &session->server_hostkey_abstract)) { \ rc = -1; \ } \ } while(0) - -#if LIBSSH2_ECDSA - /* kex_session_ecdh_curve_type * returns the EC curve type by name used in key exchange */ @@ -1764,11 +1809,11 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, { libssh2_md5_ctx fingerprint_ctx; - if(libssh2_md5_init(&fingerprint_ctx)) { - libssh2_md5_update(fingerprint_ctx, session->server_hostkey, - session->server_hostkey_len); - libssh2_md5_final(fingerprint_ctx, - session->server_hostkey_md5); + if(libssh2_md5_init(&fingerprint_ctx) && + libssh2_md5_update(fingerprint_ctx, session->server_hostkey, + session->server_hostkey_len) && + libssh2_md5_final(fingerprint_ctx, + session->server_hostkey_md5)) { session->server_hostkey_md5_valid = TRUE; } else { @@ -1792,11 +1837,11 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, { libssh2_sha1_ctx fingerprint_ctx; - if(libssh2_sha1_init(&fingerprint_ctx)) { - libssh2_sha1_update(fingerprint_ctx, session->server_hostkey, - session->server_hostkey_len); - libssh2_sha1_final(fingerprint_ctx, - session->server_hostkey_sha1); + if(libssh2_sha1_init(&fingerprint_ctx) && + libssh2_sha1_update(fingerprint_ctx, session->server_hostkey, + session->server_hostkey_len) && + libssh2_sha1_final(fingerprint_ctx, + session->server_hostkey_sha1)) { session->server_hostkey_sha1_valid = TRUE; } else { @@ -1820,11 +1865,11 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, { libssh2_sha256_ctx fingerprint_ctx; - if(libssh2_sha256_init(&fingerprint_ctx)) { - libssh2_sha256_update(fingerprint_ctx, session->server_hostkey, - session->server_hostkey_len); - libssh2_sha256_final(fingerprint_ctx, - session->server_hostkey_sha256); + if(libssh2_sha256_init(&fingerprint_ctx) && + libssh2_sha256_update(fingerprint_ctx, session->server_hostkey, + session->server_hostkey_len) && + libssh2_sha256_final(fingerprint_ctx, + session->server_hostkey_sha256)) { session->server_hostkey_sha256_valid = TRUE; } else { @@ -1909,7 +1954,6 @@ static int ecdh_sha2_nistp(LIBSSH2_SESSION *session, libssh2_curve_type type, case LIBSSH2_EC_CURVE_NISTP256: LIBSSH2_KEX_METHOD_EC_SHA_HASH_CREATE_VERIFY(256); break; - case LIBSSH2_EC_CURVE_NISTP384: LIBSSH2_KEX_METHOD_EC_SHA_HASH_CREATE_VERIFY(384); break; @@ -2396,11 +2440,11 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, { libssh2_md5_ctx fingerprint_ctx; - if(libssh2_md5_init(&fingerprint_ctx)) { - libssh2_md5_update(fingerprint_ctx, session->server_hostkey, - session->server_hostkey_len); - libssh2_md5_final(fingerprint_ctx, - session->server_hostkey_md5); + if(libssh2_md5_init(&fingerprint_ctx) && + libssh2_md5_update(fingerprint_ctx, session->server_hostkey, + session->server_hostkey_len) && + libssh2_md5_final(fingerprint_ctx, + session->server_hostkey_md5)) { session->server_hostkey_md5_valid = TRUE; } else { @@ -2424,11 +2468,11 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, { libssh2_sha1_ctx fingerprint_ctx; - if(libssh2_sha1_init(&fingerprint_ctx)) { - libssh2_sha1_update(fingerprint_ctx, session->server_hostkey, - session->server_hostkey_len); - libssh2_sha1_final(fingerprint_ctx, - session->server_hostkey_sha1); + if(libssh2_sha1_init(&fingerprint_ctx) && + libssh2_sha1_update(fingerprint_ctx, session->server_hostkey, + session->server_hostkey_len) && + libssh2_sha1_final(fingerprint_ctx, + session->server_hostkey_sha1)) { session->server_hostkey_sha1_valid = TRUE; } else { @@ -2452,11 +2496,11 @@ curve25519_sha256(LIBSSH2_SESSION *session, unsigned char *data, { libssh2_sha256_ctx fingerprint_ctx; - if(libssh2_sha256_init(&fingerprint_ctx)) { - libssh2_sha256_update(fingerprint_ctx, session->server_hostkey, - session->server_hostkey_len); - libssh2_sha256_final(fingerprint_ctx, - session->server_hostkey_sha256); + if(libssh2_sha256_init(&fingerprint_ctx) && + libssh2_sha256_update(fingerprint_ctx, session->server_hostkey, + session->server_hostkey_len) && + libssh2_sha256_final(fingerprint_ctx, + session->server_hostkey_sha256)) { session->server_hostkey_sha256_valid = TRUE; } else { @@ -3033,6 +3077,13 @@ kex_method_extension_negotiation = { 0, }; +static const LIBSSH2_KEX_METHOD +kex_method_strict_client_extension = { + "kex-strict-c-v00@openssh.com", + NULL, + 0, +}; + static const LIBSSH2_KEX_METHOD *libssh2_kex_methods[] = { #if LIBSSH2_ED25519 &kex_method_ssh_curve25519_sha256, @@ -3051,6 +3102,7 @@ static const LIBSSH2_KEX_METHOD *libssh2_kex_methods[] = { &kex_method_diffie_helman_group1_sha1, &kex_method_diffie_helman_group_exchange_sha1, &kex_method_extension_negotiation, + &kex_method_strict_client_extension, NULL }; @@ -3303,13 +3355,13 @@ static int kexinit(LIBSSH2_SESSION * session) return 0; } -/* kex_agree_instr +/* _libssh2_kex_agree_instr * Kex specific variant of strstr() * Needle must be preceded by BOL or ',', and followed by ',' or EOL */ -static unsigned char * -kex_agree_instr(unsigned char *haystack, size_t haystack_len, - const unsigned char *needle, size_t needle_len) +unsigned char * +_libssh2_kex_agree_instr(unsigned char *haystack, size_t haystack_len, + const unsigned char *needle, size_t needle_len) { unsigned char *s; unsigned char *end_haystack; @@ -3342,6 +3394,7 @@ kex_agree_instr(unsigned char *haystack, size_t haystack_len, left = end_haystack - s; if((left >= 1) && (left <= haystack_len) && (left > needle_len)) { s++; + left--; } else { return NULL; @@ -3394,7 +3447,7 @@ static int kex_agree_hostkey(LIBSSH2_SESSION * session, while(s && *s) { unsigned char *p = (unsigned char *) strchr((char *) s, ','); size_t method_len = (p ? (size_t)(p - s) : strlen((char *) s)); - if(kex_agree_instr(hostkey, hostkey_len, s, method_len)) { + if(_libssh2_kex_agree_instr(hostkey, hostkey_len, s, method_len)) { const LIBSSH2_HOSTKEY_METHOD *method = (const LIBSSH2_HOSTKEY_METHOD *) kex_get_method_by_name((char *) s, method_len, @@ -3428,9 +3481,9 @@ static int kex_agree_hostkey(LIBSSH2_SESSION * session, } while(hostkeyp && (*hostkeyp) && (*hostkeyp)->name) { - s = kex_agree_instr(hostkey, hostkey_len, - (unsigned char *) (*hostkeyp)->name, - strlen((*hostkeyp)->name)); + s = _libssh2_kex_agree_instr(hostkey, hostkey_len, + (unsigned char *) (*hostkeyp)->name, + strlen((*hostkeyp)->name)); if(s) { /* So far so good, but does it suit our purposes? (Encrypting vs Signing) */ @@ -3464,6 +3517,12 @@ static int kex_agree_kex_hostkey(LIBSSH2_SESSION * session, unsigned char *kex, { const LIBSSH2_KEX_METHOD **kexp = libssh2_kex_methods; unsigned char *s; + const unsigned char *strict = + (unsigned char *)"kex-strict-s-v00@openssh.com"; + + if(_libssh2_kex_agree_instr(kex, kex_len, strict, 28)) { + session->kex_strict = 1; + } if(session->kex_prefs) { s = (unsigned char *) session->kex_prefs; @@ -3471,7 +3530,7 @@ static int kex_agree_kex_hostkey(LIBSSH2_SESSION * session, unsigned char *kex, while(s && *s) { unsigned char *q, *p = (unsigned char *) strchr((char *) s, ','); size_t method_len = (p ? (size_t)(p - s) : strlen((char *) s)); - q = kex_agree_instr(kex, kex_len, s, method_len); + q = _libssh2_kex_agree_instr(kex, kex_len, s, method_len); if(q) { const LIBSSH2_KEX_METHOD *method = (const LIBSSH2_KEX_METHOD *) kex_get_method_by_name((char *) s, method_len, @@ -3505,9 +3564,9 @@ static int kex_agree_kex_hostkey(LIBSSH2_SESSION * session, unsigned char *kex, } while(*kexp && (*kexp)->name) { - s = kex_agree_instr(kex, kex_len, - (unsigned char *) (*kexp)->name, - strlen((*kexp)->name)); + s = _libssh2_kex_agree_instr(kex, kex_len, + (unsigned char *) (*kexp)->name, + strlen((*kexp)->name)); if(s) { /* We've agreed on a key exchange method, * Can we agree on a hostkey that works with this kex? @@ -3551,7 +3610,7 @@ static int kex_agree_crypt(LIBSSH2_SESSION * session, unsigned char *p = (unsigned char *) strchr((char *) s, ','); size_t method_len = (p ? (size_t)(p - s) : strlen((char *) s)); - if(kex_agree_instr(crypt, crypt_len, s, method_len)) { + if(_libssh2_kex_agree_instr(crypt, crypt_len, s, method_len)) { const LIBSSH2_CRYPT_METHOD *method = (const LIBSSH2_CRYPT_METHOD *) kex_get_method_by_name((char *) s, method_len, @@ -3573,9 +3632,9 @@ static int kex_agree_crypt(LIBSSH2_SESSION * session, } while(*cryptp && (*cryptp)->name) { - s = kex_agree_instr(crypt, crypt_len, - (unsigned char *) (*cryptp)->name, - strlen((*cryptp)->name)); + s = _libssh2_kex_agree_instr(crypt, crypt_len, + (unsigned char *) (*cryptp)->name, + strlen((*cryptp)->name)); if(s) { endpoint->crypt = *cryptp; return 0; @@ -3615,7 +3674,7 @@ static int kex_agree_mac(LIBSSH2_SESSION * session, unsigned char *p = (unsigned char *) strchr((char *) s, ','); size_t method_len = (p ? (size_t)(p - s) : strlen((char *) s)); - if(kex_agree_instr(mac, mac_len, s, method_len)) { + if(_libssh2_kex_agree_instr(mac, mac_len, s, method_len)) { const LIBSSH2_MAC_METHOD *method = (const LIBSSH2_MAC_METHOD *) kex_get_method_by_name((char *) s, method_len, (const LIBSSH2_COMMON_METHOD **) @@ -3636,8 +3695,9 @@ static int kex_agree_mac(LIBSSH2_SESSION * session, } while(*macp && (*macp)->name) { - s = kex_agree_instr(mac, mac_len, (unsigned char *) (*macp)->name, - strlen((*macp)->name)); + s = _libssh2_kex_agree_instr(mac, mac_len, + (unsigned char *) (*macp)->name, + strlen((*macp)->name)); if(s) { endpoint->mac = *macp; return 0; @@ -3668,7 +3728,7 @@ static int kex_agree_comp(LIBSSH2_SESSION *session, unsigned char *p = (unsigned char *) strchr((char *) s, ','); size_t method_len = (p ? (size_t)(p - s) : strlen((char *) s)); - if(kex_agree_instr(comp, comp_len, s, method_len)) { + if(_libssh2_kex_agree_instr(comp, comp_len, s, method_len)) { const LIBSSH2_COMP_METHOD *method = (const LIBSSH2_COMP_METHOD *) kex_get_method_by_name((char *) s, method_len, @@ -3690,8 +3750,9 @@ static int kex_agree_comp(LIBSSH2_SESSION *session, } while(*compp && (*compp)->name) { - s = kex_agree_instr(comp, comp_len, (unsigned char *) (*compp)->name, - strlen((*compp)->name)); + s = _libssh2_kex_agree_instr(comp, comp_len, + (unsigned char *) (*compp)->name, + strlen((*compp)->name)); if(s) { endpoint->comp = *compp; return 0; @@ -3872,6 +3933,7 @@ _libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange, session->local.kexinit = key_state->oldlocal; session->local.kexinit_len = key_state->oldlocal_len; key_state->state = libssh2_NB_state_idle; + session->state &= ~LIBSSH2_STATE_INITIAL_KEX; session->state &= ~LIBSSH2_STATE_KEX_ACTIVE; session->state &= ~LIBSSH2_STATE_EXCHANGING_KEYS; return -1; @@ -3897,6 +3959,7 @@ _libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange, session->local.kexinit = key_state->oldlocal; session->local.kexinit_len = key_state->oldlocal_len; key_state->state = libssh2_NB_state_idle; + session->state &= ~LIBSSH2_STATE_INITIAL_KEX; session->state &= ~LIBSSH2_STATE_KEX_ACTIVE; session->state &= ~LIBSSH2_STATE_EXCHANGING_KEYS; return -1; @@ -3945,6 +4008,7 @@ _libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange, session->remote.kexinit = NULL; } + session->state &= ~LIBSSH2_STATE_INITIAL_KEX; session->state &= ~LIBSSH2_STATE_KEX_ACTIVE; session->state &= ~LIBSSH2_STATE_EXCHANGING_KEYS; diff --git a/libs/libssh2/src/knownhost.c b/libs/libssh2/src/knownhost.c index 1caab14789..5eba6a108c 100644 --- a/libs/libssh2/src/knownhost.c +++ b/libs/libssh2/src/knownhost.c @@ -421,19 +421,23 @@ knownhost_check(LIBSSH2_KNOWNHOSTS *hosts, */ unsigned char hash[SHA_DIGEST_LENGTH]; libssh2_hmac_ctx ctx; - libssh2_hmac_ctx_init(ctx); + if(!_libssh2_hmac_ctx_init(&ctx)) + break; if(SHA_DIGEST_LENGTH != node->name_len) { /* the name hash length must be the sha1 size or we can't match it */ break; } - libssh2_hmac_sha1_init(&ctx, (unsigned char *)node->salt, - node->salt_len); - libssh2_hmac_update(ctx, (unsigned char *)host, - strlen(host)); - libssh2_hmac_final(ctx, hash); - libssh2_hmac_cleanup(&ctx); + if(!_libssh2_hmac_sha1_init(&ctx, + node->salt, node->salt_len)) + break; + if(!_libssh2_hmac_update(&ctx, host, strlen(host)) || + !_libssh2_hmac_final(&ctx, hash)) { + _libssh2_hmac_cleanup(&ctx); + break; + } + _libssh2_hmac_cleanup(&ctx); if(!memcmp(hash, node->name, SHA_DIGEST_LENGTH)) /* this is a node we're interested in */ @@ -1049,7 +1053,7 @@ knownhost_writeline(LIBSSH2_KNOWNHOSTS *hosts, break; } /* otherwise fallback to default and error */ - /* FALL-THROUGH */ + LIBSSH2_FALLTHROUGH(); default: return _libssh2_error(hosts->session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, diff --git a/libs/libssh2/src/libgcrypt.c b/libs/libssh2/src/libgcrypt.c index e463d9e347..b92ec7c97d 100644 --- a/libs/libssh2/src/libgcrypt.c +++ b/libs/libssh2/src/libgcrypt.c @@ -40,6 +40,105 @@ #ifdef LIBSSH2_CRYPTO_C /* Compile this via crypto.c */ +int _libssh2_hmac_ctx_init(libssh2_hmac_ctx *ctx) +{ + *ctx = NULL; + return 1; +} + +#if LIBSSH2_MD5 +int _libssh2_hmac_md5_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen) +{ + gcry_error_t err; + err = gcry_md_open(ctx, GCRY_MD_MD5, GCRY_MD_FLAG_HMAC); + if(gcry_err_code(err) != GPG_ERR_NO_ERROR) + return 0; + err = gcry_md_setkey(*ctx, key, keylen); + if(gcry_err_code(err) != GPG_ERR_NO_ERROR) + return 0; + return 1; +} +#endif + +#if LIBSSH2_HMAC_RIPEMD +int _libssh2_hmac_ripemd160_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen) +{ + gcry_error_t err; + err = gcry_md_open(ctx, GCRY_MD_RMD160, GCRY_MD_FLAG_HMAC); + if(gcry_err_code(err) != GPG_ERR_NO_ERROR) + return 0; + err = gcry_md_setkey(*ctx, key, keylen); + if(gcry_err_code(err) != GPG_ERR_NO_ERROR) + return 0; + return 1; +} +#endif + +int _libssh2_hmac_sha1_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen) +{ + gcry_error_t err; + err = gcry_md_open(ctx, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC); + if(gcry_err_code(err) != GPG_ERR_NO_ERROR) + return 0; + err = gcry_md_setkey(*ctx, key, keylen); + if(gcry_err_code(err) != GPG_ERR_NO_ERROR) + return 0; + return 1; +} + +int _libssh2_hmac_sha256_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen) +{ + gcry_error_t err; + err = gcry_md_open(ctx, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC); + if(gcry_err_code(err) != GPG_ERR_NO_ERROR) + return 0; + err = gcry_md_setkey(*ctx, key, keylen); + if(gcry_err_code(err) != GPG_ERR_NO_ERROR) + return 0; + return 1; +} + +int _libssh2_hmac_sha512_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen) +{ + gcry_error_t err; + err = gcry_md_open(ctx, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC); + if(gcry_err_code(err) != GPG_ERR_NO_ERROR) + return 0; + err = gcry_md_setkey(*ctx, key, keylen); + if(gcry_err_code(err) != GPG_ERR_NO_ERROR) + return 0; + return 1; +} + +int _libssh2_hmac_update(libssh2_hmac_ctx *ctx, + const void *data, size_t datalen) +{ + gcry_md_write(*ctx, data, datalen); + return 1; +} + +int _libssh2_hmac_final(libssh2_hmac_ctx *ctx, void *data) +{ + unsigned char *res = gcry_md_read(*ctx, 0); + + if(!res) + return 0; + + memcpy(data, res, gcry_md_get_algo_dlen(gcry_md_get_algo(*ctx))); + + return 1; +} + +void _libssh2_hmac_cleanup(libssh2_hmac_ctx *ctx) +{ + gcry_md_close(*ctx); +} + #if LIBSSH2_RSA int _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, @@ -95,7 +194,9 @@ _libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsa, gcry_sexp_t s_sig, s_hash; int rc = -1; - libssh2_sha1(m, m_len, hash); + if(libssh2_sha1(m, m_len, hash)) { + return -1; + } rc = gcry_sexp_build(&s_hash, NULL, "(data (flags pkcs1) (hash sha1 %b))", @@ -544,7 +645,9 @@ _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx, gcry_sexp_t s_sig, s_hash; int rc = -1; - libssh2_sha1(m, m_len, hash + 1); + if(libssh2_sha1(m, m_len, hash + 1)) { + return -1; + } hash[0] = 0; if(gcry_sexp_build(&s_hash, NULL, "(data(flags raw)(value %b))", diff --git a/libs/libssh2/src/libgcrypt.h b/libs/libssh2/src/libgcrypt.h index 77a1b8aba3..7fc8148720 100644 --- a/libs/libssh2/src/libgcrypt.h +++ b/libs/libssh2/src/libgcrypt.h @@ -1,5 +1,5 @@ -#ifndef __LIBSSH2_LIBGCRYPT_H -#define __LIBSSH2_LIBGCRYPT_H +#ifndef LIBSSH2_LIBGCRYPT_H +#define LIBSSH2_LIBGCRYPT_H /* * Copyright (C) Simon Josefsson * Copyright (C) The Written Word, Inc. @@ -53,7 +53,7 @@ #define LIBSSH2_AES_CBC 1 #define LIBSSH2_AES_CTR 1 -#define LIBSSH2_AES_GCM 1 +#define LIBSSH2_AES_GCM 0 #define LIBSSH2_BLOWFISH 1 #define LIBSSH2_RC4 1 #define LIBSSH2_CAST 1 @@ -61,12 +61,16 @@ #define LIBSSH2_RSA 1 #define LIBSSH2_RSA_SHA1 1 -#define LIBSSH2_RSA_SHA2 1 +#define LIBSSH2_RSA_SHA2 0 #define LIBSSH2_DSA 1 -#define LIBSSH2_ECDSA 1 -#define LIBSSH2_ED25519 1 +#define LIBSSH2_ECDSA 0 +#define LIBSSH2_ED25519 0 +#include "crypto_config.h" + +#if LIBSSH2_MD5 || LIBSSH2_MD5_PEM #define MD5_DIGEST_LENGTH 16 +#endif #define SHA_DIGEST_LENGTH 20 #define SHA256_DIGEST_LENGTH 32 #define SHA384_DIGEST_LENGTH 48 @@ -80,86 +84,62 @@ #define libssh2_prepare_iovec(vec, len) /* Empty. */ #define libssh2_sha1_ctx gcry_md_hd_t - /* returns 0 in case of failure */ #define libssh2_sha1_init(ctx) \ (GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA1, 0)) #define libssh2_sha1_update(ctx, data, len) \ - gcry_md_write(ctx, (unsigned char *) data, len) + (gcry_md_write(ctx, (unsigned char *) data, len), 1) #define libssh2_sha1_final(ctx, out) \ - memcpy(out, gcry_md_read(ctx, 0), SHA_DIGEST_LENGTH), gcry_md_close(ctx) + (memcpy(out, gcry_md_read(ctx, 0), SHA_DIGEST_LENGTH), \ + gcry_md_close(ctx), 1) #define libssh2_sha1(message, len, out) \ - gcry_md_hash_buffer(GCRY_MD_SHA1, out, message, len) + (gcry_md_hash_buffer(GCRY_MD_SHA1, out, message, len), 0) #define libssh2_sha256_ctx gcry_md_hd_t - #define libssh2_sha256_init(ctx) \ (GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA256, 0)) #define libssh2_sha256_update(ctx, data, len) \ - gcry_md_write(ctx, (unsigned char *) data, len) + (gcry_md_write(ctx, (unsigned char *) data, len), 1) #define libssh2_sha256_final(ctx, out) \ - memcpy(out, gcry_md_read(ctx, 0), SHA256_DIGEST_LENGTH), gcry_md_close(ctx) + (memcpy(out, gcry_md_read(ctx, 0), SHA256_DIGEST_LENGTH), \ + gcry_md_close(ctx), 1) #define libssh2_sha256(message, len, out) \ - gcry_md_hash_buffer(GCRY_MD_SHA256, out, message, len) + (gcry_md_hash_buffer(GCRY_MD_SHA256, out, message, len), 0) #define libssh2_sha384_ctx gcry_md_hd_t - #define libssh2_sha384_init(ctx) \ (GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA384, 0)) #define libssh2_sha384_update(ctx, data, len) \ - gcry_md_write(ctx, (unsigned char *) data, len) + (gcry_md_write(ctx, (unsigned char *) data, len), 1) #define libssh2_sha384_final(ctx, out) \ - memcpy(out, gcry_md_read(ctx, 0), SHA384_DIGEST_LENGTH), gcry_md_close(ctx) + (memcpy(out, gcry_md_read(ctx, 0), SHA384_DIGEST_LENGTH), \ + gcry_md_close(ctx), 1) #define libssh2_sha384(message, len, out) \ - gcry_md_hash_buffer(GCRY_MD_SHA384, out, message, len) + (gcry_md_hash_buffer(GCRY_MD_SHA384, out, message, len), 0) #define libssh2_sha512_ctx gcry_md_hd_t - #define libssh2_sha512_init(ctx) \ (GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_SHA512, 0)) #define libssh2_sha512_update(ctx, data, len) \ - gcry_md_write(ctx, (unsigned char *) data, len) + (gcry_md_write(ctx, (unsigned char *) data, len), 1) #define libssh2_sha512_final(ctx, out) \ - memcpy(out, gcry_md_read(ctx, 0), SHA512_DIGEST_LENGTH), gcry_md_close(ctx) + (memcpy(out, gcry_md_read(ctx, 0), SHA512_DIGEST_LENGTH), \ + gcry_md_close(ctx), 1) #define libssh2_sha512(message, len, out) \ - gcry_md_hash_buffer(GCRY_MD_SHA512, out, message, len) + (gcry_md_hash_buffer(GCRY_MD_SHA512, out, message, len), 0) +#if LIBSSH2_MD5 || LIBSSH2_MD5_PEM #define libssh2_md5_ctx gcry_md_hd_t - -/* returns 0 in case of failure */ #define libssh2_md5_init(ctx) \ (GPG_ERR_NO_ERROR == gcry_md_open(ctx, GCRY_MD_MD5, 0)) - #define libssh2_md5_update(ctx, data, len) \ - gcry_md_write(ctx, (unsigned char *) data, len) + (gcry_md_write(ctx, (unsigned char *) data, len), 1) #define libssh2_md5_final(ctx, out) \ - memcpy(out, gcry_md_read(ctx, 0), MD5_DIGEST_LENGTH), gcry_md_close(ctx) -#define libssh2_md5(message, len, out) \ - gcry_md_hash_buffer(GCRY_MD_MD5, out, message, len) + (memcpy(out, gcry_md_read(ctx, 0), MD5_DIGEST_LENGTH), \ + gcry_md_close(ctx), 1) +#endif #define libssh2_hmac_ctx gcry_md_hd_t -#define libssh2_hmac_ctx_init(ctx) -#define libssh2_hmac_sha1_init(ctx, key, keylen) \ - gcry_md_open(ctx, GCRY_MD_SHA1, GCRY_MD_FLAG_HMAC), \ - gcry_md_setkey(*ctx, key, keylen) -#define libssh2_hmac_md5_init(ctx, key, keylen) \ - gcry_md_open(ctx, GCRY_MD_MD5, GCRY_MD_FLAG_HMAC), \ - gcry_md_setkey(*ctx, key, keylen) -#define libssh2_hmac_ripemd160_init(ctx, key, keylen) \ - gcry_md_open(ctx, GCRY_MD_RMD160, GCRY_MD_FLAG_HMAC), \ - gcry_md_setkey(*ctx, key, keylen) -#define libssh2_hmac_sha256_init(ctx, key, keylen) \ - gcry_md_open(ctx, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC), \ - gcry_md_setkey(*ctx, key, keylen) -#define libssh2_hmac_sha512_init(ctx, key, keylen) \ - gcry_md_open(ctx, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC), \ - gcry_md_setkey(*ctx, key, keylen) -#define libssh2_hmac_update(ctx, data, datalen) \ - gcry_md_write(ctx, (unsigned char *) data, datalen) -#define libssh2_hmac_final(ctx, data) \ - memcpy(data, gcry_md_read(ctx, 0), \ - gcry_md_get_algo_dlen(gcry_md_get_algo(ctx))) -#define libssh2_hmac_cleanup(ctx) gcry_md_close(*ctx) #define libssh2_crypto_init() gcry_control(GCRYCTL_DISABLE_SECMEM) #define libssh2_crypto_exit() @@ -250,4 +230,4 @@ extern int _libssh2_dh_secret(_libssh2_dh_ctx *dhctx, _libssh2_bn *secret, _libssh2_bn *f, _libssh2_bn *p); extern void _libssh2_dh_dtor(_libssh2_dh_ctx *dhctx); -#endif /* __LIBSSH2_LIBGCRYPT_H */ +#endif /* LIBSSH2_LIBGCRYPT_H */ diff --git a/libs/libssh2/src/libssh2.rc b/libs/libssh2/src/libssh2.rc index 4862d78eef..3021d8e69c 100644 --- a/libs/libssh2/src/libssh2.rc +++ b/libs/libssh2/src/libssh2.rc @@ -1,7 +1,7 @@ /*************************************************************************** * libssh2 Windows resource file * Copyright (C) The libssh2 project and its contributors. -* +* * SPDX-License-Identifier: BSD-3-Clause ***************************************************************************/ #include <winver.h> @@ -29,7 +29,7 @@ BEGIN BEGIN BLOCK "040904b0" /* 0x0409: en-US, 1200/0x04b0: UTF-16LE */ BEGIN - VALUE "CompanyName", "The libssh2 library, https://www.libssh2.org/\0" + VALUE "CompanyName", "The libssh2 library, https://libssh2.org/\0" VALUE "FileDescription", "libssh2 Shared Library\0" VALUE "FileVersion", LIBSSH2_VERSION "\0" VALUE "InternalName", "libssh2\0" @@ -37,7 +37,7 @@ BEGIN VALUE "ProductName", "The libssh2 library\0" VALUE "ProductVersion", LIBSSH2_VERSION "\0" VALUE "LegalCopyright", "Copyright (C) " LIBSSH2_COPYRIGHT "\0" - VALUE "License", "https://www.libssh2.org/license.html\0" + VALUE "License", "https://libssh2.org/license.html\0" END END diff --git a/libs/libssh2/src/libssh2_priv.h b/libs/libssh2/src/libssh2_priv.h index 96af134279..18d9ab2130 100644 --- a/libs/libssh2/src/libssh2_priv.h +++ b/libs/libssh2/src/libssh2_priv.h @@ -1,5 +1,5 @@ -#ifndef __LIBSSH2_PRIV_H -#define __LIBSSH2_PRIV_H +#ifndef LIBSSH2_PRIV_H +#define LIBSSH2_PRIV_H /* Copyright (C) Sara Golemon <sarag@libssh2.org> * Copyright (C) Daniel Stenberg * Copyright (C) Simon Josefsson @@ -41,7 +41,14 @@ * SPDX-License-Identifier: BSD-3-Clause */ -/* Header used by 'src' */ +/* Header used by 'src' and 'tests' */ + +/* FIXME: Disable warnings for 'src' */ +#if !defined(LIBSSH2_TESTS) && !defined(LIBSSH2_WARN_SIGN_CONVERSION) +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wsign-conversion" +#endif +#endif #define LIBSSH2_LIBRARY @@ -86,6 +93,19 @@ #include "libssh2_sftp.h" #include "misc.h" +#ifdef _WIN32 +/* Detect Windows App environment which has a restricted access + to the Win32 APIs. */ +# if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \ + defined(WINAPI_FAMILY) +# include <winapifamily.h> +# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \ + !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +# define LIBSSH2_WINDOWS_UWP +# endif +# endif +#endif + #ifndef FALSE #define FALSE 0 #endif @@ -93,12 +113,28 @@ #define TRUE 1 #endif +#if (defined(__GNUC__) || defined(__clang__)) && \ + defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ + !defined(LIBSSH2_NO_FMT_CHECKS) +#ifdef __MINGW_PRINTF_FORMAT +#define LIBSSH2_PRINTF(fmt, arg) \ + __attribute__((format(__MINGW_PRINTF_FORMAT, fmt, arg))) +#elif !defined(__MINGW32__) +#define LIBSSH2_PRINTF(fmt, arg) \ + __attribute__((format(printf, fmt, arg))) +#endif +#endif +#ifndef LIBSSH2_PRINTF +#define LIBSSH2_PRINTF(fmt, arg) +#endif + /* Use local implementation when not available */ #if !defined(HAVE_SNPRINTF) #undef snprintf #define snprintf _libssh2_snprintf #define LIBSSH2_SNPRINTF -int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...); +int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...) + LIBSSH2_PRINTF(3, 4); #endif #if !defined(HAVE_GETTIMEOFDAY) @@ -111,6 +147,15 @@ int _libssh2_gettimeofday(struct timeval *tp, void *tzp); #include <sys/time.h> #endif +#if !defined(LIBSSH2_FALLTHROUGH) +#if (defined(__GNUC__) && __GNUC__ >= 7) || \ + (defined(__clang__) && __clang_major__ >= 10) +# define LIBSSH2_FALLTHROUGH() __attribute__((fallthrough)) +#else +# define LIBSSH2_FALLTHROUGH() do {} while (0) +#endif +#endif + /* "inline" keyword is valid only with C++ engine! */ #ifdef __GNUC__ #undef inline @@ -121,7 +166,7 @@ int _libssh2_gettimeofday(struct timeval *tp, void *tzp); #endif /* 3DS doesn't seem to have iovec */ -#if defined(WIN32) || defined(_3DS) +#if defined(_WIN32) || defined(_3DS) struct iovec { size_t iov_len; @@ -152,6 +197,9 @@ struct iovec { #define LIBSSH2_MAX(x, y) ((x) > (y) ? (x) : (y)) #define LIBSSH2_MIN(x, y) ((x) < (y) ? (x) : (y)) +#define MAX_BLOCKSIZE 32 /* MUST fit biggest crypto block size we use/get */ +#define MAX_MACSIZE 64 /* MUST fit biggest MAC length we support */ + /* RFC4253 section 6.1 Maximum Packet Length says: * * "All implementations MUST be able to process packets with @@ -402,7 +450,7 @@ struct _LIBSSH2_CHANNEL struct list_node node; unsigned char *channel_type; - unsigned channel_type_len; + size_t channel_type_len; /* channel's program exit status */ int exit_status; @@ -455,7 +503,7 @@ struct _LIBSSH2_CHANNEL size_t flush_refund_bytes; size_t flush_flush_bytes; - /* State variables used in libssh2_channel_receive_window_adjust() */ + /* State variables used in libssh2_channel_receive_window_adjust2() */ libssh2_nonblocking_states adjust_state; unsigned char adjust_adjust[9]; /* packet_type(1) + channel(4) + adjustment(4) */ @@ -688,6 +736,9 @@ struct _LIBSSH2_SESSION /* key signing algorithm preferences -- NULL yields server order */ char *sign_algo_prefs; + /* Whether to use the OpenSSH Strict KEX extension */ + int kex_strict; + /* (remote as source of data -- packet_read ) */ libssh2_endpoint_data remote; @@ -710,7 +761,8 @@ struct _LIBSSH2_SESSION int socket_state; int socket_block_directions; int socket_prev_blockstate; /* stores the state of the socket blockiness - when libssh2_session_startup() is called */ + when libssh2_session_handshake() + is called */ /* Error tracking */ const char *err_msg; @@ -736,7 +788,7 @@ struct _LIBSSH2_SESSION unsigned char *kexinit_data; size_t kexinit_data_len; - /* State variables used in libssh2_session_startup() */ + /* State variables used in libssh2_session_handshake() */ libssh2_nonblocking_states startup_state; unsigned char *startup_data; size_t startup_data_len; @@ -859,6 +911,7 @@ struct _LIBSSH2_SESSION int fullpacket_macstate; size_t fullpacket_payload_len; int fullpacket_packet_type; + uint32_t fullpacket_required_type; /* State variables used in libssh2_sftp_init() */ libssh2_nonblocking_states sftpInit_state; @@ -869,7 +922,7 @@ struct _LIBSSH2_SESSION size_t sftpInit_sent; /* number of bytes from the buffer that have been sent */ - /* State variables used in libssh2_scp_recv() / libssh_scp_recv2() */ + /* State variables used in libssh2_scp_recv2() */ libssh2_nonblocking_states scpRecv_state; unsigned char *scpRecv_command; size_t scpRecv_command_len; @@ -899,10 +952,11 @@ struct _LIBSSH2_SESSION }; /* session.state bits */ -#define LIBSSH2_STATE_EXCHANGING_KEYS 0x00000001 -#define LIBSSH2_STATE_NEWKEYS 0x00000002 -#define LIBSSH2_STATE_AUTHENTICATED 0x00000004 -#define LIBSSH2_STATE_KEX_ACTIVE 0x00000008 +#define LIBSSH2_STATE_INITIAL_KEX 0x00000001 +#define LIBSSH2_STATE_EXCHANGING_KEYS 0x00000002 +#define LIBSSH2_STATE_NEWKEYS 0x00000004 +#define LIBSSH2_STATE_AUTHENTICATED 0x00000008 +#define LIBSSH2_STATE_KEX_ACTIVE 0x00000010 /* session.flag helpers */ #ifdef MSG_NOSIGNAL @@ -1032,7 +1086,7 @@ struct _LIBSSH2_COMP_METHOD #ifdef LIBSSH2DEBUG void _libssh2_debug_low(LIBSSH2_SESSION * session, int context, const char *format, - ...); + ...) LIBSSH2_PRINTF(3, 4); #define _libssh2_debug(x) _libssh2_debug_low x #else #define _libssh2_debug(x) do {} while(0) @@ -1133,6 +1187,11 @@ ssize_t _libssh2_send(libssh2_socket_t socket, const void *buffer, int _libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange, key_exchange_state_t * state); +unsigned char *_libssh2_kex_agree_instr(unsigned char *haystack, + size_t haystack_len, + const unsigned char *needle, + size_t needle_len); + /* Let crypt.c/hostkey.c expose their method structs */ const LIBSSH2_CRYPT_METHOD **libssh2_crypt_methods(void); const LIBSSH2_HOSTKEY_METHOD **libssh2_hostkey_methods(void); @@ -1182,6 +1241,8 @@ size_t plain_method(char *method, size_t method_len); /* define to output the libssh2_int64_t type in a *printf() */ #if defined(__BORLANDC__) || defined(_MSC_VER) #define LIBSSH2_INT64_T_FORMAT "I64d" +#elif defined(__MINGW32__) +#define LIBSSH2_INT64_T_FORMAT PRId64 #else #define LIBSSH2_INT64_T_FORMAT "lld" #endif @@ -1189,12 +1250,12 @@ size_t plain_method(char *method, size_t method_len); /* In Windows the default file mode is text but an application can override it. Therefore we specify it explicitly. https://github.com/curl/curl/pull/258 */ -#if defined(WIN32) || defined(MSDOS) +#if defined(_WIN32) || defined(MSDOS) #define FOPEN_READTEXT "rt" #define FOPEN_WRITETEXT "wt" #define FOPEN_APPENDTEXT "at" #elif defined(__CYGWIN__) -/* Cygwin has specific behavior we need to address when WIN32 is not defined. +/* Cygwin has specific behavior we need to address when _WIN32 is not defined. https://cygwin.com/cygwin-ug-net/using-textbinary.html For write we want our output to have line endings of LF and be compatible with other Cygwin utilities. For read we want to handle input that may have @@ -1209,4 +1270,4 @@ size_t plain_method(char *method, size_t method_len); #define FOPEN_APPENDTEXT "a" #endif -#endif /* __LIBSSH2_PRIV_H */ +#endif /* LIBSSH2_PRIV_H */ diff --git a/libs/libssh2/src/libssh2_setup.h b/libs/libssh2/src/libssh2_setup.h index 8e56a06042..7e084f993a 100644 --- a/libs/libssh2/src/libssh2_setup.h +++ b/libs/libssh2/src/libssh2_setup.h @@ -9,10 +9,6 @@ /* Header for platform/compiler-specific initialization. Used by 'src', 'example', 'tests' */ -#if defined(_WIN32) && !defined(WIN32) -#define WIN32 -#endif - /* Define mingw-w64 version macros, eg __MINGW{32,64}_{MINOR,MAJOR}_VERSION */ #ifdef __MINGW32__ #include <_mingw.h> @@ -26,7 +22,7 @@ /* Hand-crafted configuration for platforms which lack config tool. Keep this synced with root CMakeLists.txt */ -#elif defined(WIN32) +#elif defined(_WIN32) #define HAVE_SELECT #define HAVE_SNPRINTF @@ -54,7 +50,7 @@ /* Below applies to both auto-detected and hand-crafted configs */ -#ifdef WIN32 +#ifdef _WIN32 #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN @@ -103,6 +99,6 @@ # endif #endif -#endif /* WIN32 */ +#endif /* _WIN32 */ #endif /* LIBSSH2_SETUP_H */ diff --git a/libs/libssh2/src/mac.c b/libs/libssh2/src/mac.c index db6f57a44e..03ecd329ee 100644 --- a/libs/libssh2/src/mac.c +++ b/libs/libssh2/src/mac.c @@ -124,23 +124,27 @@ mac_method_hmac_sha2_512_hash(LIBSSH2_SESSION * session, { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; + int res; (void)session; _libssh2_htonu32(seqno_buf, seqno); - libssh2_hmac_ctx_init(ctx); - libssh2_hmac_sha512_init(&ctx, *abstract, 64); - libssh2_hmac_update(ctx, seqno_buf, 4); - libssh2_hmac_update(ctx, packet, packet_len); - if(addtl && addtl_len) { - libssh2_hmac_update(ctx, addtl, addtl_len); - } - libssh2_hmac_final(ctx, buf); - libssh2_hmac_cleanup(&ctx); - - return 0; + if(!_libssh2_hmac_ctx_init(&ctx)) + return 1; + res = _libssh2_hmac_sha512_init(&ctx, *abstract, 64) && + _libssh2_hmac_update(&ctx, seqno_buf, 4) && + _libssh2_hmac_update(&ctx, packet, packet_len); + if(res && addtl && addtl_len) + res = _libssh2_hmac_update(&ctx, addtl, addtl_len); + if(res) + res = _libssh2_hmac_final(&ctx, buf); + _libssh2_hmac_cleanup(&ctx); + + return !res; } + + static const LIBSSH2_MAC_METHOD mac_method_hmac_sha2_512 = { "hmac-sha2-512", 64, @@ -179,21 +183,23 @@ mac_method_hmac_sha2_256_hash(LIBSSH2_SESSION * session, { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; + int res; (void)session; _libssh2_htonu32(seqno_buf, seqno); - libssh2_hmac_ctx_init(ctx); - libssh2_hmac_sha256_init(&ctx, *abstract, 32); - libssh2_hmac_update(ctx, seqno_buf, 4); - libssh2_hmac_update(ctx, packet, packet_len); - if(addtl && addtl_len) { - libssh2_hmac_update(ctx, addtl, addtl_len); - } - libssh2_hmac_final(ctx, buf); - libssh2_hmac_cleanup(&ctx); - - return 0; + if(!_libssh2_hmac_ctx_init(&ctx)) + return 1; + res = _libssh2_hmac_sha256_init(&ctx, *abstract, 32) && + _libssh2_hmac_update(&ctx, seqno_buf, 4) && + _libssh2_hmac_update(&ctx, packet, packet_len); + if(res && addtl && addtl_len) + res = _libssh2_hmac_update(&ctx, addtl, addtl_len); + if(res) + res = _libssh2_hmac_final(&ctx, buf); + _libssh2_hmac_cleanup(&ctx); + + return !res; } @@ -236,21 +242,23 @@ mac_method_hmac_sha1_hash(LIBSSH2_SESSION * session, { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; + int res; (void)session; _libssh2_htonu32(seqno_buf, seqno); - libssh2_hmac_ctx_init(ctx); - libssh2_hmac_sha1_init(&ctx, *abstract, 20); - libssh2_hmac_update(ctx, seqno_buf, 4); - libssh2_hmac_update(ctx, packet, packet_len); - if(addtl && addtl_len) { - libssh2_hmac_update(ctx, addtl, addtl_len); - } - libssh2_hmac_final(ctx, buf); - libssh2_hmac_cleanup(&ctx); - - return 0; + if(!_libssh2_hmac_ctx_init(&ctx)) + return 1; + res = _libssh2_hmac_sha1_init(&ctx, *abstract, 20) && + _libssh2_hmac_update(&ctx, seqno_buf, 4) && + _libssh2_hmac_update(&ctx, packet, packet_len); + if(res && addtl && addtl_len) + res = _libssh2_hmac_update(&ctx, addtl, addtl_len); + if(res) + res = _libssh2_hmac_final(&ctx, buf); + _libssh2_hmac_cleanup(&ctx); + + return !res; } @@ -288,10 +296,11 @@ mac_method_hmac_sha1_96_hash(LIBSSH2_SESSION * session, { unsigned char temp[SHA_DIGEST_LENGTH]; - mac_method_hmac_sha1_hash(session, temp, seqno, packet, packet_len, - addtl, addtl_len, abstract); - memcpy(buf, (char *) temp, 96 / 8); + if(mac_method_hmac_sha1_hash(session, temp, seqno, packet, packet_len, + addtl, addtl_len, abstract)) + return 1; + memcpy(buf, (char *) temp, 96 / 8); return 0; } @@ -321,21 +330,23 @@ mac_method_hmac_md5_hash(LIBSSH2_SESSION * session, unsigned char *buf, { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; + int res; (void)session; _libssh2_htonu32(seqno_buf, seqno); - libssh2_hmac_ctx_init(ctx); - libssh2_hmac_md5_init(&ctx, *abstract, 16); - libssh2_hmac_update(ctx, seqno_buf, 4); - libssh2_hmac_update(ctx, packet, packet_len); - if(addtl && addtl_len) { - libssh2_hmac_update(ctx, addtl, addtl_len); - } - libssh2_hmac_final(ctx, buf); - libssh2_hmac_cleanup(&ctx); - - return 0; + if(!_libssh2_hmac_ctx_init(&ctx)) + return 1; + res = _libssh2_hmac_md5_init(&ctx, *abstract, 16) && + _libssh2_hmac_update(&ctx, seqno_buf, 4) && + _libssh2_hmac_update(&ctx, packet, packet_len); + if(res && addtl && addtl_len) + res = _libssh2_hmac_update(&ctx, addtl, addtl_len); + if(res) + res = _libssh2_hmac_final(&ctx, buf); + _libssh2_hmac_cleanup(&ctx); + + return !res; } @@ -362,8 +373,11 @@ mac_method_hmac_md5_96_hash(LIBSSH2_SESSION * session, size_t addtl_len, void **abstract) { unsigned char temp[MD5_DIGEST_LENGTH]; - mac_method_hmac_md5_hash(session, temp, seqno, packet, packet_len, - addtl, addtl_len, abstract); + + if(mac_method_hmac_md5_hash(session, temp, seqno, packet, packet_len, + addtl, addtl_len, abstract)) + return 1; + memcpy(buf, (char *) temp, 96 / 8); return 0; } @@ -396,21 +410,23 @@ mac_method_hmac_ripemd160_hash(LIBSSH2_SESSION * session, { libssh2_hmac_ctx ctx; unsigned char seqno_buf[4]; + int res; (void)session; _libssh2_htonu32(seqno_buf, seqno); - libssh2_hmac_ctx_init(ctx); - libssh2_hmac_ripemd160_init(&ctx, *abstract, 20); - libssh2_hmac_update(ctx, seqno_buf, 4); - libssh2_hmac_update(ctx, packet, packet_len); - if(addtl && addtl_len) { - libssh2_hmac_update(ctx, addtl, addtl_len); - } - libssh2_hmac_final(ctx, buf); - libssh2_hmac_cleanup(&ctx); - - return 0; + if(!_libssh2_hmac_ctx_init(&ctx)) + return 1; + res = _libssh2_hmac_ripemd160_init(&ctx, *abstract, 20) && + _libssh2_hmac_update(&ctx, seqno_buf, 4) && + _libssh2_hmac_update(&ctx, packet, packet_len); + if(res && addtl && addtl_len) + res = _libssh2_hmac_update(&ctx, addtl, addtl_len); + if(res) + res = _libssh2_hmac_final(&ctx, buf); + _libssh2_hmac_cleanup(&ctx); + + return !res; } diff --git a/libs/libssh2/src/mac.h b/libs/libssh2/src/mac.h index 696f835aa6..8e5b8c280f 100644 --- a/libs/libssh2/src/mac.h +++ b/libs/libssh2/src/mac.h @@ -1,5 +1,5 @@ -#ifndef __LIBSSH2_MAC_H -#define __LIBSSH2_MAC_H +#ifndef LIBSSH2_MAC_H +#define LIBSSH2_MAC_H /* Copyright (C) Daniel Stenberg * All rights reserved. * @@ -69,4 +69,4 @@ const LIBSSH2_MAC_METHOD **_libssh2_mac_methods(void); const LIBSSH2_MAC_METHOD *_libssh2_mac_override( const LIBSSH2_CRYPT_METHOD *crypt); -#endif /* __LIBSSH2_MAC_H */ +#endif /* LIBSSH2_MAC_H */ diff --git a/libs/libssh2/src/misc.c b/libs/libssh2/src/misc.c index b386e3d667..0dee48f5f5 100644 --- a/libs/libssh2/src/misc.c +++ b/libs/libssh2/src/misc.c @@ -40,7 +40,6 @@ */ #include "libssh2_priv.h" -#include "misc.h" #ifdef HAVE_UNISTD_H #include <unistd.h> @@ -49,7 +48,7 @@ #include <errno.h> #include <assert.h> -#ifdef WIN32 +#ifdef _WIN32 /* Force parameter type. */ #define recv(s, b, l, f) recv((s), (b), (int)(l), (f)) #define send(s, b, l, f) send((s), (b), (int)(l), (f)) @@ -73,7 +72,14 @@ int _libssh2_snprintf(char *cp, size_t cp_max_len, const char *fmt, ...) if(cp_max_len < 2) return 0; va_start(args, fmt); +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wformat-nonliteral" +#endif n = vsnprintf(cp, cp_max_len, fmt, args); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif va_end(args); return (n < (int)cp_max_len) ? n : (int)(cp_max_len - 1); } @@ -126,8 +132,8 @@ int _libssh2_error(LIBSSH2_SESSION* session, int errcode, const char *errmsg) return _libssh2_error_flags(session, errcode, errmsg, 0); } -#ifdef WIN32 -static int wsa2errno(void) +#ifdef _WIN32 +int _libssh2_wsa2errno(void) { switch(WSAGetLastError()) { case WSAEWOULDBLOCK: @@ -161,23 +167,29 @@ _libssh2_recv(libssh2_socket_t sock, void *buffer, size_t length, (void)abstract; rc = recv(sock, buffer, length, flags); -#ifdef WIN32 - if(rc < 0) - return -wsa2errno(); -#else if(rc < 0) { + int err; +#ifdef _WIN32 + err = _libssh2_wsa2errno(); +#else + err = errno; +#endif + /* Profiling tools that use SIGPROF can cause EINTR responses. + recv() does not modify its arguments when it returns EINTR, + but there may be data waiting, so the caller should try again */ + if(err == EINTR) + return -EAGAIN; /* Sometimes the first recv() function call sets errno to ENOENT on Solaris and HP-UX */ - if(errno == ENOENT) + if(err == ENOENT) return -EAGAIN; #ifdef EWOULDBLOCK /* For VMS and other special unixes */ - else if(errno == EWOULDBLOCK) - return -EAGAIN; + else if(err == EWOULDBLOCK) + return -EAGAIN; #endif else - return -errno; + return -err; } -#endif return rc; } @@ -194,18 +206,24 @@ _libssh2_send(libssh2_socket_t sock, const void *buffer, size_t length, (void)abstract; rc = send(sock, buffer, length, flags); -#ifdef WIN32 - if(rc < 0) - return -wsa2errno(); -#else if(rc < 0) { + int err; +#ifdef _WIN32 + err = _libssh2_wsa2errno(); +#else + err = errno; +#endif + /* Profiling tools that use SIGPROF can cause EINTR responses. + send() is defined as not yet sending any data when it returns EINTR, + so the caller should try again */ + if(err == EINTR) + return -EAGAIN; #ifdef EWOULDBLOCK /* For VMS and other special unixes */ - if(errno == EWOULDBLOCK) + if(err == EWOULDBLOCK) return -EAGAIN; #endif - return -errno; + return -err; } -#endif return rc; } @@ -557,7 +575,14 @@ _libssh2_debug_low(LIBSSH2_SESSION * session, int context, const char *format, buflen -= len; msglen = len; va_start(vargs, format); +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wformat-nonliteral" +#endif len = vsnprintf(buffer + msglen, buflen, format, vargs); +#ifdef __clang__ +#pragma clang diagnostic pop +#endif va_end(vargs); msglen += len < buflen ? len : buflen - 1; } @@ -709,7 +734,7 @@ int _libssh2_gettimeofday(struct timeval *tp, void *tzp) { (void)tzp; if(tp) { -#ifdef WIN32 +#ifdef _WIN32 /* Offset between 1601-01-01 and 1970-01-01 in 100 nanosec units */ #define _WIN32_FT_OFFSET (116444736000000000) @@ -901,7 +926,6 @@ int _libssh2_copy_string(LIBSSH2_SESSION *session, struct string_buf *buf, } } else { - *outlen = 0; *outbuf = NULL; } diff --git a/libs/libssh2/src/misc.h b/libs/libssh2/src/misc.h index bf3e3c3623..c7b090f1b8 100644 --- a/libs/libssh2/src/misc.h +++ b/libs/libssh2/src/misc.h @@ -1,5 +1,5 @@ -#ifndef __LIBSSH2_MISC_H -#define __LIBSSH2_MISC_H +#ifndef LIBSSH2_MISC_H +#define LIBSSH2_MISC_H /* Copyright (C) Daniel Stenberg * All rights reserved. * @@ -44,8 +44,7 @@ (void)(buf); \ (void)(size); \ } while(0) -#else -#ifdef WIN32 +#elif defined(_WIN32) #define _libssh2_explicit_zero(buf, size) SecureZeroMemory(buf, size) #elif defined(HAVE_EXPLICIT_BZERO) #define _libssh2_explicit_zero(buf, size) explicit_bzero(buf, size) @@ -58,7 +57,6 @@ void _libssh2_memzero(void *buf, size_t size); #define _libssh2_explicit_zero(buf, size) _libssh2_memzero(buf, size) #endif -#endif struct list_head { struct list_node *last; @@ -81,6 +79,11 @@ int _libssh2_error_flags(LIBSSH2_SESSION* session, int errcode, const char *errmsg, int errflags); int _libssh2_error(LIBSSH2_SESSION* session, int errcode, const char *errmsg); +#ifdef _WIN32 +/* Convert Win32 WSAGetLastError to errno equivalent */ +int _libssh2_wsa2errno(void); +#endif + void _libssh2_list_init(struct list_head *head); /* add a node last in the list */ @@ -139,4 +142,4 @@ void _libssh2_xor_data(unsigned char *output, void _libssh2_aes_ctr_increment(unsigned char *ctr, size_t length); -#endif /* _LIBSSH2_MISC_H */ +#endif /* LIBSSH2_MISC_H */ diff --git a/libs/libssh2/src/openssl.c b/libs/libssh2/src/openssl.c index 2dc2340c3b..31220f9cc8 100644 --- a/libs/libssh2/src/openssl.c +++ b/libs/libssh2/src/openssl.c @@ -44,16 +44,161 @@ #include <stdlib.h> #include <assert.h> -#ifndef EVP_MAX_BLOCK_LENGTH -#define EVP_MAX_BLOCK_LENGTH 32 +int _libssh2_hmac_ctx_init(libssh2_hmac_ctx *ctx) +{ +#ifdef USE_OPENSSL_3 + *ctx = NULL; + return 1; +#elif defined(HAVE_OPAQUE_STRUCTS) + *ctx = HMAC_CTX_new(); + return *ctx ? 1 : 0; +#else + HMAC_CTX_init(ctx); + return 1; #endif +} -int -read_openssh_private_key_from_memory(void **key_ctx, LIBSSH2_SESSION *session, - const char *key_type, - const char *filedata, - size_t filedata_len, - unsigned const char *passphrase); +#ifdef USE_OPENSSL_3 +static int _libssh2_hmac_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen, + const char *digest_name) +{ + EVP_MAC* mac; + OSSL_PARAM params[3]; + + mac = EVP_MAC_fetch(NULL, OSSL_MAC_NAME_HMAC, NULL); + if(!mac) + return 0; + + *ctx = EVP_MAC_CTX_new(mac); + EVP_MAC_free(mac); + if(!*ctx) + return 0; + + params[0] = OSSL_PARAM_construct_octet_string( + OSSL_MAC_PARAM_KEY, (void *)key, keylen); + params[1] = OSSL_PARAM_construct_utf8_string( + OSSL_MAC_PARAM_DIGEST, (char *)digest_name, 0); + params[2] = OSSL_PARAM_construct_end(); + + return EVP_MAC_init(*ctx, NULL, 0, params); +} +#endif + +#if LIBSSH2_MD5 +int _libssh2_hmac_md5_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen) +{ +#ifdef USE_OPENSSL_3 + return _libssh2_hmac_init(ctx, key, keylen, OSSL_DIGEST_NAME_MD5); +#elif defined(HAVE_OPAQUE_STRUCTS) + return HMAC_Init_ex(*ctx, key, (int)keylen, EVP_md5(), NULL); +#else + return HMAC_Init_ex(ctx, key, (int)keylen, EVP_md5(), NULL); +#endif +} +#endif + +#if LIBSSH2_HMAC_RIPEMD +int _libssh2_hmac_ripemd160_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen) +{ +#ifdef USE_OPENSSL_3 + return _libssh2_hmac_init(ctx, key, keylen, OSSL_DIGEST_NAME_RIPEMD160); +#elif defined(HAVE_OPAQUE_STRUCTS) + return HMAC_Init_ex(*ctx, key, (int)keylen, EVP_ripemd160(), NULL); +#else + return HMAC_Init_ex(ctx, key, (int)keylen, EVP_ripemd160(), NULL); +#endif +} +#endif + +int _libssh2_hmac_sha1_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen) +{ +#ifdef USE_OPENSSL_3 + return _libssh2_hmac_init(ctx, key, keylen, OSSL_DIGEST_NAME_SHA1); +#elif defined(HAVE_OPAQUE_STRUCTS) + return HMAC_Init_ex(*ctx, key, (int)keylen, EVP_sha1(), NULL); +#else + return HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha1(), NULL); +#endif +} + +int _libssh2_hmac_sha256_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen) +{ +#ifdef USE_OPENSSL_3 + return _libssh2_hmac_init(ctx, key, keylen, OSSL_DIGEST_NAME_SHA2_256); +#elif defined(HAVE_OPAQUE_STRUCTS) + return HMAC_Init_ex(*ctx, key, (int)keylen, EVP_sha256(), NULL); +#else + return HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha256(), NULL); +#endif +} + +int _libssh2_hmac_sha512_init(libssh2_hmac_ctx *ctx, + void *key, size_t keylen) +{ +#ifdef USE_OPENSSL_3 + return _libssh2_hmac_init(ctx, key, keylen, OSSL_DIGEST_NAME_SHA2_512); +#elif defined(HAVE_OPAQUE_STRUCTS) + return HMAC_Init_ex(*ctx, key, (int)keylen, EVP_sha512(), NULL); +#else + return HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha512(), NULL); +#endif +} + +int _libssh2_hmac_update(libssh2_hmac_ctx *ctx, + const void *data, size_t datalen) +{ +#ifdef USE_OPENSSL_3 + return EVP_MAC_update(*ctx, data, datalen); +#elif defined(HAVE_OPAQUE_STRUCTS) +/* FIXME: upstream bug as of v5.6.0: datalen is int instead of size_t */ +#if defined(LIBSSH2_WOLFSSL) + return HMAC_Update(*ctx, data, (int)datalen); +#else /* !LIBSSH2_WOLFSSL */ + return HMAC_Update(*ctx, data, datalen); +#endif /* LIBSSH2_WOLFSSL */ +#else + return HMAC_Update(ctx, data, datalen); +#endif +} + +int _libssh2_hmac_final(libssh2_hmac_ctx *ctx, void *data) +{ +#ifdef USE_OPENSSL_3 + return EVP_MAC_final(*ctx, data, NULL, MAX_MACSIZE); +#elif defined(HAVE_OPAQUE_STRUCTS) + return HMAC_Final(*ctx, data, NULL); +#else + return HMAC_Final(ctx, data, NULL); +#endif +} + +void _libssh2_hmac_cleanup(libssh2_hmac_ctx *ctx) +{ +#ifdef USE_OPENSSL_3 + EVP_MAC_CTX_free(*ctx); +#elif defined(HAVE_OPAQUE_STRUCTS) + HMAC_CTX_free(*ctx); +#else + HMAC_cleanup(ctx); +#endif +} + +static int +_libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, + void **key_ctx, + const char *key_type, + unsigned char **method, + size_t *method_len, + unsigned char **pubkeydata, + size_t *pubkeydata_len, + const char *privatekeydata, + size_t privatekeydata_len, + unsigned const char *passphrase); static int _libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session, @@ -92,6 +237,20 @@ write_bn(unsigned char *buf, const BIGNUM *bn, int bn_bytes) } #endif +static inline void +_libssh2_swap_bytes(unsigned char *buf, unsigned long len) +{ +#if !defined(WORDS_BIGENDIAN) || !WORDS_BIGENDIAN + unsigned long i, j; + unsigned char temp; + for(i = 0, j = len - 1; i < j; i++, j--) { + temp = buf[i]; + buf[i] = buf[j]; + buf[j] = temp; + } +#endif +} + int _libssh2_openssl_random(void *buf, size_t len) { @@ -121,6 +280,76 @@ _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, unsigned long e2len, const unsigned char *coeffdata, unsigned long coefflen) { +#ifdef USE_OPENSSL_3 + int ret = 0; + EVP_PKEY_CTX *ctx; + OSSL_PARAM params[4]; + int param_num = 0; + unsigned char *nbuf = NULL; + unsigned char *ebuf = NULL; + unsigned char *dbuf = NULL; + + (void)pdata; + (void)plen; + (void)qdata; + (void)qlen; + (void)e1data; + (void)e1len; + (void)e2data; + (void)e2len; + (void)coeffdata; + (void)coefflen; + + if(ndata && nlen > 0) { + nbuf = OPENSSL_malloc(nlen); + + if(nbuf) { + memcpy(nbuf, ndata, nlen); + _libssh2_swap_bytes(nbuf, nlen); + params[param_num++] = + OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_RSA_N, nbuf, nlen); + } + } + + if(edata && elen > 0) { + ebuf = OPENSSL_malloc(elen); + if(ebuf) { + memcpy(ebuf, edata, elen); + _libssh2_swap_bytes(ebuf, elen); + params[param_num++] = + OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_RSA_E, ebuf, elen); + } + } + + if(ddata && dlen > 0) { + dbuf = OPENSSL_malloc(dlen); + if(dbuf) { + memcpy(dbuf, ddata, dlen); + _libssh2_swap_bytes(dbuf, dlen); + params[param_num++] = + OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_RSA_D, dbuf, dlen); + } + } + + params[param_num] = OSSL_PARAM_construct_end(); + + *rsa = NULL; + ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL); + + if(EVP_PKEY_fromdata_init(ctx) > 0) { + ret = EVP_PKEY_fromdata(ctx, rsa, EVP_PKEY_KEYPAIR, params); + } + if(nbuf) + OPENSSL_clear_free(nbuf, nlen); + + if(ebuf) + OPENSSL_clear_free(ebuf, elen); + + if(dbuf) + OPENSSL_clear_free(dbuf, dlen); + + return (ret == 1) ? 0 : -1; +#else BIGNUM * e; BIGNUM * n; BIGNUM * d = 0; @@ -180,6 +409,8 @@ _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, (*rsa)->iqmp = iqmp; #endif return 0; + +#endif /* USE_OPENSSL_3 */ } int @@ -189,6 +420,11 @@ _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, size_t sig_len, const unsigned char *m, size_t m_len) { +#ifdef USE_OPENSSL_3 + EVP_PKEY_CTX *ctx = NULL; + const EVP_MD *md = NULL; +#endif + int ret; int nid_type; unsigned char *hash = malloc(hash_len); @@ -202,7 +438,6 @@ _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, else if(hash_len == SHA256_DIGEST_LENGTH) { nid_type = NID_sha256; ret = _libssh2_sha256(m, m_len, hash); - } else if(hash_len == SHA512_DIGEST_LENGTH) { nid_type = NID_sha512; @@ -222,9 +457,37 @@ _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, return -1; /* failure */ } +#ifdef USE_OPENSSL_3 + ctx = EVP_PKEY_CTX_new(rsactx, NULL); + + if(nid_type == NID_sha1) { + md = EVP_sha1(); + } + else if(nid_type == NID_sha256) { + md = EVP_sha256(); + } + else if(nid_type == NID_sha512) { + md = EVP_sha512(); + } + + if(ctx && md) { + if(EVP_PKEY_verify_init(ctx) > 0 && + EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) > 0 && + EVP_PKEY_CTX_set_signature_md(ctx, md) > 0) { + ret = EVP_PKEY_verify(ctx, sig, sig_len, hash, hash_len); + } + } + + if(ctx) { + EVP_PKEY_CTX_free(ctx); + } + +#else + ret = RSA_verify(nid_type, hash, (unsigned int) hash_len, (unsigned char *) sig, (unsigned int) sig_len, rsactx); +#endif free(hash); @@ -257,6 +520,97 @@ _libssh2_dsa_new(libssh2_dsa_ctx ** dsactx, unsigned long y_len, const unsigned char *x, unsigned long x_len) { +#ifdef USE_OPENSSL_3 + int ret = 0; + EVP_PKEY_CTX *ctx = NULL; + OSSL_PARAM params[6]; + int param_num = 0; + unsigned char *p_buf = NULL; + unsigned char *q_buf = NULL; + unsigned char *g_buf = NULL; + unsigned char *y_buf = NULL; + unsigned char *x_buf = NULL; + + if(p && p_len > 0) { + p_buf = OPENSSL_malloc(p_len); + + if(p_buf) { + memcpy(p_buf, p, p_len); + _libssh2_swap_bytes(p_buf, p_len); + params[param_num++] = + OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_FFC_P, p_buf, p_len); + } + } + + if(q && q_len > 0) { + q_buf = OPENSSL_malloc(q_len); + + if(q_buf) { + memcpy(q_buf, q, q_len); + _libssh2_swap_bytes(q_buf, q_len); + params[param_num++] = + OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_FFC_Q, q_buf, q_len); + } + } + + if(g && g_len > 0) { + g_buf = OPENSSL_malloc(g_len); + + if(g_buf) { + memcpy(g_buf, g, g_len); + _libssh2_swap_bytes(g_buf, g_len); + params[param_num++] = + OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_FFC_G, g_buf, g_len); + } + } + + if(y && y_len > 0) { + y_buf = OPENSSL_malloc(y_len); + + if(y_buf) { + memcpy(y_buf, y, y_len); + _libssh2_swap_bytes(y_buf, y_len); + params[param_num++] = + OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_PUB_KEY, y_buf, y_len); + } + } + + if(x && x_len > 0) { + x_buf = OPENSSL_malloc(x_len); + + if(x_buf) { + memcpy(x_buf, x, x_len); + _libssh2_swap_bytes(x_buf, x_len); + params[param_num++] = + OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_PRIV_KEY, + x_buf, x_len); + } + } + + params[param_num] = OSSL_PARAM_construct_end(); + + *dsactx = NULL; + ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_DSA, NULL); + + if(EVP_PKEY_fromdata_init(ctx) > 0) { + ret = EVP_PKEY_fromdata(ctx, dsactx, EVP_PKEY_KEYPAIR, params); + } + + if(p_buf) + OPENSSL_clear_free(p_buf, p_len); + if(q_buf) + OPENSSL_clear_free(q_buf, q_len); + if(g_buf) + OPENSSL_clear_free(g_buf, g_len); + if(x_buf) + OPENSSL_clear_free(x_buf, x_len); + if(y_buf) + OPENSSL_clear_free(y_buf, y_len); + + return (ret == 1) ? 0 : -1; + +#else + BIGNUM * p_bn; BIGNUM * q_bn; BIGNUM * g_bn; @@ -297,6 +651,8 @@ _libssh2_dsa_new(libssh2_dsa_ctx ** dsactx, (*dsactx)->priv_key = priv_key; #endif return 0; + +#endif /* USE_OPENSSL_3 */ } int @@ -304,6 +660,12 @@ _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx, const unsigned char *sig, const unsigned char *m, size_t m_len) { +#ifdef USE_OPENSSL_3 + EVP_PKEY_CTX *ctx = NULL; + unsigned char *der = NULL; + int der_len = 0; +#endif + unsigned char hash[SHA_DIGEST_LENGTH]; DSA_SIG * dsasig; BIGNUM * r; @@ -322,9 +684,30 @@ _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx, dsasig->r = r; dsasig->s = s; #endif + +#ifdef USE_OPENSSL_3 + ctx = EVP_PKEY_CTX_new(dsactx, NULL); + der_len = i2d_DSA_SIG(dsasig, &der); + + if(ctx && !_libssh2_sha1(m, m_len, hash)) { + /* _libssh2_sha1() succeeded */ + if(EVP_PKEY_verify_init(ctx) > 0) { + ret = EVP_PKEY_verify(ctx, der, der_len, hash, SHA_DIGEST_LENGTH); + } + } + + if(ctx) { + EVP_PKEY_CTX_free(ctx); + } + + if(der) { + OPENSSL_clear_free(der, der_len); + } +#else if(!_libssh2_sha1(m, m_len, hash)) /* _libssh2_sha1() succeeded */ ret = DSA_do_verify(hash, SHA_DIGEST_LENGTH, dsasig, dsactx); +#endif DSA_SIG_free(dsasig); @@ -343,8 +726,25 @@ _libssh2_dsa_sha1_verify(libssh2_dsa_ctx * dsactx, libssh2_curve_type _libssh2_ecdsa_get_curve_type(libssh2_ecdsa_ctx *ec_ctx) { +#ifdef USE_OPENSSL_3 + int bits = 0; + EVP_PKEY_get_int_param(ec_ctx, OSSL_PKEY_PARAM_BITS, &bits); + + if(bits == 256) { + return LIBSSH2_EC_CURVE_NISTP256; + } + else if(bits == 384) { + return LIBSSH2_EC_CURVE_NISTP384; + } + else if(bits == 521) { + return LIBSSH2_EC_CURVE_NISTP521; + } + + return LIBSSH2_EC_CURVE_NISTP256; +#else const EC_GROUP *group = EC_KEY_get0_group(ec_ctx); return EC_GROUP_get_curve_name(group); +#endif } /* _libssh2_ecdsa_curve_type_from_name @@ -390,13 +790,56 @@ _libssh2_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx ** ec_ctx, const unsigned char *k, size_t k_len, libssh2_curve_type curve) { - int ret = 0; - const EC_GROUP *ec_group = NULL; + +#ifdef USE_OPENSSL_3 + EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL); + const char *n = EC_curve_nid2nist(curve); + char *group_name = NULL; + unsigned char *data = NULL; + + if(n) { + group_name = OPENSSL_zalloc(strlen(n) + 1); + } + + if(k_len > 0) { + data = OPENSSL_malloc(k_len); + } + + if(group_name && data) { + OSSL_PARAM params[3] = { 0 }; + + memcpy(group_name, n, strlen(n)); + memcpy(data, k, k_len); + + params[0] = + OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME, + group_name, 0); + + params[1] = + OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_PUB_KEY, + data, k_len); + + params[2] = OSSL_PARAM_construct_end(); + + if(EVP_PKEY_fromdata_init(ctx) > 0) { + ret = EVP_PKEY_fromdata(ctx, ec_ctx, EVP_PKEY_PUBLIC_KEY, + params); + } + + if(group_name) + OPENSSL_clear_free(group_name, strlen(n)); + + if(data) + OPENSSL_clear_free(data, k_len); + } +#else EC_KEY *ec_key = EC_KEY_new_by_curve_name(curve); - EC_POINT *point = NULL; if(ec_key) { + const EC_GROUP *ec_group = NULL; + EC_POINT *point = NULL; + ec_group = EC_KEY_get0_group(ec_key); point = EC_POINT_new(ec_group); ret = EC_POINT_oct2point(ec_group, point, k, k_len, NULL); @@ -408,27 +851,51 @@ _libssh2_ecdsa_curve_name_with_octal_new(libssh2_ecdsa_ctx ** ec_ctx, if(ec_ctx) *ec_ctx = ec_key; } +#endif return (ret == 1) ? 0 : -1; } +#ifdef USE_OPENSSL_3 #define LIBSSH2_ECDSA_VERIFY(digest_type) \ do { \ unsigned char hash[SHA##digest_type##_DIGEST_LENGTH]; \ - libssh2_sha##digest_type(m, m_len, hash); \ - ret = ECDSA_do_verify(hash, SHA##digest_type##_DIGEST_LENGTH, \ - ecdsa_sig, ec_key); \ + if(libssh2_sha##digest_type(m, m_len, hash) == 0) { \ + ret = EVP_PKEY_verify_init(ctx); \ + if(ret > 0) { \ + ret = EVP_PKEY_verify(ctx, der, der_len, hash, \ + SHA##digest_type##_DIGEST_LENGTH); \ + } \ + } \ } while(0) +#else +#define LIBSSH2_ECDSA_VERIFY(digest_type) \ + do { \ + unsigned char hash[SHA##digest_type##_DIGEST_LENGTH]; \ + if(libssh2_sha##digest_type(m, m_len, hash) == 0) { \ + ret = ECDSA_do_verify(hash, \ + SHA##digest_type##_DIGEST_LENGTH, \ + ecdsa_sig, ec_key); \ + } \ + } while(0) +#endif int -_libssh2_ecdsa_verify(libssh2_ecdsa_ctx * ctx, +_libssh2_ecdsa_verify(libssh2_ecdsa_ctx * ecdsa_ctx, const unsigned char *r, size_t r_len, const unsigned char *s, size_t s_len, const unsigned char *m, size_t m_len) { int ret = 0; - EC_KEY *ec_key = (EC_KEY*)ctx; - libssh2_curve_type type = _libssh2_ecdsa_get_curve_type(ec_key); + libssh2_curve_type type = _libssh2_ecdsa_get_curve_type(ecdsa_ctx); + +#ifdef USE_OPENSSL_3 + EVP_PKEY_CTX *ctx = NULL; + unsigned char *der = NULL; + int der_len = 0; +#else + EC_KEY *ec_key = (EC_KEY*)ecdsa_ctx; +#endif #ifdef HAVE_OPAQUE_STRUCTS ECDSA_SIG *ecdsa_sig = ECDSA_SIG_new(); @@ -438,7 +905,6 @@ _libssh2_ecdsa_verify(libssh2_ecdsa_ctx * ctx, BN_bin2bn(r, (int) r_len, pr); BN_bin2bn(s, (int) s_len, ps); ECDSA_SIG_set0(ecdsa_sig, pr, ps); - #else ECDSA_SIG ecdsa_sig_; ECDSA_SIG *ecdsa_sig = &ecdsa_sig_; @@ -448,6 +914,11 @@ _libssh2_ecdsa_verify(libssh2_ecdsa_ctx * ctx, BN_bin2bn(s, (int) s_len, ecdsa_sig_.s); #endif +#ifdef USE_OPENSSL_3 + ctx = EVP_PKEY_CTX_new(ecdsa_ctx, NULL); + der_len = i2d_ECDSA_SIG(ecdsa_sig, &der); +#endif + if(type == LIBSSH2_EC_CURVE_NISTP256) { LIBSSH2_ECDSA_VERIFY(256); } @@ -502,6 +973,10 @@ _libssh2_cipher_init(_libssh2_cipher_ctx * h, #endif } +#ifndef EVP_MAX_BLOCK_LENGTH +#define EVP_MAX_BLOCK_LENGTH 32 +#endif + int _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, _libssh2_cipher_type(algo), @@ -568,8 +1043,7 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, #endif } -#if (defined(OPENSSL_VERSION_MAJOR) && OPENSSL_VERSION_MAJOR >= 3) || \ - defined(LIBSSH2_WOLFSSL) +#if defined(USE_OPENSSL_3) || defined(LIBSSH2_WOLFSSL) if(ret != -1) #else if(ret >= 1) @@ -617,13 +1091,8 @@ _libssh2_cipher_crypt(_libssh2_cipher_ctx * ctx, void _libssh2_openssl_crypto_init(void) { -#if OPENSSL_VERSION_NUMBER >= 0x10100000L && \ - !defined(LIBRESSL_VERSION_NUMBER) -#ifndef OPENSSL_NO_ENGINE - ENGINE_load_builtin_engines(); - ENGINE_register_all_complete(); -#endif -#else +#if OPENSSL_VERSION_NUMBER < 0x10100000L || \ + (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x2070000fL) OpenSSL_add_all_algorithms(); OpenSSL_add_all_ciphers(); OpenSSL_add_all_digests(); @@ -632,6 +1101,9 @@ void _libssh2_openssl_crypto_init(void) ENGINE_register_all_complete(); #endif #endif +#if defined(LIBSSH2_WOLFSSL) && defined(DEBUG_WOLFSSL) + wolfSSL_Debugging_ON(); +#endif } void _libssh2_openssl_crypto_exit(void) @@ -717,43 +1189,69 @@ read_private_key_from_file(void **key_ctx, int _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx ** rsa, LIBSSH2_SESSION * session, - const char *filedata, size_t filedata_len, + const char *filedata, + size_t filedata_len, unsigned const char *passphrase) { int rc; +#if defined(USE_OPENSSL_3) + pem_read_bio_func read_rsa = + (pem_read_bio_func) &PEM_read_bio_PrivateKey; +#else pem_read_bio_func read_rsa = (pem_read_bio_func) &PEM_read_bio_RSAPrivateKey; +#endif _libssh2_init_if_needed(); - rc = read_private_key_from_memory((void **) rsa, read_rsa, - filedata, filedata_len, passphrase); + rc = read_private_key_from_memory((void **)rsa, read_rsa, + filedata, filedata_len, + passphrase); if(rc) { - rc = read_openssh_private_key_from_memory((void **)rsa, session, - "ssh-rsa", filedata, filedata_len, passphrase); + rc = _libssh2_pub_priv_openssh_keyfilememory(session, (void **)rsa, + "ssh-rsa", + NULL, NULL, NULL, NULL, + filedata, filedata_len, + passphrase); } return rc; } static unsigned char * -gen_publickey_from_rsa(LIBSSH2_SESSION *session, RSA *rsa, +gen_publickey_from_rsa(LIBSSH2_SESSION *session, libssh2_rsa_ctx *rsa, size_t *key_len) { int e_bytes, n_bytes; unsigned long len; unsigned char *key; unsigned char *p; + +#ifdef USE_OPENSSL_3 + BIGNUM * e = NULL; + BIGNUM * n = NULL; + + EVP_PKEY_get_bn_param(rsa, OSSL_PKEY_PARAM_RSA_E, &e); + EVP_PKEY_get_bn_param(rsa, OSSL_PKEY_PARAM_RSA_N, &n); +#else const BIGNUM * e; const BIGNUM * n; -#ifdef HAVE_OPAQUE_STRUCTS +#if defined(HAVE_OPAQUE_STRUCTS) + e = NULL; + n = NULL; + RSA_get0_key(rsa, &n, &e, NULL); #else e = rsa->e; n = rsa->n; #endif +#endif + if(!e || !n) { + return NULL; + } + e_bytes = BN_num_bytes(e) + 1; n_bytes = BN_num_bytes(n) + 1; @@ -788,7 +1286,7 @@ gen_publickey_from_rsa_evp(LIBSSH2_SESSION *session, size_t *pubkeydata_len, EVP_PKEY *pk) { - RSA* rsa = NULL; + libssh2_rsa_ctx* rsa = NULL; unsigned char *key; unsigned char *method_buf = NULL; size_t key_len; @@ -797,7 +1295,11 @@ gen_publickey_from_rsa_evp(LIBSSH2_SESSION *session, LIBSSH2_TRACE_AUTH, "Computing public key from RSA private key envelope")); +#ifdef USE_OPENSSL_3 + rsa = pk; +#else rsa = EVP_PKEY_get1_RSA(pk); +#endif if(!rsa) { /* Assume memory allocation error... what else could it be ? */ goto __alloc_error; @@ -812,19 +1314,27 @@ gen_publickey_from_rsa_evp(LIBSSH2_SESSION *session, if(!key) { goto __alloc_error; } +#ifndef USE_OPENSSL_3 RSA_free(rsa); +#endif memcpy(method_buf, "ssh-rsa", 7); - *method = method_buf; - *method_len = 7; - *pubkeydata = key; - *pubkeydata_len = key_len; + *method = method_buf; + if(method_len) { + *method_len = 7; + } + *pubkeydata = key; + if(pubkeydata_len) { + *pubkeydata_len = key_len; + } return 0; __alloc_error: +#ifndef USE_OPENSSL_3 if(rsa) { RSA_free(rsa); } +#endif if(method_buf) { LIBSSH2_FREE(session, method_buf); } @@ -834,7 +1344,8 @@ __alloc_error: "Unable to allocate memory for private key data"); } -static int _libssh2_rsa_new_additional_parameters(RSA *rsa) +#ifndef USE_OPENSSL_3 +static int _libssh2_rsa_new_additional_parameters(libssh2_rsa_ctx *rsa) { BN_CTX *ctx = NULL; BIGNUM *aux = NULL; @@ -905,6 +1416,7 @@ out: return rc; } +#endif /* ndef USE_OPENSSL_3 */ static int gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session, @@ -918,7 +1430,7 @@ gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session, int rc = 0; size_t nlen, elen, dlen, plen, qlen, coefflen, commentlen; unsigned char *n, *e, *d, *p, *q, *coeff, *comment; - RSA *rsa = NULL; + libssh2_rsa_ctx *rsa = NULL; _libssh2_debug((session, LIBSSH2_TRACE_AUTH, @@ -983,32 +1495,40 @@ gen_publickey_from_rsa_openssh_priv_data(LIBSSH2_SESSION *session, goto fail; } +#ifndef USE_OPENSSL_3 if(rsa) rc = _libssh2_rsa_new_additional_parameters(rsa); +#endif if(rsa && pubkeydata && method) { +#ifdef USE_OPENSSL_3 + EVP_PKEY *pk = rsa; +#else EVP_PKEY *pk = EVP_PKEY_new(); EVP_PKEY_set1_RSA(pk, rsa); +#endif rc = gen_publickey_from_rsa_evp(session, method, method_len, pubkeydata, pubkeydata_len, pk); +#ifndef USE_OPENSSL_3 if(pk) EVP_PKEY_free(pk); +#endif } if(rsa_ctx) *rsa_ctx = rsa; else - RSA_free(rsa); + _libssh2_rsa_free(rsa); return rc; fail: if(rsa) - RSA_free(rsa); + _libssh2_rsa_free(rsa); return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, @@ -1058,8 +1578,8 @@ _libssh2_rsa_new_openssh_private(libssh2_rsa_ctx ** rsa, if(strcmp("ssh-rsa", (const char *)buf) == 0) { rc = gen_publickey_from_rsa_openssh_priv_data(session, decrypted, - NULL, 0, - NULL, 0, rsa); + NULL, NULL, + NULL, NULL, rsa); } else { rc = -1; @@ -1078,8 +1598,13 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa, { int rc; +#if defined(USE_OPENSSL_3) + pem_read_bio_func read_rsa = + (pem_read_bio_func) &PEM_read_bio_PrivateKey; +#else pem_read_bio_func read_rsa = (pem_read_bio_func) &PEM_read_bio_RSAPrivateKey; +#endif _libssh2_init_if_needed(); @@ -1099,13 +1624,19 @@ _libssh2_rsa_new_private(libssh2_rsa_ctx ** rsa, int _libssh2_dsa_new_private_frommemory(libssh2_dsa_ctx ** dsa, LIBSSH2_SESSION * session, - const char *filedata, size_t filedata_len, + const char *filedata, + size_t filedata_len, unsigned const char *passphrase) { int rc; +#if defined(USE_OPENSSL_3) + pem_read_bio_func read_dsa = + (pem_read_bio_func) &PEM_read_bio_PrivateKey; +#else pem_read_bio_func read_dsa = (pem_read_bio_func) &PEM_read_bio_DSAPrivateKey; +#endif _libssh2_init_if_needed(); @@ -1114,17 +1645,18 @@ _libssh2_dsa_new_private_frommemory(libssh2_dsa_ctx ** dsa, passphrase); if(rc) { - rc = read_openssh_private_key_from_memory((void **)dsa, session, - "ssh-dsa", - filedata, filedata_len, - passphrase); + rc = _libssh2_pub_priv_openssh_keyfilememory(session, (void **)dsa, + "ssh-dsa", + NULL, NULL, NULL, NULL, + filedata, filedata_len, + passphrase); } return rc; } static unsigned char * -gen_publickey_from_dsa(LIBSSH2_SESSION* session, DSA *dsa, +gen_publickey_from_dsa(LIBSSH2_SESSION* session, libssh2_dsa_ctx *dsa, size_t *key_len) { int p_bytes, q_bytes, g_bytes, k_bytes; @@ -1132,6 +1664,17 @@ gen_publickey_from_dsa(LIBSSH2_SESSION* session, DSA *dsa, unsigned char *key; unsigned char *p; +#ifdef USE_OPENSSL_3 + BIGNUM * p_bn; + BIGNUM * q; + BIGNUM * g; + BIGNUM * pub_key; + + EVP_PKEY_get_bn_param(dsa, OSSL_PKEY_PARAM_FFC_P, &p_bn); + EVP_PKEY_get_bn_param(dsa, OSSL_PKEY_PARAM_FFC_G, &q); + EVP_PKEY_get_bn_param(dsa, OSSL_PKEY_PARAM_FFC_Q, &g); + EVP_PKEY_get_bn_param(dsa, OSSL_PKEY_PARAM_PUB_KEY, &pub_key); +#else const BIGNUM * p_bn; const BIGNUM * q; const BIGNUM * g; @@ -1149,6 +1692,7 @@ gen_publickey_from_dsa(LIBSSH2_SESSION* session, DSA *dsa, #else pub_key = dsa->pub_key; #endif +#endif p_bytes = BN_num_bytes(p_bn) + 1; q_bytes = BN_num_bytes(q) + 1; g_bytes = BN_num_bytes(g) + 1; @@ -1187,7 +1731,7 @@ gen_publickey_from_dsa_evp(LIBSSH2_SESSION *session, size_t *pubkeydata_len, EVP_PKEY *pk) { - DSA* dsa = NULL; + libssh2_dsa_ctx *dsa = NULL; unsigned char *key; unsigned char *method_buf = NULL; size_t key_len; @@ -1196,7 +1740,11 @@ gen_publickey_from_dsa_evp(LIBSSH2_SESSION *session, LIBSSH2_TRACE_AUTH, "Computing public key from DSA private key envelope")); +#ifdef USE_OPENSSL_3 + dsa = pk; +#else dsa = EVP_PKEY_get1_DSA(pk); +#endif if(!dsa) { /* Assume memory allocation error... what else could it be ? */ goto __alloc_error; @@ -1211,19 +1759,27 @@ gen_publickey_from_dsa_evp(LIBSSH2_SESSION *session, if(!key) { goto __alloc_error; } +#ifndef USE_OPENSSL_3 DSA_free(dsa); +#endif memcpy(method_buf, "ssh-dss", 7); - *method = method_buf; - *method_len = 7; - *pubkeydata = key; - *pubkeydata_len = key_len; + *method = method_buf; + if(method_len) { + *method_len = 7; + } + *pubkeydata = key; + if(pubkeydata_len) { + *pubkeydata_len = key_len; + } return 0; __alloc_error: +#ifndef USE_OPENSSL_3 if(dsa) { DSA_free(dsa); } +#endif if(method_buf) { LIBSSH2_FREE(session, method_buf); } @@ -1245,7 +1801,7 @@ gen_publickey_from_dsa_openssh_priv_data(LIBSSH2_SESSION *session, int rc = 0; size_t plen, qlen, glen, pub_len, priv_len; unsigned char *p, *q, *g, *pub_key, *priv_key; - DSA *dsa = NULL; + libssh2_dsa_ctx *dsa = NULL; _libssh2_debug((session, LIBSSH2_TRACE_AUTH, @@ -1295,28 +1851,34 @@ gen_publickey_from_dsa_openssh_priv_data(LIBSSH2_SESSION *session, } if(dsa && pubkeydata && method) { +#ifdef USE_OPENSSL_3 + EVP_PKEY *pk = dsa; +#else EVP_PKEY *pk = EVP_PKEY_new(); EVP_PKEY_set1_DSA(pk, dsa); +#endif rc = gen_publickey_from_dsa_evp(session, method, method_len, pubkeydata, pubkeydata_len, pk); +#ifndef USE_OPENSSL_3 if(pk) EVP_PKEY_free(pk); +#endif } if(dsa_ctx) *dsa_ctx = dsa; else - DSA_free(dsa); + _libssh2_dsa_free(dsa); return rc; fail: if(dsa) - DSA_free(dsa); + _libssh2_dsa_free(dsa); return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, @@ -1366,8 +1928,8 @@ _libssh2_dsa_new_openssh_private(libssh2_dsa_ctx ** dsa, if(strcmp("ssh-dss", (const char *)buf) == 0) { rc = gen_publickey_from_dsa_openssh_priv_data(session, decrypted, - NULL, 0, - NULL, 0, dsa); + NULL, NULL, + NULL, NULL, dsa); } else { rc = -1; @@ -1386,8 +1948,13 @@ _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa, { int rc; +#if defined(USE_OPENSSL_3) + pem_read_bio_func read_dsa = + (pem_read_bio_func) &PEM_read_bio_PrivateKey; +#else pem_read_bio_func read_dsa = (pem_read_bio_func) &PEM_read_bio_DSAPrivateKey; +#endif _libssh2_init_if_needed(); @@ -1404,7 +1971,6 @@ _libssh2_dsa_new_private(libssh2_dsa_ctx ** dsa, #endif /* LIBSSH_DSA */ #if LIBSSH2_ECDSA - int _libssh2_ecdsa_new_private_frommemory(libssh2_ecdsa_ctx ** ec_ctx, LIBSSH2_SESSION * session, @@ -1414,20 +1980,26 @@ _libssh2_ecdsa_new_private_frommemory(libssh2_ecdsa_ctx ** ec_ctx, { int rc; +#if defined(USE_OPENSSL_3) + pem_read_bio_func read_ec = + (pem_read_bio_func) &PEM_read_bio_PrivateKey; +#else pem_read_bio_func read_ec = (pem_read_bio_func) &PEM_read_bio_ECPrivateKey; +#endif _libssh2_init_if_needed(); - rc = read_private_key_from_memory((void **) ec_ctx, read_ec, + rc = read_private_key_from_memory((void **)ec_ctx, read_ec, filedata, filedata_len, passphrase); if(rc) { - rc = read_openssh_private_key_from_memory((void **)ec_ctx, session, - "ssh-ecdsa", - filedata, filedata_len, - passphrase); + rc = _libssh2_pub_priv_openssh_keyfilememory(session, (void **)ec_ctx, + "ssh-ecdsa", + NULL, NULL, NULL, NULL, + filedata, filedata_len, + passphrase); } return rc; @@ -1584,10 +2156,14 @@ gen_publickey_from_ed_evp(LIBSSH2_SESSION *session, goto fail; } - *method = methodBuf; - *method_len = sizeof(methodName) - 1; - *pubkeydata = keyBuf; - *pubkeydata_len = bufLen; + *method = methodBuf; + if(method_len) { + *method_len = sizeof(methodName) - 1; + } + *pubkeydata = keyBuf; + if(pubkeydata_len) { + *pubkeydata_len = bufLen; + } return 0; fail: @@ -1896,7 +2472,6 @@ clean_exit: return -1; } - int _libssh2_ed25519_new_private(libssh2_ed25519_ctx ** ed_ctx, LIBSSH2_SESSION * session, @@ -1939,12 +2514,9 @@ _libssh2_ed25519_new_private(libssh2_ed25519_ctx ** ed_ctx, } if(strcmp("ssh-ed25519", (const char *)buf) == 0) { - rc = gen_publickey_from_ed25519_openssh_priv_data(session, - decrypted, - NULL, - NULL, - NULL, - NULL, + rc = gen_publickey_from_ed25519_openssh_priv_data(session, decrypted, + NULL, NULL, + NULL, NULL, &ctx); } else { @@ -2013,10 +2585,8 @@ _libssh2_ed25519_new_private_sk(libssh2_ed25519_ctx **ed_ctx, if(strcmp("sk-ssh-ed25519@openssh.com", (const char *)buf) == 0) { rc = gen_publickey_from_sk_ed25519_openssh_priv_data(session, decrypted, - NULL, - NULL, - NULL, - NULL, + NULL, NULL, + NULL, NULL, flags, application, key_handle, @@ -2066,10 +2636,11 @@ _libssh2_ed25519_new_private_frommemory(libssh2_ed25519_ctx ** ed_ctx, return 0; } - return read_openssh_private_key_from_memory((void **)ed_ctx, session, - "ssh-ed25519", - filedata, filedata_len, - passphrase); + return _libssh2_pub_priv_openssh_keyfilememory(session, (void **)ed_ctx, + "ssh-ed25519", + NULL, NULL, NULL, NULL, + filedata, filedata_len, + passphrase); } int @@ -2136,17 +2707,57 @@ _libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session, size_t hash_len, unsigned char **signature, size_t *signature_len) { - int ret; - unsigned char *sig; - unsigned int sig_len; + int ret = -1; + unsigned char *sig = NULL; + +#ifdef USE_OPENSSL_3 + size_t sig_len = 0; + BIGNUM *n = NULL; + const EVP_MD *md = NULL; + + if(EVP_PKEY_get_bn_param(rsactx, OSSL_PKEY_PARAM_RSA_N, &n) > 0) { + sig_len = BN_num_bytes(n); + } + + if(sig_len > 0) + sig = LIBSSH2_ALLOC(session, sig_len); +#else + unsigned int sig_len = 0; sig_len = RSA_size(rsactx); sig = LIBSSH2_ALLOC(session, sig_len); +#endif if(!sig) { return -1; } +#ifdef USE_OPENSSL_3 + if(hash_len == SHA_DIGEST_LENGTH) + md = EVP_sha1(); + else if(hash_len == SHA256_DIGEST_LENGTH) + md = EVP_sha256(); + else if(hash_len == SHA512_DIGEST_LENGTH) + md = EVP_sha512(); + else { + _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "Unsupported hash digest length"); + } + + if(md) { + EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(rsactx, NULL); + if(ctx && + EVP_PKEY_sign_init(ctx) > 0 && + EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) > 0 && + EVP_PKEY_CTX_set_signature_md(ctx, md) > 0) { + ret = EVP_PKEY_sign(ctx, sig, &sig_len, hash, hash_len); + } + + if(ctx) { + EVP_PKEY_CTX_free(ctx); + } + } +#else if(hash_len == SHA_DIGEST_LENGTH) ret = RSA_sign(NID_sha1, hash, (unsigned int) hash_len, sig, &sig_len, rsactx); @@ -2161,6 +2772,7 @@ _libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session, "Unsupported hash digest length"); ret = -1; } +#endif if(!ret) { LIBSSH2_FREE(session, sig); @@ -2193,14 +2805,41 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx, const unsigned char *hash, size_t hash_len, unsigned char *signature) { - DSA_SIG *sig; + DSA_SIG *sig = NULL; const BIGNUM * r; const BIGNUM * s; int r_len, s_len; +#ifdef USE_OPENSSL_3 + EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(dsactx, NULL); + unsigned char *buf = NULL; + size_t sig_len = 0; + int size = 0; + + if(EVP_PKEY_get_int_param(dsactx, OSSL_PKEY_PARAM_MAX_SIZE, &size) > 0) { + sig_len = size; + buf = OPENSSL_malloc(size); + } + + if(buf && ctx && EVP_PKEY_sign_init(ctx) > 0) { + EVP_PKEY_sign(ctx, buf, &sig_len, hash, hash_len); + } + + if(ctx) { + EVP_PKEY_CTX_free(ctx); + } + + if(buf) { + const unsigned char *in = buf; + d2i_DSA_SIG(&sig, &in, (long)sig_len); + OPENSSL_clear_free(buf, size); + } +#else (void)hash_len; sig = DSA_do_sign(hash, SHA_DIGEST_LENGTH, dsactx); +#endif + if(!sig) { return -1; } @@ -2212,20 +2851,20 @@ _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx, s = sig->s; #endif r_len = BN_num_bytes(r); - if(r_len < 1 || r_len > 20) { + if(r_len < 1 || r_len > SHA_DIGEST_LENGTH) { DSA_SIG_free(sig); return -1; } s_len = BN_num_bytes(s); - if(s_len < 1 || s_len > 20) { + if(s_len < 1 || s_len > SHA_DIGEST_LENGTH) { DSA_SIG_free(sig); return -1; } - memset(signature, 0, 40); + memset(signature, 0, SHA_DIGEST_LENGTH * 2); - BN_bn2bin(r, signature + (20 - r_len)); - BN_bn2bin(s, signature + 20 + (20 - s_len)); + BN_bn2bin(r, signature + (SHA_DIGEST_LENGTH - r_len)); + BN_bn2bin(s, signature + SHA_DIGEST_LENGTH + (SHA_DIGEST_LENGTH - s_len)); DSA_SIG_free(sig); @@ -2247,10 +2886,47 @@ _libssh2_ecdsa_sign(LIBSSH2_SESSION * session, libssh2_ecdsa_ctx * ec_ctx, const BIGNUM *pr = NULL, *ps = NULL; unsigned char *temp_buffer = NULL; unsigned char *out_buffer = NULL; + ECDSA_SIG *sig = NULL; + +#ifdef USE_OPENSSL_3 + EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new(ec_ctx, NULL); + const unsigned char *p = NULL; + rc = -1; + + if(!ctx) { + return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, + "out of memory"); + } + + out_buffer_len = EVP_PKEY_get_size(ec_ctx); + temp_buffer = LIBSSH2_ALLOC(session, out_buffer_len); + if(!temp_buffer) { + goto clean_exit; + } + + rc = EVP_PKEY_sign_init(ctx); + if(rc <= 0) { + rc = -1; + goto clean_exit; + } + + rc = EVP_PKEY_sign(ctx, temp_buffer, &out_buffer_len, hash, hash_len); + if(rc <= 0) { + rc = -1; + goto clean_exit; + } - ECDSA_SIG *sig = ECDSA_do_sign(hash, (int) hash_len, ec_ctx); + rc = 0; + + p = temp_buffer; + sig = d2i_ECDSA_SIG(NULL, &p, (long)out_buffer_len); + OPENSSL_clear_free(temp_buffer, out_buffer_len); +#else + sig = ECDSA_do_sign(hash, (int)hash_len, ec_ctx); if(!sig) return -1; +#endif + #ifdef HAVE_OPAQUE_STRUCTS ECDSA_SIG_get0(sig, &pr, &ps); #else @@ -2292,6 +2968,11 @@ clean_exit: if(sig) ECDSA_SIG_free(sig); +#ifdef USE_OPENSSL_3 + if(ctx) + EVP_PKEY_CTX_free(ctx); +#endif + return rc; } #endif /* LIBSSH2_ECDSA */ @@ -2319,6 +3000,30 @@ _libssh2_sha1_init(libssh2_sha1_ctx *ctx) } int +_libssh2_sha1_update(libssh2_sha1_ctx *ctx, + const void *data, size_t len) +{ +#ifdef HAVE_OPAQUE_STRUCTS + return EVP_DigestUpdate(*ctx, data, len); +#else + return EVP_DigestUpdate(ctx, data, len); +#endif +} + +int +_libssh2_sha1_final(libssh2_sha1_ctx *ctx, + unsigned char *out) +{ +#ifdef HAVE_OPAQUE_STRUCTS + int ret = EVP_DigestFinal(*ctx, out, NULL); + EVP_MD_CTX_free(*ctx); + return ret; +#else + return EVP_DigestFinal(ctx, out, NULL); +#endif +} + +int _libssh2_sha1(const unsigned char *message, size_t len, unsigned char *out) { @@ -2371,6 +3076,30 @@ _libssh2_sha256_init(libssh2_sha256_ctx *ctx) } int +_libssh2_sha256_update(libssh2_sha256_ctx *ctx, + const void *data, size_t len) +{ +#ifdef HAVE_OPAQUE_STRUCTS + return EVP_DigestUpdate(*ctx, data, len); +#else + return EVP_DigestUpdate(ctx, data, len); +#endif +} + +int +_libssh2_sha256_final(libssh2_sha256_ctx *ctx, + unsigned char *out) +{ +#ifdef HAVE_OPAQUE_STRUCTS + int ret = EVP_DigestFinal(*ctx, out, NULL); + EVP_MD_CTX_free(*ctx); + return ret; +#else + return EVP_DigestFinal(ctx, out, NULL); +#endif +} + +int _libssh2_sha256(const unsigned char *message, size_t len, unsigned char *out) { @@ -2423,6 +3152,30 @@ _libssh2_sha384_init(libssh2_sha384_ctx *ctx) } int +_libssh2_sha384_update(libssh2_sha384_ctx *ctx, + const void *data, size_t len) +{ +#ifdef HAVE_OPAQUE_STRUCTS + return EVP_DigestUpdate(*ctx, data, len); +#else + return EVP_DigestUpdate(ctx, data, len); +#endif +} + +int +_libssh2_sha384_final(libssh2_sha384_ctx *ctx, + unsigned char *out) +{ +#ifdef HAVE_OPAQUE_STRUCTS + int ret = EVP_DigestFinal(*ctx, out, NULL); + EVP_MD_CTX_free(*ctx); + return ret; +#else + return EVP_DigestFinal(ctx, out, NULL); +#endif +} + +int _libssh2_sha384(const unsigned char *message, size_t len, unsigned char *out) { @@ -2475,6 +3228,30 @@ _libssh2_sha512_init(libssh2_sha512_ctx *ctx) } int +_libssh2_sha512_update(libssh2_sha512_ctx *ctx, + const void *data, size_t len) +{ +#ifdef HAVE_OPAQUE_STRUCTS + return EVP_DigestUpdate(*ctx, data, len); +#else + return EVP_DigestUpdate(ctx, data, len); +#endif +} + +int +_libssh2_sha512_final(libssh2_sha512_ctx *ctx, + unsigned char *out) +{ +#ifdef HAVE_OPAQUE_STRUCTS + int ret = EVP_DigestFinal(*ctx, out, NULL); + EVP_MD_CTX_free(*ctx); + return ret; +#else + return EVP_DigestFinal(ctx, out, NULL); +#endif +} + +int _libssh2_sha512(const unsigned char *message, size_t len, unsigned char *out) { @@ -2504,6 +3281,7 @@ _libssh2_sha512(const unsigned char *message, size_t len, return 1; /* error */ } +#if LIBSSH2_MD5 || LIBSSH2_MD5_PEM int _libssh2_md5_init(libssh2_md5_ctx *ctx) { @@ -2513,8 +3291,7 @@ _libssh2_md5_init(libssh2_md5_ctx *ctx) * So, just return 0 in FIPS mode */ #if OPENSSL_VERSION_NUMBER >= 0x000907000L && \ - defined(OPENSSL_VERSION_MAJOR) && \ - OPENSSL_VERSION_MAJOR < 3 && \ + !defined(USE_OPENSSL_3) && \ !defined(LIBRESSL_VERSION_NUMBER) if(FIPS_mode()) @@ -2540,6 +3317,31 @@ _libssh2_md5_init(libssh2_md5_ctx *ctx) #endif } +int +_libssh2_md5_update(libssh2_md5_ctx *ctx, + const void *data, size_t len) +{ +#ifdef HAVE_OPAQUE_STRUCTS + return EVP_DigestUpdate(*ctx, data, len); +#else + return EVP_DigestUpdate(ctx, data, len); +#endif +} + +int +_libssh2_md5_final(libssh2_md5_ctx *ctx, + unsigned char *out) +{ +#ifdef HAVE_OPAQUE_STRUCTS + int ret = EVP_DigestFinal(*ctx, out, NULL); + EVP_MD_CTX_free(*ctx); + return ret; +#else + return EVP_DigestFinal(ctx, out, NULL); +#endif +} +#endif + #if LIBSSH2_ECDSA static int @@ -2552,17 +3354,26 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, EVP_PKEY *pk) { int rc = 0; - EC_KEY *ec = NULL; unsigned char *p; unsigned char *method_buf = NULL; unsigned char *key; + size_t method_buf_len = 0; size_t key_len = 0; unsigned char *octal_value = NULL; size_t octal_len; + libssh2_curve_type type; + +#ifdef USE_OPENSSL_3 + _libssh2_debug((session, + LIBSSH2_TRACE_AUTH, + "Computing public key from EC private key envelope")); + + type = _libssh2_ecdsa_get_curve_type(pk); +#else + EC_KEY *ec = NULL; const EC_POINT *public_key; const EC_GROUP *group; - BN_CTX *bn_ctx; - libssh2_curve_type type; + BN_CTX *bn_ctx = NULL; _libssh2_debug((session, LIBSSH2_TRACE_AUTH, @@ -2581,26 +3392,32 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, public_key = EC_KEY_get0_public_key(ec); group = EC_KEY_get0_group(ec); type = _libssh2_ecdsa_get_curve_type(ec); +#endif if(is_sk) - *method_len = 34; + method_buf_len = 34; else - *method_len = 19; + method_buf_len = 19; - method_buf = LIBSSH2_ALLOC(session, *method_len); + method_buf = LIBSSH2_ALLOC(session, method_buf_len); if(!method_buf) { return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "out of memory"); } - if(is_sk) - memcpy(method_buf, "sk-ecdsa-sha2-nistp256@openssh.com", *method_len); - else if(type == LIBSSH2_EC_CURVE_NISTP256) - memcpy(method_buf, "ecdsa-sha2-nistp256", *method_len); - else if(type == LIBSSH2_EC_CURVE_NISTP384) - memcpy(method_buf, "ecdsa-sha2-nistp384", *method_len); - else if(type == LIBSSH2_EC_CURVE_NISTP521) - memcpy(method_buf, "ecdsa-sha2-nistp521", *method_len); + if(is_sk) { + memcpy(method_buf, "sk-ecdsa-sha2-nistp256@openssh.com", + method_buf_len); + } + else if(type == LIBSSH2_EC_CURVE_NISTP256) { + memcpy(method_buf, "ecdsa-sha2-nistp256", method_buf_len); + } + else if(type == LIBSSH2_EC_CURVE_NISTP384) { + memcpy(method_buf, "ecdsa-sha2-nistp384", method_buf_len); + } + else if(type == LIBSSH2_EC_CURVE_NISTP521) { + memcpy(method_buf, "ecdsa-sha2-nistp521", method_buf_len); + } else { _libssh2_debug((session, LIBSSH2_TRACE_ERROR, @@ -2609,6 +3426,12 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, goto clean_exit; } +#ifdef USE_OPENSSL_3 + octal_len = EC_MAX_POINT_LEN; + octal_value = LIBSSH2_ALLOC(session, octal_len); + EVP_PKEY_get_octet_string_param(pk, OSSL_PKEY_PARAM_PUB_KEY, + octal_value, octal_len, &octal_len); +#else /* get length */ octal_len = EC_POINT_point2oct(group, public_key, POINT_CONVERSION_UNCOMPRESSED, @@ -2630,10 +3453,11 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, rc = -1; goto clean_exit; } +#endif - /* Key form is: type_len(4) + type(method_len) + domain_len(4) + domain(8) - + pub_key_len(4) + pub_key(~65). */ - key_len = 4 + *method_len + 4 + 8 + 4 + octal_len; + /* Key form is: type_len(4) + type(method_buf_len) + domain_len(4) + + domain(8) + pub_key_len(4) + pub_key(~65). */ + key_len = 4 + method_buf_len + 4 + 8 + 4 + octal_len; key = LIBSSH2_ALLOC(session, key_len); if(!key) { rc = -1; @@ -2644,7 +3468,7 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, p = key; /* Key type */ - _libssh2_store_str(&p, (const char *)method_buf, *method_len); + _libssh2_store_str(&p, (const char *)method_buf, method_buf_len); /* Name domain */ if(is_sk) { @@ -2657,18 +3481,25 @@ gen_publickey_from_ec_evp(LIBSSH2_SESSION *session, /* Public key */ _libssh2_store_str(&p, (const char *)octal_value, octal_len); - *method = method_buf; - *pubkeydata = key; - *pubkeydata_len = key_len; + *method = method_buf; + if(method_len) { + *method_len = method_buf_len; + } + *pubkeydata = key; + if(pubkeydata_len) { + *pubkeydata_len = key_len; + } clean_exit: +#ifndef USE_OPENSSL_3 if(ec) EC_KEY_free(ec); if(bn_ctx) { BN_CTX_free(bn_ctx); } +#endif if(octal_value) free(octal_value); @@ -2695,8 +3526,16 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, int rc = 0; size_t curvelen, exponentlen, pointlen; unsigned char *curve, *exponent, *point_buf; - EC_KEY *ec_key = NULL; + libssh2_ecdsa_ctx *ec_key = NULL; + +#ifdef USE_OPENSSL_3 + EVP_PKEY_CTX *fromdata_ctx = NULL; + OSSL_PARAM params[4]; + const char *n = EC_curve_nid2nist(curve_type); + char *group_name = NULL; +#else BIGNUM *bn_exponent; +#endif _libssh2_debug((session, LIBSSH2_TRACE_AUTH, @@ -2721,6 +3560,43 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, return -1; } +#ifdef USE_OPENSSL_3 + if(!n) + return -1; + + fromdata_ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL); + + if(!fromdata_ctx) + goto fail; + + group_name = OPENSSL_zalloc(strlen(n) + 1); + + if(!group_name) + goto fail; + + memcpy(group_name, n, strlen(n)); + _libssh2_swap_bytes(exponent, (unsigned long)exponentlen); + + params[0] = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME, + group_name, 0); + + params[1] = OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_PUB_KEY, + point_buf, pointlen); + + params[2] = OSSL_PARAM_construct_BN(OSSL_PKEY_PARAM_PRIV_KEY, exponent, + exponentlen); + + params[3] = OSSL_PARAM_construct_end(); + + if(EVP_PKEY_fromdata_init(fromdata_ctx) <= 0) + goto fail; + + rc = EVP_PKEY_fromdata(fromdata_ctx, &ec_key, EVP_PKEY_KEYPAIR, params); + rc = rc != 1; + + if(group_name) + OPENSSL_clear_free(group_name, strlen(n)); +#else rc = _libssh2_ecdsa_curve_name_with_octal_new(&ec_key, point_buf, pointlen, curve_type); @@ -2741,29 +3617,46 @@ gen_publickey_from_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, BN_bin2bn(exponent, (int) exponentlen, bn_exponent); rc = (EC_KEY_set_private_key(ec_key, bn_exponent) != 1); +#endif if(rc == 0 && ec_key && pubkeydata && method) { +#ifdef USE_OPENSSL_3 + EVP_PKEY *pk = ec_key; +#else EVP_PKEY *pk = EVP_PKEY_new(); EVP_PKEY_set1_EC_KEY(pk, ec_key); +#endif rc = gen_publickey_from_ec_evp(session, method, method_len, pubkeydata, pubkeydata_len, 0, pk); +#ifndef USE_OPENSSL_3 if(pk) EVP_PKEY_free(pk); +#endif } +#ifdef USE_OPENSSL_3 + if(fromdata_ctx) + EVP_PKEY_CTX_free(fromdata_ctx); +#endif + if(ec_ctx) *ec_ctx = ec_key; else - EC_KEY_free(ec_key); + _libssh2_ecdsa_free(ec_key); return rc; fail: +#ifdef USE_OPENSSL_3 + if(fromdata_ctx) + EVP_PKEY_CTX_free(fromdata_ctx); +#endif + if(ec_key) - EC_KEY_free(ec_key); + _libssh2_ecdsa_free(ec_key); return rc; } @@ -2784,7 +3677,7 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, int rc = 0; size_t curvelen, pointlen, key_len, app_len; unsigned char *curve, *point_buf, *p, *key, *app; - EC_KEY *ec_key = NULL; + libssh2_ecdsa_ctx *ec_key = NULL; _libssh2_debug((session, LIBSSH2_TRACE_AUTH, @@ -2843,15 +3736,21 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, } if(rc == 0 && ec_key && pubkeydata && method) { +#ifdef USE_OPENSSL_3 + EVP_PKEY *pk = ec_key; +#else EVP_PKEY *pk = EVP_PKEY_new(); EVP_PKEY_set1_EC_KEY(pk, ec_key); +#endif rc = gen_publickey_from_ec_evp(session, method, method_len, pubkeydata, pubkeydata_len, 1, pk); +#ifndef USE_OPENSSL_3 if(pk) EVP_PKEY_free(pk); +#endif } if(rc == 0 && pubkeydata) { @@ -2886,13 +3785,13 @@ gen_publickey_from_sk_ecdsa_openssh_priv_data(LIBSSH2_SESSION *session, if(ec_ctx) *ec_ctx = ec_key; else - EC_KEY_free(ec_key); + _libssh2_ecdsa_free(ec_key); return rc; fail: if(ec_key) - EC_KEY_free(ec_key); + _libssh2_ecdsa_free(ec_key); if(application && *application) { LIBSSH2_FREE(session, (void *)application); @@ -2954,8 +3853,9 @@ _libssh2_ecdsa_new_openssh_private(libssh2_ecdsa_ctx ** ec_ctx, if(rc == 0) { rc = gen_publickey_from_ecdsa_openssh_priv_data(session, type, - decrypted, NULL, 0, - NULL, 0, ec_ctx); + decrypted, + NULL, NULL, + NULL, NULL, ec_ctx); } else { rc = -1; @@ -3015,8 +3915,8 @@ _libssh2_ecdsa_new_openssh_private_sk(libssh2_ecdsa_ctx ** ec_ctx, if(strcmp("sk-ecdsa-sha2-nistp256@openssh.com", (const char *)buf) == 0) { rc = gen_publickey_from_sk_ecdsa_openssh_priv_data(session, decrypted, - NULL, 0, - NULL, 0, + NULL, NULL, + NULL, NULL, flags, application, key_handle, @@ -3040,12 +3940,18 @@ _libssh2_ecdsa_new_private(libssh2_ecdsa_ctx ** ec_ctx, { int rc; - pem_read_bio_func read_ec = (pem_read_bio_func) &PEM_read_bio_ECPrivateKey; +#if defined(USE_OPENSSL_3) + pem_read_bio_func read_ec = + (pem_read_bio_func) &PEM_read_bio_PrivateKey; +#else + pem_read_bio_func read_ec = + (pem_read_bio_func) &PEM_read_bio_ECPrivateKey; +#endif _libssh2_init_if_needed(); rc = read_private_key_from_file((void **) ec_ctx, read_ec, - filename, passphrase); + filename, passphrase); if(rc) { return _libssh2_ecdsa_new_openssh_private(ec_ctx, session, @@ -3067,12 +3973,18 @@ _libssh2_ecdsa_new_private_sk(libssh2_ecdsa_ctx ** ec_ctx, { int rc; - pem_read_bio_func read_ec = (pem_read_bio_func) &PEM_read_bio_ECPrivateKey; +#if defined(USE_OPENSSL_3) + pem_read_bio_func read_ec = + (pem_read_bio_func) &PEM_read_bio_PrivateKey; +#else + pem_read_bio_func read_ec = + (pem_read_bio_func) &PEM_read_bio_ECPrivateKey; +#endif _libssh2_init_if_needed(); rc = read_private_key_from_file((void **) ec_ctx, read_ec, - filename, passphrase); + filename, passphrase); if(rc) { return _libssh2_ecdsa_new_openssh_private_sk(ec_ctx, @@ -3107,8 +4019,51 @@ _libssh2_ecdsa_create_key(LIBSSH2_SESSION *session, int ret = 1; size_t octal_len = 0; unsigned char octal_value[EC_MAX_POINT_LEN]; + _libssh2_ec_key *private_key = NULL; + +#ifdef USE_OPENSSL_3 + EVP_PKEY_CTX *ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL); + + if(ctx && + EVP_PKEY_keygen_init(ctx) >0 && + EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, curve_type) > 0) { + ret = EVP_PKEY_keygen(ctx, &private_key); + } + + if(ret <= 0) { + goto clean_exit; + } + + if(out_private_key) + *out_private_key = private_key; + + ret = EVP_PKEY_get_octet_string_param(private_key, OSSL_PKEY_PARAM_PUB_KEY, + NULL, 0, &octal_len); + + if(ret <= 0) { + goto clean_exit; + } + + *out_public_key_octal = LIBSSH2_ALLOC(session, octal_len); + + if(!(*out_public_key_octal)) { + ret = -1; + goto clean_exit; + } + + ret = EVP_PKEY_get_octet_string_param(private_key, OSSL_PKEY_PARAM_PUB_KEY, + octal_value, octal_len, &octal_len); + + if(ret <= 0) { + goto clean_exit; + } + + memcpy(*out_public_key_octal, octal_value, octal_len); + + if(out_public_key_octal_len) + *out_public_key_octal_len = octal_len; +#else const EC_POINT *public_key = NULL; - EC_KEY *private_key = NULL; const EC_GROUP *group = NULL; /* create key */ @@ -3153,11 +4108,16 @@ _libssh2_ecdsa_create_key(LIBSSH2_SESSION *session, if(out_public_key_octal_len) *out_public_key_octal_len = octal_len; +#endif /* USE_OPENSSL_3 */ clean_exit: - +#ifdef USE_OPENSSL_3 + if(ctx) + EVP_PKEY_CTX_free(ctx); +#else if(bn_ctx) BN_CTX_free(bn_ctx); +#endif return (ret == 1) ? 0 : -1; } @@ -3170,16 +4130,120 @@ clean_exit: int _libssh2_ecdh_gen_k(_libssh2_bn **k, _libssh2_ec_key *private_key, - const unsigned char *server_public_key, size_t server_public_key_len) + const unsigned char *server_public_key, + size_t server_public_key_len) { int ret = 0; - int rc; + BN_CTX *bn_ctx = NULL; + +#ifdef USE_OPENSSL_3 + char *group_name = NULL; + size_t group_name_len = 0; + unsigned char *out_shared_key = NULL; + EVP_PKEY *peer_key = NULL, *server_key = NULL; + EVP_PKEY_CTX *key_fromdata_ctx = NULL; + EVP_PKEY_CTX *server_key_ctx = NULL; + OSSL_PARAM params[3]; + + size_t out_len = 0; + + if(!k || !(*k) || server_public_key_len <= 0) + return -1; + + bn_ctx = BN_CTX_new(); + if(!bn_ctx) + goto clean_exit; + + key_fromdata_ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL); + if(!key_fromdata_ctx) + goto clean_exit; + + ret = EVP_PKEY_get_utf8_string_param(private_key, + OSSL_PKEY_PARAM_GROUP_NAME, + NULL, 0, &group_name_len); + + if(ret <= 0) + goto clean_exit; + + group_name_len += 1; + group_name = OPENSSL_zalloc(group_name_len); + + if(!group_name) + goto clean_exit; + + ret = EVP_PKEY_get_utf8_string_param(private_key, + OSSL_PKEY_PARAM_GROUP_NAME, + group_name, group_name_len, + &group_name_len); + + if(ret <= 0) + goto clean_exit; + + out_shared_key = OPENSSL_malloc(server_public_key_len); + + if(!out_shared_key) + goto clean_exit; + + memcpy(out_shared_key, server_public_key, server_public_key_len); + + params[0] = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_GROUP_NAME, + group_name, 0); + + params[1] = OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_PUB_KEY, + out_shared_key, + server_public_key_len); + + params[2] = OSSL_PARAM_construct_end(); + + ret = EVP_PKEY_fromdata_init(key_fromdata_ctx); + if(ret <= 0) + goto clean_exit; + + ret = EVP_PKEY_fromdata(key_fromdata_ctx, &peer_key, + EVP_PKEY_PUBLIC_KEY, params); + + if(ret <= 0) + goto clean_exit; + + server_key = private_key; + + if(!peer_key || !server_key) { + goto clean_exit; + } + + server_key_ctx = EVP_PKEY_CTX_new(server_key, NULL); + if(!server_key_ctx) { + goto clean_exit; + } + + ret = EVP_PKEY_derive_init(server_key_ctx); + if(ret <= 0) + goto clean_exit; + + ret = EVP_PKEY_derive_set_peer(server_key_ctx, peer_key); + if(ret <= 0) + goto clean_exit; + + ret = EVP_PKEY_derive(server_key_ctx, NULL, &out_len); + if(ret <= 0) + goto clean_exit; + + ret = EVP_PKEY_derive(server_key_ctx, out_shared_key, &out_len); + + if(ret == 1) { + BN_bin2bn(out_shared_key, (int)out_len, *k); + } + else { + ret = -1; + } +#else + int rc = -1; size_t secret_len; unsigned char *secret = NULL; const EC_GROUP *private_key_group; EC_POINT *server_public_key_point; - BN_CTX *bn_ctx = BN_CTX_new(); + bn_ctx = BN_CTX_new(); if(!bn_ctx) return -1; @@ -3216,9 +4280,19 @@ _libssh2_ecdh_gen_k(_libssh2_bn **k, _libssh2_ec_key *private_key, } BN_bin2bn(secret, (int) secret_len, *k); +#endif clean_exit: +#ifdef USE_OPENSSL_3 + if(group_name) + OPENSSL_clear_free(group_name, group_name_len); + if(out_shared_key) + OPENSSL_clear_free(out_shared_key, server_public_key_len); + + if(server_key_ctx) + EVP_PKEY_CTX_free(server_key_ctx); +#else if(server_public_key_point) EC_POINT_free(server_public_key_point); @@ -3227,8 +4301,13 @@ clean_exit: if(secret) free(secret); +#endif +#ifdef USE_OPENSSL_3 + return ret == 1 ? 0 : -1; +#else return ret; +#endif } @@ -3522,7 +4601,7 @@ _libssh2_pub_priv_keyfile(LIBSSH2_SESSION *session, "file: Unable to open private key file"); } - BIO_reset(bp); + (void)BIO_reset(bp); pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void *)passphrase); BIO_free(bp); @@ -3664,10 +4743,8 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, method_len, pubkeydata, pubkeydata_len, - NULL, - NULL, - NULL, - NULL, + NULL, NULL, + NULL, NULL, (libssh2_ed25519_ctx**)key_ctx); } } @@ -3696,16 +4773,15 @@ _libssh2_pub_priv_openssh_keyfilememory(LIBSSH2_SESSION *session, #endif #if LIBSSH2_ECDSA { - libssh2_curve_type type; + libssh2_curve_type type; if(strcmp("sk-ecdsa-sha2-nistp256@openssh.com", (const char *)buf) == 0) { rc = gen_publickey_from_sk_ecdsa_openssh_priv_data(session, decrypted, method, method_len, pubkeydata, pubkeydata_len, - NULL, NULL, NULL, - NULL, + NULL, NULL, (libssh2_ecdsa_ctx**)key_ctx); } else if(_libssh2_ecdsa_curve_type_from_name((const char *)buf, &type) @@ -3840,19 +4916,6 @@ _libssh2_sk_pub_openssh_keyfilememory(LIBSSH2_SESSION *session, return rc; } -int -read_openssh_private_key_from_memory(void **key_ctx, LIBSSH2_SESSION *session, - const char *key_type, - const char *filedata, - size_t filedata_len, - unsigned const char *passphrase) -{ - return _libssh2_pub_priv_openssh_keyfilememory(session, key_ctx, key_type, - NULL, NULL, NULL, NULL, - filedata, filedata_len, - passphrase); -} - #if OPENSSL_VERSION_NUMBER >= 0x30000000L #define HAVE_SSLERROR_BAD_DECRYPT #endif @@ -3888,7 +4951,7 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory when" "computing public key"); - BIO_reset(bp); + (void)BIO_reset(bp); pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void *)passphrase); #ifdef HAVE_SSLERROR_BAD_DECRYPT sslError = ERR_get_error(); @@ -3932,8 +4995,8 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, switch(pktype) { #if LIBSSH2_ED25519 case EVP_PKEY_ED25519: - st = gen_publickey_from_ed_evp( - session, method, method_len, pubkeydata, pubkeydata_len, pk); + st = gen_publickey_from_ed_evp(session, method, method_len, + pubkeydata, pubkeydata_len, pk); break; #endif /* LIBSSH2_ED25519 */ #if LIBSSH2_RSA @@ -3951,8 +5014,7 @@ _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, #if LIBSSH2_ECDSA case EVP_PKEY_EC: st = gen_publickey_from_ec_evp(session, method, method_len, - pubkeydata, pubkeydata_len, - 0, pk); + pubkeydata, pubkeydata_len, 0, pk); break; #endif /* LIBSSH2_ECDSA */ default: @@ -4000,7 +5062,7 @@ _libssh2_sk_pub_keyfilememory(LIBSSH2_SESSION *session, return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "Unable to allocate memory when" "computing public key"); - BIO_reset(bp); + (void)BIO_reset(bp); pk = PEM_read_bio_PrivateKey(bp, NULL, NULL, (void *)passphrase); BIO_free(bp); @@ -4074,7 +5136,11 @@ _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, #if LIBSSH2_RSA_SHA2 if(key_method_len == 7 && memcmp(key_method, "ssh-rsa", key_method_len) == 0) { - return "rsa-sha2-512,rsa-sha2-256,ssh-rsa"; + return "rsa-sha2-512,rsa-sha2-256" +#if LIBSSH2_RSA_SHA1 + ",ssh-rsa" +#endif + ; } #endif diff --git a/libs/libssh2/src/openssl.h b/libs/libssh2/src/openssl.h index efd9a007f6..e44c87498c 100644 --- a/libs/libssh2/src/openssl.h +++ b/libs/libssh2/src/openssl.h @@ -1,5 +1,5 @@ -#ifndef __LIBSSH2_OPENSSL_H -#define __LIBSSH2_OPENSSL_H +#ifndef LIBSSH2_OPENSSL_H +#define LIBSSH2_OPENSSL_H /* Copyright (C) Simon Josefsson * Copyright (C) The Written Word, Inc. * All rights reserved. @@ -78,6 +78,7 @@ #endif /* LIBSSH2_WOLFSSL */ +#include <openssl/opensslconf.h> #include <openssl/sha.h> #include <openssl/rsa.h> #ifndef OPENSSL_NO_ENGINE @@ -96,9 +97,15 @@ #include <openssl/pem.h> #include <openssl/rand.h> +#if OPENSSL_VERSION_NUMBER >= 0x30000000L +#define USE_OPENSSL_3 1 +#include <openssl/core_names.h> +#endif + #if (OPENSSL_VERSION_NUMBER >= 0x10100000L && \ !defined(LIBRESSL_VERSION_NUMBER)) || defined(LIBSSH2_WOLFSSL) || \ - LIBRESSL_VERSION_NUMBER >= 0x3050000fL + (defined(LIBRESSL_VERSION_NUMBER) && \ + LIBRESSL_VERSION_NUMBER >= 0x3050000fL) /* For wolfSSL, whether the structs are truly opaque or not, it's best to not * rely on their internal data members being exposed publicly. */ # define HAVE_OPAQUE_STRUCTS 1 @@ -192,6 +199,8 @@ # define LIBSSH2_3DES 1 #endif +#include "crypto_config.h" + #define EC_MAX_POINT_LEN ((528 * 2 / 8) + 1) #define _libssh2_random(buf, len) \ @@ -207,19 +216,15 @@ /* returns 0 in case of failure */ int _libssh2_sha1_init(libssh2_sha1_ctx *ctx); -#define libssh2_sha1_init(x) _libssh2_sha1_init(x) -#ifdef HAVE_OPAQUE_STRUCTS -#define libssh2_sha1_update(ctx, data, len) EVP_DigestUpdate(ctx, data, len) -#define libssh2_sha1_final(ctx, out) do { \ - EVP_DigestFinal(ctx, out, NULL); \ - EVP_MD_CTX_free(ctx); \ - } while(0) -#else -#define libssh2_sha1_update(ctx, data, len) EVP_DigestUpdate(&(ctx), data, len) -#define libssh2_sha1_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL) -#endif +int _libssh2_sha1_update(libssh2_sha1_ctx *ctx, + const void *data, size_t len); +int _libssh2_sha1_final(libssh2_sha1_ctx *ctx, unsigned char *out); int _libssh2_sha1(const unsigned char *message, size_t len, unsigned char *out); +#define libssh2_sha1_init(x) _libssh2_sha1_init(x) +#define libssh2_sha1_update(ctx, data, len) \ + _libssh2_sha1_update(&(ctx), data, len) +#define libssh2_sha1_final(ctx, out) _libssh2_sha1_final(&(ctx), out) #define libssh2_sha1(x,y,z) _libssh2_sha1(x,y,z) #ifdef HAVE_OPAQUE_STRUCTS @@ -230,20 +235,15 @@ int _libssh2_sha1(const unsigned char *message, size_t len, /* returns 0 in case of failure */ int _libssh2_sha256_init(libssh2_sha256_ctx *ctx); -#define libssh2_sha256_init(x) _libssh2_sha256_init(x) -#ifdef HAVE_OPAQUE_STRUCTS -#define libssh2_sha256_update(ctx, data, len) EVP_DigestUpdate(ctx, data, len) -#define libssh2_sha256_final(ctx, out) do { \ - EVP_DigestFinal(ctx, out, NULL); \ - EVP_MD_CTX_free(ctx); \ - } while(0) -#else -#define libssh2_sha256_update(ctx, data, len) \ - EVP_DigestUpdate(&(ctx), data, len) -#define libssh2_sha256_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL) -#endif +int _libssh2_sha256_update(libssh2_sha256_ctx *ctx, + const void *data, size_t len); +int _libssh2_sha256_final(libssh2_sha256_ctx *ctx, unsigned char *out); int _libssh2_sha256(const unsigned char *message, size_t len, unsigned char *out); +#define libssh2_sha256_init(x) _libssh2_sha256_init(x) +#define libssh2_sha256_update(ctx, data, len) \ + _libssh2_sha256_update(&(ctx), data, len) +#define libssh2_sha256_final(ctx, out) _libssh2_sha256_final(&(ctx), out) #define libssh2_sha256(x,y,z) _libssh2_sha256(x,y,z) #ifdef HAVE_OPAQUE_STRUCTS @@ -254,20 +254,15 @@ int _libssh2_sha256(const unsigned char *message, size_t len, /* returns 0 in case of failure */ int _libssh2_sha384_init(libssh2_sha384_ctx *ctx); -#define libssh2_sha384_init(x) _libssh2_sha384_init(x) -#ifdef HAVE_OPAQUE_STRUCTS -#define libssh2_sha384_update(ctx, data, len) EVP_DigestUpdate(ctx, data, len) -#define libssh2_sha384_final(ctx, out) do { \ - EVP_DigestFinal(ctx, out, NULL); \ - EVP_MD_CTX_free(ctx); \ - } while(0) -#else -#define libssh2_sha384_update(ctx, data, len) \ - EVP_DigestUpdate(&(ctx), data, len) -#define libssh2_sha384_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL) -#endif +int _libssh2_sha384_update(libssh2_sha384_ctx *ctx, + const void *data, size_t len); +int _libssh2_sha384_final(libssh2_sha384_ctx *ctx, unsigned char *out); int _libssh2_sha384(const unsigned char *message, size_t len, unsigned char *out); +#define libssh2_sha384_init(x) _libssh2_sha384_init(x) +#define libssh2_sha384_update(ctx, data, len) \ + _libssh2_sha384_update(&(ctx), data, len) +#define libssh2_sha384_final(ctx, out) _libssh2_sha384_final(&(ctx), out) #define libssh2_sha384(x,y,z) _libssh2_sha384(x,y,z) #ifdef HAVE_OPAQUE_STRUCTS @@ -278,22 +273,18 @@ int _libssh2_sha384(const unsigned char *message, size_t len, /* returns 0 in case of failure */ int _libssh2_sha512_init(libssh2_sha512_ctx *ctx); -#define libssh2_sha512_init(x) _libssh2_sha512_init(x) -#ifdef HAVE_OPAQUE_STRUCTS -#define libssh2_sha512_update(ctx, data, len) EVP_DigestUpdate(ctx, data, len) -#define libssh2_sha512_final(ctx, out) do { \ - EVP_DigestFinal(ctx, out, NULL); \ - EVP_MD_CTX_free(ctx); \ - } while(0) -#else -#define libssh2_sha512_update(ctx, data, len) \ - EVP_DigestUpdate(&(ctx), data, len) -#define libssh2_sha512_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL) -#endif +int _libssh2_sha512_update(libssh2_sha512_ctx *ctx, + const void *data, size_t len); +int _libssh2_sha512_final(libssh2_sha512_ctx *ctx, unsigned char *out); int _libssh2_sha512(const unsigned char *message, size_t len, unsigned char *out); +#define libssh2_sha512_init(x) _libssh2_sha512_init(x) +#define libssh2_sha512_update(ctx, data, len) \ + _libssh2_sha512_update(&(ctx), data, len) +#define libssh2_sha512_final(ctx, out) _libssh2_sha512_final(&(ctx), out) #define libssh2_sha512(x,y,z) _libssh2_sha512(x,y,z) +#if LIBSSH2_MD5 || LIBSSH2_MD5_PEM #ifdef HAVE_OPAQUE_STRUCTS #define libssh2_md5_ctx EVP_MD_CTX * #else @@ -302,62 +293,22 @@ int _libssh2_sha512(const unsigned char *message, size_t len, /* returns 0 in case of failure */ int _libssh2_md5_init(libssh2_md5_ctx *ctx); +int _libssh2_md5_update(libssh2_md5_ctx *ctx, + const void *data, size_t len); +int _libssh2_md5_final(libssh2_md5_ctx *ctx, unsigned char *out); #define libssh2_md5_init(x) _libssh2_md5_init(x) -#ifdef HAVE_OPAQUE_STRUCTS -#define libssh2_md5_update(ctx, data, len) EVP_DigestUpdate(ctx, data, len) -#define libssh2_md5_final(ctx, out) do { \ - EVP_DigestFinal(ctx, out, NULL); \ - EVP_MD_CTX_free(ctx); \ - } while(0) -#else -#define libssh2_md5_update(ctx, data, len) EVP_DigestUpdate(&(ctx), data, len) -#define libssh2_md5_final(ctx, out) EVP_DigestFinal(&(ctx), out, NULL) -#endif - -#ifdef HAVE_OPAQUE_STRUCTS +#define libssh2_md5_update(ctx, data, len) \ + _libssh2_md5_update(&(ctx), data, len) +#define libssh2_md5_final(ctx, out) _libssh2_md5_final(&(ctx), out) +#endif /* LIBSSH2_MD5 || LIBSSH2_MD5_PEM */ + +#ifdef USE_OPENSSL_3 +#define libssh2_hmac_ctx EVP_MAC_CTX * +#elif defined(HAVE_OPAQUE_STRUCTS) #define libssh2_hmac_ctx HMAC_CTX * -#define libssh2_hmac_ctx_init(ctx) ctx = HMAC_CTX_new() -#define libssh2_hmac_sha1_init(ctx, key, keylen) \ - HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha1(), NULL) -#define libssh2_hmac_md5_init(ctx, key, keylen) \ - HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_md5(), NULL) -#define libssh2_hmac_ripemd160_init(ctx, key, keylen) \ - HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_ripemd160(), NULL) -#define libssh2_hmac_sha256_init(ctx, key, keylen) \ - HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha256(), NULL) -#define libssh2_hmac_sha512_init(ctx, key, keylen) \ - HMAC_Init_ex(*(ctx), key, (int)keylen, EVP_sha512(), NULL) - -#ifdef LIBSSH2_WOLFSSL -/* FIXME: upstream bug as of v5.6.0: datalen is int instead of size_t */ -#define libssh2_hmac_update(ctx, data, datalen) \ - HMAC_Update(ctx, data, (int)datalen) -#else -#define libssh2_hmac_update(ctx, data, datalen) \ - HMAC_Update(ctx, data, datalen) -#endif /* LIBSSH2_WOLFSSL */ -#define libssh2_hmac_final(ctx, data) HMAC_Final(ctx, data, NULL) -#define libssh2_hmac_cleanup(ctx) HMAC_CTX_free(*(ctx)) -#else +#else /* !HAVE_OPAQUE_STRUCTS */ #define libssh2_hmac_ctx HMAC_CTX -#define libssh2_hmac_ctx_init(ctx) \ - HMAC_CTX_init(&ctx) -#define libssh2_hmac_sha1_init(ctx, key, keylen) \ - HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha1(), NULL) -#define libssh2_hmac_md5_init(ctx, key, keylen) \ - HMAC_Init_ex(ctx, key, (int)keylen, EVP_md5(), NULL) -#define libssh2_hmac_ripemd160_init(ctx, key, keylen) \ - HMAC_Init_ex(ctx, key, (int)keylen, EVP_ripemd160(), NULL) -#define libssh2_hmac_sha256_init(ctx, key, keylen) \ - HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha256(), NULL) -#define libssh2_hmac_sha512_init(ctx, key, keylen) \ - HMAC_Init_ex(ctx, key, (int)keylen, EVP_sha512(), NULL) - -#define libssh2_hmac_update(ctx, data, datalen) \ - HMAC_Update(&(ctx), data, datalen) -#define libssh2_hmac_final(ctx, data) HMAC_Final(&(ctx), data, NULL) -#define libssh2_hmac_cleanup(ctx) HMAC_cleanup(ctx) -#endif +#endif /* USE_OPENSSL_3 */ extern void _libssh2_openssl_crypto_init(void); extern void _libssh2_openssl_crypto_exit(void); @@ -365,21 +316,40 @@ extern void _libssh2_openssl_crypto_exit(void); #define libssh2_crypto_exit() _libssh2_openssl_crypto_exit() #if LIBSSH2_RSA -#define libssh2_rsa_ctx RSA +#ifdef USE_OPENSSL_3 +#define libssh2_rsa_ctx EVP_PKEY +#define _libssh2_rsa_free(rsactx) EVP_PKEY_free(rsactx) +#else +#define libssh2_rsa_ctx RSA #define _libssh2_rsa_free(rsactx) RSA_free(rsactx) #endif +#endif /* LIBSSH2_RSA */ + #if LIBSSH2_DSA -#define libssh2_dsa_ctx DSA +#ifdef USE_OPENSSL_3 +#define libssh2_dsa_ctx EVP_PKEY +#define _libssh2_dsa_free(rsactx) EVP_PKEY_free(rsactx) +#else +#define libssh2_dsa_ctx DSA #define _libssh2_dsa_free(dsactx) DSA_free(dsactx) #endif +#endif /* LIBSSH2_DSA */ + #if LIBSSH2_ECDSA + +#ifdef USE_OPENSSL_3 +#define libssh2_ecdsa_ctx EVP_PKEY +#define _libssh2_ecdsa_free(ecdsactx) EVP_PKEY_free(ecdsactx) +#define _libssh2_ec_key EVP_PKEY +#else #define libssh2_ecdsa_ctx EC_KEY #define _libssh2_ecdsa_free(ecdsactx) EC_KEY_free(ecdsactx) #define _libssh2_ec_key EC_KEY +#endif typedef enum { LIBSSH2_EC_CURVE_NISTP256 = NID_X9_62_prime256v1, @@ -387,15 +357,14 @@ typedef enum { LIBSSH2_EC_CURVE_NISTP521 = NID_secp521r1 } libssh2_curve_type; -#else +#else /* !LIBSSH2_ECDSA */ #define _libssh2_ec_key void #endif /* LIBSSH2_ECDSA */ #if LIBSSH2_ED25519 #define libssh2_ed25519_ctx EVP_PKEY - #define _libssh2_ed25519_free(ctx) EVP_PKEY_free(ctx) -#endif /* ED25519 */ +#endif /* LIBSSH2_ED25519 */ #define _libssh2_cipher_type(name) const EVP_CIPHER *(*name)(void) #ifdef HAVE_OPAQUE_STRUCTS @@ -468,4 +437,4 @@ const EVP_CIPHER *_libssh2_EVP_aes_128_ctr(void); const EVP_CIPHER *_libssh2_EVP_aes_192_ctr(void); const EVP_CIPHER *_libssh2_EVP_aes_256_ctr(void); -#endif /* __LIBSSH2_OPENSSL_H */ +#endif /* LIBSSH2_OPENSSL_H */ diff --git a/libs/libssh2/src/packet.c b/libs/libssh2/src/packet.c index e3ccf814d4..6da14e9fa1 100644 --- a/libs/libssh2/src/packet.c +++ b/libs/libssh2/src/packet.c @@ -71,14 +71,14 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, * Look for a matching listener */ /* 17 = packet_type(1) + channel(4) + reason(4) + descr(4) + lang(4) */ - size_t packet_len = 17 + (sizeof(FwdNotReq) - 1); + size_t packet_len = 17 + strlen(FwdNotReq); unsigned char *p; LIBSSH2_LISTENER *listn = _libssh2_list_first(&session->listeners); char failure_code = SSH_OPEN_ADMINISTRATIVELY_PROHIBITED; int rc; if(listen_state->state == libssh2_NB_state_idle) { - size_t offset = (sizeof("forwarded-tcpip") - 1) + 5; + size_t offset = strlen("forwarded-tcpip") + 5; size_t temp_len = 0; struct string_buf buf; buf.data = data; @@ -126,7 +126,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, } _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Remote received connection from %s:%ld to %s:%ld", + "Remote received connection from %s:%u to %s:%u", listen_state->shost, listen_state->sport, listen_state->host, listen_state->port)); @@ -137,8 +137,8 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, while(listn) { if((listn->port == (int) listen_state->port) && (strlen(listn->host) == listen_state->host_len) && - (memcmp (listn->host, listen_state->host, - listen_state->host_len) == 0)) { + (memcmp(listn->host, listen_state->host, + listen_state->host_len) == 0)) { /* This is our listener */ LIBSSH2_CHANNEL *channel = NULL; listen_state->channel = NULL; @@ -166,7 +166,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, listen_state->channel = channel; channel->session = session; - channel->channel_type_len = sizeof("forwarded-tcpip") - 1; + channel->channel_type_len = strlen("forwarded-tcpip"); channel->channel_type = LIBSSH2_ALLOC(session, channel-> channel_type_len + @@ -199,8 +199,8 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, channel->local.packet_size = listen_state->packet_size; _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Connection queued: channel %lu/%lu " - "win %lu/%lu packet %lu/%lu", + "Connection queued: channel %u/%u " + "win %u/%u packet %u/%u", channel->local.id, channel->remote.id, channel->local.window_size, channel->remote.window_size, @@ -253,7 +253,7 @@ packet_queue_listener(LIBSSH2_SESSION * session, unsigned char *data, *(p++) = SSH_MSG_CHANNEL_OPEN_FAILURE; _libssh2_store_u32(&p, listen_state->sender_channel); _libssh2_store_u32(&p, failure_code); - _libssh2_store_str(&p, FwdNotReq, sizeof(FwdNotReq) - 1); + _libssh2_store_str(&p, FwdNotReq, strlen(FwdNotReq)); _libssh2_htonu32(p, 0); rc = _libssh2_transport_send(session, listen_state->packet, @@ -282,14 +282,14 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, { int failure_code = SSH_OPEN_CONNECT_FAILED; /* 17 = packet_type(1) + channel(4) + reason(4) + descr(4) + lang(4) */ - size_t packet_len = 17 + (sizeof(X11FwdUnAvil) - 1); + size_t packet_len = 17 + strlen(X11FwdUnAvil); unsigned char *p; LIBSSH2_CHANNEL *channel = x11open_state->channel; int rc; if(x11open_state->state == libssh2_NB_state_idle) { - size_t offset = (sizeof("x11") - 1) + 5; + size_t offset = strlen("x11") + 5; size_t temp_len = 0; struct string_buf buf; buf.data = data; @@ -339,7 +339,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, } _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "X11 Connection Received from %s:%ld on channel %lu", + "X11 Connection Received from %s:%u on channel %u", x11open_state->shost, x11open_state->sport, x11open_state->sender_channel)); @@ -357,7 +357,7 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, } channel->session = session; - channel->channel_type_len = sizeof("x11") - 1; + channel->channel_type_len = strlen("x11"); channel->channel_type = LIBSSH2_ALLOC(session, channel->channel_type_len + 1); @@ -384,8 +384,8 @@ packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data, channel->local.packet_size = x11open_state->packet_size; _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "X11 Connection established: channel %lu/%lu " - "win %lu/%lu packet %lu/%lu", + "X11 Connection established: channel %u/%u " + "win %u/%u packet %u/%u", channel->local.id, channel->remote.id, channel->local.window_size, channel->remote.window_size, @@ -436,7 +436,7 @@ x11_exit: *(p++) = SSH_MSG_CHANNEL_OPEN_FAILURE; _libssh2_store_u32(&p, x11open_state->sender_channel); _libssh2_store_u32(&p, failure_code); - _libssh2_store_str(&p, X11FwdUnAvil, sizeof(X11FwdUnAvil) - 1); + _libssh2_store_str(&p, X11FwdUnAvil, strlen(X11FwdUnAvil)); _libssh2_htonu32(p, 0); rc = _libssh2_transport_send(session, x11open_state->packet, packet_len, @@ -464,23 +464,40 @@ packet_authagent_open(LIBSSH2_SESSION * session, { int failure_code = SSH_OPEN_CONNECT_FAILED; /* 17 = packet_type(1) + channel(4) + reason(4) + descr(4) + lang(4) */ - size_t packet_len = 17 + (sizeof(X11FwdUnAvil) - 1); + size_t packet_len = 17 + strlen(X11FwdUnAvil); unsigned char *p; LIBSSH2_CHANNEL *channel = authagent_state->channel; int rc; + struct string_buf buf; + size_t offset = strlen("auth-agent@openssh.org") + 5; - (void)datalen; + buf.data = data; + buf.dataptr = buf.data; + buf.len = datalen; + + buf.dataptr += offset; + + if(datalen < offset) { + return _libssh2_error(session, LIBSSH2_ERROR_OUT_OF_BOUNDARY, + "Unexpected packet size"); + } if(authagent_state->state == libssh2_NB_state_idle) { - unsigned char *s = data + (sizeof("auth-agent@openssh.org") - 1) + 5; - authagent_state->sender_channel = _libssh2_ntohu32(s); - s += 4; - authagent_state->initial_window_size = _libssh2_ntohu32(s); - s += 4; - authagent_state->packet_size = _libssh2_ntohu32(s); + if(_libssh2_get_u32(&buf, &(authagent_state->sender_channel))) { + return _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, + "Data too short extracting channel"); + } + if(_libssh2_get_u32(&buf, &(authagent_state->initial_window_size))) { + return _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, + "Data too short extracting window size"); + } + if(_libssh2_get_u32(&buf, &(authagent_state->packet_size))) { + return _libssh2_error(session, LIBSSH2_ERROR_BUFFER_TOO_SMALL, + "Data too short extracting packet"); + } _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Auth Agent Connection Received on channel %lu", + "Auth Agent Connection Received on channel %u", authagent_state->sender_channel)); authagent_state->state = libssh2_NB_state_allocated; @@ -500,7 +517,7 @@ packet_authagent_open(LIBSSH2_SESSION * session, memset(channel, 0, sizeof(LIBSSH2_CHANNEL)); channel->session = session; - channel->channel_type_len = sizeof("auth agent") - 1; + channel->channel_type_len = strlen("auth agent"); channel->channel_type = LIBSSH2_ALLOC(session, channel->channel_type_len + 1); @@ -528,7 +545,7 @@ packet_authagent_open(LIBSSH2_SESSION * session, _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Auth Agent Connection established: channel " - "%lu/%lu win %lu/%lu packet %lu/%lu", + "%u/%u win %u/%u packet %u/%u", channel->local.id, channel->remote.id, channel->local.window_size, channel->remote.window_size, @@ -584,7 +601,7 @@ authagent_exit: *(p++) = SSH_MSG_CHANNEL_OPEN_FAILURE; _libssh2_store_u32(&p, authagent_state->sender_channel); _libssh2_store_u32(&p, failure_code); - _libssh2_store_str(&p, AuthAgentUnavail, sizeof(AuthAgentUnavail) - 1); + _libssh2_store_str(&p, AuthAgentUnavail, strlen(AuthAgentUnavail)); _libssh2_htonu32(p, 0); rc = _libssh2_transport_send(session, authagent_state->packet, packet_len, @@ -607,14 +624,13 @@ authagent_exit: * layer when it has received a packet. * * The input pointer 'data' is pointing to allocated data that this function - * is asked to deal with so on failure OR success, it must be freed fine. - * The only exception is when the return code is LIBSSH2_ERROR_EAGAIN. + * will be freed unless return the code is LIBSSH2_ERROR_EAGAIN. * * This function will always be called with 'datalen' greater than zero. */ int _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, - size_t datalen, int macstate) + size_t datalen, int macstate, uint32_t seq) { int rc = 0; unsigned char *message = NULL; @@ -628,8 +644,8 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, switch(session->packAdd_state) { case libssh2_NB_state_idle: _libssh2_debug((session, LIBSSH2_TRACE_TRANS, - "Packet type %d received, length=%d", - (int) msg, (int) datalen)); + "Packet type %u received, length=%ld", + (unsigned int) msg, (long) datalen)); if((macstate == LIBSSH2_MAC_INVALID) && (!session->macerror || @@ -659,6 +675,70 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, break; } + if(session->state & LIBSSH2_STATE_INITIAL_KEX) { + if(msg == SSH_MSG_KEXINIT) { + if(!session->kex_strict) { + if(datalen < 17) { + LIBSSH2_FREE(session, data); + session->packAdd_state = libssh2_NB_state_idle; + return _libssh2_error(session, + LIBSSH2_ERROR_BUFFER_TOO_SMALL, + "Data too short extracting kex"); + } + else { + const unsigned char *strict = + (unsigned char *)"kex-strict-s-v00@openssh.com"; + struct string_buf buf; + unsigned char *algs = NULL; + size_t algs_len = 0; + + buf.data = (unsigned char *)data; + buf.dataptr = buf.data; + buf.len = datalen; + buf.dataptr += 17; /* advance past type and cookie */ + + if(_libssh2_get_string(&buf, &algs, &algs_len)) { + LIBSSH2_FREE(session, data); + session->packAdd_state = libssh2_NB_state_idle; + return _libssh2_error(session, + LIBSSH2_ERROR_BUFFER_TOO_SMALL, + "Algs too short"); + } + + if(algs_len == 0 || + _libssh2_kex_agree_instr(algs, algs_len, strict, 28)) { + session->kex_strict = 1; + } + } + } + + if(session->kex_strict && seq) { + LIBSSH2_FREE(session, data); + session->socket_state = LIBSSH2_SOCKET_DISCONNECTED; + session->packAdd_state = libssh2_NB_state_idle; + libssh2_session_disconnect(session, "strict KEX violation: " + "KEXINIT was not the first packet"); + + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_DISCONNECT, + "strict KEX violation: " + "KEXINIT was not the first packet"); + } + } + + if(session->kex_strict && session->fullpacket_required_type && + session->fullpacket_required_type != msg) { + LIBSSH2_FREE(session, data); + session->socket_state = LIBSSH2_SOCKET_DISCONNECTED; + session->packAdd_state = libssh2_NB_state_idle; + libssh2_session_disconnect(session, "strict KEX violation: " + "unexpected packet type"); + + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_DISCONNECT, + "strict KEX violation: " + "unexpected packet type"); + } + } + if(session->packAdd_state == libssh2_NB_state_allocated) { /* A couple exceptions to the packet adding rule: */ switch(msg) { @@ -795,7 +875,8 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Server to Client extension %.*s: %.*s", - name_len, name, value_len, value)); + (int)name_len, name, + (int)value_len, value)); } if(name_len == 15 && @@ -843,7 +924,7 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Received global request type %.*s (wr %X)", - len, data + 5, want_reply)); + (int)len, data + 5, want_reply)); } @@ -872,7 +953,7 @@ libssh2_packet_add_jump_point5: /* streamid(4) */ data_head += 4; - /* fall-through */ + LIBSSH2_FALLTHROUGH(); /* byte SSH_MSG_CHANNEL_DATA @@ -903,8 +984,8 @@ libssh2_packet_add_jump_point5: stream_id = _libssh2_ntohu32(data + 5); _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "%d bytes packet_add() for %lu/%lu/%lu", - (int) (datalen - data_head), + "%ld bytes packet_add() for %u/%u/%u", + (long) (datalen - data_head), channelp->local.id, channelp->remote.id, stream_id)); @@ -917,8 +998,8 @@ libssh2_packet_add_jump_point5: LIBSSH2_FREE(session, data); _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Ignoring extended data and refunding %d bytes", - (int) (datalen - 13))); + "Ignoring extended data and refunding %ld bytes", + (long) (datalen - 13))); if(channelp->read_avail + datalen - data_head >= channelp->remote.window_size) datalen = channelp->remote.window_size - @@ -927,11 +1008,11 @@ libssh2_packet_add_jump_point5: channelp->remote.window_size -= (uint32_t)(datalen - data_head); _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "shrinking window size by %lu bytes to %lu, " - "read_avail %lu", - datalen - data_head, + "shrinking window size by %ld bytes to %u, " + "read_avail %ld", + (long) (datalen - data_head), channelp->remote.window_size, - channelp->read_avail)); + (long) channelp->read_avail)); session->packAdd_channelp = channelp; @@ -993,10 +1074,10 @@ libssh2_packet_add_jump_point1: channelp->read_avail += datalen - data_head; _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "increasing read_avail by %lu bytes to %lu/%lu", + "increasing read_avail by %ld bytes to %ld/%u", (long)(datalen - data_head), (long)channelp->read_avail, - (long)channelp->remote.window_size)); + channelp->remote.window_size)); break; @@ -1016,7 +1097,7 @@ libssh2_packet_add_jump_point1: else { _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "EOF received for channel %lu/%lu", + "EOF received for channel %u/%u", channelp->local.id, channelp->remote.id)); channelp->remote.eof = 1; @@ -1044,43 +1125,45 @@ libssh2_packet_add_jump_point1: _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Channel %d received request type %.*s (wr %X)", - channel, len, data + 9, want_reply)); + "Channel %u received request type %.*s (wr %X)", + channel, (int)len, data + 9, want_reply)); - if(len == sizeof("exit-status") - 1 - && (sizeof("exit-status") - 1 + 9) <= datalen + if(len == strlen("exit-status") + && (strlen("exit-status") + 9) <= datalen && !memcmp("exit-status", data + 9, - sizeof("exit-status") - 1)) { + strlen("exit-status"))) { /* we've got "exit-status" packet. Set the session value */ if(datalen >= 20) channelp = _libssh2_channel_locate(session, channel); - if(channelp && (sizeof("exit-status") + 13) <= datalen) { + if(channelp && (strlen("exit-status") + 14) <= datalen) { channelp->exit_status = - _libssh2_ntohu32(data + 9 + sizeof("exit-status")); + _libssh2_ntohu32(data + 10 + + strlen("exit-status")); _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Exit status %lu received for " - "channel %lu/%lu", + "Exit status %d received for " + "channel %u/%u", channelp->exit_status, channelp->local.id, channelp->remote.id)); } } - else if(len == sizeof("exit-signal") - 1 - && (sizeof("exit-signal") - 1 + 9) <= datalen + else if(len == strlen("exit-signal") + && (strlen("exit-signal") + 9) <= datalen && !memcmp("exit-signal", data + 9, - sizeof("exit-signal") - 1)) { + strlen("exit-signal"))) { /* command terminated due to signal */ if(datalen >= 20) channelp = _libssh2_channel_locate(session, channel); - if(channelp && (sizeof("exit-signal") + 13) <= datalen) { + if(channelp && (strlen("exit-signal") + 14) <= datalen) { /* set signal name (without SIG prefix) */ uint32_t namelen = - _libssh2_ntohu32(data + 9 + sizeof("exit-signal")); + _libssh2_ntohu32(data + 10 + + strlen("exit-signal")); if(namelen <= UINT_MAX - 1) { channelp->exit_signal = @@ -1093,15 +1176,15 @@ libssh2_packet_add_jump_point1: if(!channelp->exit_signal) rc = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, "memory for signal name"); - else if((sizeof("exit-signal") + 13 + namelen <= + else if((strlen("exit-signal") + 14 + namelen <= datalen)) { memcpy(channelp->exit_signal, - data + 13 + sizeof("exit-signal"), namelen); + data + 14 + strlen("exit-signal"), namelen); channelp->exit_signal[namelen] = '\0'; /* TODO: save error message and language tag */ _libssh2_debug((session, LIBSSH2_TRACE_CONN, "Exit signal %s received for " - "channel %lu/%lu", + "channel %u/%u", channelp->exit_signal, channelp->local.id, channelp->remote.id)); @@ -1142,7 +1225,7 @@ libssh2_packet_add_jump_point4: return 0; } _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Close received for channel %lu/%lu", + "Close received for channel %u/%u", channelp->local.id, channelp->remote.id)); @@ -1164,12 +1247,12 @@ libssh2_packet_add_jump_point4: case SSH_MSG_CHANNEL_OPEN: if(datalen < 17) ; - else if((datalen >= (sizeof("forwarded-tcpip") + 4)) && - ((sizeof("forwarded-tcpip") - 1) == + else if((datalen >= (strlen("forwarded-tcpip") + 5)) && + (strlen("forwarded-tcpip") == _libssh2_ntohu32(data + 1)) && (memcmp(data + 5, "forwarded-tcpip", - sizeof("forwarded-tcpip") - 1) == 0)) { + strlen("forwarded-tcpip")) == 0)) { /* init the state struct */ memset(&session->packAdd_Qlstn_state, 0, @@ -1180,9 +1263,9 @@ libssh2_packet_add_jump_point2: rc = packet_queue_listener(session, data, datalen, &session->packAdd_Qlstn_state); } - else if((datalen >= (sizeof("x11") + 4)) && - ((sizeof("x11") - 1) == _libssh2_ntohu32(data + 1)) && - (memcmp(data + 5, "x11", sizeof("x11") - 1) == 0)) { + else if((datalen >= (strlen("x11") + 5)) && + ((strlen("x11")) == _libssh2_ntohu32(data + 1)) && + (memcmp(data + 5, "x11", strlen("x11")) == 0)) { /* init the state struct */ memset(&session->packAdd_x11open_state, 0, @@ -1193,11 +1276,11 @@ libssh2_packet_add_jump_point3: rc = packet_x11_open(session, data, datalen, &session->packAdd_x11open_state); } - else if((datalen >= (sizeof("auth-agent@openssh.com") + 4)) && - ((sizeof("auth-agent@openssh.com") - 1) == + else if((datalen >= (strlen("auth-agent@openssh.com") + 5)) && + (strlen("auth-agent@openssh.com") == _libssh2_ntohu32(data + 1)) && (memcmp(data + 5, "auth-agent@openssh.com", - sizeof("auth-agent@openssh.com") - 1) == 0)) { + strlen("auth-agent@openssh.com")) == 0)) { /* init the state struct */ memset(&session->packAdd_authagent_state, 0, @@ -1232,8 +1315,8 @@ libssh2_packet_add_jump_authagent: channelp->local.window_size += bytestoadd; _libssh2_debug((session, LIBSSH2_TRACE_CONN, - "Window adjust for channel %lu/%lu, " - "adding %lu bytes, new window_size=%lu", + "Window adjust for channel %u/%u, " + "adding %u bytes, new window_size=%u", channelp->local.id, channelp->remote.id, bytestoadd, @@ -1325,7 +1408,8 @@ _libssh2_packet_ask(LIBSSH2_SESSION * session, unsigned char packet_type, LIBSSH2_PACKET *packet = _libssh2_list_first(&session->packets); _libssh2_debug((session, LIBSSH2_TRACE_TRANS, - "Looking for packet of type: %d", (int) packet_type)); + "Looking for packet of type: %u", + (unsigned int)packet_type)); while(packet) { if(packet->data[0] == packet_type @@ -1343,6 +1427,15 @@ _libssh2_packet_ask(LIBSSH2_SESSION * session, unsigned char packet_type, return 0; } + else if(session->kex_strict && + (session->state & LIBSSH2_STATE_INITIAL_KEX)) { + libssh2_session_disconnect(session, "strict KEX violation: " + "unexpected packet type"); + + return _libssh2_error(session, LIBSSH2_ERROR_SOCKET_DISCONNECT, + "strict KEX violation: " + "unexpected packet type"); + } packet = _libssh2_list_next(&packet->node); } return -1; @@ -1404,7 +1497,10 @@ _libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type, } while(session->socket_state == LIBSSH2_SOCKET_CONNECTED) { - int ret = _libssh2_transport_read(session); + int ret; + session->fullpacket_required_type = packet_type; + ret = _libssh2_transport_read(session); + session->fullpacket_required_type = 0; if(ret == LIBSSH2_ERROR_EAGAIN) return ret; else if(ret < 0) { diff --git a/libs/libssh2/src/packet.h b/libs/libssh2/src/packet.h index 55428d0651..955351e5f6 100644 --- a/libs/libssh2/src/packet.h +++ b/libs/libssh2/src/packet.h @@ -1,5 +1,5 @@ -#ifndef __LIBSSH2_PACKET_H -#define __LIBSSH2_PACKET_H +#ifndef LIBSSH2_PACKET_H +#define LIBSSH2_PACKET_H /* * Copyright (C) Daniel Stenberg * All rights reserved. @@ -72,6 +72,6 @@ int _libssh2_packet_burn(LIBSSH2_SESSION * session, int _libssh2_packet_write(LIBSSH2_SESSION * session, unsigned char *data, unsigned long data_len); int _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, - size_t datalen, int macstate); + size_t datalen, int macstate, uint32_t seq); -#endif /* __LIBSSH2_PACKET_H */ +#endif /* LIBSSH2_PACKET_H */ diff --git a/libs/libssh2/src/pem.c b/libs/libssh2/src/pem.c index 912498c5d3..c658896809 100644 --- a/libs/libssh2/src/pem.c +++ b/libs/libssh2/src/pem.c @@ -106,12 +106,6 @@ static unsigned char hex_decode(char digit) ((digit >= 'A') ? (0xA + (digit - 'A')) : (digit - '0')); } -/* Hack to fix builds with crypto backends with MD5 support disabled. - FIXME: Honor our LIBSSH2_MD5 macro for MD5-dependent logic. */ -#ifdef OPENSSL_NO_MD5 -#define MD5_DIGEST_LENGTH 16 -#endif - int _libssh2_pem_parse(LIBSSH2_SESSION * session, const char *headerbegin, @@ -215,6 +209,7 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session, } if(method) { +#if LIBSSH2_MD5_PEM /* Set up decryption */ int free_iv = 0, free_secret = 0, len_decrypted = 0, padding = 0; int blocksize = method->blocksize; @@ -223,24 +218,26 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session, libssh2_md5_ctx fingerprint_ctx; /* Perform key derivation (PBKDF1/MD5) */ - if(!libssh2_md5_init(&fingerprint_ctx)) { + if(!libssh2_md5_init(&fingerprint_ctx) || + !libssh2_md5_update(fingerprint_ctx, passphrase, + strlen((char *)passphrase)) || + !libssh2_md5_update(fingerprint_ctx, iv, 8) || + !libssh2_md5_final(fingerprint_ctx, secret)) { ret = -1; goto out; } - libssh2_md5_update(fingerprint_ctx, passphrase, - strlen((char *)passphrase)); - libssh2_md5_update(fingerprint_ctx, iv, 8); - libssh2_md5_final(fingerprint_ctx, secret); if(method->secret_len > MD5_DIGEST_LENGTH) { - if(!libssh2_md5_init(&fingerprint_ctx)) { + if(!libssh2_md5_init(&fingerprint_ctx) || + !libssh2_md5_update(fingerprint_ctx, + secret, MD5_DIGEST_LENGTH) || + !libssh2_md5_update(fingerprint_ctx, + passphrase, strlen((char *)passphrase)) || + !libssh2_md5_update(fingerprint_ctx, iv, 8) || + !libssh2_md5_final(fingerprint_ctx, + secret + MD5_DIGEST_LENGTH)) { ret = -1; goto out; } - libssh2_md5_update(fingerprint_ctx, secret, MD5_DIGEST_LENGTH); - libssh2_md5_update(fingerprint_ctx, passphrase, - strlen((char *)passphrase)); - libssh2_md5_update(fingerprint_ctx, iv, 8); - libssh2_md5_final(fingerprint_ctx, secret + MD5_DIGEST_LENGTH); } /* Initialize the decryption */ @@ -292,6 +289,10 @@ _libssh2_pem_parse(LIBSSH2_SESSION * session, /* Clean up */ _libssh2_explicit_zero((char *)secret, sizeof(secret)); method->dtor(session, &abstract); +#else + ret = -1; + goto out; +#endif } ret = 0; @@ -599,13 +600,17 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, } while((size_t)len_decrypted <= decrypted.len - blocksize) { + /* We always pass MIDDLE_BLOCK here because OpenSSH Key Files + * do not use AAD to authenticate the length. + * Furthermore, the authentication tag is appended after the + * encrypted key, and the length of the authentication tag is + * not included in the key length, so we check it after the + * loop. + */ if(method->crypt(session, decrypted.data + len_decrypted, blocksize, &abstract, - len_decrypted == 0 ? FIRST_BLOCK : ( - ((size_t)len_decrypted == decrypted.len - blocksize) ? - LAST_BLOCK : MIDDLE_BLOCK) - )) { + MIDDLE_BLOCK)) { ret = LIBSSH2_ERROR_DECRYPT; method->dtor(session, &abstract); goto out; @@ -616,6 +621,26 @@ _libssh2_openssh_pem_parse_data(LIBSSH2_SESSION * session, /* No padding */ + /* for the AES GCM methods, the 16 byte authentication tag is + * appended to the encrypted key */ + if(strcmp(method->name, "aes256-gcm@openssh.com") == 0 || + strcmp(method->name, "aes128-gcm@openssh.com") == 0) { + if(!_libssh2_check_length(&decoded, 16)) { + ret = _libssh2_error(session, LIBSSH2_ERROR_PROTO, + "GCM auth tag missing"); + method->dtor(session, &abstract); + goto out; + } + if(method->crypt(session, decoded.dataptr, 16, &abstract, + LAST_BLOCK)) { + ret = _libssh2_error(session, LIBSSH2_ERROR_DECRYPT, + "GCM auth tag invalid"); + method->dtor(session, &abstract); + goto out; + } + decoded.dataptr += 16; + } + method->dtor(session, &abstract); } diff --git a/libs/libssh2/src/publickey.c b/libs/libssh2/src/publickey.c index db45be99be..9c9fa61884 100644 --- a/libs/libssh2/src/publickey.c +++ b/libs/libssh2/src/publickey.c @@ -516,13 +516,13 @@ static LIBSSH2_PUBLICKEY *publickey_init(LIBSSH2_SESSION *session) LIBSSH2_PUBLICKEY_VERSION) { _libssh2_debug((session, LIBSSH2_TRACE_PUBLICKEY, "Truncate remote publickey version " - "from %lu", + "from %u", session->pkeyInit_pkey->version)); session->pkeyInit_pkey->version = LIBSSH2_PUBLICKEY_VERSION; } _libssh2_debug((session, LIBSSH2_TRACE_PUBLICKEY, - "Enabling publickey subsystem version %lu", + "Enabling publickey subsystem version %u", session->pkeyInit_pkey->version)); LIBSSH2_FREE(session, session->pkeyInit_data); session->pkeyInit_data = NULL; diff --git a/libs/libssh2/src/scp.c b/libs/libssh2/src/scp.c index ff20a80ae5..0900655aac 100644 --- a/libs/libssh2/src/scp.c +++ b/libs/libssh2/src/scp.c @@ -748,7 +748,7 @@ scp_recv(LIBSSH2_SESSION * session, const char *path, libssh2_struct_stat * sb) } _libssh2_debug((session, LIBSSH2_TRACE_SCP, "mode = 0%lo size = %ld", session->scpRecv_mode, - session->scpRecv_size)); + (long)session->scpRecv_size)); /* We *should* check that basename is valid, but why let that stop us? */ @@ -792,6 +792,7 @@ scp_recv_error: return NULL; } +#ifndef LIBSSH2_NO_DEPRECATED /* * libssh2_scp_recv * @@ -828,6 +829,7 @@ libssh2_scp_recv(LIBSSH2_SESSION *session, const char *path, struct stat *sb) return ptr; } +#endif /* * libssh2_scp_recv2 diff --git a/libs/libssh2/src/session.c b/libs/libssh2/src/session.c index 4d9edc5c8c..9d89ade8ec 100644 --- a/libs/libssh2/src/session.c +++ b/libs/libssh2/src/session.c @@ -41,7 +41,7 @@ #include "libssh2_priv.h" -#ifdef WIN32 +#ifdef _WIN32 #include <ws2tcpip.h> /* for socklen_t */ #endif #ifdef HAVE_UNISTD_H @@ -60,7 +60,7 @@ #include "channel.h" #include "mac.h" -#if defined(WIN32) +#if defined(_WIN32) #define libssh2_usec_t long #elif defined(__APPLE__) #define libssh2_usec_t suseconds_t @@ -132,11 +132,11 @@ banner_receive(LIBSSH2_SESSION * session) if(session->api_block_mode || (ret != -EAGAIN)) /* ignore EAGAIN when non-blocking */ _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Error recving %d bytes: %d", 1, (int)-ret)); + "Error recving %d bytes: %ld", 1, (long)-ret)); } else _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Recved %d bytes banner", (int)ret)); + "Recved %ld bytes banner", (long)ret)); if(ret < 0) { if(ret == -EAGAIN) { @@ -253,13 +253,14 @@ banner_send(LIBSSH2_SESSION * session) LIBSSH2_SOCKET_SEND_FLAGS(session)); if(ret < 0) _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Error sending %d bytes: %d", - banner_len - session->banner_TxRx_total_send, -ret)); + "Error sending %ld bytes: %ld", + (long)(banner_len - session->banner_TxRx_total_send), + (long)-ret)); else _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Sent %d/%d bytes at %p+%d", ret, - banner_len - session->banner_TxRx_total_send, - banner, session->banner_TxRx_total_send)); + "Sent %ld/%ld bytes at %p+%ld", (long)ret, + (long)(banner_len - session->banner_TxRx_total_send), + (void *)banner, (long)session->banner_TxRx_total_send)); if(ret != (ssize_t)(banner_len - session->banner_TxRx_total_send)) { if(ret >= 0 || ret == -EAGAIN) { @@ -313,7 +314,7 @@ session_nonblock(libssh2_socket_t sockfd, /* operate on this */ /* BeOS */ long b = nonblock ? 1 : 0; return setsockopt(sockfd, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b)); -#elif defined(WIN32) +#elif defined(_WIN32) unsigned long flags; flags = nonblock; @@ -366,7 +367,7 @@ get_socket_nonblocking(libssh2_socket_t sockfd) return 1; } return 0; -#elif defined(WIN32) +#elif defined(_WIN32) unsigned int option_value; socklen_t option_len = sizeof(option_value); @@ -417,6 +418,7 @@ libssh2_session_banner_set(LIBSSH2_SESSION * session, const char *banner) return 0; } +#ifndef LIBSSH2_NO_DEPRECATED /* libssh2_banner_set * Set the local banner. DEPRECATED VERSION */ @@ -425,6 +427,7 @@ libssh2_banner_set(LIBSSH2_SESSION * session, const char *banner) { return libssh2_session_banner_set(session, banner); } +#endif /* * libssh2_session_init_ex @@ -466,6 +469,8 @@ libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)), session->abstract = abstract; session->api_timeout = 0; /* timeout-free API by default */ session->api_block_mode = 1; /* blocking API by default */ + session->state = LIBSSH2_STATE_INITIAL_KEX; + session->fullpacket_required_type = 0; session->packet_read_timeout = LIBSSH2_DEFAULT_READ_TIMEOUT; session->flag.quote_paths = 1; /* default behavior is to quote paths for the scp subsystem */ @@ -477,77 +482,68 @@ libssh2_session_init_ex(LIBSSH2_ALLOC_FUNC((*my_alloc)), } /* - * libssh2_session_callback_set + * libssh2_session_callback_set2 * * Set (or reset) a callback function * Returns the prior address - * - * ALERT: this function relies on that we can typecast function pointers - * to void pointers, which isn't allowed in ISO C! */ -#ifdef _MSC_VER -#pragma warning(push) -/* nonstandard extension, function/data pointer conversion in expression */ -#pragma warning(disable:4152) -#else -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpedantic" -#endif -LIBSSH2_API void * -libssh2_session_callback_set(LIBSSH2_SESSION * session, - int cbtype, void *callback) +LIBSSH2_API libssh2_cb_generic * +libssh2_session_callback_set2(LIBSSH2_SESSION *session, int cbtype, + libssh2_cb_generic *callback) { - void *oldcb; + libssh2_cb_generic *oldcb; switch(cbtype) { case LIBSSH2_CALLBACK_IGNORE: - oldcb = session->ssh_msg_ignore; - session->ssh_msg_ignore = callback; + oldcb = (libssh2_cb_generic *)session->ssh_msg_ignore; + session->ssh_msg_ignore = (LIBSSH2_IGNORE_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_DEBUG: - oldcb = session->ssh_msg_debug; - session->ssh_msg_debug = callback; + oldcb = (libssh2_cb_generic *)session->ssh_msg_debug; + session->ssh_msg_debug = (LIBSSH2_DEBUG_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_DISCONNECT: - oldcb = session->ssh_msg_disconnect; - session->ssh_msg_disconnect = callback; + oldcb = (libssh2_cb_generic *)session->ssh_msg_disconnect; + session->ssh_msg_disconnect = (LIBSSH2_DISCONNECT_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_MACERROR: - oldcb = session->macerror; - session->macerror = callback; + oldcb = (libssh2_cb_generic *)session->macerror; + session->macerror = (LIBSSH2_MACERROR_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_X11: - oldcb = session->x11; - session->x11 = callback; + oldcb = (libssh2_cb_generic *)session->x11; + session->x11 = (LIBSSH2_X11_OPEN_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_SEND: - oldcb = session->send; - session->send = callback; + oldcb = (libssh2_cb_generic *)session->send; + session->send = (LIBSSH2_SEND_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_RECV: - oldcb = session->recv; - session->recv = callback; + oldcb = (libssh2_cb_generic *)session->recv; + session->recv = (LIBSSH2_RECV_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_AUTHAGENT: - oldcb = session->authagent; - session->authagent = callback; + oldcb = (libssh2_cb_generic *)session->authagent; + session->authagent = (LIBSSH2_AUTHAGENT_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_AUTHAGENT_IDENTITIES: - oldcb = session->addLocalIdentities; - session->addLocalIdentities = callback; + oldcb = (libssh2_cb_generic *)session->addLocalIdentities; + session->addLocalIdentities = + (LIBSSH2_ADD_IDENTITIES_FUNC((*)))callback; return oldcb; case LIBSSH2_CALLBACK_AUTHAGENT_SIGN: - oldcb = session->agentSignCallback; - session->agentSignCallback = callback; + oldcb = (libssh2_cb_generic *)session->agentSignCallback; + session->agentSignCallback = + (LIBSSH2_AUTHAGENT_SIGN_FUNC((*)))callback; return oldcb; } _libssh2_debug((session, LIBSSH2_TRACE_TRANS, "Setting Callback %d", @@ -555,6 +551,33 @@ libssh2_session_callback_set(LIBSSH2_SESSION * session, return NULL; } + +/* + * libssh2_session_callback_set (DEPRECATED, DO NOT USE!) + * + * Set (or reset) a callback function + * Returns the prior address + * + * ALERT: this function relies on that we can typecast function pointers + * to void pointers, which isn't allowed in ISO C! + */ +#ifdef _MSC_VER +#pragma warning(push) +/* 'type cast': from data pointer to function pointer */ +#pragma warning(disable:4054) +/* 'type cast': from function pointer to data pointer */ +#pragma warning(disable:4055) +#else +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" +#endif +LIBSSH2_API void * +libssh2_session_callback_set(LIBSSH2_SESSION * session, + int cbtype, void *callback) +{ + return (void *)libssh2_session_callback_set2(session, cbtype, + (libssh2_cb_generic *)callback); +} #ifdef _MSC_VER #pragma warning(pop) #else @@ -670,6 +693,18 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t start_time) "Timed out waiting on socket"); } if(rc < 0) { + int err; +#ifdef _WIN32 + err = _libssh2_wsa2errno(); +#else + err = errno; +#endif + /* Profiling tools that use SIGPROF can cause EINTR responses. + poll() / select() do not set any descriptor states on EINTR, + but some fds may be ready, so the caller should try again */ + if(err == EINTR) + return 0; + return _libssh2_error(session, LIBSSH2_ERROR_TIMEOUT, "Error waiting on socket"); } @@ -684,7 +719,7 @@ session_startup(LIBSSH2_SESSION *session, libssh2_socket_t sock) if(session->startup_state == libssh2_NB_state_idle) { _libssh2_debug((session, LIBSSH2_TRACE_TRANS, - "session_startup for socket %d", sock)); + "session_startup for socket %ld", (long)sock)); if(LIBSSH2_INVALID_SOCKET == sock) { /* Did we forget something? */ return _libssh2_error(session, LIBSSH2_ERROR_BAD_SOCKET, @@ -830,6 +865,7 @@ libssh2_session_handshake(LIBSSH2_SESSION *session, libssh2_socket_t sock) return rc; } +#ifndef LIBSSH2_NO_DEPRECATED /* * libssh2_session_startup * @@ -846,6 +882,7 @@ libssh2_session_startup(LIBSSH2_SESSION *session, int sock) { return libssh2_session_handshake(session, (libssh2_socket_t) sock); } +#endif /* * session_free @@ -864,8 +901,8 @@ session_free(LIBSSH2_SESSION *session) if(session->free_state == libssh2_NB_state_idle) { _libssh2_debug((session, LIBSSH2_TRACE_TRANS, - "Freeing session resource", - session->remote.banner)); + "Freeing session resource %p", + (void *)session->remote.banner)); session->free_state = libssh2_NB_state_created; } @@ -1188,6 +1225,7 @@ libssh2_session_disconnect_ex(LIBSSH2_SESSION *session, int reason, const char *desc, const char *lang) { int rc; + session->state &= ~LIBSSH2_STATE_INITIAL_KEX; session->state &= ~LIBSSH2_STATE_EXCHANGING_KEYS; BLOCK_ADJUST(rc, session, session_disconnect(session, reason, desc, lang)); @@ -1773,7 +1811,11 @@ libssh2_poll(LIBSSH2_POLLFD * fds, unsigned int nfds, long timeout) } #elif defined(HAVE_SELECT) tv.tv_sec = timeout_remaining / 1000; +#ifdef libssh2_usec_t + tv.tv_usec = (libssh2_usec_t)((timeout_remaining % 1000) * 1000); +#else tv.tv_usec = (timeout_remaining % 1000) * 1000; +#endif { struct timeval tv_begin, tv_end; diff --git a/libs/libssh2/src/session.h b/libs/libssh2/src/session.h index bfc9b545b8..d4fc5755e5 100644 --- a/libs/libssh2/src/session.h +++ b/libs/libssh2/src/session.h @@ -1,5 +1,5 @@ -#ifndef __LIBSSH2_SESSION_H -#define __LIBSSH2_SESSION_H +#ifndef LIBSSH2_SESSION_H +#define LIBSSH2_SESSION_H /* Copyright (C) Sara Golemon <sarag@libssh2.org> * Copyright (C) Daniel Stenberg * Copyright (C) Simon Josefsson <simon@josefsson.org> @@ -91,4 +91,4 @@ int _libssh2_wait_socket(LIBSSH2_SESSION *session, time_t entry_time); /* this is the lib-internal set blocking function */ int _libssh2_session_set_blocking(LIBSSH2_SESSION * session, int blocking); -#endif /* __LIBSSH2_SESSION_H */ +#endif /* LIBSSH2_SESSION_H */ diff --git a/libs/libssh2/src/sftp.c b/libs/libssh2/src/sftp.c index 16ee7b8689..f8f1323e02 100644 --- a/libs/libssh2/src/sftp.c +++ b/libs/libssh2/src/sftp.c @@ -152,7 +152,7 @@ remove_zombie_request(LIBSSH2_SFTP *sftp, uint32_t request_id) request_id); if(zombie) { _libssh2_debug((session, LIBSSH2_TRACE_SFTP, - "Removing request ID %ld from the list of " + "Removing request ID %u from the list of " "zombie requests", request_id)); @@ -169,13 +169,13 @@ add_zombie_request(LIBSSH2_SFTP *sftp, uint32_t request_id) struct sftp_zombie_requests *zombie; _libssh2_debug((session, LIBSSH2_TRACE_SFTP, - "Marking request ID %ld as a zombie request", request_id)); + "Marking request ID %u as a zombie request", request_id)); zombie = LIBSSH2_ALLOC(sftp->channel->session, sizeof(struct sftp_zombie_requests)); if(!zombie) return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, - "malloc fail for zombie request ID"); + "malloc fail for zombie request ID"); else { zombie->request_id = request_id; _libssh2_list_add(&sftp->zombie_requests, &zombie->node); @@ -199,8 +199,8 @@ sftp_packet_add(LIBSSH2_SFTP *sftp, unsigned char *data, } _libssh2_debug((session, LIBSSH2_TRACE_SFTP, - "Received packet type %d (len %d)", - (int) data[0], data_len)); + "Received packet type %u (len %lu)", + (unsigned int)data[0], (unsigned long)data_len)); /* * Experience shows that if we mess up EAGAIN handling somewhere or @@ -306,11 +306,11 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) packet = sftp->partial_packet; _libssh2_debug((session, LIBSSH2_TRACE_SFTP, - "partial read cont, len: %lu", sftp->partial_len)); + "partial read cont, len: %u", sftp->partial_len)); _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "partial read cont, already recvd: %lu", - sftp->partial_received)); - /* fall-through */ + (unsigned long)sftp->partial_received)); + LIBSSH2_FALLTHROUGH(); default: if(!packet) { /* only do this if there's not already a packet buffer allocated @@ -359,7 +359,7 @@ sftp_packet_read(LIBSSH2_SFTP *sftp) _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Data begin - Packet Length: %lu", - sftp->partial_len)); + (unsigned long)sftp->partial_len)); packet = LIBSSH2_ALLOC(session, sftp->partial_len); if(!packet) return _libssh2_error(session, LIBSSH2_ERROR_ALLOC, @@ -526,13 +526,13 @@ sftp_packet_require(LIBSSH2_SFTP *sftp, unsigned char packet_type, return LIBSSH2_ERROR_BAD_USE; } - _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Requiring packet %d id %ld", - (int) packet_type, request_id)); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Requiring packet %u id %u", + (unsigned int) packet_type, request_id)); if(sftp_packet_ask(sftp, packet_type, request_id, data, data_len) == 0) { /* The right packet was available in the packet brigade */ - _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Got %d", - (int) packet_type)); + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Got %u", + (unsigned int) packet_type)); if(*data_len < required_size) { return LIBSSH2_ERROR_BUFFER_TOO_SMALL; @@ -550,7 +550,7 @@ sftp_packet_require(LIBSSH2_SFTP *sftp, unsigned char packet_type, if(!sftp_packet_ask(sftp, packet_type, request_id, data, data_len)) { /* The right packet was available in the packet brigade */ _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "Got %d", - (int) packet_type)); + (unsigned int) packet_type)); if(*data_len < required_size) { return LIBSSH2_ERROR_BUFFER_TOO_SMALL; @@ -979,12 +979,12 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) if(sftp_handle->version > LIBSSH2_SFTP_VERSION) { _libssh2_debug((session, LIBSSH2_TRACE_SFTP, - "Truncating remote SFTP version from %lu", + "Truncating remote SFTP version from %u", sftp_handle->version)); sftp_handle->version = LIBSSH2_SFTP_VERSION; } _libssh2_debug((session, LIBSSH2_TRACE_SFTP, - "Enabling SFTP version %lu compatibility", + "Enabling SFTP version %u compatibility", sftp_handle->version)); while(buf.dataptr < endp) { unsigned char *extname, *extdata; @@ -1567,10 +1567,11 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, more packets */ count -= LIBSSH2_MIN(size, count); _libssh2_debug((session, LIBSSH2_TRACE_SFTP, - "read request id %d sent (offset: %d, size: %d)", - request_id, (int)chunk->offset, (int)chunk->len)); + "read request id %d sent (offset: %lu, size: %lu)", + request_id, (unsigned long)chunk->offset, + (unsigned long)chunk->len)); } - /* FALL-THROUGH */ + LIBSSH2_FALLTHROUGH(); case libssh2_NB_state_sent: sftp->read_state = libssh2_NB_state_idle; @@ -1610,7 +1611,7 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, /* move on to the next chunk with data to send */ chunk = _libssh2_list_next(&chunk->node); } - /* FALL-THROUGH */ + LIBSSH2_FALLTHROUGH(); case libssh2_NB_state_sent2: @@ -1690,7 +1691,6 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, return _libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL, "SFTP READ error"); } - break; case SSH_FXP_DATA: if(chunk->offset != filep->offset) { @@ -1922,8 +1922,8 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, end: _libssh2_debug((session, LIBSSH2_TRACE_SFTP, - "libssh2_sftp_readdir_ex() return %d", - filename_len)); + "libssh2_sftp_readdir_ex() return %lu", + (unsigned long)filename_len)); return (ssize_t)filename_len; } @@ -2003,7 +2003,7 @@ end: sftp->readdir_state = libssh2_NB_state_idle; num_names = _libssh2_ntohu32(data + 5); - _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "%lu entries returned", + _libssh2_debug((session, LIBSSH2_TRACE_SFTP, "%u entries returned", num_names)); if(!num_names) { LIBSSH2_FREE(session, data); @@ -2185,7 +2185,8 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer, chunk = _libssh2_list_next(&chunk->node); } - /* fall-through */ + LIBSSH2_FALLTHROUGH(); + case libssh2_NB_state_sent: sftp->write_state = libssh2_NB_state_idle; diff --git a/libs/libssh2/src/sftp.h b/libs/libssh2/src/sftp.h index 647ddbc007..267c8fef0d 100644 --- a/libs/libssh2/src/sftp.h +++ b/libs/libssh2/src/sftp.h @@ -1,5 +1,5 @@ -#ifndef __LIBSSH2_SFTP_H -#define __LIBSSH2_SFTP_H +#ifndef LIBSSH2_SFTP_PRIV_H +#define LIBSSH2_SFTP_PRIV_H /* * Copyright (C) Daniel Stenberg * All rights reserved. @@ -233,4 +233,4 @@ struct _LIBSSH2_SFTP uint32_t symlink_request_id; }; -#endif /* __LIBSSH2_SFTP_H */ +#endif /* LIBSSH2_SFTP_PRIV_H */ diff --git a/libs/libssh2/src/transport.c b/libs/libssh2/src/transport.c index c73b859e4d..531f5aa15a 100644 --- a/libs/libssh2/src/transport.c +++ b/libs/libssh2/src/transport.c @@ -51,9 +51,6 @@ #include "transport.h" #include "mac.h" -#define MAX_BLOCKSIZE 32 /* MUST fit biggest crypto block size we use/get */ -#define MAX_MACSIZE 64 /* MUST fit biggest MAC length we support */ - #ifdef LIBSSH2DEBUG #define UNPRINTABLE_CHAR '.' static void @@ -72,8 +69,8 @@ debugdump(LIBSSH2_SESSION * session, return; } - used = snprintf(buffer, sizeof(buffer), "=> %s (%d bytes)\n", - desc, (int) size); + used = snprintf(buffer, sizeof(buffer), "=> %s (%lu bytes)\n", + desc, (unsigned long) size); if(session->tracehandler) (session->tracehandler)(session, session->tracehandler_context, buffer, used); @@ -189,6 +186,7 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ ) struct transportpacket *p = &session->packet; int rc; int compressed; + uint32_t seq = session->remote.seqno; if(session->fullpacket_state == libssh2_NB_state_idle) { session->fullpacket_macstate = LIBSSH2_MAC_CONFIRMED; @@ -320,7 +318,7 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ ) if(session->fullpacket_state == libssh2_NB_state_created) { rc = _libssh2_packet_add(session, p->payload, session->fullpacket_payload_len, - session->fullpacket_macstate); + session->fullpacket_macstate, seq); if(rc == LIBSSH2_ERROR_EAGAIN) return rc; if(rc) { @@ -331,6 +329,11 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ ) session->fullpacket_state = libssh2_NB_state_idle; + if(session->kex_strict && + session->fullpacket_packet_type == SSH_MSG_NEWKEYS) { + session->remote.seqno = 0; + } + return session->fullpacket_packet_type; } @@ -467,13 +470,15 @@ int _libssh2_transport_read(LIBSSH2_SESSION * session) return LIBSSH2_ERROR_EAGAIN; } _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Error recving %d bytes (got %d)", - PACKETBUFSIZE - remainbuf, -nread)); + "Error recving %ld bytes (got %ld)", + (long)(PACKETBUFSIZE - remainbuf), + (long)-nread)); return LIBSSH2_ERROR_SOCKET_RECV; } _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Recved %d/%d bytes to %p+%d", nread, - PACKETBUFSIZE - remainbuf, p->buf, remainbuf)); + "Recved %ld/%ld bytes to %p+%ld", (long)nread, + (long)(PACKETBUFSIZE - remainbuf), (void *)p->buf, + (long)remainbuf)); debugdump(session, "libssh2_transport_read() raw", &p->buf[remainbuf], nread); @@ -790,11 +795,12 @@ send_existing(LIBSSH2_SESSION *session, const unsigned char *data, LIBSSH2_SOCKET_SEND_FLAGS(session)); if(rc < 0) _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Error sending %d bytes: %d", length, -rc)); + "Error sending %ld bytes: %ld", + (long)length, (long)-rc)); else { _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Sent %d/%d bytes at %p+%d", rc, length, p->outbuf, - p->osent)); + "Sent %ld/%ld bytes at %p+%lu", (long)rc, (long)length, + (void *)p->outbuf, (unsigned long)p->osent)); debugdump(session, "libssh2_transport_write send()", &p->outbuf[p->osent], rc); } @@ -1022,10 +1028,12 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, INTEGRATED_MAC case, where the crypto algorithm also does its own hash. */ if(!etm && !CRYPT_FLAG_R(session, INTEGRATED_MAC)) { - session->local.mac->hash(session, p->outbuf + packet_length, - session->local.seqno, p->outbuf, - packet_length, NULL, 0, - &session->local.mac_abstract); + if(session->local.mac->hash(session, p->outbuf + packet_length, + session->local.seqno, p->outbuf, + packet_length, NULL, 0, + &session->local.mac_abstract)) + return _libssh2_error(session, LIBSSH2_ERROR_MAC_FAILURE, + "Failed to calculate MAC"); } /* Encrypt the whole packet data, one block size at a time. @@ -1058,8 +1066,8 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, i += bsize - session->local.crypt->blocksize; } _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "crypting bytes %d-%d", i, - i + session->local.crypt->blocksize - 1)); + "crypting bytes %lu-%lu", (unsigned long)i, + (unsigned long)(i + bsize - 1))); if(session->local.crypt->crypt(session, ptr, bsize, &session->local.crypt_abstract, @@ -1084,24 +1092,31 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, calculated on the entire packet (length plain the rest encrypted), including all fields except the MAC field itself. */ - session->local.mac->hash(session, p->outbuf + packet_length, - session->local.seqno, p->outbuf, - packet_length, NULL, 0, - &session->local.mac_abstract); + if(session->local.mac->hash(session, p->outbuf + packet_length, + session->local.seqno, p->outbuf, + packet_length, NULL, 0, + &session->local.mac_abstract)) + return _libssh2_error(session, LIBSSH2_ERROR_MAC_FAILURE, + "Failed to calculate MAC"); } } session->local.seqno++; + if(session->kex_strict && data[0] == SSH_MSG_NEWKEYS) { + session->local.seqno = 0; + } + ret = LIBSSH2_SEND(session, p->outbuf, total_length, LIBSSH2_SOCKET_SEND_FLAGS(session)); if(ret < 0) _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Error sending %d bytes: %d", total_length, -ret)); + "Error sending %ld bytes: %ld", + (long)total_length, (long)-ret)); else { _libssh2_debug((session, LIBSSH2_TRACE_SOCKET, - "Sent %d/%d bytes at %p", - ret, total_length, p->outbuf)); + "Sent %ld/%ld bytes at %p", + (long)ret, (long)total_length, (void *)p->outbuf)); debugdump(session, "libssh2_transport_write send()", p->outbuf, ret); } diff --git a/libs/libssh2/src/transport.h b/libs/libssh2/src/transport.h index 64482290ee..4b824e2096 100644 --- a/libs/libssh2/src/transport.h +++ b/libs/libssh2/src/transport.h @@ -1,5 +1,5 @@ -#ifndef __LIBSSH2_TRANSPORT_H -#define __LIBSSH2_TRANSPORT_H +#ifndef LIBSSH2_TRANSPORT_H +#define LIBSSH2_TRANSPORT_H /* Copyright (C) The Written Word, Inc. * Copyright (C) Daniel Stenberg * All rights reserved. @@ -84,4 +84,4 @@ int _libssh2_transport_send(LIBSSH2_SESSION *session, */ int _libssh2_transport_read(LIBSSH2_SESSION * session); -#endif /* __LIBSSH2_TRANSPORT_H */ +#endif /* LIBSSH2_TRANSPORT_H */ diff --git a/libs/libssh2/src/userauth.c b/libs/libssh2/src/userauth.c index e7578759f3..60fd48e47d 100644 --- a/libs/libssh2/src/userauth.c +++ b/libs/libssh2/src/userauth.c @@ -818,11 +818,17 @@ struct privkey_file { const char *passphrase; }; +struct privkey_mem { + const char *passphrase; + const char *data; + size_t data_len; +}; + static int sign_frommemory(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, const unsigned char *data, size_t data_len, void **abstract) { - struct privkey_file *pk_file = (struct privkey_file *) (*abstract); + struct privkey_mem *pk_mem = (struct privkey_mem *) (*abstract); const LIBSSH2_HOSTKEY_METHOD *privkeyobj; void *hostkey_abstract; struct iovec datavec; @@ -831,9 +837,9 @@ sign_frommemory(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, rc = memory_read_privatekey(session, &privkeyobj, &hostkey_abstract, session->userauth_pblc_method, session->userauth_pblc_method_len, - pk_file->filename, - strlen(pk_file->filename), - pk_file->passphrase); + pk_mem->data, + pk_mem->data_len, + pk_mem->passphrase); if(rc) return rc; @@ -1410,7 +1416,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, LIBSSH2_FREE(session, *key_method); *key_method = LIBSSH2_ALLOC(session, match_len); - if(key_method) { + if(*key_method) { memcpy(*key_method, match, match_len); *key_method_len = match_len; } @@ -1511,7 +1517,7 @@ retry_auth: _libssh2_debug((session, LIBSSH2_TRACE_KEX, "Signing using %.*s", - session->userauth_pblc_method_len, + (int)session->userauth_pblc_method_len, session->userauth_pblc_method)); } @@ -1835,12 +1841,13 @@ userauth_publickey_frommemory(LIBSSH2_SESSION *session, { unsigned char *pubkeydata = NULL; size_t pubkeydata_len = 0; - struct privkey_file privkey_file; - void *abstract = &privkey_file; + struct privkey_mem privkey_mem; + void *abstract = &privkey_mem; int rc; - privkey_file.filename = privatekeydata; - privkey_file.passphrase = passphrase; + privkey_mem.data = privatekeydata; + privkey_mem.data_len = privatekeydata_len; + privkey_mem.passphrase = passphrase; if(session->userauth_pblc_state == libssh2_NB_state_idle) { if(publickeydata_len && publickeydata) { diff --git a/libs/libssh2/src/userauth.h b/libs/libssh2/src/userauth.h index 24f8037ec2..2f53ac5be9 100644 --- a/libs/libssh2/src/userauth.h +++ b/libs/libssh2/src/userauth.h @@ -1,5 +1,5 @@ -#ifndef __LIBSSH2_USERAUTH_H -#define __LIBSSH2_USERAUTH_H +#ifndef LIBSSH2_USERAUTH_H +#define LIBSSH2_USERAUTH_H /* Copyright (C) Sara Golemon <sarag@libssh2.org> * Copyright (C) Daniel Stenberg * All rights reserved. @@ -50,4 +50,4 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, ((*sign_callback)), void *abstract); -#endif /* __LIBSSH2_USERAUTH_H */ +#endif /* LIBSSH2_USERAUTH_H */ diff --git a/libs/libssh2/src/userauth_kbd_packet.h b/libs/libssh2/src/userauth_kbd_packet.h index bee34495e1..56e88b3f32 100644 --- a/libs/libssh2/src/userauth_kbd_packet.h +++ b/libs/libssh2/src/userauth_kbd_packet.h @@ -37,9 +37,9 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef __LIBSSH2_USERAUTH_KBD_PARSE_H -#define __LIBSSH2_USERAUTH_KBD_PARSE_H +#ifndef LIBSSH2_USERAUTH_KBD_PACKET_H +#define LIBSSH2_USERAUTH_KBD_PACKET_H int userauth_keyboard_interactive_decode_info_request(LIBSSH2_SESSION *); -#endif /* __LIBSSH2_USERAUTH_KBD_PARSE_H */ +#endif /* LIBSSH2_USERAUTH_KBD_PACKET_H */ |