1806 Commits

Author SHA1 Message Date
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
002db176b7 os400: fix an ILE/RPG prototype 2016-01-18 13:35:28 +01:00
Patrick Monnerat
7a37c33264 os400: implement character encoding conversion support 2016-01-18 13:35:28 +01:00
Patrick Monnerat
914157804f 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.
2016-01-18 13:35:28 +01:00
Patrick Monnerat
4c4d6a8da4 os400: Really add specific README 2016-01-18 13:35:28 +01:00
Patrick Monnerat
c367e61294 os400: Add specific README and include new files in dist tarball 2016-01-18 13:35:28 +01:00
Patrick Monnerat
d900984b0a os400: add compilation scripts 2016-01-18 13:35:28 +01:00
Patrick Monnerat
4bd6d7ebf6 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.
2016-01-18 13:35:28 +01:00
Patrick Monnerat
dac4b3bac3 os400: add supplementary header files/wrappers. Define configuration. 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
Patrick Monnerat
8ba6bf2aef Add interface for OS/400 crypto library QC3 2016-01-18 13:35:28 +01:00
Patrick Monnerat
0fba5cfda6 misc: include stdarg.h for debug code 2016-01-18 13:35:28 +01:00
Patrick Monnerat
72bedfe761 Document crypto library interface 2016-01-18 13:35:28 +01:00
Patrick Monnerat
f915a31a4d 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.
2016-01-18 13:35:28 +01:00
Patrick Monnerat
0fbf8f3c7e Fold long lines in include files 2016-01-18 13:35:28 +01:00
Viktor Szakats
e64260a117 kex.c: fix indentation
Closes #71
2016-01-17 17:11:58 +01:00
Viktor Szakats
ed2c3c8d28 add OpenSSL-1.1.0-pre2 compatibility
Closes #70
2016-01-17 17:10:45 +01:00
Viktor Szakats
73930e6577 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.
2016-01-17 17:10:32 +01:00
Marc Hoersken
cf544d0f4c 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.
2015-12-22 13:38:10 +01:00
Marc Hoersken
d0ffeba72e 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.
2015-12-22 13:36:56 +01:00
Paul Howarth
9bf32da607 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>
2015-12-15 10:57:50 +01:00
Marc Hoersken
95dc2a6a52 hostkey.c: align code path of ssh_rsa_init to ssh_dss_init 2015-12-06 21:35:09 +01:00
Marc Hoersken
036196b0b0 hostkey.c: fix invalid memory access if libssh2_dsa_new fails
Reported by dimmaq, fixes #66
2015-12-06 21:34:54 +01:00
Will Cosgrove
51dcded3eb gcrypt: define libssh2_sha256_ctx
Looks like it didn't make it into the latest commit for whatever reason.

Closes #58
2015-11-03 07:43:32 +01:00
Salvador Fandino
b83c3e056e 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>
2015-11-02 14:50:15 +01:00
Salvador Fandino
ad23faaae6 _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>
2015-11-02 14:49:54 +01:00
Will Cosgrove
d441da3086 added engine.h include to fix warning 2015-10-05 10:52:52 +02:00
sune
ad26fd92cf kex.c: removed dupe entry from libssh2_kex_methods[]
Closes #51
2015-10-05 10:50:34 +02:00
Salvador Fandiño
4d97ed92b2 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>
2015-09-29 09:48:48 +02:00
Salvador Fandino
fb432f3f78 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>
2015-09-29 09:48:36 +02:00
Will Cosgrove
fc4a969a05 kex: Added diffie-hellman-group-exchange-sha256 support
... and fixed HMAC_Init depricated usage

Closes #48
2015-09-29 09:43:30 +02:00
Alexander Lamaison
92fff06e27 Prefixed new #defines to prevent collisions.
Other libraries might have their own USE_WIN32_*FILES.
2015-09-21 18:44:48 +01:00
keith-daigle
a49f479b4c Update examples/scp.c to fix bug where large files on win32 would cause got to wrap and go negative 2015-09-21 18:01:24 +01:00
David Byron
6c84a426be add libssh2_scp_recv2 to support large (> 2GB) files on windows 2015-09-21 18:01:23 +01:00
sune
4961014033 WinCNG: support for SHA256/512 HMAC
Closes #47
2015-09-17 15:27:30 +02:00
brian m. carlson
a53cebba34 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
2015-09-16 09:32:19 +02:00
Zenju
3768f8aeef kex: free server host key before allocating it (again)
Fixes a memory leak when Synology server requests key exchange

Closes #43
2015-09-12 12:30:13 +02:00
Viktor Szakats
3acca4ad15 GNUmakefile: up OpenSSL version
closes #23
2015-09-04 08:17:57 +02:00