1
1

78 Коммитов

Автор SHA1 Сообщение Дата
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
Marc Hoersken
8f799f98d9 silence multiple data conversion warnings 2014-12-26 11:05:34 +01:00
Dan Fandrich
c00efa5f93 Fixed a few typos 2014-02-24 23:23:13 +01:00
Dan Fandrich
5559ad8fe1 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.
2014-02-24 23:23:13 +01:00
Kamil Dudka
5d567faecc crypt: use hard-wired cipher block sizes consistently 2012-09-17 09:48:07 +02:00
Dave Hayden
42fec44c8a 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.
2012-08-19 13:47:50 +02:00
Matthew Booth
cc4f9d5679 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.
2012-03-16 16:40:04 +01:00
Henrik Nordstrom
7aa4bfc671 Custom callbacks for performing low level socket I/O 2011-08-21 15:19:44 +02:00
Peter Stuge
516fa7fdd9 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.
2011-02-26 05:21:01 +01:00
Alfred Gebert
ad88325b3f 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
2011-02-16 13:57:58 +01:00
Daniel Stenberg
4552c73cd5 data size: cleanup
Fix 64bit warnings by using (s)size_t and dedicated uint32_t types more.
2010-12-30 00:09:53 +01:00
Daniel Stenberg
121237ce2f 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.
2010-12-15 09:52:18 +01:00
Daniel Stenberg
e87293d480 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.
2010-11-13 12:25:06 +01:00
Peter Stuge
97a1881749 Use fprintf(stderr, ) instead of write(2, ) for debugging 2010-11-13 02:06:41 +01:00
Peter Stuge
80f7508d55 session/transport: Correctly handle when _libssh2_send() returns -EAGAIN 2010-11-13 01:53:39 +01:00
Daniel Stenberg
ca2e81eb1f 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.
2010-11-12 21:53:35 +01:00
Daniel Stenberg
588c8946fc 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.
2010-11-03 15:03:57 +01:00
Daniel Stenberg
a6fc9aeec9 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.
2010-11-03 14:52:42 +01:00
Daniel Stenberg
753e55ef23 _libssh2_transport_send: remove dead assignment
'data' isn't accessed beyond this point so there's no need to assign it.
2010-11-01 23:00:07 +01:00
Daniel Stenberg
dec0ea9e70 send_existing: don't tell parent to return when drained
That will just cause unnecessary code execution.
2010-10-23 00:47:51 +02:00
Daniel Stenberg
c48840ba88 _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.
2010-10-23 00:11:59 +02:00
Daniel Stenberg
c49061e708 send_existing: clear olen when the data is sent off 2010-10-22 13:37:14 +02:00
Daniel Stenberg
d674b1a09a _libssh2_transport_write: allow 256 extra bytes around the packet 2010-10-22 13:37:13 +02:00
Daniel Stenberg
5ede32a826 _libssh2_transport_write: remade to send without malloc 2010-10-22 13:37:13 +02:00
Daniel Stenberg
59636cc11e 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.
2010-10-08 16:26:50 +02:00
Daniel Stenberg
861fc75fa3 _libssh2_transport_drain: removed
This function proved not to be used nor useful.
2010-10-07 13:30:05 +02:00
Daniel Stenberg
4faf67d3e9 _libssh2_transport_write: updated documentation blurb 2010-10-07 13:17:28 +02:00
Daniel Stenberg
76a30f2c6f _libssh2_transport_write: remove fprintf remainder
Mistake from previous debugging
2010-10-07 12:57:08 +02:00
Daniel Stenberg
7c49c8be58 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.
2010-10-07 11:18:14 +02:00
Daniel Stenberg
71fb9cc93e 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.
2010-04-25 19:35:43 +02:00
Daniel Stenberg
1acca6e3ee remove check for negative padding_length
It was silly, since it is read as an unsigned char...
2010-04-20 22:48:40 +02:00
Daniel Stenberg
100059989f data types: convert more to use size_t and uint32_t 2010-04-17 13:34:44 +02:00
Daniel Stenberg
c3bcdd88a4 cleanups: better binary packet gen, size_t fixes and PACKET_* removal
I'll introduce a new internal function set named

 _libssh2_store_u32
 _libssh2_store_u64
 _libssh2_store_str

That can be used all through the library to build binary outgoing
packets.  Using these instead of the current approach removes
hundreds of lines from the library while at the same time greatly
enhances readability. I've not yet fully converted everything to
use these functions.

I've converted LOTS of 'unsigned long' to 'size_t' where
data/string lengths are dealt with internally. This is The Right
Thing and it will help us make the transition to our
size_t-polished API later on as well.

I'm removing the PACKET_* error codes. They were originally
introduced as a set of separate error codes from the transport
layer, but having its own set of errors turned out to be very
awkward and they were then converted into a set of #defines that
simply maps them to the global libssh2 error codes instead. Now,
I'l take the next logical step and simply replace the PACKET_*
defines with the actual LIBSSH2_ERROR_* defines. It will increase
readability and decrease confusion.

