Compare commits

..

1177 Commits

Author SHA1 Message Date
Andreas Schneider
6e0dee7845 poll: Fix compilation with struct ssh_timestamp
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit e0a73d3dbe)
2015-05-06 10:07:38 +02:00
Andreas Schneider
9e99408dba Bump version to 0.6.5
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-29 12:24:33 +02:00
Andreas Schneider
6b49863bb0 Update Changelog
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-29 12:23:50 +02:00
Aris Adamantiadis
e9d16bd343 buffers: Fix a possible null pointer dereference
This is an addition to CVE-2015-3146 to fix the null pointer
dereference. The patch is not required to fix the CVE but prevents
issues in future.

Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 3091025472)
2015-04-23 10:34:13 +02:00
Aris Adamantiadis
94f6955fba CVE-2015-3146: Fix state validation in packet handlers
The state validation in the packet handlers for SSH_MSG_NEWKEYS and
SSH_MSG_KEXDH_REPLY had a bug which did not raise an error.

The issue has been found and reported by Mariusz Ziule.

Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit bf0c7ae0ae)
2015-04-23 10:34:12 +02:00
Kevin Fan
d2a990a68e Fix leak of sftp->ext when sftp_new() fails
Signed-off-by: Kevin Fan <kevinfan@google.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit b5dc8197f7)
2015-04-14 20:57:17 +02:00
Andreas Schneider
584ab49b7b cmake: Detect network function correctly on Windows
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 195f25cfbd)
2015-04-10 14:32:53 +02:00
Andreas Schneider
dc30183d8a cmake: Detect __func__ and __FUNCTION__ during configure step
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-02 13:42:12 +02:00
Andreas Schneider
396f5e2110 include: We should use __func__ which is C99
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-02 10:57:18 +02:00
Seb Boving
6b18f0b4b0 Locally restart ssh_poll() upon EINTR.
BUG: https://red.libssh.org/issues/186

Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
Signed-off-by: Sebastien Boving <seb@google.com>
2015-02-23 22:06:34 +01:00
xjoaalm
8f2eee6509 Sending EOF on Socket that received a Broken Pipe makes call to poll to hang
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
Signed-off-by: Joao Pedro Almeida Pereira <joao.almeida@blue-tc.com>
2015-02-23 22:02:35 +01:00
Aris Adamantiadis
4bd704295c examples: cast arguments of connect(2)
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-14 22:20:45 +01:00
Aris Adamantiadis
be2f5399dd torture: fix includes for freebsd10 2015-02-14 22:13:58 +01:00
Aris Adamantiadis
a672b3e7bb tests: torture-misc: check for NULL return codes
Use the LOGNAME environment variable if USER is not set, as it sometimes
happens in cron jobs.
2015-02-12 11:39:53 +01:00
Aris Adamantiadis
ddc3f987a7 tests: workaround for compiling with older cmocka 2015-02-12 11:39:45 +01:00
Aris Adamantiadis
e9ad0c3c69 sftp: fix endianess issue 2015-02-11 21:35:02 +01:00
Andreas Schneider
2ccab05cba connect: Fix mingw build.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit a198193723)
2015-01-26 17:10:19 +01:00
Andreas Schneider
58348fcc57 sftp: Fix sftp_get_new_id().
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-01-21 08:44:34 +01:00
Léo Peltier
0579b7d8b2 cmake: Add libsshpp.hpp to the distributed headers list.
BUG: https://red.libssh.org/issues/163

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 8db4520d89)
2015-01-20 19:33:16 +01:00
Andreas Schneider
915d28ffa5 pki: Make sure sig is not used unintialized.
BUG: https://red.libssh.org/issues/167

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 9a7d450098)
2015-01-20 19:31:29 +01:00
Andreas Schneider
884bff5bdc sftp: Fix sftp endianess bugs.
BUG: https://red.libssh.org/issues/179

This is a backport of 6019cf1bed.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-01-20 19:17:02 +01:00
Andreas Schneider
08c33d6aeb threads: Fix building with POSIX threads in MinGW.
BUG: https://red.libssh.org/issues/181

Originally written by Patrick von Reth <vonreth () kde ! org>.

This patch is part of the larger patch:
https://projects.kde.org/projects/kdesupport/emerge/repository/revisions/master/changes/portage/win32libs/libssh/0002-add-a-way-to-test-ssh-connections-on-windows.patch

MinGW (in particular, the MinGW-w64 fork) can use either posix threads
or win32 threads. This patch fixes the MinGW build when using posix
threads.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 433f8fd550)
2015-01-20 19:03:08 +01:00
Yanis Kurganov
fa4740bdf5 channels1: Fix pty request state
Signed-off-by: Yanis Kurganov <YKurganov@ptsecurity.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit c6590bd189)
2015-01-20 18:59:01 +01:00
Andreas Schneider
da91ca43c0 connect: Fix a memory leak.
CID: #1238618

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
(cherry picked from commit 06a0d8ff1c)
2015-01-14 15:21:41 +01:00
Andreas Schneider
4de6a708ad sftp: Fix a possible integer overflow.
CID: #1238630

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
(cherry picked from commit af0dd3fb02)
2015-01-14 15:21:40 +01:00
Andreas Schneider
fd3b1f63a1 sftp: Use a declared variable for data len.
CID: #1238632

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
(cherry picked from commit ce02f6576a)
2015-01-14 15:21:36 +01:00
Andreas Schneider
914f8abde8 cmake: Fix ntohll and htonll macro detection.
BUG: https://red.libssh.org/issues/164

Thanks to Ryan Schmidt!

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 8536cd9808)
2015-01-13 08:55:07 +01:00
Aris Adamantiadis
3880a8ed80 Fix the dh.c build with libgcrypt
Fixes bug reported by gentoo at https://bugs.gentoo.org/show_bug.cgi?id=533424
The function was only used by EDCSA backend which are not supported by the libgcrypt code anyway.
2014-12-29 16:06:33 +01:00
Andreas Schneider
0e969e0316 connect: Check that errno is 0 to fix Windows build.
Thanks to Viktor Butskih.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit e051135a05)
2014-12-25 12:35:24 +01:00
Andreas Schneider
a45dd8e000 options: Fix setting the port.
Make sure we correctly read the port from the config file.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit bb18442fe8)
2014-12-25 12:35:21 +01:00
Andreas Schneider
319129399d Bump version to 0.6.4. 2014-12-17 19:45:23 +01:00
Jon Simons
87ae95eb3c CVE-2014-8132: Fixup error path in ssh_packet_kexinit()
Before this change, dangling pointers can be unintentionally left in the
respective next_crypto kex methods slots.  Ensure to set all slots to
NULL in the error-out path.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 2ced24ddd67a261dc364ad4d8958c068c1671ae7)
2014-12-17 19:45:23 +01:00
Andreas Schneider
055f102601 libcrypto: Fix Windows build with ssh_reseed().
gettimeofday() is not available on Windows and we need it only in case
of forking.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit b7b535816d)
2014-12-17 19:40:57 +01:00
Andreas Schneider
2d6862ddb9 cmake: Fix the build on Windows.
(cherry picked from commit a738507ad2)
2014-12-17 19:31:32 +01:00
Andreas Schneider
22aa60d506 cmake: Fix config variable names.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit d8e691b58a)
2014-12-17 10:40:31 +01:00
Andreas Schneider
4b02bbbd32 cmake: Fix libssh cmake-config files.
(cherry picked from commit 142b2e4ede)
2014-12-17 10:40:25 +01:00
William Orr
31ded2070e config: Also tokenize on equal sign.
The ssh config specifies it as a valid separator.

BUG: https://red.libssh.org/issues/166

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 52968b1a11)
2014-12-17 10:35:17 +01:00
Davide \"FunkyAss\" Del Zompo
df3d53e561 doc: clarify tutorial error section
Signed-off-by: Davide "FunkyAss" Del Zompo <davide.delzompo@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit bb197de75d)
2014-12-05 11:09:34 +01:00
Hani Benhabiles
f28c3099da Set the correct error in ssh_options_set().
Signed-off-by: Hani Benhabiles <hani@linux.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 03095f1516)
2014-12-05 11:04:35 +01:00
Andreas Schneider
32a106c70d messages: Fix a possible double free.
Thanks to Ramana Gampa.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2014-12-05 10:59:41 +01:00
Jon Simons
5d75090d9f pki_crypto.c: plug ecdsa_sig->[r,s] bignum leaks
Per ecdsa(3ssl), ECDSA_SIG_new does allocate its 'r' and 's' bignum fields.
Fix a bug where the initial 'r' and 's' bignums were being overwritten with
newly-allocated bignums, resulting in a memory leak.

BUG: https://red.libssh.org/issues/175

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>

(cherry picked from commit 4745d652b5)
2014-12-05 10:46:31 +01:00
Andreas Schneider
32a3cfe661 connect: Do not fail if the connect is in progress.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit a48711ae7e)
2014-10-28 10:33:47 +01:00
Stef Walter
1c59844dfe gssapi: ssh_gssapi_set_creds() is a client side function
It should not be guarded by the WITH_SERVER #ifdef

Signed-off-by: Stef Walter <stefw@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit cd2dc3770a)
2014-10-12 15:47:13 +02:00
William Orr
f071954a76 Check return code of connect(2).
Signed-off-by: William Orr <will@worrbase.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 250f506487)
2014-10-12 15:47:12 +02:00
Artyom V. Poptsov
a033b93c61 pki_gcrypt: Initialize 'type_c' in 'pki_do_sign_sessionid'
Add missing initialization of 'type_c' field of a SSH signature in
'pki_do_sign_sessionid' procedure.

If libssh is compiled with GCrypt, 'dh_handshake_server' fails with
"Could not sign the session id" error.  The change fixes that.

Signed-off-by: Artyom V. Poptsov <poptsov.artyom@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit aaae6cd97d)
2014-10-02 08:30:30 +02:00
Jon Simons
b7856780a9 crypto: check malloc return in ssh_mac_ctx_init
Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit af25c5e668)
2014-10-02 08:26:08 +02:00
Jon Simons
8b3425865a wrapper: fix z_stream leak
Ensure to free the z_stream structures as allocated from
the gzip.c initcompress, initdecompress functions.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 092fe0b727)
2014-10-02 08:25:27 +02:00
Andreas Schneider
a30e234c03 string: Correctly burn the string buffer.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
(cherry picked from commit 1ddb99c46f)
2014-09-15 20:46:06 +02:00
Jon Simons
bbf172a79c session: fix ssh_session->srv.ecdsa_key leak
Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-05-28 10:24:01 +02:00
Andreas Schneider
f28748578d pki: Fix build without ECC support.
Signed-off-by: Andreas Schneider <asn@samba.org>
2014-05-09 08:56:10 +02:00
Andreas Schneider
36f7d1a614 pki: Add missing semi-colon. 2014-05-07 09:36:11 +02:00
Andreas Schneider
71241ca68c pki: Move ssh_pki_key_ecdsa_name() to the correct file. 2014-05-07 09:35:49 +02:00
Andreas Schneider
bfbf9283d0 cmake: Fix doxygen. 2014-05-07 09:35:34 +02:00
Andreas Schneider
d75573e665 cmake: Update doxygen module. 2014-05-07 09:35:34 +02:00
Jon Simons
8fe36e3d07 pki crypto: expose new ssh_pki_key_ecdsa_name API
Enable retrieving the "ecdsa-sha2-nistpNNN" name of ECDSA keys with a
new 'ssh_pki_key_ecdsa_name' API.  This gives more information than the
'ssh_key_type_to_char' API, which yields "ssh-ecdsa" for ECDSA keys.
The motivation is that this info is useful to have in a server context.

The torture_pki unit test is updated to include the new API, and a few
more passes are added to additionally test 384 and 521-bit keys.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-05-07 09:35:06 +02:00
Alan Dunn
f2e9ce68e7 messages: Add missing ntohl on X11 request screen number
BUG: https://red.libssh.org/issues/160

Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-05-06 08:56:55 +02:00
Andreas Schneider
cfb4d27c47 pki: Correctly update the ECDSA keytype.
(cherry picked from commit 2884bbf5b1)
2014-05-06 08:54:11 +02:00
Andreas Schneider
d366e289f3 pki: Move ssh_pki_key_ecdsa_name() to the correct file.
(cherry picked from commit f48a99b97c)
2014-05-06 08:54:06 +02:00
Andreas Schneider
2fc8347504 pki: Make pki_key_ecdsa_nid_to_name() a shared function.
(cherry picked from commit 11cfb2903e)
2014-05-06 08:54:00 +02:00
Andreas Schneider
2691ed595e cmake: Install cmake config files to the correct directory.
(cherry picked from commit 291312c5e4)
2014-04-22 09:10:05 +02:00
Andreas Schneider
7b133cf9f5 doc: Improve docs for ssh_channel_get_exit_status().
BUG: https://red.libssh.org/issues/154
(cherry picked from commit adf23533e0)
2014-04-22 09:09:57 +02:00
Andreas Schneider
9b59f1a222 channels: Fix exit-signal request.
BUG: https://red.libssh.org/issues/153
(cherry picked from commit 927cd90dc1)
2014-04-22 09:09:56 +02:00
Andreas Schneider
8f21f879d3 session: Fix a memory leak with custom banner.
BUG: https://red.libssh.org/issues/152
(cherry picked from commit b5efbe75cd)
2014-04-22 09:09:39 +02:00
Andreas Schneider
67752dabfc cmake: Enable creation of the compile command database by default.
(cherry picked from commit 437a39c798)
2014-04-22 09:09:28 +02:00
Jon Simons
34ac4e4248 packet: elide two buffer_prepend calls into one
In packet_send2, rather than issue two separate buffer_prepend_data calls
(each of which may entail realloc + memmove + memcpy), elide the prepend
work into a single buffer_prepend_data: the header information is computed
locally, and a single 5 byte prepend operation is now done instead of
prepending 1, then 4 bytes.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit aa05248ca8)

Conflicts:
	src/packet.c
2014-03-27 11:25:15 +01:00
Andreas Schneider
1928fb6a85 doc: Fix ssh_userauth_none() function signature.
Thanks to David Tibbe!

BUG: https://red.libssh.org/issues/151
(cherry picked from commit 04543c9dbc)
2014-03-27 11:16:23 +01:00
Alan Dunn
5b1678f197 doc: Improve and consolidate ssh_bind_options_set docs
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 47bd0b6d1f)
2014-03-27 11:15:39 +01:00
Petar Koretic
8aff91dfcb libssh: libhpp: overload read function to support timeout parameter
Signed-off-by: Petar Koretic <petar.koretic@sartura.hr>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 8e2590b535)
2014-03-27 11:15:39 +01:00
Petar Koretic
c0cc12d582 libssh: libhpp: avoid unnecessary call to ssh_channel_read
ssh_channel_read is a wrapper for ssh_channel_read_timeout with timeout
-1 (infinite) so we call that directly.

Signed-off-by: Petar Koretic <petar.koretic@sartura.hr>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit c51f42a566)
2014-03-27 11:15:39 +01:00
Petar Koretic
a162071f9a libssh: libhpp: fix multiple definitions for acceptForward function
Defining a non inlined class function in a header will cause multiple
definitions when header is included in more that one file since for each
file function will get defined.

Signed-off-by: Petar Koretic <petar.koretic@sartura.hr>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 00d4fbe753)

Conflicts:
	include/libssh/libsshpp.hpp
2014-03-27 11:15:19 +01:00
Jon Simons
2091dab273 channel: check for closed state in waitwindow loops
Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit dee8e5688b)
2014-03-27 11:14:25 +01:00
Jon Simons
7f18ec4620 kex: enable more ECDSA hostkey algos
Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 40d81bb7ca)
2014-03-27 11:14:25 +01:00
Jon Simons
8e698382db pki_crypto: guard against NULL pubkey->rsa in signature extraction
Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 10bc5ac203)
2014-03-27 11:14:25 +01:00
Luka Perkov
ce10d40325 session: fix comment typo
Signed-off-by: Luka Perkov <luka.perkov@sartura.hr>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 8ba9402282)
2014-03-27 11:14:25 +01:00
Luka Perkov
3fed9a5aff messages: use predefined macro for clearing sensitive data
Signed-off-by: Luka Perkov <luka.perkov@sartura.hr>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit a2fe341da5)
2014-03-27 11:14:25 +01:00
Luka Perkov
da0c77fdb1 client: fix corner case when sockets are manually created
If the sockets are created manually and passed to libssh the internal session
state is set to SSH_SESSION_STATE_SOCKET_CONNECTED. Result of this fix can be
verified by running torture_connect test (torture_connect_socket) with -vvvv
flags.

Signed-off-by: Luka Perkov <luka.perkov@sartura.hr>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit dbb2de272b)
2014-03-27 11:14:25 +01:00
Luka Perkov
818c80baed tests: torture_connect: add test for user provided socket
Signed-off-by: Luka Perkov <luka.perkov@sartura.hr>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 9423a3a065)
2014-03-27 11:14:25 +01:00
Luka Perkov
bb55bb2daf tests: torture_connect: fix coding style
Signed-off-by: Luka Perkov <luka.perkov@sartura.hr>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 0c5d4954a7)
2014-03-27 11:14:25 +01:00
Petar Koretic
fdced9d544 pki_crypto: Replace deprecated RSA_generate_key() with RSA_generate_key_ex()
On Mar 16, 09:41, Aris Adamantiadis wrote:
> Hi Petar,
> I agree with the principle, but I don't think this code can work...
> RSA_generate_key takes an RSA* as parameter and in our code we probably
> have key->rsa==NULL. (if we don't then the old code had a memory leak).
>
> Does the test case work ?
>
> Aris
>

Yes, you are right. This works, tested with tests/unittests/torture_pki

Signed-off-by: Petar Koretic <petar.koretic@sartura.hr>
(cherry picked from commit 0b8d24f800)
2014-03-27 11:14:25 +01:00
Luka Perkov
96db44ff17 update gitignore file
The libssh library by default does not allow in-source build (with cmake
MacroEnsureOutOfSourceBuild macro). The INSTALL file (implicitly) suggests
creating a build directory. So lets add build to list of git ignore files to
avoid complaints from git.

Signed-off-by: Luka Perkov <luka.perkov@sartura.hr>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 48354f56ec)
2014-03-27 11:14:25 +01:00
Alan Dunn
70dbbfa320 doc: Add ECDSA keys to docs, make key docs consistent
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit f6276fe739)
2014-03-27 11:13:15 +01:00
Alan Dunn
1118fc2adf options: Allow use of host ECDSA key
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 2a1089d607)
2014-03-27 11:13:15 +01:00
Andreas Schneider
257449a0b6 tests: Check the the ecdsa_nid is the same.
(cherry picked from commit fbf73ede1e)
2014-03-27 11:13:15 +01:00
Alan Dunn
8752460df4 tests: Add test case for bug #147
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 577840d7f7)
2014-03-27 11:13:15 +01:00
Alan Dunn
6f089a098b pki_crypto: Always copy ecdsa_nid into duplicated ECDSA keys
BUG: https://red.libssh.org/issues/147

Signed-off-by: Alan Dunn <amdunn@gmail.com>
2014-03-12 14:16:43 +01:00
Alan Dunn
8b3be050c9 pki: Use SHA-2 for session ID signing with ECDSA keys
Previously, SHA-1 was used always.

BUG: https://red.libssh.org/issues/148

Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-12 14:16:35 +01:00
Luka Perkov
ade33474be server: silence build warning
The commit fixes this build warning:

====
src/server.c:223:8: warning: ‘privkey’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     rc = ssh_pki_export_privkey_to_pubkey(*privkey, &pubkey);
        ^
src/server.c:243:11: note: ‘privkey’ was declared here
   ssh_key privkey;
====

Signed-off-by: Luka Perkov <luka.perkov@sartura.hr>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-12 14:16:33 +01:00
Jon Simons
dbf7749696 packet: log disconnect code in host byte order
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-12 14:16:30 +01:00
Jon Simons
2db45dd547 bind: only set bindfd after successful listen
In 'ssh_bind_listen', move setting of 'sshbind->bindfd' to only happen after
the listen call: otherwise 'bindfd' can be set to a bogus descriptor for the
case that listen fails.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-12 14:16:28 +01:00
Andreas Schneider
87145387aa Prepare libssh-0.6.3.
We messed up some thing, so we release 0.6.3.
2014-03-04 13:20:52 +01:00
Aris Adamantiadis
d027460792 bump version to 0.6.2 2014-03-04 11:34:36 +01:00
Aris Adamantiadis
3fdd82f2a8 security: fix for vulnerability CVE-2014-0017
When accepting a new connection, a forking server based on libssh forks
and the child process handles the request. The RAND_bytes() function of
openssl doesn't reset its state after the fork, but simply adds the
current process id (getpid) to the PRNG state, which is not guaranteed
to be unique.
This can cause several children to end up with same PRNG state which is
a security issue.
2014-03-04 09:55:02 +01:00
Andreas Schneider
6cd94a63ff pki: Fix the build on OpenSolaris. 2014-02-12 09:40:09 +01:00
Andreas Schneider
e85b20ba82 pki: Fix memory leak with ecdsa signatures. 2014-02-11 10:31:51 +01:00
Andreas Schneider
78d5d64b38 Update ChangeLog. 2014-02-10 10:17:43 +01:00
Andreas Schneider
f73a44c223 cpack: Ignore obj directory. 2014-02-10 10:17:43 +01:00
Andreas Schneider
1cccfdf8a0 packet: Improve readablity of packet decrypt.
After discussion with Aris and it was not obvious enough to understand
the issue we decided to refactor it.

Reviewd-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-02-06 20:32:05 +01:00
Alan Dunn
abe4ed0e75 packet_crypt: Make packet_{en,de}crypt fail consistently on len == 0
Right now the behavior of packet_{en,de}crypt on len == 0 depends on
the behavior of malloc.  Instead, make these consistently fail based
on what I assume the desired behavior is due to the first error
message in each.

Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-06 19:40:29 +01:00
Alan Dunn
e7f831f0a3 packet: Do not decrypt zero length rest of buffer
If we receive a packet of length exactly blocksize, then
packet_decrypt gets called on a buffer of size 0.  The check at the
beginning of packet_decrypt indicates that the function should be
called on buffers of at least one blocksize, though the check allows
through zero length.  As is packet_decrypt can return -1 when len is 0
because malloc can return NULL in this case: according to the ISO C
standard, malloc is free to return NULL or a pointer that can be freed
when size == 0, and uclibc by default will return NULL here (in
"non-glibc-compatible" mode).  The net result is that when using
uclibc connections with libssh can anomalously fail.

Alternatively, packet_decrypt (and probably packet_encrypt for
consistency) could be made to always succeed on len == 0 without
depending on the behavior of malloc.

Thanks to Josh Berlin for bringing conneciton failures with uclibc to
my attention.

Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-06 19:40:09 +01:00
Raphael Kubo da Costa
4ea4e12df2 build: Use Threads_FOUND to decide whether to build ssh_threads.
Follow-up to 4e04ec8, which caused a regression on OS X.

Checking the value of CMAKE_THREAD_LIBS_INIT to decide whether any threading
library is present on a system turns out to be wrong -- in OS X, for
example, usage of pthreads does not depend on any additional linker or
compiler flags, so CMAKE_THREAD_LIBS_INIT is empty and our check in
src/CMakeLists.txt failed (it used to work before 4e04ec8 because
CMAKE_HAVE_THREADS_LIBRARY is set).

Instead, just look for Threads_FOUND, which FindThreads sets just like any
other Find module when it has found what it was looking for.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-06 11:13:23 +01:00
Jon Simons
fb49e194df session: skip timestamp init for non-blocking case
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-06 11:13:22 +01:00
Jon Simons
13f4e31ad1 session: add getters for session cipher names
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-06 11:13:20 +01:00
Aris Adamantiadis
da5fa4ef66 Revert f2c2687ca6
Fix bug #142
The mode does need to be an octal numeric string. Mode 0600 now gets sent on the wire as 0384, triggering a "scp: protocol error: bad mode" response, and an "scp status code 1d not valid" message from libssh.
2014-02-05 22:30:10 +01:00
Aris Adamantiadis
dca415a38e knownhosts: resolve leaks found by coverity 2014-02-05 08:08:31 +01:00
Aris Adamantiadis
56f86cd4a1 knownhosts: detect variations of ecdsa 2014-02-05 08:08:31 +01:00
Aris Adamantiadis
f265afacfb tests: lines lost during last cherry-pick merge 2014-02-04 16:20:20 +01:00
Aris Adamantiadis
99f8b2b803 Kex: fix coverity warning + edge case 2014-02-04 16:04:45 +01:00
Audrius Butkevicius
22edaf43ee server: use custom server banners
Value of session->serverbanner never gets used

Signed-off-by: Audrius Butkevicius <audrius.butkevicius@gmail.com>
2014-02-04 16:04:26 +01:00
Aris Adamantiadis
497bd31364 server: allow custom server banners (bug #83) 2014-02-04 16:04:26 +01:00
Aris Adamantiadis
8ed0c0b3c8 Knownhosts: implement hostkey with knownhosts heuristic 2014-02-04 16:01:37 +01:00
Aris Adamantiadis
ce39d2fa73 knownhosts: add test case for bug #138 2014-02-04 16:01:37 +01:00
Aris Adamantiadis
90d3768f0f known_hosts: add ssh_knownhosts_algorithms()
Goal of that function is to test the preferred key exchange methods
based on what's available in the known_hosts file

Conflicts:
	tests/client/torture_knownhosts.c
2014-02-04 16:01:02 +01:00
Aris Adamantiadis
6f66032209 build: remove OSX deprecated warnings for openssl 2014-02-04 15:55:37 +01:00
Raphael Kubo da Costa
c571cd8402 threads: Be less strict when deciding whether to build libssh_threads.
As mentioned in the previous commit, there are cases where
CMAKE_HAVE_THREADS_LIBRARY is not set and pthreads _is_ being used: one can
pass -DTHREADS_HAVE_PTHREAD_ARG=1 to CMake directly so that it just passes
-pthread to the compiler/linker and does not set CMAKE_HAVE_THREADS_LIBRARY.

Since we are only interested in knowing whether any threading library has
been found, we should use CMAKE_THREAD_LIBS_INIT instead (Threads_FOUND
would also work).

Note that, at the moment, there is only a pthreads backend available in
threads/, so if it is not found configuration will fail because CMake will
try to create a library from an empty set of source files.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-03 14:39:15 +01:00
Raphael Kubo da Costa
b049e12652 ConfigureChecks: Stop checking for CMAKE_HAVE_THREADS_LIBRARY.
libssh is primarily interested in whether pthreads is present and can be
used. Checking for CMAKE_HAVE_THREADS_LIBRARY is not the same thing, as
there are cases where pthread exists but CMAKE_HAVE_THREADS_LIBRARY is not
set (for example, FreeBSD passes -DTHREADS_HAVE_PTHREAD_ARG=1 to CMake by
default as a way to skip the checks for -lpthread, -lpthreads and others and
tell the build system that -pthread is the one expected to be used).

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-03 14:39:14 +01:00
Jon Simons
785682ac28 socket: fix read of non-connected socket
Ensure to check whether the socket at hand is indeed still connected
throughout POLLIN processing in ssh_socket_pollcallback.

Before this change, the POLLIN block in ssh_socket_pollcallback is
predicated against the condition (s->state == SSH_SOCKET_CONNECTED).
Once entered, data from the socket is consumed through the data
callback in this loop:

  do {
    r = s->callbacks->data(buffer_get_rest(s->in_buffer),
                           buffer_get_rest_len(s->in_buffer),
                           s->callbacks->userdata);
    buffer_pass_bytes(s->in_buffer,r);
  } while (r > 0);

However, it is possible for the socket data callback to change the
state of the socket (closing it, for example).  Fix the loop to only
continue so long as the socket remains connected: this also entails
setting the ssh_socket state to SSH_SOCKET_CLOSED upon close.

The bug can be observed before the change by sending a bogus banner
to the server: 'echo -e "A\r\nB\r\n" | nc localhost 22'.  Each of
'A' and 'B' will be processed by 'callback_receive_banner', even
though the client socket is closed after rejection of 'A'.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-02 22:21:07 +01:00
Jon Simons
f29f10876a doc: correct ssh_channel_read_timeout units
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-02 22:21:07 +01:00
Audrius Butkevicius
45d28c7682 doc: Document expected return value of channel data callback
Signed-off-by: Audrius Butkevicius <audrius.butkevicius@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-02 22:21:07 +01:00
Audrius Butkevicius
2786565e77 src: Fix argument order in ssh_channel_pty_window_change_callback
So that it would match ssh_channel_pty_request_callback as well as the documentation

Signed-off-by: Audrius Butkevicius <audrius.butkevicius@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-02 22:21:07 +01:00
Joseph Southwell
96ad690c80 src: Define MAX_BUF_SIZE globally and use it.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-02 22:21:07 +01:00
Joseph Southwell
0d82186503 client: Fix EOF session error reporting.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-02 22:21:07 +01:00
Oleksandr Shneyder
5157d96958 Make function ssh_channel_accept() nonblocking if timeout is 0.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-02 22:21:07 +01:00
Andreas Schneider
6a0787a366 pki_crypto: Fix memory leak with EC_KEY_set_public_key().
BUG: https://red.libssh.org/issues/146
2014-01-28 12:01:35 +01:00
Andreas Schneider
709e921942 doc: Document the unit for ssh_select() timeout.
BUG: https://red.libssh.org/issues/143
2014-01-23 11:29:58 +01:00
Rod Vagg
43a69b0a65 dh: Fix NULL check for p_group14.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-01-23 11:22:22 +01:00
Jon Simons
18506f697c pki_crypto: fix DSA signature extraction
Fix the DSA portion of 'pki_signature_to_blob': before this change, it
is possible to sometimes observe DSA signature validation failure when
testing with OpenSSH clients.  The problem ended up being the following
snippet which did not account for the case when 'ssh_string_len(x)' may
be less than 20:

  r = make_bignum_string(sig->dsa_sig->r);
  ...
  memcpy(buffer,
         ((char *) ssh_string_data(r)) + ssh_string_len(r) - 20,
         20);

Above consider the case that ssh_string_len(r) is 19; in that case the
memcpy unintentionally starts in the wrong place.  The same situation
can happen for value 's' in this code.

To fix, adjust the offsets used for the input and output pointers, taking
into account that the lengths of 'r' and 's' can be less than 20.  With
the fix I am no longer able to reproduce the original failure mode.

BUG: https://red.libssh.org/issues/144

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-01-23 11:17:45 +01:00
Alan Dunn
15bede0c0e doc: Fix description of error parameter for ssh_get_error*
ssh_get_error can actually work on anything with an ssh_common_struct
as its first member.  It is already used in examples in the
distribution with ssh_sessions and ssh_binds.

Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-01-22 09:46:00 +01:00
Jon Simons
92dde09a37 pki_crypto: pad RSA signature blobs
Pad RSA signature blobs to the expected RSA signature length
when processing via 'pki_signature_to_blob'.

Some clients, notably PuTTY, may send unpadded RSA signatures
during the public key exchange: before this change, one can
sometimes observe failure in signature validation when using
PuTTY's 'plink' client, along these lines:

   ssh_packet_process: ssh_packet_process: Dispatching handler for packet type 50
   ssh_packet_userauth_request: ssh_packet_userauth_request: Auth request for service ssh-connection, method publickey for user 'foo'
   ssh_pki_signature_verify_blob: ssh_pki_signature_verify_blob: Going to verify a ssh-rsa type signature
   pki_signature_verify: pki_signature_verify: RSA error: error:04091077:rsa routines:INT_RSA_VERIFY:wrong signature length
   ssh_packet_userauth_request: ssh_packet_userauth_request: Received an invalid  signature from peer

For cross-reference this issue once also existed between
PuTTY and OpenSSH:

  http://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/rsa-verify-failed.html

  http://www.openbsd.org/cgi-bin/cvsweb/src/usr.bin/ssh/ssh-rsa.c?rev=1.19;content-type=text%2Fx-cvsweb-markup

With the fix I am unable to reproduce the above failure mode when
testing with 'plink'.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-01-21 16:12:00 +01:00
Alan Dunn
809d76cbf2 Test change to ssh_bind_accept_fd
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-01-21 16:08:12 +01:00
Alan Dunn
f78a74c160 Import keys during ssh_bind_accept_fd
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-01-21 16:08:12 +01:00
Alan Dunn
b3b3045a81 Separate out key import functionality from ssh_bind_listen
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-01-21 16:08:11 +01:00
Andreas Schneider
72fd3a73df doc: Fix channel documentation. 2014-01-17 11:09:07 +01:00
Jon Simons
cf19770ede bind: fix possible double-frees in ssh_bind_free
Make sure to explicitly set key pointers to NULL following the use
of 'ssh_key_free' throughout bind.c.

Before this change, a double free can happen via 'ssh_bind_free'
as in this example callpath:

  // create an ssh_bind
  ssh_bind b = ssh_bind_new();

  // provide a path to a wrong key-type
  ssh_bind_options_set(b, SSH_BIND_OPTIONS_DSAKEY, path_to_rsa_key);

  // initialize set key-type
  ssh_bind_listen(b);

    -> error path "The DSA host key has the wrong type: %d",

       ssh_key_free(sshbind->dsa)

         -> ssh_key_clean(key) // OK

         -> SAFE_FREE(key)     // OK, but, sshbind->dsa is *not* set to NULL

  // ssh_bind_listen failed, so clean up ssh_bind
  ssh_bind_free(b);

    -> ssh_key_free(sshbind->dsa)  // double-free here

To fix, set pointers to NULL that have been free'd with 'ssh_key_free'.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-01-16 09:27:55 +01:00
Andreas Schneider
7f42f5a3c9 cmake: Increase version numbers for 0.6.1. 2014-01-16 09:16:11 +01:00
Andreas Schneider
6223e05b23 doc: Use ssh_channel_accept_forward() in documentation. 2014-01-16 09:14:52 +01:00
Oleksandr Shneyder
634671db11 channel: Add ssh_channel_accept_forward().
This works same way as ssh_forward_accept() but can return a destination
port of the channel (useful if SSH connection forwarding several TCP/IP
ports).

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-01-16 09:13:57 +01:00
Aris Adamantiadis
1f689261ec threads: support libgcrypt 1.6 hack
Not 100% satisfied of this patch, but the way libgcrypt handles
threading in 1.6 is not compatible with custom handlers. The
new code basicaly uses pthreads in every case. This will probably
not work on windows.
2014-01-08 22:06:38 +01:00
Andreas Schneider
4919771f0f ChangeLog: Set release date. 2014-01-08 11:17:12 +01:00
Andreas Schneider
8aad24c062 include: Remove warning cause VSC doesn't know about it. 2014-01-08 10:55:39 +01:00
Andreas Schneider
0e5510bb99 include: Fix building if we do not have asm volatile. 2014-01-08 10:52:57 +01:00
Andreas Schneider
de464cb74e src: Update my mail address. 2014-01-07 16:09:04 +01:00
Andreas Schneider
c41f32bcca cmake: Remove unused macro modules. 2014-01-07 16:09:02 +01:00
Aris Adamantiadis
61e701caaa update copyright information 2014-01-07 15:18:44 +01:00
Aris Adamantiadis
1c36642fed tests: avoid reading uninitialized bytes 2014-01-07 14:43:01 +01:00
Aris Adamantiadis
ad287371fb pki: fix gcrypt signature process 2014-01-07 14:21:15 +01:00
Andreas Schneider
ebfdfd9a14 examples: Make sure buffer is initialized. 2014-01-07 09:19:30 +01:00
Andreas Schneider
c9a1be5a85 example: Add missing include for forkpty(). 2014-01-07 09:04:06 +01:00
Aris Adamantiadis
fc0db4d982 test: fixed torture_auth_none condition 2014-01-06 22:10:23 +01:00
Aris Adamantiadis
8f1a350b6e test: test case for async auth_none
This test currently fails
2014-01-06 16:52:35 +01:00
Aris Adamantiadis
15ed51cf20 tests: auth_agent_nonblocking should run in nonblocking 2014-01-06 16:52:35 +01:00
Andreas Schneider
7b2e07ecbc session: Fix a possible memory leak. 2014-01-06 16:18:06 +01:00
Aris Adamantiadis
0404d45c29 poll: fix poll_handles ownerships 2014-01-06 16:18:06 +01:00
Aris Adamantiadis
f2215d14de socket: don't attempt reading a non-connected socket 2014-01-06 16:18:06 +01:00
Aris Adamantiadis
ebbf7988b9 tests: use LC_LIBSSH instead of LANG for env tests.
LANG is stripped and replaced on many distros and LC_* is accepted
by default on debian
2014-01-06 16:17:38 +01:00
Andreas Schneider
ec307d9862 examples: Fix building samplesshd-tty on FreeBSD. 2013-12-26 16:38:38 +01:00
Andreas Schneider
2068973ff3 poll: Correctly free ssh_event_fd_wrapper.
This is allocated by ssh_event_add_fd.
2013-12-22 22:26:51 +01:00
Andreas Schneider
6eea08a9ef config: Support expansion in the Host variable too.
BUG: https://red.libssh.org/issues/127
2013-12-21 14:37:55 +01:00
Andreas Schneider
3ba2e7ace7 tests: Fix non-blocking auth tests.
The ssh_userauth_none() call should already be non-blocking. However
this this function is broken in non-blocking mode. It should reveal the
existing bug.
2013-12-15 21:04:46 +01:00
Andreas Schneider
15c64b2981 tests: Use new auth API in the torture_session test. 2013-12-15 20:30:48 +01:00
Andreas Schneider
ce5d421753 tests: Use new auth API in the torture_auth test. 2013-12-15 20:26:59 +01:00
Andreas Schneider
fd77439a12 tests: Fix pki test with gcrypt. 2013-12-11 21:12:12 +01:00
Jon Simons
a633deb985 channel: fix setting of channel->flags
Fix the setting of 'channel->flags' to use '|='.  Before this
change, one bug symptom can be that channels are never fully
free'd via ssh_channel_free, resulting in memory leaks.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-12-11 21:03:45 +01:00
Jon Simons
50b9a182f5 client: use ssh_channel_do_free in ssh_disconnect
Ensure to use 'ssh_channel_do_free' in 'ssh_disconnect', when removing and
free'ing up a session's channels.  This matches the behavior in 'ssh_free',
and is necessary to fully free any channel which may not have been closed
completely (see usage of flags SSH_CHANNEL_FLAG_CLOSED_REMOTE,
SSH_CHANNEL_FLAG_FREED_LOCAL).

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-12-11 21:03:43 +01:00
Andreas Schneider
bb88b637a9 bind: Correctly free all memory in ssh_bind_free().
Thanks to Jacob Baines.
2013-12-09 19:50:52 +01:00
Jon Simons
60d5824760 session: Add ssh_get_clientbanner(). 2013-12-07 16:24:53 +01:00
Andreas Schneider
397be918cd channels: Add a ssh_channel_read_timeout function. 2013-12-04 20:34:52 +01:00
Andreas Schneider
880fdb4b52 tests: Try to fix torture_forward. 2013-12-04 16:27:19 +01:00
Andreas Schneider
6a74677cef tests: Fix memory leaks. 2013-12-04 16:27:18 +01:00
Andreas Schneider
2c66eeaf75 pki: Fix a memory leak.
CID #1132819
2013-11-28 11:44:34 +01:00
Andreas Schneider
91edc0ee21 tests: Add torture_pki_write_privkey_ecdsa test. 2013-11-27 22:54:40 +01:00
Andreas Schneider
46bda45d95 tests: Add torture_pki_write_privkey_dsa test. 2013-11-27 22:54:40 +01:00
Andreas Schneider
9773c0852a tests: Add torture_pki_write_privkey_rsa test. 2013-11-27 22:54:40 +01:00
Andreas Schneider
f1c56e4309 pki: Add ssh_pki_import_privkey_file(). 2013-11-27 22:54:40 +01:00
Andreas Schneider
1fdc1025a8 pki_crypto: Add pki_private_key_to_pem(). 2013-11-27 22:54:40 +01:00
Andreas Schneider
a375b6c996 pki_gcrypt: Add pki_private_key_to_pem() stub. 2013-11-27 22:54:40 +01:00
Andreas Schneider
ecb01e05a2 curve25519: Fix memory leaks in ssh_server_curve25519_init().
CID #1125255
2013-11-27 22:53:53 +01:00
Andreas Schneider
b3911d0fa2 curve25519: Do not leak q_s_string.
CID #1125256
2013-11-27 22:53:53 +01:00
Andreas Schneider
1ee687ea6f curve25519: Fix a memory leak.
CID #1125257
2013-11-27 22:53:53 +01:00
Andreas Schneider
73e1f2691f examples: Fix else branch.
CID #1127816
2013-11-27 22:53:53 +01:00
Andreas Schneider
84e29f9c06 packet: Remove logically dead code.
CID #1128796
2013-11-27 22:53:53 +01:00
Andreas Schneider
23837b2080 tests: Try to fix valgrind warnings. 2013-11-27 22:53:53 +01:00
Andreas Schneider
4884f1d6fc tests: Fix a valgrind warning. 2013-11-27 22:53:53 +01:00
Andreas Schneider
ead1c4b168 ecdh: Check if we have ECC support. 2013-11-27 22:53:53 +01:00
Andreas Schneider
3e11cb8071 ecdh: Use bignum_bin2bn. 2013-11-27 22:53:48 +01:00
Nicolas Viennot
78e78642e7 server: Add a ssh_send_keepalive() function.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-24 23:21:39 +01:00
Jon Simons
7ab0e3fe62 channel: fix infinite loop in channel_write_common
BUG: https://red.libssh.org/issues/130

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-22 10:34:49 +01:00
Andreas Schneider
5da02d6de2 Update ChangeLog. 2013-11-19 10:29:59 +01:00
Rod Vagg
94db978218 flush channel after EOF and CLOSE 2013-11-18 17:23:52 +01:00
Aris Adamantiadis
78ea8608b0 logging: fix server-side logging 2013-11-18 15:28:59 +01:00
Aris Adamantiadis
7d9940d6eb gssapi: fix logging 2013-11-18 15:10:56 +01:00
Aris Adamantiadis
9f4fa22250 sockets: null pointer check 2013-11-18 14:42:06 +01:00
Simo Sorce
330f6c73f6 gssapi: Fix support of delegated credentials
In a previous refactoring patch, the code underpinning the
ssh_gssapi_set_creds() API was inadvertently removed. This patch
fixes the problem.

Also clarify what variable holds which credentials and insure that
credentials created within the library are propelry freed.

Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-17 11:43:52 +01:00
Simo Sorce
4a3934da48 gssapi: Add support for GSSAPIDelegateCredentials config option.
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-17 11:43:52 +01:00
Simo Sorce
68b996bdbf options: Add SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS option.
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-17 11:43:50 +01:00
Andreas Schneider
d364374422 gssapi: Add error checks and cleanup the code in ssh_gssapi_auth_mic(). 2013-11-15 16:29:49 +01:00
Simo Sorce
00af5bd582 gssapi: Use GSSAPIClientIdentity to acquire creds
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-15 16:29:49 +01:00
Andreas Schneider
1ab5abf0e6 gssapi: Add support for GSSAPIClientIdentity config option. 2013-11-15 16:29:49 +01:00
Andreas Schneider
f5d1d813fb options: Add SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY option. 2013-11-15 16:29:49 +01:00
Andreas Schneider
92928a7d8d gssapi: Add support for GSSAPIServerIdentity config option. 2013-11-15 16:29:49 +01:00
Andreas Schneider
651c173e72 gssapi: Add suppport to set GSSAPI server identity. 2013-11-15 16:29:49 +01:00
Simo Sorce
f76cd8b6d5 Fix gssapi credential handling.
- Properly acquire and inquitre credentials to get the list of available
credentials.
- Avoid enforcing a specific username it breaks some use cases (k5login).
- Remove confusing references to delegated credentials as there is no code
that actually uses delegated credentials in the initialization case.

Signed-off-by: Siom Sorce <simo@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-15 16:29:49 +01:00
Andreas Schneider
2bbeebd505 socket: Fix connect if we pass in a fd.
BUG: https://red.libssh.org/issues/106

Thanks to Saju Panikulam.
2013-11-15 08:54:18 +01:00
Andreas Schneider
fef32b4c14 packet: Remove dead code. 2013-11-14 11:44:12 +01:00
Andreas Schneider
2eaff2b363 packet: Set the packet to the processed data position.
Else we could end up with packet - current_macsize if to_be_read is 0.
2013-11-14 11:44:11 +01:00
Andreas Schneider
2b3e69fd5f dh: Fix wrong assignment.
Ups, sorry.
2013-11-14 08:09:42 +01:00
Andreas Schneider
cd992a90fb poll: Fix realloc in ssh_poll_ctx_resize(). 2013-11-13 16:29:41 +01:00
Andreas Schneider
6ea111fd8a dh: Avoid possible memory leaks with realloc. 2013-11-13 16:29:41 +01:00
Andreas Schneider
cda641176d packet: Refactor ssh_packet_socket_callback().
Make error checking more readable and add additional NULL checks.
2013-11-13 16:29:41 +01:00
Andreas Schneider
5581645500 server: Fix malloc call. 2013-11-13 16:29:41 +01:00
Colin Walters
3e64ef3bf5 session: Always request POLLIN
The assumption is that if libssh functions are being invoked, we want
to read data.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-09 12:29:26 +01:00
Colin Walters
7372cd837a Add ssh_get_poll_flags()
For integration with an external mainloop, we need to know how to
replicate libssh's internal poll() calls.  We originally through
ssh_get_status() was that API, but it's not really - those flags only
get updated from the *result* of a poll(), where what we really need
is to know how libssh would *start* a poll().

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-09 12:29:25 +01:00
Colin Walters
1ecf7003f6 client: If we have a pre-connected FD, set state to SOCKET_CONNECTED
Otherwise applications providing their own fd end up tripping an
assertion, since the session is just in _CONNECTING.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-09 12:29:24 +01:00
Andreas Schneider
70c54d9445 example: Use ssh_get_publickey_hash(). 2013-11-06 17:11:26 +01:00
Andreas Schneider
e52ff2c8ff dh: Move ssh_get_hexa() and ssh_print_hexa() down.
This way they are in the documentation block for the session and we get
documentation for them.
2013-11-06 17:11:25 +01:00
Andreas Schneider
9bf9d52e21 dh: Add new ssh_get_publickey_hash() function. 2013-11-06 17:11:24 +01:00
Andreas Schneider
965000129e doc: Fix doxygen warnings. 2013-11-04 21:55:58 +01:00
Aris Adamantiadis
0940c6f1b0 Fix cast warnings on 64bits 2013-11-04 10:51:17 +01:00
Aris Adamantiadis
2e6dbe8d3d remove warnings on OSX (workaround) 2013-11-04 10:51:09 +01:00
Aris Adamantiadis
8bf6907c1d curve25519: include reference implementation 2013-11-03 14:58:47 +01:00
Aris Adamantiadis
6e9e13cc24 examples: fix forktty() warning on OSX 2013-11-03 14:09:28 +01:00
Aris Adamantiadis
5bc32bfd88 Fix examples compilation on OSX (libargp) 2013-11-03 13:51:03 +01:00
Aris Adamantiadis
7c8a793b0a socket: Fix check for pending data.
BUG: https://red.libssh.org/issues/119

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-03 12:48:12 +01:00
Nicolas Viennot
e9b0a8210d server: Fix ssh_execute_server_callbacks() client execution
When the public key auth handler is executed and returns SSH_OK,
ssh_execute_server_callbacks() still runs some client callbacks,
which may set rc to SSH_AGAIN, which triggers a default reply on
auth, denying auth.

Signed-off-by: Nicolas Viennot <nicolas@viennot.biz>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-03 10:53:44 +01:00
Nicolas Viennot
fb63887c16 server kex: enable delayed compression
The code is careful to reenable compression when rekeying.

Signed-off-by: Nicolas Viennot <nicolas@viennot.biz>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-03 10:53:42 +01:00
Andreas Schneider
b113b78dfc session: Make sure we correctly burn the buffer. 2013-11-03 10:53:41 +01:00
Andreas Schneider
646112b4e4 wrapper: Make sure we really burn the buffer. 2013-11-03 10:53:40 +01:00
Andreas Schneider
ba4346f089 priv: Fix brackets of burn macros. 2013-11-03 10:53:38 +01:00
Jon Simons
401865d725 server: fix pubkey reply for key probes
Per RFC 4252, it is required to send back only one of either
SSH_MSG_USERAUTH_PK_OK or SSH_MSG_USERAUTH_FAILURE for public
key probes.

Update the handling of 'auth_pubkey_function' to send back PK_OK
instead of SSH_MSG_USERAUTH_SUCCESS for the case that the state
of the message at hand is SSH_PUBLICKEY_STATE_NONE.

With this change, it is now possible to process an initial key probe
and then subsequent signature validation using the server callbacks.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-02 21:03:20 +01:00
William Orr
d312af1ed5 ssh_options_get can now return ProxyCommand
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-02 21:03:19 +01:00
Jon Simons
3cfd8a126b connect: fix memory leak in ssh_select
Balance 'ssh_event_add_fd' with 'ssh_event_remove_fd' in 'ssh_select'.

BUG: https://red.libssh.org/issues/128

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-10-31 12:48:56 +01:00
Andreas Schneider
24ebbb8b39 tests: Add a test for ssh_channel(). 2013-10-31 12:48:55 +01:00
Jon Simons
447ee309b0 poll: fix leak in ssh_poll_ctx_free
Fix a memory leak in 'ssh_poll_ctx_free': issue 'ssh_poll_free'
to remove the poll handle from its context and free it.

BUG: https://red.libssh.org/issues/128

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-10-31 11:55:27 +01:00
Alan Dunn
6c213c913b SSH_AUTH_OK -> SSH_AUTH_SUCCESS in comments
A few callback descriptions refer to a non-existent value SSH_AUTH_OK,
which should be SSH_AUTH_SUCCESS.  This commit fixes these.

Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-10-31 08:19:35 +01:00
Andreas Schneider
f8f6eb0ce6 cmake: Check for isblank(). 2013-10-30 17:33:32 +01:00
Jon Simons
54f89af6d3 bind: fix leak in ssh_bind_accept error path
Use 'ssh_socket_free' to cleanup if 'ssh_bind_accept_fd'
fails, to be sure to free the ssh_socket in/out buffers.
2013-10-24 10:37:59 +02:00
Andreas Schneider
0e4a1b1f66 tests: Add a sftp_read blocking test. 2013-10-23 15:54:40 +02:00
Colin Walters
5eeadf533f auth: docs: Fix typo optoins -> options
I'm just getting my feet wet with this codebase.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-10-23 09:55:39 +02:00
Andreas Schneider
a4e2e01d3e doc: Improve sftp_read_sync() example. 2013-10-23 09:55:38 +02:00
Andreas Schneider
3911046f7e include: Fix build on platforms without ECC. 2013-10-21 07:16:26 +02:00
Andreas Schneider
2727af0fe6 tests: Add a test for ssh_channel_request_env(). 2013-10-20 17:06:23 +02:00
Andreas Schneider
c42da23348 tests: We can't test the accept right now. 2013-10-20 17:06:22 +02:00
Andreas Schneider
e0adcea90d tests: Fix torture_forward. 2013-10-20 17:06:21 +02:00
Andreas Schneider
a62399fcd5 channel: Reinit the buffer and reset the state on error.
BUG: https://red.libssh.org/issues/126
2013-10-20 12:47:17 +02:00
Andreas Schneider
0ee68ac2a1 channel: Fix ssh_global_request_termination().
BUG: https://red.libssh.org/issues/126
2013-10-20 12:47:16 +02:00
Andreas Schneider
796d285eaf tests: Add torture forward test. 2013-10-20 12:47:16 +02:00
Andreas Schneider
b5f71f35a3 pki: Don't leak a buffer. 2013-10-19 10:42:18 +02:00
Andreas Schneider
b98ea81903 wrapper: Fix compilation with gcrypt. 2013-10-19 10:39:44 +02:00
Andreas Schneider
beeca3c650 pki_crpypto: Fix ecdsa signature to blob.
BUG: https://red.libssh.org/issues/118
2013-10-18 23:50:09 +02:00
Andreas Schneider
9f5abdb526 pki: Add support for ECDSA private key signing. 2013-10-18 23:50:08 +02:00
Andreas Schneider
02f80eb288 pki: Add the type as a char pointer. 2013-10-18 23:50:08 +02:00
Andreas Schneider
5b7f07b484 wrapper: Add more evp functions. 2013-10-18 23:50:06 +02:00
Andreas Schneider
ec5278e34d client: Fix the build. 2013-10-18 21:19:33 +02:00
Oliver Stöneberg
e554f0dc0d scp: Fixed result of ssh_scp_string_mode() to get SCP working.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-10-18 14:59:01 +02:00
Oliver Stöneberg
e8e1916d2e client: Added a missing NULL pointer check.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-10-18 14:58:59 +02:00
Andreas Schneider
58893352b0 doc: Make sure we have the defines to build all docs. 2013-10-14 15:40:18 +02:00
Aris Adamantiadis
cdcc92e344 Compile libssh with nacl if possible
Conflicts:
	DefineOptions.cmake
2013-10-06 17:43:53 +02:00
Andreas Schneider
29b3a94032 channel: Fix packets termination timeout in global_request().
BUG: https://red.libssh.org/issues/126
2013-10-01 14:51:55 +02:00
Andreas Schneider
8f2b26a837 session: Try the ecdsa default key first. 2013-10-01 14:48:20 +02:00
Andreas Schneider
42c07f379d channels: Correctly handle timeouts in channel functions. 2013-10-01 14:47:58 +02:00
Andreas Schneider
f79c4fd7a3 channel: Use the correct timeout option in channel_open().
BUG: https://red.libssh.org/issues/124
2013-10-01 14:47:58 +02:00
Andreas Schneider
7b2aee90f0 callbacks: Improve the documentation of ssh_threads_set_callbacks().
BUG: https://red.libssh.org/issues/123
2013-10-01 14:47:58 +02:00
Andreas Schneider
aaacd18031 callbacks: Improve the documentation of ssh_threads_get_noop().
BUG: https://red.libssh.org/issues/123
2013-10-01 14:47:58 +02:00
Andreas Schneider
9f60352497 session: Document return value of ssh_get_serverbanner().
BUG: https://red.libssh.org/issues/122
2013-10-01 14:47:58 +02:00
Andreas Schneider
70c796e8b8 session: Remove obsolete status variables.
BUG: https://red.libssh.org/issues/121
2013-10-01 14:47:57 +02:00
Andreas Schneider
5b7a696cf2 client: Add example code for ssh_get_openssh_version().
BUG: https://red.libssh.org/issues/120
2013-10-01 14:47:57 +02:00
Andreas Schneider
c59568c3c1 channels: Correctly decrement timeout value in ssh_channel_accept().
BUG: https://red.libssh.org/issues/116
2013-10-01 14:47:57 +02:00
Andreas Schneider
6f10422685 channel: Document SSH_AGAIN in ssh_channel_read().
BUG: https://red.libssh.org/issues/115
2013-10-01 14:47:57 +02:00
Andreas Schneider
44f851d287 cmake: Allow to build without examples.
BUG: https://red.libssh.org/issues/114
2013-10-01 14:47:57 +02:00
Andreas Schneider
3d158fffa0 doc: Improve the PKI documentation a bit. 2013-10-01 14:47:57 +02:00
Andreas Schneider
c8be0201c6 doc: Update documentation of ssh_set_blocking().
This should work correctly in libssh 0.6.0. If not then you hit a bug.
2013-10-01 14:47:57 +02:00
Tristan CACQUERAY
a8969c4be6 callbacks: add support for auth_none_function 2013-09-27 16:06:09 +02:00
Aris Adamantiadis
8ec8d35e1a doc: Documentation of curve25519-sha256@libssh.org 2013-09-27 16:06:09 +02:00
Aris Adamantiadis
666db37e21 kex: implement curve25519-sha256@libssh.org 2013-09-27 16:06:09 +02:00
Andreas Schneider
391bd88355 scp: Document more scp functionts. 2013-08-12 11:25:15 +02:00
Andreas Schneider
5f90b77a1b cmake: Update libssh version. 2013-08-07 17:33:03 +02:00
Nicolas Viennot
af99a4dc05 server kex: Fix server side compression typo
The original code had a typo (COMP was CRYPT). This fixes the zlib compression
method.

Signed-off-by: Nicolas Viennot <nicolas@viennot.biz>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-08-05 18:27:23 +02:00
Andreas Schneider
e800269013 INSTALL: Fix source directory. 2013-08-05 18:27:23 +02:00
Andreas Schneider
ad709edadb Update INSTALL. 2013-08-05 15:07:21 +02:00
Andreas Schneider
0774da3c40 Update ChangeLog. 2013-08-05 11:07:27 +02:00
Andreas Schneider
f1ec4f11e3 cmake: Add CMOCKA_ROOT_DIR with hints and paths. 2013-08-01 16:55:40 +02:00
Andreas Schneider
3eb66cba37 doc: Update Features section. 2013-08-01 14:19:25 +02:00
Andreas Schneider
514a01f3df doc: Remove obsolete Trac header and footer. 2013-08-01 14:12:33 +02:00
Andreas Schneider
9156b8c068 doc: Better explain LIBSSH_STATIC. 2013-08-01 14:12:19 +02:00
Andreas Schneider
1067591480 cmake: Fix configure check for ntohll and htonll. 2013-07-27 11:27:09 +02:00
Andreas Schneider
7375de0b05 include: Fix a build warning in MinGW. 2013-07-27 10:55:53 +02:00
Andreas Schneider
51296a0237 tests: Add suppression for getdelim with selinux. 2013-07-26 08:04:03 +02:00
Andreas Schneider
6efa55d154 session: Add parentheses to fix a build warning. 2013-07-26 07:50:37 +02:00
Andreas Schneider
f9b8395122 session: Handle session state in ssh_get_status().
BUG: https://red.libssh.org/issues/109
2013-07-25 22:43:09 +02:00
Nicolas Viennot
cdf193d8b5 session: ssh_handle_packets_termination() SSH_AGAIN bug fix
ssh_handle_packets_termination() must not return SSH_OK when exiting due to
a timeout while the termination function still returns 1.

Signed-off-by: Nicolas Viennot <nicolas@viennot.biz>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-25 22:35:03 +02:00
Nicolas Viennot
2f674aeec1 channels: allow channel_open() to return SSH_AGAIN
Signed-off-by: Nicolas Viennot <nicolas@viennot.biz>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-25 22:34:51 +02:00
Andreas Schneider
74bbcf7e29 doc: Don't generate latex documentation. 2013-07-25 12:29:07 +02:00
Andreas Schneider
26c118890f cmake: Only build with _FORTIFY_SOURCE on release builds. 2013-07-25 10:02:01 +02:00
Andreas Schneider
38420bff76 gssapi: Fix a build warning if we build without server support. 2013-07-25 10:01:38 +02:00
Andreas Schneider
1444d62d96 cmake: Document GSSAPI_FLAVOR_MIT and GSSAPI_FLAVOR_HEIMDAL. 2013-07-24 20:52:39 +02:00
Andreas Schneider
5ba88f01e8 cmake: Rewrote FindGSSAPI.cmake. 2013-07-24 20:48:14 +02:00
Andreas Schneider
6a83f9a044 gssapi: Fix include with Heimdal. 2013-07-24 20:41:41 +02:00
Andreas Schneider
61084b76f6 example: Fix a memory leak on error in tty server.
CID: #1032746
2013-07-24 17:38:27 +02:00
Andreas Schneider
c55ab44caf cmake: Update FindNSIS module. 2013-07-24 11:17:30 +02:00
Andreas Schneider
90e5ce3c3e cmake: Set HAVE_GETADDRINFO if we have libsocket.
This fixes the build on Solaris.
2013-07-24 07:54:11 +02:00
Andreas Schneider
448738eb00 cmake: Change start time to UTC. 2013-07-24 07:49:27 +02:00
Andreas Schneider
e1280ce153 gssapi: Fix a memory leak in ssh_gssapi_auth_mic().
CID: 1046708
2013-07-23 12:27:55 +02:00
Andreas Schneider
11c45b0f55 callbacks: Fix value assigning.
CID: 1046709
2013-07-23 12:25:18 +02:00
Andreas Schneider
e1576ef55a cmake: Don't build examples on Windows but on Unix. 2013-07-23 10:44:51 +02:00
Andreas Schneider
df81a05505 cmake: Check for unistd.h. 2013-07-23 10:44:51 +02:00
Andreas Schneider
7d07e1f1bd cmake: If we don't have gssapi libs, disable it. 2013-07-23 10:44:51 +02:00
Andreas Schneider
1829e9981b cmake: Check for HAVE_GCC_VOLATILE_MEMORY_PROTECTION.
This ensures that the memset call is not optimized out by the compiler
(works works with gcc and clang).
2013-07-23 10:44:39 +02:00
Andreas Schneider
5145daba69 cmake: Define HAVE_NTOHLL and HAVE_HTONLL on Windows. 2013-07-22 13:01:36 +02:00
Andreas Schneider
729a586027 cmake: Make sure we check some functions on all platforms. 2013-07-22 13:01:36 +02:00
Andreas Schneider
8ff6a7a850 cmake: Check for _strtoui64() on Windows. 2013-07-22 13:01:36 +02:00
Andreas Schneider
dbf3cdecda auth: Fix build warning if we don't build with gssapi. 2013-07-22 13:01:36 +02:00
Andreas Schneider
35d0c3a860 connect: Fix a build warning on Windows. 2013-07-22 13:01:36 +02:00
Andreas Schneider
229ef082c1 scp: Cast return value from uint64_t to size_t. 2013-07-22 13:01:36 +02:00
Andreas Schneider
da1eaea51a gassapi: Fix check if it is enabled. 2013-07-22 10:42:30 +02:00
Andreas Schneider
329f4da1e1 options: Fix compiler warning on Windows. 2013-07-22 10:42:30 +02:00
Andreas Schneider
2c9808daf8 example: Fix location of port definition.
It shouldn't be inside #ifdef HAVE_ARGP.
2013-07-22 10:42:30 +02:00
Andreas Schneider
5e7b15e2c1 pki: Fix declaration of ssh_pki_convert functions. 2013-07-22 10:20:14 +02:00
Andreas Schneider
20312e23b7 log: Make _ssh_log() public. 2013-07-21 11:53:55 +02:00
Andreas Schneider
2106db3efa tests: Don't leak memory in torture_channel_read_error(). 2013-07-21 11:27:30 +02:00
Andreas Schneider
08c31ccf31 error: Fix logging in ssh_set_error(). 2013-07-21 11:26:55 +02:00
Andreas Schneider
f3e09612b3 options: Set log level through options too. 2013-07-21 11:26:32 +02:00
Andreas Schneider
7ed5512145 clang: Add missing defines. 2013-07-21 11:03:16 +02:00
Andreas Schneider
d1bbc35f33 gssapi: Add brackets in ssh_packet_userauth_gssapi_mic(). 2013-07-21 11:03:00 +02:00
Andreas Schneider
f458055e9c gssapi: Cleanup ssh_gssapi_set_creds(). 2013-07-21 10:58:30 +02:00
Andreas Schneider
4103358daa gssapi: Replace printf with SSH_LOG. 2013-07-21 10:56:47 +02:00
Andreas Schneider
1ab4b28b00 messages: Split ssh_execute_server_callbacks() in small functions. 2013-07-21 10:53:18 +02:00
Andreas Schneider
461988b153 session: Add brackets to ssh_handle_packets_termination(). 2013-07-21 10:35:18 +02:00
Andreas Schneider
c4937cedea misc: Use the szPath variable instead of calling getenv. 2013-07-16 13:36:52 +02:00
Andreas Schneider
11c82a26a6 channels: Fix a SSH_LOG call. 2013-07-15 08:07:34 +02:00
Andreas Schneider
351e4107ed examples: Check return value of fstat().
CID #743297
2013-07-14 15:02:11 +02:00
Andreas Schneider
776ff528df examples: Make sure we have a valid scp pointer.
CID #1032343
2013-07-14 15:02:11 +02:00
Andreas Schneider
22e8858134 agent: Fix possible segfaults due to NULL pointer deref.
CID #1035578
2013-07-14 15:02:11 +02:00
Andreas Schneider
483ba8100f examples: Check return value of ssh_event_dopoll().
CID #0
2013-07-14 15:02:08 +02:00
Andreas Schneider
0138c9fd59 gssapi: Refactor ssh_gssapi_send_mic() to not leak memory.
CID #0
2013-07-14 15:02:05 +02:00
Andreas Schneider
831ed08a56 gssapi: Check return values of buffer functions.
CID #0
2013-07-14 15:02:02 +02:00
Andreas Schneider
1467e0782e gssapi: Remove dead code.
CID #0
2013-07-14 15:01:59 +02:00
Andreas Schneider
ecec2abfc7 gssapi: Refactor ssh_gssapi_build_mic() to avoid memory leaks.
CID #0
2013-07-14 15:01:57 +02:00
Andreas Schneider
8f0b6ccd66 gssapi: Fix a possible memory leak.
CID #0
2013-07-14 15:01:55 +02:00
Andreas Schneider
b4790fbdd2 gssapi: Fix a memory leak.
CID #0
2013-07-14 15:01:52 +02:00
Andreas Schneider
df373efc56 callbacks: Still support the legacy callback. 2013-07-14 14:12:08 +02:00
Andreas Schneider
e3b4f27aa9 examples: Remove ssh_log from ssh client example. 2013-07-14 13:35:25 +02:00
Andreas Schneider
c64ec43eef src: Remove enter_function() and leave_function(). 2013-07-14 13:31:24 +02:00
Andreas Schneider
0d3deeec10 options: Use the new function to use the log level. 2013-07-14 12:53:01 +02:00
Andreas Schneider
c28efb8cbc include: Mark ssh_log as depcrecated. 2013-07-14 12:44:32 +02:00
Andreas Schneider
ebdd0c6ac1 src: Migrate to SSH_LOG. 2013-07-14 12:44:26 +02:00
Andreas Schneider
dcd94de076 error: Use new logging function. 2013-07-14 12:37:12 +02:00
Andreas Schneider
a73557053e doc: Document public functions. 2013-07-14 12:37:12 +02:00
Andreas Schneider
2c91efcc68 log: Implment new logging functions. 2013-07-14 12:36:59 +02:00
Andreas Schneider
73309f19e5 cmake: Check if we have Thread Local Storage support. 2013-07-14 12:36:35 +02:00
Aris Adamantiadis
6ad80bb4b2 examples: fix warning 2013-07-14 11:18:13 +02:00
Aris Adamantiadis
365a3bba6e auth: fix warnings with missing switch() params 2013-07-14 09:35:30 +02:00
Aris Adamantiadis
e95e3b5736 examples: fix compilation warnings 2013-07-14 09:32:19 +02:00
Aris Adamantiadis
ad92740dc3 server: Fix compilation without WITH_SERVER 2013-07-14 09:30:59 +02:00
Aris Adamantiadis
bf5e5eebd7 pki: fix comments 2013-07-13 23:01:30 +02:00
Aris Adamantiadis
9d88dcab3e Server: disallow channel opening till authenticated 2013-07-13 22:56:32 +02:00
Aris Adamantiadis
dd6a0b51ac Server: fix rekeying 2013-07-13 22:56:07 +02:00
Aris Adamantiadis
3b81da21c2 DH: fix rekeying when using aes256 and bigger 2013-07-13 18:12:10 +02:00
Andreas Schneider
ed7e3c936b cmake: Don't make GSSAPI a hard requirement. 2013-07-13 15:50:57 +02:00
Andreas Schneider
1663917f71 cmake: Make GSSAPI optional. 2013-07-13 15:48:49 +02:00
Andreas Schneider
9bbbccc0e7 auth: Remove unused code. 2013-07-13 15:29:53 +02:00
Aris Adamantiadis
c44029e5ce gssapi: Fix indentation.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 15:23:33 +02:00
Aris Adamantiadis
c231029be3 gssapi: Fix ticket forwarding bug
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 15:23:33 +02:00
Aris Adamantiadis
2ab7f2be75 server: add pubkey auth callback
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 15:23:33 +02:00
Aris Adamantiadis
47a4eea827 examples: fix with new gssapi cb API
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 15:23:33 +02:00
Aris Adamantiadis
0d1ec1fa48 gssapi: Add user parameter to gssapi auth callback
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 15:03:18 +02:00
Aris Adamantiadis
0356b78ede gssapi: remove dead code
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 15:02:52 +02:00
Aris Adamantiadis
b0ab39a6f1 gssapi: gssapi callbacks serverside
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 15:02:03 +02:00
Aris Adamantiadis
31a129ee9e sftp: more flexibility on channels
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 15:01:17 +02:00
Aris Adamantiadis
7e7910a1ca sftp: added useful server APIs
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 15:00:52 +02:00
Aris Adamantiadis
55ddc3932e gssapi: more debug info
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:59:56 +02:00
Aris Adamantiadis
2a0c1e917f server: callback for channel_request_subsystem
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:59:46 +02:00
Aris Adamantiadis
db20a22e51 server: added 2 missing channel callbacks
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:59:21 +02:00
Aris Adamantiadis
560b508771 events: don't poll handles busy handling callbacks
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:58:47 +02:00
Aris Adamantiadis
f528f71920 agent: the valid request is auth-agent@openssh.com
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:58:18 +02:00
Aris Adamantiadis
458e4c07c7 server: export ssh_channel_open_x11()
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:58:06 +02:00
Aris Adamantiadis
7555f3235e client: call client callback even in non-server mode
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:57:48 +02:00
Aris Adamantiadis
3e7bd72f76 client: handle x11 channel open requests with callbacks
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:57:13 +02:00
Aris Adamantiadis
f457080d62 server: Implement X11 requests and window-change
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:56:37 +02:00
Aris Adamantiadis
37cce98f7e Doc: fix a few broken parameters
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:56:14 +02:00
Aris Adamantiadis
7e306a9ec6 server: implement server-side of agent forwarding
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:55:58 +02:00
Aris Adamantiadis
81e769ec6a channels: implement callback for agent forwarding request
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:55:47 +02:00
Aris Adamantiadis
e809fa881e examples: adapt samplesshd-cb to new callback
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:54:15 +02:00
Aris Adamantiadis
52d9e15c25 examples: adapt to the new callback format
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:51:00 +02:00
Aris Adamantiadis
e933d1e1b1 callbacks: make the channel accept callback more logical
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:51:00 +02:00
Aris Adamantiadis
e76442b650 ssh-agent: implement the clientside for agent forwarding auth.
This can only be used to authenticate the client, not to allow the
connected server to transfer agent requests

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:51:00 +02:00
Aris Adamantiadis
9bdb546852 Examples: Exemple of an SSH proxy
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:51:00 +02:00
Aris Adamantiadis
86ae29b30d gssapi: implement ticket delegation
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:51:00 +02:00
Aris Adamantiadis
65eccf1969 gssapi: retrieve forwarded (delegated) tickets
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:50:56 +02:00
Aris Adamantiadis
d944310412 auth: store client's credentials
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:41:28 +02:00
Aris Adamantiadis
7cb6b15aaa auth: implement client-side gssapi
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:41:20 +02:00
Aris Adamantiadis
212261bb10 examples:Compile samplessh on bsd too
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:25:32 +02:00
Aris Adamantiadis
fadbe80c43 options: Fix null ptr deference introduced in earlier fix.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:24:57 +02:00
Aris Adamantiadis
7fef6e817e auth: implement gssapi-with-mic server side
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:21:36 +02:00
Aris Adamantiadis
1246ad812c server: move message-specific call to ssh_*
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:21:36 +02:00
Aris Adamantiadis
3b52e38a33 auth: adapt libssh to gssapi-with-mic server
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:21:36 +02:00
Aris Adamantiadis
6bb5063046 example: adapt example for gssapi callback
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:19:23 +02:00
Aris Adamantiadis
950d8e89a9 callbacks: new callbacks for gssapi
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:19:23 +02:00
Aris Adamantiadis
6c26a23cf4 build: build with gssapi if detected
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:19:23 +02:00
Aris Adamantiadis
b69c26ad72 build: detect gssapi.h
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:19:23 +02:00
Aris Adamantiadis
cb0f886a5c cmake: Add FindGSSAPI.cmake
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:19:23 +02:00
Aris Adamantiadis
3d7b24c534 gssapi: added SSH constants
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:12:06 +02:00
Aris Adamantiadis
4c99f5de4d GSSAPI: added stub
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:11:26 +02:00
Aris Adamantiadis
a34ad5825b Added server example with callbacks impl
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:10:03 +02:00
Aris Adamantiadis
4497cd9b43 Make examples more BSD friendly
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:08:44 +02:00
Aris Adamantiadis
2b54db7603 Try to find ARGP on solaris, BSD
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:07:46 +02:00
Aris Adamantiadis
ff30a8feb0 Implement callbacks for servers in the message queue
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:06:57 +02:00
Aris Adamantiadis
82b4cffe66 bind: ssh_pki functions also return SSH_EOF error code
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:03:55 +02:00
Aris Adamantiadis
66b37c856c session: Introduce SSH_TIMEOUT_DEFAULT
The default timeout of 30seconds is very nice when connecting to a new SSH
session, however it completely breaks the synchronous blocking API.
Use SSH_TIMEOUT_DEFAULT when in blocking mode so channel reads&write are blocking
as expected

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:03:42 +02:00
Aris Adamantiadis
6bc64c368d server: added channel callbacks
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 14:00:18 +02:00
Aris Adamantiadis
ab2e641b4a Defined SSH server callbacks interface
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-13 13:59:58 +02:00
Andreas Schneider
48b715cce0 tests: Use fstat() after the open(). 2013-07-13 13:59:58 +02:00
Andreas Schneider
97e7c95d21 cmake: Pass _FORTIFY_SOURCE directly to the preprocessor. 2013-07-13 13:54:00 +02:00
Andreas Schneider
e52cc613e4 BUG 103: Disable proxy command if set to 'none'.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2013-07-11 15:34:50 +02:00
Andreas Schneider
89be6d0309 examples: Check return value of fileno(). 2013-06-19 12:32:10 +02:00
Andreas Schneider
36e4c2e5bc messages: Fix a possible memory leak. 2013-06-19 12:29:54 +02:00
Andreas Schneider
aed9d7a84d agent: Fix a possible memory leak. 2013-06-19 12:24:00 +02:00
Andreas Schneider
f0a362fdbe agent: Fix possible memory leak. 2013-06-19 12:19:05 +02:00
Andreas Schneider
de4cb811a0 examples: Fix a possible memory leak. 2013-06-19 12:16:57 +02:00
Andreas Schneider
abb25861e5 examples: Fix a possible memory leak. 2013-06-19 12:14:25 +02:00
Andreas Schneider
b698f6361c kex1: Fix a possible null pointer dereference. 2013-06-19 12:06:43 +02:00
Andreas Schneider
e6be005236 ecdh: Add missing return in ssh_client_ecdh_init(). 2013-06-19 12:04:38 +02:00
Andreas Schneider
8a4364a99b ecdh: Avoid memory leaks in ssh_server_ecdh_init(). 2013-06-19 11:19:08 +02:00
Andreas Schneider
6dae8baefc src: Add fall trough comments. 2013-06-18 17:17:23 +02:00
Andreas Schneider
94a8c30feb pki: Fix switch statement of pki_key_generate_ecdsa(). 2013-06-18 17:16:59 +02:00
Andreas Schneider
68be73ec0d tests: Check return value of stat. 2013-06-18 17:11:34 +02:00
Andreas Schneider
485e3b4014 tests: Check return values of buffer functions. 2013-06-18 17:10:00 +02:00
Andreas Schneider
1deb3412bb connect: Use the correct close function. 2013-06-18 17:06:58 +02:00
Andreas Schneider
aaae3c4ec1 connect: Correctly fail in ssh_connect_host_nonblocking(). 2013-06-18 17:05:57 +02:00
Andreas Schneider
b31efd9ff1 ecdh: Make sure we don't leak memory in ssh_client_ecdh_init().
This also adds more checks for return values.
2013-06-18 17:02:40 +02:00
Andreas Schneider
5d05aec2ef auth: Cleanup the agent return code. 2013-06-18 16:42:33 +02:00
Nicolas Viennot
6306bee86c auth: If the agent fails, fall back to regular path
It's causing issues on MacOSX when ssh_agent_get_ident_count()
reports "Agent count: 0".
2013-06-18 16:39:31 +02:00
Andreas Schneider
59dcebd604 sample: Fix a possible buffer overrun. 2013-06-17 13:27:40 +02:00
Andreas Schneider
7ceaea479e kex1: Fix null check of hostkey. 2013-06-17 13:21:51 +02:00
Andreas Schneider
2b68728552 socket: Check if socket (non)blocking is working. 2013-06-17 13:18:55 +02:00
Andreas Schneider
42c7bc5a21 socket: Check return value of getsockopt(). 2013-06-17 13:09:50 +02:00
Andreas Schneider
ee47cab548 packet: Fix a possible segfault. 2013-06-17 13:04:27 +02:00
Andreas Schneider
a65029da5d messages: Fix a possible segfault. 2013-06-17 13:02:49 +02:00
Andreas Schneider
f31c33bb31 ecdh: Check return values of buffer_add_* functions. 2013-06-17 12:59:22 +02:00
Andreas Schneider
4255a7223c dh: Check return value of buffer_add_ssh_string(). 2013-06-17 12:53:26 +02:00
Andreas Schneider
9ee45a18d7 connect: Check return value of getsockopt(). 2013-06-17 12:47:21 +02:00
Andreas Schneider
0ba075e9ce channels1: Check return value of buffer_add_u8(). 2013-06-17 12:40:35 +02:00
Andreas Schneider
d93e38bbfe examples: Check return value of ssh_channel_read. 2013-06-17 12:35:42 +02:00
Andreas Schneider
e4bcd063b7 packet1: Don't free an invalid address. 2013-06-17 12:10:55 +02:00
Andreas Schneider
d83b3d9ebe pki: Limit privkey to 4M for now. 2013-06-17 12:07:32 +02:00
Andreas Schneider
6f8b5ed679 pki: Fix a resource leak on error. 2013-06-17 11:49:13 +02:00
Andreas Schneider
d255d1bf32 tests: Use memory assert functions. 2013-06-17 11:44:28 +02:00
Andreas Schneider
33e95792ce pki: Fix resource leak on error. 2013-06-13 15:46:53 +02:00
Andreas Schneider
a38c56370c torture: Fix a resource leak on error. 2013-06-13 15:43:50 +02:00
Andreas Schneider
01493b8d47 tests: Don't leak memory. 2013-06-13 15:42:13 +02:00
Andreas Schneider
1a894e2cf2 client: Fix possible NULL pointer dereference. 2013-06-13 11:46:17 +02:00
Andreas Schneider
b8a3e5ffe3 known_hosts: Fix readablity. 2013-06-13 11:08:37 +02:00
Andreas Schneider
09663692dd pki: Use fstat() after opening the file. 2013-06-13 11:04:59 +02:00
Andreas Schneider
a03d8f49fb examples: Fix a use after free in scp example. 2013-06-13 10:55:12 +02:00
Andreas Schneider
abd6b8004e kex: Fix a double free. 2013-06-13 10:51:12 +02:00
Andreas Schneider
e3c5096fcf server: Fix a double free. 2013-06-13 10:48:50 +02:00
Andreas Schneider
51a531f4a7 tests: Check the return value of write. 2013-06-11 09:59:22 +02:00
Andreas Schneider
fcf8af20f8 BUG 103: Fix ProxyCommand parsing. 2013-06-02 19:29:28 +02:00
Andreas Schneider
2d28ee7d22 config: Rename ssh_config_get_str(). 2013-06-02 18:54:16 +02:00
Andreas Schneider
e41482fec4 opts: Fix segfault in option parser. 2013-06-02 18:34:39 +02:00
Andreas Schneider
992f00b145 getpass: Don't fail if stdin is not a tty.
We don't need to manipulate the tty state (such as turning off echo)
when prompting for passwords if we're not reading from a tty.
2013-04-05 14:14:22 +02:00
Andreas Schneider
24e94d53e9 cmake: Fix installation path for some strange platforms. 2013-03-20 09:38:03 +01:00
Andreas Schneider
8455d79bb6 priv: Make really sure memset doesn't get optimzed out. 2013-03-13 15:37:51 +01:00
Aris Adamantiadis
222a0d78ca poll: return error on poll() when pollset is empty 2013-02-26 23:52:25 +01:00
Andreas Schneider
e471aa4e0b cmake: Fix config include dir variable name. 2013-02-13 15:30:23 +01:00
Andreas Schneider
5d6cab4b14 cmake: Add cmake config files for new find_package() mode. 2013-02-12 13:32:34 +01:00
Andreas Schneider
afe4c92bbf cmake: Fix setting -D_FORTIFY_SOURCE=2. 2013-02-07 17:02:51 +01:00
Johannes Krude
186116f34a socket: Call data handler as long as handler takes data.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-01-29 10:56:49 +01:00
Andreas Schneider
b2f52799c2 include: Fix the LGPL header.
This has been reported by rpmlint:
libssh-devel.x86_64: W: incorrect-fsf-address libssh.h
2013-01-23 00:22:46 +01:00
Andreas Schneider
915781381e BUG 99: Fix string function if no build type is set. 2013-01-22 16:28:25 +01:00
Andreas Schneider
21a45e89c5 options: Fix a free crash bug if we parse unknown options.
Thanks to Yong Chuan Koh, X-Force Research <kohyc@sg.ibm.com>
2013-01-22 11:32:47 +01:00
Aris Adamantiadis
de096910b3 Report according status when errors are detected 2012-12-27 22:01:37 +01:00
Aris Adamantiadis
ce33633bcb Test for bug #64, ssh_channel_read doesn't detect errors 2012-12-27 22:01:08 +01:00
Andreas Schneider
fb3f649c76 cmake: Only set -D_FORTIFY_SOURCE=2 if we have optimizations. 2012-12-25 17:35:07 +01:00
Aris Adamantiadis
5dfc474fa8 Benchmarks: parse config files 2012-12-23 23:10:52 +01:00
Aris Adamantiadis
6d61c3ce4a Fix channel_write to wait during key reexchanges 2012-12-23 23:10:29 +01:00
Aris Adamantiadis
63c3f0e736 Implement key re-exchange 2012-12-23 23:09:50 +01:00
Andreas Schneider
e934ab0816 BUG 82: Fix function names of ssh_forward_*. 2012-12-19 18:15:54 +01:00
Andreas Schneider
9fa53cd932 doc: Fix forward function names. 2012-12-19 18:10:16 +01:00
Andrew Collins
5cd7942801 Fix an invalid strlen comparison in ssh_message_auth_reply_default
During the transition to strncat in ssh_message_auth_reply_default,
an invalid strlen comparison was added which causes the function
to fail whenever it's called.

Signed-off-by: Andrew Collins <bsderandrew@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2012-12-19 16:03:49 +01:00
Andreas Schneider
de9bc1fa41 string: Fix memory leak in ssh_string_to_char().
This was probably a mistake by me fixing up a patch after merging.
2012-12-13 19:29:46 +01:00
Andreas Schneider
b14df297fa BUG 97: Fix strtoull() detection on serveral platforms. 2012-12-03 14:00:06 +01:00
Andreas Schneider
3896aa43ff BUG 96: Guard ntohll() and htonll prototypes correctly. 2012-12-03 13:44:02 +01:00
Andreas Schneider
da8d44ccba BUG 98: Use __attribute__ ((packed)) only with GCC. 2012-12-03 13:19:29 +01:00
Andreas Schneider
c6fc69fbdd BUG 97: Remove obsolete hsterror().
This function is pretty much obsolete on most platforms. The standard
errno should be used. If it is not enough on Windows we should use
WSAGetLastError() in future.
2012-12-03 13:08:17 +01:00
Andreas Schneider
ab8c7de6f8 BUG 94: Fix big endian issue. 2012-12-03 12:35:36 +01:00
Aris Adamantiadis
cd4e28e7c8 test: Try to fetch wrong values in buffer.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2012-11-27 19:10:41 +01:00
Andreas Schneider
ea0e858de0 priv: Add BURN_BUFFER macro and make sure it isn't optimzed out. 2012-11-23 11:56:21 +01:00
Andreas Schneider
e403596d98 pki: Add a size limit for pubkey files. 2012-11-21 12:44:00 +01:00
Andreas Schneider
571dc42335 CVE-2012-4559: Make sure we don't free name and longname twice on error. 2012-11-14 17:36:24 +01:00
Andreas Schneider
68d04c8e47 CVE-2012-4559: Ensure that we don't free req twice. 2012-11-14 17:36:24 +01:00
Andreas Schneider
bd3acae4f3 CVE-2012-4560: Fix a write one past the end of 'buf'. 2012-11-14 17:36:24 +01:00
Andreas Schneider
894bbf3137 CVE-2012-4560: Fix a write one past the end of the 'u' buffer. 2012-11-14 17:36:24 +01:00
Andreas Schneider
f61813eaea CVE-2012-4562: Fix a possible infinite loop in buffer_reinit().
If needed is bigger than the highest power of two or a which fits in an
integer we will loop forever.
2012-11-14 17:36:22 +01:00
Xi Wang
ad5f306884 CVE-2012-4562: Fix multiple integer overflows in buffer-related functions. 2012-11-14 17:36:19 +01:00
Xi Wang
5ffb8c7cde CVE-2012-4562: Fix possible integer overflows. 2012-11-14 17:36:16 +01:00
Xi Wang
efaebad323 CVE-2012-4562: Fix possible integer overflow in ssh_get_hexa().
No exploit known, but it is better to check the string length.
2012-11-14 17:36:11 +01:00
Xi Wang
cab00c3bfc pki: Fix integer overflow in ssh_pki_import_privkey_file().
If the file size is ULONG_MAX, the call to malloc() may allocate a
small buffer, leading to a memory corruption.
2012-10-22 21:00:08 +02:00
Xi Wang
d404ad7152 channels: Fix integer overflow in generate_cookie().
Since the type of rnd[i] is signed char, (rnd[i] >> 4), which is
considered as arithmetic shift by gcc, could be negative, leading
to out-of-bounds read.
2012-10-22 21:00:08 +02:00
Andreas Schneider
a4ffaff550 channels1: Add missing request_state and set it to accepted.
This fixes bug #88.
2012-10-22 18:05:06 +02:00
Andreas Schneider
e164b236c6 auth1: Reset error state to no error.
This fixes bug #89.
2012-10-22 18:01:39 +02:00
Andreas Schneider
166ccef8dc session: Fix a possible use after free in ssh_free().
We need to cleanup the channels first cause we call ssh_channel_close()
on the channels which still require a working socket and poll context.

Thanks to sh4rm4!
2012-10-22 17:37:32 +02:00
Andreas Schneider
f2e498c7db cmake: Set GNU compiler flags also for clang. 2012-10-22 16:05:39 +02:00
Andreas Schneider
dde0404dfb cmake: Add message if we build with static library. 2012-10-15 11:55:42 +02:00
Andreas Schneider
f86b2bf743 doc: Update copyright policy. 2012-10-14 19:58:07 +02:00
Andreas Schneider
13c26f0733 options: Fix documentation of ssh_options_get_port(). 2012-10-14 19:53:51 +02:00
Andreas Schneider
f5d8bdf946 doc: Update doxygen config. 2012-10-14 19:52:28 +02:00
Andreas Schneider
f4f2237263 doc: Use the correct channel functions. 2012-10-14 19:44:02 +02:00
Andreas Schneider
7e93edc722 cmake: Add better check to detect -fvisibility=hidden. 2012-10-14 18:40:05 +02:00
Andreas Schneider
95ab34696b kex: Use getter functions to access kex arrays.
This should fix the build on OpenIndiana.
2012-10-12 17:46:37 +02:00
Andreas Schneider
82711acd39 cmake: Fix building with gcrypt support. 2012-10-12 17:07:20 +02:00
Andreas Schneider
e8118c5be4 tests: Add a valgrind suppression for getaddrino leak.
https://bugzilla.redhat.com/show_bug.cgi?id=859717
2012-10-12 14:45:54 +02:00
Andreas Schneider
a59a379ce4 tests: Add a valgrind suppression for OPENSSL_cleanse(). 2012-10-12 14:45:54 +02:00
Andreas Schneider
0bd2bbefa7 scp: Make sure buffer is initialzed.
Found by Coverity.
2012-10-12 14:45:54 +02:00
Andreas Schneider
3d390cf6ff pki: Make sure the key_buf is null terminated.
Found by Coverity.
2012-10-12 14:45:54 +02:00
Andreas Schneider
e04dc45f20 misc: Use a fixed buffer for getenv(). 2012-10-12 14:45:54 +02:00
Andreas Schneider
de34a64895 poll: Fix sizeof in ssh_poll_ctx_resize().
sizeof(ssh_poll_handle *) is to be equal to sizeof(ssh_poll_handle), but
this is not a portable assumption.

Found by Coverity.
2012-10-12 14:45:54 +02:00
Andreas Schneider
46f22576b0 legacy: Use snprintf instead of sprintf.
Found by Coverity.
2012-10-12 14:45:54 +02:00
Andreas Schneider
2f8ddc6e65 dh: Don't use strcat for ssh_get_hexa().
This is just hardening the code.

Found by Coverity.
2012-10-12 14:45:54 +02:00
Andreas Schneider
b1287cd946 server: Use strncat instead of strcat.
This is just hardening the code.

Found by Coverity.
2012-10-12 14:45:54 +02:00
Andreas Schneider
a660177a6e misc: Use strncpy instead of strcat.
This is just hardening the code.

Found by Coverity.
2012-10-12 14:45:36 +02:00
Andreas Schneider
0a4ea19982 pki: Fix a possible null pointer dereference.
Found by Coverity.
2012-10-12 08:07:02 +02:00
Andreas Schneider
0bf2dd81e6 messages: Fix memory leaks in user request callback. 2012-10-12 08:07:02 +02:00
Andreas Schneider
ecb6cfd053 connect: Don't leak the addressinfo on error. 2012-10-12 08:07:02 +02:00
Andreas Schneider
ba220adb84 connect: Don't leak the file descriptor on error.
Found by Coverity.
2012-10-12 08:07:02 +02:00
Andreas Schneider
802e4133cb session: Don't leak memory in ssh_send_debug().
Found by Coverity.
2012-10-12 08:07:02 +02:00
Andreas Schneider
dde3deb9ea channels: Don't leak memory in channel_rcv_request callback.
Found by Coverity.
2012-10-12 08:07:02 +02:00
Andreas Schneider
66045054f4 auth: Don't leak memory on error in info request callback.
Found by Coverity.
2012-10-12 08:07:01 +02:00
Andreas Schneider
96e0301b58 dh: Don't leak 'f' on error.
Found by Coverity.
2012-10-12 08:07:01 +02:00
Andreas Schneider
029d165b61 legacy: Don't leak the key struct on error.
Found by Coverity.
2012-10-12 08:07:01 +02:00
Andreas Schneider
4e7736444f server: Don't leak memory on calling ssh_string_from_char().
Also check the return values.

Found by Coverity.
2012-10-12 08:07:01 +02:00
Andreas Schneider
7254390ac2 pki: Don't leak the signature on error paths.
Found by Coverity.
2012-10-12 08:07:01 +02:00
Andreas Schneider
188c596803 sftp: Don't leak owner and group in sftp_parse_attr_4. 2012-10-12 08:07:01 +02:00
Andreas Schneider
0295301928 known_hosts: Don't leak memory in ssh_write_knownhost error paths.
Found by Coverity.
2012-10-12 08:07:01 +02:00
Andreas Schneider
a6e7d1f255 agent: Fix some memory leaks in error paths.
Found by Coverity.
2012-10-12 08:07:01 +02:00
Andreas Schneider
f2c183b413 include: Fix an include recursion.
It includes itself: libssh.h -> legacy.h -> libssh.h.

Found by Coverity.
2012-10-12 08:07:01 +02:00
Andreas Schneider
5e8e21d106 options: Check return code of ssh_iterator_value.
Found by Coverity.
2012-10-12 08:07:01 +02:00
Andreas Schneider
bcc00eec9b kex: Don't compare an array to null.
Found by Coverity.
2012-10-12 08:07:01 +02:00
Andreas Schneider
53008fb5d4 string: Don't compare an array to null.
Found by Coverity.
2012-10-12 08:07:01 +02:00
Andreas Schneider
9338fb8e5e message: Set correct request type.
Found by Coverity.
2012-10-12 08:07:01 +02:00
Andreas Schneider
ec5b4d377f sftpserver: Add missing break statement.
Found by Coverity.
2012-10-12 08:07:01 +02:00
Andreas Schneider
6352b3d93a server: Fix for loop to free server methods.
Found by Coverity.
2012-10-12 08:06:55 +02:00
Andreas Schneider
b8de9e75d0 client: If session is NULL we can't set an error.
Found by Coverity.
2012-10-09 11:09:34 +02:00
Andreas Schneider
ec56d1d453 match: Don't dereference 's' directly.
Found by Coverity.
2012-10-09 11:09:34 +02:00
Andreas Schneider
87036839f9 example: Simplify auth_callback of the client.
Found by Coverity.
2012-10-09 11:09:34 +02:00
Andreas Schneider
131a0de32e auth: Make error handling code reachable again.
Found by Coverity.
2012-10-09 11:09:34 +02:00
Andreas Schneider
3e93836e8b pki: Make error handling code reachable again.
Found by Coverity.
2012-10-09 11:09:34 +02:00
Andreas Schneider
21db70888a socket: Check return value of buffer function.
Found by Coverity.
2012-10-09 11:09:34 +02:00
Andreas Schneider
bb2848de5a channels: Check return values of buffer functions.
Found by Coverity.
2012-10-09 11:09:34 +02:00
Andreas Schneider
6acce40a28 scp: Check return value of ssh_channel_poll.
Found by Coverity.
2012-10-09 11:09:34 +02:00
Andreas Schneider
41269874f5 packet: Check return values of buffer functions.
Found by Coverity.
2012-10-09 11:09:34 +02:00
Andreas Schneider
9abe591843 client: Check return value of ssh_handle_packets_termination.
Found by Coverity.
2012-10-09 11:09:34 +02:00
Andreas Schneider
114cc51a10 pcap: Check return codes of buffer_add_* functions.
Found by Coverity.
2012-10-09 11:09:34 +02:00
Andreas Schneider
9fe47da903 torture: Fix keyboard interactive authentication. 2012-10-09 10:11:55 +02:00
Andreas Schneider
362be13156 tests: Make sure the array is null terminated. 2012-10-07 23:23:33 +02:00
Andreas Schneider
e17fcd70f9 torture: Use new userauth functions. 2012-10-07 23:21:17 +02:00
Andreas Schneider
5f0f334d1c pki: Don't leak memory in pubkey to blob. 2012-10-07 22:36:06 +02:00
Andreas Schneider
996b7cae26 pki: Make sure we don't double free pointers. 2012-10-07 22:35:33 +02:00
Andreas Schneider
b219d1890c tests: Don't leak memory in options test. 2012-10-07 22:15:20 +02:00
Andreas Schneider
bfa568e448 pki: Check for no memory available calling ssh_key_new(). 2012-10-07 22:04:58 +02:00
Andreas Schneider
ff53664f54 sftp: Fix a possible null pointer dereference in sftp_async_read. 2012-10-07 22:03:35 +02:00
Andreas Schneider
b811b89f57 channels1: Fix severa possible null pointer dereferences. 2012-10-07 22:01:48 +02:00
Andreas Schneider
3db2ac41eb pki: Handle error of pki_import_pubkey_buffer() correctly. 2012-10-07 21:53:37 +02:00
Andreas Schneider
ca74d91d50 example: Clear the password. 2012-10-07 21:49:45 +02:00
Andreas Schneider
956cf94f70 server: Removed unused variable keytype in the ecdsa case. 2012-10-07 21:31:49 +02:00
Andreas Schneider
191faea325 misc: Use size_t for len. 2012-10-07 18:06:33 +02:00
Andreas Schneider
0493c1fea9 tests: Don't run ecdh tests if not supported by crypto lib. 2012-10-07 12:04:58 +02:00
Andreas Schneider
ecd2ee95e7 kex: Fix supported methods index. 2012-10-07 12:03:54 +02:00
Andreas Schneider
c81010e2f7 test: Use cmocka instead of cmockery.
cmocka is the successor of cmockery.

http://git.cryptomilk.org/projects/cmocka.git/
2012-10-07 11:10:27 +02:00
Andreas Schneider
c078e36219 example: Fix a build warning. 2012-10-07 10:56:10 +02:00
Andreas Schneider
c5782b7486 session: Make sure we don't segfault on freeing id. 2012-10-07 10:52:54 +02:00
Dmitriy Kuznetsov
1e836a03d2 gcrypt: Fix simple DES support. 2012-10-05 11:22:15 +02:00
Andreas Schneider
ceb8072b34 channel: Fix a possible null pointer dereference. 2012-10-05 11:17:06 +02:00
Andreas Schneider
656fd60110 channels: Fix a possible null pointer dereference. 2012-10-05 11:16:03 +02:00
Andreas Schneider
6092596199 getpass: Fix a memory leak in ssh_gets() on error. 2012-10-05 11:12:14 +02:00
Andreas Schneider
22f607649d sftp: Harden sftp_extension_supported() against null pointers. 2012-10-05 11:12:14 +02:00
Andreas Schneider
b5c4b090da sftp: Fix a memory on error in sftp_opendir(). 2012-10-05 11:12:13 +02:00
Andreas Schneider
fd2064d0b4 messages: Fix error path of ssh_packet_userauth_info_response.
This fixes a memory leak on error.
2012-10-05 11:12:13 +02:00
Andreas Schneider
8567fc8d8c messages: Fix a possible null pointer dereference. 2012-10-05 11:12:13 +02:00
Andreas Schneider
61d032fc03 misc: Don't leak memory on ssh_path_expand_escape() on error. 2012-10-05 11:12:13 +02:00
Andreas Schneider
dc8103925c packet: Fix a possible segfault. 2012-10-05 11:12:13 +02:00
Andreas Schneider
280ce3fe93 session: Fix a memory leak in ssh_new() on error. 2012-10-05 11:12:13 +02:00
Andreas Schneider
332f1a2a51 channels: Fix a memory leak in ssh_channel_select(). 2012-10-05 11:12:13 +02:00
Andreas Schneider
213321d706 options: Fix a memory in ssh_options_copy() on error. 2012-10-05 11:12:13 +02:00
Andreas Schneider
cddfe602cc options: Fix a memory leak if we can't add an idenity. 2012-10-05 11:08:51 +02:00
Andreas Schneider
d0889dd9ea kex: Fix simpledes with gcrypt. 2012-09-25 15:29:38 +02:00
Andreas Schneider
3c5235fdc0 dh: Fix dh_generate_e() with gcrypt. 2012-09-25 15:25:52 +02:00
Andreas Schneider
ed94e7f8a8 messages: Fix a possible null pointer dereference. 2012-09-24 20:57:40 +02:00
Christophe Baribaud
9460c5906f MSVC Windows and winsock2.h
With Microsoft Visual Studio, winsock2.h shall be included before
ws2tcpip.h

Signed-off-by: Christophe Baribaud <christophe.baribaud@gmail.com>
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2012-09-21 09:45:03 +02:00
Christophe Baribaud
160da5810f Finds zlib in a debug only build (windows)
Signed-off-by: Christophe Baribaud <christophe.baribaud@gmail.com>
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2012-09-21 09:44:19 +02:00
Dmitriy Kuznetsov
a18106d3af channels: Fix channel_request_pty_size1 always returning an error.
Fixes bug #88.
2012-09-07 12:23:55 +02:00
Andreas Schneider
3739bd99c5 channels: Fix return value of ssh_channel_request_pty_size with SSHv1.
Thanks to Dmitriy Kuznetsov <dk@yandex.ru>.
2012-09-07 12:21:28 +02:00
Dmitriy Kuznetsov
320951f42f kex: Add simple DES support for SSHv1. 2012-09-07 12:19:43 +02:00
Andreas Schneider
a3f83e7274 changelog: Update features. 2012-09-05 17:03:26 +02:00
Dmitriy Kuznetsov
e689375e45 dh: Add support for diffie-hellman-group14-sha1. 2012-09-04 16:17:46 +02:00
Andreas Schneider
977951e96a pki: Open privkey file in binary mode.
This is needed to correctly detect carriage return.
2012-09-04 11:28:33 +02:00
Andreas Schneider
782b2e37c6 build: Fix missing struct in_addr warning. 2012-07-17 18:16:07 +02:00
Andreas Schneider
a92c97b2e1 sftp: Fix bug in sftp_mkdir not returning on error.
resolves: #84
2012-07-17 18:12:44 +02:00
Andreas Schneider
43e3a8e497 socket: Add a SSH_WRITE_PENDING socket status. 2012-07-17 18:05:51 +02:00
Andreas Schneider
8ef45e00c7 auth: Improve ssh_userauth_kbdint_setanswer() documentation.
Thanks to Arto Karppinen.
2012-07-17 18:04:55 +02:00
Andreas Schneider
e8cebc2a37 auth: Fix ssh_userauth_kbdint*() documentation.
Thanks to Arto Karppinen.
2012-07-17 18:04:55 +02:00
Andreas Schneider
8624651de3 auth: Fix ssh_userauth_password() documentation. 2012-07-17 18:04:55 +02:00
Andreas Schneider
8b8d9dc83a connect: Fix a build warning. 2012-07-17 17:34:27 +02:00
Oliver Gasser
ad24427f03 options: Add option to specify host keys string.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2012-07-06 11:04:05 +02:00
Andreas Schneider
2ed9d2160d dh: Add a doc hint to ssh_string_free_char() for ssh_get_hexa(). 2012-06-11 23:14:25 +02:00
Andreas Schneider
9bac67a05a bind: Fix build. 2012-05-09 09:04:32 +02:00
Andreas Schneider
a3cb5b0707 server: Add ecdsa hostkey support. 2012-05-08 11:34:24 +02:00
Andreas Schneider
88d6e6253c agent: Do not fail reads with EPIPE if there is not enough data to read. 2012-04-10 12:04:44 +02:00
Andreas Schneider
a3cf1e4acc Fix typo. 2012-03-09 18:14:13 +01:00
Andreas Schneider
62657d5f87 auth: Fix build warning. 2012-02-20 09:44:36 +01:00
Andreas Schneider
1973e833f2 server: Add ecdsa hostkey support. 2012-02-19 18:49:07 +01:00
Andreas Schneider
387d9e4855 examples: Fix sparse warnings in sshd examples. 2012-02-19 13:26:03 +01:00
Andreas Schneider
2ca0a9cdb2 examples: Make variabes static in client sample.
Fixes sparse warnings.
2012-02-19 13:26:03 +01:00
Andreas Schneider
29ad0d19f9 examples: Make variables static in scp example.
Fixes sparse warnings.
2012-02-19 13:26:02 +01:00
Andreas Schneider
c31004442a examples: Make variables static in scp example.
Fixes sparse warnings.
2012-02-19 13:26:02 +01:00
Andreas Schneider
e68b763a67 threads: Make libcrypto_mutexes static.
Fixes sparse warnings.
2012-02-19 13:26:02 +01:00
Andreas Schneider
72db38b31d threads: Fix function defintions.
Fixes sparse warnings.
2012-02-19 13:26:02 +01:00
Andreas Schneider
300caf9ff3 pcap: Fix definition of ssh_pcap_file_new().
Fixes sparse warnings.
2012-02-19 13:26:02 +01:00
Andreas Schneider
3888a050f8 packet: Make default_packet_handlers static.
Fixes sparse warnings.
2012-02-19 13:26:02 +01:00
Andreas Schneider
66aaa6f573 misc: Improve byte swapping of ntohll().
Fixes sparse warnings.
2012-02-19 13:26:02 +01:00
Andreas Schneider
3582e386b7 misc: Fix definitions of ssh_list_new().
Fixes sparse warnings.
2012-02-19 13:26:02 +01:00
Andreas Schneider
72001ff8cc auth: Improve doc of ssh_userauth_kbdint_getprompt(). 2012-02-19 13:25:22 +01:00
Andreas Schneider
b7507fc85e cmake: Update FindCMokery. 2012-02-08 20:10:45 +01:00
Andreas Schneider
f558c66e78 doc: Add a note about makefile generators on Windows. 2012-02-08 19:10:41 +01:00
Andreas Schneider
3bb381fad7 doc: Add more infor about Windows binaries. 2012-02-08 19:07:43 +01:00
zhengfish
88964cb541 Fixed a compiling error in src/log.c on Win32 with MSVC 2012-02-07 09:59:33 +01:00
Andreas Schneider
8fea5c7a28 tests: Fix known_hosts test. 2012-02-07 09:54:54 +01:00
Andreas Schneider
19090c5cd8 SubmittingPatches: Fix version number and typo. 2012-02-06 16:21:32 +01:00
Andreas Schneider
f0589a2caf Add SubmittingPatches document. 2012-02-06 16:12:06 +01:00
Andreas Schneider
50e9608dcd auth: Fix SSHv1 build. 2012-02-06 09:54:59 +01:00
Andreas Schneider
ee774479de session: Use a struct for all options. 2012-02-05 11:50:49 +01:00
Andreas Schneider
840f75f10c tests: Turn debug crypto on in ctest. 2012-02-05 10:53:43 +01:00
Andreas Schneider
c0a7a84e92 dh: Fix build with DEBUG_CRYPTO. 2012-02-05 10:52:39 +01:00
Andreas Schneider
4019dbed85 pki: Add ecdsa support for signature verification. 2012-02-04 23:45:01 +01:00
Andreas Schneider
216cb8b1aa crypto: Add evp hashing function. 2012-02-04 23:44:55 +01:00
Andreas Schneider
fb6855a821 pki: Fix openssl ecdsa signature from blob. 2012-02-04 23:04:26 +01:00
Andreas Schneider
0770843309 pki: Fix ssh_pki_log function. 2012-02-04 23:03:53 +01:00
Andreas Schneider
f639b8ec1f pki: Make a strcmp better readable. 2012-02-04 22:09:43 +01:00
Andreas Schneider
c209c6d5ac kex: Add support for ecdsa hostkeys. 2012-02-04 22:08:55 +01:00
Andreas Schneider
b136a986a0 kex: Add a define for the kex method size. 2012-02-04 22:08:08 +01:00
Andreas Schneider
e93f17cad8 pki: Don't free a const key! 2012-02-04 22:07:03 +01:00
Andreas Schneider
47226d9d44 sftp: Fix memory leak in sftp_free() on server.
Thanks to Tom Judge for the report.
2012-02-04 21:06:37 +01:00
Andreas Schneider
a311ec32b1 ecdh: Fix a memory leak in ecdh_build_k().
Thanks to Tom Judge for the report.
2012-02-04 21:06:33 +01:00
Andreas Schneider
4223c8a116 ecdh: Fix a memory leak in ssh_server_ecdh_init().
Thanks to Tom Judge for the report.
2012-02-04 21:06:11 +01:00
Andreas Schneider
e4d0ac7ba1 pki: Update copyright. 2012-02-04 20:37:29 +01:00
Andreas Schneider
84dfa13fe8 cmake: Disable gcrypt ECC. 2012-02-04 20:35:27 +01:00
Andreas Schneider
19f7458ed3 pki: Add ecdsa gcrypt stubs. 2012-02-04 20:25:24 +01:00
Andreas Schneider
3e83bc665f cmake: Enable ECC support for GCrypt 1.5.0 or newer. 2012-02-04 20:25:07 +01:00
Andreas Schneider
ddcfe95bbd cmake: Update GCrypt module. 2012-02-04 20:09:51 +01:00
Andreas Schneider
679cd9efd8 pki: Fix build if you don't have ECC support. 2012-02-04 18:37:05 +01:00
Andreas Schneider
ae59049347 tests: Test ecdsa key generation and signing. 2012-02-04 18:37:05 +01:00
Andreas Schneider
b1434fd09b pki: Add ecdsa support to do_sign_sessionid. 2012-02-04 18:37:04 +01:00
Andreas Schneider
79383cf8ee pki: Add ecdsa support to do_sign. 2012-02-04 18:37:04 +01:00
Andreas Schneider
33b0cfc199 pki: Add ecdsa support for signature_verify. 2012-02-04 18:37:04 +01:00
Andreas Schneider
e9f5c7421e pki: Add ecdsa support for signature_from_blob. 2012-02-04 18:37:04 +01:00
Andreas Schneider
9070b04184 pki: Add ecdsa support for signature_to_blob. 2012-02-04 18:37:04 +01:00
Andreas Schneider
b309dd8fb7 pki: Add support to generate ecdsa keys. 2012-02-04 18:37:04 +01:00
Andreas Schneider
91372e298d tests: Add duplicate ecdsa key test. 2012-02-04 18:37:04 +01:00
Andreas Schneider
14bb23ae3b tests: Add ecdsa pubkey_from_privkey test. 2012-02-04 18:37:04 +01:00
Andreas Schneider
0e1992a9cc tests: Add ecdsa publickey_from_privatekey test. 2012-02-04 18:37:04 +01:00
Andreas Schneider
ecbdc589f4 pki: Fix ecdsa key dup. 2012-02-04 18:37:04 +01:00
Andreas Schneider
fc8a182823 tests: Add a testing of importing ecdsa pubkeys. 2012-02-04 18:37:04 +01:00
Andreas Schneider
f35c284761 pki: Add support to import ecdsa pubkeys. 2012-02-04 18:37:04 +01:00
Andreas Schneider
fa37965ab0 cmake: Add a define to see if we have ecc support. 2012-02-04 18:37:04 +01:00
Andreas Schneider
3c7571e61b pki: Add support for export ecdsa pubkeys. 2012-02-04 18:37:04 +01:00
Andreas Schneider
d44a79da9b tests: Add test for reading ecdsa privkey. 2012-02-04 18:37:04 +01:00
Andreas Schneider
ea74a12b70 pki: Add support to import ecdsa private keys. 2012-02-04 18:37:03 +01:00
Andreas Schneider
b4823252ca pki: Add ECDSA for key compare. 2012-02-04 18:37:03 +01:00
Andreas Schneider
244fa0474b pki: Fix typo in error message. 2012-02-04 18:37:03 +01:00
Anthony VEREZ
9e5b3914de examples: Fix PTY allocation error. 2012-01-30 09:48:01 +01:00
Martin Drasar
31727bf33a Ignore and debug messages can be sent using public API
Signed-off-by: Martin Drasar <drasar@ics.muni.cz>
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2012-01-05 11:26:53 +01:00
Lee Hambley
a15399992e Fix logic erorr with brace-less conditional statement 2012-01-03 19:41:28 +01:00
rofl0r
89733e697f patch pki_gcrypt.c to be compilable without CMake 2012-01-02 16:41:52 +01:00
rofl0r
2ffbdb0492 commit a7e14524c4f7903f607cdcd02b83782e89f0a82c 2012-01-02 16:31:37 +01:00
rofl0r
4305da29a1 session: Cleanup timeout functions.
It is possible that we get unrelated packets while waiting for
termination, thus waiting indefinitely. As a workaround we have to
check the user-supplied timeout.
2012-01-02 12:39:43 +01:00
Andreas Schneider
2f861a858b message: Fix compiler warning. 2012-01-02 09:31:40 +01:00
Andreas Schneider
74f5f43409 auth: Fix public key authentication so we can continue. 2012-01-01 23:53:21 +01:00
Andreas Schneider
0b7b699ced auth: Fix a possible double free. 2012-01-01 23:53:14 +01:00
rofl0r
c08bdf5917 message: Handle all unknown global messages.
Reply to unknown global messages as required by the RFC. Therefore
keepalive@openssh.com style messages should get treated in a sane way.
2012-01-01 20:53:13 +01:00
Andreas Schneider
7d26f7ceab torture: Fix compilation with cmockery. 2011-12-27 07:14:08 +01:00
Andreas Schneider
90893fd1a3 options: Fix typo in ssh_options_get() docs. 2011-12-14 13:45:19 +01:00
Andreas Schneider
76fad364cd sftp: Add references to sftp_get_error() to docs. 2011-11-17 19:12:31 +01:00
Andreas Schneider
ba4f10dc46 agent: Improve logging. 2011-11-16 11:32:06 +01:00
Andreas Schneider
ce0324770d kex: Fix some build warnings. 2011-11-10 14:46:22 +01:00
Andreas Schneider
bc2ab9b414 bind: Add more error messages. 2011-11-09 10:21:51 +01:00
Andreas Schneider
ce26b8d777 packet: Use a define for the macsize. 2011-11-09 10:13:26 +01:00
Andreas Schneider
99d2cf02a6 options: Add missing argument check. 2011-11-03 18:24:52 +01:00
Lee Hambley
17f396ffab Improve ssh_options_get(ssh_session, enum ssh_options_e, char**).
* Use SSH_ERROR and SSH_OK instead of `-1` and `0`.
 * Re-factor for code duplication
 * No longer call `ssh_set_error_invalid(ssh_session)` when the
   ssh_session is NULL.
2011-11-03 18:24:02 +01:00
Andreas Schneider
2c04994443 pki: Add a ssh_key_cmp() function. 2011-10-29 19:58:28 +02:00
Andreas Schneider
e799c0ce7d dh: Add ssh_get_publickey(). 2011-10-29 19:58:28 +02:00
Andreas Schneider
2cc48db673 tests: Fix build warning. 2011-10-29 19:58:10 +02:00
Lee Hambley
e797781bb5 Implement ssh_options_get_port(ssh_session, unsigned int*). 2011-10-28 12:15:12 +02:00
Lee Hambley
6bd95b50f5 Implement ssh_options_get(ssh_session, enum ssh_options_e, char**). 2011-10-28 12:14:34 +02:00
Andreas Schneider
d8d9755b7d bind: Fix ssh_bind_listen in normal case. 2011-10-17 19:27:29 +02:00
Aris Adamantiadis
1fcddebadc server: use app-provided bind socket when available 2011-10-13 22:30:27 +02:00
Aris Adamantiadis
551a0c855b server: ssh_bind_accept_fd
This function will not call accept() but use function parameter
instead
2011-10-13 22:23:48 +02:00
Andreas Schneider
85cc582d4a doc: Improve doc of ssh_get_pubkey_hash(). 2011-10-04 10:47:05 +02:00
Aris Adamantiadis
c340192144 packet: cleaner logs with less redundant info 2011-10-03 13:52:19 +03:00
Aris Adamantiadis
b6d0b531f8 server: pubkey auth doesn't work with ecdh 2011-09-25 23:47:55 +02:00
Aris Adamantiadis
5c19cda280 Fix warning 2011-09-24 14:08:52 +02:00
Aris Adamantiadis
e38f2f933b pki: ssh_pki_generate
for both gcrypt and openssl
2011-09-24 01:36:58 +02:00
Aris Adamantiadis
21d68112b8 Torture: test new ssh_pki_generate function 2011-09-24 01:36:39 +02:00
Aris Adamantiadis
3fa5293aec pki: DO actually verify signatures
Would have been an embarrassing bug...
2011-09-24 00:25:44 +02:00
Andreas Schneider
6859e4f4ec build: Fix zlib support. 2011-09-23 22:57:21 +02:00
Aris Adamantiadis
43fc7553f8 torture_algorithm: follow verbosity 2011-09-23 22:57:05 +02:00
Aris Adamantiadis
717840fc09 torture: check for presence of ssh agent 2011-09-23 22:33:21 +02:00
Aris Adamantiadis
046aa02f39 Fix bugs found by clang 2011-09-23 22:27:46 +02:00
Andreas Schneider
8a3b02f68d cmake: Fix library linking. 2011-09-23 08:00:58 +02:00
Aris Adamantiadis
dad35304b6 channels: fix embarrasing channel_read_nonblocking bug 2011-09-22 13:48:21 +03:00
Andreas Schneider
744b7720af build: Fix SSHv1 build. 2011-09-22 12:07:09 +02:00
Andreas Schneider
5083742192 packet: Move packet callbacks to packet_cb.c. 2011-09-18 21:37:18 +02:00
Andreas Schneider
dc42a1757f gzip: Fix zlib support. 2011-09-18 21:37:18 +02:00
Andreas Schneider
7202a26b6c priv: Remove dead prototype. 2011-09-18 21:37:17 +02:00
Andreas Schneider
b785014a15 crypt: Rename to packet_crypt. 2011-09-18 21:37:17 +02:00
Andreas Schneider
acfc8ea83f priv: Remove crypto.h and add correct includes to src files. 2011-09-18 21:37:17 +02:00
Andreas Schneider
c2686b8feb socket: Move socket function to right location. 2011-09-18 21:37:17 +02:00
Andreas Schneider
e7009fe8f3 priv: Create crc32.h.
As crc32 is only needed by SSHv1, build it only with SSHv1.
2011-09-18 21:37:17 +02:00
Andreas Schneider
ffb827b539 priv: Move gcrypt functions to gcrypt header. 2011-09-18 21:37:17 +02:00
Andreas Schneider
33754c391f priv: Start to remove enter_function. 2011-09-18 21:37:17 +02:00
Andreas Schneider
d7fa15df83 priv: Move kex functions to kex header. 2011-09-18 21:37:17 +02:00
Andreas Schneider
519291558d priv: Move options and config prototypes to own header. 2011-09-18 21:37:17 +02:00
Andreas Schneider
abd9856c6a priv: Move defines to the top. 2011-09-18 21:37:17 +02:00
Andreas Schneider
4a6a0987a8 client: Remove unused variable. 2011-09-18 21:36:40 +02:00
Andreas Schneider
3622ac83f6 legacy: Fix possible segfault with publickey_from_file().
This function is obsolete.
2011-09-18 21:36:23 +02:00
Aris Adamantiadis
f61269a2ef ECDH key exchange working 2011-09-18 20:34:16 +02:00
Aris Adamantiadis
d24e353e38 pki: null ptr check 2011-09-18 20:34:16 +02:00
Aris Adamantiadis
09b33b1b6e server: split dh_handsake_server 2011-09-18 20:34:16 +02:00
Aris Adamantiadis
af09313eac crypto: rename crypto_struct -> ssh_cipher_struct 2011-09-18 20:34:16 +02:00
Aris Adamantiadis
ac41a083ef kex: moved KEX structures to ssh_crypto_struct 2011-09-18 20:34:16 +02:00
Aris Adamantiadis
48980573c1 wrapper.c: cleanup 2011-09-18 20:34:15 +02:00
Aris Adamantiadis
22668bcdae kex: have server_kex use the elected methods 2011-09-18 20:34:15 +02:00
Aris Adamantiadis
07abc3406d kex: split key selection and sending 2011-09-18 20:34:15 +02:00
Aris Adamantiadis
1b10b175fc dh: fix segfault in server 2011-09-18 20:34:15 +02:00
Aris Adamantiadis
8f1161f649 scp: introduce a 64bits getter to respect ABI 2011-09-18 20:34:15 +02:00
Andreas Schneider
2cc95e1e08 doc: Fix threading documentation. 2011-09-17 21:32:29 +02:00
Andreas Schneider
fa7798833a pki: Use ssh_log_function() for ssh_pki_log(). 2011-09-17 11:09:19 +02:00
Andreas Schneider
b96943e861 log: Split do_ssh_log(). 2011-09-17 11:05:17 +02:00
Andreas Schneider
569312f7bd log: Remove unneeded ssh_log_function(). 2011-09-17 11:00:33 +02:00
Andreas Schneider
c2883c1f37 auth: Use the new SSH_LOG function. 2011-09-17 10:38:08 +02:00
Andreas Schneider
c19c638d74 error: Use macros for error functions. 2011-09-17 10:38:08 +02:00
Andreas Schneider
afa56e0102 session: Use defines for ssh_handle_packets(). 2011-09-17 10:38:08 +02:00
Andreas Schneider
544747d02c crypt: Fix function definition. 2011-09-15 11:04:00 +02:00
Aris Adamantiadis
68bab2a490 SSH1: handle exit-status message (channels would not close) 2011-09-14 22:53:01 +02:00
Aris Adamantiadis
c4701a34d3 channels1: made channel_write1 nonblocking 2011-09-14 22:39:05 +02:00
Aris Adamantiadis
36ec488663 channels: don't send SSH2 packets on SSH1 ! 2011-09-14 22:35:12 +02:00
Aris Adamantiadis
714aeca91f SSH1: fix kex bugs introduced in refactoring 2011-09-14 22:21:43 +02:00
Aris Adamantiadis
af225e68cb SSH1: make authentication nonblocking 2011-09-14 21:55:54 +02:00
Aris Adamantiadis
ebfb2a5cdb auth: fix spelling in error message 2011-09-14 20:37:30 +02:00
Aris Adamantiadis
33cf16488b Revert "auth: Check if we have any prompts."
This reverts commit 3b5bdc5db4.
It's perfectly legit to have only zero prompts.
2011-09-14 20:36:23 +02:00
Aris Adamantiadis
0fa88fdcfe Auth: fix possible off-by-one
No security impact, only triggable by specific API call
2011-09-14 17:28:41 +03:00
Andreas Schneider
49ae226b90 log: Fixed a typo. 2011-09-12 10:46:32 +02:00
Aris Adamantiadis
f3d00e4bc3 tests: nonblocking keyboard-interactive 2011-09-11 17:39:20 +02:00
Aris Adamantiadis
fa68d91869 log: remove the annoying \n between date and message 2011-09-11 17:39:20 +02:00
Aris Adamantiadis
1f31415760 auth: made keyboard-interactive nonblocking 2011-09-11 17:39:20 +02:00
Aris Adamantiadis
27dea35608 Test: added torture_auth_autopubkey_nonblocking 2011-09-11 17:22:27 +02:00
Aris Adamantiadis
ff5bf51af1 Auth: nonblocking ssh_userauth_pubkey_auto 2011-09-11 17:22:27 +02:00
Aris Adamantiadis
7b663df185 Tests: unit test for agent authentication 2011-09-11 17:22:27 +02:00
Aris Adamantiadis
33bd3d6cd9 auth: Implement nonblocking ssh_auth_agent 2011-09-11 17:22:26 +02:00
Aris Adamantiadis
28bfc7645c auth: different code for auth_agent 2011-09-11 17:22:26 +02:00
Aris Adamantiadis
ae89dfd6f2 Auth: made ssh_userauth_get_response respect timeout 2011-09-11 17:22:26 +02:00
Andreas Schneider
06e0305100 server: Fix some build warnings. 2011-09-11 15:32:39 +02:00
Andreas Schneider
3b5bdc5db4 auth: Check if we have any prompts. 2011-09-11 15:29:27 +02:00
Andreas Schneider
95ec57f2fd server: Fix compiler warning. 2011-09-11 15:12:35 +02:00
Andreas Schneider
a5d89624d5 log: Add missing include. 2011-09-11 14:38:44 +02:00
Andreas Schneider
04faa33259 kex: Fix includes. 2011-09-11 08:24:33 +02:00
Andreas Schneider
35dce7e8d1 priv: Remove obsolete ssh_keys_struct. 2011-09-10 12:47:47 +02:00
Andreas Schneider
c8f48a2478 log: Improve the logging function. 2011-09-10 12:38:42 +02:00
Andreas Schneider
08129002de log: Add new debug log levels.
These should be used in future!
2011-09-10 12:31:54 +02:00
Andreas Schneider
b3d62ecba8 agent: Add missing config.h include. 2011-09-10 11:55:50 +02:00
Andreas Schneider
bf72440eff kex: Split out SSHv1 functions to kex1.c. 2011-09-10 11:03:46 +02:00
Andreas Schneider
77e71ae3b5 dh: Use ssh_string_new() in make_bignum_string(). 2011-09-08 19:58:59 +02:00
Andreas Schneider
81017b0fc2 string: Make sure we always have the right byte order. 2011-09-08 19:57:34 +02:00
Andreas Schneider
4a5b72a535 pki: Use ssh_string_get_char(). 2011-09-08 16:14:35 +02:00
Andreas Schneider
c1f8b38b78 string: Add ssh_string_get_char(). 2011-09-08 16:14:35 +02:00
Andreas Schneider
5581323c2c string: Use the struct and array for allocating the struct. 2011-09-08 15:50:39 +02:00
Andreas Schneider
55c758d079 auth1: Fix ssh_string usage. 2011-09-08 15:29:05 +02:00
Andreas Schneider
09da9418cc known_hosts: Fix a free before last use. 2011-09-08 13:42:30 +02:00
Andreas Schneider
6d3d5a446e known_hosts: Fix a memleak. 2011-09-07 17:51:43 +02:00
Andreas Schneider
11f3b0e684 pki: Add missing ECC ifdef. 2011-09-06 09:44:45 +02:00
Andreas Schneider
ae1f87e37a options: Fix NULL value handling. 2011-09-06 09:16:54 +02:00
Andreas Schneider
3105b3c205 options: Fix the ssh_options_set() function.
This is a refactor so that we check if the values are sane the user
wants to set. If not return an error.
2011-09-05 20:15:34 +02:00
Andreas Schneider
2e83cc925d known_hosts: Migrate ssh_write_knownhost() to new pki. 2011-09-05 11:28:19 +02:00
Andreas Schneider
808c7a9be4 pki: Add ssh_pki_export_pubkey_rsa1(). 2011-09-05 11:28:19 +02:00
Andreas Schneider
6901e25085 pki_crypto: Add ecdsa support for key duplication. 2011-09-02 23:10:23 +02:00
Andreas Schneider
a0e3facac7 pki: Add ecdsa key support. 2011-09-02 23:10:23 +02:00
Andreas Schneider
6dc7ddde3f channels: Export ssh_channel_poll_timeout(). 2011-09-02 22:40:32 +02:00
Aris Adamantiadis
7e5f1edcb4 auth: fix things broken during merge 2011-09-02 14:09:12 +03:00
Aris Adamantiadis
20f8e73e3e Update libssh to ssh_handle_packets_termination
cherry-picked from 0cb5248

Should resolve all timeout problems

Conflicts:

	src/auth.c
	src/channels.c
2011-09-02 13:58:37 +03:00
Aris Adamantiadis
ef5701a535 Channels: fix the "server specified invalid channel" bug
Resolved by introducing a flag entry in channel structure.
2011-09-02 13:50:06 +03:00
Aris Adamantiadis
7d347aa6f4 channel: ssh_channel_read is nonblocking, + docfixes
cherry-picked from 6091147
Conflicts:

	src/channels.c
2011-09-02 13:49:05 +03:00
Aris Adamantiadis
6d8bb956c5 channels: replaced bugged lists with ssh_list
cherry-picked from 0aef5f
Conflicts:

	src/session.c
2011-09-02 13:46:10 +03:00
Aris Adamantiadis
3eece8ac0b SSH1: fix build 2011-09-02 11:43:12 +03:00
Aris Adamantiadis
92c8a71abb ssh_select converted to ssh_event, and bugfix to ssh_channel_select 2011-09-02 11:43:12 +03:00
Aris Adamantiadis
b5351f2809 poll: resolve use-after-free + inconsistent callbacks call
This code was weird in the first place. I suspect my change will break something else
(probably the appcode that needed it). ssh_poll_ctx_free is not a good
place to send exception callbacks imho.
2011-09-02 11:43:12 +03:00
Aris Adamantiadis
d1ebc4697a channels: ssh_channel_select implemented with ssh_poll
Should fix #56
2011-09-02 11:43:11 +03:00
Aris Adamantiadis
7f5206b8ac sample: fix ssh_channel_read 2011-09-02 11:43:11 +03:00
Aris Adamantiadis
cb2a111fa1 channel: implement ssh_channel_poll_timeout
Resolves bug #57
2011-09-02 11:43:11 +03:00
Aris Adamantiadis
555d1a4347 benchmarks: fix some bugs 2011-09-02 11:43:07 +03:00
Aris Adamantiadis
17ae216340 Channels: increase window size x10
Provides me a 3x performance boost for async sftp, 5x for sync sftp
(on localhost)
2011-09-02 11:43:07 +03:00
Aris Adamantiadis
3a5cc18b32 benchmarks: sftp_async + few changes 2011-09-02 11:43:07 +03:00
Aris Adamantiadis
b11567ed9b benchmarks: refactoring + sync sftp tests
no surprise, sync sftp is much slower, even for localhost,
especially for download.
2011-09-02 11:43:07 +03:00
Aris Adamantiadis
faaf334aa3 benchmarks: added "data" option 2011-09-02 11:43:05 +03:00
Aris Adamantiadis
5d9cd8bf39 benchmarks: added raw_download test 2011-09-02 11:43:05 +03:00
Aris Adamantiadis
a2c94abb92 channels: made the remaining calls nonblocking + fix #52 2011-09-02 11:42:59 +03:00
Aris Adamantiadis
510c741229 channels: use hard random for the X11 cookie
We are in a security library or we are not.
2011-09-02 11:42:59 +03:00
Aris Adamantiadis
f9dad9ad68 channels: made all channel requests nonblocking 2011-09-02 11:42:59 +03:00
Aris Adamantiadis
7363b29427 unittests:make sftp_dir pass on my laptop 2011-09-02 11:41:04 +03:00
Aris Adamantiadis
99e6fde751 scp: Fixed documentation bug #9 2011-09-02 11:40:52 +03:00
Andreas Schneider
5c48438dcb doc: Improve doc of ssh_message_auth_pubkey(). 2011-08-30 23:11:32 +02:00
Andreas Schneider
b5b3db6c90 pki: Check the type of the key blob earlier. 2011-08-30 22:35:01 +02:00
Andreas Schneider
e5a39a3ae9 keys: Remove keys.h where it is obsolete. 2011-08-30 12:15:20 +02:00
Andreas Schneider
fedfbf9563 keys: Remove obsolete keys.c. 2011-08-30 12:15:20 +02:00
Andreas Schneider
7093ac986d keys: Remove dead prototypes. 2011-08-30 12:15:20 +02:00
Andreas Schneider
64de14f51e keys: Move publickey_from_privatekey() to legacy.c. 2011-08-30 12:15:20 +02:00
Andreas Schneider
fe246db27d keys: Move publickey_free() to legacy.c. 2011-08-30 12:15:20 +02:00
milo
0cbbe39e4f Include stdio.h for snprintf 2011-08-30 11:39:14 +02:00
Andreas Schneider
822c68eb8e pki: Use consistent API for ssh_pki_export_privkey_to_pubkey(). 2011-08-30 10:28:57 +02:00
Andreas Schneider
60b92e458e pki: Use consistent API for ssh_pki_export_pubkey_blob(). 2011-08-30 10:16:53 +02:00
Andreas Schneider
e236577503 tests: Enable ecdh_sha2_nistp256 test only with openssl. 2011-08-30 09:34:23 +02:00
Andreas Schneider
85d12f6774 cmake: Add ec.h and ecdsa.h checks. 2011-08-30 00:44:46 +02:00
Andreas Schneider
6bf8dfa073 pki: Fix session_id hashing.
I don't understand why this code worked before. It was completly wrong.
2011-08-29 22:39:47 +02:00
rofl0r
66188f1af8 channels: Fix possible infinite loop in channel_read(). 2011-08-29 21:47:01 +02:00
Jonas Jonsson
d1df255df4 sftp: Handle short reads of sftp_async_read().
sftp_async_read() and sftp_async_read_begin() assume that the whole read
will be successful but when this is not the case, the offset will be
wrong.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2011-08-29 10:05:26 +02:00
Andreas Schneider
a060a235a4 pki: string_* -> ssh_string_* 2011-08-28 22:51:00 +02:00
Andreas Schneider
7a9f65dd94 pki: Refactor ssh_pki_do_sign(). 2011-08-28 22:25:33 +02:00
Andreas Schneider
246d20ef23 pki: Refactor _RSA_do_sign(). 2011-08-28 22:25:33 +02:00
Andreas Schneider
f803538d21 doc: Fix authentication docs. 2011-08-28 20:08:36 +02:00
Andreas Schneider
292ed71f09 doc: Fix a check in the doc code. 2011-08-28 20:02:27 +02:00
Andreas Schneider
2d9cd48b1d pki: Cleanup crypto includes. 2011-08-28 14:50:43 +02:00
Andreas Schneider
10d3d73039 pki: Fix gcrypt includes and update copyright. 2011-08-28 14:50:43 +02:00
Andreas Schneider
f02f889111 pki: Get rid of the string.h include in pki_gcrypt.c. 2011-08-28 14:50:43 +02:00
Andreas Schneider
a9eb0020b8 legacy: Move ssh_private_key and ssh_public_key typedefs. 2011-08-28 14:50:43 +02:00
Andreas Schneider
fb4f1412ba build: Fix the build of keyfiles torture test. 2011-08-28 14:50:28 +02:00
Andreas Schneider
561441105f pki: Add Windows defines. 2011-08-28 14:29:44 +02:00
Andreas Schneider
7c28d0ce6d pki: Compile pki_gcrypt.c only if we need it. 2011-08-28 14:29:17 +02:00
Andreas Schneider
5cf23522de keyfiles: Remove keyfiles.h. 2011-08-28 14:26:40 +02:00
Andreas Schneider
be660e801a keyfiles: Remove try_publickey_from_file(). 2011-08-28 14:24:23 +02:00
Andreas Schneider
bce2c22e45 keyfiles: Make ssh_try_publickey_from_file() legacy. 2011-08-28 14:21:56 +02:00
Andreas Schneider
29ecccb96d keyfiles: Make ssh_try_publickey_from_file() legacy. 2011-08-28 14:19:07 +02:00
Andreas Schneider
16b47496c1 sftp: Don't create file page. 2011-08-28 13:20:58 +02:00
Andreas Schneider
9379a93c98 doc: Fix some doxygen latex warnings. 2011-08-28 13:17:39 +02:00
Andreas Schneider
21875bc71e sftp: Improve documentation. 2011-08-28 13:17:27 +02:00
Andreas Schneider
0f41f21227 auth: Refactor and rename kbdauth_send(). 2011-08-28 12:54:49 +02:00
Andreas Schneider
98ada12f66 libsshpp: Remove type argument from doc. 2011-08-27 13:58:53 +02:00
Andreas Schneider
0bd99b3773 auth: Fix doc typos. 2011-08-27 13:58:08 +02:00
Andreas Schneider
e5e673bafe auth: Handle request service timeout in blocking mode. 2011-08-26 23:56:49 +02:00
Andreas Schneider
79ed1bc601 pki: Handle hash correctly.
Looks like only DSA in grypt needs a leading zero to mark the has as
positive. See

http://lists.gnupg.org/pipermail/gcrypt-devel/2005-February/000754.html
2011-08-26 23:13:57 +02:00
milo
228e2edac5 Quick fix for gcrypt DSA signature 2011-08-26 22:18:04 +02:00
Andreas Schneider
1d734f16cf legacy: Remove privatekey_from_base64().
This function has been introduced for libssh 0.6. So we can remove it
completely.
2011-08-26 21:46:56 +02:00
Andreas Schneider
5a0735d1e8 messages: Fix ssh_packet_userauth_request().
Remove useless ssh_pki_import_signature_blob().
2011-08-26 21:19:49 +02:00
milo
f1634d33da Free sig_blob if an error occurs 2011-08-26 18:17:14 +02:00
milo
4bdd831d7f Fix double free in ssh_packet_userauth_request 2011-08-26 15:49:12 +02:00
Andreas Schneider
d4424b2767 auth: Refactor and fix ssh_userauth_kbdint(). 2011-08-26 13:44:00 +02:00
Andreas Schneider
f2e08e8d7b auth: Fix ssh_userauth_agent_publickey pending state. 2011-08-26 13:34:40 +02:00
Andreas Schneider
26e624c1b7 auth: Don't fail in publickey_auto if we can't read the key.
We should go on and try the next one as it was before. Also make sure we
don't leak memory ;)
2011-08-26 13:34:40 +02:00
Andreas Schneider
f8c987d1d4 auth: Fix ssh_userauth_publickey() pending_call_state. 2011-08-26 13:32:08 +02:00
Andreas Schneider
696f574a56 keys: Remove obsolete signatue functions. 2011-08-26 10:48:37 +02:00
Andreas Schneider
ab1a66ca7b pki: Fix build with DEBUG_CRYPTO. 2011-08-26 10:44:43 +02:00
Andreas Schneider
7457937bab pki: Migrate ssh_pki_do_sign to new pki. 2011-08-26 09:51:02 +02:00
Andreas Schneider
b5db04003d auth: Fix a segfault in ssh_userauth_kbdint_init(). 2011-08-26 09:00:39 +02:00
Andreas Schneider
a51d377afe auth: Refactor kbdauth_init().
Rename it to ssh_userauth_kbdint_init.
2011-08-25 16:41:14 +02:00
Andreas Schneider
892cb92f57 auth: Prefix kbdint functions. 2011-08-25 16:26:12 +02:00
Andreas Schneider
c59939d4a2 auth: Make ssh_userauth_privatekey_file() legacy. 2011-08-25 16:14:29 +02:00
Andreas Schneider
5c601115c3 auth: Refactor ssh_userauth_password(). 2011-08-25 16:14:21 +02:00
Andreas Schneider
89253fd22a auth: Make ssh_userauth_autopubkey legacy. 2011-08-25 10:19:09 +02:00
Andreas Schneider
21261270e5 auth: Add ssh_userauth_publickey_auto(). 2011-08-25 10:13:23 +02:00
Andreas Schneider
1a56892e9f keys: Remove obsolete ssh_do_sign(). 2011-08-25 10:13:23 +02:00
Andreas Schneider
c5643c0967 agent: Remove obsolete agent_sign_data(). 2011-08-25 10:13:23 +02:00
Andreas Schneider
c5837a6c63 keys: Remove obsolete ssh_do_sign_with_agent(). 2011-08-25 10:13:23 +02:00
Andreas Schneider
c221db0f36 auth: Add ssh_userauth_agent().
This commit is pretty big cause several functions have been refactored.
2011-08-25 10:13:23 +02:00
Andreas Schneider
4c1d3b708c auth: Make ssh_userauth_pubkey legacy. 2011-08-23 21:54:02 +02:00
Andreas Schneider
379d65eaaf auth: Add ssh_userauth_publickey(). 2011-08-23 21:54:02 +02:00
Andreas Schneider
aa018c1484 auth: Make ssh_userauth_try_publickey() legacy. 2011-08-23 21:54:02 +02:00
Andreas Schneider
37df5e17c3 auth: Update copyright. 2011-08-23 21:54:02 +02:00
Andreas Schneider
609f8fbb7a auth: Add ssh_userauth_try_publickey(). 2011-08-23 21:54:01 +02:00
Andreas Schneider
5b706c7ab6 auth: Refactor ssh_userauth_none(). 2011-08-23 21:54:01 +02:00
Andreas Schneider
a15dab6c00 auth: Rename wait_auth_status. 2011-08-23 21:54:01 +02:00
Andreas Schneider
5695f92e22 auth: Update ssh_userauth_list(). 2011-08-23 21:54:01 +02:00
Andreas Schneider
2e577cecb4 auth: Move ssh_auth_list to legacy functions. 2011-08-23 21:54:01 +02:00
Andreas Schneider
058bb04396 auth: Rename ask_userauth. 2011-08-23 21:54:01 +02:00
Andreas Schneider
dc9feec005 pki: Add more return values for file importing functions. 2011-08-23 21:54:01 +02:00
Andreas Schneider
fa4378d47e poll: Just make the code a bit more readable.
Maybe this fixes a cppcheck false positive.
(cherry picked from commit 45c1a23769b63e72e895158bcab83aad31d483dd)
2011-08-23 21:52:21 +02:00
Andreas Schneider
e94b0f8c08 server: Fix a build warning.
Thanks to Tom Judge.
2011-08-23 15:15:28 +02:00
Andreas Schneider
149be78ee0 pki: We need only one signature verify blob function.
This fixes the build without server.
2011-08-23 08:19:53 +02:00
Andreas Schneider
8fb8ad0151 agent: Fix memory leak. 2011-08-22 21:57:00 +02:00
Andreas Schneider
93c4a8e427 pki: Fix memleak in gcrypt pki_publickey_to_blob(). 2011-08-22 21:56:44 +02:00
Andreas Schneider
9da331e79b dh: Remove obsolete signature functions. 2011-08-22 18:47:15 +02:00
Andreas Schneider
8edf57fbf2 client: Migrate to new signature pki. 2011-08-22 18:41:47 +02:00
Andreas Schneider
8c8a91a9b7 server: Migrate more functions to new pki. 2011-08-22 18:41:47 +02:00
Andreas Schneider
bf2f553fc3 pki: Improve pki gcrypt error reports. 2011-08-22 18:41:47 +02:00
Andreas Schneider
82ca6a6c53 pki: Add ssh_srv_pki_signature_verify_blob(). 2011-08-22 18:41:47 +02:00
Andreas Schneider
5cc98ed720 pki: Add ssh_pki_signature_verify_blob(). 2011-08-22 18:39:56 +02:00
Andreas Schneider
bcc0a6d0e0 pki: Fix gcrypt pki_signature_from_blob(). 2011-08-22 18:22:28 +02:00
Andreas Schneider
6c03b7a9c9 misc: Add ssh_match_group(). 2011-08-22 16:16:34 +02:00
Andreas Schneider
90167f09d3 server: Migrate hostkey check to new pki. 2011-08-22 15:22:58 +02:00
Andreas Schneider
9c376dd913 auth: Fix ssh_auth_list() documentation.
The server will not return SSH_AUTH_METHOD_NONE.
2011-08-22 15:03:25 +02:00
Andreas Schneider
1e019fee43 keys: Remove unused obsolete ssh_sign_session_id(). 2011-08-22 14:30:08 +02:00
Andreas Schneider
4de4520559 server: Use new pki infrastructure. 2011-08-22 14:29:39 +02:00
Andreas Schneider
245a354187 pki: Fix switch in crypto pki_signature_to_blob(). 2011-08-22 14:28:46 +02:00
Andreas Schneider
d6829d073c kex: Move ssh_encrypt_rsa1 to SSHv1 kex code. 2011-08-22 13:58:02 +02:00
Andreas Schneider
79ffd49940 pki: Add ssh_srv_pki_do_sign_sessionid(). 2011-08-22 13:48:25 +02:00
Andreas Schneider
a2e08697b1 messages: Move ssh_userauth_build_digest() and make it static. 2011-08-22 12:57:01 +02:00
Andreas Schneider
ca9b01af99 pki: Migrate signature functions to legacy code. 2011-08-22 11:23:33 +02:00
Andreas Schneider
d0d9e62611 tests: Fix torture test with zlib support. 2011-08-22 08:26:02 +02:00
Andreas Schneider
a86ac461fd pki: Ensure sig_blob isn't used uninitialized. 2011-08-22 08:04:22 +02:00
Andreas Schneider
859ed8583c ctest: Fix the ctest build script. 2011-08-21 14:08:40 +02:00
Andreas Schneider
1b57445f6b pki: Add ssh_pki_do_sign_agent(). 2011-08-21 13:43:20 +02:00
Andreas Schneider
af82d8dfab agent: Add ssh_agent_sign_data(). 2011-08-21 13:42:49 +02:00
Andreas Schneider
a98301d2b0 tests: Add pki signature test. 2011-08-21 13:17:30 +02:00
Andreas Schneider
9c9199e05f pki: Fix possible segfault in ssh_key_type_from_name(). 2011-08-21 13:13:53 +02:00
Andreas Schneider
fa4f2d8bc1 tests: Add pki torture tests for keytypes. 2011-08-21 13:13:21 +02:00
Andreas Schneider
42cea1f2f1 pki: Fix ssh_key_dup() with gcrypt. 2011-08-21 12:59:55 +02:00
Andreas Schneider
c8d06b6b1c tests: Fix memleak in torture_pki. 2011-08-21 12:41:42 +02:00
Andreas Schneider
948400ed92 cmake: Support WITH_ZLIB and WITH_LIBZ) 2011-08-21 12:39:16 +02:00
Andreas Schneider
eb65f031af pki: Fix setting flags in ssh_key_dup(). 2011-08-21 12:31:16 +02:00
Andreas Schneider
c041261921 pki: Create a pki private header file. 2011-08-21 11:15:29 +02:00
Andreas Schneider
a4b2518761 pki: Add ssh_pki_import_signature_blob(). 2011-08-21 11:03:53 +02:00
Andreas Schneider
4f19a304d1 pki: Add ssh_pki_export_signature_blob(). 2011-08-21 10:11:05 +02:00
Andreas Schneider
ab0354dbb6 priv: Add discard_const macros. 2011-08-21 10:10:27 +02:00
Andreas Schneider
ce41747fae pki: Introduce ssh_signature. 2011-08-20 18:37:43 +02:00
Andreas Schneider
8acc3dd3af pki: Add _RSA_do_sign to pki_crypto. 2011-08-20 18:08:16 +02:00
Andreas Schneider
79029854f6 tests: Added more pki tests. 2011-08-20 12:59:19 +02:00
Andreas Schneider
743a00dad4 pki: Fix build warnings. 2011-08-20 11:07:54 +02:00
Andreas Schneider
bb509ce4f7 pki: Remove unused variables. 2011-08-20 10:55:22 +02:00
Andreas Schneider
bac5f62eaf tests: Fix build warning. 2011-08-20 10:54:43 +02:00
Andreas Schneider
e3bd018465 tests: Fix the torture_pki test. 2011-08-20 10:48:34 +02:00
Andreas Schneider
5bcf36f098 session: Fix ssh_free() with NULL argument. 2011-08-20 10:47:59 +02:00
Andreas Schneider
c575de17a8 pki: Use a consistent naming scheme. 2011-08-19 11:14:23 +02:00
Andreas Schneider
3e56ac650c tests: Fix torture_pki build warnings. 2011-08-19 11:14:06 +02:00
Andreas Schneider
765b42e68a tests: Improve pki_import_privkey_base64 test. 2011-08-19 11:03:31 +02:00
Andreas Schneider
2615f8bc94 tests: Added test for pubkey from privkey. 2011-08-16 23:06:13 +02:00
Andreas Schneider
c39181437b pki: Add ssh_pki_export_publickey_file(). 2011-08-16 23:04:25 +02:00
Andreas Schneider
ddcb88070b misc: Remove session from ssh_get_local_username(). 2011-08-16 23:04:25 +02:00
Andreas Schneider
1a0fbedc2e pki: Fix and rename ssh_pki_publickey_to_base64().
Rename it to ssh_pki_export_publickey_base64().
2011-08-16 23:04:25 +02:00
Andreas Schneider
254c30be2e pki: Remove session from ssh_pki_import_pubkey_* functions. 2011-08-16 19:33:24 +02:00
Andreas Schneider
25a2108809 pki: Remove session from ssh_pki_import_privkey_* functions. 2011-08-16 18:53:18 +02:00
Andreas Schneider
9b84464748 pki: Make publickey_to_string a legacy function. 2011-08-16 17:54:10 +02:00
Andreas Schneider
a40f1d8597 pki: Make publickey_from_string a legacy function. 2011-08-16 17:47:29 +02:00
Andreas Schneider
c940918821 pki: Fix memleak in privatekey_from_file(). 2011-08-16 09:23:57 +02:00
Andreas Schneider
f7a7bf071d torture: Fix memleak in pubkey base64 tests. 2011-08-16 09:23:53 +02:00
Andreas Schneider
c5028e76ad pki: Fix memleak in pki_import_pubkey_buffer(). 2011-08-16 09:15:29 +02:00
Andreas Schneider
df29df6e35 pki: Add ssh_pki_log function.
The plan is to get rid of the session as a parameter to ssh pki key
functions. We don't need a session for it and probably don't want it.
2011-08-16 01:18:36 +02:00
Andreas Schneider
330c713fdb pki: Add test torture_pki_publickey_dsa_base64(). 2011-08-16 01:17:24 +02:00
Andreas Schneider
42dda7b958 pki: Fix ssh_pki_publickey_to_base64() warnings. 2011-08-16 00:58:20 +02:00
Andreas Schneider
614ad97c12 pki: Make ssh_type_from_name() a legacy function. 2011-08-16 00:55:47 +02:00
Andreas Schneider
04ce7967b8 pki: Make ssh_type_to_char() a legacy function. 2011-08-16 00:54:00 +02:00
Andreas Schneider
19a3f5a61d pki: Make publickey_from_file() a legacy function. 2011-08-16 00:47:43 +02:00
Andreas Schneider
9dfef44fd8 pki: Add ssh_pki_publickey_to_base64(). 2011-08-16 00:47:43 +02:00
Andreas Schneider
c085892802 pki: Add ssh_pki_import_pubkey_file(). 2011-08-16 00:47:43 +02:00
Andreas Schneider
47ebcac4cd torture: Add torture_pki_publickey_rsa_base64 test. 2011-08-16 00:47:43 +02:00
Andreas Schneider
977d6fc089 pki: Fix pki_publickey_to_string() rsa checks. 2011-08-16 00:47:43 +02:00
Andreas Schneider
3c3673d1b8 build: Add missing path to .clan_complete 2011-08-16 00:47:43 +02:00
Andreas Schneider
3f70bce373 pki: Rename ssh_pki_publickey_to_string and make it public. 2011-08-16 00:47:43 +02:00
Andreas Schneider
6c1b508efd pki: Rename ssh_pki_import_pubkey_string and make it public.
It should be named ssh_pki_import_pubkey_blob().
2011-08-16 00:47:43 +02:00
Andreas Schneider
714fa8960d pki: Move ssh_privatekey_type and privatekey_free to legacy. 2011-08-16 00:47:43 +02:00
Andreas Schneider
54a2b8a303 pki: Fix ssh_pki_import_pubkey_base64(). 2011-08-16 00:47:43 +02:00
milo
96e338ba56 Fixed typos in ssh_pki_publickey_to_string 2011-08-15 18:58:27 +02:00
Andreas Schneider
6ffee22448 pki: Add ssh_pki_publickey_to_string(). 2011-08-15 18:48:08 +02:00
Andreas Schneider
fe375132c3 bind: Add checks around key functions. 2011-08-15 18:48:08 +02:00
Andreas Schneider
2780f76247 pki: Flags are a bit mask so use hex. 2011-08-15 18:48:08 +02:00
Andreas Schneider
a983512678 pki: Fix ssh_key_dup(). 2011-08-15 18:48:08 +02:00
Andreas Schneider
c77b23b32a pki: Cleanup pki header. 2011-08-15 18:48:08 +02:00
milo
962bdb1eea Fixed missing include for FILE 2011-08-15 17:37:01 +02:00
Andreas Schneider
e06b3dba0d bind: Read only once in ssh_bind_listen() (bug #11). 2011-08-15 16:50:30 +02:00
Andreas Schneider
190ae27463 pki: Added ssh_key_dup(). 2011-08-15 16:26:58 +02:00
Andreas Schneider
481522cf63 agent: Use new pki functions. 2011-08-13 12:21:23 +02:00
Andreas Schneider
0523adf95c pki: Add ssh_pki_import_pubkey_string(). 2011-08-13 12:13:09 +02:00
Andreas Schneider
74d755873d pki: Use const. 2011-08-13 11:26:03 +02:00
Andreas Schneider
30ec1e0b05 pki: Document public key function. 2011-08-13 11:19:37 +02:00
Andreas Schneider
f421c05913 cmake: Check for argp library only on bsd and solaris. 2011-08-13 11:07:57 +02:00
Andreas Schneider
e92787395a pki: Fix doc of ssh_pki_import_privkey_base64(). 2011-08-12 11:04:30 +02:00
Andreas Schneider
a4a1af5bbf options: Allocate dest in ssh_options_copy(). 2011-08-11 12:53:02 +02:00
Andreas Schneider
1c30c2a510 pki: Fix a resource leak. 2011-08-11 12:36:01 +02:00
Andreas Schneider
8bf8a7ef49 Fix typo. 2011-08-10 19:07:42 +02:00
Andreas Schneider
37a38d4959 Added CodingStyle file. 2011-08-10 19:05:15 +02:00
Andreas Schneider
13227714f2 channels: Fix incorrect return values in ssh_channel_write(). 2011-08-10 16:58:10 +02:00
rofl0r
7949f2cdc6 session: Fix an infinite loop in the termination callback.
This happened due to the use of the buggy and obsolete timeout
funtions.
2011-08-10 15:41:36 +02:00
Andreas Schneider
2f87873642 channels: Handle SSH_AGAIN in channel_open(). 2011-08-09 22:59:17 +02:00
Mark Riordan
6c45d6dc01 Fix "status -5 inflating zlib packet"
Signed-off-by: Mark Riordan <mriordan@ipswitch.com>
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2011-08-09 20:13:20 +02:00
Andreas Schneider
9c0af42dd8 pki: Use a consistent name scheme.
Rename ssh_key_import_private to ssh_pki_import_privkey_file.
2011-08-09 18:05:47 +02:00
Andreas Schneider
bec483bc18 pki: Add ssh_pki_import_pubkey_base64(). 2011-08-08 15:28:31 +02:00
Andreas Schneider
f81444bd57 pki: Add pki_do_sign(). 2011-08-08 15:28:31 +02:00
Andreas Schneider
38d00c0e7a bind: Use ssh_key_import_private(). 2011-08-08 15:28:31 +02:00
Andreas Schneider
9bed334da3 pki: Add ssh_pki_convert_key_to_privatekey(). 2011-08-08 15:28:31 +02:00
Andreas Schneider
7c302d376c pki: Move _privatekey_from_file to legacy.c. 2011-08-08 15:28:31 +02:00
Andreas Schneider
36ee2d3332 pki: Create pki_publickey_from_privatekey(). 2011-08-08 15:28:31 +02:00
Andreas Schneider
f55cd7de43 pki: Improve ssh_key_import_private(). 2011-08-08 15:28:31 +02:00
Andreas Schneider
9569d053d8 pki: Improve ssh_pki_import_privkey_base64(). 2011-08-08 15:28:31 +02:00
Andreas Schneider
028888719a pki: Add pki_privatekey_type_from_string(). 2011-08-08 15:28:31 +02:00
Andreas Schneider
d8b41bcac3 pki: Add placeholder for ecdsa and certs. 2011-08-08 15:28:31 +02:00
Andreas Schneider
6ccb3f7a82 pki: Add pki_crypto.c. 2011-08-08 15:28:31 +02:00
Andreas Schneider
37b80e9261 pki: Move keyfiles to pki_gcrypt.c. 2011-08-08 15:28:31 +02:00
Einar Floystad Dorum
01c4b713dc Fixed ssh_scp_write so it works when doing recursive copy
There where two issues with ssh_scp_write:
1) It did not write a status message after the last write and OpenSSH
   would then give up after the write finished.
2) OpenSSH would sometimes write a status message, after near ends write.
   If scp_write didn't handle it, and subsequent status message. The remote
   window would shrink to zero and ssh_channel_write would start returning 0.

Signed-off-by: Einar Floystad Dorum <einarfd@mailthief.com>
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2011-08-08 15:27:23 +02:00
rofl0r
35686b4822 client: Fix another source of endless wait. 2011-08-06 11:12:02 +02:00
rofl0r
7ccd9c31b3 channels: Fix an endless loop in case of a channel_open error. 2011-08-06 11:12:02 +02:00
rofl0r
af85337f5f session: Fix timeout handling.
-2 now means to use the timeout specified in options. It wasn't used
earlier and poll only knows -1 and 0 anyway for special meanings.
2011-08-06 11:12:02 +02:00
rofl0r
563fbe4de8 channels: Fix checking for fatal errors.
We need this that we don't end up in and infinite poll loop.
2011-08-06 11:11:12 +02:00
rofl0r
39f962c91e channels: Fix ssh_channel_from_local()
It only worked if the first channel in the list was equivalent to we
were looking for.
2011-08-06 11:08:55 +02:00
rofl0r
c31cac93f3 misc: Fix ssh_timeout_update(). 2011-08-06 11:08:38 +02:00
rofl0r
a290fe33c1 gitignore: ignore object files 2011-08-06 10:53:08 +02:00
Andreas Schneider
15ebbad146 examples: Fix permissions of the file we copy.
Thanks to Baptiste Marchand.
2011-08-03 22:21:43 +02:00
Andreas Schneider
790b62bca5 channels: Set the max packet size to 32768. 2011-08-03 20:49:57 +02:00
Andreas Schneider
ca47c9b46e cmake: Make CHECK_C_COMPILER_FLAG_SSP a function. 2011-07-29 11:37:52 +02:00
Aris Adamantiadis
0943ce3a4a Fixed build on openssl 2011-07-20 09:56:43 +02:00
Aris Adamantiadis
da954c2c5e Fixes the ssh_log issue on ssh_bind handles. 2011-07-19 22:16:28 +02:00
Andreas Schneider
dc9ac022f5 doc: Add OpenSSH pub certkey auth. 2011-07-19 12:20:36 +02:00
Aris Adamantiadis
54fb43358c Workaround ssh_get_user_home_dir on LDAP users 2011-07-13 12:04:46 +02:00
Andreas Schneider
cc29fef234 build: Remove broken old Makefile. 2011-06-30 15:47:52 +02:00
Andreas Schneider
f684e76ab2 Merge branch 'pki' 2011-06-15 18:27:23 +02:00
Andreas Schneider
c75581fb93 pki: Make ssh_key_is_private() a public function. 2011-06-15 18:27:05 +02:00
Andreas Schneider
27cedaa0b6 pki: Make ssh_key_is_public() a public function. 2011-06-15 18:27:05 +02:00
Andreas Schneider
2be90be740 known_hosts: Added a log message for key type mismatch. 2011-06-15 18:27:05 +02:00
Andreas Schneider
3ba44badb0 build: Fix libssh_threads pkg-config. 2011-06-15 18:26:51 +02:00
Aris Adamantiadis
bcec7eeddc [crypto] fix pubkey authentication with ecdh 2011-06-14 23:13:20 +02:00
Aris Adamantiadis
ce03d26e03 Fix memory leak with session_id 2011-06-14 22:57:43 +02:00
Aris Adamantiadis
db2d0ebc44 Fix build with missing openssl/ecdh.h 2011-06-14 22:57:43 +02:00
Andreas Schneider
583a7f933a cmake: Added pkg-config support for libssh_treads. 2011-06-14 13:47:04 +02:00
Aris Adamantiadis
2653b31af0 [crypto] Removed ugly ifdefs on gcrypt/libcrypto 2011-06-13 14:47:17 +02:00
Aris Adamantiadis
a3c28f2558 Fix memory leak 2011-06-13 14:06:30 +02:00
Aris Adamantiadis
c5a998f47a [crypto] initial support for ecdh-sha2-nistp256
Works with openssl
Still requires work for libgcrypt and other modes
2011-06-13 13:46:34 +02:00
Aris Adamantiadis
3b72bf0880 Moved DH specific code to dh.h 2011-06-12 20:55:58 +02:00
Aris Adamantiadis
113de13543 Test for ecdh and dh-group1 2011-06-12 20:54:33 +02:00
Aris Adamantiadis
b54e8cdae5 Check for ecdsa with openssl, added log_warning 2011-06-12 19:38:42 +02:00
Andreas Schneider
fb0f125351 packet: Don't (de)compress empty buffers.
This fixes bug #50.
2011-06-11 13:15:46 +02:00
Andreas Schneider
981190f8d3 pki: Add ssh_key_type_to_char() and ssh_key_type_from_name(). 2011-06-11 13:04:22 +02:00
Andreas Schneider
88e2f17b97 pki: Make ssh_key_type a public function. 2011-06-11 13:04:22 +02:00
Andreas Schneider
29fa4b6b35 pki: Add SSH_KEYTYPE_ECDSA. 2011-06-11 13:04:22 +02:00
Aris Adamantiadis
7ff69d9c48 packet: Abort session on fatal errors on packets 2011-06-09 23:27:41 +02:00
Andreas Schneider
640e3830f2 build: Check for ntohll().
This function is available on AIX.
2011-06-06 18:56:30 +02:00
Andreas Schneider
3fa801a929 string: Added missing include. 2011-06-06 18:56:15 +02:00
Andreas Schneider
d536cc4f39 string: Added missing errno. 2011-06-06 18:50:39 +02:00
Andreas Schneider
ee83301eb3 build: Update ChangeLog. 2011-06-01 17:55:26 +02:00
Andreas Schneider
1880ef54d2 cmake: Fix static .lib overwriting on Windows. 2011-06-01 14:52:27 +02:00
Andreas Schneider
94ca5ed3df cmake: Set next version. 2011-05-30 12:38:17 +02:00
Andreas Schneider
693425afab tests: Check error of ssh_userauth_kbdint(). 2011-05-28 13:31:17 +02:00
Andreas Schneider
82798035fc tests: Remove superfluous closedir(). 2011-05-28 13:28:49 +02:00
Andreas Schneider
3c21281bf0 session: Fix return code of ssh_blocking_flush(). 2011-05-28 13:27:14 +02:00
Aris Adamantiadis
3bc46c3bf0 remove "0.5.0 is dev" in the doc 2011-05-27 13:37:52 +02:00
Aris Adamantiadis
ac167c9077 Forgot a cast to remove warnings 2011-05-27 13:36:55 +02:00
Aris Adamantiadis
c84380bad5 Fix documentation bug about threading 2011-05-27 13:26:15 +02:00
Aris Adamantiadis
17454caf64 Fix bug #5, channel_read_nonblocking that blocks 2011-05-27 13:13:02 +02:00
Mark Riordan
dcea8db6b2 Fix memory leak when compression is used
Signed-off-by: Mark Riordan <mriordan@ipswitch.com>
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2011-05-27 11:45:45 +02:00
Aris Adamantiadis
809b3adeba Fix compilation without server and sftp modes 2011-05-26 21:56:42 +02:00
Aris Adamantiadis
34b05fd2dc Fix memory leaks in pki and testcase 2011-05-26 21:33:36 +02:00
Andreas Schneider
c483418b82 sftp: Reset eof on seek operations.
This fixes bug #48.
2011-05-26 11:22:11 +02:00
Andreas Schneider
ba03388031 misc: Fix compilation on Windows. 2011-05-26 11:20:04 +02:00
Andreas Schneider
8b73609e47 cmake: Remove unused regcomp check. 2011-05-25 22:09:41 +02:00
Andreas Schneider
07fb895fe9 cmake: Fix detection of clock_gettime. 2011-05-25 22:08:31 +02:00
Aris Adamantiadis
65282841e2 Replace clock_gettime with gettimeofday when missing 2011-05-25 21:27:48 +02:00
Aris Adamantiadis
59f7647cd9 Introduced ssh_timeout_elapsed functions
Functions to mesure elapsed time before and after a serie of
calls. Introduces a dependancy to clock_gettime() and librt,
hope this doesn't break anything. Porting to gettimeofday() should
not be too hard.
2011-05-24 23:26:18 +02:00
Aris Adamantiadis
4d6b1aa2c7 Added testcase for the timeout connecting problem 2011-05-24 23:25:40 +02:00
Aris Adamantiadis
79434649d0 Fix "connecting to closed port" on MacosX 2011-05-20 15:13:45 +02:00
Aris Adamantiadis
a053d819a3 Fixed warnings on MacosX with Xcode4 2011-05-20 14:31:13 +02:00
Aris Adamantiadis
837896e72d scp: Fixed documentation bugs. bug #8 2011-05-20 13:42:24 +02:00
Oliver Stöneberg
12b61a6266 doc: Small update to auth.c documentation. 2011-05-17 14:22:11 +02:00
Oliver Stöneberg
f4f4ce37f0 poll: Removed WSAPoll() support.
It was causing too many issues and the poll emulation is quite stable.
2011-05-17 14:21:17 +02:00
Oliver Stöneberg
671a982739 connect: Set timeout on connect
This also fixes error handling in ssh_poll_ctx_dopoll() and
ssh_handle_packets(), so it won't loop forever on an actual timeout.
2011-05-17 14:21:04 +02:00
Oliver Stöneberg
4e153aed8a channel: Fixed potential use-after-free in ssh_channel_get_exit_status().
If ssh_channel_get_exit_status() is called more than once and the
connection closed.
2011-05-17 14:20:56 +02:00
Oliver Stöneberg
525324b2f9 examples: Use the right cleanup functions. 2011-05-17 14:20:48 +02:00
Oliver Stöneberg
e3311d03db tests: Fixed some cppcheck warnings. 2011-05-17 14:20:28 +02:00
Oliver Stöneberg
7f0761885c keyfiles: Fixed compilation without defines.
This fixes cppcheck issues.
2011-05-17 14:20:09 +02:00
Oliver Stöneberg
9866763789 socket: Fixed use-after-free.
When s->callbacks->exception() was called in ssh_socket_pollcallback()
we had a use after free bug.
2011-05-17 14:19:51 +02:00
Andreas Schneider
32cd45612b channel: Improve the request signal documentation. 2011-05-15 13:42:38 +02:00
Andreas Schneider
d4838d4dc8 messages: Try to fix the build. 2011-05-03 10:55:14 +02:00
Oliver Stöneberg
daf1c3e0a8 Use BIO* in _privatekey_from_file [Oliver Stöneberg]
_privatekey_from_file: moved FILE* into HAVE_LIBGCRYPT code / added missing #ifdef's to default case of switch [Oliver Stöneberg]
(cherry picked from commit dcb50cc0c8)
2011-05-02 19:19:41 +02:00
milo
32ba5204b7 Delay the check for kbdint->answers in kbdint_send() 2011-05-02 18:02:56 +02:00
milo
b6e712e934 Fix segfault when ssh_userauth_kbdint_setanswer() has not been called 2011-05-02 17:30:43 +02:00
milo
7d2064c289 [socket] fix a segfault at disconnect
(cherry picked from commit 56394917b15e41603c641c22a4e29c33b096d673)
2011-05-02 17:02:25 +02:00
milo
eb5fedb685 [event] don't use sessions in event anymore
(cherry picked from commit 89d0fdbbde4cf48e783a8ee7c5907c51a83e207b)
2011-05-02 17:01:59 +02:00
milo
1979c14aac [messages] don't queue messages if callback present
(cherry picked from commit 99d0f6d7c77e064b7fd0f0f46c40988de1996f3b)
2011-05-02 16:59:52 +02:00
milo
8092541603 [poll] avoid infinite loop in ssh_poll_ctx_free()
(cherry picked from commit eace59d3eaad413fd846d1c8b4c926285f6cd5ab)
2011-05-02 16:58:40 +02:00
milo
7ba0938846 [channels] Added ssh_channel_window_size() and avoided reentrancy in channel_write_common()
(cherry picked from commit 27313334578f4acb7ccf0687bba7f76b2febd569)
2011-05-02 16:58:27 +02:00
Oliver Stöneberg
3ae01ff9f5 init: Some initialization fixes.
- Check result of ssh_init() in privatekey_from_base64()
- Moved code from ssh_finalize() to appropriate subroutines
- Only initialize sockets once (caused mismatch of WSAStartup() and
  WSACleanup() calls and potential usage of bsd_poll when win_poll
  should be used)
2011-05-01 19:42:50 +02:00
Oliver Stöneberg
040a543f57 socket: Fixed poll input event. 2011-05-01 19:42:38 +02:00
Oliver Stöneberg
a73459171b examples: Removed unnecessary \n from ssh_log() calls in samplessh. 2011-05-01 19:33:26 +02:00
Oliver Stöneberg
c3849a3cfd examples: Fixed memory leak in samplessh when using commands. 2011-05-01 19:33:09 +02:00
milo
91c9d86d45 [keyfiles] Fix two memory leaks 2011-04-18 17:49:54 +02:00
milo
6e58342abc [pki] remove unused functions 2011-04-18 17:40:27 +02:00
Andreas Schneider
8b95328b1b poll: Fix poll input events.
bug#38
2011-04-15 19:14:15 +02:00
Andreas Schneider
644145a88c examples: Fix some memory leaks. 2011-04-15 19:05:53 +02:00
Andreas Schneider
ef658b4bef Fix assertion with Visual Studio because of %zu. 2011-04-15 19:02:21 +02:00
Andreas Schneider
a6c53d51de scp: More correct fix for snprintf 64-bit format. 2011-04-15 18:56:52 +02:00
Mark Riordan
e7e4f261a6 scp: Fix snprintf format for 64-bit size on SCP push.
Signed-off-by: Mark Riordan <mriordan@ipswitch.com>
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2011-04-15 16:18:26 +02:00
Mark Riordan
96d5f13813 scp: Support huge files by changing size to 64-bit type.
Signed-off-by: Mark Riordan <mriordan@ipswitch.com>
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2011-04-15 16:18:26 +02:00
Aris Adamantiadis
3a77f2aebe [pki] Fix buffer overflow in pki 2011-04-15 09:11:09 +02:00
Mark Riordan
5939cfe78a scp: Fix potential infinite loop in ssh_scp_close
Signed-off-by: Mark Riordan <mriordan@ipswitch.com>
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2011-04-14 14:18:45 +02:00
Andreas Schneider
3e7d4534ce examples: Call correct functions on exit. 2011-04-14 14:16:58 +02:00
milo
cee8ca339b Use const for x11_auth_* strings 2011-04-14 14:05:44 +02:00
milo
7cc4471168 Implemented X11 server side 2011-04-14 14:05:44 +02:00
milo
3046a50614 Skip \r when reading private keys 2011-04-14 14:05:44 +02:00
milo
23aa58e442 Added some tortures for pki 2011-04-14 14:05:44 +02:00
milo
f8c7ad9c7a [pki] Added ssh_userauth_pki_pubkey() function 2011-04-14 14:05:44 +02:00
milo
72b53aa11e Fix error message in privatekey_from_base64() 2011-04-14 14:05:44 +02:00
milo
c96314971c [pki] Add documentation and check for NULLs 2011-04-14 14:05:44 +02:00
milo
82e3068cb7 Set freed pointers to NULL in ssh_key struct 2011-04-14 14:05:44 +02:00
milo
b308bb9d52 [pki] added ssh_pki_do_sign() function 2011-04-14 14:05:44 +02:00
milo
c1f65492f7 [pki] Added conversion functions to migrate seemlessly to ssh_key 2011-04-14 14:05:44 +02:00
milo
c5db7674ec [pki] check for NULL and small cosmetic changes 2011-04-14 14:05:44 +02:00
milo
2694853979 [pki] Added ssh_pki_publickey_from_privatekey() function 2011-04-14 14:05:44 +02:00
milo
69d2457762 [pki] Added ssh_pki_import_privkey_base64() 2011-04-14 14:05:44 +02:00
milo
c1d385f6da [pki] remove non existing function prototype 2011-04-14 14:05:44 +02:00
milo
c20afa75a2 [pki] Fixed a probable bug in privatekey_file_to_buffer() 2011-04-14 14:05:44 +02:00
milo
df3e497dbd [pki] Added privatekey_from_base64() function...
and wrapped it with privatekey_from_file()
2011-04-14 14:05:44 +02:00
milo
9a21093ab8 [pki] Added b64decode_dsa_privatekey() function 2011-04-14 14:05:44 +02:00
milo
5f54eff0be [pki] Added b64decode_rsa_privatekey() function 2011-04-14 14:05:43 +02:00
milo
43ebdbfe46 [pki] Added privatekey_string_to_buffer() function 2011-04-14 14:05:43 +02:00
milo
2be42922c8 [pki] Make ssh_key_new and ssh_key_free public 2011-04-14 14:05:43 +02:00
milo
a0a3ceeaa0 Semantic fix on malloc 2011-04-14 13:46:40 +02:00
milo
42315772b2 Fix a memleak on event poll contexts 2011-04-14 13:31:24 +02:00
milo
23b28a573c Fix a 0 bytes malloc in server kbdint implementation 2011-04-14 13:31:11 +02:00
Aris Adamantiadis
934252d6ca Fixed missing CRYPTO_cleanup_all_ex_data() in ssh_finalize 2011-04-14 13:09:09 +02:00
Andreas Schneider
94e7d345a7 wrapper: Fixed a possible NULL pointer dereference. 2011-04-14 10:17:44 +02:00
Andreas Schneider
7e4916cefc server: Fixed a possible NULL pointer dereference. 2011-04-14 10:10:19 +02:00
milo
e04d30e083 Bug fix in ssh_poll_ctx_remove() 2011-04-14 00:09:35 +02:00
Oliver Stöneberg
166ee451c5 build: Fixed some VS2010 problems. 2011-04-11 11:18:57 +02:00
Oliver Stöneberg
46475dfa2f keys: Fixed issues reported by cppcheck. 2011-04-11 11:06:32 +02:00
Andreas Schneider
7150cabafa cmake: Fixed a typo. 2011-04-08 11:02:25 +02:00
Mark Riordan
29bb718a93 sftp: Fixed double-free in sftp_unlink(). 2011-04-08 10:59:05 +02:00
Aris Adamantiadis
1c062b22bf Fixed doc of ssh_userauth_list() 2011-03-28 12:55:48 +02:00
Aris Adamantiadis
4bc9c96e4e Change session state after receiving a Disconnect 2011-03-28 12:46:08 +02:00
Andreas Schneider
0ab17a8906 doc: Extremly important README update! 2011-03-25 19:24:42 +01:00
Aris Adamantiadis
1a101a959e Fix the ssh_message_retrieve problem by anihilation 2011-03-22 12:23:02 +01:00
Aris Adamantiadis
dff4e4e6d3 Implement ssh_blocking_flush()
Based on code from Jan Willamowius
2011-03-22 11:49:57 +01:00
Aris Adamantiadis
79b74bdf64 Added a IP address test 2011-03-22 10:45:07 +01:00
Andreas Schneider
633d6532be example: Use const in auth_password from samplesshd. 2011-03-10 11:23:45 +01:00
Andreas Schneider
7e921b7afb messages: Make returned strings const. 2011-03-09 19:45:17 +01:00
Andreas Schneider
7420b0fb83 doc: More doc for messaging functions. 2011-03-09 19:39:34 +01:00
Andreas Schneider
52e223dfdd doc: Added missing doc for common message function. 2011-03-09 19:19:56 +01:00
Andreas Schneider
e2706fe21d doc: Fixed typos in messaging introduction. 2011-03-09 19:06:59 +01:00
Andreas Schneider
7daa81f3aa doc: Improve the doc of ssh_bind_set_callbacks. 2011-03-09 18:33:03 +01:00
Andreas Schneider
6754c34711 doc: Improved documentation for server options. 2011-03-06 14:25:21 +01:00
Andreas Schneider
7e9d384ec8 build: Set version to 0.5.90. 2011-03-01 21:28:50 +01:00
Andreas Schneider
d97458d640 messages: Added missing config.h include. 2011-02-25 10:22:19 +01:00
Andreas Schneider
dab8f847e6 legacy: Added missing channel_write_stderr. 2011-02-23 12:38:45 +01:00
Andreas Schneider
8d3823127c legacy: Fixed the symbol export. 2011-02-23 12:31:29 +01:00
milo
8ee8d4f913 Check for NULL channel pointers 2011-02-22 14:11:19 +01:00
milo
000d659ea2 examples: Added a event context based sshd example. 2011-02-20 14:37:43 +01:00
milo
ddb1c1838f poll: Added a function to poll the events. 2011-02-20 14:37:43 +01:00
milo
e40261c22c poll: Added function to remove fd from the event context. 2011-02-20 14:37:34 +01:00
milo
6582da1d67 poll: Added function to add an fd to the events. 2011-02-20 14:37:34 +01:00
milo
0c76156f54 poll: Added function to remove session from event loop. 2011-02-20 14:37:31 +01:00
milo
4b72953c7e poll: Added function to add session to an event. 2011-02-20 14:36:44 +01:00
milo
4ee4450a6b poll: Added a function to free an event. 2011-02-20 14:35:11 +01:00
milo
a2634ceea8 poll: Started to add a poll based event loop. 2011-02-20 14:21:45 +01:00
Andreas Schneider
ac8276c70e server: Fixed logging function name. 2011-02-18 20:57:09 +01:00
Andreas Schneider
5cc2e69d0d channel: Fixed a possible NULL pointe dereference. 2011-02-18 18:03:37 +01:00
Bernhard R. Link
23b3c46fd6 channel: Improve ssh_channel_open_reverse_forward documentation. 2011-02-18 17:50:50 +01:00
Bernhard R. Link
8a83990c16 channels: set error for new NULL pointer checks
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2011-02-18 17:45:28 +01:00
Bernhard R. Link
071b0034db socket: Set errors on return.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2011-02-14 22:48:53 +01:00
Bernhard R. Link
7ae59c571a channels: Set errors on return.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2011-02-14 22:48:53 +01:00
Bernhard R. Link
b1db0e54ad bind: Set errors on return.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2011-02-14 22:48:53 +01:00
milo
4230509e80 Check for NULL pointers in string.c 2011-02-14 20:23:12 +01:00
milo
11e54e8221 Check for NULL pointers in channels.c 2011-02-14 20:02:02 +01:00
Andreas Schneider
eea1df3574 misc: Fixed ssh_is_ipaddr_v4() on Windows. 2011-02-13 17:36:45 +01:00
Andreas Schneider
9baa491b0b build: Try to fix the build on Solaris. 2011-02-13 13:22:25 +01:00
Andreas Schneider
cd30a1d4b1 misc: Added working ssh_is_ipaddr for Windows. 2011-02-13 11:56:47 +01:00
Andreas Schneider
ca941d6985 tests: Fixed misc and isipaddr test on Windows. 2011-02-13 11:56:47 +01:00
Andreas Schneider
cbcd5668f5 torture: Fixed torture on Windows. 2011-02-13 11:56:47 +01:00
Andreas Schneider
fdd1cb18d0 auth: Fixed a memory leak in kdbint auth.
Milo please check!
2011-02-13 11:04:09 +01:00
Andreas Schneider
a0c05c4c4e tests: Added two asserts to torture_sftp_dir. 2011-02-13 10:44:09 +01:00
Andreas Schneider
499467d362 auth: Fixed a double free error. 2011-02-13 10:43:59 +01:00
Andreas Schneider
d1ddec00d9 misc: Fixed ssh_is_ipaddr on FreeBSD. 2011-02-13 10:32:47 +01:00
Bernhard R. Link
637fc7ea59 always set error when returning error in auth.c
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2011-02-12 20:11:50 +01:00
Andreas Schneider
622d5a43b3 ctest: Added support for checking out a branch. 2011-02-12 20:08:23 +01:00
Aris Adamantiadis
483cdc2d2c Added ssh_userauth_[offer_]pubkey nonblocking iface 2011-02-12 19:21:13 +01:00
Andreas Schneider
5d4bd5a21d tests: Added ipv6 tests. 2011-02-12 19:16:06 +01:00
Andreas Schneider
e8c3f55751 tests: Fixed torture_isipaddr. 2011-02-12 19:12:39 +01:00
Bernhard R. Link
8d9d46ca66 use ssh_log instead of fprintf in ssh_config_parse_file
ssh_config_parse_file calls "fprintf(stderr," directly thus ignoring
a set log callback. Replacing the print with a call to ssh_log should
fix this.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2011-02-12 19:08:59 +01:00
Andreas Schneider
4d38b4c848 srv_sftp: Set error messages in sftp_get_client_message(). 2011-02-12 19:08:59 +01:00
Andreas Schneider
768fbdd92e connect: Use ssh_is_ipaddr instead of regex. 2011-02-12 19:08:59 +01:00
Andreas Schneider
b313fa944a misc: Added ssh_is_ipaddr() function. 2011-02-12 19:08:59 +01:00
Aris Adamantiadis
7acc2fa607 Connect: Test the new isipaddr() function 2011-02-12 15:07:37 +01:00
Bernhard R. Link
8e0e4d8fb3 ssh_connect_host_nonblocking returns SSH_EINTR, not E_INTR, so update documentation
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2011-02-12 14:29:03 +01:00
Bernhard R. Link
8b51d29363 proper prototypes
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2011-02-12 12:26:33 +01:00
milo
cc76a192df New example server for kbdint authentication. 2011-02-10 14:39:58 +01:00
milo
3c0a4781e4 Added the keyboard-interactive authentication method 2011-02-10 14:39:20 +01:00
milo
32e23a25da Reverse commit 076dfb82 for the server side 2011-02-10 14:37:34 +01:00
milo
3eaf25d989 Fix NULL pointer checks in poll 2011-02-10 14:35:29 +01:00
Andreas Schneider
6f2bf91e29 build: Increased version numbers. 2011-02-10 12:54:33 +01:00
194 changed files with 27210 additions and 11940 deletions

View File

@@ -1 +1,11 @@
-Iinclude -Ibuild
-DWITH_SERVER=1
-DWITH_GSSAPI=1
-DWITH_ZLIB=1
-DWITH_SFTP=1
-DWITH_SSH1=1
-DWITH_PCAP=1
-Iinclude/libssh
-Iinclude
-Ibuild
-Itests
-Isrc

3
.gitignore vendored
View File

@@ -1,6 +1,9 @@
*.a
*.o
.*
*.swp
*~$
build
cscope.*
tags
build

View File

@@ -1,7 +1,7 @@
Author(s):
Aris Adamantiadis <aris@0xbadc0de.be> (project initiator)
Andreas Schneider <mail@cynapses.org> (developer)
Andreas Schneider <asn@cryptomilk.org> (developer)
Nick Zitzmann <seiryu (at) comcast (dot) net> (mostly client SFTP stuff)

View File

@@ -7,8 +7,8 @@ cmake_minimum_required(VERSION 2.6.0)
set(APPLICATION_NAME ${PROJECT_NAME})
set(APPLICATION_VERSION_MAJOR "0")
set(APPLICATION_VERSION_MINOR "5")
set(APPLICATION_VERSION_PATCH "2")
set(APPLICATION_VERSION_MINOR "6")
set(APPLICATION_VERSION_PATCH "5")
set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
@@ -19,7 +19,7 @@ set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINO
# Increment AGE. Set REVISION to 0
# If the source code was changed, but there were no interface changes:
# Increment REVISION.
set(LIBRARY_VERSION "4.2.2")
set(LIBRARY_VERSION "4.5.1")
set(LIBRARY_SOVERSION "4")
# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
@@ -39,17 +39,13 @@ include(CPackConfig.cmake)
include(MacroEnsureOutOfSourceBuild)
macro_ensure_out_of_source_build("${PROJECT_NAME} requires an out of source build. Please create a separate build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there.")
# add macros
include(MacroAddPlugin)
include(MacroCopyFile)
# search for libraries
if (WITH_LIBZ)
if (WITH_ZLIB)
find_package(ZLIB REQUIRED)
endif (WITH_LIBZ)
endif (WITH_ZLIB)
if (WITH_GCRYPT)
find_package(GCrypt REQUIRED)
find_package(GCrypt 1.5.0 REQUIRED)
if (NOT GCRYPT_FOUND)
message(FATAL_ERROR "Could not find GCrypt")
endif (NOT GCRYPT_FOUND)
@@ -67,6 +63,17 @@ endif(WITH_GCRYPT)
set(CMAKE_THREAD_PREFER_PTHREADS ON)
find_package(Threads)
if (WITH_GSSAPI)
find_package(GSSAPI)
endif (WITH_GSSAPI)
if (WITH_NACL)
find_package(NaCl)
if (NOT NACL_FOUND)
set(WITH_NACL OFF)
endif (NOT NACL_FOUND)
endif (WITH_NACL)
# config.h checks
include(ConfigureChecks.cmake)
configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
@@ -89,11 +96,33 @@ install(
pkgconfig
)
add_subdirectory(examples)
# cmake config files
set(LIBSSH_LIBRARY_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}ssh${CMAKE_SHARED_LIBRARY_SUFFIX})
set(LIBSSH_THREADS_LIBRARY_NAME ${CMAKE_SHARED_LIBRARY_PREFIX}ssh${CMAKE_SHARED_LIBRARY_SUFFIX})
configure_file(${PROJECT_NAME}-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake @ONLY)
configure_file(${PROJECT_NAME}-config-version.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake @ONLY)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
DESTINATION
${CMAKE_INSTALL_DIR}/${PROJECT_NAME}
COMPONENT
devel
)
# in tree build settings
configure_file(libssh-build-tree-settings.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libssh-build-tree-settings.cmake @ONLY)
if (WITH_EXAMPLES)
add_subdirectory(examples)
endif (WITH_EXAMPLES)
if (WITH_TESTING)
find_package(CMockery REQUIRED)
include(AddCMockeryTest)
find_package(CMocka REQUIRED)
include(AddCMockaTest)
add_subdirectory(tests)
endif (WITH_TESTING)
@@ -101,12 +130,15 @@ endif (WITH_TESTING)
message(STATUS "********************************************")
message(STATUS "********** ${PROJECT_NAME} build options : **********")
message(STATUS "zlib support: ${WITH_LIBZ}")
message(STATUS "zlib support: ${WITH_ZLIB}")
message(STATUS "libgcrypt support: ${WITH_GCRYPT}")
message(STATUS "libnacl support: ${WITH_NACL}")
message(STATUS "SSH-1 support: ${WITH_SSH1}")
message(STATUS "SFTP support: ${WITH_SFTP}")
message(STATUS "Server support : ${WITH_SERVER}")
message(STATUS "GSSAPI support : ${WITH_GSSAPI}")
message(STATUS "Pcap debugging support : ${WITH_PCAP}")
message(STATUS "With static library: ${WITH_STATIC_LIB}")
message(STATUS "Unit testing: ${WITH_TESTING}")
message(STATUS "Client code Unit testing: ${WITH_CLIENT_TESTING}")
if (WITH_INTERNAL_DOC)

View File

@@ -11,15 +11,15 @@ set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
### versions
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "5")
set(CPACK_PACKAGE_VERSION_PATCH "2")
set(CPACK_PACKAGE_VERSION_MAJOR ${APPLICATION_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${APPLICATION_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${APPLICATION_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
### source generator
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SOURCE_IGNORE_FILES "~$;[.]swp$;/[.]svn/;/[.]git/;.gitignore;/build/;tags;cscope.*")
set(CPACK_SOURCE_IGNORE_FILES "~$;[.]swp$;/[.]svn/;/[.]git/;.gitignore;/build/;/obj/;tags;cscope.*")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
if (WIN32)

View File

@@ -1,7 +1,7 @@
set(UPDATE_TYPE "true")
set(CTEST_PROJECT_NAME "libssh")
set(CTEST_NIGHTLY_START_TIME "01:00:00 CET")
set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
set(CTEST_DROP_METHOD "http")
set(CTEST_DROP_SITE "test.libssh.org")

View File

@@ -1,6 +1,98 @@
ChangeLog
==========
version 0.6.5 (released 2015-04-29)
* Fixed CVE-2015-3146
* Fixed port handling in config file
* Fixed the build with libgcrypt
* Fixed SFTP endian issues (rlo #179)
* Fixed uninitilized sig variable (rlo #167)
* Fixed polling issues which could result in a hang
* Fixed handling of EINTR in ssh_poll() (rlo #186)
* Fixed C99 issues with __func__
* Fixed some memory leaks
* Improved macro detection on Windows
version 0.6.4 (released 2014-12-19)
* Fixed CVE-2014-8132.
* Added SHA-2 for session ID signing with ECDSA keys.
* Added support for ECDSA host keys.
* Added support for more ECDSA hostkey algorithms.
* Added ssh_pki_key_ecdsa_name() API.
* Fixed setting the bindfd only after successful listen.
* Fixed issues with user created sockets.
* Fixed several issues in libssh C++ wrapper.
* Fixed several documentation issues.
* Fixed channel exit-signal request.
* Fixed X11 request screen number in messages.
* Fixed several memory leaks.
version 0.6.3 (released 2014-03-04)
* Fixed CVE-2014-0017.
* Fixed memory leak with ecdsa signatures.
version 0.6.2 (released 2014-03-04)
* security: fix for vulnerability CVE-2014-0017
version 0.6.1 (released 2014-02-08)
* Added support for libgcrypt 1.6.
* Added ssh_channel_accept_forward().
* Added known_hosts heuristic during connection (#138).
* Added getters for session cipher names.
* Fixed decrypt of zero length buffer.
* Fixed padding in RSA signature blobs.
* Fixed DSA signature extraction.
* Fixed some memory leaks.
* Fixed read of non-connected socket.
* Fixed thread dectection.
version 0.6.0 (released 2014-01-08)
* Added new publicy key API.
* Added new userauth API.
* Added ssh_get_publickey_hash() function.
* Added ssh_get_poll_flags() function.
* Added gssapi-mic userauth.
* Added GSSAPIServerIdentity option.
* Added GSSAPIClientIdentity option.
* Added GSSAPIDelegateCredentials option.
* Added new callback based server API.
* Added Elliptic Curve DSA (ECDSA) support (with OpenSSL).
* Added Elliptic Curve Diffie Hellman (ECDH) support.
* Added Curve25519 for ECDH key exchange.
* Added improved logging system.
* Added SSH-agent forwarding.
* Added key-reexchange.
* Added more unit tests.
* Improved documentation.
* Fixed timeout handling.
version 0.5.5 (released 2013-07-26)
* BUG 103: Fix ProxyCommand parsing.
* Fix setting -D_FORTIFY_SOURCE=2.
* Fix pollset error return if emtpy.
* Fix NULL pointer checks in channel functions.
* Several bugfixes.
version 0.5.4 (released 2013-01-22)
* CVE-2013-0176 - NULL dereference leads to denial of service
* Fixed several NULL pointer dereferences in SSHv1.
* Fixed a free crash bug in options parsing.
version 0.5.3 (released 2012-11-20)
* CVE-2012-4559 Fixed multiple double free() flaws.
* CVE-2012-4560 Fixed multiple buffer overflow flaws.
* CVE-2012-4561 Fixed multiple invalid free() flaws.
* BUG #84 - Fix bug in sftp_mkdir not returning on error.
* BUG #85 - Fixed a possible channel infinite loop if the connection dropped.
* BUG #88 - Added missing channel request_state and set it to accepted.
* BUG #89 - Reset error state to no error on successful SSHv1 authentiction.
* Fixed a possible use after free in ssh_free().
* Fixed multiple possible NULL pointer dereferences.
* Fixed multiple memory leaks in error paths.
* Fixed timeout handling.
* Fixed regression in pre-connected socket setting.
* Handle all unknown global messages.
version 0.5.2 (released 2011-09-17)
* Increased window size x10.
* Fixed SSHv1.

59
CodingStyle Normal file
View File

@@ -0,0 +1,59 @@
Coding Style Conventions
========================
Coding style guidelines are about reducing the number of unnecessary
reformatting patches and making things easier for developers to work together.
You don't have to like them or even agree with them, but once put in place we
all have to abide by them (or vote to change them). However, coding style
should never outweigh coding itself and so the guidelines described here are
hopefully easy enough to follow as they are very common and supported by tools
and editors.
The basic style for C code is the Linux kernel coding style [1] with one
excecption, we use 4 spaces instead of tabs. This closely matches what most
libssh developers use already anyways, with a few exceptions as mentioned
below.
To shorthen this here are the highlights:
* Maximum line width is 80 characters
The reason is not about people with low-res screens but rather sticking
to 80 columns prevents you from easily nesting more than one level of
if statements or other code blocks.
* Use 4 spaces to indent
* No trailing whitespaces
* Follow the K&R guidelines. We won't go through all of them here. Do you
have a copy of "The C Programming Language" anyways right?
Editors
========
VIM
----
set ts=4 sw=4 et cindent
For Vim, the following settings in $HOME/.vimrc will also deal with
displaying trailing whitespace:
if has("syntax") && (&t_Co > 2 || has("gui_running"))
syntax on
function! ActivateInvisibleCharIndicator()
syntax match TrailingSpace "[ \t]\+$" display containedin=ALL
highlight TrailingSpace ctermbg=Red
endf
autocmd BufNewFile,BufRead * call ActivateInvisibleCharIndicator()
endif
" Show tabs, trailing whitespace, and continued lines visually
set list listchars=tab:»·,trail:·,extends:…
" highlight overly long lines same as TODOs.
set textwidth=80
autocmd BufNewFile,BufRead *.c,*.h exec 'match Todo /\%>' . &textwidth . 'v.\+/'
[1] https://www.kernel.org/doc/Documentation/CodingStyle

View File

@@ -36,7 +36,12 @@ endfunction()
if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
compiler_dumpversion(GNUCC_VERSION)
if (NOT GNUCC_VERSION EQUAL 34)
check_c_compiler_flag("-fvisibility=hidden" WITH_VISIBILITY_HIDDEN)
set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden")
check_c_source_compiles(
"void __attribute__((visibility(\"default\"))) test() {}
int main(void){ return 0; }
" WITH_VISIBILITY_HIDDEN)
set(CMAKE_REQUIRED_FLAGS "")
endif (NOT GNUCC_VERSION EQUAL 34)
endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
@@ -44,19 +49,16 @@ endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
check_include_file(argp.h HAVE_ARGP_H)
check_include_file(pty.h HAVE_PTY_H)
check_include_file(termios.h HAVE_TERMIOS_H)
check_include_file(unistd.h HAVE_UNISTD_H)
check_include_file(util.h HAVE_UTIL_H)
check_include_file(sys/time.h HAVE_SYS_TIME_H)
if (WIN32)
check_include_file(wspiapi.h HAVE_WSPIAPI_H)
check_include_files("winsock2.h;ws2tcpip.h;wspiapi.h" HAVE_WSPIAPI_H)
if (NOT HAVE_WSPIAPI_H)
message(STATUS "WARNING: Without wspiapi.h, this build will only work on Windows XP and newer versions")
endif (NOT HAVE_WSPIAPI_H)
check_include_file(ws2tcpip.h HAVE_WS2TCPIP_H)
if (HAVE_WSPIAPI_H OR HAVE_WS2TCPIP_H)
set(HAVE_GETADDRINFO TRUE)
set(HAVE_GETHOSTBYNAME TRUE)
endif (HAVE_WSPIAPI_H OR HAVE_WS2TCPIP_H)
set(HAVE_SELECT TRUE)
check_include_files("winsock2.h;ws2tcpip.h" HAVE_WS2TCPIP_H)
endif (WIN32)
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
@@ -68,37 +70,76 @@ check_include_file(openssl/blowfish.h HAVE_OPENSSL_BLOWFISH_H)
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
check_include_file(openssl/des.h HAVE_OPENSSL_DES_H)
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
check_include_file(openssl/ecdh.h HAVE_OPENSSL_ECDH_H)
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
check_include_file(openssl/ec.h HAVE_OPENSSL_EC_H)
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
check_include_file(openssl/ecdsa.h HAVE_OPENSSL_ECDSA_H)
if (CMAKE_HAVE_PTHREAD_H)
set(HAVE_PTHREAD_H 1)
endif (CMAKE_HAVE_PTHREAD_H)
if (NOT WITH_GCRYPT)
if (HAVE_OPENSSL_EC_H AND HAVE_OPENSSL_ECDSA_H)
set(HAVE_OPENSSL_ECC 1)
endif (HAVE_OPENSSL_EC_H AND HAVE_OPENSSL_ECDSA_H)
if (HAVE_OPENSSL_ECC)
set(HAVE_ECC 1)
endif (HAVE_OPENSSL_ECC)
endif (NOT WITH_GCRYPT)
# FUNCTIONS
check_function_exists(isblank HAVE_ISBLANK)
check_function_exists(strncpy HAVE_STRNCPY)
check_function_exists(vsnprintf HAVE_VSNPRINTF)
check_function_exists(snprintf HAVE_SNPRINTF)
if (WIN32)
check_function_exists(_strtoui64 HAVE__STRTOUI64)
check_function_exists(_vsnprintf_s HAVE__VSNPRINTF_S)
check_function_exists(_vsnprintf HAVE__VSNPRINTF)
check_function_exists(_snprintf HAVE__SNPRINTF)
check_function_exists(_snprintf_s HAVE__SNPRINTF_S)
if (HAVE_WSPIAPI_H OR HAVE_WS2TCPIP_H)
check_symbol_exists(ntohll winsock2.h HAVE_NTOHLL)
check_symbol_exists(htonll winsock2.h HAVE_HTONLL)
set(CMAKE_REQUIRED_LIBRARIES ws2_32)
check_symbol_exists(select "winsock2.h;ws2tcpip.h" HAVE_SELECT)
check_symbol_exists(poll "winsock2.h;ws2tcpip.h" HAVE_SELECT)
# The getaddrinfo function is defined to the WspiapiGetAddrInfo inline function
check_symbol_exists(getaddrinfo "winsock2.h;ws2tcpip.h" HAVE_GETADDRINFO)
set(CMAKE_REQUIRED_LIBRARIES)
endif (HAVE_WSPIAPI_H OR HAVE_WS2TCPIP_H)
set(HAVE_SELECT TRUE)
else (WIN32)
check_function_exists(poll HAVE_POLL)
check_function_exists(select HAVE_SELECT)
check_function_exists(getaddrinfo HAVE_GETADDRINFO)
check_symbol_exists(ntohll arpa/inet.h HAVE_NTOHLL)
check_symbol_exists(htonll arpa/inet.h HAVE_HTONLL)
endif (WIN32)
if (UNIX)
if (NOT LINUX)
# libsocket (Solaris)
check_library_exists(socket getaddrinfo "" HAVE_LIBSOCKET)
if (HAVE_LIBSOCKET)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} socket)
set(HAVE_GETADDRINFO TRUE)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} socket)
endif (HAVE_LIBSOCKET)
# libresolv
check_library_exists(resolv hstrerror "" HAVE_LIBRESOLV)
if (HAVE_LIBRESOLV)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} resolv)
endif (HAVE_LIBRESOLV)
# libnsl/inet_pton (Solaris)
check_library_exists(nsl inet_pton "" HAVE_LIBNSL)
if (HAVE_LIBNSL)
@@ -114,12 +155,10 @@ if (UNIX)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt)
endif (HAVE_LIBRT OR HAVE_CLOCK_GETTIME)
check_function_exists(getaddrinfo HAVE_GETADDRINFO)
check_function_exists(poll HAVE_POLL)
check_function_exists(select HAVE_SELECT)
check_library_exists(util forkpty "" HAVE_LIBUTIL)
check_function_exists(cfmakeraw HAVE_CFMAKERAW)
check_function_exists(regcomp HAVE_REGCOMP)
check_function_exists(ntohll HAVE_NTOHLL)
check_function_exists(strtoull HAVE_STRTOULL)
check_function_exists(__strtoull HAVE___STRTOULL)
endif (UNIX)
set(LIBSSH_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "libssh required system libraries")
@@ -130,20 +169,58 @@ if (OPENSSL_FOUND)
endif (OPENSSL_FOUND)
if (GCRYPT_FOUND)
set(HAVE_LIBGCRYPT 1)
set(HAVE_LIBGCRYPT 1)
if (GCRYPT_VERSION VERSION_GREATER "1.4.6")
#set(HAVE_GCRYPT_ECC 1)
#set(HAVE_ECC 1)
endif (GCRYPT_VERSION VERSION_GREATER "1.4.6")
endif (GCRYPT_FOUND)
if (ZLIB_LIBRARY)
set(HAVE_LIBZ 1)
endif (ZLIB_LIBRARY)
if (CMAKE_HAVE_THREADS_LIBRARY)
if (CMAKE_USE_PTHREADS_INIT)
set(HAVE_PTHREAD 1)
endif (CMAKE_USE_PTHREADS_INIT)
endif (CMAKE_HAVE_THREADS_LIBRARY)
if (CMAKE_USE_PTHREADS_INIT)
set(HAVE_PTHREAD 1)
endif (CMAKE_USE_PTHREADS_INIT)
# OPTIONS
check_c_source_compiles("
__thread int tls;
int main(void) {
return 0;
}" HAVE_GCC_THREAD_LOCAL_STORAGE)
check_c_source_compiles("
__declspec(thread) int tls;
int main(void) {
return 0;
}" HAVE_MSC_THREAD_LOCAL_STORAGE)
check_c_source_compiles("
#include <string.h>
int main(void)
{
char buf[] = \"This is some content\";
memset(buf, '\\\\0', sizeof(buf)); __asm__ volatile(\"\" : : \"r\"(&buf) : \"memory\");
return 0;
}" HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
check_c_source_compiles("
#include <stdio.h>
int main(void) {
printf(\"%s\", __func__);
return 0;
}" HAVE_COMPILER__FUNC__)
check_c_source_compiles("
#include <stdio.h>
int main(void) {
printf(\"%s\", __FUNCTION__);
return 0;
}" HAVE_COMPILER__FUNCTION__)
if (WITH_DEBUG_CRYPTO)
set(DEBUG_CRYPTO 1)
endif (WITH_DEBUG_CRYPTO)
@@ -152,6 +229,10 @@ if (WITH_DEBUG_CALLTRACE)
set(DEBUG_CALLTRACE 1)
endif (WITH_DEBUG_CALLTRACE)
if (WITH_GSSAPI AND NOT GSSAPI_FOUND)
set(WITH_GSSAPI 0)
endif (WITH_GSSAPI AND NOT GSSAPI_FOUND)
# ENDIAN
if (NOT WIN32)
test_big_endian(WORDS_BIGENDIAN)

View File

@@ -1,4 +1,5 @@
option(WITH_LIBZ "Build with ZLIB support" ON)
option(WITH_GSSAPI "Build with GSSAPI support" ON)
option(WITH_ZLIB "Build with ZLIB support" ON)
option(WITH_SSH1 "Build with SSH1 support" OFF)
option(WITH_SFTP "Build with SFTP support" ON)
option(WITH_SERVER "Build with SSH server support" ON)
@@ -11,6 +12,13 @@ option(WITH_INTERNAL_DOC "Compile doxygen internal documentation" OFF)
option(WITH_TESTING "Build with unit tests" OFF)
option(WITH_CLIENT_TESTING "Build with client tests; requires a running sshd" OFF)
option(WITH_BENCHMARKS "Build benchmarks tools" OFF)
option(WITH_EXAMPLES "Build examples" ON)
option(WITH_NACL "Build with libnacl (curve25519" ON)
if (WITH_ZLIB)
set(WITH_LIBZ ON)
else (WITH_ZLIB)
set(WITH_LIBZ OFF)
endif (WITH_ZLIB)
if(WITH_BENCHMARKS)
set(WITH_TESTING ON)
@@ -19,3 +27,7 @@ endif(WITH_BENCHMARKS)
if (WITH_TESTING)
set(WITH_STATIC_LIB ON)
endif (WITH_TESTING)
if (WITH_NACL)
set(WITH_NACL ON)
endif (WITH_NACL)

27
INSTALL
View File

@@ -18,16 +18,26 @@ optional:
Note that these version numbers are version we know works correctly. If you
build and run libssh successfully with an older version, please let us know.
Windows binaries known to be working:
- http://www.slproweb.com/products/Win32OpenSSL.html
- http://zlib.net/ -> zlib compiled DLL
We installed them in C:\Program Files
## Building
First, you need to configure the compilation, using CMake. Go inside the
`build` dir. Create it if it doesn't exist.
GNU/Linux and MacOS X:
GNU/Linux, MacOS X, MSYS/MinGW:
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug ..
make
On Windows you should choose a makefile gernerator with -G or use
cmake-gui.exe ..
### CMake standard options
Here is a list of the most interesting options provided out of the box by
CMake.
@@ -47,7 +57,7 @@ Options are defined in the following files:
They can be changed with the -D option:
`cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug -DWITH_LIBZ=OFF ..`
`cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug -DWITH_ZLIB=OFF ..`
### Browsing/editing CMake options
@@ -59,6 +69,17 @@ and MacOS X).
- On Windows: run `cmakesetup`
- On GNU/Linux and MacOS X: run `ccmake ..`
### Useful Windows options:
If you have installed OpenSSL or ZLIB in non standard directories, maybe you
want to set:
OPENSSL_ROOT_DIR
and
ZLIB_ROOT_DIR
## Installing
If you want to install libssh after compilation run:
@@ -67,7 +88,7 @@ If you want to install libssh after compilation run:
## Running
The libssh binary can be found in the `build/libssh` directory.
The libssh binary can be found in the `build/src` directory.
You can use `build/examples/samplessh` which is a sample client to
test libssh on UNIX.

120
README
View File

@@ -1,5 +1,12 @@
libssh: the SSH library
~~~~~~~~~~~~~~~~~~~~~~~
_ _ _ _
(_) (_) (_) (_)
(_) _ (_) _ _ _ _ _ (_) _
(_) (_) (_)(_) _ (_)(_) (_)(_) (_)(_) _
(_) (_) (_) (_) _ (_) _ (_) (_) (_)
(_) (_) (_)(_)(_) (_)(_) (_)(_) (_) (_).org
The SSH library
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1* Why ?
-_-_-_-_-_
@@ -55,17 +62,102 @@ ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
5* Copyright policy
-_-_-_-_-_-_-_-_-_-_
The developers of libssh have a policy of asking for contributions to be made
under the personal copyright of the contributor, instead of a corporate
copyright.
libssh is a project with distributed copyright ownership, which means we prefer
the copyright on parts of libssh to be held by individuals rather than
corporations if possible. There are historical legal reasons for this, but one
of the best ways to explain it is that its much easier to work with
individuals who have ownership than corporate legal departments if we ever need
to make reasonable compromises with people using and working with libssh.
There are some reasons for the establishment of this policy:
We track the ownership of every part of libssh via git, our source code control
system, so we know the provenance of every piece of code that is committed to
libssh.
* Individual copyrights make copyright registration in the US a simpler
process.
* If libssh is copyrighted by individuals rather than corporations,
decisions regarding enforcement and protection of copyright will, more
likely, be made in the interests of the project, and not in the interests
of any corporations shareholders.
* If we ever need to relicense a portion of the code contacting individuals
for permission to do so is much easier than contacting a company.
So if possible, if youre doing libssh changes on behalf of a company who
normally owns all the work you do please get them to assign personal copyright
ownership of your changes to you as an individual, that makes things very easy
for us to work with and avoids bringing corporate legal departments into the
picture.
If you cant do this we can still accept patches from you owned by your
employer under a standard employment contract with corporate copyright
ownership. It just requires a simple set-up process first.
We use a process very similar to the way things are done in the Linux Kernel
community, so it should be very easy to get a sign off from your corporate
legal department. The only changes weve made are to accommodate the license we
use, which is LGPLv2 (or later) whereas the Linux kernel uses GPLv2.
The process is called signing.
How to sign your work
----------------------
Once you have permission to contribute to libssh from your employer, simply
email a copy of the following text from your corporate email address to:
contributing@libssh.org
--------------------------------------------------------------------------
libssh Developer's Certificate of Origin. Version 1.0
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the appropriate
version of the GNU General Public License; or
(b) The contribution is based upon previous work that, to the best of
my knowledge, is covered under an appropriate open source license
and I have the right under that license to submit that work with
modifications, whether created in whole or in part by me, under
the GNU General Public License, in the appropriate version; or
(c) The contribution was provided directly to me by some other
person who certified (a) or (b) and I have not modified it.
(d) I understand and agree that this project and the contribution are
public and that a record of the contribution (including all
metadata and personal information I submit with it, including my
sign-off) is maintained indefinitely and may be redistributed
consistent with the libssh Team's policies and the requirements of
the GNU GPL where they are relevant.
(e) I am granting this work to this project under the terms of the
GNU Lesser General Public License as published by the
Free Software Foundation; either version 2.1 of
the License, or (at the option of the project) any later version.
http://www.gnu.org/licenses/lgpl-2.1.html
--------------------------------------------------------------------------
We will maintain a copy of that email as a record that you have the rights to
contribute code to libssh under the required licenses whilst working for the
company where the email came from.
Then when sending in a patch via the normal mechanisms described above, add a
line that states:
Signed-off-by: Random J Developer <random@developer.example.org>
using your real name and the email address you sent the original email you used
to send the libssh Developers Certificate of Origin to us (sorry, no
pseudonyms or anonymous contributions.)
Thats it! Such code can then quite happily contain changes that have copyright
messages such as:
(c) Example Corporation.
and can be merged into the libssh codebase in the same way as patches from any
other individual. You dont need to send in a copy of the libssh Developers
Certificate of Origin for each patch, or inside each patch. Just the sign-off
message is all that is required once weve received the initial email.
Have fun and happy libssh hacking!
The libssh Team

118
SubmittingPatches Normal file
View File

@@ -0,0 +1,118 @@
How to contribute a patch to libssh
====================================
Simple, just make the code change, and email it as either a "diff -u"
change, or as a "git format-patch" change against the original source
code to libssh@libssh.org, or attach it to a bug report at
https://red.libssh.org/
For larger code changes, breaking the changes up into a set of simple
patches, each of which does a single thing, are much easier to review.
Patch sets like that will most likely have an easier time being merged
into the libssh code than large single patches that make lots of
changes in one large diff.
Ownership of the contributed code
==================================
libssh is a project with distributed copyright ownership, which means
we prefer the copyright on parts of libssh to be held by individuals
rather than corporations if possible. There are historical legal
reasons for this, but one of the best ways to explain it is that it's
much easier to work with individuals who have ownership than corporate
legal departments if we ever need to make reasonable compromises with
people using and working with libssh.
We track the ownership of every part of libssh via http://git.libssh.org,
our source code control system, so we know the provenance of every piece
of code that is committed to libssh.
So if possible, if you're doing libssh changes on behalf of a company
who normally owns all the work you do please get them to assign
personal copyright ownership of your changes to you as an individual,
that makes things very easy for us to work with and avoids bringing
corporate legal departments into the picture.
If you can't do this we can still accept patches from you owned by
your employer under a standard employment contract with corporate
copyright ownership. It just requires a simple set-up process first.
We use a process very similar to the way things are done in the Linux
Kernel community, so it should be very easy to get a sign off from
your corporate legal department. The only changes we've made are to
accommodate the license we use, which is LGPLv2 (or later) whereas the
Linux kernel uses GPLv2.
The process is called signing.
How to sign your work
----------------------
Once you have permission to contribute to libssh from your employer, simply
email a copy of the following text from your corporate email address to:
contributing@libssh.org
libssh Developer's Certificate of Origin. Version 1.0
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the appropriate
version of the GNU General Public License; or
(b) The contribution is based upon previous work that, to the best of
my knowledge, is covered under an appropriate open source license
and I have the right under that license to submit that work with
modifications, whether created in whole or in part by me, under
the GNU General Public License, in the appropriate version; or
(c) The contribution was provided directly to me by some other
person who certified (a) or (b) and I have not modified it.
(d) I understand and agree that this project and the contribution are
public and that a record of the contribution (including all
metadata and personal information I submit with it, including my
sign-off) is maintained indefinitely and may be redistributed
consistent with the libssh Team's policies and the requirements of
the GNU GPL where they are relevant.
(e) I am granting this work to this project under the terms of the
GNU Lesser General Public License as published by the
Free Software Foundation; either version 2.1 of
the License, or (at the option of the project) any later version.
http://www.gnu.org/licenses/lgpl-2.1.html
We will maintain a copy of that email as a record that you have the
rights to contribute code to libssh under the required licenses whilst
working for the company where the email came from.
Then when sending in a patch via the normal mechanisms described
above, add a line that states:
Signed-off-by: Random J Developer <random@developer.example.org>
using your real name and the email address you sent the original email
you used to send the libssh Developer's Certificate of Origin to us
(sorry, no pseudonyms or anonymous contributions.)
That's it! Such code can then quite happily contain changes that have
copyright messages such as:
(c) Example Corporation.
and can be merged into the libssh codebase in the same way as patches
from any other individual. You don't need to send in a copy of the
libssh Developer's Certificate of Origin for each patch, or inside each
patch. Just the sign-off message is all that is required once we've
received the initial email.
Have fun and happy libssh hacking !
The libssh Team

View File

@@ -4,7 +4,7 @@
#
# Script to build libssh on UNIX.
#
# Copyright (c) 2006-2007 Andreas Schneider <mail@cynapses.org>
# Copyright (c) 2006-2007 Andreas Schneider <asn@cryptomilk.org>
#
SOURCE_DIR=".."

View File

@@ -1,7 +1,7 @@
# - ADD_CHECK_TEST(test_name test_source linklib1 ... linklibN)
# Copyright (c) 2007 Daniel Gollub <dgollub@suse.de>
# Copyright (c) 2007-2010 Andreas Schneider <asn@cynapses.org>
# Copyright (c) 2007-2010 Andreas Schneider <asn@cryptomilk.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
@@ -16,8 +16,8 @@ if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
set(CMAKE_EXEC_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags")
endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
function (ADD_CMOCKERY_TEST _testName _testSource)
function (ADD_CMOCKA_TEST _testName _testSource)
add_executable(${_testName} ${_testSource})
target_link_libraries(${_testName} ${ARGN})
add_test(${_testName} ${CMAKE_CURRENT_BINARY_DIR}/${_testName})
endfunction (ADD_CMOCKERY_TEST)
endfunction (ADD_CMOCKA_TEST)

View File

@@ -1,11 +1,12 @@
# - Check whether the C compiler supports a given flag in the
# context of a stack checking compiler option.
# CHECK_C_COMPILER_FLAG_SSP(FLAG VARIABLE)
#
# FLAG - the compiler flag
# VARIABLE - variable to store the result
#
# This actually calls the check_c_source_compiles macro.
#
# This actually calls check_c_source_compiles.
# See help for CheckCSourceCompiles for a listing of variables
# that can modify the build.
@@ -15,12 +16,11 @@
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
INCLUDE(CheckCSourceCompiles)
MACRO (CHECK_C_COMPILER_FLAG_SSP _FLAG _RESULT)
SET(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
CHECK_C_SOURCE_COMPILES("int main(int argc, char **argv) { char buffer[256]; return buffer[argc]=0;}" ${_RESULT})
SET (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
ENDMACRO (CHECK_C_COMPILER_FLAG_SSP)
include(CheckCSourceCompiles)
function(CHECK_C_COMPILER_FLAG_SSP _FLAG _RESULT)
set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
check_c_source_compiles("int main(int argc, char **argv) { char buffer[256]; return buffer[argc]=0;}" ${_RESULT})
set(CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
endfunction(CHECK_C_COMPILER_FLAG_SSP)

View File

@@ -25,3 +25,6 @@ if (NOT CMAKE_BUILD_TYPE)
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
)
endif (NOT CMAKE_BUILD_TYPE)
# Create the compile command database for clang by default
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

View File

@@ -1,13 +1,14 @@
# define system dependent compiler flags
include(CheckCCompilerFlag)
include(MacroCheckCCompilerFlagSSP)
include(CheckCCompilerFlagSSP)
if (UNIX AND NOT WIN32)
#
# Define GNUCC compiler flags
#
if (${CMAKE_C_COMPILER_ID} MATCHES GNU)
if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)")
# add -Wconversion ?
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic -pedantic-errors")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wshadow -Wmissing-prototypes -Wdeclaration-after-statement")
@@ -25,11 +26,16 @@ if (UNIX AND NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
endif (WITH_STACK_PROTECTOR)
check_c_compiler_flag("-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE)
if (WITH_FORTIFY_SOURCE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2")
endif (WITH_FORTIFY_SOURCE)
endif (${CMAKE_C_COMPILER_ID} MATCHES GNU)
if (CMAKE_BUILD_TYPE)
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
if (CMAKE_BUILD_TYPE_LOWER MATCHES (release|relwithdebinfo|minsizerel))
check_c_compiler_flag("-Wp,-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE)
if (WITH_FORTIFY_SOURCE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wp,-D_FORTIFY_SOURCE=2")
endif (WITH_FORTIFY_SOURCE)
endif()
endif()
endif (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)")
#
# Check for large filesystem support
@@ -69,3 +75,10 @@ if (MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_NONSTDC_NO_WARNINGS=1 /D _CRT_SECURE_NO_WARNINGS=1")
endif (MSVC)
# This removes this annoying warning
# "warning: 'BN_CTX_free' is deprecated: first deprecated in OS X 10.7 [-Wdeprecated-declarations]"
if (OSX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-deprecated-declarations")
endif (OSX)

View File

@@ -1,15 +1,4 @@
if (WIN32)
# Same same
set(BIN_INSTALL_DIR "bin" CACHE PATH "-")
set(SBIN_INSTALL_DIR "." CACHE PATH "-")
set(LIB_INSTALL_DIR "lib" CACHE PATH "-")
set(INCLUDE_INSTALL_DIR "include" CACHE PATH "-")
set(PLUGIN_INSTALL_DIR "plugins" CACHE PATH "-")
set(HTML_INSTALL_DIR "doc/HTML" CACHE PATH "-")
set(ICON_INSTALL_DIR "." CACHE PATH "-")
set(SOUND_INSTALL_DIR "." CACHE PATH "-")
set(LOCALE_INSTALL_DIR "lang" CACHE PATH "-")
elseif (UNIX OR OS2)
if (UNIX OR OS2)
IF (NOT APPLICATION_NAME)
MESSAGE(STATUS "${PROJECT_NAME} is used as APPLICATION_NAME")
SET(APPLICATION_NAME ${PROJECT_NAME})
@@ -58,6 +47,10 @@ elseif (UNIX OR OS2)
CACHE PATH "The subdirectory to the header prefix (default prefix/include)"
)
set(CMAKE_INSTALL_DIR
"${LIB_INSTALL_DIR}/cmake"
CACHE PATH "The subdirectory to install cmake config files")
SET(DATA_INSTALL_DIR
"${DATA_INSTALL_PREFIX}"
CACHE PATH "The parent directory where applications can install their data (default prefix/share/${APPLICATION_NAME})"
@@ -101,4 +94,16 @@ elseif (UNIX OR OS2)
"${SHARE_INSTALL_PREFIX}/info"
CACHE PATH "The ${APPLICATION_NAME} info install dir (default prefix/info)"
)
else()
# Same same
set(BIN_INSTALL_DIR "bin" CACHE PATH "-")
set(SBIN_INSTALL_DIR "sbin" CACHE PATH "-")
set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "-")
set(INCLUDE_INSTALL_DIR "include" CACHE PATH "-")
set(CMAKE_INSTALL_DIR "CMake" CACHE PATH "-")
set(PLUGIN_INSTALL_DIR "plugins" CACHE PATH "-")
set(HTML_INSTALL_DIR "doc/HTML" CACHE PATH "-")
set(ICON_INSTALL_DIR "icons" CACHE PATH "-")
set(SOUND_INSTALL_DIR "soudns" CACHE PATH "-")
set(LOCALE_INSTALL_DIR "lang" CACHE PATH "-")
endif ()

View File

@@ -26,3 +26,7 @@ endif (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
if (CMAKE_SYSTEM_NAME MATCHES "OS2")
set(OS2 TRUE)
endif (CMAKE_SYSTEM_NAME MATCHES "OS2")
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
set (OSX TRUE)
endif (CMAKE_SYSTEM_NAME MATCHES "Darwin")

View File

@@ -6,7 +6,7 @@
# ARGP_LIBRARIES - Link these to use Argp
# ARGP_DEFINITIONS - Compiler switches required for using Argp
#
# Copyright (c) 2010 Andreas Schneider <asn@cynapses.org>
# Copyright (c) 2010 Andreas Schneider <asn@cryptomilk.org>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.

View File

@@ -0,0 +1,66 @@
# - Try to find CMocka
# Once done this will define
#
# CMOCKA_ROOT_DIR - Set this variable to the root installation of CMocka
#
# Read-Only variables:
# CMOCKA_FOUND - system has CMocka
# CMOCKA_INCLUDE_DIR - the CMocka include directory
# CMOCKA_LIBRARIES - Link these to use CMocka
# CMOCKA_DEFINITIONS - Compiler switches required for using CMocka
#
#=============================================================================
# Copyright (c) 2011-2012 Andreas Schneider <asn@cryptomilk.org>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
#
set(_CMOCKA_ROOT_HINTS
)
set(_CMOCKA_ROOT_PATHS
"$ENV{PROGRAMFILES}/cmocka"
)
find_path(CMOCKA_ROOT_DIR
NAMES
include/cmocka.h
HINTS
${_CMOCKA_ROOT_HINTS}
PATHS
${_CMOCKA_ROOT_PATHS}
)
mark_as_advanced(CMOCKA_ROOT_DIR)
find_path(CMOCKA_INCLUDE_DIR
NAMES
cmocka.h
PATHS
${CMOCKA_ROOT_DIR}/include
)
find_library(CMOCKA_LIBRARY
NAMES
cmocka
PATHS
${CMOCKA_ROOT_DIR}/lib
)
if (CMOCKA_LIBRARY)
set(CMOCKA_LIBRARIES
${CMOCKA_LIBRARIES}
${CMOCKA_LIBRARY}
)
endif (CMOCKA_LIBRARY)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CMocka DEFAULT_MSG CMOCKA_LIBRARIES CMOCKA_INCLUDE_DIR)
# show the CMOCKA_INCLUDE_DIR and CMOCKA_LIBRARIES variables only in the advanced view
mark_as_advanced(CMOCKA_INCLUDE_DIR CMOCKA_LIBRARIES)

View File

@@ -1,63 +0,0 @@
# - Try to find CMockery
# Once done this will define
#
# CMOCKERY_FOUND - system has CMockery
# CMOCKERY_INCLUDE_DIRS - the CMockery include directory
# CMOCKERY_LIBRARIES - Link these to use CMockery
# CMOCKERY_DEFINITIONS - Compiler switches required for using CMockery
#
# Copyright (c) 2010 Andreas Schneider <asn@cryptomilk.org>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
if (CMOCKERY_LIBRARIES AND CMOCKERY_INCLUDE_DIRS)
# in cache already
set(CMOCKERY_FOUND TRUE)
else (CMOCKERY_LIBRARIES AND CMOCKERY_INCLUDE_DIRS)
find_path(CMOCKERY_INCLUDE_DIR
NAMES
google/cmockery.h
PATHS
${_CMOCKERY_DIR}/include
/usr/include
/usr/local/include
/opt/local/include
/sw/include
$ENV{PROGRAMFILES}/cmockery/include
)
find_library(CMOCKERY_LIBRARY
NAMES
cmockery
PATHS
${_CMOCKERY_DIR}/lib
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
$ENV{PROGRAMFILES}/cmockery/lib
)
set(CMOCKERY_INCLUDE_DIRS
${CMOCKERY_INCLUDE_DIR}
)
if (CMOCKERY_LIBRARY)
set(CMOCKERY_LIBRARIES
${CMOCKERY_LIBRARIES}
${CMOCKERY_LIBRARY}
)
endif (CMOCKERY_LIBRARY)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CMockery DEFAULT_MSG CMOCKERY_LIBRARIES CMOCKERY_INCLUDE_DIRS)
# show the CMOCKERY_INCLUDE_DIRS and CMOCKERY_LIBRARIES variables only in the advanced view
mark_as_advanced(CMOCKERY_INCLUDE_DIRS CMOCKERY_LIBRARIES)
endif (CMOCKERY_LIBRARIES AND CMOCKERY_INCLUDE_DIRS)

View File

@@ -7,7 +7,7 @@
# GCRYPT_DEFINITIONS - Compiler switches required for using GCrypt
#
#=============================================================================
# Copyright (c) 2009-2011 Andreas Schneider <asn@cryptomilk.org>
# Copyright (c) 2009-2012 Andreas Schneider <asn@cryptomilk.org>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
@@ -18,53 +18,58 @@
#=============================================================================
#
if (GCRYPT_LIBRARIES AND GCRYPT_INCLUDE_DIRS)
# in cache already
# set(GCRYPT_FOUND TRUE)
else (GCRYPT_LIBRARIES AND GCRYPT_INCLUDE_DIRS)
set(_GCRYPT_ROOT_HINTS
$ENV{GCRYTPT_ROOT_DIR}
${GCRYPT_ROOT_DIR})
set(_GCRYPT_ROOT_PATHS
"$ENV{PROGRAMFILES}/libgcrypt"
set(_GCRYPT_ROOT_PATHS
"$ENV{PROGRAMFILES}/libgcrypt")
set(_GCRYPT_ROOT_HINTS_AND_PATHS
HINTS ${_GCRYPT_ROOT_HINTS}
PATHS ${_GCRYPT_ROOT_PATHS})
find_path(GCRYPT_INCLUDE_DIR
NAMES
gcrypt.h
HINTS
${_GCRYPT_ROOT_HINTS_AND_PATHS}
)
find_library(GCRYPT_LIBRARY
NAMES
gcrypt
gcrypt11
libgcrypt-11
HINTS
${_GCRYPT_ROOT_HINTS_AND_PATHS}
)
set(GCRYPT_LIBRARIES ${GCRYPT_LIBRARY})
if (GCRYPT_INCLUDE_DIR)
file(STRINGS "${GCRYPT_INCLUDE_DIR}/gcrypt.h" _gcrypt_version_str REGEX "^#define GCRYPT_VERSION \"[0-9]+.[0-9]+.[0-9]+\"")
string(REGEX REPLACE "^.*GCRYPT_VERSION.*([0-9]+.[0-9]+.[0-9]+).*" "\\1" GCRYPT_VERSION "${_gcrypt_version_str}")
endif (GCRYPT_INCLUDE_DIR)
include(FindPackageHandleStandardArgs)
if (GCRYPT_VERSION)
find_package_handle_standard_args(GCrypt
REQUIRED_VARS
GCRYPT_INCLUDE_DIR
GCRYPT_LIBRARIES
VERSION_VAR
GCRYPT_VERSION
FAIL_MESSAGE
"Could NOT find GCrypt, try to set the path to GCrypt root folder in the system variable GCRYPT_ROOT_DIR"
)
else (GCRYPT_VERSION)
find_package_handle_standard_args(GCrypt
"Could NOT find GCrypt, try to set the path to GCrypt root folder in the system variable GCRYPT_ROOT_DIR"
GCRYPT_INCLUDE_DIR
GCRYPT_LIBRARIES)
endif (GCRYPT_VERSION)
find_path(GCRYPT_ROOT_DIR
NAMES
include/gcrypt.h
PATHS
${_GCRYPT_ROOT_PATHS}
)
mark_as_advanced(ZLIB_ROOT_DIR)
find_path(GCRYPT_INCLUDE_DIR
NAMES
gcrypt.h
PATHS
/usr/local/include
/opt/local/include
/sw/include
/usr/lib/sfw/include
${GCRYPT_ROOT_DIR}/include
)
set(GCRYPT_INCLUDE_DIRS ${GCRYPT_INCLUDE_DIR})
find_library(GCRYPT_LIBRARY
NAMES
gcrypt
gcrypt11
libgcrypt-11
PATHS
/opt/local/lib
/sw/lib
/usr/sfw/lib/64
/usr/sfw/lib
${GCRYPT_ROOT_DIR}/lib
)
set(GCRYPT_LIBRARIES ${GCRYPT_LIBRARY})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GCrypt DEFAULT_MSG GCRYPT_LIBRARIES GCRYPT_INCLUDE_DIRS)
# show the GCRYPT_INCLUDE_DIRS and GCRYPT_LIBRARIES variables only in the advanced view
mark_as_advanced(GCRYPT_INCLUDE_DIRS GCRYPT_LIBRARIES)
endif (GCRYPT_LIBRARIES AND GCRYPT_INCLUDE_DIRS)
# show the GCRYPT_INCLUDE_DIRS and GCRYPT_LIBRARIES variables only in the advanced view
mark_as_advanced(GCRYPT_INCLUDE_DIR GCRYPT_LIBRARIES)

View File

@@ -0,0 +1,324 @@
# - Try to find GSSAPI
# Once done this will define
#
# KRB5_CONFIG - Path to krb5-config
# GSSAPI_ROOT_DIR - Set this variable to the root installation of GSSAPI
#
# Read-Only variables:
# GSSAPI_FLAVOR_MIT - set to TURE if MIT Kerberos has been found
# GSSAPI_FLAVOR_HEIMDAL - set to TRUE if Heimdal Keberos has been found
# GSSAPI_FOUND - system has GSSAPI
# GSSAPI_INCLUDE_DIR - the GSSAPI include directory
# GSSAPI_LIBRARIES - Link these to use GSSAPI
# GSSAPI_DEFINITIONS - Compiler switches required for using GSSAPI
#
#=============================================================================
# Copyright (c) 2013 Andreas Schneider <asn@cryptomilk.org>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
#
find_path(GSSAPI_ROOT_DIR
NAMES
include/gssapi.h
include/gssapi/gssapi.h
HINTS
${_GSSAPI_ROOT_HINTS}
PATHS
${_GSSAPI_ROOT_PATHS}
)
mark_as_advanced(GSSAPI_ROOT_DIR)
if (UNIX)
find_program(KRB5_CONFIG
NAMES
krb5-config
PATHS
${GSSAPI_ROOT_DIR}/bin
/opt/local/bin)
mark_as_advanced(KRB5_CONFIG)
if (KRB5_CONFIG)
# Check if we have MIT KRB5
execute_process(
COMMAND
${KRB5_CONFIG} --vendor
RESULT_VARIABLE
_GSSAPI_VENDOR_RESULT
OUTPUT_VARIABLE
_GSSAPI_VENDOR_STRING)
if (_GSSAPI_VENDOR_STRING MATCHES ".*Massachusetts.*")
set(GSSAPI_FLAVOR_MIT TRUE)
else()
execute_process(
COMMAND
${KRB5_CONFIG} --libs gssapi
RESULT_VARIABLE
_GSSAPI_LIBS_RESULT
OUTPUT_VARIABLE
_GSSAPI_LIBS_STRING)
if (_GSSAPI_LIBS_STRING MATCHES ".*roken.*")
set(GSSAPI_FLAVOR_HEIMDAL TRUE)
endif()
endif()
# Get the include dir
execute_process(
COMMAND
${KRB5_CONFIG} --cflags gssapi
RESULT_VARIABLE
_GSSAPI_INCLUDE_RESULT
OUTPUT_VARIABLE
_GSSAPI_INCLUDE_STRING)
string(REGEX REPLACE "(\r?\n)+$" "" _GSSAPI_INCLUDE_STRING "${_GSSAPI_INCLUDE_STRING}")
string(REGEX REPLACE " *-I" "" _GSSAPI_INCLUDEDIR "${_GSSAPI_INCLUDE_STRING}")
endif()
if (NOT GSSAPI_FLAVOR_MIT AND NOT GSSAPI_FLAVOR_HEIMDAL)
# Check for HEIMDAL
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(_GSSAPI heimdal-gssapi)
endif (PKG_CONFIG_FOUND)
if (_GSSAPI_FOUND)
set(GSSAPI_FLAVOR_HEIMDAL TRUE)
else()
find_path(_GSSAPI_ROKEN
NAMES
roken.h
PATHS
${GSSAPI_ROOT_DIR}/include
${_GSSAPI_INCLUDEDIR})
if (_GSSAPI_ROKEN)
set(GSSAPI_FLAVOR_HEIMDAL TRUE)
endif()
endif ()
endif()
endif (UNIX)
find_path(GSSAPI_INCLUDE_DIR
NAMES
gssapi.h
gssapi/gssapi.h
PATHS
${GSSAPI_ROOT_DIR}/include
${_GSSAPI_INCLUDEDIR}
)
if (GSSAPI_FLAVOR_MIT)
find_library(GSSAPI_LIBRARY
NAMES
gssapi_krb5
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(KRB5_LIBRARY
NAMES
krb5
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(K5CRYPTO_LIBRARY
NAMES
k5crypto
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(COM_ERR_LIBRARY
NAMES
com_err
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
if (GSSAPI_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${GSSAPI_LIBRARY}
)
endif (GSSAPI_LIBRARY)
if (KRB5_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${KRB5_LIBRARY}
)
endif (KRB5_LIBRARY)
if (K5CRYPTO_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${K5CRYPTO_LIBRARY}
)
endif (K5CRYPTO_LIBRARY)
if (COM_ERR_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${COM_ERR_LIBRARY}
)
endif (COM_ERR_LIBRARY)
endif (GSSAPI_FLAVOR_MIT)
if (GSSAPI_FLAVOR_HEIMDAL)
find_library(GSSAPI_LIBRARY
NAMES
gssapi
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(KRB5_LIBRARY
NAMES
krb5
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(HCRYPTO_LIBRARY
NAMES
hcrypto
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(COM_ERR_LIBRARY
NAMES
com_err
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(HEIMNTLM_LIBRARY
NAMES
heimntlm
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(HX509_LIBRARY
NAMES
hx509
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(ASN1_LIBRARY
NAMES
asn1
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(WIND_LIBRARY
NAMES
wind
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
find_library(ROKEN_LIBRARY
NAMES
roken
PATHS
${GSSAPI_ROOT_DIR}/lib
${_GSSAPI_LIBDIR}
)
if (GSSAPI_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${GSSAPI_LIBRARY}
)
endif (GSSAPI_LIBRARY)
if (KRB5_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${KRB5_LIBRARY}
)
endif (KRB5_LIBRARY)
if (HCRYPTO_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${HCRYPTO_LIBRARY}
)
endif (HCRYPTO_LIBRARY)
if (COM_ERR_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${COM_ERR_LIBRARY}
)
endif (COM_ERR_LIBRARY)
if (HEIMNTLM_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${HEIMNTLM_LIBRARY}
)
endif (HEIMNTLM_LIBRARY)
if (HX509_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${HX509_LIBRARY}
)
endif (HX509_LIBRARY)
if (ASN1_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${ASN1_LIBRARY}
)
endif (ASN1_LIBRARY)
if (WIND_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${WIND_LIBRARY}
)
endif (WIND_LIBRARY)
if (ROKEN_LIBRARY)
set(GSSAPI_LIBRARIES
${GSSAPI_LIBRARIES}
${WIND_LIBRARY}
)
endif (ROKEN_LIBRARY)
endif (GSSAPI_FLAVOR_HEIMDAL)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GSSAPI DEFAULT_MSG GSSAPI_LIBRARIES GSSAPI_INCLUDE_DIR)
if (GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES)
set(GSSAPI_FOUND TRUE)
endif (GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES)
# show the GSSAPI_INCLUDE_DIRS and GSSAPI_LIBRARIES variables only in the advanced view
mark_as_advanced(GSSAPI_INCLUDE_DIRS GSSAPI_LIBRARIES)

View File

@@ -1,14 +1,15 @@
# - Try to find NSIS
# Once done this will define
#
# NSIS_ROOT_DIR - Set this variable to the root installation of ZLIB
# NSIS_ROOT_PATH - Set this variable to the root installation of NSIS
#
# Read-Only variables:
#
# NSIS_FOUND - system has NSIS
# NSIS_MAKE - NSIS creator executable
#
#=============================================================================
# Copyright (c) 2010-2011 Andreas Schneider <asn@cryptomilk.org>
# Copyright (c) 2010-2013 Andreas Schneider <asn@cryptomilk.org>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
@@ -19,21 +20,36 @@
#=============================================================================
#
set(_NSIS_ROOT_PATHS
C:/NSIS/Bin
"$ENV{PROGRAMFILES}/NSIS"
)
if (WIN32)
set(_NSIS_ROOT_HINTS
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\NSIS;Default]")
set(_NSIS_ROOT_PATHS
$ENV{PROGRAMFILES}/NSIS)
find_path(NSIS_ROOT_PATH
NAMES
Include/Library.nsh
HINTS
${_NSIS_ROOT_HINTS}
PATHS
${_NSIS_ROOT_PATHS}
)
mark_as_advanced(NSIS_ROOT_PATH)
endif (WIN32)
find_program(NSIS_MAKE
NAMES
makensis
PATHS
${NSIS_ROOT_PATH}
${NSIS_ROOT_PATH}/Bin
${_NSIS_ROOT_PATHS}
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NSIS DEFAULT_MSG NSIS_MAKE)
if (NSIS_MAKE)
set(NSIS_FOUND TRUE)
endif (NSIS_MAKE)
mark_as_advanced(NSIS_MAKE)

View File

@@ -0,0 +1,61 @@
# - Try to find NaCl
# Once done this will define
#
# NACL_FOUND - system has NaCl
# NACL_INCLUDE_DIRS - the NaCl include directory
# NACL_LIBRARIES - Link these to use NaCl
# NACL_DEFINITIONS - Compiler switches required for using NaCl
#
# Copyright (c) 2010 Andreas Schneider <asn@cryptomilk.org>
# Copyright (c) 2013 Aris Adamantiadis <aris@badcode.be>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
if (NACL_LIBRARIES AND NACL_INCLUDE_DIRS)
# in cache already
set(NACL_FOUND TRUE)
else (NACL_LIBRARIES AND NACL_INCLUDE_DIRS)
find_path(NACL_INCLUDE_DIR
NAMES
nacl/crypto_box_curve25519xsalsa20poly1305.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
/sw/include
)
find_library(NACL_LIBRARY
NAMES
nacl
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
set(NACL_INCLUDE_DIRS
${NACL_INCLUDE_DIR}
)
if (NACL_LIBRARY)
set(NACL_LIBRARIES
${NACL_LIBRARIES}
${NACL_LIBRARY}
)
endif (NACL_LIBRARY)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(NaCl DEFAULT_MSG NACL_LIBRARIES NACL_INCLUDE_DIRS)
# show the NACL_INCLUDE_DIRS and NACL_LIBRARIES variables only in the advanced view
mark_as_advanced(NACL_INCLUDE_DIRS NACL_LIBRARIES)
endif (NACL_LIBRARIES AND NACL_INCLUDE_DIRS)

View File

@@ -97,6 +97,7 @@ else (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)
zdll
zlib
zlib1
zlibd
PATHS
/usr/local/lib
/opt/local/lib

View File

@@ -1,21 +0,0 @@
# - MACRO_ADD_COMPILE_FLAGS(target_name flag1 ... flagN)
# Copyright (c) 2006, Oswald Buddenhagen, <ossi@kde.org>
# Copyright (c) 2006, Andreas Schneider, <mail@cynapses.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
macro (MACRO_ADD_COMPILE_FLAGS _target)
get_target_property(_flags ${_target} COMPILE_FLAGS)
if (_flags)
set(_flags ${_flags} ${ARGN})
else (_flags)
set(_flags ${ARGN})
endif (_flags)
set_target_properties(${_target} PROPERTIES COMPILE_FLAGS ${_flags})
endmacro (MACRO_ADD_COMPILE_FLAGS)

View File

@@ -1,20 +0,0 @@
# - MACRO_ADD_LINK_FLAGS(target_name flag1 ... flagN)
# Copyright (c) 2006, Oswald Buddenhagen, <ossi@kde.org>
# Copyright (c) 2006, Andreas Schneider, <mail@cynapses.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
macro (MACRO_ADD_LINK_FLAGS _target)
get_target_property(_flags ${_target} LINK_FLAGS)
if (_flags)
set(_flags "${_flags} ${ARGN}")
else (_flags)
set(_flags "${ARGN}")
endif (_flags)
set_target_properties(${_target} PROPERTIES LINK_FLAGS "${_flags}")
endmacro (MACRO_ADD_LINK_FLAGS)

View File

@@ -1,30 +0,0 @@
# - MACRO_ADD_PLUGIN(name [WITH_PREFIX] file1 .. fileN)
#
# Create a plugin from the given source files.
# If WITH_PREFIX is given, the resulting plugin will have the
# prefix "lib", otherwise it won't.
#
# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
# Copyright (c) 2006, Laurent Montel, <montel@kde.org>
# Copyright (c) 2006, Andreas Schneider, <mail@cynapses.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
macro (MACRO_ADD_PLUGIN _target_NAME _with_PREFIX)
if (${_with_PREFIX} STREQUAL "WITH_PREFIX")
set(_first_SRC)
else (${_with_PREFIX} STREQUAL "WITH_PREFIX")
set(_first_SRC ${_with_PREFIX})
endif (${_with_PREFIX} STREQUAL "WITH_PREFIX")
add_library(${_target_NAME} MODULE ${_first_SRC} ${ARGN})
if (_first_SRC)
set_target_properties(${_target_NAME} PROPERTIES PREFIX "")
endif (_first_SRC)
endmacro (MACRO_ADD_PLUGIN _name _sources)

View File

@@ -1,33 +0,0 @@
# - macro_copy_file(_src _dst)
# Copies a file to ${_dst} only if ${_src} is different (newer) than ${_dst}
#
# Example:
# macro_copy_file(${CMAKE_CURRENT_SOURCE_DIR}/icon.png ${CMAKE_CURRENT_BINARY_DIR}/.)
# Copies file icon.png to ${CMAKE_CURRENT_BINARY_DIR} directory
#
# Copyright (c) 2006-2007 Wengo
# Copyright (c) 2006-2008 Andreas Schneider <mail@cynapses.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING file.
macro (macro_copy_file _src _dst)
# Removes all path containing .svn or CVS or CMakeLists.txt during the copy
if (NOT ${_src} MATCHES ".*\\.svn|CVS|CMakeLists\\.txt.*")
if (CMAKE_VERBOSE_MAKEFILE)
message(STATUS "Copy file from ${_src} to ${_dst}")
endif (CMAKE_VERBOSE_MAKEFILE)
# Creates directory if necessary
get_filename_component(_path ${_dst} PATH)
file(MAKE_DIRECTORY ${_path})
execute_process(
COMMAND
${CMAKE_COMMAND} -E copy_if_different ${_src} ${_dst}
OUTPUT_QUIET
)
endif (NOT ${_src} MATCHES ".*\\.svn|CVS|CMakeLists\\.txt.*")
endmacro (macro_copy_file)

View File

@@ -2,10 +2,18 @@
#
# Adds a doxygen target that runs doxygen to generate the html
# and optionally the LaTeX API documentation.
# The doxygen target is added to the doc target as dependency.
# The doxygen target is added to the doc target as a dependency.
# i.e.: the API documentation is built with:
# make doc
#
# USAGE: GLOBAL INSTALL
#
# Install it with:
# cmake ./ && sudo make install
# Add the following to the CMakeLists.txt of your project:
# include(UseDoxygen OPTIONAL)
# Optionally copy Doxyfile.in in the directory of CMakeLists.txt and edit it.
#
# USAGE: INCLUDE IN PROJECT
#
# set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
@@ -13,88 +21,120 @@
# Add the Doxyfile.in and UseDoxygen.cmake files to the projects source directory.
#
#
# CONFIGURATION
#
# To configure Doxygen you can edit Doxyfile.in and set some variables in cmake.
# Variables you may define are:
# DOXYFILE_OUTPUT_DIR - Path where the Doxygen output is stored. Defaults to "doc".
#
# DOXYFILE_LATEX_DIR - Directory where the Doxygen LaTeX output is stored. Defaults to "latex".
#
# DOXYFILE_HTML_DIR - Directory where the Doxygen html output is stored. Defaults to "html".
# DOXYFILE_SOURCE_DIR - Path where the Doxygen input files are.
# Defaults to the current source directory.
# DOXYFILE_EXTRA_SOURCES - Additional source diretories/files for Doxygen to scan.
# The Paths should be in double quotes and separated by space. e.g.:
# "${CMAKE_CURRENT_BINARY_DIR}/foo.c" "${CMAKE_CURRENT_BINARY_DIR}/bar/"
#
# DOXYFILE_OUTPUT_DIR - Path where the Doxygen output is stored.
# Defaults to "${CMAKE_CURRENT_BINARY_DIR}/doc".
#
# DOXYFILE_LATEX - ON/OFF; Set to "ON" if you want the LaTeX documentation
# to be built.
# DOXYFILE_LATEX_DIR - Directory relative to DOXYFILE_OUTPUT_DIR where
# the Doxygen LaTeX output is stored. Defaults to "latex".
#
# DOXYFILE_HTML_DIR - Directory relative to DOXYFILE_OUTPUT_DIR where
# the Doxygen html output is stored. Defaults to "html".
#
#
# Copyright (c) 2009-2010 Tobias Rautenkranz <tobias@rautenkranz.ch>
# Copyright (c) 2010 Andreas Schneider <mail@cynapses.org>
# Copyright (c) 2009, 2010, 2011 Tobias Rautenkranz <tobias@rautenkranz.ch>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
macro(usedoxygen_set_default name value)
if(NOT DEFINED "${name}")
set("${name}" "${value}")
endif()
macro(usedoxygen_set_default name value type docstring)
if(NOT DEFINED "${name}")
set("${name}" "${value}" CACHE "${type}" "${docstring}")
endif()
endmacro()
find_package(Doxygen)
if(DOXYGEN_FOUND)
find_file(DOXYFILE_IN
NAMES
doxy.config.in
PATHS
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_ROOT}/Modules/
NO_DEFAULT_PATH)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(DOXYFILE_IN DEFAULT_MSG "DOXYFILE_IN")
find_file(DOXYFILE_IN "Doxyfile.in"
PATHS "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_ROOT}/Modules/"
NO_DEFAULT_PATH
DOC "Path to the doxygen configuration template file")
set(DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(DOXYFILE_IN DEFAULT_MSG "DOXYFILE_IN")
endif()
if(DOXYGEN_FOUND AND DOXYFILE_IN_FOUND)
add_custom_target(doxygen ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxy.config)
usedoxygen_set_default(DOXYFILE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/doc"
PATH "Doxygen output directory")
usedoxygen_set_default(DOXYFILE_HTML_DIR "html"
STRING "Doxygen HTML output directory")
usedoxygen_set_default(DOXYFILE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
PATH "Input files source directory")
usedoxygen_set_default(DOXYFILE_EXTRA_SOURCE_DIRS ""
STRING "Additional source files/directories separated by space")
set(DOXYFILE_SOURCE_DIRS "\"${DOXYFILE_SOURCE_DIR}\" ${DOXYFILE_EXTRA_SOURCES}")
usedoxygen_set_default(DOXYFILE_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
usedoxygen_set_default(DOXYFILE_HTML_DIR "html")
usedoxygen_set_default(DOXYFILE_LATEX YES BOOL "Generate LaTeX API documentation" OFF)
usedoxygen_set_default(DOXYFILE_LATEX_DIR "latex" STRING "LaTex output directory")
set_property(DIRECTORY APPEND PROPERTY
ADDITIONAL_MAKE_CLEAN_FILES "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_HTML_DIR}")
mark_as_advanced(DOXYFILE_OUTPUT_DIR DOXYFILE_HTML_DIR DOXYFILE_LATEX_DIR
DOXYFILE_SOURCE_DIR DOXYFILE_EXTRA_SOURCE_DIRS DOXYFILE_IN)
set(DOXYFILE_LATEX FALSE)
set(DOXYFILE_PDFLATEX FALSE)
set(DOXYFILE_DOT FALSE)
find_package(LATEX)
if(LATEX_COMPILER AND MAKEINDEX_COMPILER)
set(DOXYFILE_LATEX TRUE)
usedoxygen_set_default(DOXYFILE_LATEX_DIR "latex")
set_property(DIRECTORY
APPEND PROPERTY
ADDITIONAL_MAKE_CLEAN_FILES
"${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_HTML_DIR}")
set_property(DIRECTORY APPEND PROPERTY
ADDITIONAL_MAKE_CLEAN_FILES
"${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}")
add_custom_target(doxygen
COMMAND "${DOXYGEN_EXECUTABLE}"
"${DOXYFILE}"
COMMENT "Writing documentation to ${DOXYFILE_OUTPUT_DIR}..."
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
if(PDFLATEX_COMPILER)
set(DOXYFILE_PDFLATEX TRUE)
endif()
if(DOXYGEN_DOT_EXECUTABLE)
set(DOXYFILE_DOT TRUE)
endif()
set(DOXYFILE_DOT "NO")
if(DOXYGEN_DOT_EXECUTABLE)
set(DOXYFILE_DOT "YES")
endif()
add_custom_command(TARGET doxygen
POST_BUILD
COMMAND ${CMAKE_MAKE_PROGRAM}
WORKING_DIRECTORY "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}")
endif()
## LaTeX
set(DOXYFILE_PDFLATEX "NO")
configure_file(${DOXYFILE_IN} ${CMAKE_CURRENT_BINARY_DIR}/doxy.config ESCAPE_QUOTES IMMEDIATE @ONLY)
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/doxy.trac.in)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doxy.trac.in ${CMAKE_CURRENT_BINARY_DIR}/doxy.trac ESCAPE_QUOTES IMMEDIATE @ONLY)
add_custom_target(doxygen-trac ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxy.trac)
endif()
set_property(DIRECTORY APPEND PROPERTY
ADDITIONAL_MAKE_CLEAN_FILES
"${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}")
get_target_property(DOC_TARGET doc TYPE)
if(NOT DOC_TARGET)
add_custom_target(doc)
endif()
if(DOXYFILE_LATEX STREQUAL "ON")
set(DOXYFILE_GENERATE_LATEX "YES")
find_package(LATEX)
find_program(DOXYFILE_MAKE make)
mark_as_advanced(DOXYFILE_MAKE)
if(LATEX_COMPILER AND MAKEINDEX_COMPILER AND DOXYFILE_MAKE)
if(PDFLATEX_COMPILER)
set(DOXYFILE_PDFLATEX "YES")
endif()
add_dependencies(doc doxygen)
add_custom_command(TARGET doxygen
POST_BUILD
COMMAND "${DOXYFILE_MAKE}"
COMMENT "Running LaTeX for Doxygen documentation in ${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}..."
WORKING_DIRECTORY "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}")
else()
set(DOXYGEN_LATEX "NO")
endif()
else()
set(DOXYFILE_GENERATE_LATEX "NO")
endif()
configure_file("${DOXYFILE_IN}" "${DOXYFILE}" @ONLY)
add_custom_target(doc)
add_dependencies(doc doxygen)
endif()

View File

@@ -20,9 +20,18 @@
/* Define to 1 if you have the <pty.h> header file. */
#cmakedefine HAVE_PTY_H 1
/* Define to 1 if you have the <util.h> header file. */
#cmakedefine HAVE_UTIL_H 1
/* Define to 1 if you have the <sys/time.h> header file. */
#cmakedefine HAVE_SYS_TIME_H 1
/* Define to 1 if you have the <termios.h> header file. */
#cmakedefine HAVE_TERMIOS_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H 1
/* Define to 1 if you have the <openssl/aes.h> header file. */
#cmakedefine HAVE_OPENSSL_AES_H 1
@@ -35,9 +44,26 @@
/* Define to 1 if you have the <openssl/des.h> header file. */
#cmakedefine HAVE_OPENSSL_DES_H 1
/* Define to 1 if you have the <openssl/ecdh.h> header file. */
#cmakedefine HAVE_OPENSSL_ECDH_H 1
/* Define to 1 if you have the <openssl/ec.h> header file. */
#cmakedefine HAVE_OPENSSL_EC_H 1
/* Define to 1 if you have the <openssl/ecdsa.h> header file. */
#cmakedefine HAVE_OPENSSL_ECDSA_H 1
/* Define to 1 if you have the <pthread.h> header file. */
#cmakedefine HAVE_PTHREAD_H 1
/* Define to 1 if you have eliptic curve cryptography in openssl */
#cmakedefine HAVE_OPENSSL_ECC 1
/* Define to 1 if you have eliptic curve cryptography in gcrypt */
#cmakedefine HAVE_GCRYPT_ECC 1
/* Define to 1 if you have eliptic curve cryptography */
#cmakedefine HAVE_ECC 1
/*************************** FUNCTIONS ***************************/
@@ -59,6 +85,9 @@
/* Define to 1 if you have the `_vsnprintf_s' function. */
#cmakedefine HAVE__VSNPRINTF_S 1
/* Define to 1 if you have the `isblank' function. */
#cmakedefine HAVE_ISBLANK 1
/* Define to 1 if you have the `strncpy' function. */
#cmakedefine HAVE_STRNCPY 1
@@ -74,15 +103,24 @@
/* Define to 1 if you have the `select' function. */
#cmakedefine HAVE_SELECT 1
/* Define to 1 if you have the `regcomp' function. */
#cmakedefine HAVE_REGCOMP 1
/* Define to 1 if you have the `clock_gettime' function. */
#cmakedefine HAVE_CLOCK_GETTIME 1
/* Define to 1 if you have the `ntohll' function. */
#cmakedefine HAVE_NTOHLL 1
/* Define to 1 if you have the `htonll' function. */
#cmakedefine HAVE_HTONLL 1
/* Define to 1 if you have the `strtoull' function. */
#cmakedefine HAVE_STRTOULL 1
/* Define to 1 if you have the `__strtoull' function. */
#cmakedefine HAVE___STRTOULL 1
/* Define to 1 if you have the `_strtoui64' function. */
#cmakedefine HAVE__STRTOUI64 1
/*************************** LIBRARIES ***************************/
/* Define to 1 if you have the `crypto' library (-lcrypto). */
@@ -91,17 +129,24 @@
/* Define to 1 if you have the `gcrypt' library (-lgcrypt). */
#cmakedefine HAVE_LIBGCRYPT 1
/* Define to 1 if you have the `z' library (-lz). */
#cmakedefine HAVE_LIBZ 1
/* Define to 1 if you have the `pthread' library (-lpthread). */
#cmakedefine HAVE_PTHREAD 1
/**************************** OPTIONS ****************************/
#cmakedefine HAVE_GCC_THREAD_LOCAL_STORAGE 1
#cmakedefine HAVE_MSC_THREAD_LOCAL_STORAGE 1
#cmakedefine HAVE_GCC_VOLATILE_MEMORY_PROTECTION 1
#cmakedefine HAVE_COMPILER__FUNC__ 1
#cmakedefine HAVE_COMPILER__FUNCTION__ 1
/* Define to 1 if you want to enable GSSAPI */
#cmakedefine WITH_GSSAPI 1
/* Define to 1 if you want to enable ZLIB */
#cmakedefine WITH_LIBZ 1
#cmakedefine WITH_ZLIB 1
/* Define to 1 if you want to enable SFTP */
#cmakedefine WITH_SFTP 1
@@ -121,6 +166,9 @@
/* Define to 1 if you want to enable calltrace debug output */
#cmakedefine DEBUG_CALLTRACE 1
/* Define to 1 if you want to enable NaCl support */
#cmakedefine WITH_NACL 1
/*************************** ENDIAN *****************************/
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most

File diff suppressed because it is too large Load Diff

View File

@@ -1 +0,0 @@
<!-- Doxygen TracFooter -->

View File

@@ -1,4 +0,0 @@
<!-- Doxygen TracHeader -->
<style>@import url(/chrome/site/doxygen.css);</style>
<style>@import url(/chrome/site/tabs.css);</style>
<!-- /Doxygen TracHeader -->

View File

@@ -21,7 +21,7 @@ to read the abundant documentation on this topic to fully understand the
advantages and security risks linked to each method.
@subsection pubkeys Authenticating with public keys
@subsection pubkeys Authenticating with public keys
libssh is fully compatible with the openssh public and private keys. You
can either use the automatic public key authentication method provided by
@@ -40,22 +40,21 @@ The function ssh_userauth_autopubkey() does this using the available keys in
- SSH_AUTH_DENIED: no key matched
- SSH_AUTH_SUCCESS: you are now authenticated
- SSH_AUTH_PARTIAL: some key matched but you still have to provide an other
mean of authentication (like a password).
mean of authentication (like a password).
The ssh_userauth_autopubkey() function also tries to authenticate using the
The ssh_userauth_publickey_auto() function also tries to authenticate using the
SSH agent, if you have one running, or the "none" method otherwise.
If you wish to authenticate with public key by your own, follow these steps:
- Retrieve the public key in a ssh_string using publickey_from_file().
- Offer the public key to the SSH server using ssh_userauth_offer_pubkey().
- Retrieve the public key with ssh_import_pubkey_file().
- Offer the public key to the SSH server using ssh_userauth_try_publickey().
If the return value is SSH_AUTH_SUCCESS, the SSH server accepts to
authenticate using the public key and you can go to the next step.
- Retrieve the private key, using the privatekey_from_file() function. If
a passphrase is needed, either the passphrase specified as argument or
a callback (see callbacks section) will be used.
- Authenticate using ssh_userauth_pubkey() with your public key string
and private key.
- Do not forget cleaning up memory using string_free() and privatekey_free().
- Retrieve the private key, using the ssh_pki_import_privkey_file() function.
If a passphrase is needed, either the passphrase specified as argument or
a callback will be used.
- Authenticate using ssh_userauth_publickey() with your private key.
- Do not forget cleaning up memory using ssh_key_free().
Here is a minimalistic example of public key authentication:
@@ -64,7 +63,7 @@ int authenticate_pubkey(ssh_session session)
{
int rc;
rc = ssh_userauth_autopubkey(session, NULL);
rc = ssh_userauth_publickey_auto(session, NULL);
if (rc == SSH_AUTH_ERROR)
{
@@ -77,14 +76,12 @@ int authenticate_pubkey(ssh_session session)
}
@endcode
@see ssh_userauth_autopubkey
@see ssh_userauth_offer_pubkey
@see ssh_userauth_pubkey
@see publickey_from_file
@see publickey_from_privatekey
@see string_free
@see privatekey_from_file
@see privatekey_free
@see ssh_userauth_publickey_auto()
@see ssh_userauth_try_publickey()
@see ssh_userauth_publickey()
@see ssh_pki_import_pubkey_file()
@see ssh_pki_import_privkey_file()
@see ssh_key_free()
@subsection password Authenticating with a password
@@ -167,13 +164,13 @@ Here is a little note about how to use the information from
keyboard-interactive authentication, coming from the RFC itself (rfc4256):
@verbatim
3.3 User Interface Upon receiving a request message, the client SHOULD
prompt the user as follows: A command line interface (CLI) client SHOULD
print the name and instruction (if non-empty), adding newlines. Then for
each prompt in turn, the client SHOULD display the prompt and read the
user input.
A graphical user interface (GUI) client has many choices on how to prompt
the user. One possibility is to use the name field (possibly prefixed
with the application's name) as the title of a dialog window in which
@@ -184,18 +181,18 @@ keyboard-interactive authentication, coming from the RFC itself (rfc4256):
titles; it SHOULD instead find another way to display this information. If
prompts are presented in a dialog window, then the client SHOULD NOT
present each prompt in a separate window.
All clients MUST properly handle an instruction field with embedded
newlines. They SHOULD also be able to display at least 30 characters for
the name and prompts. If the server presents names or prompts longer than 30
characters, the client MAY truncate these fields to the length it can
display. If the client does truncate any fields, there MUST be an obvious
indication that such truncation has occured.
The instruction field SHOULD NOT be truncated. Clients SHOULD use control
character filtering as discussed in [SSH-ARCH] to avoid attacks by
including terminal control characters in the fields to be displayed.
For each prompt, the corresponding echo field indicates whether or not
the user input should be echoed as characters are typed. Clients SHOULD
correctly echo/mask user input for each prompt independently of other
@@ -265,10 +262,10 @@ int authenticate_kbdint(ssh_session session)
@endcode
@see ssh_userauth_kbdint()
@see ssh_userauth_kbdint_getnprompts
@see ssh_userauth_kbdint_getname
@see ssh_userauth_kbdint_getinstruction
@see ssh_userauth_kbdint_getprompt
@see ssh_userauth_kbdint_getnprompts()
@see ssh_userauth_kbdint_getname()
@see ssh_userauth_kbdint_getinstruction()
@see ssh_userauth_kbdint_getprompt()
@see ssh_userauth_kbdint_setanswer()
@@ -288,7 +285,7 @@ int authenticate_kbdint(ssh_session session)
{
int rc;
rc = ssh_userauth_none(session, NULL, NULL);
rc = ssh_userauth_none(session, NULL);
return rc;
}
@endcode
@@ -307,6 +304,11 @@ int test_several_auth_methods(ssh_session session)
{
int method, rc;
rc = ssh_userauth_none(session, NULL);
if (rc != SSH_AUTH_SUCCESS) {
return rc;
}
method = ssh_userauth_list(session, NULL);
if (method & SSH_AUTH_METHOD_NONE)

View File

@@ -0,0 +1,119 @@
curve25519-sha256@libssh.org.txt Aris Adamantiadis <aris@badcode.be>
21/9/2013
1. Introduction
This document describes the key exchange methode curve25519-sha256@libssh.org
for SSH version 2 protocol. It is provided as an alternative to the existing
key exchange mechanisms based on either Diffie-Hellman or Elliptic Curve Diffie-
Hellman [RFC5656].
The reason is the following : During summer of 2013, revelations from ex-
consultant at NSA Edward Snowden gave proof that NSA willingly inserts backdoors
into softwares, hardware components and published standards. While it is still
believed that the mathematics behind ECC cryptography are still sound and solid,
some people (including Bruce Schneier [SCHNEIER]), showed their lack of confidence
in NIST-published curves such as nistp256, nistp384, nistp521, for which constant
parameters (including the generator point) are defined without explanation. It
is also believed that NSA had a word to say in their definition. These curves
are not the most secure or fastest possible for their key sizes [DJB], and
researchers think it is possible that NSA have ways of cracking NIST curves.
It is also interesting to note that SSH belongs to the list of protocols the NSA
claims to be able to eavesdrop. Having a secure replacement would make passive
attacks much harder if such a backdoor exists.
However an alternative exists in the form of Curve25519. This algorithm has been
proposed in 2006 by DJB [Curve25519]. Its main stengths are its speed, its
constant-time run time (and resistance against side-channel attacks), and its
lack of nebulous hard-coded constants.
The reference version being used in this document is the one described in
[Curve25519] as implemented in the library NaCl [NaCl].
This document does not attempts to provide alternatives to the ecdsa-sha1-*
authentication keys.
2. Key exchange
The key exchange procedure is very similar to the one described chapter 4 of
[RFC5656]. Public ephemeral keys are transmitted over SSH encapsulated into
standard SSH strings.
The following is an overview of the key exchange process:
Client Server
------ ------
Generate ephemeral key pair.
SSH_MSG_KEX_ECDH_INIT -------->
Verify that client public key
length is 32 bytes.
Generate ephemeral key pair.
Compute shared secret.
Generate and sign exchange hash.
<-------- SSH_MSG_KEX_ECDH_REPLY
Verify that server public key length is 32 bytes.
* Verify host keys belong to server.
Compute shared secret.
Generate exchange hash.
Verify server's signature.
* Optional but strongly recommanded as this protects against MITM attacks.
This is implemented using the same messages as described in RFC5656 chapter 4
3. Method Name
The name of this key exchange method is "curve25519-sha256@libssh.org".
4. Implementation considerations
The whole method is based on the curve25519 scalar multiplication. In this
method, a private key is a scalar of 256 bits, and a public key is a point
of 256 bits.
4.1. Private key generation
A 32 bytes private key should be generated for each new connection,
using a secure PRNG. The following actions must be done on the private key:
mysecret[0] &= 248;
mysecret[31] &= 127;
mysecret[31] |= 64;
In order to keep the key valid. However, many cryptographic libraries will do
this automatically.
It should be noted that, in opposition to NIST curves, no special validation
should be done to ensure the result is a valid and secure private key.
4.2 Public key generation
The 32 bytes public key of either a client or a server must be generated using
the 32 bytes private key and a common generator base. This base is defined as 9
followed by all zeroes:
const unsigned char basepoint[32] = {9};
The public key is calculated using the cryptographic scalar multiplication:
const unsigned char privkey[32];
unsigned char pubkey[32];
crypto_scalarmult (pubkey, privkey, basepoint);
However some cryptographic libraries may provide a combined function:
crypto_scalarmult_base (pubkey, privkey);
It should be noted that, in opposition to NIST curves, no special validation
should be done to ensure the received public keys are valid curves point. The
Curve25519 algorithm ensure that every possible public key maps to a valid
ECC Point.
4.3 Shared secret generation
The shared secret, k, is defined in SSH specifications to be a big integer.
This number is calculated using the following procedure:
X is the 32 bytes point obtained by the scalar multiplication of the other
side's public key and the local private key scalar.
The whole 32 bytes of the number X are then converted into a big integer k.
This conversion follows the network byte order. This step differs from
RFC5656.
[RFC5656] http://tools.ietf.org/html/rfc5656
[SCHNEIER] https://www.schneier.com/blog/archives/2013/09/the_nsa_is_brea.html#c1675929
[DJB] http://cr.yp.to/talks/2013.05.31/slides-dan+tanja-20130531-4x3.pdf
[Curve25519] "Curve25519: new Diffie-Hellman speed records."
http://cr.yp.to/ecdh/curve25519-20060209.pdf

File diff suppressed because it is too large Load Diff

View File

@@ -85,7 +85,7 @@ this tutorial.
@subsection libssh_direct Doing direct port forwarding with libssh
To do direct port forwarding, call function channel_open_forward():
To do direct port forwarding, call function ssh_channel_open_forward():
- you need a separate channel for the tunnel as first parameter;
- second and third parameters are the remote endpoint;
- fourth and fifth parameters are sent to the remote server
@@ -106,11 +106,13 @@ int direct_forwarding(ssh_session session)
int nbytes, nwritten;
forwarding_channel = ssh_channel_new(session);
if (rc != SSH_OK) return rc;
if (forwarding_channel == NULL) {
return rc;
}
rc = channel_open_forward(forwarding_channel,
"www.google.com", 80,
"localhost", 5555);
rc = ssh_channel_open_forward(forwarding_channel,
"www.google.com", 80,
"localhost", 5555);
if (rc != SSH_OK)
{
ssh_channel_free(forwarding_channel);
@@ -118,7 +120,9 @@ int direct_forwarding(ssh_session session)
}
nbytes = strlen(http_get);
nwritten = channel_write(forwarding_channel, http_get, nbytes);
nwritten = ssh_channel_write(forwarding_channel,
http_get,
nbytes);
if (nbytes != nwritten)
{
ssh_channel_free(forwarding_channel);
@@ -140,10 +144,10 @@ or whatever use you have for it.
@subsection libssh_reverse Doing reverse port forwarding with libssh
To do reverse port forwarding, call ssh_channel_forward_listen(),
then ssh_channel_forward_accept().
To do reverse port forwarding, call ssh_forward_listen(),
then ssh_channel_accept_forward().
When you call ssh_channel_forward_listen(), you can let the remote server
When you call ssh_forward_listen(), you can let the remote server
chose the non-priviledged port it should listen to. Otherwise, you can chose
your own priviledged or non-priviledged port. Beware that you should have
administrative priviledges on the remote server to open a priviledged port
@@ -160,6 +164,7 @@ int web_server(ssh_session session)
ssh_channel channel;
char buffer[256];
int nbytes, nwritten;
int port;
char *helloworld = ""
"HTTP/1.1 200 OK\n"
"Content-Type: text/html\n"
@@ -174,17 +179,19 @@ int web_server(ssh_session session)
" </body>\n"
"</html>\n";
rc = ssh_channel_forward_listen(session, NULL, 8080, NULL);
rc = ssh_forward_listen(session, NULL, 8080, NULL);
if (rc != SSH_OK)
{
fprintf(stderr, "Error opening remote port: %s\n", ssh_get_error(session));
fprintf(stderr, "Error opening remote port: %s\n",
ssh_get_error(session));
return rc;
}
channel = ssh_channel_forward_accept(session, 60000);
channel = ssh_channel_accept_forward(session, 60000, &port);
if (channel == NULL)
{
fprintf(stderr, "Error waiting for incoming connection: %s\n", ssh_get_error(session));
fprintf(stderr, "Error waiting for incoming connection: %s\n",
ssh_get_error(session));
return SSH_ERROR;
}
@@ -193,7 +200,8 @@ int web_server(ssh_session session)
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
if (nbytes < 0)
{
fprintf(stderr, "Error reading incoming data: %s\n", ssh_get_error(session));
fprintf(stderr, "Error reading incoming data: %s\n",
ssh_get_error(session));
ssh_channel_send_eof(channel);
ssh_channel_free(channel);
return SSH_ERROR;
@@ -204,7 +212,8 @@ int web_server(ssh_session session)
nwritten = ssh_channel_write(channel, helloworld, nbytes);
if (nwritten != nbytes)
{
fprintf(stderr, "Error sending answer: %s\n", ssh_get_error(session));
fprintf(stderr, "Error sending answer: %s\n",
ssh_get_error(session));
ssh_channel_send_eof(channel);
ssh_channel_free(channel);
return SSH_ERROR;

View File

@@ -443,11 +443,10 @@ Most of time, the error returned are SSH_FATAL, but some functions
(generaly the ssh_request_xxx ones) may fail because of server denying request.
In these cases, SSH_REQUEST_DENIED is returned.
ssh_get_error() and ssh_get_error_code() take a ssh_session as a parameter.
That's for thread safety, error messages that can be attached to a session
aren't static anymore. Any error that happens during ssh_options_xxx()
or ssh_connect() (i.e., outside of any session) can be retrieved by
giving NULL as argument.
For thread safety, errors are bound to ssh_session objects.
As long as your ssh_session object is not NULL, you can retrieve the last error
message and error code from the ssh_session using ssh_get_error() and
ssh_get_error_code() respectively.
The SFTP subsystem has its own error codes, in addition to libssh ones.

View File

@@ -14,9 +14,8 @@ libssh is a Free Software / Open Source project. The libssh library
is distributed under LGPL license. The libssh project has nothing to do with
"libssh2", which is a completly different and independant project.
libssh can run on top of either libgcrypt (http://directory.fsf.org/project/libgcrypt/)
or libcrypto (http://www.openssl.org/docs/crypto/crypto.html), two general-purpose
cryptographic libraries.
libssh can run on top of either libgcrypt or libcrypto,
two general-purpose cryptographic libraries.
This tutorial concentrates for its main part on the "client" side of libssh.
To learn how to accept incoming SSH connexions (how to write a SSH server),

View File

@@ -17,8 +17,14 @@ On UNIX systems linking against the static version of the library is the
same as linking against the shared library. Both have the same name. Some
build system require to use the full path to the static library.
On Windows you need to define LIBSSH_STATIC in the compiler command
line. This is required cause the dynamic library needs to specify the
dllimport attribute.
To be able to compile the application you're developing you need to either pass
LIBSSH_STATIC as a define in the compiler command line or define it before you
include libssh.h. This is required cause the dynamic library needs to specify
the dllimport attribute.
@code
#define LIBSSH_STATIC 1
#include <libssh/libssh.h>
@endcode
*/

View File

@@ -19,41 +19,131 @@ the interesting functions as you go.
The libssh library provides:
- Full C library functions for manipulating a client-side SSH connection
- SSH2 and SSH1 protocol compliant
- Fully configurable sessions
- Server support
- SSH agent authentication support
- Support for AES-128, AES-192, AES-256, Blowfish, 3DES in CBC mode, and AES in CTR mode
- Supports OpenSSL and GCrypt
- Use multiple SSH connections in a same process, at same time
- Use multiple channels in the same connection
- Thread safety when using different sessions at same time
- POSIX-like SFTP (Secure File Transfer) implementation with openssh extension support
- SCP implementation
- Large file system support (files bigger than 4GB)
- RSA and DSS server public key supported
- Compression support (with zlib)
- Public key (RSA and DSS), password and keyboard-interactive authentication
- Full poll()/WSAPoll() support and a poll-emulation for Win32.
- Runs and tested under x86_64, x86, ARM, Sparc32, PPC under Linux, BSD, MacOSX, Solaris and Windows
- <strong>Key Exchange Methods</strong>: <i>ecdh-sha2-nistp256</i>, diffie-hellman-group1-sha1, diffie-hellman-group14-sha1
- <strong>Hostkey Types</strong>: <i>ecdsa-sha2-nistp256</i>, ssh-dss, ssh-rsa
- <strong>Ciphers</strong>: <i>aes256-ctr, aes192-ctr, aes128-ctr</i>, aes256-cbc (rijndael-cbc@lysator.liu.se), aes192-cbc, aes128-cbc, 3des-cbc, des-cbc-ssh1, blowfish-cbc, none
- <strong>Compression Schemes</strong>: zlib, <i>zlib@openssh.com</i>, none
- <strong>MAC hashes</strong>: hmac-sha1, none
- <strong>Authentication</strong>: none, password, public-key, hostbased, keyboard-interactive, <i>gssapi-with-mic</i>
- <strong>Channels</strong>: shell, exec (incl. SCP wrapper), direct-tcpip, subsystem, <i>auth-agent-req@openssh.com</i>
- <strong>Global Requests</strong>: tcpip-forward, forwarded-tcpip
- <strong>Channel Requests</strong>: x11, pty, <i>exit-status, signal, exit-signal, keepalive@openssh.com, auth-agent-req@openssh.com</i>
- <strong>Subsystems</strong>: sftp(version 3), publickey(version 2), <i>OpenSSH Extensions</i>
- <strong>SFTP</strong>: <i>statvfs@openssh.com, fstatvfs@openssh.com</i>
- <strong>Thread-safe</strong>: Just don't share sessions
- <strong>Non-blocking</strong>: it can be used both blocking and non-blocking
- <strong>Your sockets</strong>: the app hands over the socket, or uses libssh sockets
- <b>OpenSSL</b> or <b>gcrypt</b>: builds with either
@section main-additional-features Additional Features
- Client <b>and</b> server support
- SSHv2 and SSHv1 protocol support
- Supports <a href="http://test.libssh.org/" target="_blank">Linux, UNIX, BSD, Solaris, OS/2 and Windows</a>
- Automated test cases with nightly <a href="http://test.libssh.org/" target="_blank">tests</a>
- Event model based on poll(2), or a poll(2)-emulation.
@section main-copyright Copyright Policy
The developers of libssh have a policy of asking for contributions to be made
under the personal copyright of the contributor, instead of a corporate
copyright.
libssh is a project with distributed copyright ownership, which means we prefer
the copyright on parts of libssh to be held by individuals rather than
corporations if possible. There are historical legal reasons for this, but one
of the best ways to explain it is that its much easier to work with
individuals who have ownership than corporate legal departments if we ever need
to make reasonable compromises with people using and working with libssh.
There are some reasons for the establishment of this policy:
We track the ownership of every part of libssh via git, our source code control
system, so we know the provenance of every piece of code that is committed to
libssh.
@li Individual copyrights make copyright registration in the US a simpler
process.
@li If libssh is copyrighted by individuals rather than corporations,
decisions regarding enforcement and protection of copyright will, more
likely, be made in the interests of the project, and not in the interests
of any corporations shareholders.
@li If we ever need to relicense a portion of the code contacting individuals
for permission to do so is much easier than contacting a company.
So if possible, if youre doing libssh changes on behalf of a company who
normally owns all the work you do please get them to assign personal copyright
ownership of your changes to you as an individual, that makes things very easy
for us to work with and avoids bringing corporate legal departments into the
picture.
If you cant do this we can still accept patches from you owned by your
employer under a standard employment contract with corporate copyright
ownership. It just requires a simple set-up process first.
We use a process very similar to the way things are done in the Linux Kernel
community, so it should be very easy to get a sign off from your corporate
legal department. The only changes weve made are to accommodate the license we
use, which is LGPLv2 (or later) whereas the Linux kernel uses GPLv2.
The process is called signing.
How to sign your work
----------------------
Once you have permission to contribute to libssh from your employer, simply
email a copy of the following text from your corporate email address to:
contributing@libssh.org
@verbatim
libssh Developer's Certificate of Origin. Version 1.0
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the appropriate
version of the GNU General Public License; or
(b) The contribution is based upon previous work that, to the best of
my knowledge, is covered under an appropriate open source license
and I have the right under that license to submit that work with
modifications, whether created in whole or in part by me, under
the GNU General Public License, in the appropriate version; or
(c) The contribution was provided directly to me by some other
person who certified (a) or (b) and I have not modified it.
(d) I understand and agree that this project and the contribution are
public and that a record of the contribution (including all
metadata and personal information I submit with it, including my
sign-off) is maintained indefinitely and may be redistributed
consistent with the libssh Team's policies and the requirements of
the GNU GPL where they are relevant.
(e) I am granting this work to this project under the terms of the
GNU Lesser General Public License as published by the
Free Software Foundation; either version 2.1 of
the License, or (at the option of the project) any later version.
http://www.gnu.org/licenses/lgpl-2.1.html
@endverbatim
We will maintain a copy of that email as a record that you have the rights to
contribute code to libssh under the required licenses whilst working for the
company where the email came from.
Then when sending in a patch via the normal mechanisms described above, add a
line that states:
@verbatim
Signed-off-by: Random J Developer <random@developer.example.org>
@endverbatim
using your real name and the email address you sent the original email you used
to send the libssh Developers Certificate of Origin to us (sorry, no
pseudonyms or anonymous contributions.)
Thats it! Such code can then quite happily contain changes that have copyright
messages such as:
@verbatim
(c) Example Corporation.
@endverbatim
and can be merged into the libssh codebase in the same way as patches from any
other individual. You dont need to send in a copy of the libssh Developers
Certificate of Origin for each patch, or inside each patch. Just the sign-off
message is all that is required once weve received the initial email.
Have fun and happy libssh hacking!
The libssh Team
@section main-rfc Internet standard
@@ -120,5 +210,7 @@ them like the statvfs calls in SFTP or the ssh-agent.
OpenSSH's deviations and extensions</a>
- <a href="http://api.libssh.org/rfc/PROTOCOL.agent" target="_blank">
OpenSSH's ssh-agent</a>
- <a href="http://api.libssh.org/rfc/PROTOCOL.certkeys" target="_blank">
OpenSSH's pubkey certificate authentication</a>
*/

View File

@@ -39,14 +39,16 @@ int scp_write(ssh_session session)
(session, SSH_SCP_WRITE | SSH_SCP_RECURSIVE, ".");
if (scp == NULL)
{
fprintf(stderr, "Error allocating scp session: %s\n", ssh_get_error(session));
fprintf(stderr, "Error allocating scp session: %s\n",
ssh_get_error(session));
return SSH_ERROR;
}
rc = ssh_scp_init(scp);
if (rc != SSH_OK)
{
fprintf(stderr, "Error initializing scp session: %s\n", ssh_get_error(session));
fprintf(stderr, "Error initializing scp session: %s\n",
ssh_get_error(session));
ssh_scp_free(scp);
return rc;
}
@@ -71,14 +73,16 @@ int scp_read(ssh_session session)
(session, SSH_SCP_READ, "helloworld/helloworld.txt");
if (scp == NULL)
{
fprintf(stderr, "Error allocating scp session: %s\n", ssh_get_error(session));
fprintf(stderr, "Error allocating scp session: %s\n",
ssh_get_error(session));
return SSH_ERROR;
}
rc = ssh_scp_init(scp);
if (rc != SSH_OK)
{
fprintf(stderr, "Error initializing scp session: %s\n", ssh_get_error(session));
fprintf(stderr, "Error initializing scp session: %s\n",
ssh_get_error(session));
ssh_scp_free(scp);
return rc;
}
@@ -119,7 +123,8 @@ int scp_helloworld(ssh_session session, ssh_scp scp)
rc = ssh_scp_push_directory(scp, "helloworld", S_IRWXU);
if (rc != SSH_OK)
{
fprintf(stderr, "Can't create remote directory: %s\n", ssh_get_error(session));
fprintf(stderr, "Can't create remote directory: %s\n",
ssh_get_error(session));
return rc;
}
@@ -127,14 +132,16 @@ int scp_helloworld(ssh_session session, ssh_scp scp)
(scp, "helloworld.txt", length, S_IRUSR | S_IWUSR);
if (rc != SSH_OK)
{
fprintf(stderr, "Can't open remote file: %s\n", ssh_get_error(session));
fprintf(stderr, "Can't open remote file: %s\n",
ssh_get_error(session));
return rc;
}
rc = ssh_scp_write(scp, helloworld, length);
if (rc != SSH_OK)
{
fprintf(stderr, "Can't write to remote file: %s\n", ssh_get_error(session));
fprintf(stderr, "Can't write to remote file: %s\n",
ssh_get_error(session));
return rc;
}
@@ -195,14 +202,16 @@ int scp_receive(ssh_session session, ssh_scp scp)
rc = ssh_scp_pull_request(scp);
if (rc != SSH_SCP_REQUEST_NEWFILE)
{
fprintf(stderr, "Error receiving information about file: %s\n", ssh_get_error(session));
fprintf(stderr, "Error receiving information about file: %s\n",
ssh_get_error(session));
return SSH_ERROR;
}
size = ssh_scp_request_get_size(scp);
filename = strdup(ssh_scp_request_get_filename(scp));
mode = ssh_scp_request_get_permissions(scp);
printf("Receiving file %s, size %d, permisssions 0%o\n", filename, size, mode);
printf("Receiving file %s, size %d, permisssions 0%o\n",
filename, size, mode);
free(filename);
buffer = malloc(size);
@@ -216,7 +225,8 @@ int scp_receive(ssh_session session, ssh_scp scp)
rc = ssh_scp_read(scp, buffer, size);
if (rc == SSH_ERROR)
{
fprintf(stderr, "Error receiving file data: %s\n", ssh_get_error(session));
fprintf(stderr, "Error receiving file data: %s\n",
ssh_get_error(session));
free(buffer);
return rc;
}
@@ -228,7 +238,8 @@ int scp_receive(ssh_session session, ssh_scp scp)
rc = ssh_scp_pull_request(scp);
if (rc != SSH_SCP_REQUEST_EOF)
{
fprintf(stderr, "Unexpected request: %s\n", ssh_get_error(session));
fprintf(stderr, "Unexpected request: %s\n",
ssh_get_error(session));
return SSH_ERROR;
}

View File

@@ -53,14 +53,16 @@ int sftp_helloworld(ssh_session session)
sftp = sftp_new(session);
if (sftp == NULL)
{
fprintf(stderr, "Error allocating SFTP session: %s\n", ssh_get_error(session));
fprintf(stderr, "Error allocating SFTP session: %s\n",
ssh_get_error(session));
return SSH_ERROR;
}
rc = sftp_init(sftp);
if (rc != SSH_OK)
{
fprintf(stderr, "Error initializing SFTP session: %s.\n", sftp_get_error(sftp));
fprintf(stderr, "Error initializing SFTP session: %s.\n",
sftp_get_error(sftp));
sftp_free(sftp);
return rc;
}
@@ -121,7 +123,8 @@ int sftp_helloworld(ssh_session session, sftp_session sftp)
{
if (sftp_get_error(sftp) != SSH_FX_FILE_ALREADY_EXISTS)
{
fprintf(stderr, "Can't create directory: %s\n", ssh_get_error(session));
fprintf(stderr, "Can't create directory: %s\n",
ssh_get_error(session));
return rc;
}
}
@@ -167,17 +170,20 @@ int sftp_helloworld(ssh_session session, sftp_session sftp)
...
file = sftp_open(sftp, "helloworld/helloworld.txt", access_type, S_IRWXU);
file = sftp_open(sftp, "helloworld/helloworld.txt",
access_type, S_IRWXU);
if (file == NULL)
{
fprintf(stderr, "Can't open file for writing: %s\n", ssh_get_error(session));
fprintf(stderr, "Can't open file for writing: %s\n",
ssh_get_error(session));
return SSH_ERROR;
}
nwritten = sftp_write(file, helloworld, length);
if (nwritten != length)
{
fprintf(stderr, "Can't write data to file: %s\n", ssh_get_error(session));
fprintf(stderr, "Can't write data to file: %s\n",
ssh_get_error(session));
sftp_close(file);
return SSH_ERROR;
}
@@ -185,7 +191,8 @@ int sftp_helloworld(ssh_session session, sftp_session sftp)
rc = sftp_close(file);
if (rc != SSH_OK)
{
fprintf(stderr, "Can't close the written file: %s\n", ssh_get_error(session));
fprintf(stderr, "Can't close the written file: %s\n",
ssh_get_error(session));
return rc;
}
@@ -203,48 +210,63 @@ results to come.
Synchronous read is done with sftp_read().
The following example prints the contents of remote file "/etc/profile". For
each 1024 bytes of information read, it waits until the end of the read operation:
Files are normally transferred in chunks. A good chunk size is 16 KB. The following
example transfers the remote file "/etc/profile" in 16 KB chunks. For each chunk we
request, sftp_read blocks till the data has been received:
@code
// Good chunk size
#define MAX_XFER_BUF_SIZE 16384
int sftp_read_sync(ssh_session session, sftp_session sftp)
{
int access_type;
sftp_file file;
char buffer[1024];
int nbytes, rc;
char buffer[MAX_XFER_BUF_SIZE];
int nbytes, nwritten, rc;
int fd;
access_type = O_RDONLY;
file = sftp_open(sftp, "/etc/profile", access_type, 0);
if (file == NULL)
{
fprintf(stderr, "Can't open file for reading: %s\n", ssh_get_error(session));
return SSH_ERROR;
}
nbytes = sftp_read(file, buffer, sizeof(buffer));
while (nbytes > 0)
{
if (write(1, buffer, nbytes) != nbytes)
{
sftp_close(file);
file = sftp_open(sftp, "/etc/profile",
access_type, 0);
if (file == NULL) {
fprintf(stderr, "Can't open file for reading: %s\n",
ssh_get_error(session));
return SSH_ERROR;
}
nbytes = sftp_read(file, buffer, sizeof(buffer));
}
if (nbytes < 0)
{
fprintf(stderr, "Error while reading file: %s\n", ssh_get_error(session));
sftp_close(file);
return SSH_ERROR;
fd = open("/path/to/profile", O_CREAT);
if (fd < 0) {
fprintf(stderr, "Can't open file for writing: %s\n",
strerror(errno));
return SSH_ERROR;
}
for (;;) {
nbytes = sftp_read(file, buffer, sizeof(buffer));
if (nbytes == 0) {
break; // EOF
} else if (nbytes < 0) {
fprintf(stderr, "Error while reading file: %s\n",
ssh_get_error(session));
sftp_close(file);
return SSH_ERROR;
}
nwritten = write(fd, buf, nbytes);
if (nwritten != nbytes) {
fprintf(stderr, "Error writing: %s\n",
strerror(errno));
sftp_close(file);
return SSH_ERROR;
}
}
rc = sftp_close(file);
if (rc != SSH_OK)
{
fprintf(stderr, "Can't close the read file: %s\n", ssh_get_error(session));
return rc;
if (rc != SSH_OK) {
fprintf(stderr, "Can't close the read file: %s\n",
ssh_get_error(session));
return rc;
}
return SSH_OK;
@@ -263,21 +285,25 @@ The example below reads a very big file in asynchronous, nonblocking, mode. Each
time the data are not ready yet, a counter is incrementer.
@code
// Good chunk size
#define MAX_XFER_BUF_SIZE 16384
int sftp_read_async(ssh_session session, sftp_session sftp)
{
int access_type;
sftp_file file;
char buffer[1024];
char buffer[MAX_XFER_BUF_SIZE];
int async_request;
int nbytes;
long counter;
int rc;
access_type = O_RDONLY;
file = sftp_open(sftp, "some_very_big_file", access_type, 0);
if (file == NULL)
{
fprintf(stderr, "Can't open file for reading: %s\n", ssh_get_error(session));
file = sftp_open(sftp, "some_very_big_file",
access_type, 0);
if (file == NULL) {
fprintf(stderr, "Can't open file for reading: %s\n",
ssh_get_error(session));
return SSH_ERROR;
}
sftp_file_set_nonblocking(file);
@@ -285,26 +311,33 @@ int sftp_read_async(ssh_session session, sftp_session sftp)
async_request = sftp_async_read_begin(file, sizeof(buffer));
counter = 0L;
usleep(10000);
if (async_request >= 0)
nbytes = sftp_async_read(file, buffer, sizeof(buffer), async_request);
else nbytes = -1;
while (nbytes > 0 || nbytes == SSH_AGAIN)
{
if (nbytes > 0)
{
write(1, buffer, nbytes);
async_request = sftp_async_read_begin(file, sizeof(buffer));
}
else counter++;
usleep(10000);
if (async_request >= 0)
nbytes = sftp_async_read(file, buffer, sizeof(buffer), async_request);
else nbytes = -1;
if (async_request >= 0) {
nbytes = sftp_async_read(file, buffer, sizeof(buffer),
async_request);
} else {
nbytes = -1;
}
if (nbytes < 0)
{
fprintf(stderr, "Error while reading file: %s\n", ssh_get_error(session));
while (nbytes > 0 || nbytes == SSH_AGAIN) {
if (nbytes > 0) {
write(1, buffer, nbytes);
async_request = sftp_async_read_begin(file, sizeof(buffer));
} else {
counter++;
}
usleep(10000);
if (async_request >= 0) {
nbytes = sftp_async_read(file, buffer, sizeof(buffer),
async_request);
} else {
nbytes = -1;
}
}
if (nbytes < 0) {
fprintf(stderr, "Error while reading file: %s\n",
ssh_get_error(session));
sftp_close(file);
return SSH_ERROR;
}
@@ -312,9 +345,9 @@ int sftp_read_async(ssh_session session, sftp_session sftp)
printf("The counter has reached value: %ld\n", counter);
rc = sftp_close(file);
if (rc != SSH_OK)
{
fprintf(stderr, "Can't close the read file: %s\n", ssh_get_error(session));
if (rc != SSH_OK) {
fprintf(stderr, "Can't close the read file: %s\n",
ssh_get_error(session));
return rc;
}
@@ -356,15 +389,16 @@ int sftp_list_dir(ssh_session session, sftp_session sftp)
dir = sftp_opendir(sftp, "/var/log");
if (!dir)
{
fprintf(stderr, "Directory not opened: %s\n", ssh_get_error(session));
fprintf(stderr, "Directory not opened: %s\n",
ssh_get_error(session));
return SSH_ERROR;
}
printf("Name Size Perms Owner\tGroup\n");
printf("Name Size Perms Owner\tGroup\n");
while ((attributes = sftp_readdir(sftp, dir)) != NULL)
{
printf("%-22s %10llu %.8o %s(%d)\t%s(%d)\n",
printf("%-20s %10llu %.8o %s(%d)\t%s(%d)\n",
attributes->name,
(long long unsigned int) attributes->size,
attributes->permissions,
@@ -378,7 +412,8 @@ int sftp_list_dir(ssh_session session, sftp_session sftp)
if (!sftp_dir_eof(dir))
{
fprintf(stderr, "Can't list directory: %s\n", ssh_get_error(session));
fprintf(stderr, "Can't list directory: %s\n",
ssh_get_error(session));
sftp_closedir(dir);
return SSH_ERROR;
}
@@ -386,7 +421,8 @@ int sftp_list_dir(ssh_session session, sftp_session sftp)
rc = sftp_closedir(dir);
if (rc != SSH_OK)
{
fprintf(stderr, "Can't close directory: %s\n", ssh_get_error(session));
fprintf(stderr, "Can't close directory: %s\n",
ssh_get_error(session));
return rc;
}
}

View File

@@ -6,16 +6,16 @@ libssh may be used in multithreaded applications, but under several conditions :
- Threading must be initialized during the initialization of libssh. This
initialization must be done outside of any threading context.
- If pthreads is being used by your application (or your framework's backend),
you must link with libssh_threads_pthread dynamic library and initialize
you must link with libssh_threads dynamic library and initialize
threading with the ssh_threads_pthreads threading object.
- If an other threading library is being used by your application, you must
implement all the methods of the ssh_threads_callbacks_struct structure
and initialize libssh with it.
- At all times, you may use different sessions inside threads, make parallel
connections, read/write on different sessions and so on. You can use a
single session in several channels at the same time. This will lead to
internal state corruption. This limitation is being worked out and will
maybe disappear later.
connections, read/write on different sessions and so on. You *cannot* use a
single session (or channels for a single session) in several threads at the same
time. This will most likely lead to internal state corruption. This limitation is
being worked out and will maybe disappear later.
@subsection threads_init Initialization of threads
@@ -25,7 +25,7 @@ use, using ssh_threads_set_callbacks(), then call ssh_init().
@code
#include <libssh/callbacks.h>
...
ssh_threads_set_callbacks(ssh_threads_noop);
ssh_threads_set_callbacks(ssh_threads_get_noop());
ssh_init();
@endcode
@@ -40,14 +40,14 @@ threading backend:
@code
#include <libssh/callbacks.h>
...
ssh_threads_set_callbacks(ssh_threads_pthread);
ssh_threads_set_callbacks(ssh_threads_get_pthread());
ssh_init();
@endcode
However, you must be sure to link with the library ssh_threads_pthread. If
However, you must be sure to link with the library ssh_threads. If
you're using gcc, you must use the commandline
@code
gcc -o output input.c -lssh -lssh_threads_pthread
gcc -o output input.c -lssh -lssh_threads
@endcode
@@ -61,5 +61,6 @@ implement the following methods :
- mutex_destroy
- thread_id
libgcrypt 1.6 and bigger backend does not support custom callback. Using anything else than pthreads (ssh_threads_get_pthread()) here will fail.
Good luck !
*/

View File

@@ -11,29 +11,52 @@ include_directories(
${CMAKE_BINARY_DIR}
)
if (LINUX)
if (BSD OR SOLARIS OR OSX)
find_package(Argp)
endif (BSD OR SOLARIS OR OSX)
if (UNIX AND NOT WIN32)
add_executable(libssh_scp libssh_scp.c ${examples_SRCS})
target_link_libraries(libssh_scp ${LIBSSH_SHARED_LIBRARY})
add_executable(scp_download scp_download.c ${examples_SRCS})
target_link_libraries(scp_download ${LIBSSH_SHARED_LIBRARY})
add_executable(samplessh sample.c ${examples_SRCS})
target_link_libraries(samplessh ${LIBSSH_SHARED_LIBRARY})
add_executable(sshnetcat sshnetcat.c ${examples_SRCS})
target_link_libraries(sshnetcat ${LIBSSH_SHARED_LIBRARY})
if (WITH_SERVER)
if (HAVE_LIBUTIL)
add_executable(samplesshd-tty samplesshd-tty.c)
target_link_libraries(samplesshd-tty ${LIBSSH_SHARED_LIBRARY} ${ARGP_LIBRARIES} util)
endif (HAVE_LIBUTIL)
endif (WITH_SERVER)
if (WITH_SFTP)
add_executable(samplesftp samplesftp.c ${examples_SRCS})
target_link_libraries(samplesftp ${LIBSSH_SHARED_LIBRARY})
endif (WITH_SFTP)
add_executable(samplessh sample.c ${examples_SRCS})
target_link_libraries(samplessh ${LIBSSH_SHARED_LIBRARY})
if (WITH_SERVER)
add_executable(samplesshd samplesshd.c)
target_link_libraries(samplesshd ${LIBSSH_SHARED_LIBRARY})
target_link_libraries(samplesshd ${LIBSSH_SHARED_LIBRARY} ${ARGP_LIBRARIES})
if (WITH_GSSAPI AND GSSAPI_FOUND)
add_executable(samplesshd-cb samplesshd-cb.c)
target_link_libraries(samplesshd-cb ${LIBSSH_SHARED_LIBRARY} ${ARGP_LIBRARIES})
add_executable(proxy proxy.c)
target_link_libraries(proxy ${LIBSSH_SHARED_LIBRARY} ${ARGP_LIBRARIES})
endif (WITH_GSSAPI AND GSSAPI_FOUND)
add_executable(samplesshd-kbdint samplesshd-kbdint.c)
target_link_libraries(samplesshd-kbdint ${LIBSSH_SHARED_LIBRARY} ${ARGP_LIBRARIES})
endif (WITH_SERVER)
endif (LINUX)
endif (UNIX AND NOT WIN32)
add_executable(exec exec.c ${examples_SRCS})
target_link_libraries(exec ${LIBSSH_SHARED_LIBRARY})

View File

@@ -86,7 +86,9 @@ int authenticate_kbdint(ssh_session session, const char *password) {
}
answer = buffer;
}
if (ssh_userauth_kbdint_setanswer(session, i, answer) < 0) {
err = ssh_userauth_kbdint_setanswer(session, i, answer);
memset(buffer, 0, sizeof(buffer));
if (err < 0) {
return SSH_AUTH_ERROR;
}
}
@@ -116,6 +118,15 @@ int authenticate_console(ssh_session session){
method = ssh_auth_list(session);
while (rc != SSH_AUTH_SUCCESS) {
if (method & SSH_AUTH_METHOD_GSSAPI_MIC){
rc = ssh_userauth_gssapi(session);
if(rc == SSH_AUTH_ERROR) {
error(session);
return rc;
} else if (rc == SSH_AUTH_SUCCESS) {
break;
}
}
// Try to authenticate with public key first
if (method & SSH_AUTH_METHOD_PUBLICKEY) {
rc = ssh_userauth_autopubkey(session, NULL);
@@ -152,6 +163,7 @@ int authenticate_console(ssh_session session){
break;
}
}
memset(password, 0, sizeof(password));
}
banner = ssh_get_issue_banner(session);

View File

@@ -34,14 +34,26 @@ int verify_knownhost(ssh_session session){
int state;
char buf[10];
unsigned char *hash = NULL;
int hlen;
size_t hlen;
ssh_key srv_pubkey;
int rc;
state=ssh_is_server_known(session);
hlen = ssh_get_pubkey_hash(session, &hash);
if (hlen < 0) {
return -1;
rc = ssh_get_publickey(session, &srv_pubkey);
if (rc < 0) {
return -1;
}
rc = ssh_get_publickey_hash(srv_pubkey,
SSH_PUBLICKEY_HASH_SHA1,
&hash,
&hlen);
ssh_key_free(srv_pubkey);
if (rc < 0) {
return -1;
}
switch(state){
case SSH_SERVER_KNOWN_OK:
break; /* ok */

View File

@@ -22,10 +22,10 @@ program.
#include <libssh/libssh.h>
#include "examples_common.h"
char **sources;
int nsources;
char *destination;
int verbosity=0;
static char **sources;
static int nsources;
static char *destination;
static int verbosity=0;
struct location {
int is_ssh;
@@ -84,9 +84,15 @@ static int opts(int argc, char **argv){
}
static struct location *parse_location(char *loc){
struct location *location=malloc(sizeof(struct location));
struct location *location;
char *ptr;
location = malloc(sizeof(struct location));
if (location == NULL) {
return NULL;
}
memset(location, 0, sizeof(struct location));
location->host=location->user=NULL;
ptr=strchr(loc,':');
if(ptr != NULL){
@@ -123,6 +129,7 @@ static int open_location(struct location *loc, int flag){
if(ssh_scp_init(loc->scp)==SSH_ERROR){
fprintf(stderr,"error : %s\n",ssh_get_error(loc->session));
ssh_scp_free(loc->scp);
loc->scp = NULL;
return -1;
}
return 0;
@@ -140,6 +147,7 @@ static int open_location(struct location *loc, int flag){
if(ssh_scp_init(loc->scp)==SSH_ERROR){
fprintf(stderr,"error : %s\n",ssh_get_error(loc->session));
ssh_scp_free(loc->scp);
loc->scp = NULL;
return -1;
}
return 0;
@@ -174,13 +182,20 @@ static int do_copy(struct location *src, struct location *dest, int recursive){
char buffer[16384];
int total=0;
int mode;
char *filename;
char *filename = NULL;
/* recursive mode doesn't work yet */
(void)recursive;
/* Get the file name and size*/
if(!src->is_ssh){
fd=fileno(src->file);
fstat(fd,&s);
fd = fileno(src->file);
if (fd < 0) {
fprintf(stderr, "Invalid file pointer, error: %s\n", strerror(errno));
return -1;
}
r = fstat(fd, &s);
if (r < 0) {
return -1;
}
size=s.st_size;
mode = s.st_mode & ~S_IFMT;
filename=ssh_basename(src->path);
@@ -201,6 +216,7 @@ static int do_copy(struct location *src, struct location *dest, int recursive){
}
if(r==SSH_ERROR){
fprintf(stderr,"Error: %s\n",ssh_get_error(src->session));
ssh_string_free_char(filename);
return -1;
}
} while(r != SSH_SCP_REQUEST_NEWFILE);
@@ -211,6 +227,7 @@ static int do_copy(struct location *src, struct location *dest, int recursive){
// snprintf(buffer,sizeof(buffer),"C0644 %d %s\n",size,src->path);
if(r==SSH_ERROR){
fprintf(stderr,"error: %s\n",ssh_get_error(dest->session));
ssh_string_free_char(filename);
ssh_scp_free(dest->scp);
return -1;
}
@@ -221,6 +238,7 @@ static int do_copy(struct location *src, struct location *dest, int recursive){
fprintf(stderr,"Cannot open %s for writing: %s\n",filename,strerror(errno));
if(src->is_ssh)
ssh_scp_deny_request(src->scp,"Cannot open local file");
ssh_string_free_char(filename);
return -1;
}
}
@@ -233,6 +251,7 @@ static int do_copy(struct location *src, struct location *dest, int recursive){
r=ssh_scp_read(src->scp,buffer,sizeof(buffer));
if(r==SSH_ERROR){
fprintf(stderr,"Error reading scp: %s\n",ssh_get_error(src->session));
ssh_string_free_char(filename);
return -1;
}
if(r==0)
@@ -243,6 +262,7 @@ static int do_copy(struct location *src, struct location *dest, int recursive){
break;
if(r<0){
fprintf(stderr,"Error reading file: %s\n",strerror(errno));
ssh_string_free_char(filename);
return -1;
}
}
@@ -252,18 +272,21 @@ static int do_copy(struct location *src, struct location *dest, int recursive){
fprintf(stderr,"Error writing in scp: %s\n",ssh_get_error(dest->session));
ssh_scp_free(dest->scp);
dest->scp=NULL;
ssh_string_free_char(filename);
return -1;
}
} else {
w=fwrite(buffer,r,1,dest->file);
if(w<=0){
fprintf(stderr,"Error writing in local file: %s\n",strerror(errno));
ssh_string_free_char(filename);
return -1;
}
}
total+=r;
} while(total < size);
ssh_string_free_char(filename);
printf("wrote %d bytes\n",total);
return 0;
}
@@ -286,7 +309,7 @@ int main(int argc, char **argv){
break;
}
}
if(dest->is_ssh){
if (dest->is_ssh && dest->scp != NULL) {
r=ssh_scp_close(dest->scp);
if(r == SSH_ERROR){
fprintf(stderr,"Error closing scp: %s\n",ssh_get_error(dest->session));

View File

@@ -23,7 +23,7 @@ int main(int argc, const char **argv){
else
session.setOption(SSH_OPTIONS_HOST,"localhost");
session.connect();
session.userauthAutopubkey();
session.userauthPublickeyAuto();
session.disconnect();
} catch (ssh::SshException e){
std::cout << "Error during connection : ";

View File

@@ -29,7 +29,7 @@ int main(int argc, const char **argv){
err=session.connect();
if(err==SSH_ERROR)
goto error;
err=session.userauthAutopubkey();
err=session.userauthPublickeyAuto();
if(err==SSH_ERROR)
goto error;

347
examples/proxy.c Normal file
View File

@@ -0,0 +1,347 @@
/* This is a sample implementation of a libssh based SSH proxy */
/*
Copyright 2003-2013 Aris Adamantiadis
This file is part of the SSH Library
You are free to copy this file, modify it in any way, consider it being public
domain. This does not apply to the rest of the library though, but it is
allowed to cut-and-paste working code from this file to any license of
program.
The goal is to show the API in action. It's not a reference on how terminal
clients must be made or how a client should react.
*/
#include "config.h"
#include <libssh/libssh.h>
#include <libssh/server.h>
#include <libssh/callbacks.h>
#ifdef HAVE_ARGP_H
#include <argp.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define USER "myuser"
#define PASSWORD "mypassword"
static int authenticated=0;
static int tries = 0;
static int error = 0;
static ssh_channel chan=NULL;
static char *username;
static ssh_gssapi_creds client_creds = NULL;
static int auth_password(ssh_session session, const char *user,
const char *password, void *userdata){
(void)userdata;
printf("Authenticating user %s pwd %s\n",user, password);
if(strcmp(user,USER) == 0 && strcmp(password, PASSWORD) == 0){
authenticated = 1;
printf("Authenticated\n");
return SSH_AUTH_SUCCESS;
}
if (tries >= 3){
printf("Too many authentication tries\n");
ssh_disconnect(session);
error = 1;
return SSH_AUTH_DENIED;
}
tries++;
return SSH_AUTH_DENIED;
}
static int auth_gssapi_mic(ssh_session session, const char *user, const char *principal, void *userdata){
(void)userdata;
client_creds = ssh_gssapi_get_creds(session);
printf("Authenticating user %s with gssapi principal %s\n",user, principal);
if (client_creds != NULL)
printf("Received some gssapi credentials\n");
else
printf("Not received any forwardable creds\n");
printf("authenticated\n");
authenticated = 1;
username = strdup(principal);
return SSH_AUTH_SUCCESS;
}
static int pty_request(ssh_session session, ssh_channel channel, const char *term,
int x,int y, int px, int py, void *userdata){
(void) session;
(void) channel;
(void) term;
(void) x;
(void) y;
(void) px;
(void) py;
(void) userdata;
printf("Allocated terminal\n");
return 0;
}
static int shell_request(ssh_session session, ssh_channel channel, void *userdata){
(void)session;
(void)channel;
(void)userdata;
printf("Allocated shell\n");
return 0;
}
struct ssh_channel_callbacks_struct channel_cb = {
.channel_pty_request_function = pty_request,
.channel_shell_request_function = shell_request
};
static ssh_channel new_session_channel(ssh_session session, void *userdata){
(void) session;
(void) userdata;
if(chan != NULL)
return NULL;
printf("Allocated session channel\n");
chan = ssh_channel_new(session);
ssh_callbacks_init(&channel_cb);
ssh_set_channel_callbacks(chan, &channel_cb);
return chan;
}
#ifdef HAVE_ARGP_H
const char *argp_program_version = "libssh proxy example "
SSH_STRINGIFY(LIBSSH_VERSION);
const char *argp_program_bug_address = "<libssh@libssh.org>";
/* Program documentation. */
static char doc[] = "libssh -- a Secure Shell protocol implementation";
/* A description of the arguments we accept. */
static char args_doc[] = "BINDADDR";
/* The options we understand. */
static struct argp_option options[] = {
{
.name = "port",
.key = 'p',
.arg = "PORT",
.flags = 0,
.doc = "Set the port to bind.",
.group = 0
},
{
.name = "hostkey",
.key = 'k',
.arg = "FILE",
.flags = 0,
.doc = "Set the host key.",
.group = 0
},
{
.name = "dsakey",
.key = 'd',
.arg = "FILE",
.flags = 0,
.doc = "Set the dsa key.",
.group = 0
},
{
.name = "rsakey",
.key = 'r',
.arg = "FILE",
.flags = 0,
.doc = "Set the rsa key.",
.group = 0
},
{
.name = "verbose",
.key = 'v',
.arg = NULL,
.flags = 0,
.doc = "Get verbose output.",
.group = 0
},
{NULL, 0, NULL, 0, NULL, 0}
};
/* Parse a single option. */
static error_t parse_opt (int key, char *arg, struct argp_state *state) {
/* Get the input argument from argp_parse, which we
* know is a pointer to our arguments structure.
*/
ssh_bind sshbind = state->input;
switch (key) {
case 'p':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT_STR, arg);
break;
case 'd':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, arg);
break;
case 'k':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, arg);
break;
case 'r':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, arg);
break;
case 'v':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, "3");
break;
case ARGP_KEY_ARG:
if (state->arg_num >= 1) {
/* Too many arguments. */
argp_usage (state);
}
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, arg);
break;
case ARGP_KEY_END:
if (state->arg_num < 1) {
/* Not enough arguments. */
argp_usage (state);
}
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
/* Our argp parser. */
static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL};
#endif /* HAVE_ARGP_H */
int main(int argc, char **argv){
ssh_session session;
ssh_bind sshbind;
ssh_event mainloop;
ssh_session client_session;
struct ssh_server_callbacks_struct cb = {
.userdata = NULL,
.auth_password_function = auth_password,
.auth_gssapi_mic_function = auth_gssapi_mic,
.channel_open_request_session_function = new_session_channel
};
char buf[2048];
char host[128]="";
char *ptr;
int i,r, rc;
sshbind=ssh_bind_new();
session=ssh_new();
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, "sshd_rsa");
#ifdef HAVE_ARGP_H
/*
* Parse our arguments; every option seen by parse_opt will
* be reflected in arguments.
*/
argp_parse (&argp, argc, argv, 0, 0, sshbind);
#else
(void) argc;
(void) argv;
#endif
if(ssh_bind_listen(sshbind)<0){
printf("Error listening to socket: %s\n",ssh_get_error(sshbind));
return 1;
}
r=ssh_bind_accept(sshbind,session);
if(r==SSH_ERROR){
printf("error accepting a connection : %s\n",ssh_get_error(sshbind));
return 1;
}
ssh_callbacks_init(&cb);
ssh_set_server_callbacks(session, &cb);
if (ssh_handle_key_exchange(session)) {
printf("ssh_handle_key_exchange: %s\n", ssh_get_error(session));
return 1;
}
ssh_set_auth_methods(session,SSH_AUTH_METHOD_PASSWORD | SSH_AUTH_METHOD_GSSAPI_MIC);
mainloop = ssh_event_new();
ssh_event_add_session(mainloop, session);
while (!(authenticated && chan != NULL)){
if(error)
break;
r = ssh_event_dopoll(mainloop, -1);
if (r == SSH_ERROR){
printf("Error : %s\n",ssh_get_error(session));
ssh_disconnect(session);
return 1;
}
}
if(error){
printf("Error, exiting loop\n");
return 1;
} else
printf("Authenticated and got a channel\n");
if (!client_creds){
snprintf(buf,sizeof(buf), "Sorry, but you do not have forwardable tickets. Try again with -K\r\n");
ssh_channel_write(chan,buf,strlen(buf));
printf("%s",buf);
ssh_disconnect(session);
return 1;
}
snprintf(buf,sizeof(buf), "Hello %s, welcome to the Sample SSH proxy.\r\nPlease select your destination: ", username);
ssh_channel_write(chan, buf, strlen(buf));
do{
i=ssh_channel_read(chan,buf, 2048, 0);
if(i>0) {
ssh_channel_write(chan, buf, i);
if(strlen(host) + i < sizeof(host)){
strncat(host, buf, i);
}
if (strchr(host, '\x0d')) {
*strchr(host, '\x0d')='\0';
ssh_channel_write(chan, "\n", 1);
break;
}
} else {
printf ("Error: %s\n", ssh_get_error(session) );
return 1;
}
} while (i>0);
snprintf(buf,sizeof(buf),"Trying to connect to \"%s\"\r\n", host);
ssh_channel_write(chan, buf, strlen(buf));
printf("%s",buf);
client_session = ssh_new();
/* ssh servers expect username without realm */
ptr = strchr(username,'@');
if(ptr)
*ptr= '\0';
ssh_options_set(client_session, SSH_OPTIONS_HOST, host);
ssh_options_set(client_session, SSH_OPTIONS_USER, username);
ssh_gssapi_set_creds(client_session, client_creds);
rc = ssh_connect(client_session);
if (rc != SSH_OK){
printf("Error connecting to %s: %s", host, ssh_get_error(client_session));
return 1;
}
rc = ssh_userauth_none(client_session, NULL);
if(rc == SSH_AUTH_SUCCESS){
printf("Authenticated using method none\n");
} else {
rc = ssh_userauth_gssapi(client_session);
if(rc != SSH_AUTH_SUCCESS){
printf("GSSAPI Authentication failed: %s\n",ssh_get_error(client_session));
return 1;
}
}
snprintf(buf,sizeof(buf), "Authentication success\r\n");
printf("%s",buf);
ssh_channel_write(chan,buf,strlen(buf));
ssh_disconnect(client_session);
ssh_disconnect(session);
ssh_bind_free(sshbind);
ssh_finalize();
return 0;
}

View File

@@ -14,63 +14,50 @@ clients must be made or how a client should react.
#include "config.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <sys/select.h>
#include <sys/time.h>
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_PTY_H
#include <pty.h>
#endif
#include <sys/ioctl.h>
#include <signal.h>
#include <errno.h>
#include <fcntl.h>
#include <libssh/callbacks.h>
#include <libssh/libssh.h>
#include <libssh/sftp.h>
#include <fcntl.h>
#include "examples_common.h"
#define MAXCMD 10
char *host;
char *user;
char *cmds[MAXCMD];
struct termios terminal;
char *pcap_file=NULL;
static char *host;
static char *user;
static char *cmds[MAXCMD];
static struct termios terminal;
char *proxycommand;
static char *pcap_file=NULL;
static char *proxycommand;
static int auth_callback(const char *prompt, char *buf, size_t len,
int echo, int verify, void *userdata) {
char *answer = NULL;
char *ptr;
(void) verify;
(void) userdata;
(void) verify;
(void) userdata;
if (echo) {
while ((answer = fgets(buf, len, stdin)) == NULL);
if ((ptr = strchr(buf, '\n'))) {
*ptr = '\0';
}
} else {
if (ssh_getpass(prompt, buf, len, 0, 0) < 0) {
return -1;
}
return 0;
}
if (answer == NULL) {
return -1;
}
strncpy(buf, answer, len);
return 0;
return ssh_getpass(prompt, buf, len, echo, verify);
}
struct ssh_callbacks_struct cb = {
@@ -80,9 +67,12 @@ struct ssh_callbacks_struct cb = {
static void add_cmd(char *cmd){
int n;
for(n=0;cmds[n] && (n<MAXCMD);n++);
if(n==MAXCMD)
for (n = 0; (n < MAXCMD) && cmds[n] != NULL; n++);
if (n == MAXCMD) {
return;
}
cmds[n]=strdup(cmd);
}
@@ -246,8 +236,6 @@ static void select_loop(ssh_session session,ssh_channel channel){
// we already looked for input from stdin. Now, we are looking for input from the channel
if(channel && ssh_channel_is_closed(channel)){
ssh_log(session,SSH_LOG_RARE,"exit-status : %d",ssh_channel_get_exit_status(channel));
ssh_channel_free(channel);
channel=NULL;
channels[0]=NULL;
@@ -261,9 +249,6 @@ static void select_loop(ssh_session session,ssh_channel channel){
return;
}
if(lus==0){
ssh_log(session,SSH_LOG_RARE,"EOF received");
ssh_log(session,SSH_LOG_RARE,"exit-status : %d",ssh_channel_get_exit_status(channel));
ssh_channel_free(channel);
channel=channels[0]=NULL;
} else
@@ -280,8 +265,6 @@ static void select_loop(ssh_session session,ssh_channel channel){
return;
}
if(lus==0){
ssh_log(session,SSH_LOG_RARE,"EOF received");
ssh_log(session,SSH_LOG_RARE,"exit-status : %d",ssh_channel_get_exit_status(channel));
ssh_channel_free(channel);
channel=channels[0]=NULL;
} else
@@ -311,6 +294,7 @@ static void select_loop(ssh_session session,ssh_channel channel){
int lus;
int eof=0;
int maxfd;
unsigned int r;
int ret;
while(channel){
do{
@@ -338,24 +322,19 @@ static void select_loop(ssh_session session,ssh_channel channel){
}
}
if(channel && ssh_channel_is_closed(channel)){
ssh_log(session,SSH_LOG_RARE,"exit-status : %d",ssh_channel_get_exit_status(channel));
ssh_channel_free(channel);
channel=NULL;
channels[0]=NULL;
}
if(outchannels[0]){
while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,0)!=0){
lus=ssh_channel_read(channel,buffer,sizeof(buffer),0);
while(channel && ssh_channel_is_open(channel) && (r = ssh_channel_poll(channel,0))!=0){
lus=ssh_channel_read(channel,buffer,sizeof(buffer) > r ? r : sizeof(buffer),0);
if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n",
ssh_get_error(session));
return;
}
if(lus==0){
ssh_log(session,SSH_LOG_RARE,"EOF received");
ssh_log(session,SSH_LOG_RARE,"exit-status : %d",ssh_channel_get_exit_status(channel));
ssh_channel_free(channel);
channel=channels[0]=NULL;
} else
@@ -364,16 +343,14 @@ static void select_loop(ssh_session session,ssh_channel channel){
return;
}
}
while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,1)!=0){ /* stderr */
lus=ssh_channel_read(channel,buffer,sizeof(buffer),1);
while(channel && ssh_channel_is_open(channel) && (r = ssh_channel_poll(channel,1))!=0){ /* stderr */
lus=ssh_channel_read(channel,buffer,sizeof(buffer) > r ? r : sizeof(buffer),1);
if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n",
ssh_get_error(session));
return;
}
if(lus==0){
ssh_log(session,SSH_LOG_RARE,"EOF received");
ssh_log(session,SSH_LOG_RARE,"exit-status : %d",ssh_channel_get_exit_status(channel));
ssh_channel_free(channel);
channel=channels[0]=NULL;
} else
@@ -477,7 +454,6 @@ static int client(ssh_session session){
if(auth != SSH_AUTH_SUCCESS){
return -1;
}
ssh_log(session, SSH_LOG_FUNCTIONS, "Authentication success");
if(!cmds[0])
shell(session);
else

View File

@@ -15,11 +15,13 @@ clients must be made or how a client should react.
#include <sys/statvfs.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <libssh/libssh.h>
#include <libssh/sftp.h>
@@ -27,8 +29,9 @@ clients must be made or how a client should react.
#include "examples_common.h"
#ifdef WITH_SFTP
int verbosity;
char *destination;
static int verbosity;
static char *destination;
#define DATALEN 65536
static void do_sftp(ssh_session session){
sftp_session sftp=sftp_new(session);

306
examples/samplesshd-cb.c Normal file
View File

@@ -0,0 +1,306 @@
/* This is a sample implementation of a libssh based SSH server */
/*
Copyright 2003-2009 Aris Adamantiadis
This file is part of the SSH Library
You are free to copy this file, modify it in any way, consider it being public
domain. This does not apply to the rest of the library though, but it is
allowed to cut-and-paste working code from this file to any license of
program.
The goal is to show the API in action. It's not a reference on how terminal
clients must be made or how a client should react.
*/
#include "config.h"
#include <libssh/libssh.h>
#include <libssh/server.h>
#include <libssh/callbacks.h>
#ifdef HAVE_ARGP_H
#include <argp.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#ifndef KEYS_FOLDER
#ifdef _WIN32
#define KEYS_FOLDER
#else
#define KEYS_FOLDER "/etc/ssh/"
#endif
#endif
#define USER "myuser"
#define PASSWORD "mypassword"
static int authenticated=0;
static int tries = 0;
static int error = 0;
static ssh_channel chan=NULL;
static int auth_password(ssh_session session, const char *user,
const char *password, void *userdata){
(void)userdata;
printf("Authenticating user %s pwd %s\n",user, password);
if(strcmp(user,USER) == 0 && strcmp(password, PASSWORD) == 0){
authenticated = 1;
printf("Authenticated\n");
return SSH_AUTH_SUCCESS;
}
if (tries >= 3){
printf("Too many authentication tries\n");
ssh_disconnect(session);
error = 1;
return SSH_AUTH_DENIED;
}
tries++;
return SSH_AUTH_DENIED;
}
static int auth_gssapi_mic(ssh_session session, const char *user, const char *principal, void *userdata){
ssh_gssapi_creds creds = ssh_gssapi_get_creds(session);
(void)userdata;
printf("Authenticating user %s with gssapi principal %s\n",user, principal);
if (creds != NULL)
printf("Received some gssapi credentials\n");
else
printf("Not received any forwardable creds\n");
printf("authenticated\n");
authenticated = 1;
return SSH_AUTH_SUCCESS;
}
static int pty_request(ssh_session session, ssh_channel channel, const char *term,
int x,int y, int px, int py, void *userdata){
(void) session;
(void) channel;
(void) term;
(void) x;
(void) y;
(void) px;
(void) py;
(void) userdata;
printf("Allocated terminal\n");
return 0;
}
static int shell_request(ssh_session session, ssh_channel channel, void *userdata){
(void)session;
(void)channel;
(void)userdata;
printf("Allocated shell\n");
return 0;
}
struct ssh_channel_callbacks_struct channel_cb = {
.channel_pty_request_function = pty_request,
.channel_shell_request_function = shell_request
};
static ssh_channel new_session_channel(ssh_session session, void *userdata){
(void) session;
(void) userdata;
if(chan != NULL)
return NULL;
printf("Allocated session channel\n");
chan = ssh_channel_new(session);
ssh_callbacks_init(&channel_cb);
ssh_set_channel_callbacks(chan, &channel_cb);
return chan;
}
#ifdef HAVE_ARGP_H
const char *argp_program_version = "libssh server example "
SSH_STRINGIFY(LIBSSH_VERSION);
const char *argp_program_bug_address = "<libssh@libssh.org>";
/* Program documentation. */
static char doc[] = "libssh -- a Secure Shell protocol implementation";
/* A description of the arguments we accept. */
static char args_doc[] = "BINDADDR";
/* The options we understand. */
static struct argp_option options[] = {
{
.name = "port",
.key = 'p',
.arg = "PORT",
.flags = 0,
.doc = "Set the port to bind.",
.group = 0
},
{
.name = "hostkey",
.key = 'k',
.arg = "FILE",
.flags = 0,
.doc = "Set the host key.",
.group = 0
},
{
.name = "dsakey",
.key = 'd',
.arg = "FILE",
.flags = 0,
.doc = "Set the dsa key.",
.group = 0
},
{
.name = "rsakey",
.key = 'r',
.arg = "FILE",
.flags = 0,
.doc = "Set the rsa key.",
.group = 0
},
{
.name = "verbose",
.key = 'v',
.arg = NULL,
.flags = 0,
.doc = "Get verbose output.",
.group = 0
},
{NULL, 0, NULL, 0, NULL, 0}
};
/* Parse a single option. */
static error_t parse_opt (int key, char *arg, struct argp_state *state) {
/* Get the input argument from argp_parse, which we
* know is a pointer to our arguments structure.
*/
ssh_bind sshbind = state->input;
switch (key) {
case 'p':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT_STR, arg);
break;
case 'd':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, arg);
break;
case 'k':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, arg);
break;
case 'r':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, arg);
break;
case 'v':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, "3");
break;
case ARGP_KEY_ARG:
if (state->arg_num >= 1) {
/* Too many arguments. */
argp_usage (state);
}
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, arg);
break;
case ARGP_KEY_END:
if (state->arg_num < 1) {
/* Not enough arguments. */
argp_usage (state);
}
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
/* Our argp parser. */
static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL};
#endif /* HAVE_ARGP_H */
int main(int argc, char **argv){
ssh_session session;
ssh_bind sshbind;
ssh_event mainloop;
struct ssh_server_callbacks_struct cb = {
.userdata = NULL,
.auth_password_function = auth_password,
.auth_gssapi_mic_function = auth_gssapi_mic,
.channel_open_request_session_function = new_session_channel
};
char buf[2048];
int i;
int r;
sshbind=ssh_bind_new();
session=ssh_new();
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, KEYS_FOLDER "ssh_host_dsa_key");
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, KEYS_FOLDER "ssh_host_rsa_key");
#ifdef HAVE_ARGP_H
/*
* Parse our arguments; every option seen by parse_opt will
* be reflected in arguments.
*/
argp_parse (&argp, argc, argv, 0, 0, sshbind);
#else
(void) argc;
(void) argv;
#endif
if(ssh_bind_listen(sshbind)<0){
printf("Error listening to socket: %s\n",ssh_get_error(sshbind));
return 1;
}
r=ssh_bind_accept(sshbind,session);
if(r==SSH_ERROR){
printf("error accepting a connection : %s\n",ssh_get_error(sshbind));
return 1;
}
ssh_callbacks_init(&cb);
ssh_set_server_callbacks(session, &cb);
if (ssh_handle_key_exchange(session)) {
printf("ssh_handle_key_exchange: %s\n", ssh_get_error(session));
return 1;
}
ssh_set_auth_methods(session,SSH_AUTH_METHOD_PASSWORD | SSH_AUTH_METHOD_GSSAPI_MIC);
mainloop = ssh_event_new();
ssh_event_add_session(mainloop, session);
while (!(authenticated && chan != NULL)){
if(error)
break;
r = ssh_event_dopoll(mainloop, -1);
if (r == SSH_ERROR){
printf("Error : %s\n",ssh_get_error(session));
ssh_disconnect(session);
return 1;
}
}
if(error){
printf("Error, exiting loop\n");
} else
printf("Authenticated and got a channel\n");
do{
i=ssh_channel_read(chan,buf, 2048, 0);
if(i>0) {
ssh_channel_write(chan, buf, i);
if (write(1,buf,i) < 0) {
printf("error writing to buffer\n");
return 1;
}
if (buf[0] == '\x0d') {
if (write(1, "\n", 1) < 0) {
printf("error writing to buffer\n");
return 1;
}
ssh_channel_write(chan, "\n", 1);
}
}
} while (i>0);
ssh_disconnect(session);
ssh_bind_free(sshbind);
ssh_finalize();
return 0;
}

View File

@@ -0,0 +1,413 @@
/* This is a sample implementation of a libssh based SSH server */
/*
Copyright 2003-2011 Aris Adamantiadis
This file is part of the SSH Library
You are free to copy this file, modify it in any way, consider it being public
domain. This does not apply to the rest of the library though, but it is
allowed to cut-and-paste working code from this file to any license of
program.
The goal is to show the API in action. It's not a reference on how terminal
clients must be made or how a client should react.
*/
#include "config.h"
#include <libssh/libssh.h>
#include <libssh/server.h>
#ifdef HAVE_ARGP_H
#include <argp.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define SSHD_USER "libssh"
#define SSHD_PASSWORD "libssh"
#ifndef KEYS_FOLDER
#ifdef _WIN32
#define KEYS_FOLDER
#else
#define KEYS_FOLDER "/etc/ssh/"
#endif
#endif
static int port = 22;
#ifdef WITH_PCAP
static const char *pcap_file = "debug.server.pcap";
static ssh_pcap_file pcap;
static void set_pcap(ssh_session session){
if(!pcap_file)
return;
pcap=ssh_pcap_file_new();
if(ssh_pcap_file_open(pcap,pcap_file) == SSH_ERROR){
printf("Error opening pcap file\n");
ssh_pcap_file_free(pcap);
pcap=NULL;
return;
}
ssh_set_pcap_file(session,pcap);
}
static void cleanup_pcap(void) {
ssh_pcap_file_free(pcap);
pcap=NULL;
}
#endif
static int auth_password(const char *user, const char *password){
if(strcmp(user, SSHD_USER))
return 0;
if(strcmp(password, SSHD_PASSWORD))
return 0;
return 1; // authenticated
}
#ifdef HAVE_ARGP_H
const char *argp_program_version = "libssh server example "
SSH_STRINGIFY(LIBSSH_VERSION);
const char *argp_program_bug_address = "<libssh@libssh.org>";
/* Program documentation. */
static char doc[] = "libssh -- a Secure Shell protocol implementation";
/* A description of the arguments we accept. */
static char args_doc[] = "BINDADDR";
/* The options we understand. */
static struct argp_option options[] = {
{
.name = "port",
.key = 'p',
.arg = "PORT",
.flags = 0,
.doc = "Set the port to bind.",
.group = 0
},
{
.name = "hostkey",
.key = 'k',
.arg = "FILE",
.flags = 0,
.doc = "Set the host key.",
.group = 0
},
{
.name = "dsakey",
.key = 'd',
.arg = "FILE",
.flags = 0,
.doc = "Set the dsa key.",
.group = 0
},
{
.name = "rsakey",
.key = 'r',
.arg = "FILE",
.flags = 0,
.doc = "Set the rsa key.",
.group = 0
},
{
.name = "verbose",
.key = 'v',
.arg = NULL,
.flags = 0,
.doc = "Get verbose output.",
.group = 0
},
{NULL, 0, 0, 0, NULL, 0}
};
/* Parse a single option. */
static error_t parse_opt (int key, char *arg, struct argp_state *state) {
/* Get the input argument from argp_parse, which we
* know is a pointer to our arguments structure.
*/
ssh_bind sshbind = state->input;
switch (key) {
case 'p':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT_STR, arg);
port = atoi(arg);
break;
case 'd':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, arg);
break;
case 'k':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, arg);
break;
case 'r':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, arg);
break;
case 'v':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, "3");
break;
case ARGP_KEY_ARG:
if (state->arg_num >= 1) {
/* Too many arguments. */
argp_usage (state);
}
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, arg);
break;
case ARGP_KEY_END:
if (state->arg_num < 1) {
/* Not enough arguments. */
argp_usage (state);
}
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
/* Our argp parser. */
static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL};
#endif /* HAVE_ARGP_H */
static const char *name;
static const char *instruction;
static const char *prompts[2];
static char echo[] = { 1, 0 };
static int kbdint_check_response(ssh_session session) {
int count;
count = ssh_userauth_kbdint_getnanswers(session);
if(count != 2) {
instruction = "Something weird happened :(";
return 0;
}
if(strcasecmp("Arthur Dent",
ssh_userauth_kbdint_getanswer(session, 0)) != 0) {
instruction = "OK, this is not YOUR name, "
"but it's a reference to the HGTG...";
prompts[0] = "The main character's full name: ";
return 0;
}
if(strcmp("42", ssh_userauth_kbdint_getanswer(session, 1)) != 0) {
instruction = "Make an effort !!! What is the Answer to the Ultimate "
"Question of Life, the Universe, and Everything ?";
prompts[1] = "Answer to the Ultimate Question of Life, the Universe, "
"and Everything: ";
return 0;
}
return 1;
}
static int authenticate(ssh_session session) {
ssh_message message;
name = "\n\nKeyboard-Interactive Fancy Authentication\n";
instruction = "Please enter your real name and your password";
prompts[0] = "Real name: ";
prompts[1] = "Password: ";
do {
message=ssh_message_get(session);
if(!message)
break;
switch(ssh_message_type(message)){
case SSH_REQUEST_AUTH:
switch(ssh_message_subtype(message)){
case SSH_AUTH_METHOD_PASSWORD:
printf("User %s wants to auth with pass %s\n",
ssh_message_auth_user(message),
ssh_message_auth_password(message));
if(auth_password(ssh_message_auth_user(message),
ssh_message_auth_password(message))){
ssh_message_auth_reply_success(message,0);
ssh_message_free(message);
return 1;
}
ssh_message_auth_set_methods(message,
SSH_AUTH_METHOD_PASSWORD |
SSH_AUTH_METHOD_INTERACTIVE);
// not authenticated, send default message
ssh_message_reply_default(message);
break;
case SSH_AUTH_METHOD_INTERACTIVE:
if(!ssh_message_auth_kbdint_is_response(message)) {
printf("User %s wants to auth with kbdint\n",
ssh_message_auth_user(message));
ssh_message_auth_interactive_request(message, name,
instruction, 2, prompts, echo);
} else {
if(kbdint_check_response(session)) {
ssh_message_auth_reply_success(message,0);
ssh_message_free(message);
return 1;
}
ssh_message_auth_set_methods(message,
SSH_AUTH_METHOD_PASSWORD |
SSH_AUTH_METHOD_INTERACTIVE);
ssh_message_reply_default(message);
}
break;
case SSH_AUTH_METHOD_NONE:
default:
printf("User %s wants to auth with unknown auth %d\n",
ssh_message_auth_user(message),
ssh_message_subtype(message));
ssh_message_auth_set_methods(message,
SSH_AUTH_METHOD_PASSWORD |
SSH_AUTH_METHOD_INTERACTIVE);
ssh_message_reply_default(message);
break;
}
break;
default:
ssh_message_auth_set_methods(message,
SSH_AUTH_METHOD_PASSWORD |
SSH_AUTH_METHOD_INTERACTIVE);
ssh_message_reply_default(message);
}
ssh_message_free(message);
} while (1);
return 0;
}
int main(int argc, char **argv){
ssh_session session;
ssh_bind sshbind;
ssh_message message;
ssh_channel chan=0;
char buf[2048];
int auth=0;
int shell=0;
int i;
int r;
sshbind=ssh_bind_new();
session=ssh_new();
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY,
KEYS_FOLDER "ssh_host_dsa_key");
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY,
KEYS_FOLDER "ssh_host_rsa_key");
#ifdef HAVE_ARGP_H
/*
* Parse our arguments; every option seen by parse_opt will
* be reflected in arguments.
*/
argp_parse (&argp, argc, argv, 0, 0, sshbind);
#else
(void) argc;
(void) argv;
#endif
#ifdef WITH_PCAP
set_pcap(session);
#endif
if(ssh_bind_listen(sshbind)<0){
printf("Error listening to socket: %s\n", ssh_get_error(sshbind));
return 1;
}
printf("Started sample libssh sshd on port %d\n", port);
printf("You can login as the user %s with the password %s\n", SSHD_USER,
SSHD_PASSWORD);
r = ssh_bind_accept(sshbind, session);
if(r==SSH_ERROR){
printf("Error accepting a connection: %s\n", ssh_get_error(sshbind));
return 1;
}
if (ssh_handle_key_exchange(session)) {
printf("ssh_handle_key_exchange: %s\n", ssh_get_error(session));
return 1;
}
/* proceed to authentication */
auth = authenticate(session);
if(!auth){
printf("Authentication error: %s\n", ssh_get_error(session));
ssh_disconnect(session);
return 1;
}
/* wait for a channel session */
do {
message = ssh_message_get(session);
if(message){
if(ssh_message_type(message) == SSH_REQUEST_CHANNEL_OPEN &&
ssh_message_subtype(message) == SSH_CHANNEL_SESSION) {
chan = ssh_message_channel_request_open_reply_accept(message);
ssh_message_free(message);
break;
} else {
ssh_message_reply_default(message);
ssh_message_free(message);
}
} else {
break;
}
} while(!chan);
if(!chan) {
printf("Error: cleint did not ask for a channel session (%s)\n",
ssh_get_error(session));
ssh_finalize();
return 1;
}
/* wait for a shell */
do {
message = ssh_message_get(session);
if(message != NULL) {
if(ssh_message_type(message) == SSH_REQUEST_CHANNEL &&
ssh_message_subtype(message) == SSH_CHANNEL_REQUEST_SHELL) {
shell = 1;
ssh_message_channel_request_reply_success(message);
ssh_message_free(message);
break;
}
ssh_message_reply_default(message);
ssh_message_free(message);
} else {
break;
}
} while(!shell);
if(!shell) {
printf("Error: No shell requested (%s)\n", ssh_get_error(session));
return 1;
}
printf("it works !\n");
do{
i=ssh_channel_read(chan,buf, 2048, 0);
if(i>0) {
if(*buf == '' || *buf == '')
break;
if(i == 1 && *buf == '\r')
ssh_channel_write(chan, "\r\n", 2);
else
ssh_channel_write(chan, buf, i);
if (write(1,buf,i) < 0) {
printf("error writing to buffer\n");
return 1;
}
}
} while (i>0);
ssh_channel_close(chan);
ssh_disconnect(session);
ssh_bind_free(sshbind);
#ifdef WITH_PCAP
cleanup_pcap();
#endif
ssh_finalize();
return 0;
}

469
examples/samplesshd-tty.c Normal file
View File

@@ -0,0 +1,469 @@
/* This is a sample implementation of a libssh based SSH server */
/*
Copyright 2003-2011 Aris Adamantiadis
This file is part of the SSH Library
You are free to copy this file, modify it in any way, consider it being public
domain. This does not apply to the rest of the library though, but it is
allowed to cut-and-paste working code from this file to any license of
program.
The goal is to show the API in action. It's not a reference on how terminal
clients must be made or how a client should react.
*/
#include "config.h"
#include <libssh/libssh.h>
#include <libssh/server.h>
#include <libssh/callbacks.h>
#ifdef HAVE_ARGP_H
#include <argp.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <poll.h>
#ifdef HAVE_PTY_H
#include <pty.h>
#endif
#ifdef HAVE_UTIL_H
#include <util.h>
#endif
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
#define SSHD_USER "libssh"
#define SSHD_PASSWORD "libssh"
#ifndef KEYS_FOLDER
#ifdef _WIN32
#define KEYS_FOLDER
#else
#define KEYS_FOLDER "/etc/ssh/"
#endif
#endif
static int port = 22;
#ifdef WITH_PCAP
const char *pcap_file="debug.server.pcap";
ssh_pcap_file pcap;
static void set_pcap(ssh_session session){
if(!pcap_file)
return;
pcap=ssh_pcap_file_new();
if(ssh_pcap_file_open(pcap,pcap_file) == SSH_ERROR){
printf("Error opening pcap file\n");
ssh_pcap_file_free(pcap);
pcap=NULL;
return;
}
ssh_set_pcap_file(session,pcap);
}
static void cleanup_pcap(){
ssh_pcap_file_free(pcap);
pcap=NULL;
}
#endif
static int auth_password(const char *user, const char *password){
if(strcmp(user, SSHD_USER))
return 0;
if(strcmp(password, SSHD_PASSWORD))
return 0;
return 1; // authenticated
}
#ifdef HAVE_ARGP_H
const char *argp_program_version = "libssh server example "
SSH_STRINGIFY(LIBSSH_VERSION);
const char *argp_program_bug_address = "<libssh@libssh.org>";
/* Program documentation. */
static char doc[] = "libssh -- a Secure Shell protocol implementation";
/* A description of the arguments we accept. */
static char args_doc[] = "BINDADDR";
/* The options we understand. */
static struct argp_option options[] = {
{
.name = "port",
.key = 'p',
.arg = "PORT",
.flags = 0,
.doc = "Set the port to bind.",
.group = 0
},
{
.name = "hostkey",
.key = 'k',
.arg = "FILE",
.flags = 0,
.doc = "Set the host key.",
.group = 0
},
{
.name = "dsakey",
.key = 'd',
.arg = "FILE",
.flags = 0,
.doc = "Set the dsa key.",
.group = 0
},
{
.name = "rsakey",
.key = 'r',
.arg = "FILE",
.flags = 0,
.doc = "Set the rsa key.",
.group = 0
},
{
.name = "verbose",
.key = 'v',
.arg = NULL,
.flags = 0,
.doc = "Get verbose output.",
.group = 0
},
{NULL, 0, 0, 0, NULL, 0}
};
/* Parse a single option. */
static error_t parse_opt (int key, char *arg, struct argp_state *state) {
/* Get the input argument from argp_parse, which we
* know is a pointer to our arguments structure.
*/
ssh_bind sshbind = state->input;
switch (key) {
case 'p':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT_STR, arg);
port = atoi(arg);
break;
case 'd':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, arg);
break;
case 'k':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, arg);
break;
case 'r':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, arg);
break;
case 'v':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_LOG_VERBOSITY_STR, "3");
break;
case ARGP_KEY_ARG:
if (state->arg_num >= 1) {
/* Too many arguments. */
argp_usage (state);
}
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, arg);
break;
case ARGP_KEY_END:
if (state->arg_num < 1) {
/* Not enough arguments. */
argp_usage (state);
}
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
/* Our argp parser. */
static struct argp argp = {options, parse_opt, args_doc, doc, NULL, NULL, NULL};
#endif /* HAVE_ARGP_H */
static int authenticate(ssh_session session) {
ssh_message message;
do {
message=ssh_message_get(session);
if(!message)
break;
switch(ssh_message_type(message)){
case SSH_REQUEST_AUTH:
switch(ssh_message_subtype(message)){
case SSH_AUTH_METHOD_PASSWORD:
printf("User %s wants to auth with pass %s\n",
ssh_message_auth_user(message),
ssh_message_auth_password(message));
if(auth_password(ssh_message_auth_user(message),
ssh_message_auth_password(message))){
ssh_message_auth_reply_success(message,0);
ssh_message_free(message);
return 1;
}
ssh_message_auth_set_methods(message,
SSH_AUTH_METHOD_PASSWORD |
SSH_AUTH_METHOD_INTERACTIVE);
// not authenticated, send default message
ssh_message_reply_default(message);
break;
case SSH_AUTH_METHOD_NONE:
default:
printf("User %s wants to auth with unknown auth %d\n",
ssh_message_auth_user(message),
ssh_message_subtype(message));
ssh_message_auth_set_methods(message,
SSH_AUTH_METHOD_PASSWORD |
SSH_AUTH_METHOD_INTERACTIVE);
ssh_message_reply_default(message);
break;
}
break;
default:
ssh_message_auth_set_methods(message,
SSH_AUTH_METHOD_PASSWORD |
SSH_AUTH_METHOD_INTERACTIVE);
ssh_message_reply_default(message);
}
ssh_message_free(message);
} while (1);
return 0;
}
static int copy_fd_to_chan(socket_t fd, int revents, void *userdata) {
ssh_channel chan = (ssh_channel)userdata;
char buf[2048];
int sz = 0;
if(!chan) {
close(fd);
return -1;
}
if(revents & POLLIN) {
sz = read(fd, buf, 2048);
if(sz > 0) {
ssh_channel_write(chan, buf, sz);
}
}
if(revents & POLLHUP) {
ssh_channel_close(chan);
sz = -1;
}
return sz;
}
static int copy_chan_to_fd(ssh_session session,
ssh_channel channel,
void *data,
uint32_t len,
int is_stderr,
void *userdata) {
int fd = *(int*)userdata;
int sz;
(void)session;
(void)channel;
(void)is_stderr;
sz = write(fd, data, len);
return sz;
}
static void chan_close(ssh_session session, ssh_channel channel, void *userdata) {
int fd = *(int*)userdata;
(void)session;
(void)channel;
close(fd);
}
struct ssh_channel_callbacks_struct cb = {
.channel_data_function = copy_chan_to_fd,
.channel_eof_function = chan_close,
.channel_close_function = chan_close,
.userdata = NULL
};
static int main_loop(ssh_channel chan) {
ssh_session session = ssh_channel_get_session(chan);
socket_t fd;
struct termios *term = NULL;
struct winsize *win = NULL;
pid_t childpid;
ssh_event event;
short events;
int rc;
childpid = forkpty(&fd, NULL, term, win);
if(childpid == 0) {
execl("/bin/bash", "/bin/bash", (char *)NULL);
abort();
}
cb.userdata = &fd;
ssh_callbacks_init(&cb);
ssh_set_channel_callbacks(chan, &cb);
events = POLLIN | POLLPRI | POLLERR | POLLHUP | POLLNVAL;
event = ssh_event_new();
if(event == NULL) {
printf("Couldn't get a event\n");
return -1;
}
if(ssh_event_add_fd(event, fd, events, copy_fd_to_chan, chan) != SSH_OK) {
printf("Couldn't add an fd to the event\n");
ssh_event_free(event);
return -1;
}
if(ssh_event_add_session(event, session) != SSH_OK) {
printf("Couldn't add the session to the event\n");
ssh_event_remove_fd(event, fd);
ssh_event_free(event);
return -1;
}
do {
rc = ssh_event_dopoll(event, 1000);
if (rc == SSH_ERROR){
fprintf(stderr, "Error : %s\n", ssh_get_error(session));
ssh_event_free(event);
ssh_disconnect(session);
return -1;
}
} while(!ssh_channel_is_closed(chan));
ssh_event_remove_fd(event, fd);
ssh_event_remove_session(event, session);
ssh_event_free(event);
return 0;
}
int main(int argc, char **argv){
ssh_session session;
ssh_bind sshbind;
ssh_message message;
ssh_channel chan=0;
int auth=0;
int shell=0;
int r;
sshbind=ssh_bind_new();
session=ssh_new();
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY,
KEYS_FOLDER "ssh_host_dsa_key");
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY,
KEYS_FOLDER "ssh_host_rsa_key");
#ifdef HAVE_ARGP_H
/*
* Parse our arguments; every option seen by parse_opt will
* be reflected in arguments.
*/
argp_parse (&argp, argc, argv, 0, 0, sshbind);
#else
(void) argc;
(void) argv;
#endif
#ifdef WITH_PCAP
set_pcap(session);
#endif
if(ssh_bind_listen(sshbind)<0){
printf("Error listening to socket: %s\n", ssh_get_error(sshbind));
return 1;
}
printf("Started sample libssh sshd on port %d\n", port);
printf("You can login as the user %s with the password %s\n", SSHD_USER,
SSHD_PASSWORD);
r = ssh_bind_accept(sshbind, session);
if(r==SSH_ERROR){
printf("Error accepting a connection: %s\n", ssh_get_error(sshbind));
return 1;
}
if (ssh_handle_key_exchange(session)) {
printf("ssh_handle_key_exchange: %s\n", ssh_get_error(session));
return 1;
}
/* proceed to authentication */
auth = authenticate(session);
if(!auth){
printf("Authentication error: %s\n", ssh_get_error(session));
ssh_disconnect(session);
return 1;
}
/* wait for a channel session */
do {
message = ssh_message_get(session);
if(message){
if(ssh_message_type(message) == SSH_REQUEST_CHANNEL_OPEN &&
ssh_message_subtype(message) == SSH_CHANNEL_SESSION) {
chan = ssh_message_channel_request_open_reply_accept(message);
ssh_message_free(message);
break;
} else {
ssh_message_reply_default(message);
ssh_message_free(message);
}
} else {
break;
}
} while(!chan);
if(!chan) {
printf("Error: cleint did not ask for a channel session (%s)\n",
ssh_get_error(session));
ssh_finalize();
return 1;
}
/* wait for a shell */
do {
message = ssh_message_get(session);
if(message != NULL) {
if(ssh_message_type(message) == SSH_REQUEST_CHANNEL) {
if(ssh_message_subtype(message) == SSH_CHANNEL_REQUEST_SHELL) {
shell = 1;
ssh_message_channel_request_reply_success(message);
ssh_message_free(message);
break;
} else if(ssh_message_subtype(message) == SSH_CHANNEL_REQUEST_PTY) {
ssh_message_channel_request_reply_success(message);
ssh_message_free(message);
continue;
}
}
ssh_message_reply_default(message);
ssh_message_free(message);
} else {
break;
}
} while(!shell);
if(!shell) {
printf("Error: No shell requested (%s)\n", ssh_get_error(session));
return 1;
}
printf("it works !\n");
main_loop(chan);
ssh_disconnect(session);
ssh_bind_free(sshbind);
#ifdef WITH_PCAP
cleanup_pcap();
#endif
ssh_finalize();
return 0;
}

View File

@@ -33,11 +33,10 @@ clients must be made or how a client should react.
#endif
#ifdef WITH_PCAP
const char *pcap_file="debug.server.pcap";
ssh_pcap_file pcap;
static const char *pcap_file="debug.server.pcap";
static ssh_pcap_file pcap;
void set_pcap(ssh_session session);
void set_pcap(ssh_session session){
static void set_pcap(ssh_session session) {
if(!pcap_file)
return;
pcap=ssh_pcap_file_new();
@@ -50,15 +49,14 @@ void set_pcap(ssh_session session){
ssh_set_pcap_file(session,pcap);
}
void cleanup_pcap(void);
void cleanup_pcap(){
static void cleanup_pcap(void) {
ssh_pcap_file_free(pcap);
pcap=NULL;
}
#endif
static int auth_password(char *user, char *password){
static int auth_password(const char *user, const char *password){
if(strcmp(user,"aris"))
return 0;
if(strcmp(password,"lala"))
@@ -118,7 +116,7 @@ static struct argp_option options[] = {
.doc = "Get verbose output.",
.group = 0
},
{NULL, 0, 0, 0, NULL, 0}
{NULL, 0, NULL, 0, NULL, 0}
};
/* Parse a single option. */
@@ -270,7 +268,8 @@ int main(int argc, char **argv){
do {
message=ssh_message_get(session);
if(message && ssh_message_type(message)==SSH_REQUEST_CHANNEL &&
ssh_message_subtype(message)==SSH_CHANNEL_REQUEST_SHELL){
(ssh_message_subtype(message)==SSH_CHANNEL_REQUEST_SHELL ||
ssh_message_subtype(message)==SSH_CHANNEL_REQUEST_PTY)) {
// if(!strcmp(ssh_message_channel_request_subsystem(message),"sftp")){
sftp=1;
ssh_message_channel_request_reply_success(message);
@@ -295,6 +294,13 @@ int main(int argc, char **argv){
printf("error writing to buffer\n");
return 1;
}
if (buf[0] == '\x0d') {
if (write(1, "\n", 1) < 0) {
printf("error writing to buffer\n");
return 1;
}
ssh_channel_write(chan, "\n", 1);
}
}
} while (i>0);
ssh_disconnect(session);

View File

@@ -58,6 +58,8 @@ static int opts(int argc, char **argv){
static void create_files(ssh_session session){
ssh_channel channel=ssh_channel_new(session);
char buffer[1];
int rc;
if(channel == NULL){
fprintf(stderr,"Error creating channel: %s\n",ssh_get_error(session));
exit(EXIT_FAILURE);
@@ -74,8 +76,16 @@ static void create_files(ssh_session session){
exit(EXIT_FAILURE);
}
while(!ssh_channel_is_eof(channel)){
ssh_channel_read(channel,buffer,1,1);
if (write(1,buffer,1) < 0) {
rc = ssh_channel_read(channel,buffer,1,1);
if (rc != 1) {
fprintf(stderr, "Error reading from channel\n");
ssh_channel_close(channel);
ssh_channel_free(channel);
return;
}
rc = write(1, buffer, 1);
if (rc < 0) {
fprintf(stderr, "Error writing to buffer\n");
ssh_channel_close(channel);
ssh_channel_free(channel);

View File

@@ -13,10 +13,14 @@ clients must be made or how a client should react.
#include "config.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/select.h>
#include <sys/time.h>
@@ -105,8 +109,6 @@ static void select_loop(ssh_session session,ssh_channel channel){
}
}
if(channel && channel_is_closed(channel)){
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
channel_free(channel);
channel=NULL;
channels[0]=NULL;
@@ -120,9 +122,6 @@ static void select_loop(ssh_session session,ssh_channel channel){
return;
}
if(lus==0){
ssh_log(session,SSH_LOG_RARE,"EOF received\n");
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
channel_free(channel);
channel=channels[0]=NULL;
} else {
@@ -142,17 +141,16 @@ static void select_loop(ssh_session session,ssh_channel channel){
return;
}
if(lus==0){
ssh_log(session,SSH_LOG_RARE,"EOF received\n");
ssh_log(session,SSH_LOG_RARE,"exit-status : %d\n",channel_get_exit_status(channel));
channel_free(channel);
channel=channels[0]=NULL;
} else
} else {
ret = write(2, buffer, lus);
if (ret < 0) {
fprintf(stderr, "Error writing to stderr: %s",
strerror(errno));
return;
}
}
}
}
if(channel && channel_is_closed(channel)){
@@ -202,7 +200,6 @@ static int client(ssh_session session){
if(auth != SSH_AUTH_SUCCESS){
return -1;
}
ssh_log(session, SSH_LOG_FUNCTIONS, "Authentication success");
forwarding(session);
return 0;
}

View File

@@ -5,6 +5,7 @@ set(libssh_HDRS
libssh.h
ssh2.h
legacy.h
libsshpp.hpp
)
if (WITH_SFTP)

View File

@@ -1,3 +1,23 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2008-2009 Andreas Schneider <asn@cryptomilk.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __AGENT_H
#define __AGENT_H
@@ -51,6 +71,7 @@ struct ssh_agent_struct {
struct ssh_socket_struct *sock;
ssh_buffer ident;
unsigned int count;
ssh_channel channel;
};
#ifndef _WIN32
@@ -80,17 +101,17 @@ void agent_free(struct ssh_agent_struct *agent);
*/
int agent_is_running(struct ssh_session_struct *session);
int agent_get_ident_count(struct ssh_session_struct *session);
int ssh_agent_get_ident_count(struct ssh_session_struct *session);
struct ssh_public_key_struct *agent_get_next_ident(struct ssh_session_struct *session,
char **comment);
ssh_key ssh_agent_get_next_ident(struct ssh_session_struct *session,
char **comment);
struct ssh_public_key_struct *agent_get_first_ident(struct ssh_session_struct *session,
char **comment);
ssh_key ssh_agent_get_first_ident(struct ssh_session_struct *session,
char **comment);
ssh_string agent_sign_data(struct ssh_session_struct *session,
struct ssh_buffer_struct *data,
struct ssh_public_key_struct *pubkey);
ssh_string ssh_agent_sign_data(ssh_session session,
const ssh_key pubkey,
struct ssh_buffer_struct *data);
#endif
#endif /* __AGENT_H */

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AUTH_H_
@@ -29,6 +28,27 @@ SSH_PACKET_CALLBACK(ssh_packet_userauth_failure);
SSH_PACKET_CALLBACK(ssh_packet_userauth_success);
SSH_PACKET_CALLBACK(ssh_packet_userauth_pk_ok);
SSH_PACKET_CALLBACK(ssh_packet_userauth_info_request);
SSH_PACKET_CALLBACK(ssh_packet_userauth_info_response);
/** @internal
* kdbint structure must be shared with message.c
* and server.c
*/
struct ssh_kbdint_struct {
uint32_t nprompts;
uint32_t nanswers;
char *name;
char *instruction;
char **prompts;
unsigned char *echo; /* bool array */
char **answers;
};
typedef struct ssh_kbdint_struct* ssh_kbdint;
ssh_kbdint ssh_kbdint_new(void);
void ssh_kbdint_clean(ssh_kbdint kbd);
void ssh_kbdint_free(ssh_kbdint kbd);
#ifdef WITH_SSH1
void ssh_auth1_handler(ssh_session session, uint8_t type);
@@ -63,8 +83,13 @@ enum ssh_auth_state_e {
/** Last state was a public key accepted for authentication */
SSH_AUTH_STATE_PK_OK,
/** We asked for a keyboard-interactive authentication */
SSH_AUTH_STATE_KBDINT_SENT
SSH_AUTH_STATE_KBDINT_SENT,
/** We have sent an userauth request with gssapi-with-mic */
SSH_AUTH_STATE_GSSAPI_REQUEST_SENT,
/** We are exchanging tokens until authentication */
SSH_AUTH_STATE_GSSAPI_TOKEN,
/** We have sent the MIC and expecting to be authenticated */
SSH_AUTH_STATE_GSSAPI_MIC_SENT,
};
/** @internal

View File

@@ -3,31 +3,29 @@
*
* Copyright (c) 2010 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef BIND_H_
#define BIND_H_
#include "libssh/priv.h"
#include "libssh/session.h"
struct ssh_bind_struct {
struct error_struct error;
ssh_callbacks callbacks; /* Callbacks to user functions */
struct ssh_common_struct common; /* stuff common to ssh_bind and ssh_session */
struct ssh_bind_callbacks_struct *bind_callbacks;
void *bind_callbacks_userdata;
@@ -35,13 +33,15 @@ struct ssh_bind_struct {
/* options */
char *wanted_methods[10];
char *banner;
char *ecdsakey;
char *dsakey;
char *rsakey;
ssh_key ecdsa;
ssh_key dsa;
ssh_key rsa;
char *bindaddr;
socket_t bindfd;
unsigned int bindport;
unsigned int log_verbosity;
int blocking;
int toaccept;
};

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef BUFFER_H_

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2009 Aris Adamantiadis <aris@0xbadc0de.be>
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* callback.h
@@ -64,22 +63,7 @@ typedef void (*ssh_callback_int_int) (int code, int errno_code, void *user);
typedef int (*ssh_message_callback) (ssh_session, ssh_message message, void *user);
typedef int (*ssh_channel_callback_int) (ssh_channel channel, int code, void *user);
typedef int (*ssh_channel_callback_data) (ssh_channel channel, int code, void *data, size_t len, void *user);
/**
* @brief SSH authentication callback.
*
* @param prompt Prompt to be displayed.
* @param buf Buffer to save the password. You should null-terminate it.
* @param len Length of the buffer.
* @param echo Enable or disable the echo of what you type.
* @param verify Should the password be verified?
* @param userdata Userdata to be passed to the callback function. Useful
* for GUI applications.
*
* @return 0 on success, < 0 on error.
*/
typedef int (*ssh_auth_callback) (const char *prompt, char *buf, size_t len,
int echo, int verify, void *userdata);
/**
* @brief SSH log callback. All logging messages will go through this callback
* @param session Current session handler
@@ -90,6 +74,24 @@ typedef int (*ssh_auth_callback) (const char *prompt, char *buf, size_t len,
typedef void (*ssh_log_callback) (ssh_session session, int priority,
const char *message, void *userdata);
/**
* @brief SSH log callback.
*
* All logging messages will go through this callback.
*
* @param priority Priority of the log, the smaller being the more important.
*
* @param function The function name calling the the logging fucntions.
*
* @param message The actual message
*
* @param userdata Userdata to be passed to the callback function.
*/
typedef void (*ssh_logging_callback) (int priority,
const char *function,
const char *buffer,
void *userdata);
/**
* @brief SSH Connection status callback.
* @param session Current session handler
@@ -110,6 +112,18 @@ typedef void (*ssh_status_callback) (ssh_session session, float status,
typedef void (*ssh_global_request_callback) (ssh_session session,
ssh_message message, void *userdata);
/**
* @brief Handles an SSH new channel open X11 request. This happens when the server
* sends back an X11 connection attempt. This is a client-side API
* @param session current session handler
* @param userdata Userdata to be passed to the callback function.
* @returns a valid ssh_channel handle if the request is to be allowed
* @returns NULL if the request should not be allowed
* @warning The channel pointer returned by this callback must be closed by the application.
*/
typedef ssh_channel (*ssh_channel_open_request_x11_callback) (ssh_session session,
const char * originator_address, int originator_port, void *userdata);
/**
* The structure to replace libssh functions with appropriate callbacks.
*/
@@ -137,9 +151,211 @@ struct ssh_callbacks_struct {
* This function will be called each time a global request is received.
*/
ssh_global_request_callback global_request_function;
/** This function will be called when an incoming X11 request is received.
*/
ssh_channel_open_request_x11_callback channel_open_request_x11_function;
};
typedef struct ssh_callbacks_struct *ssh_callbacks;
/** These are callbacks used specifically in SSH servers.
*/
/**
* @brief SSH authentication callback.
* @param session Current session handler
* @param user User that wants to authenticate
* @param password Password used for authentication
* @param userdata Userdata to be passed to the callback function.
* @returns SSH_AUTH_SUCCESS Authentication is accepted.
* @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
* @returns SSH_AUTH_DENIED Authentication failed.
*/
typedef int (*ssh_auth_password_callback) (ssh_session session, const char *user, const char *password,
void *userdata);
/**
* @brief SSH authentication callback. Tries to authenticates user with the "none" method
* which is anonymous or passwordless.
* @param session Current session handler
* @param user User that wants to authenticate
* @param userdata Userdata to be passed to the callback function.
* @returns SSH_AUTH_SUCCESS Authentication is accepted.
* @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
* @returns SSH_AUTH_DENIED Authentication failed.
*/
typedef int (*ssh_auth_none_callback) (ssh_session session, const char *user, void *userdata);
/**
* @brief SSH authentication callback. Tries to authenticates user with the "gssapi-with-mic" method
* @param session Current session handler
* @param user Username of the user (can be spoofed)
* @param principal Authenticated principal of the user, including realm.
* @param userdata Userdata to be passed to the callback function.
* @returns SSH_AUTH_SUCCESS Authentication is accepted.
* @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
* @returns SSH_AUTH_DENIED Authentication failed.
* @warning Implementations should verify that parameter user matches in some way the principal.
* user and principal can be different. Only the latter is guaranteed to be safe.
*/
typedef int (*ssh_auth_gssapi_mic_callback) (ssh_session session, const char *user, const char *principal,
void *userdata);
/**
* @brief SSH authentication callback.
* @param session Current session handler
* @param user User that wants to authenticate
* @param pubkey public key used for authentication
* @param signature_state SSH_PUBLICKEY_STATE_NONE if the key is not signed (simple public key probe),
* SSH_PUBLICKEY_STATE_VALID if the signature is valid. Others values should be
* replied with a SSH_AUTH_DENIED.
* @param userdata Userdata to be passed to the callback function.
* @returns SSH_AUTH_SUCCESS Authentication is accepted.
* @returns SSH_AUTH_PARTIAL Partial authentication, more authentication means are needed.
* @returns SSH_AUTH_DENIED Authentication failed.
*/
typedef int (*ssh_auth_pubkey_callback) (ssh_session session, const char *user, struct ssh_key_struct *pubkey,
char signature_state, void *userdata);
/**
* @brief Handles an SSH service request
* @param session current session handler
* @param service name of the service (e.g. "ssh-userauth") requested
* @param userdata Userdata to be passed to the callback function.
* @returns 0 if the request is to be allowed
* @returns -1 if the request should not be allowed
*/
typedef int (*ssh_service_request_callback) (ssh_session session, const char *service, void *userdata);
/**
* @brief Handles an SSH new channel open session request
* @param session current session handler
* @param userdata Userdata to be passed to the callback function.
* @returns a valid ssh_channel handle if the request is to be allowed
* @returns NULL if the request should not be allowed
* @warning The channel pointer returned by this callback must be closed by the application.
*/
typedef ssh_channel (*ssh_channel_open_request_session_callback) (ssh_session session, void *userdata);
/*
* @brief handle the beginning of a GSSAPI authentication, server side.
* @param session current session handler
* @param user the username of the client
* @param n_oid number of available oids
* @param oids OIDs provided by the client
* @returns an ssh_string containing the chosen OID, that's supported by both
* client and server.
* @warning It is not necessary to fill this callback in if libssh is linked
* with libgssapi.
*/
typedef ssh_string (*ssh_gssapi_select_oid_callback) (ssh_session session, const char *user,
int n_oid, ssh_string *oids, void *userdata);
/*
* @brief handle the negociation of a security context, server side.
* @param session current session handler
* @param[in] input_token input token provided by client
* @param[out] output_token output of the gssapi accept_sec_context method,
* NULL after completion.
* @returns SSH_OK if the token was generated correctly or accept_sec_context
* returned GSS_S_COMPLETE
* @returns SSH_ERROR in case of error
* @warning It is not necessary to fill this callback in if libssh is linked
* with libgssapi.
*/
typedef int (*ssh_gssapi_accept_sec_ctx_callback) (ssh_session session,
ssh_string input_token, ssh_string *output_token, void *userdata);
/*
* @brief Verify and authenticates a MIC, server side.
* @param session current session handler
* @param[in] mic input mic to be verified provided by client
* @param[in] mic_buffer buffer of data to be signed.
* @param[in] mic_buffer_size size of mic_buffer
* @returns SSH_OK if the MIC was authenticated correctly
* @returns SSH_ERROR in case of error
* @warning It is not necessary to fill this callback in if libssh is linked
* with libgssapi.
*/
typedef int (*ssh_gssapi_verify_mic_callback) (ssh_session session,
ssh_string mic, void *mic_buffer, size_t mic_buffer_size, void *userdata);
/**
* This structure can be used to implement a libssh server, with appropriate callbacks.
*/
struct ssh_server_callbacks_struct {
/** DON'T SET THIS use ssh_callbacks_init() instead. */
size_t size;
/**
* User-provided data. User is free to set anything he wants here
*/
void *userdata;
/** This function gets called when a client tries to authenticate through
* password method.
*/
ssh_auth_password_callback auth_password_function;
/** This function gets called when a client tries to authenticate through
* none method.
*/
ssh_auth_none_callback auth_none_function;
/** This function gets called when a client tries to authenticate through
* gssapi-mic method.
*/
ssh_auth_gssapi_mic_callback auth_gssapi_mic_function;
/** this function gets called when a client tries to authenticate or offer
* a public key.
*/
ssh_auth_pubkey_callback auth_pubkey_function;
/** This functions gets called when a service request is issued by the
* client
*/
ssh_service_request_callback service_request_function;
/** This functions gets called when a new channel request is issued by
* the client
*/
ssh_channel_open_request_session_callback channel_open_request_session_function;
/** This function will be called when a new gssapi authentication is attempted.
*/
ssh_gssapi_select_oid_callback gssapi_select_oid_function;
/** This function will be called when a gssapi token comes in.
*/
ssh_gssapi_accept_sec_ctx_callback gssapi_accept_sec_ctx_function;
/* This function will be called when a MIC needs to be verified.
*/
ssh_gssapi_verify_mic_callback gssapi_verify_mic_function;
};
typedef struct ssh_server_callbacks_struct *ssh_server_callbacks;
/**
* @brief Set the session server callback functions.
*
* This functions sets the callback structure to use your own callback
* functions for user authentication, new channels and requests.
*
* @code
* struct ssh_server_callbacks_struct cb = {
* .userdata = data,
* .auth_password_function = my_auth_function
* };
* ssh_callbacks_init(&cb);
* ssh_set_server_callbacks(session, &cb);
* @endcode
*
* @param session The session to set the callback structure.
*
* @param cb The callback structure itself.
*
* @return SSH_OK on success, SSH_ERROR on error.
*/
LIBSSH_API int ssh_set_server_callbacks(ssh_session session, ssh_server_callbacks cb);
/**
* These are the callbacks exported by the socket structure
* They are called by the socket module when a socket event appears
@@ -279,6 +495,8 @@ LIBSSH_API int ssh_set_callbacks(ssh_session session, ssh_callbacks cb);
* @param len the length of the data
* @param is_stderr is 0 for stdout or 1 for stderr
* @param userdata Userdata to be passed to the callback function.
* @returns number of bytes processed by the callee. The remaining bytes will
* be sent in the next callback message, when more data is available.
*/
typedef int (*ssh_channel_data_callback) (ssh_session session,
ssh_channel channel,
@@ -348,6 +566,120 @@ typedef void (*ssh_channel_exit_signal_callback) (ssh_session session,
const char *lang,
void *userdata);
/**
* @brief SSH channel PTY request from a client.
* @param channel the channel
* @param term The type of terminal emulation
* @param width width of the terminal, in characters
* @param height height of the terminal, in characters
* @param pxwidth width of the terminal, in pixels
* @param pxheight height of the terminal, in pixels
* @param userdata Userdata to be passed to the callback function.
* @returns 0 if the pty request is accepted
* @returns -1 if the request is denied
*/
typedef int (*ssh_channel_pty_request_callback) (ssh_session session,
ssh_channel channel,
const char *term,
int width, int height,
int pxwidth, int pwheight,
void *userdata);
/**
* @brief SSH channel Shell request from a client.
* @param channel the channel
* @param userdata Userdata to be passed to the callback function.
* @returns 0 if the shell request is accepted
* @returns 1 if the request is denied
*/
typedef int (*ssh_channel_shell_request_callback) (ssh_session session,
ssh_channel channel,
void *userdata);
/**
* @brief SSH auth-agent-request from the client. This request is
* sent by a client when agent forwarding is available.
* Server is free to ignore this callback, no answer is expected.
* @param channel the channel
* @param userdata Userdata to be passed to the callback function.
*/
typedef void (*ssh_channel_auth_agent_req_callback) (ssh_session session,
ssh_channel channel,
void *userdata);
/**
* @brief SSH X11 request from the client. This request is
* sent by a client when X11 forwarding is requested(and available).
* Server is free to ignore this callback, no answer is expected.
* @param channel the channel
* @param userdata Userdata to be passed to the callback function.
*/
typedef void (*ssh_channel_x11_req_callback) (ssh_session session,
ssh_channel channel,
int single_connection,
const char *auth_protocol,
const char *auth_cookie,
uint32_t screen_number,
void *userdata);
/**
* @brief SSH channel PTY windows change (terminal size) from a client.
* @param channel the channel
* @param width width of the terminal, in characters
* @param height height of the terminal, in characters
* @param pxwidth width of the terminal, in pixels
* @param pxheight height of the terminal, in pixels
* @param userdata Userdata to be passed to the callback function.
* @returns 0 if the pty request is accepted
* @returns -1 if the request is denied
*/
typedef int (*ssh_channel_pty_window_change_callback) (ssh_session session,
ssh_channel channel,
int width, int height,
int pxwidth, int pwheight,
void *userdata);
/**
* @brief SSH channel Exec request from a client.
* @param channel the channel
* @param command the shell command to be executed
* @param userdata Userdata to be passed to the callback function.
* @returns 0 if the exec request is accepted
* @returns 1 if the request is denied
*/
typedef int (*ssh_channel_exec_request_callback) (ssh_session session,
ssh_channel channel,
const char *command,
void *userdata);
/**
* @brief SSH channel environment request from a client.
* @param channel the channel
* @param env_name name of the environment value to be set
* @param env_value value of the environment value to be set
* @param userdata Userdata to be passed to the callback function.
* @returns 0 if the env request is accepted
* @returns 1 if the request is denied
* @warning some environment variables can be dangerous if changed (e.g.
* LD_PRELOAD) and should not be fulfilled.
*/
typedef int (*ssh_channel_env_request_callback) (ssh_session session,
ssh_channel channel,
const char *env_name,
const char *env_value,
void *userdata);
/**
* @brief SSH channel subsystem request from a client.
* @param channel the channel
* @param subsystem the subsystem required
* @param userdata Userdata to be passed to the callback function.
* @returns 0 if the subsystem request is accepted
* @returns 1 if the request is denied
*/
typedef int (*ssh_channel_subsystem_request_callback) (ssh_session session,
ssh_channel channel,
const char *subsystem,
void *userdata);
struct ssh_channel_callbacks_struct {
/** DON'T SET THIS use ssh_callbacks_init() instead. */
size_t size;
@@ -379,7 +711,40 @@ struct ssh_channel_callbacks_struct {
* This functions will be called when an exit signal has been received
*/
ssh_channel_exit_signal_callback channel_exit_signal_function;
/**
* This function will be called when a client requests a PTY
*/
ssh_channel_pty_request_callback channel_pty_request_function;
/**
* This function will be called when a client requests a shell
*/
ssh_channel_shell_request_callback channel_shell_request_function;
/** This function will be called when a client requests agent
* authentication forwarding.
*/
ssh_channel_auth_agent_req_callback channel_auth_agent_req_function;
/** This function will be called when a client requests X11
* forwarding.
*/
ssh_channel_x11_req_callback channel_x11_req_function;
/** This function will be called when a client requests a
* window change.
*/
ssh_channel_pty_window_change_callback channel_pty_window_change_function;
/** This function will be called when a client requests a
* command execution.
*/
ssh_channel_exec_request_callback channel_exec_request_function;
/** This function will be called when a client requests an environment
* variable to be set.
*/
ssh_channel_env_request_callback channel_env_request_function;
/** This function will be called when a client requests a subsystem
* (like sftp).
*/
ssh_channel_subsystem_request_callback channel_subsystem_request_function;
};
typedef struct ssh_channel_callbacks_struct *ssh_channel_callbacks;
/**
@@ -425,14 +790,21 @@ struct ssh_threads_callbacks_struct {
};
/**
* @brief sets the thread callbacks necessary if your program is using
* libssh in a multithreaded fashion. This function must be called first,
* outside of any threading context (in your main() for instance), before
* ssh_init().
* @param cb pointer to a ssh_threads_callbacks_struct structure, which contains
* the different callbacks to be set.
* @brief Set the thread callbacks structure.
*
* This is necessary if your program is using libssh in a multithreaded fashion.
* This function must be called first, outside of any threading context (in your
* main() function for instance), before you call ssh_init().
*
* @param[in] cb A pointer to a ssh_threads_callbacks_struct structure, which
* contains the different callbacks to be set.
*
* @returns Always returns SSH_OK.
*
* @see ssh_threads_callbacks_struct
* @see SSH_THREADS_PTHREAD
* @bug libgcrypt 1.6 and bigger backend does not support custom callback.
* Using anything else than pthreads here will fail.
*/
LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct
*cb);
@@ -446,13 +818,33 @@ LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct
LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_pthread(void);
/**
* @brief returns a pointer on the noop threads callbacks, to be used with
* ssh_threads_set_callbacks. These callbacks do nothing and are being used by
* default.
* @brief Get the noop threads callbacks structure
*
* This can be used with ssh_threads_set_callbacks. These callbacks do nothing
* and are being used by default.
*
* @return Always returns a valid pointer to the noop callbacks structure.
*
* @see ssh_threads_set_callbacks
*/
LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_noop(void);
/**
* @brief Set the logging callback function.
*
* @param[in] cb The callback to set.
*
* @return 0 on success, < 0 on errror.
*/
LIBSSH_API int ssh_set_log_callback(ssh_logging_callback cb);
/**
* @brief Get the pointer to the logging callback function.
*
* @return The pointer the the callback or NULL if none set.
*/
LIBSSH_API ssh_logging_callback ssh_get_log_callback(void);
/** @} */
#ifdef __cplusplus
}

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef CHANNELS_H_
@@ -42,11 +41,19 @@ enum ssh_channel_request_state_e {
enum ssh_channel_state_e {
SSH_CHANNEL_STATE_NOT_OPEN = 0,
SSH_CHANNEL_STATE_OPENING,
SSH_CHANNEL_STATE_OPEN_DENIED,
SSH_CHANNEL_STATE_OPEN,
SSH_CHANNEL_STATE_CLOSED
};
/* The channel has been closed by the remote side */
#define SSH_CHANNEL_FLAG_CLOSED_REMOTE 0x1
/* The channel has been freed by the calling program */
#define SSH_CHANNEL_FLAG_FREED_LOCAL 0x2
/* the channel has not yet been bound to a remote one */
#define SSH_CHANNEL_FLAG_NOT_BOUND 0x4
struct ssh_channel_struct {
ssh_session session; /* SSH_SESSION pointer */
uint32_t local_channel;
@@ -60,11 +67,11 @@ struct ssh_channel_struct {
uint32_t remote_maxpacket;
enum ssh_channel_state_e state;
int delayed_close;
int flags;
ssh_buffer stdout_buffer;
ssh_buffer stderr_buffer;
void *userarg;
int version;
int blocking;
int exit_status;
enum ssh_channel_request_state_e request_state;
ssh_channel_callbacks callbacks;
@@ -86,10 +93,12 @@ SSH_PACKET_CALLBACK(channel_rcv_data);
ssh_channel ssh_channel_new(ssh_session session);
int channel_default_bufferize(ssh_channel channel, void *data, int len,
int is_stderr);
int ssh_channel_flush(ssh_channel channel);
uint32_t ssh_channel_new_id(ssh_session session);
ssh_channel ssh_channel_from_local(ssh_session session, uint32_t id);
int channel_write_common(ssh_channel channel, const void *data,
uint32_t len, int is_stderr);
void ssh_channel_do_free(ssh_channel channel);
#ifdef WITH_SSH1
SSH_PACKET_CALLBACK(ssh_packet_data1);
SSH_PACKET_CALLBACK(ssh_packet_close1);

28
include/libssh/crc32.h Normal file
View File

@@ -0,0 +1,28 @@
/*
* crc32.c - simple CRC32 code
*
* This file is part of the SSH Library
*
* Copyright (c) 2005 by Aris Adamantiadis
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _CRC32_H
#define _CRC32_H
uint32_t ssh_crc32(const char *buf, uint32_t len);
#endif /* _CRC32_H */

View File

@@ -1,22 +1,21 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2003,2009 by Aris Adamantiadis
* Copyright (c) 2003-2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
@@ -40,20 +39,48 @@
#undef cbc_decrypt
#endif
#ifdef HAVE_OPENSSL_ECDH_H
#include <openssl/ecdh.h>
#endif
#include "libssh/ecdh.h"
#include "libssh/kex.h"
#include "libssh/curve25519.h"
enum ssh_key_exchange_e {
/* diffie-hellman-group1-sha1 */
SSH_KEX_DH_GROUP1_SHA1=1,
/* diffie-hellman-group14-sha1 */
SSH_KEX_DH_GROUP14_SHA1,
/* ecdh-sha2-nistp256 */
SSH_KEX_ECDH_SHA2_NISTP256,
/* curve25519-sha256@libssh.org */
SSH_KEX_CURVE25519_SHA256_LIBSSH_ORG
};
struct ssh_crypto_struct {
bignum e,f,x,k,y;
unsigned char session_id[SHA_DIGEST_LEN];
unsigned char encryptIV[SHA_DIGEST_LEN*2];
unsigned char decryptIV[SHA_DIGEST_LEN*2];
unsigned char decryptkey[SHA_DIGEST_LEN*2];
unsigned char encryptkey[SHA_DIGEST_LEN*2];
unsigned char encryptMAC[SHA_DIGEST_LEN];
unsigned char decryptMAC[SHA_DIGEST_LEN];
#ifdef HAVE_ECDH
EC_KEY *ecdh_privkey;
ssh_string ecdh_client_pubkey;
ssh_string ecdh_server_pubkey;
#endif
#ifdef HAVE_CURVE25519
ssh_curve25519_privkey curve25519_privkey;
ssh_curve25519_pubkey curve25519_client_pubkey;
ssh_curve25519_pubkey curve25519_server_pubkey;
#endif
ssh_string dh_server_signature; /* information used by dh_handshake. */
size_t digest_len; /* len of all the fields below */
unsigned char *session_id;
unsigned char *secret_hash; /* Secret hash is same as session id until re-kex */
unsigned char *encryptIV;
unsigned char *decryptIV;
unsigned char *decryptkey;
unsigned char *encryptkey;
unsigned char *encryptMAC;
unsigned char *decryptMAC;
unsigned char hmacbuf[EVP_MAX_MD_SIZE];
struct crypto_struct *in_cipher, *out_cipher; /* the cipher structures/objects */
struct ssh_cipher_struct *in_cipher, *out_cipher; /* the cipher structures/objects */
ssh_string server_pubkey;
const char *server_pubkey_type;
int do_compress_out; /* idem */
@@ -62,9 +89,15 @@ struct ssh_crypto_struct {
int delayed_compress_out;
void *compress_out_ctx; /* don't touch it */
void *compress_in_ctx; /* really, don't */
/* kex sent by server, client, and mutually elected methods */
struct ssh_kex_struct server_kex;
struct ssh_kex_struct client_kex;
char *kex_methods[SSH_KEX_METHODS];
enum ssh_key_exchange_e kex_type;
enum ssh_mac_e mac_type; /* Mac operations to use for key gen */
};
struct crypto_struct {
struct ssh_cipher_struct {
const char *name; /* ssh name of the algorithm */
unsigned int blocksize; /* blocksize of the algo */
unsigned int keylen; /* length of the key structure */
@@ -72,25 +105,16 @@ struct crypto_struct {
gcry_cipher_hd_t *key;
#elif defined HAVE_LIBCRYPTO
void *key; /* a key buffer allocated for the algo */
void *IV;
#endif
unsigned int keysize; /* bytes of key used. != keylen */
#ifdef HAVE_LIBGCRYPT
/* sets the new key for immediate use */
int (*set_encrypt_key)(struct crypto_struct *cipher, void *key, void *IV);
int (*set_decrypt_key)(struct crypto_struct *cipher, void *key, void *IV);
void (*cbc_encrypt)(struct crypto_struct *cipher, void *in, void *out,
int (*set_encrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);
int (*set_decrypt_key)(struct ssh_cipher_struct *cipher, void *key, void *IV);
void (*cbc_encrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,
unsigned long len);
void (*cbc_decrypt)(struct crypto_struct *cipher, void *in, void *out,
void (*cbc_decrypt)(struct ssh_cipher_struct *cipher, void *in, void *out,
unsigned long len);
#elif defined HAVE_LIBCRYPTO
/* sets the new key for immediate use */
int (*set_encrypt_key)(struct crypto_struct *cipher, void *key);
int (*set_decrypt_key)(struct crypto_struct *cipher, void *key);
void (*cbc_encrypt)(struct crypto_struct *cipher, void *in, void *out,
unsigned long len, void *IV);
void (*cbc_decrypt)(struct crypto_struct *cipher, void *in, void *out,
unsigned long len, void *IV);
#endif
};
/* vim: set ts=2 sw=2 et cindent: */

View File

@@ -0,0 +1,57 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2013 by Aris Adamantiadis <aris@badcode.be>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation,
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef CURVE25519_H_
#define CURVE25519_H_
#include "config.h"
#include "libssh.h"
#ifdef WITH_NACL
#include <nacl/crypto_scalarmult_curve25519.h>
#define CURVE25519_PUBKEY_SIZE crypto_scalarmult_curve25519_BYTES
#define CURVE25519_PRIVKEY_SIZE crypto_scalarmult_curve25519_SCALARBYTES
#define crypto_scalarmult_base crypto_scalarmult_curve25519_base
#define crypto_scalarmult crypto_scalarmult_curve25519
#else
#define CURVE25519_PUBKEY_SIZE 32
#define CURVE25519_PRIVKEY_SIZE 32
int crypto_scalarmult_base(unsigned char *q, const unsigned char *n);
int crypto_scalarmult(unsigned char *q, const unsigned char *n, const unsigned char *p);
#endif /* WITH_NACL */
#ifdef HAVE_ECC
#define HAVE_CURVE25519 1
#endif
typedef unsigned char ssh_curve25519_pubkey[CURVE25519_PUBKEY_SIZE];
typedef unsigned char ssh_curve25519_privkey[CURVE25519_PRIVKEY_SIZE];
int ssh_client_curve25519_init(ssh_session session);
int ssh_client_curve25519_reply(ssh_session session, ssh_buffer packet);
#ifdef WITH_SERVER
int ssh_server_curve25519_init(ssh_session session, ssh_buffer packet);
#endif /* WITH_SERVER */
#endif /* CURVE25519_H_ */

View File

@@ -3,28 +3,27 @@
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef DH_H_
#define DH_H_
#include "config.h"
/* DH key generation */
#include "libssh/keys.h"
#include "libssh/crypto.h"
void ssh_print_bignum(const char *which,bignum num);
int dh_generate_e(ssh_session session);
@@ -41,17 +40,18 @@ int dh_import_f(ssh_session session,ssh_string f_string);
int dh_import_e(ssh_session session, ssh_string e_string);
void dh_import_pubkey(ssh_session session,ssh_string pubkey_string);
int dh_build_k(ssh_session session);
int ssh_client_dh_init(ssh_session session);
int ssh_client_dh_reply(ssh_session session, ssh_buffer packet);
int make_sessionid(ssh_session session);
/* add data for the final cookie */
int hashbufin_add_cookie(ssh_session session, unsigned char *cookie);
int hashbufout_add_cookie(ssh_session session);
int generate_session_keys(ssh_session session);
int sig_verify(ssh_session session, ssh_public_key pubkey,
SIGNATURE *signature, unsigned char *digest, int size);
/* returns 1 if server signature ok, 0 otherwise. The NEXT crypto is checked, not the current one */
int signature_verify(ssh_session session,ssh_string signature);
bignum make_string_bn(ssh_string string);
#ifdef HAVE_LIBCRYPTO
void make_string_bn_inplace(ssh_string string, bignum bnout);
#endif /* HAVE_LIBCRYPTO */
ssh_string make_bignum_string(bignum num);
#endif /* DH_H_ */

43
include/libssh/ecdh.h Normal file
View File

@@ -0,0 +1,43 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2011 by Aris Adamantiadis
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ECDH_H_
#define ECDH_H_
#include "config.h"
#ifdef HAVE_LIBCRYPTO
#ifdef HAVE_OPENSSL_ECDH_H
#ifdef HAVE_ECC
#define HAVE_ECDH 1
#endif
#endif /* HAVE_OPENSSL_ECDH_H */
#endif /* HAVE_LIBCRYPTO */
int ssh_client_ecdh_init(ssh_session session);
int ssh_client_ecdh_reply(ssh_session session, ssh_buffer packet);
#ifdef WITH_SERVER
int ssh_server_ecdh_init(ssh_session session, ssh_buffer packet);
#endif /* WITH_SERVER */
#endif /* ECDH_H_ */

45
include/libssh/gssapi.h Normal file
View File

@@ -0,0 +1,45 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2013 by Aris Adamantiadis
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef GSSAPI_H_
#define GSSAPI_H_
#include "config.h"
#include "session.h"
/* all OID begin with the tag identifier + length */
#define SSH_OID_TAG 06
typedef struct ssh_gssapi_struct *ssh_gssapi;
#ifdef WITH_SERVER
int ssh_gssapi_handle_userauth(ssh_session session, const char *user, uint32_t n_oid, ssh_string *oids);
SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token_server);
SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_mic);
#endif /* WITH_SERVER */
SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token);
SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_token_client);
SSH_PACKET_CALLBACK(ssh_packet_userauth_gssapi_response);
int ssh_gssapi_auth_mic(ssh_session session);
#endif /* GSSAPI_H */

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef KEX_H_
@@ -25,9 +24,27 @@
#include "libssh/priv.h"
#include "libssh/callbacks.h"
#define SSH_KEX_METHODS 10
struct ssh_kex_struct {
unsigned char cookie[16];
char *methods[SSH_KEX_METHODS];
};
SSH_PACKET_CALLBACK(ssh_packet_kexinit);
#ifdef WITH_SSH1
SSH_PACKET_CALLBACK(ssh_packet_publickey1);
#endif
int ssh_send_kex(ssh_session session, int server_kex);
void ssh_list_kex(struct ssh_kex_struct *kex);
int set_client_kex(ssh_session session);
int ssh_kex_select_methods(ssh_session session);
int verify_existing_algo(int algo, const char *name);
char **space_tokenize(const char *chain);
int ssh_get_kex1(ssh_session session);
char *ssh_find_matching(const char *in_d, const char *what_d);
const char *ssh_kex_get_supported_method(uint32_t algo);
const char *ssh_kex_get_description(uint32_t algo);
#endif /* KEX_H_ */

View File

@@ -1,33 +0,0 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
#ifndef KEYFILES_H_
#define KEYFILES_H_
/* in keyfiles.c */
ssh_private_key _privatekey_from_file(void *session, const char *filename,
int type);
ssh_string try_publickey_from_file(ssh_session session,
struct ssh_keys_struct keytab,
char **privkeyfile, int *type);
#endif /* KEYFILES_H_ */

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef KEYS_H_
@@ -49,36 +48,9 @@ struct ssh_private_key_struct {
#endif
};
typedef struct signature_struct {
int type;
#ifdef HAVE_LIBGCRYPT
gcry_sexp_t dsa_sign;
gcry_sexp_t rsa_sign;
#elif defined HAVE_LIBCRYPTO
DSA_SIG *dsa_sign;
ssh_string rsa_sign;
#endif
} SIGNATURE;
const char *ssh_type_to_char(int type);
int ssh_type_from_name(const char *name);
ssh_buffer ssh_userauth_build_digest(ssh_session session, ssh_message msg, char *service);
ssh_private_key privatekey_make_dss(ssh_session session, ssh_buffer buffer);
ssh_private_key privatekey_make_rsa(ssh_session session, ssh_buffer buffer,
const char *type);
ssh_private_key privatekey_from_string(ssh_session session, ssh_string privkey_s);
ssh_public_key publickey_make_dss(ssh_session session, ssh_buffer buffer);
ssh_public_key publickey_make_rsa(ssh_session session, ssh_buffer buffer, int type);
ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s);
SIGNATURE *signature_from_string(ssh_session session, ssh_string signature,ssh_public_key pubkey,int needed_type);
void signature_free(SIGNATURE *sign);
ssh_string ssh_do_sign_with_agent(struct ssh_session_struct *session,
struct ssh_buffer_struct *buf, struct ssh_public_key_struct *publickey);
ssh_string ssh_do_sign(ssh_session session,ssh_buffer sigbuf,
ssh_private_key privatekey);
ssh_string ssh_sign_session_id(ssh_session session, ssh_private_key privatekey);
ssh_string ssh_encrypt_rsa1(ssh_session session, ssh_string data, ssh_public_key key);
#endif /* KEYS_H_ */

View File

@@ -0,0 +1,27 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 20014 by Aris Adamantiadis <aris@badcode.be>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef KNOWNHOSTS_H_
#define KNOWNHOSTS_H_
char **ssh_knownhosts_algorithms(ssh_session session);
#endif /* KNOWNHOSTS_H_ */

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2010 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/* Since libssh.h includes legacy.h, it's important that libssh.h is included
@@ -26,10 +25,23 @@
* removed in future.
*/
#include "libssh/libssh.h"
#ifndef LEGACY_H_
#define LEGACY_H_
typedef struct ssh_private_key_struct* ssh_private_key;
typedef struct ssh_public_key_struct* ssh_public_key;
LIBSSH_API int ssh_auth_list(ssh_session session);
LIBSSH_API int ssh_userauth_offer_pubkey(ssh_session session, const char *username, int type, ssh_string publickey);
LIBSSH_API int ssh_userauth_pubkey(ssh_session session, const char *username, ssh_string publickey, ssh_private_key privatekey);
#ifndef _WIN32
LIBSSH_API int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
ssh_public_key publickey);
#endif
LIBSSH_API int ssh_userauth_autopubkey(ssh_session session, const char *passphrase);
LIBSSH_API int ssh_userauth_privatekey_file(ssh_session session, const char *username,
const char *filename, const char *passphrase);
LIBSSH_API void buffer_free(ssh_buffer buffer);
LIBSSH_API void *buffer_get(ssh_buffer buffer);
LIBSSH_API uint32_t buffer_get_len(ssh_buffer buffer);
@@ -86,7 +98,15 @@ LIBSSH_API ssh_string publickey_from_file(ssh_session session, const char *filen
int *type);
LIBSSH_API ssh_public_key publickey_from_privatekey(ssh_private_key prv);
LIBSSH_API ssh_string publickey_to_string(ssh_public_key key);
LIBSSH_API int ssh_try_publickey_from_file(ssh_session session, const char *keyfile,
ssh_string *publickey, int *type);
LIBSSH_API enum ssh_keytypes_e ssh_privatekey_type(ssh_private_key privatekey);
LIBSSH_API ssh_string ssh_get_pubkey(ssh_session session);
LIBSSH_API ssh_message ssh_message_retrieve(ssh_session session, uint32_t packettype);
LIBSSH_API ssh_public_key ssh_message_auth_publickey(ssh_message msg);
LIBSSH_API void string_burn(ssh_string str);
LIBSSH_API ssh_string string_copy(ssh_string str);
LIBSSH_API void *string_data(ssh_string str);

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LIBCRYPTO_H_
@@ -31,9 +30,19 @@
#include <openssl/sha.h>
#include <openssl/md5.h>
#include <openssl/hmac.h>
#ifdef HAVE_OPENSSL_ECC
#include <openssl/evp.h>
#endif
typedef SHA_CTX* SHACTX;
typedef SHA256_CTX* SHA256CTX;
typedef MD5_CTX* MD5CTX;
typedef HMAC_CTX* HMACCTX;
#ifdef HAVE_ECC
typedef EVP_MD_CTX *EVPCTX;
#else
typedef void *EVPCTX;
#endif
#define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
#ifdef MD5_DIGEST_LEN
@@ -41,6 +50,10 @@ typedef HMAC_CTX* HMACCTX;
#endif
#define MD5_DIGEST_LEN MD5_DIGEST_LENGTH
#ifdef HAVE_OPENSSL_ECC
#define EVP_DIGEST_LEN EVP_MAX_MD_SIZE
#endif
#include <openssl/bn.h>
#include <openssl/opensslv.h>
#define OPENSSL_0_9_7b 0x0090702fL
@@ -67,7 +80,11 @@ typedef BN_CTX* bignum_CTX;
#define bignum_bn2bin(num,ptr) BN_bn2bin(num,ptr)
#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
struct crypto_struct *ssh_get_ciphertab(void);
SHA256CTX sha256_init(void);
void sha256_update(SHA256CTX c, const void *data, unsigned long len);
void sha256_final(unsigned char *md, SHA256CTX c);
struct ssh_cipher_struct *ssh_get_ciphertab(void);
#endif /* HAVE_LIBCRYPTO */

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LIBGCRYPT_H_
@@ -30,12 +29,26 @@
typedef gcry_md_hd_t SHACTX;
typedef gcry_md_hd_t MD5CTX;
typedef gcry_md_hd_t HMACCTX;
#define SHA_DIGEST_LEN 20
typedef void *EVPCTX;
#define SHA_DIGEST_LENGTH 20
#define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
#define MD5_DIGEST_LEN 16
#define SHA256_DIGEST_LENGTH 32
#define SHA384_DIGEST_LENGTH 48
#define SHA512_DIGEST_LENGTH 64
#ifndef EVP_MAX_MD_SIZE
#define EVP_MAX_MD_SIZE 36
#endif
#define EVP_DIGEST_LEN EVP_MAX_MD_SIZE
typedef gcry_mpi_t bignum;
/* missing gcrypt functions */
int my_gcry_dec2bn(bignum *bn, const char *data);
char *my_gcry_bn2dec(bignum bn);
#define bignum_new() gcry_mpi_new(0)
#define bignum_free(num) gcry_mpi_release(num)
#define bignum_set_word(bn,n) gcry_mpi_set_ui(bn,n)
@@ -52,9 +65,8 @@ typedef gcry_mpi_t bignum;
#define bignum_bn2bin(num,datalen,data) gcry_mpi_print(GCRYMPI_FMT_USG,data,datalen,NULL,num)
#define bignum_cmp(num1,num2) gcry_mpi_cmp(num1,num2)
#endif /* HAVE_LIBGCRYPT */
struct crypto_struct *ssh_get_ciphertab(void);
struct ssh_cipher_struct *ssh_get_ciphertab(void);
#endif /* LIBGCRYPT_H_ */

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2003-2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _LIBSSH_H
@@ -78,8 +77,8 @@
/* libssh version */
#define LIBSSH_VERSION_MAJOR 0
#define LIBSSH_VERSION_MINOR 5
#define LIBSSH_VERSION_MICRO 2
#define LIBSSH_VERSION_MINOR 6
#define LIBSSH_VERSION_MICRO 5
#define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \
LIBSSH_VERSION_MINOR, \
@@ -111,12 +110,12 @@ typedef struct ssh_buffer_struct* ssh_buffer;
typedef struct ssh_channel_struct* ssh_channel;
typedef struct ssh_message_struct* ssh_message;
typedef struct ssh_pcap_file_struct* ssh_pcap_file;
typedef struct ssh_private_key_struct* ssh_private_key;
typedef struct ssh_public_key_struct* ssh_public_key;
typedef struct ssh_key_struct* ssh_key;
typedef struct ssh_scp_struct* ssh_scp;
typedef struct ssh_session_struct* ssh_session;
typedef struct ssh_string_struct* ssh_string;
typedef struct ssh_event_struct* ssh_event;
typedef void* ssh_gssapi_creds;
/* Socket type */
#ifdef _WIN32
@@ -166,6 +165,7 @@ enum ssh_auth_e {
#define SSH_AUTH_METHOD_PUBLICKEY 0x0004
#define SSH_AUTH_METHOD_HOSTBASED 0x0008
#define SSH_AUTH_METHOD_INTERACTIVE 0x0010
#define SSH_AUTH_METHOD_GSSAPI_MIC 0x0020
/* messages */
enum ssh_requests_e {
@@ -191,7 +191,8 @@ enum ssh_channel_requests_e {
SSH_CHANNEL_REQUEST_SHELL,
SSH_CHANNEL_REQUEST_ENV,
SSH_CHANNEL_REQUEST_SUBSYSTEM,
SSH_CHANNEL_REQUEST_WINDOW_CHANGE
SSH_CHANNEL_REQUEST_WINDOW_CHANGE,
SSH_CHANNEL_REQUEST_X11
};
enum ssh_global_requests_e {
@@ -207,10 +208,15 @@ enum ssh_publickey_state_e {
SSH_PUBLICKEY_STATE_WRONG=2
};
/* status flags */
/* Status flags */
/** Socket is closed */
#define SSH_CLOSED 0x01
/** Reading to socket won't block */
#define SSH_READ_PENDING 0x02
/** Session was closed due to an error */
#define SSH_CLOSED_ERROR 0x04
/** Output buffer not empty */
#define SSH_WRITE_PENDING 0x08
enum ssh_server_known_e {
SSH_SERVER_ERROR=-1,
@@ -238,7 +244,13 @@ enum ssh_keytypes_e{
SSH_KEYTYPE_UNKNOWN=0,
SSH_KEYTYPE_DSS=1,
SSH_KEYTYPE_RSA,
SSH_KEYTYPE_RSA1
SSH_KEYTYPE_RSA1,
SSH_KEYTYPE_ECDSA
};
enum ssh_keycmp_e {
SSH_KEY_CMP_PUBLIC = 0,
SSH_KEY_CMP_PRIVATE
};
/* Error return codes */
@@ -253,16 +265,13 @@ enum ssh_keytypes_e{
* @{
*/
/**
* @brief Verbosity level for logging and help to debugging
*/
enum {
/** No logging at all
*/
SSH_LOG_NOLOG=0,
/** Only rare and noteworthy events
/** Only warnings
*/
SSH_LOG_RARE,
SSH_LOG_WARNING,
/** High level protocol information
*/
SSH_LOG_PROTOCOL,
@@ -273,6 +282,27 @@ enum {
*/
SSH_LOG_FUNCTIONS
};
/** @} */
#define SSH_LOG_RARE SSH_LOG_WARNING
/**
* @name Logging levels
*
* @brief Debug levels for logging.
* @{
*/
/** No logging at all */
#define SSH_LOG_NONE 0
/** Show only warnings */
#define SSH_LOG_WARN 1
/** Get some information what's going on */
#define SSH_LOG_INFO 2
/** Get detailed debuging information **/
#define SSH_LOG_DEBUG 3
/** Get trace output, packet information, ... */
#define SSH_LOG_TRACE 4
/** @} */
enum ssh_options_e {
@@ -299,7 +329,12 @@ enum ssh_options_e {
SSH_OPTIONS_BINDADDR,
SSH_OPTIONS_STRICTHOSTKEYCHECK,
SSH_OPTIONS_COMPRESSION,
SSH_OPTIONS_COMPRESSION_LEVEL
SSH_OPTIONS_COMPRESSION_LEVEL,
SSH_OPTIONS_KEY_EXCHANGE,
SSH_OPTIONS_HOSTKEYS,
SSH_OPTIONS_GSSAPI_SERVER_IDENTITY,
SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY,
SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS,
};
enum {
@@ -334,11 +369,15 @@ LIBSSH_API int ssh_channel_is_closed(ssh_channel channel);
LIBSSH_API int ssh_channel_is_eof(ssh_channel channel);
LIBSSH_API int ssh_channel_is_open(ssh_channel channel);
LIBSSH_API ssh_channel ssh_channel_new(ssh_session session);
LIBSSH_API int ssh_channel_open_auth_agent(ssh_channel channel);
LIBSSH_API int ssh_channel_open_forward(ssh_channel channel, const char *remotehost,
int remoteport, const char *sourcehost, int localport);
LIBSSH_API int ssh_channel_open_session(ssh_channel channel);
LIBSSH_API int ssh_channel_open_x11(ssh_channel channel, const char *orig_addr, int orig_port);
LIBSSH_API int ssh_channel_poll(ssh_channel channel, int is_stderr);
LIBSSH_API int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr);
LIBSSH_API int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
LIBSSH_API int ssh_channel_read_timeout(ssh_channel channel, void *dest, uint32_t count, int is_stderr, int timeout_ms);
LIBSSH_API int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
int is_stderr);
LIBSSH_API int ssh_channel_request_env(ssh_channel channel, const char *name, const char *value);
@@ -359,10 +398,6 @@ LIBSSH_API void ssh_channel_set_blocking(ssh_channel channel, int blocking);
LIBSSH_API int ssh_channel_write(ssh_channel channel, const void *data, uint32_t len);
LIBSSH_API uint32_t ssh_channel_window_size(ssh_channel channel);
LIBSSH_API int ssh_try_publickey_from_file(ssh_session session, const char *keyfile,
ssh_string *publickey, int *type);
LIBSSH_API int ssh_auth_list(ssh_session session);
LIBSSH_API char *ssh_basename (const char *path);
LIBSSH_API void ssh_clean_pubkey_hash(unsigned char **hash);
LIBSSH_API int ssh_connect(ssh_session session);
@@ -371,6 +406,7 @@ LIBSSH_API void ssh_disconnect(ssh_session session);
LIBSSH_API char *ssh_dirname (const char *path);
LIBSSH_API int ssh_finalize(void);
LIBSSH_API ssh_channel ssh_forward_accept(ssh_session session, int timeout_ms);
LIBSSH_API ssh_channel ssh_channel_accept_forward(ssh_session session, int timeout_ms, int *destination_port);
LIBSSH_API int ssh_forward_cancel(ssh_session session, const char *address, int port);
LIBSSH_API int ssh_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
LIBSSH_API void ssh_free(ssh_session session);
@@ -381,16 +417,43 @@ LIBSSH_API socket_t ssh_get_fd(ssh_session session);
LIBSSH_API char *ssh_get_hexa(const unsigned char *what, size_t len);
LIBSSH_API char *ssh_get_issue_banner(ssh_session session);
LIBSSH_API int ssh_get_openssh_version(ssh_session session);
LIBSSH_API ssh_string ssh_get_pubkey(ssh_session session);
LIBSSH_API int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash);
LIBSSH_API int ssh_get_publickey(ssh_session session, ssh_key *key);
enum ssh_publickey_hash_type {
SSH_PUBLICKEY_HASH_SHA1,
SSH_PUBLICKEY_HASH_MD5
};
LIBSSH_API int ssh_get_publickey_hash(const ssh_key key,
enum ssh_publickey_hash_type type,
unsigned char **hash,
size_t *hlen);
SSH_DEPRECATED LIBSSH_API int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash);
LIBSSH_API int ssh_get_random(void *where,int len,int strong);
LIBSSH_API int ssh_get_version(ssh_session session);
LIBSSH_API int ssh_get_status(ssh_session session);
LIBSSH_API int ssh_get_poll_flags(ssh_session session);
LIBSSH_API int ssh_init(void);
LIBSSH_API int ssh_is_blocking(ssh_session session);
LIBSSH_API int ssh_is_connected(ssh_session session);
LIBSSH_API int ssh_is_server_known(ssh_session session);
LIBSSH_API void ssh_log(ssh_session session, int prioriry, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
/* LOGGING */
LIBSSH_API int ssh_set_log_level(int level);
LIBSSH_API int ssh_get_log_level(void);
LIBSSH_API void *ssh_get_log_userdata(void);
LIBSSH_API int ssh_set_log_userdata(void *data);
LIBSSH_API void _ssh_log(int verbosity,
const char *function,
const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
/* legacy */
SSH_DEPRECATED LIBSSH_API void ssh_log(ssh_session session,
int prioriry,
const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
LIBSSH_API ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_reply_success(ssh_message msg);
LIBSSH_API void ssh_message_free(ssh_message msg);
@@ -405,14 +468,78 @@ LIBSSH_API int ssh_options_getopt(ssh_session session, int *argcptr, char **argv
LIBSSH_API int ssh_options_parse_config(ssh_session session, const char *filename);
LIBSSH_API int ssh_options_set(ssh_session session, enum ssh_options_e type,
const void *value);
LIBSSH_API int ssh_options_get(ssh_session session, enum ssh_options_e type,
char **value);
LIBSSH_API int ssh_options_get_port(ssh_session session, unsigned int * port_target);
LIBSSH_API int ssh_pcap_file_close(ssh_pcap_file pcap);
LIBSSH_API void ssh_pcap_file_free(ssh_pcap_file pcap);
LIBSSH_API ssh_pcap_file ssh_pcap_file_new(void);
LIBSSH_API int ssh_pcap_file_open(ssh_pcap_file pcap, const char *filename);
LIBSSH_API enum ssh_keytypes_e ssh_privatekey_type(ssh_private_key privatekey);
/**
* @brief SSH authentication callback.
*
* @param prompt Prompt to be displayed.
* @param buf Buffer to save the password. You should null-terminate it.
* @param len Length of the buffer.
* @param echo Enable or disable the echo of what you type.
* @param verify Should the password be verified?
* @param userdata Userdata to be passed to the callback function. Useful
* for GUI applications.
*
* @return 0 on success, < 0 on error.
*/
typedef int (*ssh_auth_callback) (const char *prompt, char *buf, size_t len,
int echo, int verify, void *userdata);
LIBSSH_API ssh_key ssh_key_new(void);
LIBSSH_API void ssh_key_free (ssh_key key);
LIBSSH_API enum ssh_keytypes_e ssh_key_type(const ssh_key key);
LIBSSH_API const char *ssh_key_type_to_char(enum ssh_keytypes_e type);
LIBSSH_API enum ssh_keytypes_e ssh_key_type_from_name(const char *name);
LIBSSH_API int ssh_key_is_public(const ssh_key k);
LIBSSH_API int ssh_key_is_private(const ssh_key k);
LIBSSH_API int ssh_key_cmp(const ssh_key k1,
const ssh_key k2,
enum ssh_keycmp_e what);
LIBSSH_API int ssh_pki_generate(enum ssh_keytypes_e type, int parameter,
ssh_key *pkey);
LIBSSH_API int ssh_pki_import_privkey_base64(const char *b64_key,
const char *passphrase,
ssh_auth_callback auth_fn,
void *auth_data,
ssh_key *pkey);
LIBSSH_API int ssh_pki_import_privkey_file(const char *filename,
const char *passphrase,
ssh_auth_callback auth_fn,
void *auth_data,
ssh_key *pkey);
LIBSSH_API int ssh_pki_export_privkey_file(const ssh_key privkey,
const char *passphrase,
ssh_auth_callback auth_fn,
void *auth_data,
const char *filename);
LIBSSH_API int ssh_pki_import_pubkey_base64(const char *b64_key,
enum ssh_keytypes_e type,
ssh_key *pkey);
LIBSSH_API int ssh_pki_import_pubkey_file(const char *filename,
ssh_key *pkey);
LIBSSH_API int ssh_pki_export_privkey_to_pubkey(const ssh_key privkey,
ssh_key *pkey);
LIBSSH_API int ssh_pki_export_pubkey_base64(const ssh_key key,
char **b64_key);
LIBSSH_API int ssh_pki_export_pubkey_file(const ssh_key key,
const char *filename);
LIBSSH_API const char *ssh_pki_key_ecdsa_name(const ssh_key key);
LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len);
LIBSSH_API int ssh_send_ignore (ssh_session session, const char *data);
LIBSSH_API int ssh_send_debug (ssh_session session, const char *message, int always_display);
LIBSSH_API void ssh_gssapi_set_creds(ssh_session session, const ssh_gssapi_creds creds);
LIBSSH_API int ssh_scp_accept_request(ssh_scp scp);
LIBSSH_API int ssh_scp_close(ssh_scp scp);
LIBSSH_API int ssh_scp_deny_request(ssh_scp scp, const char *reason);
@@ -423,40 +550,55 @@ LIBSSH_API ssh_scp ssh_scp_new(ssh_session session, int mode, const char *locati
LIBSSH_API int ssh_scp_pull_request(ssh_scp scp);
LIBSSH_API int ssh_scp_push_directory(ssh_scp scp, const char *dirname, int mode);
LIBSSH_API int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, int perms);
LIBSSH_API int ssh_scp_push_file64(ssh_scp scp, const char *filename, uint64_t size, int perms);
LIBSSH_API int ssh_scp_read(ssh_scp scp, void *buffer, size_t size);
LIBSSH_API const char *ssh_scp_request_get_filename(ssh_scp scp);
LIBSSH_API int ssh_scp_request_get_permissions(ssh_scp scp);
LIBSSH_API size_t ssh_scp_request_get_size(ssh_scp scp);
LIBSSH_API uint64_t ssh_scp_request_get_size64(ssh_scp scp);
LIBSSH_API const char *ssh_scp_request_get_warning(ssh_scp scp);
LIBSSH_API int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len);
LIBSSH_API int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd,
fd_set *readfds, struct timeval *timeout);
LIBSSH_API int ssh_service_request(ssh_session session, const char *service);
LIBSSH_API int ssh_set_agent_channel(ssh_session session, ssh_channel channel);
LIBSSH_API void ssh_set_blocking(ssh_session session, int blocking);
LIBSSH_API void ssh_set_fd_except(ssh_session session);
LIBSSH_API void ssh_set_fd_toread(ssh_session session);
LIBSSH_API void ssh_set_fd_towrite(ssh_session session);
LIBSSH_API void ssh_silent_disconnect(ssh_session session);
LIBSSH_API int ssh_set_pcap_file(ssh_session session, ssh_pcap_file pcapfile);
/* USERAUTH */
LIBSSH_API int ssh_userauth_none(ssh_session session, const char *username);
LIBSSH_API int ssh_userauth_list(ssh_session session, const char *username);
LIBSSH_API int ssh_userauth_try_publickey(ssh_session session,
const char *username,
const ssh_key pubkey);
LIBSSH_API int ssh_userauth_publickey(ssh_session session,
const char *username,
const ssh_key privkey);
#ifndef _WIN32
LIBSSH_API int ssh_userauth_agent_pubkey(ssh_session session, const char *username,
ssh_public_key publickey);
LIBSSH_API int ssh_userauth_agent(ssh_session session,
const char *username);
#endif
LIBSSH_API int ssh_userauth_autopubkey(ssh_session session, const char *passphrase);
LIBSSH_API int ssh_userauth_publickey_auto(ssh_session session,
const char *username,
const char *passphrase);
LIBSSH_API int ssh_userauth_password(ssh_session session,
const char *username,
const char *password);
LIBSSH_API int ssh_userauth_kbdint(ssh_session session, const char *user, const char *submethods);
LIBSSH_API const char *ssh_userauth_kbdint_getinstruction(ssh_session session);
LIBSSH_API const char *ssh_userauth_kbdint_getname(ssh_session session);
LIBSSH_API int ssh_userauth_kbdint_getnprompts(ssh_session session);
LIBSSH_API const char *ssh_userauth_kbdint_getprompt(ssh_session session, unsigned int i, char *echo);
LIBSSH_API int ssh_userauth_kbdint_getnanswers(ssh_session session);
LIBSSH_API const char *ssh_userauth_kbdint_getanswer(ssh_session session, unsigned int i);
LIBSSH_API int ssh_userauth_kbdint_setanswer(ssh_session session, unsigned int i,
const char *answer);
LIBSSH_API int ssh_userauth_list(ssh_session session, const char *username);
LIBSSH_API int ssh_userauth_none(ssh_session session, const char *username);
LIBSSH_API int ssh_userauth_offer_pubkey(ssh_session session, const char *username, int type, ssh_string publickey);
LIBSSH_API int ssh_userauth_password(ssh_session session, const char *username, const char *password);
LIBSSH_API int ssh_userauth_pubkey(ssh_session session, const char *username, ssh_string publickey, ssh_private_key privatekey);
LIBSSH_API int ssh_userauth_privatekey_file(ssh_session session, const char *username,
const char *filename, const char *passphrase);
LIBSSH_API int ssh_userauth_gssapi(ssh_session session);
LIBSSH_API const char *ssh_version(int req_version);
LIBSSH_API int ssh_write_knownhost(ssh_session session);
@@ -468,12 +610,29 @@ LIBSSH_API void ssh_string_free(ssh_string str);
LIBSSH_API ssh_string ssh_string_from_char(const char *what);
LIBSSH_API size_t ssh_string_len(ssh_string str);
LIBSSH_API ssh_string ssh_string_new(size_t size);
LIBSSH_API const char *ssh_string_get_char(ssh_string str);
LIBSSH_API char *ssh_string_to_char(ssh_string str);
LIBSSH_API void ssh_string_free_char(char *s);
LIBSSH_API int ssh_getpass(const char *prompt, char *buf, size_t len, int echo,
int verify);
typedef int (*ssh_event_callback)(socket_t fd, int revents, void *userdata);
LIBSSH_API ssh_event ssh_event_new(void);
LIBSSH_API int ssh_event_add_fd(ssh_event event, socket_t fd, short events,
ssh_event_callback cb, void *userdata);
LIBSSH_API int ssh_event_add_session(ssh_event event, ssh_session session);
LIBSSH_API int ssh_event_dopoll(ssh_event event, int timeout);
LIBSSH_API int ssh_event_remove_fd(ssh_event event, socket_t fd);
LIBSSH_API int ssh_event_remove_session(ssh_event event, ssh_session session);
LIBSSH_API void ssh_event_free(ssh_event event);
LIBSSH_API const char* ssh_get_clientbanner(ssh_session session);
LIBSSH_API const char* ssh_get_serverbanner(ssh_session session);
LIBSSH_API const char* ssh_get_cipher_in(ssh_session session);
LIBSSH_API const char* ssh_get_cipher_out(ssh_session session);
#ifndef LIBSSH_LEGACY_0_4
#include "libssh/legacy.h"
#endif

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2010 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LIBSSHPP_HPP_
@@ -177,8 +176,8 @@ public:
* @returns SSH_AUTH_SUCCESS, SSH_AUTH_PARTIAL, SSH_AUTH_DENIED
* @see ssh_userauth_autopubkey
*/
int userauthAutopubkey(void){
int ret=ssh_userauth_autopubkey(c_session,NULL);
int userauthPublickeyAuto(void){
int ret=ssh_userauth_publickey_auto(c_session, NULL, NULL);
ssh_throw(ret);
return ret;
}
@@ -206,32 +205,25 @@ public:
return ret;
}
/** @brief Try to authenticate using the publickey method.
* @param[in] type public key type
* @param[in] pubkey public key to use for authentication
* @throws SshException on error
* @returns SSH_AUTH_SUCCESS if the pubkey is accepted,
* @returns SSH_AUTH_DENIED if the pubkey is denied
* @see ssh_userauth_offer_pubkey
* @see ssh_userauth_try_pubkey
*/
int userauthOfferPubkey(int type, ssh_string pubkey){
int ret=ssh_userauth_offer_pubkey(c_session,NULL,type,pubkey);
int userauthTryPublickey(ssh_key pubkey){
int ret=ssh_userauth_try_publickey(c_session, NULL, pubkey);
ssh_throw(ret);
return ret;
}
/** @brief Authenticates using the publickey method.
* @param[in] pubkey public key to use for authentication
* @param[in] privkey private key to use for authentication
* @throws SshException on error
* @returns SSH_AUTH_SUCCESS, SSH_AUTH_PARTIAL, SSH_AUTH_DENIED
* @see ssh_userauth_pubkey
*/
int userauthPubkey(ssh_string pubkey, ssh_private_key privkey){
int ret=ssh_userauth_pubkey(c_session,NULL,pubkey,privkey);
ssh_throw(ret);
return ret;
}
int userauthPubkey(ssh_private_key privkey){
int ret=ssh_userauth_pubkey(c_session,NULL,NULL,privkey);
int userauthPublickey(ssh_key privkey){
int ret=ssh_userauth_publickey(c_session, NULL, privkey);
ssh_throw(ret);
return ret;
}
@@ -324,7 +316,7 @@ public:
va_start(va, format);
vsnprintf(buffer, sizeof(buffer), format, va);
va_end(va);
ssh_log(c_session,priority, "%s", buffer);
_ssh_log(priority, "libsshpp", "%s", buffer);
}
/** @brief copies options from a session to another
@@ -369,8 +361,8 @@ public:
* @see ssh_channel_forward_accept
* @see Session::listenForward
*/
Channel *acceptForward(int timeout_ms);
/* acceptForward is implemented later in this file */
inline Channel *acceptForward(int timeout_ms);
/* implemented outside the class due Channel references */
void_throwable cancelForward(const char *address, int port){
int err=ssh_forward_cancel(c_session, address, port);
@@ -488,12 +480,30 @@ public:
ssh_throw(err);
return err;
}
int read(void *dest, size_t count, bool is_stderr=false){
int read(void *dest, size_t count, bool is_stderr){
int err;
/* handle int overflow */
if(count > 0x7fffffff)
count = 0x7fffffff;
err=ssh_channel_read(channel,dest,count,is_stderr);
err=ssh_channel_read_timeout(channel,dest,count,is_stderr,-1);
ssh_throw(err);
return err;
}
int read(void *dest, size_t count, int timeout){
int err;
/* handle int overflow */
if(count > 0x7fffffff)
count = 0x7fffffff;
err=ssh_channel_read_timeout(channel,dest,count,false,timeout);
ssh_throw(err);
return err;
}
int read(void *dest, size_t count, bool is_stderr=false, int timeout=-1){
int err;
/* handle int overflow */
if(count > 0x7fffffff)
count = 0x7fffffff;
err=ssh_channel_read_timeout(channel,dest,count,is_stderr,timeout);
ssh_throw(err);
return err;
}

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MESSAGES_H_
@@ -28,8 +27,9 @@ struct ssh_auth_request {
char *username;
int method;
char *password;
struct ssh_public_key_struct *public_key;
struct ssh_key_struct *pubkey;
char signature_state;
char kbdint_response;
};
struct ssh_channel_request_open {
@@ -73,6 +73,12 @@ struct ssh_channel_request {
char *command;
/* subsystem */
char *subsystem;
/* X11 */
uint8_t x11_single_connection;
const char *x11_auth_protocol;
const char *x11_auth_cookie;
uint32_t x11_screen_number;
};
struct ssh_message_struct {
@@ -86,13 +92,17 @@ struct ssh_message_struct {
};
SSH_PACKET_CALLBACK(ssh_packet_channel_open);
SSH_PACKET_CALLBACK(ssh_packet_global_request);
#ifdef WITH_SERVER
SSH_PACKET_CALLBACK(ssh_packet_service_request);
SSH_PACKET_CALLBACK(ssh_packet_userauth_request);
SSH_PACKET_CALLBACK(ssh_packet_global_request);
#endif /* WITH_SERVER */
int ssh_message_handle_channel_request(ssh_session session, ssh_channel channel, ssh_buffer packet,
const char *request, uint8_t want_reply);
void ssh_message_queue(ssh_session session, ssh_message message);
ssh_message ssh_message_pop_head(ssh_session session);
int ssh_message_channel_request_open_reply_accept_channel(ssh_message msg, ssh_channel chan);
#endif /* MESSAGES_H_ */

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MISC_H_
@@ -25,7 +24,7 @@
/* in misc.c */
/* gets the user home dir. */
char *ssh_get_user_home_dir(void);
char *ssh_get_local_username(ssh_session session);
char *ssh_get_local_username(void);
int ssh_file_readaccess_ok(const char *file);
char *ssh_path_expand_tilde(const char *d);
@@ -34,9 +33,14 @@ int ssh_analyze_banner(ssh_session session, int server, int *ssh1, int *ssh2);
int ssh_is_ipaddr_v4(const char *str);
int ssh_is_ipaddr(const char *str);
#ifndef HAVE_NTOHLL
/* macro for byte ordering */
uint64_t ntohll(uint64_t);
#define htonll(x) ntohll(x)
#endif
#ifndef HAVE_HTONLL
#define htonll(x) ntohll((x))
#endif
/* list processing */
@@ -78,8 +82,11 @@ const void *_ssh_list_pop_head(struct ssh_list *list);
#define ssh_list_pop_head(type, ssh_list)\
((type)_ssh_list_pop_head(ssh_list))
int ssh_make_milliseconds(long sec, long usec);
void ssh_timestamp_init(struct ssh_timestamp *ts);
int ssh_timeout_elapsed(struct ssh_timestamp *ts, int timeout);
int ssh_timeout_update(struct ssh_timestamp *ts, int timeout);
int ssh_match_group(const char *group, const char *object);
#endif /* MISC_H_ */

28
include/libssh/options.h Normal file
View File

@@ -0,0 +1,28 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2011 Andreas Schneider <asn@cryptomilk.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _OPTIONS_H
#define _OPTIONS_H
int ssh_config_parse_file(ssh_session session, const char *filename);
int ssh_options_set_algo(ssh_session session, int algo, const char *list);
int ssh_options_apply(ssh_session session);
#endif /* _OPTIONS_H */

View File

@@ -3,25 +3,26 @@
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef PACKET_H_
#define PACKET_H_
struct ssh_socket_struct;
/* this structure should go someday */
typedef struct packet_struct {
int valid;
@@ -54,9 +55,33 @@ int ssh_packet_socket_callback1(const void *data, size_t receivedlen, void *user
#endif
SSH_PACKET_CALLBACK(ssh_packet_unimplemented);
SSH_PACKET_CALLBACK(ssh_packet_disconnect_callback);
SSH_PACKET_CALLBACK(ssh_packet_ignore_callback);
SSH_PACKET_CALLBACK(ssh_packet_dh_reply);
SSH_PACKET_CALLBACK(ssh_packet_newkeys);
SSH_PACKET_CALLBACK(ssh_packet_service_accept);
#ifdef WITH_SERVER
SSH_PACKET_CALLBACK(ssh_packet_kexdh_init);
#endif
int ssh_packet_send_unimplemented(ssh_session session, uint32_t seqnum);
int ssh_packet_parse_type(ssh_session session);
//int packet_flush(ssh_session session, int enforce_blocking);
int ssh_packet_socket_callback(const void *data, size_t len, void *user);
void ssh_packet_register_socket_callback(ssh_session session, struct ssh_socket_struct *s);
void ssh_packet_set_callbacks(ssh_session session, ssh_packet_callbacks callbacks);
void ssh_packet_set_default_callbacks(ssh_session session);
void ssh_packet_process(ssh_session session, uint8_t type);
/* PACKET CRYPT */
uint32_t packet_decrypt_len(ssh_session session, char *crypted);
int packet_decrypt(ssh_session session, void *packet, unsigned int len);
unsigned char *packet_encrypt(ssh_session session,
void *packet,
unsigned int len);
int packet_hmac_verify(ssh_session session,ssh_buffer buffer,
unsigned char *mac);
#endif /* PACKET_H_ */

View File

@@ -1,3 +1,23 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef PCAP_H_
#define PCAP_H_

View File

@@ -3,47 +3,121 @@
*
* Copyright (c) 2010 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef PKI_H_
#define PKI_H_
#define SSH_KEY_FLAG_EMPTY 0
#define SSH_KEY_FLAG_PUBLIC 1
#define SSH_KEY_FLAG_PRIVATE 2
#ifdef HAVE_OPENSSL_EC_H
#include <openssl/ec.h>
#endif
#ifdef HAVE_OPENSSL_ECDSA_H
#include <openssl/ecdsa.h>
#endif
#include "libssh/crypto.h"
#define MAX_PUBKEY_SIZE 0x100000 /* 1M */
#define MAX_PRIVKEY_SIZE 0x400000 /* 4M */
#define SSH_KEY_FLAG_EMPTY 0x0
#define SSH_KEY_FLAG_PUBLIC 0x0001
#define SSH_KEY_FLAG_PRIVATE 0x0002
struct ssh_key_struct {
enum ssh_keytypes_e type;
int flags;
const char *type_c; /* Don't free it ! it is static */
int ecdsa_nid;
#ifdef HAVE_LIBGCRYPT
gcry_sexp_t dsa;
gcry_sexp_t rsa;
void *ecdsa;
#elif HAVE_LIBCRYPTO
DSA *dsa;
RSA *rsa;
#ifdef HAVE_OPENSSL_ECC
EC_KEY *ecdsa;
#else
void *ecdsa;
#endif /* HAVE_OPENSSL_EC_H */
#endif
void *cert;
};
struct ssh_signature_struct {
enum ssh_keytypes_e type;
const char *type_c;
#ifdef HAVE_LIBGCRYPT
gcry_sexp_t dsa_sig;
gcry_sexp_t rsa_sig;
void *ecdsa_sig;
#elif defined HAVE_LIBCRYPTO
DSA_SIG *dsa_sig;
ssh_string rsa_sig;
# ifdef HAVE_OPENSSL_ECC
ECDSA_SIG *ecdsa_sig;
# else
void *ecdsa_sig;
# endif
#endif
};
ssh_key ssh_key_new (void);
typedef struct ssh_signature_struct *ssh_signature;
/* SSH Key Functions */
ssh_key ssh_key_dup(const ssh_key key);
void ssh_key_clean (ssh_key key);
enum ssh_keytypes_e ssh_key_type(ssh_key key);
int ssh_key_import_private(ssh_key key, ssh_session session,
const char *filename, const char *passphrase);
void ssh_key_free (ssh_key key);
/* SSH Signature Functions */
ssh_signature ssh_signature_new(void);
void ssh_signature_free(ssh_signature sign);
int ssh_pki_export_signature_blob(const ssh_signature sign,
ssh_string *sign_blob);
int ssh_pki_import_signature_blob(const ssh_string sig_blob,
const ssh_key pubkey,
ssh_signature *psig);
int ssh_pki_signature_verify_blob(ssh_session session,
ssh_string sig_blob,
const ssh_key key,
unsigned char *digest,
size_t dlen);
/* SSH Public Key Functions */
int ssh_pki_export_pubkey_blob(const ssh_key key,
ssh_string *pblob);
int ssh_pki_import_pubkey_blob(const ssh_string key_blob,
ssh_key *pkey);
int ssh_pki_export_pubkey_rsa1(const ssh_key key,
const char *host,
char *rsa1,
size_t rsa1_len);
/* SSH Signing Functions */
ssh_string ssh_pki_do_sign(ssh_session session, ssh_buffer sigbuf,
const ssh_key privatekey);
ssh_string ssh_pki_do_sign_agent(ssh_session session,
struct ssh_buffer_struct *buf,
const ssh_key pubkey);
ssh_string ssh_srv_pki_do_sign_sessionid(ssh_session session,
const ssh_key privkey);
/* Temporary functions, to be removed after migration to ssh_key */
ssh_public_key ssh_pki_convert_key_to_publickey(const ssh_key key);
ssh_private_key ssh_pki_convert_key_to_privatekey(const ssh_key key);
#endif /* PKI_H_ */

94
include/libssh/pki_priv.h Normal file
View File

@@ -0,0 +1,94 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2010 by Aris Adamantiadis
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef PKI_PRIV_H_
#define PKI_PRIV_H_
#define RSA_HEADER_BEGIN "-----BEGIN RSA PRIVATE KEY-----"
#define RSA_HEADER_END "-----END RSA PRIVATE KEY-----"
#define DSA_HEADER_BEGIN "-----BEGIN DSA PRIVATE KEY-----"
#define DSA_HEADER_END "-----END DSA PRIVATE KEY-----"
#define ECDSA_HEADER_BEGIN "-----BEGIN EC PRIVATE KEY-----"
#define ECDSA_HEADER_END "-----END EC PRIVATE KEY-----"
#define ssh_pki_log(...) \
_ssh_log(SSH_LOG_FUNCTIONS, __func__, __VA_ARGS__)
void _ssh_pki_log(const char *function,
const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
int pki_key_ecdsa_nid_from_name(const char *name);
const char *pki_key_ecdsa_nid_to_name(int nid);
/* SSH Key Functions */
ssh_key pki_key_dup(const ssh_key key, int demote);
int pki_key_generate_rsa(ssh_key key, int parameter);
int pki_key_generate_dss(ssh_key key, int parameter);
int pki_key_generate_ecdsa(ssh_key key, int parameter);
int pki_key_compare(const ssh_key k1,
const ssh_key k2,
enum ssh_keycmp_e what);
/* SSH Private Key Functions */
enum ssh_keytypes_e pki_privatekey_type_from_string(const char *privkey);
ssh_key pki_private_key_from_base64(const char *b64_key,
const char *passphrase,
ssh_auth_callback auth_fn,
void *auth_data);
ssh_string pki_private_key_to_pem(const ssh_key key,
const char *passphrase,
ssh_auth_callback auth_fn,
void *auth_data);
/* SSH Public Key Functions */
int pki_pubkey_build_dss(ssh_key key,
ssh_string p,
ssh_string q,
ssh_string g,
ssh_string pubkey);
int pki_pubkey_build_rsa(ssh_key key,
ssh_string e,
ssh_string n);
int pki_pubkey_build_ecdsa(ssh_key key, int nid, ssh_string e);
ssh_string pki_publickey_to_blob(const ssh_key key);
int pki_export_pubkey_rsa1(const ssh_key key,
const char *host,
char *rsa1,
size_t rsa1_len);
/* SSH Signature Functions */
ssh_string pki_signature_to_blob(const ssh_signature sign);
ssh_signature pki_signature_from_blob(const ssh_key pubkey,
const ssh_string sig_blob,
enum ssh_keytypes_e type);
int pki_signature_verify(ssh_session session,
const ssh_signature sig,
const ssh_key key,
const unsigned char *hash,
size_t hlen);
/* SSH Signing Functions */
ssh_signature pki_do_sign(const ssh_key privkey,
const unsigned char *hash,
size_t hlen);
ssh_signature pki_do_sign_sessionid(const ssh_key key,
const unsigned char *hash,
size_t hlen);
#endif /* PKI_PRIV_H_ */

View File

@@ -3,24 +3,24 @@
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef POLL_H_
#define POLL_H_
#include "config.h"
#ifdef HAVE_POLL
@@ -135,6 +135,7 @@ typedef struct ssh_poll_handle_struct *ssh_poll_handle;
typedef int (*ssh_poll_callback)(ssh_poll_handle p, socket_t fd, int revents,
void *userdata);
struct ssh_socket_struct;
ssh_poll_handle ssh_poll_new(socket_t fd, short events, ssh_poll_callback cb,
void *userdata);

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2003-2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
@@ -32,6 +31,18 @@
#include "config.h"
#if !defined(HAVE_STRTOULL)
# if defined(HAVE___STRTOULL)
# define strtoull __strtoull
# elif defined(HAVE__STRTOUI64)
# define strtoull _strtoui64
# elif defined(__hpux) && defined(__LP64__)
# define strtoull strtoul
# else
# error "no strtoull function found"
# endif
#endif /* !defined(HAVE_STRTOULL) */
#ifdef _WIN32
/* Imitate define of inttypes.h */
@@ -39,6 +50,14 @@
# define PRIdS "Id"
# endif
# ifndef PRIu64
# if __WORDSIZE == 64
# define PRIu64 "lu"
# else
# define PRIu64 "llu"
# endif /* __WORDSIZE */
# endif /* PRIu64 */
# ifdef _MSC_VER
# include <stdio.h>
@@ -48,8 +67,9 @@
# define strcasecmp _stricmp
# define strncasecmp _strnicmp
# define strtoull _strtoui64
# define isblank(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r')
# if ! defined(HAVE_ISBLANK)
# define isblank(ch) ((ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r')
# endif
# define usleep(X) Sleep(((X)+1000)/1000)
@@ -86,6 +106,9 @@
# endif /* _MSC_VER */
struct timeval;
int gettimeofday(struct timeval *__p, void *__t);
#else /* _WIN32 */
#include <unistd.h>
@@ -95,100 +118,116 @@
#include "libssh/libssh.h"
#include "libssh/callbacks.h"
#include "libssh/crypto.h"
/* some constants */
#ifndef MAX_PACKAT_LEN
#define MAX_PACKET_LEN 262144
#endif
#ifndef ERROR_BUFFERLEN
#define ERROR_BUFFERLEN 1024
#endif
#ifndef CLIENTBANNER1
#define CLIENTBANNER1 "SSH-1.5-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
#endif
#ifndef CLIENTBANNER2
#define CLIENTBANNER2 "SSH-2.0-libssh-" SSH_STRINGIFY(LIBSSH_VERSION)
#endif
#ifndef KBDINT_MAX_PROMPT
#define KBDINT_MAX_PROMPT 256 /* more than openssh's :) */
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MAX_BUF_SIZE
#define MAX_BUF_SIZE 4096
#endif
#ifndef HAVE_COMPILER__FUNC__
# ifdef HAVE_COMPILER__FUNCTION__
# define __func__ __FUNCTION__
# else
# error "Your system must provide a __func__ macro"
# endif
#endif
#if defined(HAVE_GCC_THREAD_LOCAL_STORAGE)
# define LIBSSH_THREAD __thread
#elif defined(HAVE_MSC_THREAD_LOCAL_STORAGE)
# define LIBSSH_THREAD __declspec(thread)
#else
# define LIBSSH_THREAD
#endif
/*
* This makes sure that the compiler doesn't optimize out the code
*
* Use it in a macro where the provided variable is 'x'.
*/
#if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
# define LIBSSH_MEM_PROTECTION __asm__ volatile("" : : "r"(&(x)) : "memory")
#else
# define LIBSSH_MEM_PROTECTION
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
typedef struct kex_struct {
unsigned char cookie[16];
char **methods;
} KEX;
/* forward declarations */
struct ssh_common_struct;
struct ssh_kex_struct;
int ssh_get_key_params(ssh_session session, ssh_key *privkey);
/* LOGGING */
void ssh_log_function(int verbosity,
const char *function,
const char *buffer);
#define SSH_LOG(priority, ...) \
_ssh_log(priority, __func__, __VA_ARGS__)
/* LEGACY */
void ssh_log_common(struct ssh_common_struct *common,
int verbosity,
const char *function,
const char *format, ...) PRINTF_ATTRIBUTE(4, 5);
/* ERROR HANDLING */
/* error handling structure */
struct error_struct {
/* error handling */
int error_code;
char error_buffer[ERROR_BUFFERLEN];
};
/* TODO: remove that include */
#include "libssh/wrapper.h"
#define ssh_set_error(error, code, ...) \
_ssh_set_error(error, code, __func__, __VA_ARGS__)
void _ssh_set_error(void *error,
int code,
const char *function,
const char *descr, ...) PRINTF_ATTRIBUTE(4, 5);
struct ssh_keys_struct {
const char *privatekey;
const char *publickey;
};
#define ssh_set_error_oom(error) \
_ssh_set_error_oom(error, __func__)
void _ssh_set_error_oom(void *error, const char *function);
struct ssh_message_struct;
/* server data */
#define ssh_set_error_invalid(error) \
_ssh_set_error_invalid(error, __func__)
void _ssh_set_error_invalid(void *error, const char *function);
SSH_PACKET_CALLBACK(ssh_packet_disconnect_callback);
SSH_PACKET_CALLBACK(ssh_packet_ignore_callback);
/* server.c */
#ifdef WITH_SERVER
int ssh_auth_reply_default(ssh_session session,int partial);
int ssh_auth_reply_success(ssh_session session, int partial);
#endif
/* client.c */
int ssh_send_banner(ssh_session session, int is_server);
SSH_PACKET_CALLBACK(ssh_packet_dh_reply);
SSH_PACKET_CALLBACK(ssh_packet_newkeys);
SSH_PACKET_CALLBACK(ssh_packet_service_accept);
/* config.c */
int ssh_config_parse_file(ssh_session session, const char *filename);
/* errors.c */
void ssh_set_error(void *error, int code, const char *descr, ...) PRINTF_ATTRIBUTE(3, 4);
void ssh_set_error_oom(void *);
void ssh_set_error_invalid(void *, const char *);
/* in crypt.c */
uint32_t packet_decrypt_len(ssh_session session,char *crypted);
int packet_decrypt(ssh_session session, void *packet,unsigned int len);
unsigned char *packet_encrypt(ssh_session session,void *packet,unsigned int len);
/* it returns the hmac buffer if exists*/
struct ssh_poll_handle_struct;
int packet_hmac_verify(ssh_session session,ssh_buffer buffer,unsigned char *mac);
struct ssh_socket_struct;
int ssh_packet_socket_callback(const void *data, size_t len, void *user);
void ssh_packet_register_socket_callback(ssh_session session, struct ssh_socket_struct *s);
void ssh_packet_set_callbacks(ssh_session session, ssh_packet_callbacks callbacks);
void ssh_packet_set_default_callbacks(ssh_session session);
void ssh_packet_process(ssh_session session, uint8_t type);
/* connect.c */
socket_t ssh_connect_host(ssh_session session, const char *host,const char
*bind_addr, int port, long timeout, long usec);
socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host,
const char *bind_addr, int port);
void ssh_sock_set_nonblocking(socket_t sock);
void ssh_sock_set_blocking(socket_t sock);
/* in kex.c */
extern const char *ssh_kex_nums[];
int ssh_send_kex(ssh_session session, int server_kex);
void ssh_list_kex(ssh_session session, KEX *kex);
int set_kex(ssh_session session);
int verify_existing_algo(int algo, const char *name);
char **space_tokenize(const char *chain);
int ssh_get_kex1(ssh_session session);
char *ssh_find_matching(const char *in_d, const char *what_d);
/* in base64.c */
ssh_buffer base64_to_bin(const char *source);
@@ -198,58 +237,11 @@ unsigned char *bin_to_base64(const unsigned char *source, int len);
int compress_buffer(ssh_session session,ssh_buffer buf);
int decompress_buffer(ssh_session session,ssh_buffer buf, size_t maxlen);
/* crc32.c */
uint32_t ssh_crc32(const char *buf, uint32_t len);
/* match.c */
int match_hostname(const char *host, const char *pattern, unsigned int len);
int message_handle(ssh_session session, void *user, uint8_t type, ssh_buffer packet);
/* log.c */
/* misc.c */
#ifdef _WIN32
int gettimeofday(struct timeval *__p, void *__t);
#endif /* _WIN32 */
#ifndef __FUNCTION__
#if defined(__SUNPRO_C)
#define __FUNCTION__ __func__
#endif
#endif
#define _enter_function(sess) \
do {\
if((sess)->log_verbosity >= SSH_LOG_FUNCTIONS){ \
ssh_log((sess),SSH_LOG_FUNCTIONS,"entering function %s line %d in " __FILE__ , __FUNCTION__,__LINE__);\
(sess)->log_indent++; \
} \
} while(0)
#define _leave_function(sess) \
do { \
if((sess)->log_verbosity >= SSH_LOG_FUNCTIONS){ \
(sess)->log_indent--; \
ssh_log((sess),SSH_LOG_FUNCTIONS,"leaving function %s line %d in " __FILE__ , __FUNCTION__,__LINE__);\
}\
} while(0)
#ifdef DEBUG_CALLTRACE
#define enter_function() _enter_function(session)
#define leave_function() _leave_function(session)
#else
#define enter_function() (void)session
#define leave_function() (void)session
#endif
/* options.c */
int ssh_options_set_algo(ssh_session session, int algo, const char *list);
int ssh_options_apply(ssh_session session);
/* server.c */
SSH_PACKET_CALLBACK(ssh_packet_kexdh_init);
/** Free memory space */
#define SAFE_FREE(x) do { if ((x) != NULL) {free(x); x=NULL;} } while(0)
@@ -263,18 +255,52 @@ SSH_PACKET_CALLBACK(ssh_packet_kexdh_init);
/** Get the size of an array */
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
/** Overwrite the complete string with 'X' */
#define BURN_STRING(x) do { if ((x) != NULL) memset((x), 'X', strlen((x))); } while(0)
/*
* See http://llvm.org/bugs/show_bug.cgi?id=15495
*/
#if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
/** Overwrite a string with '\0' */
# define BURN_STRING(x) do { \
if ((x) != NULL) \
memset((x), '\0', strlen((x))); __asm__ volatile("" : : "r"(&(x)) : "memory"); \
} while(0)
#ifdef HAVE_LIBGCRYPT
/* gcrypt_missing.c */
int my_gcry_dec2bn(bignum *bn, const char *data);
char *my_gcry_bn2dec(bignum bn);
#endif /* !HAVE_LIBGCRYPT */
/** Overwrite the buffer with '\0' */
# define BURN_BUFFER(x, size) do { \
if ((x) != NULL) \
memset((x), '\0', (size)); __asm__ volatile("" : : "r"(&(x)) : "memory"); \
} while(0)
#else /* HAVE_GCC_VOLATILE_MEMORY_PROTECTION */
/** Overwrite a string with '\0' */
# define BURN_STRING(x) do { \
if ((x) != NULL) memset((x), '\0', strlen((x))); \
} while(0)
#ifdef __cplusplus
}
#endif
/** Overwrite the buffer with '\0' */
# define BURN_BUFFER(x, size) do { \
if ((x) != NULL) \
memset((x), '\0', (size)); \
} while(0)
#endif /* HAVE_GCC_VOLATILE_MEMORY_PROTECTION */
/**
* This is a hack to fix warnings. The idea is to use this everywhere that we
* get the "discarding const" warning by the compiler. That doesn't actually
* fix the real issue, but marks the place and you can search the code for
* discard_const.
*
* Please use this macro only when there is no other way to fix the warning.
* We should use this function in only in a very few places.
*
* Also, please call this via the discard_const_p() macro interface, as that
* makes the return type safe.
*/
#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
/**
* Type-safe version of discard_const
*/
#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
#endif /* _LIBSSH_PRIV_H */
/* vim: set ts=2 sw=2 et cindent: */
/* vim: set ts=4 sw=4 et cindent: */

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2003-2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _SCP_H
@@ -40,8 +39,8 @@ struct ssh_scp_struct {
ssh_channel channel;
char *location;
enum ssh_scp_states state;
size_t filelen;
size_t processed;
uint64_t filelen;
uint64_t processed;
enum ssh_scp_request_types request_type;
char *request_name;
char *warning;

View File

@@ -4,20 +4,19 @@
*
* Copyright (c) 2003-2008 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
@@ -45,7 +44,8 @@ enum ssh_bind_options_e {
SSH_BIND_OPTIONS_RSAKEY,
SSH_BIND_OPTIONS_BANNER,
SSH_BIND_OPTIONS_LOG_VERBOSITY,
SSH_BIND_OPTIONS_LOG_VERBOSITY_STR
SSH_BIND_OPTIONS_LOG_VERBOSITY_STR,
SSH_BIND_OPTIONS_ECDSAKEY
};
typedef struct ssh_bind_struct* ssh_bind;
@@ -56,7 +56,6 @@ typedef struct ssh_bind_struct* ssh_bind;
* @brief Incoming connection callback. This callback is called when a ssh_bind
* has a new incoming connection.
* @param sshbind Current sshbind session handler
* @param message the actual message
* @param userdata Userdata to be passed to the callback function.
*/
typedef void (*ssh_bind_incoming_connection_callback) (ssh_bind sshbind,
@@ -82,69 +81,6 @@ typedef struct ssh_bind_callbacks_struct *ssh_bind_callbacks;
*/
LIBSSH_API ssh_bind ssh_bind_new(void);
/**
* @brief Set the options for the current SSH server bind.
*
* @param sshbind The ssh server bind to configure.
*
* @param type The option type to set. This could be one of the
* following:
*
* - SSH_BIND_OPTIONS_BINDADDR
* The ip address to bind (const char *).
*
* - SSH_BIND_OPTIONS_BINDPORT
* The port to bind (unsigned int).
*
* - SSH_BIND_OPTIONS_BINDPORT_STR
* The port to bind (const char *).
*
* - SSH_BIND_OPTIONS_HOSTKEY
* This specifies the file containing the private host key used
* by SSHv1. (const char *).
*
* - SSH_BIND_OPTIONS_DSAKEY
* This specifies the file containing the private host dsa key
* used by SSHv2. (const char *).
*
* - SSH_BIND_OPTIONS_RSAKEY
* This specifies the file containing the private host dsa key
* used by SSHv2. (const char *).
*
* - SSH_BIND_OPTIONS_BANNER
* That the server banner (version string) for SSH.
* (const char *).
*
* - SSH_BIND_OPTIONS_LOG_VERBOSITY
* Set the session logging verbosity (int).\n
* \n
* The verbosity of the messages. Every log smaller or
* equal to verbosity will be shown.
* - SSH_LOG_NOLOG: No logging
* - SSH_LOG_RARE: Rare conditions or warnings
* - SSH_LOG_ENTRY: API-accessible entrypoints
* - SSH_LOG_PACKET: Packet id and size
* - SSH_LOG_FUNCTIONS: Function entering and leaving
*
* - SSH_BIND_OPTIONS_LOG_VERBOSITY_STR
* Set the session logging verbosity (const char *).\n
* \n
* The verbosity of the messages. Every log smaller or
* equal to verbosity will be shown.
* - SSH_LOG_NOLOG: No logging
* - SSH_LOG_RARE: Rare conditions or warnings
* - SSH_LOG_ENTRY: API-accessible entrypoints
* - SSH_LOG_PACKET: Packet id and size
* - SSH_LOG_FUNCTIONS: Function entering and leaving
* \n
* See the corresponding numbers in libssh.h.
*
* @param value The value to set. This is a generic pointer and the
* datatype which is used should be set according to the
* type set.
*
* @returns SSH_OK on success, SSH_ERROR on invalid option or parameter.
*/
LIBSSH_API int ssh_bind_options_set(ssh_bind sshbind,
enum ssh_bind_options_e type, const void *value);
@@ -224,6 +160,23 @@ LIBSSH_API void ssh_bind_fd_toaccept(ssh_bind ssh_bind_o);
*/
LIBSSH_API int ssh_bind_accept(ssh_bind ssh_bind_o, ssh_session session);
/**
* @brief Accept an incoming ssh connection on the given file descriptor
* and initialize the session.
*
* @param ssh_bind_o The ssh server bind to accept a connection.
* @param session A preallocated ssh session
* @param fd A file descriptor of an already established TCP
* inbound connection
* @see ssh_new
* @see ssh_bind_accept
* @return SSH_OK when a connection is established
*/
LIBSSH_API int ssh_bind_accept_fd(ssh_bind ssh_bind_o, ssh_session session,
socket_t fd);
LIBSSH_API ssh_gssapi_creds ssh_gssapi_get_creds(ssh_session session);
/**
* @brief Handles the key exchange and set up encryption
*
@@ -240,12 +193,67 @@ LIBSSH_API int ssh_handle_key_exchange(ssh_session session);
*/
LIBSSH_API void ssh_bind_free(ssh_bind ssh_bind_o);
/* messages.c */
LIBSSH_API void ssh_set_auth_methods(ssh_session session, int auth_methods);
/**********************************************************
* SERVER MESSAGING
**********************************************************/
/**
* @brief Reply with a standard reject message.
*
* Use this function if you don't know what to respond or if you want to reject
* a request.
*
* @param[in] msg The message to use for the reply.
*
* @return 0 on success, -1 on error.
*
* @see ssh_message_get()
*/
LIBSSH_API int ssh_message_reply_default(ssh_message msg);
LIBSSH_API char *ssh_message_auth_user(ssh_message msg);
LIBSSH_API char *ssh_message_auth_password(ssh_message msg);
LIBSSH_API ssh_public_key ssh_message_auth_publickey(ssh_message msg);
/**
* @brief Get the name of the authenticated user.
*
* @param[in] msg The message to get the username from.
*
* @return The username or NULL if an error occured.
*
* @see ssh_message_get()
* @see ssh_message_type()
*/
LIBSSH_API const char *ssh_message_auth_user(ssh_message msg);
/**
* @brief Get the password of the authenticated user.
*
* @param[in] msg The message to get the password from.
*
* @return The username or NULL if an error occured.
*
* @see ssh_message_get()
* @see ssh_message_type()
*/
LIBSSH_API const char *ssh_message_auth_password(ssh_message msg);
/**
* @brief Get the publickey of the authenticated user.
*
* If you need the key for later user you should duplicate it.
*
* @param[in] msg The message to get the public key from.
*
* @return The public key or NULL.
*
* @see ssh_key_dup()
* @see ssh_key_cmp()
* @see ssh_message_get()
* @see ssh_message_type()
*/
LIBSSH_API ssh_key ssh_message_auth_pubkey(ssh_message msg);
LIBSSH_API int ssh_message_auth_kbdint_is_response(ssh_message msg);
LIBSSH_API enum ssh_publickey_state_e ssh_message_auth_publickey_state(ssh_message msg);
LIBSSH_API int ssh_message_auth_reply_success(ssh_message msg,int partial);
LIBSSH_API int ssh_message_auth_reply_pk_ok(ssh_message msg, ssh_string algo, ssh_string pubkey);
@@ -253,8 +261,12 @@ LIBSSH_API int ssh_message_auth_reply_pk_ok_simple(ssh_message msg);
LIBSSH_API int ssh_message_auth_set_methods(ssh_message msg, int methods);
LIBSSH_API int ssh_message_auth_interactive_request(ssh_message msg,
const char *name, const char *instruction,
unsigned int num_prompts, const char **prompts, char *echo);
LIBSSH_API int ssh_message_service_reply_success(ssh_message msg);
LIBSSH_API char *ssh_message_service_service(ssh_message msg);
LIBSSH_API const char *ssh_message_service_service(ssh_message msg);
LIBSSH_API int ssh_message_global_request_reply_success(ssh_message msg,
uint16_t bound_port);
@@ -264,31 +276,38 @@ LIBSSH_API void ssh_set_message_callback(ssh_session session,
void *data);
LIBSSH_API int ssh_execute_message_callbacks(ssh_session session);
LIBSSH_API char *ssh_message_channel_request_open_originator(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_open_originator(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_open_originator_port(ssh_message msg);
LIBSSH_API char *ssh_message_channel_request_open_destination(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_open_destination(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_open_destination_port(ssh_message msg);
LIBSSH_API ssh_channel ssh_message_channel_request_channel(ssh_message msg);
LIBSSH_API char *ssh_message_channel_request_pty_term(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_pty_term(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_pty_width(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_pty_height(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_pty_pxwidth(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_pty_pxheight(ssh_message msg);
LIBSSH_API char *ssh_message_channel_request_env_name(ssh_message msg);
LIBSSH_API char *ssh_message_channel_request_env_value(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_env_name(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_env_value(ssh_message msg);
LIBSSH_API char *ssh_message_channel_request_command(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_command(ssh_message msg);
LIBSSH_API char *ssh_message_channel_request_subsystem(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_subsystem(ssh_message msg);
LIBSSH_API char *ssh_message_global_request_address(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_x11_single_connection(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_x11_auth_protocol(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_x11_auth_cookie(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_x11_screen_number(ssh_message msg);
LIBSSH_API const char *ssh_message_global_request_address(ssh_message msg);
LIBSSH_API int ssh_message_global_request_port(ssh_message msg);
LIBSSH_API int ssh_channel_open_reverse_forward(ssh_channel channel, const char *remotehost,
int remoteport, const char *sourcehost, int localport);
LIBSSH_API int ssh_channel_open_x11(ssh_channel channel,
const char *orig_addr, int orig_port);
LIBSSH_API int ssh_channel_request_send_exit_status(ssh_channel channel,
int exit_status);
@@ -301,6 +320,8 @@ LIBSSH_API int ssh_channel_write_stderr(ssh_channel channel,
const void *data,
uint32_t len);
LIBSSH_API int ssh_send_keepalive(ssh_session session);
/* deprecated functions */
SSH_DEPRECATED LIBSSH_API int ssh_accept(ssh_session session);
SSH_DEPRECATED LIBSSH_API int channel_write_stderr(ssh_channel channel,

View File

@@ -3,31 +3,30 @@
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef SESSION_H_
#define SESSION_H_
#include "libssh/priv.h"
#include "libssh/kex.h"
#include "libssh/packet.h"
#include "libssh/pcap.h"
#include "libssh/auth.h"
#include "libssh/channels.h"
#include "libssh/poll.h"
typedef struct ssh_kbdint_struct* ssh_kbdint;
/* These are the different states a SSH session can be into its life */
enum ssh_session_state_e {
@@ -55,14 +54,40 @@ enum ssh_pending_call_e {
SSH_PENDING_CALL_NONE = 0,
SSH_PENDING_CALL_CONNECT,
SSH_PENDING_CALL_AUTH_NONE,
SSH_PENDING_CALL_AUTH_PASSWORD
SSH_PENDING_CALL_AUTH_PASSWORD,
SSH_PENDING_CALL_AUTH_OFFER_PUBKEY,
SSH_PENDING_CALL_AUTH_PUBKEY,
SSH_PENDING_CALL_AUTH_AGENT,
SSH_PENDING_CALL_AUTH_KBDINT_INIT,
SSH_PENDING_CALL_AUTH_KBDINT_SEND,
SSH_PENDING_CALL_AUTH_GSSAPI_MIC
};
/* libssh calls may block an undefined amount of time */
#define SSH_SESSION_FLAG_BLOCKING 1
struct ssh_session_struct {
/* Client successfully authenticated */
#define SSH_SESSION_FLAG_AUTHENTICATED 2
/* codes to use with ssh_handle_packets*() */
/* Infinite timeout */
#define SSH_TIMEOUT_INFINITE -1
/* Use the timeout defined by user if any. Mostly used with new connections */
#define SSH_TIMEOUT_USER -2
/* Use the default timeout, depending on ssh_is_blocking() */
#define SSH_TIMEOUT_DEFAULT -3
/* Don't block at all */
#define SSH_TIMEOUT_NONBLOCKING 0
/* members that are common to ssh_session and ssh_bind */
struct ssh_common_struct {
struct error_struct error;
ssh_callbacks callbacks; /* Callbacks to user functions */
int log_verbosity; /* verbosity of the log functions */
};
struct ssh_session_struct {
struct ssh_common_struct common;
struct ssh_socket_struct *socket;
char *serverbanner;
char *clientbanner;
@@ -72,9 +97,6 @@ struct ssh_session_struct {
int openssh;
uint32_t send_seq;
uint32_t recv_seq;
/* status flags */
int closed;
int closed_by_except;
int connected;
/* !=0 when the user got a session handle */
@@ -102,9 +124,9 @@ struct ssh_session_struct {
enum ssh_auth_service_state_e auth_service_state;
enum ssh_auth_state_e auth_state;
enum ssh_channel_request_state_e global_req_state;
ssh_string dh_server_signature; /* information used by dh_handshake. */
KEX server_kex;
KEX client_kex;
struct ssh_agent_state_struct *agent_state;
struct ssh_auth_auto_state_struct *auth_auto_state;
ssh_buffer in_hashbuf;
ssh_buffer out_hashbuf;
struct ssh_crypto_struct *current_crypto;
@@ -118,21 +140,24 @@ struct ssh_session_struct {
/* keyb interactive data */
struct ssh_kbdint_struct *kbdint;
struct ssh_gssapi_struct *gssapi;
int version; /* 1 or 2 */
/* server host keys */
ssh_private_key rsa_key;
ssh_private_key dsa_key;
struct {
ssh_key rsa_key;
ssh_key dsa_key;
ssh_key ecdsa_key;
/* The type of host key wanted by client */
enum ssh_keytypes_e hostkey;
} srv;
/* auths accepted by server */
int auth_methods;
int hostkeys; /* contains type of host key wanted by client, in server impl */
struct ssh_list *ssh_message_list; /* list of delayed SSH messages */
int (*ssh_message_callback)( struct ssh_session_struct *session, ssh_message msg, void *userdata);
void *ssh_message_callback_data;
int log_verbosity; /*cached copy of the option structure */
int log_indent; /* indentation level in enter_function logs */
ssh_server_callbacks server_callbacks;
void (*ssh_connection_callback)( struct ssh_session_struct *session);
ssh_callbacks callbacks; /* Callbacks to user functions */
struct ssh_packet_callbacks_struct default_packet_callbacks;
struct ssh_list *packet_callbacks;
struct ssh_socket_callbacks_struct socket_callbacks;
@@ -141,23 +166,28 @@ struct ssh_session_struct {
#ifdef WITH_PCAP
ssh_pcap_context pcap_ctx; /* pcap debugging context */
#endif
char *username;
char *host;
char *bindaddr; /* bind the client to an ip addr */
char *xbanner; /* TODO: looks like it is not needed */
struct ssh_list *identity;
char *sshdir;
char *knownhosts;
char *wanted_methods[10];
char compressionlevel;
unsigned long timeout; /* seconds */
unsigned long timeout_usec;
unsigned int port;
socket_t fd;
int ssh2;
int ssh1;
int StrictHostKeyChecking;
char *ProxyCommand;
struct {
struct ssh_list *identity;
char *username;
char *host;
char *bindaddr; /* bind the client to an ip addr */
char *sshdir;
char *knownhosts;
char *wanted_methods[10];
char *ProxyCommand;
char *custombanner;
unsigned long timeout; /* seconds */
unsigned long timeout_usec;
unsigned int port;
socket_t fd;
int StrictHostKeyChecking;
int ssh2;
int ssh1;
char compressionlevel;
char *gss_server_identity;
char *gss_client_identity;
int gss_delegate_creds;
} opts;
};
/** @internal

View File

@@ -3,24 +3,23 @@
*
* Copyright (c) 2003-2008 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file sftp.h
* @defgroup libssh_sftp The libssh SFTP API
*
* @brief SFTP handling functions
*
@@ -32,7 +31,6 @@
* it can fetch it, while continuing to read for other messages (it is
* unspecified in which order messages may be sent back to the client
*
* @defgroup libssh_sftp The libssh SFTP API
* @{
*/
@@ -61,6 +59,8 @@ extern "C" {
#endif /* _MSC_VER */
#endif /* _WIN32 */
#define LIBSFTP_VERSION 3
typedef struct sftp_attributes_struct* sftp_attributes;
typedef struct sftp_client_message_struct* sftp_client_message;
typedef struct sftp_dir_struct* sftp_dir;
@@ -132,6 +132,8 @@ struct sftp_client_message_struct {
int attr_num;
ssh_buffer attrbuf; /* used by sftp_reply_attrs */
ssh_string data; /* can be newpath of rename() */
ssh_buffer complete_message; /* complete message in case of retransmission*/
char *str_data; /* cstring version of data */
};
struct sftp_request_queue_struct {
@@ -174,31 +176,47 @@ struct sftp_attributes_struct {
ssh_string extended_data;
};
/**
* @brief SFTP statvfs structure.
*/
struct sftp_statvfs_struct {
uint64_t f_bsize; /* file system block size */
uint64_t f_frsize; /* fundamental fs block size */
uint64_t f_blocks; /* number of blocks (unit f_frsize) */
uint64_t f_bfree; /* free blocks in file system */
uint64_t f_bavail; /* free blocks for non-root */
uint64_t f_files; /* total file inodes */
uint64_t f_ffree; /* free file inodes */
uint64_t f_favail; /* free file inodes for to non-root */
uint64_t f_fsid; /* file system id */
uint64_t f_flag; /* bit mask of f_flag values */
uint64_t f_namemax; /* maximum filename length */
uint64_t f_bsize; /** file system block size */
uint64_t f_frsize; /** fundamental fs block size */
uint64_t f_blocks; /** number of blocks (unit f_frsize) */
uint64_t f_bfree; /** free blocks in file system */
uint64_t f_bavail; /** free blocks for non-root */
uint64_t f_files; /** total file inodes */
uint64_t f_ffree; /** free file inodes */
uint64_t f_favail; /** free file inodes for to non-root */
uint64_t f_fsid; /** file system id */
uint64_t f_flag; /** bit mask of f_flag values */
uint64_t f_namemax; /** maximum filename length */
};
#define LIBSFTP_VERSION 3
/**
* @brief Start a new sftp session.
*
* @param session The ssh session to use.
*
* @return A new sftp session or NULL on error.
*
* @see sftp_free()
*/
LIBSSH_API sftp_session sftp_new(ssh_session session);
/**
* @brief Start a new sftp session with an existing channel.
*
* @param session The ssh session to use.
* @param channel An open session channel with subsystem already allocated
*
* @return A new sftp session or NULL on error.
*
* @see sftp_free()
*/
LIBSSH_API sftp_session sftp_new_channel(ssh_session session, ssh_channel channel);
/**
* @brief Close and deallocate a sftp session.
*
@@ -212,6 +230,8 @@ LIBSSH_API void sftp_free(sftp_session sftp);
* @param sftp The sftp session to initialize.
*
* @return 0 on success, < 0 on error with ssh error set.
*
* @see sftp_new()
*/
LIBSSH_API int sftp_init(sftp_session sftp);
@@ -224,6 +244,8 @@ LIBSSH_API int sftp_init(sftp_session sftp);
*
* @return The saved error (see server responses), < 0 if an error
* in the function occured.
*
* @see Server responses
*/
LIBSSH_API int sftp_get_error(sftp_session sftp);
@@ -283,7 +305,7 @@ LIBSSH_API int sftp_extension_supported(sftp_session sftp, const char *name,
/**
* @brief Open a directory used to obtain directory entries.
*
* @param session The sftp session handle to open the directory.
* @param path The path of the directory to open.
*
@@ -330,6 +352,8 @@ LIBSSH_API int sftp_dir_eof(sftp_dir dir);
*
* @return The sftp attributes structure of the file or directory,
* NULL on error with ssh and sftp error set.
*
* @see sftp_get_error()
*/
LIBSSH_API sftp_attributes sftp_stat(sftp_session session, const char *path);
@@ -345,6 +369,8 @@ LIBSSH_API sftp_attributes sftp_stat(sftp_session session, const char *path);
*
* @return The sftp attributes structure of the file or directory,
* NULL on error with ssh and sftp error set.
*
* @see sftp_get_error()
*/
LIBSSH_API sftp_attributes sftp_lstat(sftp_session session, const char *path);
@@ -355,6 +381,8 @@ LIBSSH_API sftp_attributes sftp_lstat(sftp_session session, const char *path);
*
* @return The sftp attributes structure of the file or directory,
* NULL on error with ssh and sftp error set.
*
* @see sftp_get_error()
*/
LIBSSH_API sftp_attributes sftp_fstat(sftp_file file);
@@ -392,7 +420,7 @@ LIBSSH_API int sftp_close(sftp_file file);
*
* @param file The file to be opened.
*
* @param accesstype Is one of O_RDONLY, O_WRONLY or O_RDWR which request
* @param accesstype Is one of O_RDONLY, O_WRONLY or O_RDWR which request
* opening the file read-only,write-only or read/write.
* Acesss may also be bitwise-or'd with one or more of
* the following:
@@ -410,12 +438,24 @@ LIBSSH_API int sftp_close(sftp_file file);
*
* @return A sftp file handle, NULL on error with ssh and sftp
* error set.
*
* @see sftp_get_error()
*/
LIBSSH_API sftp_file sftp_open(sftp_session session, const char *file, int accesstype,
mode_t mode);
/**
* @brief Make the sftp communication for this file handle non blocking.
*
* @param[in] handle The file handle to set non blocking.
*/
LIBSSH_API void sftp_file_set_nonblocking(sftp_file handle);
/**
* @brief Make the sftp communication for this file handle blocking.
*
* @param[in] handle The file handle to set blocking.
*/
LIBSSH_API void sftp_file_set_blocking(sftp_file handle);
/**
@@ -429,6 +469,8 @@ LIBSSH_API void sftp_file_set_blocking(sftp_file handle);
*
* @return Number of bytes written, < 0 on error with ssh and sftp
* error set.
*
* @see sftp_get_error()
*/
LIBSSH_API ssize_t sftp_read(sftp_file file, void *buf, size_t count);
@@ -569,6 +611,8 @@ LIBSSH_API void sftp_rewind(sftp_file file);
* @param file The file to unlink/delete.
*
* @return 0 on success, < 0 on error with ssh and sftp error set.
*
* @see sftp_get_error()
*/
LIBSSH_API int sftp_unlink(sftp_session sftp, const char *file);
@@ -580,6 +624,8 @@ LIBSSH_API int sftp_unlink(sftp_session sftp, const char *file);
* @param directory The directory to remove.
*
* @return 0 on success, < 0 on error with ssh and sftp error set.
*
* @see sftp_get_error()
*/
LIBSSH_API int sftp_rmdir(sftp_session sftp, const char *directory);
@@ -595,6 +641,8 @@ LIBSSH_API int sftp_rmdir(sftp_session sftp, const char *directory);
* The permissions of the created file are (mode & ~umask)
*
* @return 0 on success, < 0 on error with ssh and sftp error set.
*
* @see sftp_get_error()
*/
LIBSSH_API int sftp_mkdir(sftp_session sftp, const char *directory, mode_t mode);
@@ -610,6 +658,8 @@ LIBSSH_API int sftp_mkdir(sftp_session sftp, const char *directory, mode_t mode)
* after the move.
*
* @return 0 on success, < 0 on error with ssh and sftp error set.
*
* @see sftp_get_error()
*/
LIBSSH_API int sftp_rename(sftp_session sftp, const char *original, const char *newname);
@@ -624,6 +674,8 @@ LIBSSH_API int sftp_rename(sftp_session sftp, const char *original, const char
* which should be changed.
*
* @return 0 on success, < 0 on error with ssh and sftp error set.
*
* @see sftp_get_error()
*/
LIBSSH_API int sftp_setstat(sftp_session sftp, const char *file, sftp_attributes attr);
@@ -639,6 +691,8 @@ LIBSSH_API int sftp_setstat(sftp_session sftp, const char *file, sftp_attributes
* @param group The new group which should be set.
*
* @return 0 on success, < 0 on error with ssh and sftp error set.
*
* @see sftp_get_error()
*/
LIBSSH_API int sftp_chown(sftp_session sftp, const char *file, uid_t owner, gid_t group);
@@ -654,6 +708,8 @@ LIBSSH_API int sftp_chown(sftp_session sftp, const char *file, uid_t owner, gid_
* The permissions of the created file are (mode & ~umask)
*
* @return 0 on success, < 0 on error with ssh and sftp error set.
*
* @see sftp_get_error()
*/
LIBSSH_API int sftp_chmod(sftp_session sftp, const char *file, mode_t mode);
@@ -668,6 +724,8 @@ LIBSSH_API int sftp_chmod(sftp_session sftp, const char *file, mode_t mode);
* and modification time.
*
* @return 0 on success, < 0 on error with ssh and sftp error set.
*
* @see sftp_get_error()
*/
LIBSSH_API int sftp_utimes(sftp_session sftp, const char *file, const struct timeval *times);
@@ -681,6 +739,8 @@ LIBSSH_API int sftp_utimes(sftp_session sftp, const char *file, const struct tim
* @param dest Specifies the path name of the symlink to be created.
*
* @return 0 on success, < 0 on error with ssh and sftp error set.
*
* @see sftp_get_error()
*/
LIBSSH_API int sftp_symlink(sftp_session sftp, const char *target, const char *dest);
@@ -692,6 +752,8 @@ LIBSSH_API int sftp_symlink(sftp_session sftp, const char *target, const char *d
* @param path Specifies the path name of the symlink to be read.
*
* @return The target of the link, NULL on error.
*
* @see sftp_get_error()
*/
LIBSSH_API char *sftp_readlink(sftp_session sftp, const char *path);
@@ -703,6 +765,8 @@ LIBSSH_API char *sftp_readlink(sftp_session sftp, const char *path);
* @param path The pathname of any file within the mounted file system.
*
* @return A statvfs structure or NULL on error.
*
* @see sftp_get_error()
*/
LIBSSH_API sftp_statvfs_t sftp_statvfs(sftp_session sftp, const char *path);
@@ -712,6 +776,8 @@ LIBSSH_API sftp_statvfs_t sftp_statvfs(sftp_session sftp, const char *path);
* @param file An opened file.
*
* @return A statvfs structure or NULL on error.
*
* @see sftp_get_error()
*/
LIBSSH_API sftp_statvfs_t sftp_fstatvfs(sftp_file file);
@@ -773,8 +839,14 @@ int buffer_add_attributes(ssh_buffer buffer, sftp_attributes attr);
sftp_attributes sftp_parse_attr(sftp_session session, ssh_buffer buf,int expectname);
/* sftpserver.c */
sftp_client_message sftp_get_client_message(sftp_session sftp);
void sftp_client_message_free(sftp_client_message msg);
LIBSSH_API sftp_client_message sftp_get_client_message(sftp_session sftp);
LIBSSH_API void sftp_client_message_free(sftp_client_message msg);
LIBSSH_API uint8_t sftp_client_message_get_type(sftp_client_message msg);
LIBSSH_API const char *sftp_client_message_get_filename(sftp_client_message msg);
LIBSSH_API void sftp_client_message_set_filename(sftp_client_message msg, const char *newname);
LIBSSH_API const char *sftp_client_message_get_data(sftp_client_message msg);
LIBSSH_API uint32_t sftp_client_message_get_flags(sftp_client_message msg);
LIBSSH_API int sftp_send_client_message(sftp_session sftp, sftp_client_message msg);
int sftp_reply_name(sftp_client_message msg, const char *name,
sftp_attributes attr);
int sftp_reply_handle(sftp_client_message msg, ssh_string handle);

View File

@@ -3,20 +3,19 @@
*
* Copyright (c) 2009 by Aris Adamantiadis
*
* The SSH Library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at your
* option) any later version.
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* The SSH Library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the SSH Library; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef SOCKET_H_
@@ -53,9 +52,12 @@ void ssh_socket_set_write_wontblock(ssh_socket s);
void ssh_socket_set_read_wontblock(ssh_socket s);
void ssh_socket_set_except(ssh_socket s);
int ssh_socket_get_status(ssh_socket s);
int ssh_socket_get_poll_flags(ssh_socket s);
int ssh_socket_buffered_write_bytes(ssh_socket s);
int ssh_socket_data_available(ssh_socket s);
int ssh_socket_data_writable(ssh_socket s);
int ssh_socket_set_nonblocking(socket_t fd);
int ssh_socket_set_blocking(socket_t fd);
void ssh_socket_set_callbacks(ssh_socket s, ssh_socket_callbacks callbacks);
int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd, int revents, void *v_s);

View File

@@ -13,6 +13,10 @@
#define SSH2_MSG_KEXDH_INIT 30
#define SSH2_MSG_KEXDH_REPLY 31
#define SSH2_MSG_KEX_ECDH_INIT 30
#define SSH2_MSG_KEX_ECDH_REPLY 31
#define SSH2_MSG_ECMQV_INIT 30
#define SSH2_MSG_ECMQV_REPLY 31
#define SSH2_MSG_KEX_DH_GEX_REQUEST_OLD 30
#define SSH2_MSG_KEX_DH_GEX_GROUP 31
@@ -26,7 +30,14 @@
#define SSH2_MSG_USERAUTH_PK_OK 60
#define SSH2_MSG_USERAUTH_PASSWD_CHANGEREQ 60
#define SSH2_MSG_USERAUTH_INFO_REQUEST 60
#define SSH2_MSG_USERAUTH_GSSAPI_RESPONSE 60
#define SSH2_MSG_USERAUTH_INFO_RESPONSE 61
#define SSH2_MSG_USERAUTH_GSSAPI_TOKEN 61
#define SSH2_MSG_USERAUTH_GSSAPI_EXCHANGE_COMPLETE 63
#define SSH2_MSG_USERAUTH_GSSAPI_ERROR 64
#define SSH2_MSG_USERAUTH_GSSAPI_ERRTOK 65
#define SSH2_MSG_USERAUTH_GSSAPI_MIC 66
#define SSH2_MSG_GLOBAL_REQUEST 80
#define SSH2_MSG_REQUEST_SUCCESS 81
#define SSH2_MSG_REQUEST_FAILURE 82

Some files were not shown because too many files have changed in this diff Show More