1
0
mirror of https://github.com/libssh2/libssh2.git synced 2025-08-07 08:02:56 +03:00
Commit Graph

2997 Commits

Author SHA1 Message Date
Laurent Stacul
f1f47ef79b tests: Makefile.am: Add missing tests client keys in distribution tarball (#604)
Notes:
Added missing test keys.

Credit:
Laurent Stacul
2021-05-18 08:18:06 -07:00
Laurent Stacul
62bc25c987 Makefile.am: Add missing test keys in the distribution tarball (#601)
Notes: 
Fix tests missing key to build the OCI image

Credit:
Laurent Stacul
2021-05-17 09:11:10 -07:00
Daniel Stenberg
8adbab3f6c dist: add src/agent.h
Fixes #597
Closes #599
2021-05-16 00:08:39 +02:00
Will Cosgrove
36fcd543d9 packet.c: Reset read timeout after received a packet (#576) (#586)
File:
packet.c

Notes:
Attempt keyboard interactive login (Azure AD 2FA login) and use more than 60 seconds to complete the login, the connection fails.

The _libssh2_packet_require function does almost the same as _libssh2_packet_requirev but this function sets state->start = 0 before returning.

Credit:
teottin, Co-authored-by: Tor Erik Ottinsen <tor.ottinsen@kdi.kongsberg.com>
2021-05-12 09:14:09 -07:00
kkoenig
3f9d505353 Support ECDSA certificate authentication (#570)
Files: hostkey.c, userauth.c, test_public_key_auth_succeeds_with_correct_ecdsa_key.c

Notes:
Support ECDSA certificate authentication

Add a test for:
  - Existing ecdsa basic public key authentication
  - ecdsa public key authentication with a signed public key

Credit:
kkoenig
2021-05-12 09:13:19 -07:00
Gabriel Smith
c998f79384 agent.c: Add support for Windows OpenSSH agent (#517)
Files: agent.c, agent.h, agent_win.c

Notes:
* agent: Add support for Windows OpenSSH agent

The implementation was partially taken and modified from that found in
the Portable OpenSSH port to Win32 by the PowerShell team, but mostly
based on the existing Unix OpenSSH agent support.

https://github.com/PowerShell/openssh-portable

Regarding the partial transfer support implementation: partial transfers
are easy to deal with, but you need to track additional state when
non-blocking IO enters the picture. A tracker of how many bytes have
been transfered has been placed in the transfer context struct as that's
where it makes most sense. This tracker isn't placed behind a WIN32
 #ifdef as it will probably be useful for other agent implementations.

* agent: win32 openssh: Disable overlapped IO

Non-blocking IO is not currently supported by the surrounding agent
code, despite a lot of the code having everything set up to handle it.

Credit:
Co-authored-by: Gabriel Smith <gabriel.smith@precisionot.com>
2021-05-11 14:13:37 -07:00
Zenju
58ae048c92 Fix detailed _libssh2_error being overwritten (#473)
Files: openssl.c, pem.c, userauth.c

Notes:
* Fix detailed _libssh2_error being overwritten by generic errors
* Unified error handling

Credit:
Zenju
2021-05-11 14:09:57 -07:00
Paul Capron
b3a8a6d27c Fix _libssh2_random() silently discarding errors (#520)
Notes:
* Make _libssh2_random return code consistent

Previously, _libssh2_random was advertized in HACKING.CRYPTO as
returning `void` (and was implemented that way in os400qc3.c), but that
was in other crypto backends a lie; _libssh2_random is (a macro
expanding) to an int-value expression or function.

Moreover, that returned code was:
  — 0 or success, -1 on error for the MbedTLS & WinCNG crypto backends
But also:
  — 1 on success, -1 or 0 on error for the OpenSSL backend!
  – 1 on success, error cannot happen for libgcrypt!

This commit makes explicit that _libssh2_random can fail (because most of
the underlying crypto functions can indeed fail!), and it makes its result
code consistent: 0 on success, -1 on error.

This is related to issue #519 https://github.com/libssh2/libssh2/issues/519
It fixes the first half of it.

* Don't silent errors of _libssh2_random

Make sure to check the returned code of _libssh2_random(), and
propagates any failure.

A new LIBSSH_ERROR_RANDGEN constant is added to libssh2.h
None of the existing error constants seemed fit.

This commit is related to d74285b684
and to https://github.com/libssh2/libssh2/issues/519 (see the issue
for more info.)  It closes #519.

Credit:
Paul Capron
2021-05-11 14:06:18 -07:00
Gabriel Smith
1270fdfe4b ci: Remove caching of docker image layers (#589)
Notes:
continued ci reliability work.

Credit:
Gabriel Smith
2021-05-11 13:44:12 -07:00
Gabriel Smith
92366cdb79 ci: Speed up docker builds for tests (#587)
Notes:
The OpenSSH server docker image used for tests is pre-built to prevent
wasting time building it during a test, and unneeded rebuilds are
prevented by caching the image layers.

Credit:
Gabriel Smith
2021-05-04 09:16:54 -07:00
Will Cosgrove
7118582a7c userauth.c: don't error if using keys without RSA (#555)
file: userauth.c

notes: libssh2 now supports many other key types besides RSA, if the library is built without RSA support and a user attempts RSA auth it shouldn't be an automatic error

credit: 
Will Cosgrove
2021-05-03 14:49:53 -07:00
Marc
b853d7a86e openssl.c: Avoid OpenSSL latent error in FIPS mode (#528)
File:
openssl.c

Notes:
Avoid initing MD5 digest, which is not permitted in OpenSSL FIPS certified cryptography mode.

Credit:
Marc
2021-05-03 14:49:02 -07:00
Laurent Stacul
35695772d0 openssl.c: Fix EVP_Cipher interface change in openssl 3 #463
File:
openssl.c

Notes:
Fixes building with OpenSSL 3, #463.

The change is described there:
f7397f0d58

Credit:
Laurent Stacul, reported by Sergei
2021-05-03 14:47:06 -07:00
Gabriel Smith
b5c071d180 openssh_fixture.c: Fix potential overwrite of buffer when reading stdout of command (#580)
File:
openssh_fixture.c 
Notes:
If reading the full output from the executed command took multiple
passes (such as when reading multiple lines) the old code would read
into the buffer starting at the some position (the start) every time.
The old code only works if fgets updated p or had an offset parameter,
both of which are not true.

Credit:
Gabriel Smith
2021-05-03 14:41:25 -07:00
Gabriel Smith
fb375d6fe2 ci: explicitly state the default branch (#585)
Notes:
It looks like the $default-branch macro only works in templates, not
workflows. This is not explicitly stated anywhere except the linked PR
comment.

https://github.com/actions/starter-workflows/pull/590#issuecomment-672360634

credit:
Gabriel Smith
2021-05-02 17:32:48 -07:00
Gabriel Smith
ee199144fe ci: Swap from Travis to Github Actions (#581)
Files: ci files

Notes:
Move Linux CI using Github Actions

Credit:
Gabriel Smith, Marc Hörsken
2021-04-30 16:10:52 -07:00
Mary
91393d6631 libssh2_priv.h: add iovec on 3ds (#575)
file: libssh2_priv.h
note: include iovec for 3DS
credit: Mary Mstrodl
2021-04-22 13:20:43 -07:00
Laurent Stacul
5627b82be6 Tests: Fix unused variables warning (#561)
file: test_public_key_auth_succeeds_with_correct_ed25519_key_from_mem.c

notes: fixed unused vars

credit:
Laurent Stacul
2021-03-04 14:17:00 -08:00
Viktor Szakats
4bb166a2a8 bcrypt_pbkdf.c: fix clang10 false positive warning (#563)
File: bcrypt_pbkdf.c

Notes:
blf_enc() takes a number of 64-bit blocks to encrypt, but using
sizeof(uint64_t) in the calculation triggers a warning with
clang 10 because the actual data type is uint32_t. Pass
BCRYPT_BLOCKS / 2 for the number of blocks like libc bcrypt(3)
does.

Ref: 04a2240bd8

Fixes #562

Credit:
Viktor Szakats
2021-03-04 13:10:07 -08:00
Will Cosgrove
ae26886671 transport.c: release payload on error (#554)
file: transport.c
notes: If the payload is invalid and there is an early return, we could leak the payload
credit:
Will Cosgrove
2021-02-11 09:18:16 -08:00
Will Cosgrove
8ae21cad83 ssh2_client_fuzzer.cc: fixed building
The GitHub web editor did some funky things
2021-02-05 10:05:52 -08:00
Will Cosgrove
384a50e0e4 ssh_client_fuzzer.cc: set blocking mode on (#553)
file: ssh_client_fuzzer.cc

notes: the session needs blocking mode turned on to avoid EAGAIN being returned from libssh2_session_handshake()

credit:
Will Cosgrove, reviewed by Michael Buckley
2021-02-04 09:56:16 -08:00
Etienne Samson
1adb24fd07 Add a LINT option to CMake (#372)
* ci: make style-checking available locally

* cmake: add a linting target

* tests: check test suite syntax with checksrc.pl
2021-02-02 10:28:28 -08:00
Will Cosgrove
cde13f6201 kex.c: kex_agree_instr() improve string reading (#552)
* kex.c: kex_agree_instr() improve string reading

file: kex.c
notes: if haystack isn't null terminated we should use memchr() not strchar(). We should also make sure we don't walk off the end of the buffer.
credit: 
Will Cosgrove, reviewed by Michael Buckley
2021-02-02 10:11:14 -08:00
Will Cosgrove
c69f1f27dc kex.c: use string_buf in ecdh_sha2_nistp (#551)
* kex.c: use string_buf in ecdh_sha2_nistp

file: kex.c

notes:
use string_buf in ecdh_sha2_nistp() to avoid attempting to parse malformed data
2021-01-30 19:32:14 -08:00
Will Cosgrove
1f76151c92 kex.c: move EC macro outside of if check #549 (#550)
File: kex.c

Notes:
Moved the macro LIBSSH2_KEX_METHOD_EC_SHA_HASH_CREATE_VERIFY outside of the LIBSSH2_ECDSA since it's also now used by the ED25519 code.

Sha 256, 384 and 512 need to be defined for all backends now even if they aren't used directly. I believe this is already the case, but just a heads up.

Credit:
Stefan-Ghinea
2021-01-26 11:41:21 -08:00
Tim Gates
720998f322 kex.c: fix simple typo, niumber -> number (#545)
File: kex.c

Notes:
There is a small typo in src/kex.c.

Should read `number` rather than `niumber`.

Credit:
Tim Gates
2020-12-18 09:58:29 -08:00
Tseng Jun
cfe0bf6498 session.c: Correct a typo which may lead to stack overflow (#533)
File: session.c

Notes:
Seems the author intend to terminate banner_dup buffer, later, print it to the debug console.

Author:
Tseng Jun
2020-11-11 11:18:36 -08:00
Marc Hoersken
6c7769dcc4 wincng: fix random big number generation to match openssl
The old function would set the least significant bits in
the most significant byte instead of the most significant bits.

The old function would also zero pad too much bits in the
most significant byte. This lead to a reduction of key space
in the most significant byte according to the following listing:
- 8 bits reduced to 0 bits => eg. 2048 bits to 2040 bits DH key
- 7 bits reduced to 1 bits => eg. 2047 bits to 2041 bits DH key
- 6 bits reduced to 2 bits => eg. 2046 bits to 2042 bits DH key
- 5 bits reduced to 3 bits => eg. 2045 bits to 2043 bits DH key

No change would occur for the case of 4 significant bits.
For 1 to 3 significant bits in the most significant byte
the DH key would actually be expanded instead of reduced:
- 3 bits expanded to 5 bits => eg. 2043 bits to 2045 bits DH key
- 2 bits expanded to 6 bits => eg. 2042 bits to 2046 bits DH key
- 1 bits expanded to 7 bits => eg. 2041 bits to 2047 bits DH key

There is no case of 0 significant bits in the most significant byte
since this would be a case of 8 significant bits in the next byte.

At the moment only the following case applies due to a fixed
DH key size value currently being used in libssh2:

The DH group_order is fixed to 256 (bytes) which leads to a
2047 bits DH key size by calculating (256 * 8) - 1.

This means the DH keyspace was previously reduced from 2047 bits
to 2041 bits (while the top and bottom bits are always set), so the
keyspace is actually always reduced from 2045 bits to 2039 bits.

All of this is only relevant for Windows versions supporting the
WinCNG backend (Vista or newer) before Windows 10 version 1903.

Closes #521
2020-10-10 19:58:06 +02:00
Daniel Stenberg
4afcb8cd9b libssh2_session_callback_set.3: explain the recv/send callbacks
Describe how to actually use these callbacks.

Closes #518
2020-09-28 17:45:13 +02:00
Will Cosgrove
00d5b0c385 agent.c: formatting
Improved formatting of RECV_SEND_ALL macro.
2020-09-23 13:41:34 -07:00
Will Cosgrove
a1975c5b59 CMakeLists.txt: respect install lib dir #405 (#515)
Files:
CMakeLists.txt

Notes:
Use CMAKE_INSTALL_LIBDIR directory

Credit: Arfrever
2020-09-23 13:21:11 -07:00
Will Cosgrove
f553dcc95d kex.c: group16-sha512 and group18-sha512 support #457 (#468)
Files: kex.c

Notes:
Added key exchange group16-sha512 and group18-sha512. As a result did the following:

Abstracted diffie_hellman_sha256() to diffie_hellman_sha_algo() which is now algorithm agnostic and takes the algorithm as a parameter since we needed sha512 support. Unfortunately it required some helper functions but they are simple.
Deleted diffie_hellman_sha1()
Deleted diffie_hellman_sha1 specific macro
Cleaned up some formatting
Defined sha384 in os400 and wincng backends
Defined LIBSSH2_DH_MAX_MODULUS_BITS to abort the connection if we receive too large of p from the server doing sha1 key exchange.
Reorder the default key exchange list to match OpenSSH and improve security

Credit:
Will Cosgrove
2020-09-23 13:20:00 -07:00
Igor Klevanets
9ae9ff30cb agent.c: Recv and send all bytes via network in agent_transact_unix() (#510)
Files: agent.c

Notes:
Handle sending/receiving partial packet replies in agent.c API.

Credit: Klevanets Igor <cerevra@yandex-team.ru>
2020-09-23 13:15:01 -07:00
Daniel Stenberg
ecd6a74e44 Makefile.am: include all test files in the dist #379
File:
Makefile.am

Notes:
No longer conditionally include OpenSSL specific test files, they aren't run if we're not building against OpenSSL 1.1.x anyway.

Credit:
Daniel Stenberg
2020-09-01 16:40:48 -07:00
Max Dymond
7a4b051ba4 Add support for an OSS Fuzzer fuzzing target (#392)
Files:
.travis.yml, configure.ac, ossfuzz 

Notes:
This adds support for an OSS-Fuzz fuzzing target in ssh2_client_fuzzer,
which is a cut down example of ssh2.c. Future enhancements can improve
coverage.

Credit:
Max Dymond
2020-09-01 14:20:52 -07:00
Sebastián Katzer
5528f3da02 mbedtls.c: ECDSA support for mbed TLS (#385)
Files:
mbedtls.c, mbedtls.h, .travis.yml

Notes:
This PR adds support for ECDSA for both key exchange and host key algorithms.

The following elliptic curves are supported:

256-bit curve defined by FIPS 186-4 and SEC1
384-bit curve defined by FIPS 186-4 and SEC1
521-bit curve defined by FIPS 186-4 and SEC1

Credit:
Sebastián Katzer
2020-09-01 14:18:09 -07:00
Marc Hoersken
93862bf6c1 buildconf: exec autoreconf to avoid additional process (#512)
Also make buildconf exit with the return code of autoreconf.

Follow up to #224
2020-09-01 20:37:21 +02:00
Marc Hoersken
5964268dc7 scp.c: fix indentation in shell_quotearg documentation 2020-08-23 20:53:48 +02:00
Marc Hoersken
5eaa7aa1c0 wincng: make more use of new helper functions (#496) 2020-07-21 21:18:18 +02:00
Marc Hoersken
1894b30b5c wincng: make sure algorithm providers are closed once (#496) 2020-07-21 21:17:53 +02:00
David Benjamin
1a61d0c3ca openssl.c: clean up curve25519 code (#499)
File: openssl.c, openssl.h, crypto.h, kex.c

Notes:
This cleans up a few things in the curve25519 implementation:

- There is no need to create X509_PUBKEYs or PKCS8_PRIV_KEY_INFOs to
  extract key material. EVP_PKEY_get_raw_private_key and
  EVP_PKEY_get_raw_public_key work fine.

- libssh2_x25519_ctx was never used (and occasionally mis-typedefed to
  libssh2_ed25519_ctx). Remove it. The _libssh2_curve25519_new and
  _libssh2_curve25519_gen_k interfaces use the bytes. Note, if it needs
  to be added back, there is no need to roundtrip through
  EVP_PKEY_new_raw_private_key. EVP_PKEY_keygen already generated an
  EVP_PKEY.

- Add some missing error checks.

Credit:
David Benjamin
2020-07-10 10:47:48 -07:00
Will Cosgrove
ca9bb08908 transport.c: socket is disconnected, return error (#500)
File: transport.c

Notes:
This is to fix #102, instead of continuing to attempt to read a disconnected socket, it will now error out. 

Credit:
TDi-jonesds
2020-07-10 10:45:47 -07:00
Will Cosgrove
6b5fdf796b stale.yml
Increasing stale values.
2020-07-08 13:48:59 -07:00
Marc Hoersken
3baa367136 wincng: try newer DH API first, fallback to legacy RSA API
Avoid the use of RtlGetVersion or similar Win32 functions,
since these depend on version information from manifests.

This commit makes the WinCNG backend first try to use the
new DH algorithm API with the raw secret derivation feature.
In case this feature is not available the WinCNG backend
will fallback to the classic approach of using RSA-encrypt
to perform the required modular exponentiation of BigNums.

The feature availability test is done during the first handshake
and the result is stored in the crypto backends global state.

Follow up to #397
Closes #484
2020-07-06 20:46:48 +02:00
Marc Hoersken
8e6ae2855b wincng: fix indentation of function arguments and comments
Follow up to #397
2020-07-06 20:46:48 +02:00
Wez Furlong
7a26697ede wincng: use newer DH API for Windows 8.1+
Since Windows 1903 the approach used to perform DH kex with the CNG
API has been failing.

This commit switches to using the `DH` algorithm provider to perform
generation of the key pair and derivation of the shared secret.

It uses a feature of CNG that is not yet documented.  The sources of
information that I've found on this are:

* https://stackoverflow.com/a/56378698/149111
* 5d39011e63/mini/crypto/cng/dh.inl (L355)

With this change I am able to successfully connect from Windows 10 to my
ubuntu system.

Refs: https://github.com/alexcrichton/ssh2-rs/issues/122
Fixes: https://github.com/libssh2/libssh2/issues/388
Closes: https://github.com/libssh2/libssh2/pull/397
2020-07-06 20:46:48 +02:00
Zenju
0222603df5 comp.c: Fix name clash with ZLIB macro "compress" (#418)
File: comp.c

Notes:
* Fix name clash with ZLIB macro "compress". 

Credit:
Zenju
2020-07-01 11:55:29 -07:00
yann-morin-1998
fc5d77881e buildsystem: drop custom buildconf script, rely on autoreconf (#224)
Notes:
The buildconf script is currently required, because we need to copy a
header around, because it is used both from the library and the examples
sources.

However, having a custom 'buildconf'-like script is not needed if we can
ensure that the header exists by the time it is needed. For that, we can
just append the src/ directory to the headers search path for the
examples.

And then it means we no longer need to generate the same header twice,
so we remove the second one from configure.ac.

Now, we can just call "autoreconf -fi" to generate the autotools files,
instead of relying on the canned sequence in "buildconf", since
autoreconf has now long known what to do at the correct moment (future
versions of autotools, automake, autopoint, autoheader etc... may
require an other ordering, or other intermediate steps, etc...).

Eventually, get rid of buildconf now it is no longer needed. In fact, we
really keep it for legacy, but have it just call autoreconf (and print a
nice user-friendly warning). Don't include it in the release tarballs,
though.

Update doc, gitignore, and travis-CI jobs accordingly.

Credit:
Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: Sam Voss <sam.voss@rockwellcollins.com>
2020-07-01 11:44:08 -07:00
Will Cosgrove
1c3a03ebc3 libssh2.h: Update Diffie Hellman group values (#493)
File: libssh2.h

Notes:
Update the min, preferred and max DH group values based on RFC 8270.

Credit:
Will Cosgrove, noted from email list by Mitchell Holland
2020-07-01 11:37:20 -07:00