1
1

1037 Коммитов

Автор SHA1 Сообщение Дата
Patrick Monnerat
028a0ba4ed Define new Diffie-Hellman context for mbedTLS 2016-11-13 18:14:50 +00:00
monnerat
c8c1b4a050 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.
2016-11-12 18:15:49 +00:00
Peter Stuge
e70e71a3b1 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.
2016-11-12 10:46:06 +00:00
Peter Stuge
a68356418d 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.
2016-11-05 22:18:04 +00:00
Peter Stuge
b3636eaad5 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.
2016-11-05 22:18:04 +00:00
Peter Stuge
3806115d3d 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.
2016-11-05 22:18:04 +00:00
Peter Stuge
8a7232be61 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.
2016-11-05 22:17:02 +00:00
Zenju
1d8db1d854 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.
2016-11-05 21:50:24 +00:00
Zenju
33637f136e 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'
2016-11-05 21:04:03 +00:00
Salvador Fandino
84172e5188 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.
2016-11-05 19:45:33 +00:00
Salvador Fandino
fdfcb2f9e6 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.
2016-11-05 19:45:33 +00:00
Salvador Fandino
d013a6b070 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.
2016-11-05 19:45:33 +00:00
Salvador Fandino
56dffb0262 channel_wait_eof: fix debug message 2016-11-05 19:45:33 +00:00
Kamil Dudka
e9207ee2d1 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)
2016-10-20 17:32:27 +02:00
Charles Collicutt
29bcf75fb1 libssh2_wait_socket: Fix comparison with api_timeout to use milliseconds (#134)
Fixes #74
2016-10-19 09:49:37 +02:00
Charles Collicutt
15851ba78e Set err_msg on _libssh2_wait_socket errors (#135) 2016-10-19 09:46:41 +02:00
Keno Fischer
dc8f7ca3ab configure: Add support for building with mbedtls 2016-09-27 08:06:35 +02:00
wildart
186f1a2d75 crypto: add support for the mbedTLS backend
Closes #132
2016-09-27 08:06:29 +02:00
wildart
289e9482e4 cmake: Add CLEAR_MEMORY option, analogously to that for autoconf 2016-09-27 08:02:55 +02:00
Taylor Holberton
64ebfd8182 openssl: add OpenSSL 1.1.0 compatibility 2016-09-05 12:28:51 +02:00
Viktor Szakats
1fc7c8571e misc.c: Delete unused static variables
Closes #114
2016-08-03 10:15:59 +02:00
Will Cosgrove
7934c9ce2a Merge pull request #103 from willco007/patch-2
Fix for security issue CVE-2016-0787
2016-04-09 00:54:03 +02:00
Brad Harder
4138f1e412 _libssh2_channel_open: speeling error fixed in channel error message 2016-03-26 23:57:14 +01:00
Alexander Lamaison
7b9a9a782d 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.
2016-03-15 22:09:13 +00:00
Dan Fandrich
a8dff80726 libgcrypt: Fixed a NULL pointer dereference on OOM 2016-02-29 23:55:29 +01:00
Viktor Szakats
433c327ee2 url updates, HTTP => HTTPS
Closes #87
2016-02-24 23:44:13 +01:00
Daniel Stenberg
ca5222ea81 diffie_hellman_sha256: convert bytes to bits
As otherwise we get far too small numbers.

Reported-by: Andreas Schneider

CVE-2016-0787
2016-02-23 08:23:19 +01:00
Viktor Szakats
65a4528d17 openssl: apply new HAVE_OPAQUE_STRUCTS macro
Closes #81
2016-02-16 00:08:43 +01:00
Viktor Szakats
0ffb3bfafe openssl: fix LibreSSL support after OpenSSL 1.1.0-pre1/2 support 2016-02-16 00:08:08 +01:00
Alexander Lamaison
30221cfe5d sftp.h: Fix non-C90 type.
uint64_t does not exist in C90.  Use libssh2_uint64_t instead.
2016-02-14 22:12:10 +00:00
Viktor Szakats
298f056fd6 openssl: add OpenSSL 1.1.0-pre3-dev compatibility
by using API instead of accessing an internal structure.

Closes #83
2016-02-14 10:56:37 +01:00
Daniel Stenberg
ae484b426c sftp: re-indented some minor stuff 2016-02-11 13:57:14 +01:00
Jakob Egger
85dbd4c136 sftp.c: ensure minimum read packet size
For optimum performance we need to ensure we don't request tiny packets.
2016-02-11 13:57:14 +01:00
Jakob Egger
d7e25b4729 sftp.c: Explicit return values & sanity checks 2016-02-11 13:57:14 +01:00
Jakob Egger
e12fe71462 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.
2016-02-11 13:57:14 +01:00
Jakob Egger
992de2fbfa sftp.c: Don't return EAGAIN if data was written to buffer 2016-02-11 13:57:14 +01:00
Jakob Egger
77c48d4e26 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.
2016-02-11 13:57:09 +01:00
Jakob Egger
0d60964632 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
2016-02-11 13:54:10 +01:00
Salvador Fandiño
60874670ef 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>
2016-01-21 09:23:37 +01:00
Patrick Monnerat
77d825ac93 os400qc3: support encrypted private keys
PKCS#8 EncryptedPrivateKeyinfo structures are recognized and decoded to get
values accepted by the Qc3 crypto library.
2016-01-18 13:42:57 +01:00
Patrick Monnerat
b60fb64b17 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.
2016-01-18 13:35:28 +01:00
Patrick Monnerat
0de1cba671 os400qc3: force continuous update on non-final hash/hmac computation 2016-01-18 13:35:28 +01:00
Patrick Monnerat
2ddcaf2db8 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.
2016-01-18 13:35:28 +01:00
Patrick Monnerat
0f15724e72 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.
2016-01-18 13:35:28 +01:00
Patrick Monnerat
57692b6b10 os400qc3.c: comment PEM/DER decoding 2016-01-18 13:35:28 +01:00
Patrick Monnerat
92a3ac4673 os400qc3.c: improve ASN.1 header byte checks 2016-01-18 13:35:28 +01:00
Patrick Monnerat
72453b7367 os400qc3.c: improve OID matching 2016-01-18 13:35:28 +01:00
Patrick Monnerat
8b720f342f os400: os400qc3.c: replace malloc by LIBSSH2_ALLOC or alloca where possible 2016-01-18 13:35:28 +01:00
Patrick Monnerat
e2985f0a67 os400: asn1_new_from_bytes(): use data from a single element only 2016-01-18 13:35:28 +01:00
Patrick Monnerat
7dcf5ed6fb 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.
2016-01-18 13:35:28 +01:00