I also separated packet stuff into its own packet.h header file.
2010-04-17 13:18:15 +02:00
Daniel Stenberg
1adcb5234f rename libssh2_error to the correct _libssh2_error
We reserve ^libssh2_ for public symbols and we use _libssh2 as
prefix for internal ones. I fixed the intendation of all these
edits with emacs afterwards, which then changed it slightly more
than just _libssh2_error() expressions but I didn't see any
obvious problems.
2010-04-16 00:18:51 +02:00
Daniel Stenberg
7f740368f4 channel/transport: we now drain the outgoing send buffer when we ignore EAGAIN
When we ignore the EAGAIN from the transport layer within channel_write, we
now drain the outgoing transport layer buffer so that remainders in that
won't cause any problems in the next invoke of _libssh2_transport_write()
2010-04-15 01:12:22 +02:00
Peter Stuge
b6ed60d2cc Correctly clear blocking flag after sending multipart packet
commit 7317edab61d2179febc38a2c2c4da0b951d74cbc cleared the outbound
blocking bit when send_existing() returned PACKET_NONE and *ret=0, as
opposed to before even calling send_existing(), but because *ret=1 when
sending parts 2..n of an existing packet, the bit would only be cleared
when calling libssh2_transport_write() for a new packet.

Clear the direction flag after the final part of a packet has been sent.
2010-03-28 01:35:55 +01:00
Daniel Stenberg
d4a768af4e removed libssh2_error()'s forth argument
libssh2_error() no longer allocates a string and only accepts a const
error string. I also made a lot of functions use the construct of
return libssh2_error(...) instead of having one call to
libssh2_error() and then a separate return call. In several of those
cases I then also changed the former -1 return code to a more
detailed one - something that I think will not change behaviors
anywhere but it's worth keeping an eye open for any such.
2010-03-03 23:04:05 +01:00
Sofian Brabez
a190437c4a Replace : in hexdump with " " (two spaces) 2010-02-01 16:30:47 +01:00
Dave McCaldon
f077984394 Pass user context through libssh2_trace_sethandler() to callback
The libssh2_trace_sethandler() call allows the user to handle the output of libssh2 rather than having it written to stderr.  This patch updates libssh2_trace_sethandler() to allow a user-defined void* context value to be passed back to the output handler.
2010-01-20 19:42:09 +01:00
Dave McCaldon
44eba0c993 Add libssh2_trace_sethandler() to the API (even more) 2010-01-15 22:58:44 +01:00
Peter Stuge
d142f385da Use LIBSSH2_TRACE_* internally and remove redundant LIBSSH2_DBG_* 2009-12-08 08:52:03 +01:00
Peter Stuge
1a491c6f00 Add LIBSSH2_TRACE_SOCKET context for tracing send() and recv()
Helpful in debugging the -39 errors.
2009-12-08 08:40:30 +01:00
Peter Stuge
1256c61815 Another transport layer fix for bogus -39 (LIBSSH2_ERROR_BAD_USE) errors
Commit 683aa0f6b52fb1014873c961709102b5006372fc made send_existing() send
more than just the second part of a packet when the kernel did not accept
the full packet, but the function still overlooked the SSH protocol
overhead in each packet, often 48 bytes.

If only the last few bytes of a packet remained, then the packet would
erroneously be considered completely sent, and the next call to write
more data in the session would return a -39 error.
2009-12-08 07:33:05 +01:00
Peter Stuge
7317edab61 Don't always clear write direction blocking flag
When libssh2_transport_write() is called to continue sending a
partially sent packet the write direction flag must not be cleared
until the previous packet has been completely sent, or the app would
hang if the packet still isn't sent completely, since select() gets
called by the internal blocking emulation layer in libssh2 but would
then not be watching the socket for writability.

Clear the flag only once processing of previous packet data is
complete and a new packet is about to be prepared.
2009-11-27 07:52:26 +01:00
Peter Stuge
683aa0f6b5 Fix transport layer bug causing invalid -39 (LIBSSH2_ERROR_BAD_USE) errors
The channel layer sends packets using the transport layer, possibly
calling _libssh2_transport_write() many times for each packet.

The transport layer uses the send_existing() helper to send out any
remaining parts of previous packets before a new packet is started.

The bug made send_existing() consider the entire packet sent as soon as it
successfully sent the second part of a packet, even if the packet was not
completely done yet.
2009-09-20 00:30:42 +02:00
Daniel Stenberg
face4750ca changed all return EAGAIN to return the variable instead
I made this change just to easier grep for "return .*EAGAIN" cases
as they should be very rare or done wrongly. Already worked to find
a flaw, marked with "TODO FIXME THIS IS WRONG" in channel.c. I also
fixed a few cases to become more general returns now when we have
more unified return codes internally.
2009-08-25 00:54:47 +02:00
Daniel Stenberg
fba3877ed8 remove all libssh2pack_t leftovers 2009-08-24 23:57:15 +02:00
Daniel Stenberg
f1e010f5d4 removed the libssh2pack_t type
and a minor _libssh2_transport_read() simplification
2009-08-24 23:50:53 +02:00
Daniel Stenberg
e39128df52 simplified fullpacket, clarified _libssh2_transport_write() comment 2009-08-24 23:13:14 +02:00
Daniel Stenberg
d8b6f3c7b8 move over lots of code to the _libssh2_list_* functions
and I fixed a few minor bugs at the same time
2009-08-20 00:56:54 +02:00