Compare commits

..

2457 Commits

Author SHA1 Message Date
Andreas Schneider
2721cbc8ee ChangeLog: Set release date for 0.7.0 2015-05-11 10:42:08 +02:00
Andreas Schneider
5eb7a6ca38 cpack: Use application version.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-08 13:54:56 +02:00
Andreas Schneider
3f4b5436e5 Bump version to 0.7.0
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-06 11:01:33 +02:00
Andreas Schneider
82cf5ea24c Update ChangeLog
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-06 11:00:43 +02:00
Andreas Schneider
90e4786523 valgrind: Add suppression for openssl FIPS dlopen leak
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-06 10:27:09 +02:00
Andreas Schneider
f65f41acc2 valgrind: Ignore valgrind free bug on exit
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-06 10:23:27 +02:00
Andreas Schneider
8979150745 tests: Migrate torture_keyfiles to testkey functions
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-06 09:47:37 +02:00
Andreas Schneider
f81d296e54 torture: Move TORTURE_TESTKEY_PASSWORD to header
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-06 09:47:17 +02:00
Andreas Schneider
57afe78167 tests: Fix memory leak in torture_server_x11 test
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-06 09:33:51 +02:00
Jon Simons
ee460dc04b kex: also compare host keys for 'first_kex_packet_follows'
Also consider the host key type at hand when computing whether a
'first_kex_packet_follows' packet matches the current server settings.
Without this change libssh may incorrectly believe that guessed
settings which match by kex algorithm alone fully match: the host
key types must also match.  Observed when testing with dropbear
clients.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-05 22:03:47 +02:00
Jon Simons
f134cb3d57 server: return SSH_OK for ignored SSH_MSG_KEXDH_INIT case
Return SSH_OK for the case that an incoming SSH_MSG_KEXDH_INIT should be
ignored.  That is, for the case that the initial 'first_kex_packet_follows'
guess is incorrect.  Before this change sessions served with libssh can be
observed to error out unexpectedly early when testing with dropbear clients
that send an incompatible guess.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-05 22:03:32 +02:00
Andreas Schneider
3eaad77de2 tests: Only link against threading library if available
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-05 19:09:51 +02:00
Andreas Schneider
9244750a63 cmake: Add missing OpenSSL include directory
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-05 19:04:49 +02:00
Andreas Schneider
e8720a30e2 cmake: Add --enable-stdcall-fixup for MinGW builds
This fixes warnings for getaddrinfo() and freeaddrinfo().

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-05 18:59:30 +02:00
Andreas Schneider
ad09009201 include: Fix variadic macro issues with MSVC
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-05 18:45:47 +02:00
Andreas Schneider
e4e3b3052f tests: Apply umask before calling mkstemp()
CID: #978660

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-05 11:27:09 +02:00
Andreas Schneider
96882cc58c example: Fix a use after free in the scp example
CID: #1032343

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-05 11:27:09 +02:00
Andreas Schneider
7c79959e94 example: Check return value of ssh_get_fd()
CID: #1199454

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-05 11:27:09 +02:00
Andreas Schneider
ca501df8c8 sftp: Fix size check
CID: #1296588

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-05 11:26:40 +02:00
Andreas Schneider
a4cecf59d5 external: Fix resetting the state
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-04 18:10:30 +02:00
Andreas Schneider
244881b87d external: Make sure we burn buffers in bcrypt
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-04 17:54:01 +02:00
Andreas Schneider
cf05e653de external: Fix a possible buffer overrun in bcrypt_pbkdf
CID: #1250106

This fixes a 1 byte output overflow for large key length (not reachable
in libssh). Pulled from OpenBSD BCrypt PBKDF implementation.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-04 17:54:01 +02:00
Andreas Schneider
4b9916136d sftp: Add bound check for size
CID: #1238630

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-04 17:54:01 +02:00
Andreas Schneider
33ecff11dd buffer: Cleanup vaargs in ssh_buffer_unpack_va()
CID: #1267977

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-04 17:54:01 +02:00
Andreas Schneider
83d3ee7fdb string: Improve ssh_string_len() to avoid tainted variables
CID: #1278978

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-04 17:54:01 +02:00
Andreas Schneider
b1a3f4ee33 pki_container: Fix a memory leak
CID: #1267980

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-04 17:54:01 +02:00
Andreas Schneider
05498e0e33 pki_container: Add check for return value
CID: #1267982

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-04 17:54:01 +02:00
Andreas Schneider
4948fe21cd tests: Fix ctest default script
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-04 15:52:17 +02:00
Andreas Schneider
fe8fcb805c cmake: Add support for Address Sanitizer
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-04 15:25:17 +02:00
Andreas Schneider
c4af6fbce3 config: Add missing HAVE_ARPA_INET_H define
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-05-04 10:04:26 +02:00
Aris Adamantiadis
3091025472 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>
2015-04-23 10:33:52 +02:00
Aris Adamantiadis
bf0c7ae0ae 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>
2015-04-23 10:15:47 +02:00
Kevin Fan
b5dc8197f7 Fix leak of sftp->ext when sftp_new() fails
Signed-off-by: Kevin Fan <kevinfan@google.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-14 20:56:56 +02:00
Andreas Schneider
19e23e6128 cmake: Require cmake 2.8.5
I've improved FindOpenSSL and FindZLIB in that version to work well with
Windows and Linux. This was 2011 it should be old enough that most
distributions have at least this version available.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-10 14:35:29 +02:00
Andreas Schneider
195f25cfbd cmake: Detect network function correctly on Windows
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-10 13:32:09 +02:00
Andreas Schneider
1cb940c44a socket: Cleanup ssh_socket_close() code.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-10 13:32:09 +02:00
Andreas Schneider
3f04367fb8 bind: Correctly close sockets and invalidate them.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-10 13:32:09 +02:00
Andreas Schneider
6c7e552509 cmake: Require cmake version 2.8.0 2015-04-10 13:32:09 +02:00
Andreas Schneider
b1cb8de385 cmake: Check for sys/param.h header file
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-10 13:07:12 +02:00
Andreas Schneider
69c9cd029f cmake: Check for arpa/inet.h header file
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-10 13:02:56 +02:00
Andreas Schneider
c699b9ca94 external: Use standard int types
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-10 13:02:56 +02:00
Andreas Schneider
53586ed4ba include: Do not make x11 variables const
We allocate them and also free them after the callback has been
executed.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-02 16:19:45 +02:00
Andreas Schneider
5236358a48 messages: Don't leak memory after callback execution
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-02 16:13:20 +02:00
Andreas Schneider
d6fe9dc220 unittests: Fix memory leak in torture_pki_ed25519
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-02 15:05:19 +02:00
Andreas Schneider
e0a73d3dbe poll: Fix compilation with struct ssh_timestamp
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-02 15:02:29 +02:00
Andreas Schneider
dbe7df7571 cmake: Detect __func__ and __FUNCTION__ during configure step
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-02 13:41:02 +02:00
Andreas Schneider
a3357b8920 include: We should use __func__ which is C99
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-04-02 10:58:36 +02:00
Seb Boving
7ec798d3e7 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:05:54 +01:00
xjoaalm
f32e5f2191 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:01:15 +01:00
Andreas Schneider
cd078c7085 cmake: Drop reports via https only.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-20 15:47:22 +01:00
Aris Adamantiadis
2e445d5871 torture: fix includes for freebsd10 2015-02-14 22:09:02 +01:00
Aris Adamantiadis
5c46fbc680 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:38:21 +01:00
Aris Adamantiadis
2a780afc57 tests: workaround for compiling with older cmocka 2015-02-12 11:19:04 +01:00
Aris Adamantiadis
940cb233ce buffer: buffer_pack & unpack on non-gnu compilers 2015-02-08 18:49:32 +01:00
Aris Adamantiadis
a653e27a2e buffer: detect compilers not supporting __VA_ARGS__ 2015-02-08 18:49:02 +01:00
Aris Adamantiadis
d3f30da158 buffer: fix use-before-nullcheck (coverity #1267979)
Additionally, the function call was already existing after
the NULL check
2015-02-03 22:21:22 +01:00
Aris Adamantiadis
760d93e87b Revert "pki_gcrypt: fix warnings for SSH_KEYTYPE_ED25519"
This reverts commit 10f71c6769.
Commit was redundant with ed25519 branch
2015-02-03 09:58:28 +01:00
Aris Adamantiadis
d42a1a35b0 tests: allow conditionnal execution on pattern
Option can be used to filter out irrelevant tests
usage: ./torture_pki '*ed25519'

Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 17:34:15 +01:00
Aris Adamantiadis
8af829a42a base64: Use secure buffers
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 17:33:58 +01:00
Andreas Schneider
ad8fa427dd buffer: Abort if the canary is not intact in ssh_buffer_unpack()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2015-02-02 17:32:34 +01:00
Andreas Schneider
de10a7754b buffer: buffer: Improve argument checking of in ssh_buffer_pack()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2015-02-02 17:32:31 +01:00
Andreas Schneider
6789170799 buffer: Abort if the canary is not intact in ssh_buffer_unpack()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2015-02-02 17:32:28 +01:00
Andreas Schneider
afc9988c93 buffer: Improve argument checking in ssh_buffer_pack()
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2015-02-02 17:32:18 +01:00
Aris Adamantiadis
2490404d45 Move all 3rd-party C files to src/external/
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:53 +01:00
Aris Adamantiadis
fbdb940c46 ed25519: Add test for signatures and verification
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:52 +01:00
Aris Adamantiadis
c8d0b724b3 tests: Add ed25519 encrypted keys export
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:52 +01:00
Aris Adamantiadis
9e4700cdc0 ed25519: Add support for OpenSSH encrypted container export
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:52 +01:00
Aris Adamantiadis
b76d37b341 tests: Add ed25519 encrypted keys import
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:52 +01:00
Aris Adamantiadis
423fa6818b ed25519: ADd OpenSSH encrypted container import
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:52 +01:00
Aris Adamantiadis
61e2c8f0f7 external: Add OpenSSH bcrypt and blowfish implementation
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:52 +01:00
Aris Adamantiadis
c02b260e7e server: Add support for ed25519 keys in the server.
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:52 +01:00
Aris Adamantiadis
01a6004171 kex: Add support for ed25519 on client connections.
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:52 +01:00
Aris Adamantiadis
4f5660e081 tests: Add ed25519 OpenSSH key saving
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:52 +01:00
Aris Adamantiadis
46bc11f977 ed25519: Add support to export OpenSSH container keys
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:52 +01:00
Aris Adamantiadis
119840b0a9 tests: Add ed25519 OpenSSH key loading and operations
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:52 +01:00
Aris Adamantiadis
4343ac5b08 libgcrypt: Make the PEM parser ed25519 aware
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:52 +01:00
Aris Adamantiadis
6b9183a20b libcrypto: Make the PEM parser ed25519 aware
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:52 +01:00
Aris Adamantiadis
3ec3a926e5 ed25519: Add support o import OpenSSH container keys
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:52 +01:00
Aris Adamantiadis
2f7886837f pki.h: Replace tabs with spaces
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-02-02 14:45:52 +01:00
Aris Adamantiadis
7febad5821 kex: disable des-cbc-ssh1 by default
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-01-26 08:57:06 +01:00
Andreas Schneider
b235c380f2 packet_cb: Add misssing include for ntohl().
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-01-21 09:23:43 +01:00
Andreas Schneider
f6a50aff4c tests: Fix torture_server_x11(). 2015-01-21 09:19:30 +01:00
Alan Dunn
6b7f275c32 tests: Add torture_server_x11 test.
torture_server_x11 tests whether a libssh server can correctly parse an
X11 request.

Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-01-20 20:23:19 +01:00
Alan Dunn
4bde48bb2e tests: Add ssh server setup functionality
Add the ability to generate a keypair (RSA, but tests that focus on
what occurs over a connection may well not care) and an ssh_bind
easily.

Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-01-20 19:50:52 +01:00
Alan Dunn
f4154c503b tests: Add port option to torture_ssh_session
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-01-20 19:41:53 +01:00
Léo Peltier
8db4520d89 cmake: Add libsshpp.hpp to the distributed headers list.
BUG: https://red.libssh.org/issues/163

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-01-20 19:32:48 +01:00
Andreas Schneider
9a7d450098 pki: Make sure sig is not used unintialized.
BUG: https://red.libssh.org/issues/167

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-01-20 19:31:12 +01:00
William Orr
7070117dc3 examples: Use safer names for stdin, stdout, stderr
BUG: https://red.libssh.org/issues/168

On some platforms, like OpenBSD, stdin and friends are macros which break
compilation of this struct. I've fixed these names such that it compiles and
runs cleanly on OpenBSD

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-01-20 19:27:14 +01:00
Andreas Schneider
433f8fd550 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>
2015-01-20 19:01:15 +01:00
Yanis Kurganov
c6590bd189 channels1: Fix pty request state
Signed-off-by: Yanis Kurganov <YKurganov@ptsecurity.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-01-20 18:58:13 +01:00
Andreas Schneider
929868c691 Update README.CodingStyle 2015-01-20 12:08:51 +01:00
Andreas Schneider
06a0d8ff1c connect: Fix a memory leak.
CID: #1238618

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2015-01-14 15:20:52 +01:00
Andreas Schneider
af0dd3fb02 sftp: Fix a possible integer overflow.
CID: #1238630

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2015-01-14 15:20:49 +01:00
Andreas Schneider
ce02f6576a 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>
2015-01-14 15:20:46 +01:00
Andreas Schneider
68e720a3da pkd: Make sure we do not pass -1 to close.
CID: #1245696

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2015-01-14 15:20:43 +01:00
Andreas Schneider
c224508bf8 pkd: Check return value of pkd_run_tests().
CID: #1245697

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2015-01-14 15:20:34 +01:00
Tobias Klauser
15d71a8c51 sftp: Fix memory leak on realloc failure
If realloc of sftp->ext->name or sftp->ext->data fails, the memory
previously allocated for the respective member is leaked. Fix this by
storing the return value of realloc() in a temporary variable which only
gets assigned to the respective sftp->ext member on success.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-01-14 10:22:55 +01:00
Andreas Schneider
8536cd9808 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>
2015-01-13 08:53:42 +01:00
Tobias Klauser
353751e3e3 doc: Fix a typo in curve25519-sha256@libssh.org.txt
Fix the typo 'stengths' -> 'strengths' and remove the trailing white
space on the same line.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2015-01-13 08:45:51 +01:00
Andreas Schneider
159ef828dd doc: Fix link to curve25519-sha256@libssh.org spec. 2015-01-06 15:24:30 +01:00
Andreas Schneider
3dd069c0c8 doc: Fix a typo, blank lines and trailing spaces. 2015-01-06 15:22:16 +01:00
Andreas Schneider
a198193723 connect: Fix mingw build.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2015-01-06 15:12:17 +01:00
Andreas Schneider
e051135a05 connect: Check that errno is 0 to fix Windows build.
Thanks to Viktor Butskih.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2014-12-25 12:34:59 +01:00
Andreas Schneider
bb18442fe8 options: Fix setting the port.
Make sure we correctly read the port from the config file.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2014-12-25 12:32:16 +01:00
Jon Simons
c2aed4ca78 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>
2014-12-17 19:45:09 +01:00
Andreas Schneider
b7b535816d 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>
2014-12-17 19:39:18 +01:00
Andreas Schneider
d8e691b58a cmake: Fix config variable names.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2014-12-17 10:38:56 +01:00
William Orr
52968b1a11 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>
2014-12-17 10:34:27 +01:00
Jon Simons
b35f1f488c pki_gcrypt: fix DSA signature extraction
Fix DSA signature extraction for the LIBGCRYPT build.  Here, the same fix
that was applied to the LIBCRYPTO build for https://red.libssh.org/issues/144
is now adapted for pki_gcrypt.  Additionally, ensure to set the resulting
output sig_blob buffer before returning.

Before this fix, one can observe the failure with the pkd test on a LIBGCRYPT
build as so:

  # ./pkd_hello -i 1 -t torture_pkd_openssh_dsa_dsa_default

After, runs of 10000 back-to-back iterations of the same test are passing.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-12-09 19:21:47 +01:00
Jon Simons
10f71c6769 pki_gcrypt: fix warnings for SSH_KEYTYPE_ED25519
Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-12-09 19:21:34 +01:00
Jon Simons
014fde0542 torture: fix warning for SSH_KEYTYPE_ED25519
Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-12-09 19:21:18 +01:00
Jon Simons
ca2acec34a bignum: no-op make_string_bn_inplace for LIBGCRYPT
Disable the 'make_string_bn_inplace' helper function for the LIBGCRYPT
build, rather than using '#error' to fail the build completely.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-12-09 19:20:46 +01:00
Davide \"FunkyAss\" Del Zompo
bb197de75d doc: clarify tutorial error section
Signed-off-by: Davide "FunkyAss" Del Zompo <davide.delzompo@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-12-05 11:09:00 +01:00
Hani Benhabiles
03095f1516 Set the correct error in ssh_options_set().
Signed-off-by: Hani Benhabiles <hani@linux.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-12-05 11:03:55 +01:00
Jon Simons
6895d0b727 session: add getter for kexalgo
Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-12-05 10:48:07 +01:00
Jon Simons
4745d652b5 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>
2014-12-05 10:42:32 +01:00
Andreas Schneider
a48711ae7e connect: Do not fail if the connect is in progress.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2014-10-15 10:27:55 +02:00
Jon Simons
a25790d343 tests: fix pkd build breakages
Fix a build breakage when '-DWITH_SERVER=OFF' is set: skip building the
pkd test for that case.  Add some missing includes for the OpenIndiana
and FreeBSD builds.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-10-15 10:26:24 +02:00
Stef Walter
cd2dc3770a 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>
2014-10-12 15:41:15 +02:00
William Orr
250f506487 Check return code of connect(2).
Signed-off-by: William Orr <will@worrbase.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-10-12 15:39:58 +02:00
Jon Simons
9dc932c02b tests: introduce pkd_hello
Introduce a sample public-key testing daemon to the 'pkd' test directory,
and add support code for cycling through various combinations of different
key exchange, cipher, and MAC algorithms.

The goal of the 'pkd_hello' test is to make it easy to test interactions
between non-libssh clients and a libssh-server, and to provide a starting
point for testing new implementations for key types, ciphers, MACs, and
so on.  The thinking is that testing a new algorithm should be as simple
as adding a new line for it in the PKDTESTS_* lists.

Macros are used to generate the tests and helper functions for a couple of
clients -- here, OpenSSH and dropbear are included for the first cut.  If
binaries are found for these clients, their test lists will be enabled;
when binaries are not found for a given client, those tests are skipped.

Tests are run in one large batch by default, but can also be run individually
to help with tracking down things like signature bugs that may take many
iterations to reproduce.

Each test logs its stdout and stderr to its own file, which is cleaned up
when a test succeeds.  For failures, those logs can be combined with verbose
libssh output from pkd itself to start debugging things.

Some example usages:

  pkd_hello
    Run all tests with default number of iterations.

  pkd_hello --list
    List available individual test names.

  pkd_hello -i 1000 -t torture_pkd_openssh_ecdsa_256_ecdh_sha2_nistp256
    Run only the torture_pkd_openssh_ecdsa_256_ecdh_sha2_nistp256
    testcase 1000 times.

  pkd_hello -v -v -v -v -e -o
    Run all tests with maximum libssh and pkd logging.

Included in the tests are passes for all existing kex, cipher, and MAC
algorithms.

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

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-10-12 15:01:02 +02:00
Artyom V. Poptsov
aaae6cd97d 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>
2014-10-02 08:30:17 +02:00
Jon Simons
509676e3a4 server: fix auth_interactive_request reply
Fix a missing 'buffer_pack' formatter in 'ssh_message_auth_interactive_request'.
With this fix the 'examples/samplesshd-kbdint' program is working again for me.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-10-02 08:29:22 +02:00
Jon Simons
a6d412f0d7 ed25519: fix leak in pki_ed25519_sign
Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-10-02 08:28:51 +02:00
Jon Simons
59da8dab50 pki: check ssh_buffer_pack return in ssh_pki_do_sign
Check the 'ssh_buffer_pack' return in ssh_pki_do_sign for the ED25519 case.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-10-02 08:28:05 +02:00
Jon Simons
7edbedf0dd pki: fail when pubkey buffer length is not ED25519_PK_LEN
Fail fast in 'pki_import_pubkey_buffer' for the ED25519 case if a buffer
sized ED25519_PK_LEN can not be retrieved.  Before, the 'memcpy' could
have read beyond the bounds of 'ssh_string_data(pubkey)'.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-10-02 08:27:05 +02:00
Jon Simons
af25c5e668 crypto: check malloc return in ssh_mac_ctx_init
Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-10-02 08:25:53 +02:00
Jon Simons
092fe0b727 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>
2014-10-02 08:25:10 +02:00
Andreas Schneider
1ddb99c46f string: Correctly burn the string buffer.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-09-15 20:45:47 +02:00
Aris
93c7b81b4e ed25519: Generate, sign and verify keys.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-09-07 22:07:34 +02:00
Aris Adamantiadis
93e82fa0c0 crypto: Add ed25519 implementation from OpenSSH.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-09-07 21:35:20 +02:00
Aris Adamantiadis
e9b2d164e0 base64: Use a secure buffer.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-09-07 10:38:23 +02:00
Aris Adamantiadis
86ae6b2251 buffer: Add a secure buffer mechanism to avoid memory spills
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-09-07 10:36:32 +02:00
Aris Adamantiadis
2cb2587b55 buffer: Implement "t" for text in ssh_buffer_pack().
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-09-07 10:27:35 +02:00
Andreas Schneider
86294ad3ea dh: Fix packing a pointer into the buffer.
Thanks to Giovanni Panozzo <giovanni@panozzo.it>.

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2014-08-25 12:23:17 +02:00
Andreas Schneider
173994786b tests: Fix writing the '\0'.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2014-08-18 21:41:36 +02:00
Andreas Schneider
81123d6a91 ec: Fix build on CentOS.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2014-08-18 10:08:00 +02:00
Andreas Schneider
25eb9c4914 tests: Use public testkey passphrase function in pki test.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-08-15 12:32:57 +02:00
Andreas Schneider
c6210f5aef torture: Add public testkey passphrase function.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-08-15 12:32:54 +02:00
Andreas Schneider
c673543e54 tests: Use public testkeys in pki test.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-08-15 12:32:51 +02:00
Andreas Schneider
edca9d6e96 torture: Add public testkey functions.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-08-15 12:32:47 +02:00
Andreas Schneider
83aed7610c tests: Make write file a public torture function.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-08-15 12:32:37 +02:00
Andreas Schneider
5fa4721c6e auth: Fix a memory leak in agent publickey auth.
CID: 1230358

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-08-15 12:29:26 +02:00
Andreas Schneider
8b7627efd5 tests: Make sure we null terminate the buffer.
CID: 1230359

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-08-15 12:29:23 +02:00
Andreas Schneider
662217f409 packet: Check return value of ssh_buffer_unpack().
CID: 1230357

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-08-15 12:29:20 +02:00
Andreas Schneider
19433dca00 messages: Check return value of ssh_buffer_unpack().
CID: 1230356

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-08-15 12:29:16 +02:00
Andreas Schneider
6961dd79ad tests: Fix memory leak in buffer test.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-08-15 12:29:13 +02:00
Andreas Schneider
1b6375ce89 buffer: Make sure rc is initialized.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-08-15 12:29:11 +02:00
Andreas Schneider
64f6abead7 libgcrypt: Fix initializer name.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-08-15 12:29:07 +02:00
Andreas Schneider
f20a6d0a82 bignum: Add missing include.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-08-15 12:29:00 +02:00
Andreas Schneider
97c6b76863 messages: Fix two ssh_buffer_unpack().
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Aris Adamantiadis <aris@0xbadc0de.be>
2014-08-07 17:28:42 +02:00
Aris Adamantiadis
6019cf1bed Fix sftp endianess bugs
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 10:08:25 +02:00
Aris Adamantiadis
228dc08038 bignums: detach bignum-related functions from dh.c.
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 10:07:36 +02:00
Aris Adamantiadis
33cd594f1f crypto: fix secure burning, structure members naming
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 10:05:19 +02:00
Aris Adamantiadis
0cd0f685c9 torture_pki: avoid generating keys with ssh-keygen
ssh-keygen makes the tests very slow because new keys are generated
at the start of every test.
ssh-keygen on OSX doesn't support ecdsa keys, even if libcrypto does.

Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 10:04:57 +02:00
Aris Adamantiadis
664b94d1c5 tests: test the canary feature in buffer_(un)pack()
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 10:00:07 +02:00
Aris Adamantiadis
3b4b0f01ec buffer: add a hidden canary to detect format errors
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 09:58:52 +02:00
Aris Adamantiadis
7bd62dd652 buffers: adapt sftpserver.c to ssh_buffer_(un)pack()
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 09:52:29 +02:00
Aris Adamantiadis
c341da03d3 buffers: adapt sftp.c to ssh_buffer_(un)pack()
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 09:51:00 +02:00
Aris Adamantiadis
c238136010 buffers: adapt session.c to ssh_buffer_(un)pack()
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 09:47:35 +02:00
Aris Adamantiadis
5a08ddcff2 buffers: adapt server.c to ssh_buffer_(un)pack()
Signed-off-by: Andreas Schneider <asn@samba.org>
2014-08-06 09:46:14 +02:00
Aris Adamantiadis
a182926024 buffers: adapt pcap.c to ssh_buffer_(un)pack()
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 09:46:14 +02:00
Aris Adamantiadis
9457685320 buffers: adapt ecdh.c to ssh_buffer_(un)pack()
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 09:46:14 +02:00
Aris Adamantiadis
e9fd14c7f0 buffers: adapt packet.c to ssh_buffer_(un)pack()
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 09:46:14 +02:00
Aris Adamantiadis
cfd2e4894e buffers: adapt messages.c to ssh_buffer_(un)pack()
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 09:46:14 +02:00
Aris Adamantiadis
3703389feb buffers: adapt gssapi.c to ssh_buffer_(un)pack() 2014-08-06 09:46:14 +02:00
Aris Adamantiadis
673990f568 buffers: adapt curve25519.c to ssh_buffer_(un)pack()
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 09:33:32 +02:00
Aris Adamantiadis
97638a1465 buffers: adapt client.c to ssh_buffer_(un)pack()
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 09:33:07 +02:00
Aris Adamantiadis
506e11fa8b buffers: adapt channels.c to ssh_buffer_(un)pack()
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 09:33:03 +02:00
Aris Adamantiadis
1dd95675df buffer: adapt dh.c to new ssh_buffer_(un)pack()
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 09:20:49 +02:00
Aris Adamantiadis
cb10ad0c84 buffer: adapt kex.c to new ssh_buffer_(un)pack()
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 09:20:49 +02:00
Aris Adamantiadis
1f2c61d6ad buffer: adapt auth.c to ssh_buffer_(un)pack()
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-08-06 09:20:49 +02:00
Aris Adamantiadis
1d97f75b0a tests: test for ssh_buffer_(un)pack
Reviewed-by: Andreas Schneider <asn@samba.org>
2014-08-06 09:20:45 +02:00
Aris Adamantiadis
835e34d1eb Buffer: add ssh_buffer_(un)pack()
That function permits chaining of buffer values to minimize buffer handling
in packet sending code.

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-08-06 09:04:34 +02:00
Aris Adamantiadis
13c42bff3f examples: cast arguments of connect(2)
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-07-06 20:36:49 +02:00
Andreas Schneider
59a1799501 log: Add check for return value.
For some reason I got a segfault in gdb here. Make sure it works
correctly.
2014-06-10 13:52:38 +02:00
Andreas Schneider
d9c47a8cfa tests: Add test for the logging function. 2014-06-10 13:52:20 +02:00
Jon Simons
987991a3f2 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:23:46 +02:00
Andreas Schneider
a738507ad2 cmake: Fix the build on Windows. 2014-05-27 15:42:53 +02:00
Andreas Schneider
142b2e4ede cmake: Fix libssh cmake-config files. 2014-05-22 14:52:52 +02:00
Hani Benhabiles
517a01b7ad Set the correct version in CMakeLists.txt
Signed-off-by: Hani Benhabiles <hani@linux.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-05-20 09:41:20 +02:00
Andreas Schneider
83633d539e pki: Fix build without ECC support.
Signed-off-by: Andreas Schneider <asn@samba.org>
2014-05-09 08:55:49 +02:00
Andreas Schneider
c2ee63431b pki: Add missing semi-colon. 2014-05-07 09:30:29 +02:00
Jon Simons
9e4bc10525 kex: NULL checks for 'first_kex_packet_follows'
Add NULL checks to 'is_first_kex_packet_follows_guess_wrong'
to ensure that a 'strdup(NULL)' path can not be taken.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-05-06 09:04:07 +02:00
Alan Dunn
f37c844bf7 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:44 +02:00
Hani Benhabiles
2c7dfb02a8 Small documentation fix.
Signed-off-by: Hani Benhabiles <hani@linux.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-05-06 08:52:55 +02:00
Andreas Schneider
2884bbf5b1 pki: Correctly update the ECDSA keytype. 2014-04-23 11:16:28 +02:00
Andreas Schneider
f48a99b97c pki: Move ssh_pki_key_ecdsa_name() to the correct file. 2014-04-23 11:15:05 +02:00
Andreas Schneider
11cfb2903e pki: Make pki_key_ecdsa_nid_to_name() a shared function. 2014-04-23 11:12:08 +02:00
Dirkjan Bussink
c520d97dd9 Add tests for SHA2 HMAC algorithms
BUG: https://red.libssh.org/issues/91

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-04-22 10:57:35 +02:00
Dirkjan Bussink
6c74d6f891 Add options support for setting and getting HMAC algorithms
BUG: https://red.libssh.org/issues/91

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-04-22 10:57:18 +02:00
Dirkjan Bussink
262c82ac06 Add negotiation for SHA2 HMAC algorithms
BUG: https://red.libssh.org/issues/91

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-04-22 10:57:00 +02:00
Dirkjan Bussink
164b8e99cc Add logic to support SHA2 HMAC algorithms
BUG: https://red.libssh.org/issues/91

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-04-22 10:56:46 +02:00
Dirkjan Bussink
4a08902664 Add SHA2 algorithms for HMAC
BUG: https://red.libssh.org/issues/91

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-04-22 10:55:59 +02:00
Gangadhar Sandrani
d6e6a453fc log: Fix log levels.
Signed-off-by: Gangadhar Sandrani <gangadhar.sandrani@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-04-22 09:35:33 +02:00
Jon Simons
eb86fd8cdf kex: server fix for first_kex_packet_follows
Ensure to honor the 'first_kex_packet_follow' field when processing
KEXINIT messages in the 'ssh_packet_kexinit' callback.  Until now
libssh would assume that this field is always unset (zero).  But
some clients may set this (dropbear at or beyond version 2013.57),
and it needs to be included when computing the session ID.

Also include logic for handling wrongly-guessed key exchange algorithms.
Save whether a client's guess is wrong in a new field in the session
struct: when set, the next KEX_DHINIT message to be processed will be
ignored per RFC 4253, 7.1.

While here, update both 'ssh_packet_kexinit' and 'make_sessionid' to
use softabs with a 4 space indent level throughout, and also convert
various error-checking to store intermediate values into an explicit
'rc'.

Patch adjusted from original to ensure that client tests remain passing
(ie 'torture_connect'): restrict the changes in 'ssh_packet_kexinit'
only for the 'server_kex' case.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-04-22 09:26:59 +02:00
Alan Dunn
099e2e8438 build: Do not link against libssl, only libcrypto
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-04-22 09:24:54 +02:00
Andreas Schneider
291312c5e4 cmake: Install cmake config files to the correct directory. 2014-04-16 15:45:33 +02:00
Andreas Schneider
e2805abbf7 Revert "kex: server fix for first_kex_packet_follows"
The patch breaks the client with ECDSA.

This reverts commit 5865b9436f.
2014-04-15 09:49:25 +02:00
Andreas Schneider
79d51099ac examples: Fix a bad shift if ssh_get_fd() returns -1.
Found by Coverity.

CID: #1199454
2014-04-14 21:24:28 +02:00
Andreas Schneider
adf23533e0 doc: Improve docs for ssh_channel_get_exit_status().
BUG: https://red.libssh.org/issues/154
2014-04-10 08:54:11 +02:00
Andreas Schneider
927cd90dc1 channels: Fix exit-signal request.
BUG: https://red.libssh.org/issues/153
2014-04-10 08:54:11 +02:00
Andreas Schneider
b5efbe75cd session: Fix a memory leak with custom banner.
BUG: https://red.libssh.org/issues/152
2014-04-10 08:54:10 +02:00
Andreas Schneider
01311dd419 cmake: Fix doxygen. 2014-04-10 08:54:10 +02:00
Jon Simons
5865b9436f kex: server fix for first_kex_packet_follows
Ensure to honor the 'first_kex_packet_follow' field when processing
KEXINIT messages in the 'ssh_packet_kexinit' callback.  Until now
libssh would assume that this field is always unset (zero).  But
some clients may set this (dropbear at or beyond version 2013.57),
and it needs to be included when computing the session ID.

Also include logic for handling wrongly-guessed key exchange algorithms.
Save whether a client's guess is wrong in a new field in the session
struct: when set, the next KEX_DHINIT message to be processed will be
ignored per RFC 4253, 7.1.

While here, update both 'ssh_packet_kexinit' and 'make_sessionid' to
use softabs with a 4 space indent level throughout, and also convert
various error-checking to store intermediate values into an explicit
'rc'.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-04-10 08:54:10 +02:00
Andreas Schneider
ad1313c2e5 Revert "direct-tcpip and forwarded-tcpip callbacks"
This reverts commit efe785e711.

We need a Signed-off version. I didn't have the Certificate of Origin
yet.
2014-04-09 12:49:06 +02:00
Andreas Schneider
0cb9f792b8 cmake: Update doxygen module. 2014-04-09 11:21:29 +02:00
Loïc Michaux
efe785e711 direct-tcpip and forwarded-tcpip callbacks 2014-04-09 11:13:57 +02:00
Jon Simons
48aca98cd5 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-04-09 11:01:11 +02:00
Petar Koretic
89e154f78c libsshpp: include required <string> header for std::string
Signed-off-by: Petar Koretic <petar.koretic@sartura.hr>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-04-09 10:59:59 +02:00
Alan Dunn
491b407d17 examples: Update ssh_server_fork for new SSH_BIND_OPTIONS_HOSTKEY
Tested by

ssh_server_fork -k <an ecdsa key> -k <an rsa key> ...

and connection succeeded with OpenSSH clients both for ECDSA and RSA
(the latter forced via -o HostKeyAlgorithms=ssh-rsa and some known
hosts clearing was necessary).  Also

ssh_server_fork -k <an ecdsa key> -k <another ecdsa key> ...

caused the second key to be used, as expected.

Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-04-09 10:59:21 +02:00
Alan Dunn
2f4589b765 doc: Document new meaning of SSH_BIND_OPTIONS_HOSTKEY
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-04-09 10:59:10 +02:00
Alan Dunn
acb7161c81 options: Repurpose SSH_BIND_OPTIONS_HOSTKEY to load host keys
SSH_BIND_OPTIONS_HOSTKEY will now load host keys of any supported type
rather than set the algorithms that the server permits (which seems
like an unhelpful option anyway; it seems you can always control this
by just loading the right keys).

This option has slightly different semantics than the
SSH_BIND_OPTIONS_<x>KEY options because it requires the key file to
exist immediately rather than on ssh_bind_listen or
ssh_bind_accept_fd.  The semantics of this option makes more sense to
me.

We also eliminate ssh_bind_options_set_algo, since it is no longer
used.

Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-04-09 10:57:16 +02:00
Andreas Schneider
437a39c798 cmake: Enable creation of the compile command database by default. 2014-04-04 10:03:43 +02:00
Andreas Schneider
b3e6d5df53 packet: Fix function name. 2014-03-27 11:26:27 +01:00
Luka Perkov
53644a14ac style: be consistent when iterating over wanted_methods
Signed-off-by: Luka Perkov <luka.perkov@sartura.hr>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-27 11:23:34 +01:00
Jon Simons
aa05248ca8 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>
2014-03-27 11:19:50 +01:00
Andreas Schneider
04543c9dbc doc: Fix ssh_userauth_none() function signature.
Thanks to David Tibbe!

BUG: https://red.libssh.org/issues/151
2014-03-27 11:06:01 +01:00
Alan Dunn
d5aeebe323 socket: Fix style of ssh_socket_pollcallback
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-27 10:54:55 +01:00
Alan Dunn
47bd0b6d1f doc: Improve and consolidate ssh_bind_options_set docs
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-27 10:49:08 +01:00
Petar Koretic
8e2590b535 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>
2014-03-27 10:48:13 +01:00
Petar Koretic
c51f42a566 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>
2014-03-27 10:46:21 +01:00
Petar Koretic
00d4fbe753 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>
2014-03-27 10:45:54 +01:00
Jon Simons
dee8e5688b channel: check for closed state in waitwindow loops
Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-27 10:34:22 +01:00
Jon Simons
40d81bb7ca kex: enable more ECDSA hostkey algos
Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-27 10:28:06 +01:00
Jon Simons
10bc5ac203 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>
2014-03-27 10:27:23 +01:00
Luka Perkov
8ba9402282 session: fix comment typo
Signed-off-by: Luka Perkov <luka.perkov@sartura.hr>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-27 10:16:24 +01:00
Luka Perkov
a2fe341da5 messages: use predefined macro for clearing sensitive data
Signed-off-by: Luka Perkov <luka.perkov@sartura.hr>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-27 10:16:14 +01:00
Luka Perkov
dbb2de272b 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>
2014-03-27 10:15:54 +01:00
Luka Perkov
9423a3a065 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>
2014-03-27 10:14:35 +01:00
Luka Perkov
0c5d4954a7 tests: torture_connect: fix coding style
Signed-off-by: Luka Perkov <luka.perkov@sartura.hr>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-27 10:13:57 +01:00
Petar Koretic
0b8d24f800 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>
2014-03-27 10:11:24 +01:00
Luka Perkov
48354f56ec 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>
2014-03-27 10:10:48 +01:00
Alan Dunn
5c0c95bd34 examples: Add ECDSA key option to ssh_server_fork
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-27 10:06:36 +01:00
Alan Dunn
c82dd2eb81 examples: Add no default keys options to ssh_server_fork
It seems useful to be able to run ssh_server_fork without being
required to load some key of RSA and DSA keytypes.  However, with the
current ssh_server_fork, you need to have some keys as some default
value is set by default and you can't unset the value for a keytype
(e.g. by using NULL as an argument).  So the "no default keys"
argument turns off the default key assignments.

Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-27 10:06:11 +01:00
Alan Dunn
f6276fe739 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>
2014-03-27 10:05:58 +01:00
Alan Dunn
2a1089d607 options: Allow use of host ECDSA key
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-27 10:05:23 +01:00
Andreas Schneider
fbf73ede1e tests: Check the the ecdsa_nid is the same. 2014-03-27 10:01:12 +01:00
Alan Dunn
577840d7f7 tests: Add test case for bug #147
Signed-off-by: Alan Dunn <amdunn@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-27 10:01:01 +01:00
Alan Dunn
3d9b1693eb 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:14:03 +01:00
Alan Dunn
15f3988bc8 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:13:29 +01:00
Luka Perkov
9c2127b798 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:12:18 +01:00
Jon Simons
0bb779904d packet: log disconnect code in host byte order
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-03-12 14:11:09 +01:00
Jon Simons
5eeac3566e 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:09:35 +01:00
Aris Adamantiadis
e99246246b 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:28 +01:00
Andreas Schneider
c96e862c08 examples: Add missing include for stderr.
This should fix the build on FreeBSD.
2014-02-17 09:20:46 +01:00
Andreas Schneider
7021a46617 cmake: Merge server examples. 2014-02-16 17:59:46 +01:00
Andreas Schneider
c7cb2d0657 examples: Remove old samplesshd-tty. 2014-02-16 17:58:55 +01:00
Andreas Schneider
fd50a4dd9f examples: Remove old samplesshd. 2014-02-16 17:57:09 +01:00
Audrius Butkevicius
afe97d6cab examples: Add ssh_server_fork example
Signed-off-by: Audrius Butkevicius <audrius.butkevicius@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-16 17:52:50 +01:00
Audrius Butkevicius
00949383f4 config: Add missing HAVE_LIBUTIL_H define in config.h
Signed-off-by: Audrius Butkevicius <audrius.butkevicius@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-16 17:45:47 +01:00
Andreas Schneider
2a1cb323f7 examples: Add missing include on FreeBSD. 2014-02-14 10:33:07 +01:00
Andreas Schneider
4463d89a4a cmake: Check for libutil.h on FreeBSD. 2014-02-14 10:33:07 +01:00
Andreas Schneider
9e0fb9f29b pki: Fix build warning about unused variables. 2014-02-14 10:33:07 +01:00
Audrius Butkevicius
a277dd9277 Add session/channel byte/packet counters
Signed-off-by: Audrius Butkevicius <audrius.butkevicius@elastichosts.com>
2014-02-12 18:21:16 +01:00
Andreas Schneider
370d4b014d pki: Fix the build on OpenSolaris. 2014-02-12 09:39:49 +01:00
Andreas Schneider
7bd5e4101c pki: Fix memory leak with ecdsa signatures. 2014-02-11 10:32:50 +01:00
Andreas Schneider
352c7381a8 cpack: Ignore obj directory. 2014-02-10 10:16:38 +01:00
Andreas Schneider
3e57b54688 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:30:29 +01:00
Alan Dunn
2a183440c7 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:41:01 +01:00
Alan Dunn
bb0023b7c7 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:41:00 +01:00
Raphael Kubo da Costa
398e8d50b5 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:12:50 +01:00
Jon Simons
fa34d11749 session: skip timestamp init for non-blocking case
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-06 10:21:57 +01:00
Jon Simons
93370d61ba session: add getters for session cipher names
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-06 10:21:07 +01:00
Aris Adamantiadis
22d6c36800 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:29:22 +01:00
Aris Adamantiadis
c28ad814d0 knownhosts: resolve leaks found by coverity 2014-02-05 08:07:45 +01:00
Aris Adamantiadis
fdc660f313 knownhosts: detect variations of ecdsa 2014-02-04 22:28:30 +01:00
Audrius Butkevicius
57418dd2cc server: use custom server banners
Value of session->serverbanner never gets used

Signed-off-by: Audrius Butkevicius <audrius.butkevicius@gmail.com>
2014-02-04 15:54:20 +01:00
Raphael Kubo da Costa
4e04ec8bf5 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:38:39 +01:00
Raphael Kubo da Costa
79a80cdc77 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:36:56 +01:00
Jon Simons
95782ada1f 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:19:46 +01:00
Jon Simons
f7b61bf557 doc: correct ssh_channel_read_timeout units
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-02 22:19:46 +01:00
Audrius Butkevicius
adf4d4f147 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:19:46 +01:00
Audrius Butkevicius
dc93edc932 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:19:46 +01:00
Joseph Southwell
6bbdaceaca src: Define MAX_BUF_SIZE globally and use it.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-02 22:19:46 +01:00
Joseph Southwell
eedecd0269 client: Fix EOF session error reporting.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-02 22:19:46 +01:00
Oleksandr Shneyder
d904784489 Make function ssh_channel_accept() nonblocking if timeout is 0.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-02-02 22:19:45 +01:00
Aris Adamantiadis
31fb4e1e69 build: remove OSX deprecated warnings for openssl 2014-02-02 21:41:32 +01:00
Aris Adamantiadis
3bdc2b1d4f build: fix cmake bug introduced yesterday
Compilation failed on OSX because of the missing OR OSX
2014-02-02 20:56:21 +01:00
Aris Adamantiadis
1e37430dbe Kex: fix coverity warning + edge case 2014-02-02 20:50:36 +01:00
Aris Adamantiadis
671f1979a6 server: allow custom server banners (bug #83) 2014-02-01 18:00:01 +01:00
Aris Adamantiadis
fdaa42da1a Knownhosts: implement hostkey with knownhosts heuristic 2014-02-01 17:34:16 +01:00
Aris Adamantiadis
8d450ef81a knownhosts: add test case for bug #138 2014-02-01 16:48:36 +01:00
Aris Adamantiadis
c433ac02bd 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
2014-02-01 16:42:29 +01:00
Aris Adamantiadis
1c24a0508f Added known host test cases 2014-02-01 15:33:15 +01:00
Aris Adamantiadis
f0d6ce8958 tests: fix compilation on OSX (libargp detection) 2014-02-01 14:49:57 +01:00
Andreas Schneider
75be42df75 pki_crypto: Fix memory leak with EC_KEY_set_public_key().
BUG: https://red.libssh.org/issues/146
2014-01-28 11:56:59 +01:00
Andreas Schneider
3224506fe0 doc: Document the unit for ssh_select() timeout.
BUG: https://red.libssh.org/issues/143
2014-01-23 11:29:39 +01:00
Rod Vagg
d4d30d0375 dh: Fix NULL check for p_group14.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2014-01-23 11:21:51 +01:00
Jon Simons
7ff6b3537f 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:13 +01:00
Andreas Schneider
368509f5d1 pki: Use ssh_buffer_add_data() in pki_gcrypt.. 2014-01-22 16:12:31 +01:00
Alan Dunn
7eff889384 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:45:45 +01:00
Jon Simons
465816f4a0 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:11:12 +01:00
Alan Dunn
9fff70fa41 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:07:09 +01:00
Alan Dunn
d3e081ba44 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:07:04 +01:00
Alan Dunn
086847f997 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:06:53 +01:00
Andreas Schneider
cb9786b3ae src: Rename buffer_add_data() to ssh_buffer_add_data(). 2014-01-19 20:55:55 +01:00
Andreas Schneider
9c4144689d src: Rename buffer_init to ssh_buffer_init(). 2014-01-19 20:43:29 +01:00
Andreas Schneider
e745236ae5 doc: Fix channel documentation. 2014-01-17 11:08:49 +01:00
Andreas Schneider
13eef19000 pki: Do not use deprecated string functions. 2014-01-17 09:29:24 +01:00
Andreas Schneider
2fe59071b2 src: Do not use deprecated functions. 2014-01-16 15:27:46 +01:00
Andreas Schneider
a7157b7907 include: Mark functions as deprecated! 2014-01-16 15:27:23 +01:00
Jon Simons
6007c3c43f 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:41 +01:00
Andreas Schneider
9d1ddd0547 doc: Add changes to the forwarding tutorial. 2014-01-16 09:13:06 +01:00
Andreas Schneider
5229253f86 channel: Fix the name scheme of the forward functions. 2014-01-16 09:13:06 +01:00
Oleksandr Shneyder
a1c4fc07d4 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:12:03 +01:00
Andreas Schneider
6d09104ad3 Rename build directory to obj.
Some buildsystem use build in the pathname and so we will filter out
e.g. docs generation.
2014-01-16 08:53:32 +01:00
Aris Adamantiadis
57ef959aa3 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 18:57:31 +01:00
Andreas Schneider
b617d7fa29 include: Remove warning cause VSC doesn't know about it. 2014-01-08 10:55:20 +01:00
Andreas Schneider
4b3363ecf2 include: Fix building if we do not have asm volatile. 2014-01-08 10:52:29 +01:00
Andreas Schneider
6fe51b13fb src: Update my mail address. 2014-01-07 16:08:23 +01:00
Andreas Schneider
8bcbfb1642 cmake: Remove unused macro modules. 2014-01-07 16:07:00 +01:00
Aris Adamantiadis
aecd952d18 update copyright information 2014-01-07 15:18:15 +01:00
Aris Adamantiadis
fedb1b3def tests: avoid reading uninitialized bytes 2014-01-07 14:43:46 +01:00
Aris Adamantiadis
8fdfa13227 pki: fix gcrypt signature process 2014-01-07 14:20:49 +01:00
Andreas Schneider
9d90d15e91 examples: Make sure buffer is initialized. 2014-01-07 09:19:02 +01:00
Andreas Schneider
09a715b147 example: Add missing include for forkpty(). 2014-01-07 09:03:53 +01:00
Aris Adamantiadis
42ad55377f test: fixed torture_auth_none condition 2014-01-06 22:09:43 +01:00
Aris Adamantiadis
d771dafe04 test: test case for async auth_none
This test currently fails
2014-01-06 16:52:44 +01:00
Aris Adamantiadis
09af855b6f tests: auth_agent_nonblocking should run in nonblocking 2014-01-06 16:52:44 +01:00
Aris Adamantiadis
0571360f37 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:16 +01:00
Andreas Schneider
f3e3700063 session: Fix a possible memory leak. 2014-01-05 23:05:13 +01:00
Aris Adamantiadis
41fe03e0d6 poll: fix poll_handles ownerships 2014-01-05 22:33:45 +01:00
Aris Adamantiadis
b514957af7 socket: don't attempt reading a non-connected socket 2014-01-05 21:54:08 +01:00
Andreas Schneider
d9c5d0767c examples: Fix building samplesshd-tty on FreeBSD. 2013-12-26 09:42:32 +01:00
Andreas Schneider
8f162e3b13 poll: Correctly free ssh_event_fd_wrapper.
This is allocated by ssh_event_add_fd.
2013-12-22 22:08:45 +01:00
Andreas Schneider
32ba84dac7 config: Support expansion in the Host variable too.
BUG: https://red.libssh.org/issues/127
2013-12-21 12:30:32 +01:00
Andreas Schneider
7f806b7c68 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:03:00 +01:00
Andreas Schneider
a6107f7432 tests: Fix blocking mode in password auth test. 2013-12-15 20:42:18 +01:00
Andreas Schneider
9829aa2236 tests: Use new auth API in the torture_session test. 2013-12-15 20:29:30 +01:00
Andreas Schneider
f8debe9a19 tests: Use new auth API in the torture_auth test. 2013-12-15 20:26:17 +01:00
Andreas Schneider
8b407f1ca2 tests: Fix pki test with gcrypt. 2013-12-11 21:11:49 +01:00
Jon Simons
20b5734649 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:02:47 +01:00
Jon Simons
0557f57c63 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:02:05 +01:00
Andreas Schneider
4f4e917187 bind: Correctly free all memory in ssh_bind_free().
Thanks to Jacob Baines.
2013-12-09 19:49:54 +01:00
Jon Simons
a1f0b2acfc session: Add ssh_get_clientbanner(). 2013-12-07 16:24:33 +01:00
Andreas Schneider
d65777b570 channels: Add a ssh_channel_read_timeout function. 2013-12-04 20:34:13 +01:00
Andreas Schneider
2df00fd84c tests: Try to fix torture_forward. 2013-12-04 14:21:52 +01:00
Andreas Schneider
d1d3beac33 tests: Fix memory leaks. 2013-11-28 14:40:11 +01:00
Andreas Schneider
ad0abff8b3 tests: Add missing line breaks. 2013-11-28 11:49:11 +01:00
Andreas Schneider
cdd7a6cb8d pki: Fix a memory leak.
CID #1132819
2013-11-28 09:09:45 +01:00
Andreas Schneider
004240af48 tests: Add torture_pki_write_privkey_ecdsa test. 2013-11-27 22:54:13 +01:00
Andreas Schneider
4e3d16e291 tests: Add torture_pki_write_privkey_dsa test. 2013-11-27 22:54:13 +01:00
Andreas Schneider
7933aef747 tests: Add torture_pki_write_privkey_rsa test. 2013-11-27 22:54:13 +01:00
Andreas Schneider
136efd6ed5 pki: Add ssh_pki_import_privkey_file(). 2013-11-27 22:54:13 +01:00
Andreas Schneider
94969cf263 pki_crypto: Add pki_private_key_to_pem(). 2013-11-27 22:54:13 +01:00
Andreas Schneider
68c3c26029 pki_gcrypt: Add pki_private_key_to_pem() stub. 2013-11-27 22:54:13 +01:00
Andreas Schneider
fd185acbea curve25519: Fix memory leaks in ssh_server_curve25519_init().
CID #1125255
2013-11-27 20:26:14 +01:00
Andreas Schneider
7a4e8e58f0 curve25519: Do not leak q_s_string.
CID #1125256
2013-11-27 20:20:07 +01:00
Andreas Schneider
cbeb2a9de7 curve25519: Fix a memory leak.
CID #1125257
2013-11-27 20:18:25 +01:00
Andreas Schneider
d61fcbf7b2 examples: Fix else branch.
CID #1127816
2013-11-27 20:16:09 +01:00
Andreas Schneider
75e61f498b packet: Remove logically dead code.
CID #1128796
2013-11-27 20:14:02 +01:00
Andreas Schneider
09edee123a tests: Try to fix valgrind warnings. 2013-11-27 18:04:44 +01:00
Andreas Schneider
060171028c tests: Fix a valgrind warning. 2013-11-27 17:55:48 +01:00
Andreas Schneider
7ecdc3e0d5 ecdh: Check if we have ECC support. 2013-11-27 17:38:21 +01:00
Andreas Schneider
67a080874b ecdh: Use bignum_bin2bn. 2013-11-27 17:35:36 +01:00
Nicolas Viennot
7b63fe2f22 server: Add a ssh_send_keepalive() function.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-24 23:21:04 +01:00
Jon Simons
3d934f3ddc 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:23 +01:00
Rod Vagg
06cc94eecf flush channel after EOF and CLOSE 2013-11-18 17:22:30 +01:00
Aris Adamantiadis
f6443b725a logging: fix server-side logging 2013-11-18 15:29:27 +01:00
Aris Adamantiadis
d8ead516de gssapi: fix logging 2013-11-18 15:11:26 +01:00
Aris Adamantiadis
ccdc0f1805 sockets: null pointer check 2013-11-18 14:42:40 +01:00
Simo Sorce
66e7e7023b 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-15 23:32:20 -05:00
Simo Sorce
b4fc5d9524 gssapi: Add support for GSSAPIDelegateCredentials config option.
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-15 16:53:59 -05:00
Simo Sorce
811c645f2a 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-15 16:10:29 -05:00
Andreas Schneider
c2312f9dda gssapi: Add error checks and cleanup the code in ssh_gssapi_auth_mic(). 2013-11-15 16:28:49 +01:00
Simo Sorce
440d2ec0ea 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:19:28 +01:00
Andreas Schneider
47e53deebd gssapi: Add support for GSSAPIClientIdentity config option. 2013-11-15 15:50:09 +01:00
Andreas Schneider
095a01b70c options: Add SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY option. 2013-11-15 15:50:09 +01:00
Andreas Schneider
503c729bb0 gssapi: Add support for GSSAPIServerIdentity config option. 2013-11-15 15:50:09 +01:00
Andreas Schneider
41d99d32e8 gssapi: Add suppport to set GSSAPI server identity. 2013-11-15 15:50:09 +01:00
Simo Sorce
c481f9dafd 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 14:49:29 +01:00
Andreas Schneider
f240ecf328 socket: Fix connect if we pass in a fd.
BUG: https://red.libssh.org/issues/106

Thanks to Saju Panikulam.
2013-11-15 08:47:58 +01:00
Andreas Schneider
1972a27fe0 packet: Remove dead code. 2013-11-14 11:43:49 +01:00
Andreas Schneider
097760db17 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:42:21 +01:00
Andreas Schneider
b3a08ba8d3 dh: Fix wrong assignment.
Ups, sorry.
2013-11-14 08:08:49 +01:00
Andreas Schneider
fef7e1dffe poll: Fix realloc in ssh_poll_ctx_resize(). 2013-11-09 13:27:59 +01:00
Andreas Schneider
6d7bbe63fe dh: Avoid possible memory leaks with realloc. 2013-11-09 13:20:13 +01:00
Andreas Schneider
387e26c837 packet: Refactor ssh_packet_socket_callback().
Make error checking more readable and add additional NULL checks.
2013-11-09 13:10:41 +01:00
Andreas Schneider
e8e99ec6de server: Fix malloc call. 2013-11-09 12:47:02 +01:00
Colin Walters
13c4499449 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:07 +01:00
Colin Walters
4cc7f4ad03 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:26:19 +01:00
Colin Walters
a8dc67ded8 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:25:41 +01:00
Andreas Schneider
aa33d18930 example: Use ssh_get_publickey_hash(). 2013-11-06 17:10:41 +01:00
Andreas Schneider
8c5777554a 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:10:41 +01:00
Andreas Schneider
06cd9bc4dc dh: Add new ssh_get_publickey_hash() function. 2013-11-06 17:10:35 +01:00
Andreas Schneider
0c8984ba9f doc: Add curve25519 to features list. 2013-11-05 13:15:11 +01:00
Andreas Schneider
6f0f1ef292 doc: Fix doxygen warnings. 2013-11-04 21:55:29 +01:00
Aris Adamantiadis
b12f3f38c7 Fix cast warnings on 64bits 2013-11-04 10:49:32 +01:00
Aris Adamantiadis
cb165df64e remove warnings on OSX (workaround) 2013-11-04 10:47:22 +01:00
Aris Adamantiadis
e4c4f57f05 logging: fix wording 2013-11-04 10:31:10 +01:00
Aris Adamantiadis
c5ef5ed18f curve25519: include reference implementation 2013-11-03 14:58:10 +01:00
Aris Adamantiadis
ebf4a03908 examples: fix forktty() warning on OSX 2013-11-03 14:10:04 +01:00
Aris Adamantiadis
4f3ee2fc7e Fix examples compilation on OSX (libargp) 2013-11-03 13:49:27 +01:00
Aris Adamantiadis
f565aeebfa Compile libssh with nacl if possible
Conflicts:
	DefineOptions.cmake
2013-11-03 13:18:26 +01:00
Aris Adamantiadis
04cb94a2dd socket: Fix check for pending data.
BUG: https://red.libssh.org/issues/119

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-03 12:46:27 +01:00
Nicolas Viennot
754152aa22 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:52:38 +01:00
Nicolas Viennot
1ef00045dd 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:48:59 +01:00
Andreas Schneider
a466a624e2 session: Make sure we correctly burn the buffer. 2013-11-03 10:45:02 +01:00
Andreas Schneider
643a3b7cc3 wrapper: Make sure we really burn the buffer. 2013-11-03 10:39:31 +01:00
Andreas Schneider
d2dea8dc2e priv: Fix brackets of burn macros. 2013-11-03 10:24:47 +01:00
Andreas Schneider
6edb6bcca1 doc: Add missing RFCs. 2013-11-03 09:35:35 +01:00
Jon Simons
d4f5a0e6ab 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:02:56 +01:00
William Orr
ce1d73e0f0 ssh_options_get can now return ProxyCommand
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-11-02 21:02:56 +01:00
Jon Simons
20caa68b84 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:45:21 +01:00
Andreas Schneider
b00a6e3885 tests: Add a test for ssh_channel(). 2013-10-31 12:44:48 +01:00
Jon Simons
ffc33ca28c 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:09 +01:00
Alan Dunn
ee95c05c08 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:18:55 +01:00
Andreas Schneider
cfea381307 cmake: Check for isblank(). 2013-10-30 17:30:07 +01:00
Jon Simons
099b914fd9 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:37 +02:00
Andreas Schneider
afd35fa98c tests: Add a sftp_read blocking test. 2013-10-23 15:49:07 +02:00
Colin Walters
f02bc4768e 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:09 +02:00
Andreas Schneider
bcb162816e doc: Improve sftp_read_sync() example. 2013-10-23 09:53:16 +02:00
Andreas Schneider
5baa6aed6b include: Fix build on platforms without ECC. 2013-10-21 07:15:59 +02:00
Andreas Schneider
6a6e85752e tests: Add a test for ssh_channel_request_env(). 2013-10-20 17:05:35 +02:00
Andreas Schneider
4421540b7b tests: We can't test the accept right now. 2013-10-20 13:28:53 +02:00
Andreas Schneider
d3c186b04c tests: Fix torture_forward. 2013-10-20 13:23:31 +02:00
Andreas Schneider
e30acdb58a channel: Reinit the buffer and reset the state on error.
BUG: https://red.libssh.org/issues/126
2013-10-20 12:46:57 +02:00
Andreas Schneider
b0cbe88b0b channel: Fix ssh_global_request_termination().
BUG: https://red.libssh.org/issues/126
2013-10-20 12:46:17 +02:00
Andreas Schneider
3afba83134 tests: Add torture forward test. 2013-10-20 12:46:17 +02:00
Andreas Schneider
b8d47a438c pki: Don't leak a buffer. 2013-10-19 10:41:57 +02:00
Andreas Schneider
5201c5850e wrapper: Fix compilation with gcrypt. 2013-10-19 10:39:00 +02:00
Andreas Schneider
bd8ab422d0 pki_crpypto: Fix ecdsa signature to blob.
BUG: https://red.libssh.org/issues/118
2013-10-18 23:48:21 +02:00
Andreas Schneider
33890daf41 pki: Add support for ECDSA private key signing. 2013-10-18 23:22:24 +02:00
Andreas Schneider
ac4c5699b1 pki: Add the type as a char pointer. 2013-10-18 23:22:24 +02:00
Andreas Schneider
15e31eb464 wrapper: Add more evp functions. 2013-10-18 23:22:24 +02:00
Andreas Schneider
2e81dd61dd client: Fix the build. 2013-10-18 21:18:36 +02:00
Oliver Stöneberg
f2c2687ca6 scp: Fixed result of ssh_scp_string_mode() to get SCP working.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-10-18 14:58:47 +02:00
Oliver Stöneberg
4c300313c3 client: Added a missing NULL pointer check.
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2013-10-18 14:57:33 +02:00
Andreas Schneider
bec13a6ac0 doc: Make sure we have the defines to build all docs. 2013-10-14 15:39:33 +02:00
Andreas Schneider
423d8c9b6a channel: Fix packets termination timeout in global_request().
BUG: https://red.libssh.org/issues/126
2013-10-01 14:50:56 +02:00
Andreas Schneider
685fe1d0b6 session: Try the ecdsa default key first. 2013-10-01 14:45:01 +02:00
Tristan CACQUERAY
e588e2325d callbacks: add support for auth_none_function 2013-09-27 15:34:45 +02:00
Aris Adamantiadis
04fd756c49 doc: Documentation of curve25519-sha256@libssh.org 2013-09-27 15:32:52 +02:00
Aris Adamantiadis
4cb6afcbd4 kex: implement curve25519-sha256@libssh.org 2013-09-27 15:32:44 +02:00
Andreas Schneider
4eae4d592c channels: Correctly handle timeouts in channel functions. 2013-09-17 11:23:56 +02:00
Andreas Schneider
566d842405 channel: Use the correct timeout option in channel_open().
BUG: https://red.libssh.org/issues/124
2013-09-17 11:19:49 +02:00
Andreas Schneider
5e2fbbc202 callbacks: Improve the documentation of ssh_threads_set_callbacks().
BUG: https://red.libssh.org/issues/123
2013-09-16 10:54:30 +02:00
Andreas Schneider
8e703b9974 callbacks: Improve the documentation of ssh_threads_get_noop().
BUG: https://red.libssh.org/issues/123
2013-09-16 10:50:25 +02:00
Andreas Schneider
89853607c5 session: Document return value of ssh_get_serverbanner().
BUG: https://red.libssh.org/issues/122
2013-09-16 10:38:14 +02:00
Andreas Schneider
20658abc78 session: Remove obsolete status variables.
BUG: https://red.libssh.org/issues/121
2013-09-16 10:38:14 +02:00
Andreas Schneider
8823dee51a client: Add example code for ssh_get_openssh_version().
BUG: https://red.libssh.org/issues/120
2013-09-16 10:38:14 +02:00
Andreas Schneider
3e07359a35 channels: Correctly decrement timeout value in ssh_channel_accept().
BUG: https://red.libssh.org/issues/116
2013-09-16 10:38:14 +02:00
Andreas Schneider
e9242a7a31 channel: Document SSH_AGAIN in ssh_channel_read().
BUG: https://red.libssh.org/issues/115
2013-09-16 10:38:14 +02:00
Andreas Schneider
b9ada25296 cmake: Allow to build without examples.
BUG: https://red.libssh.org/issues/114
2013-09-16 10:38:14 +02:00
Andreas Schneider
33cb1bc08b doc: Improve the PKI documentation a bit. 2013-09-10 06:59:25 +02:00
Andreas Schneider
6da54688eb doc: Update documentation of ssh_set_blocking().
This should work correctly in libssh 0.6.0. If not then you hit a bug.
2013-09-09 16:43:46 +02:00
Andreas Schneider
ef6d19fbb1 clang_complete: Update definitons. 2013-08-13 12:09:59 +02:00
Andreas Schneider
acbca6a562 ecdh: Refactor ecdh_build_k to check errors codes. 2013-08-13 12:09:36 +02:00
Andreas Schneider
fc8081cd06 channel: Refactor channel_write_common() code.
This makes it easier to read and easier to debug.
2013-08-13 08:22:28 +02:00
Andreas Schneider
7a64dd1b9a channel: Make channel_write_common() static. 2013-08-13 08:17:15 +02:00
Andreas Schneider
5045133dc2 channel: Use MIN macro in channel_write_common(). 2013-08-13 08:15:37 +02:00
Andreas Schneider
7f2049b0d5 include: Add a MIN macro. 2013-08-13 08:15:16 +02:00
Andreas Schneider
aa3eeb38f9 scp: Document more scp functionts. 2013-08-12 11:24:38 +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
Andreas Schneider
5a8a2a56af poll: Use WSAPoll() on Windows. 2011-02-09 00:36:16 +01:00
Andreas Schneider
d464b57fa5 Revert "poll: Remove obsolete win_poll functions."
This reverts commit c950ed3b4c.
2011-02-09 00:34:36 +01:00
Andreas Schneider
c950ed3b4c poll: Remove obsolete win_poll functions.
Thanks for the hint Milo ;)
2011-02-09 00:13:47 +01:00
Andreas Schneider
5144f390ca examples: Fixed build warning. 2011-02-08 19:36:44 +01:00
Andreas Schneider
f5e2c94ae3 torture: Fixed memory leak. 2011-02-08 19:08:27 +01:00
Andreas Schneider
8078d4f674 doc: Use fwrite for the command example. 2011-02-08 10:59:50 +01:00
Andreas Schneider
ac785e0aa3 examples: The exec example should be like tutorial one. 2011-02-08 10:54:25 +01:00
Andreas Schneider
541519e563 build: Updated the ChangeLog. 2011-02-07 18:22:34 +01:00
Andreas Schneider
58feb0c983 vim: Added .clang_complete file. 2011-02-07 17:39:06 +01:00
Andreas Schneider
72e08d5dd9 build: Added a --clang option. 2011-02-07 13:34:37 +01:00
Andreas Schneider
f812ace256 tests: Some fixes for sftp_dir. 2011-02-07 13:33:28 +01:00
Andreas Schneider
057704c097 torture: Added more test for correct auth. 2011-02-07 13:31:31 +01:00
Andreas Schneider
92f20ec85a torture: Fixed the kbdint auth. 2011-02-07 13:31:08 +01:00
Andreas Schneider
a26194ece0 torture: Rename the static auth kbdint function. 2011-02-07 13:30:23 +01:00
Andreas Schneider
22b1e5bc7c tests: Added test for sftp directory functions. 2011-02-06 16:35:54 +01:00
Andreas Schneider
38d6d38c1f torture: Added a function to setup a sftp session. 2011-02-06 16:27:43 +01:00
Andreas Schneider
215c41710e torture: Added torture_isdir(). 2011-02-06 15:35:18 +01:00
Andreas Schneider
97d261dc79 torture: Added torture_rmdirs(). 2011-02-06 15:35:18 +01:00
Andreas Schneider
892ebf35f1 torture: Added GPL header. 2011-02-06 15:34:32 +01:00
Andreas Schneider
05cd7296ba tests: Added a torture_ssh_session(). 2011-02-06 11:15:05 +01:00
Andreas Schneider
93a2d79459 session: Added ssh_is_connected(). 2011-02-06 10:50:14 +01:00
Andreas Schneider
30e4096c66 tests: Fixed missing ; 2011-02-06 08:45:37 +01:00
Andreas Schneider
03b387cf47 Revert "sftp: Added missing break's to server."
This reverts commit 131e3b968f.
2011-02-05 18:40:00 +01:00
Andreas Schneider
131e3b968f sftp: Added missing break's to server. 2011-02-05 18:24:23 +01:00
Andreas Schneider
4bf8ee8032 tests: Check fgets output. 2011-02-05 15:23:19 +01:00
Andreas Schneider
63c42f066f tests: Fixed checking return values of system(). 2011-02-05 15:23:19 +01:00
Andreas Schneider
9e40e60bc4 examples: Check return values of write. 2011-02-05 15:23:19 +01:00
Andreas Schneider
8f850585dd session: Fixed possible uninitialized return of ret. 2011-02-05 15:23:19 +01:00
Andreas Schneider
4b07157fc6 getpass: Fixed a compiler warning. 2011-02-05 15:23:19 +01:00
milo
867944b939 Respect RFC when sending stderr data
http://tools.ietf.org/html/rfc4254#section-5.2

      byte      SSH_MSG_CHANNEL_EXTENDED_DATA
      uint32    recipient channel
     *uint32    data_type_code*
      string    data
2011-02-04 12:46:51 +01:00
Andreas Schneider
b0c2be25a6 doc: Fixed the include dir. 2011-01-28 13:13:08 +01:00
Aris Adamantiadis
c1ecec7cda SSH1: Update a few fix from 0.4.8-git 2011-01-26 22:50:05 +01:00
Aris Adamantiadis
00d68d63fa Getpass: fixed loop + indentation 2011-01-26 21:49:58 +01:00
Aris Adamantiadis
5d87ca94a8 Getpass: Fix password clearing 2011-01-26 13:22:29 +01:00
Andreas Schneider
1e827a8e81 getpass: Fixed possible segfault if len is too small. 2011-01-24 17:13:35 +01:00
Andreas Schneider
20e637968a cmake: Define BSD. 2011-01-24 15:44:11 +01:00
Andreas Schneider
5c581f8a4c libsshpp: Removed unused variable. 2011-01-24 15:25:50 +01:00
Andreas Schneider
d67cbdc926 examples: Fixed compilation on Windows. 2011-01-24 15:25:50 +01:00
Andreas Schneider
a63dbc07f3 examples: Fixed knownhosts on Windows. 2011-01-24 13:55:05 +01:00
Andreas Schneider
6a3cd6c20f examples: enable exec and senddata on all plattforms. 2011-01-24 13:55:05 +01:00
Andreas Schneider
8a9ce6239a examples: Remove unused header file. 2011-01-24 13:55:05 +01:00
Andreas Schneider
f3685f0f73 examples: Use ssh_getpass(). 2011-01-24 13:55:05 +01:00
Andreas Schneider
50a119dd0a misc: Added multiplatform ssh_getpass() fuction. 2011-01-24 13:55:05 +01:00
Andreas Schneider
8abdaa7abf examples: Start to build examples on more plattforms. 2011-01-23 18:57:35 +01:00
Aris Adamantiadis
80ef7d9304 Fix problem with ssh_connect w/ timeout &fd > 1024
Convert that code to ssh_poll
(cherry picked from commit b1a65dd25f)
2011-01-22 16:55:36 +01:00
Aris Adamantiadis
84df46f805 Fix use-after-free when socket is closed in a callback handler 2011-01-19 16:01:21 +01:00
Andreas Schneider
460d43f050 cmake: Fixed ZLIB configure check. 2011-01-18 18:56:24 +01:00
Andreas Schneider
625692f4c5 cmake: Don't use cmake 2.8.3 features. 2011-01-17 09:24:57 +01:00
Aris Adamantiadis
0e2bbdd25b Fix doxygen warning 2011-01-16 23:42:19 +01:00
Aris Adamantiadis
6b52aaff1c ssh_auth_password made nonblocking 2011-01-16 23:42:19 +01:00
Aris Adamantiadis
227764a803 Made ssh_userauth_none nonblocking 2011-01-16 23:42:19 +01:00
Aris Adamantiadis
624676b1cc Made ask_userauth nonblocking 2011-01-16 23:42:19 +01:00
Andreas Schneider
a236a15c6c modules: Improved the GCrypt module. 2011-01-16 12:47:06 +01:00
Andreas Schneider
cb775092bc cmake: Fixed NSIS module. 2011-01-16 12:21:58 +01:00
Andreas Schneider
8d7d313498 cmake: Fixed ZLIB path checks. 2011-01-16 12:16:53 +01:00
Andreas Schneider
c6e1792696 cmake: Improved the NSIS module. 2011-01-16 12:12:35 +01:00
Andreas Schneider
90fc5554e1 cmake: Improved the ZLIB find module based on CMake one. 2011-01-16 11:53:37 +01:00
Andreas Schneider
e579dfb342 cmake: Fixed license header of the OpenSSL module. 2011-01-16 11:51:02 +01:00
Andreas Schneider
0c93914948 cmake: Improved FindOpenSSL based on CMake ones. 2011-01-16 11:30:24 +01:00
Aris Adamantiadis
670dd17044 Test double ssh_disconnect 2011-01-15 22:50:34 +01:00
Aris Adamantiadis
b945cbca52 Fix double-connect testcase 2011-01-15 22:43:58 +01:00
Aris Adamantiadis
f8361d324e Fix torture_connect_double so it tests the right thing 2011-01-14 14:35:44 +01:00
Aris Adamantiadis
0b46f68c5f Fixed compilation without argp.h available 2011-01-13 21:21:19 +01:00
Aris Adamantiadis
2917e71aad Replaced argp support for platforms that support it
Argp is really useful, but it's not mandatory.
2011-01-13 18:34:04 +01:00
Aris Adamantiadis
551b87b65b New testcases for nonblocking ssh_connect and double ssh_connect 2011-01-13 18:09:04 +01:00
Aris Adamantiadis
5b6f048197 Use termination functions for event polling 2011-01-12 23:04:43 +01:00
Aris Adamantiadis
a17472ff2b Fix unit tests for opensolaris 2011-01-11 17:55:12 +01:00
Aris Adamantiadis
7fbb926c0b Fix getpwuid_r on opensolaris 2011-01-11 17:55:12 +01:00
Andreas Schneider
bb5f5281c0 build: Fixed build on Windows. 2011-01-11 11:07:17 +01:00
Aris Adamantiadis
9140242cbe Non-blocking mode for ssh_connect
This looks ugly. I'll see if we need to revert or change that patch later.
2011-01-10 18:01:35 +01:00
Aris Adamantiadis
bcea8921ba Change blocking parameter to a flag 2011-01-10 17:39:47 +01:00
Aris Adamantiadis
076dfb8294 Fix connection callbacks called at wrong time 2011-01-10 12:14:26 +01:00
Aris Adamantiadis
d631ce32ed All error path consistent with ssh_packet_kexinit 2011-01-10 11:24:15 +01:00
Aris Adamantiadis
4439d5c774 Log errors with ssh_log 2011-01-10 11:23:49 +01:00
Aris Adamantiadis
ac6278feb7 Fix leak when key exchange fails. 2011-01-09 22:27:55 +01:00
Andreas Schneider
d1e1103198 examples: Improve the authenticate_kbdint function.
The function excepts a predefined password now. It will try to use it if
the prompt is a Password prompt. This works in 80% of the cases.
2011-01-08 10:18:55 +01:00
Aris Adamantiadis
4f83918109 Added interesting link 2011-01-07 13:41:10 +01:00
Andreas Schneider
6b27966c9c keys: Fixed memory leaks in session signing.
Found by cppcheck - http://test.libssh.org/cppcheck-analyzer/
2011-01-06 14:32:39 +01:00
Andreas Schneider
a016d356fa dh: Fixed a memory leak in ssh_print_hexa.
Found by cppcheck - http://test.libssh.org/cppcheck-analyzer/
2011-01-06 14:25:35 +01:00
Andreas Schneider
61852635b5 tests: Moved assert to the write place in torture_keyfiles.
Found by clang-analyzer http://test.libssh.org/clang-analyzer/
2011-01-06 11:44:02 +01:00
Andreas Schneider
184f1e1706 tests: Assert if ssh_get_random failed in torture_rand_thread.
Found by clang-analyzer http://test.libssh.org/clang-analyzer/
2011-01-06 10:15:01 +01:00
Andreas Schneider
dfa01d0862 examples: Use the src mode in scp do_copy function.
Found by clang-analyzer http://test.libssh.org/clang-analyzer/
2011-01-06 10:15:01 +01:00
Andreas Schneider
82547867eb options: Remove unsused getopt option.
Found by clang-analyzer http://test.libssh.org/clang-analyzer/
2011-01-06 10:15:01 +01:00
Andreas Schneider
7d9f889911 tests: Added missing asserts in torture_keyfiles.
Found by clang-analyzer http://test.libssh.org/clang-analyzer/
2011-01-06 10:15:01 +01:00
Andreas Schneider
13ece2a2f8 messages: Added missing NULL pointer checks.
Found by clang-analyzer http://test.libssh.org/clang-analyzer/
2011-01-06 10:04:12 +01:00
Aris Adamantiadis
e57d5a45b9 Fix the missing returns in C++ wrapper 2011-01-05 21:14:27 +01:00
Andreas Schneider
ec12da273e tests: Fixed the segfault in torture_knownhosts. 2011-01-04 23:10:01 +01:00
Aris Adamantiadis
fdffa42c02 Fix "SSH_KEXINIT received in wrong state" race
Setting the flag before doing any IO
2011-01-04 16:59:54 +01:00
Andreas Schneider
d679d5d7ef poll: Ensure that the poll handle and ctx is zeroed. 2011-01-03 09:07:02 +01:00
Andreas Schneider
2464a25de7 tests: Fixed a build warning introduced before. 2011-01-03 09:02:34 +01:00
Andreas Schneider
e12253168c tests: Call init and finalize in client torture tests. 2011-01-03 08:46:14 +01:00
Andreas Schneider
1540dad17f tests: Added more openssl valgrind suppressions. 2011-01-03 07:51:46 +01:00
Andreas Schneider
350838d1b5 messages: Fixed cast warnings on Windows. 2011-01-02 19:35:54 +01:00
Andreas Schneider
f23880ddee base64: Added casts to GET macros to fix build warnings. 2011-01-02 19:35:54 +01:00
Andreas Schneider
be3e5c35cf scp: Fixed a build warning on Windows. 2011-01-02 19:35:54 +01:00
Andreas Schneider
73c0cd050e poll: Fixed a build warning on Windows. 2011-01-02 19:35:53 +01:00
Andreas Schneider
c54d6b7f8a bind: Added include file for close function on Windows. 2011-01-02 19:35:53 +01:00
Andreas Schneider
2b6fa19fe5 cmake: Fixed msvc posix warnings and unsecure functions. 2011-01-02 19:35:53 +01:00
Aris Adamantiadis
3f538b3ddd Call ssh_init()/ssh_finalize bf/af each testcase 2011-01-02 17:25:51 +01:00
Aris Adamantiadis
2faaefade9 Revert "tests: Call ssh_init() and ssh_finalize() before we run the tests."
Reason: breaks test_rand, because threading has to be initialized
before ssh_init()

This reverts commit ef1866db76.
2011-01-02 17:15:03 +01:00
Andreas Schneider
ef1866db76 tests: Call ssh_init() and ssh_finalize() before we run the tests. 2011-01-02 09:19:53 +01:00
Andreas Schneider
d4072082d0 tests: More openssl valgrind suppressions. 2011-01-02 09:10:42 +01:00
Andreas Schneider
a7237e8cea tests: Updated the valgrind suppressions file. 2011-01-01 22:13:03 +01:00
Andreas Schneider
bc2db562e5 cmake: Added missing OpenSSL directories on Windows. 2011-01-01 20:53:55 +01:00
Andreas Schneider
93ce8e8ffd cmake: Added looking for zdll on Windows. 2011-01-01 20:53:55 +01:00
Andreas Schneider
98bacf032f tests: Added torture_auth_autopubkey client test. 2011-01-01 20:53:55 +01:00
Andreas Schneider
e795dae8f2 tests: Added a windows test for torture_path_expand_tilde. 2011-01-01 20:53:55 +01:00
Andreas Schneider
459fa3734f tests: Fixed includes for torture_list on Windows. 2011-01-01 20:53:54 +01:00
Andreas Schneider
52d6b7b914 tests: Fixed includes of torture_options for windows. 2011-01-01 20:53:54 +01:00
Andreas Schneider
5331489581 tests: Fixed the torture_callbacks test.
We should zero the structure else ssh_callback_exists() can't be
working.
2011-01-01 19:14:54 +01:00
Andreas Schneider
2945a42c75 tests: Don't run torture_keyfiles on Windows.
This test needs ssh-keygen to be working.
2011-01-01 19:14:54 +01:00
Andreas Schneider
1f47730a82 tests: Fixed Windows build of torture_options. 2011-01-01 19:14:49 +01:00
Andreas Schneider
1b88542fbe misc: Avoid redefine of _WIN32_IE. 2011-01-01 18:43:37 +01:00
Andreas Schneider
530629c5a7 cmake: Added ssl libraries for OS/2. 2010-12-31 14:55:36 +01:00
Andreas Schneider
98b5f07631 cmake: Fixed a warning on OS/2 if the compiler version is empty. 2010-12-31 14:41:50 +01:00
Andreas Schneider
f46bf41813 libssh: Don't use the visibility flag on OS/2. 2010-12-31 14:35:06 +01:00
Andreas Schneider
8e632b14d1 cmake: Fixed installation path for OS/2. 2010-12-31 14:08:20 +01:00
Andreas Schneider
4728ac54fc build: Fixed some build warnings. 2010-12-30 12:12:34 +01:00
Andreas Schneider
da86340551 cmake: Improved the ctest file. 2010-12-30 12:12:06 +01:00
Andreas Schneider
fc8fdcb16b cmake: Only use Profiling on Unix systems. 2010-12-30 11:55:13 +01:00
Andreas Schneider
be68cfe923 cmake: Fixed NSIS detection on Windows. 2010-12-30 11:17:48 +01:00
Andreas Schneider
cb48057098 threads: Fixed ssh_pthread_thread_id with mingw. 2010-12-30 00:39:07 +01:00
Andreas Schneider
ef91ac4ea0 socket: Fixed ssh_socket_fd_set prototype. 2010-12-30 00:30:44 +01:00
Andreas Schneider
1646ce970c cmake: Fixed find modules on Windows. 2010-12-30 00:26:37 +01:00
Andreas Schneider
08906e0f7f tests: It is enough to include libssh.h for torture_init. 2010-12-29 21:02:51 +01:00
Andreas Schneider
887d201bd3 server: Added missing include files for getaddrinfo on Windows. 2010-12-29 20:53:28 +01:00
Andreas Schneider
1267240810 connect: Added and improved regex for ip detection.
Thanks to Norbert Kiesel, rlo#14.
2010-12-29 20:44:07 +01:00
Andreas Schneider
296767afc4 server: Added include files for getaddrinfo. 2010-12-29 20:36:14 +01:00
Andreas Schneider
13f3679b2f tests: Fixed torture_get_user_home_dir on Windows. 2010-12-29 20:35:55 +01:00
Andreas Schneider
f3a6c3152c cmake: Don't build torture_rand on Windows. 2010-12-29 20:33:32 +01:00
Andreas Schneider
80d7ccb522 cmake: Added missing include dirs for libssh. 2010-12-29 20:18:18 +01:00
Andreas Schneider
78abf5a88d cmake: Added include and library deps to torture. 2010-12-29 20:17:36 +01:00
Andreas Schneider
ad231ccd30 cmake: Fixed test includes and libraries. 2010-12-29 20:11:00 +01:00
Andreas Schneider
d4a6c27a83 cmake: Only set profile GCC flags on UNIX systems. 2010-12-29 20:02:03 +01:00
Andreas Schneider
e7a06ad3b4 cmake: Find cmockery on Windows. 2010-12-29 19:51:46 +01:00
Andreas Schneider
d2bf90c982 build: Fixed include directories for torture lib. 2010-12-29 19:49:07 +01:00
Andreas Schneider
69ac51dfaa connect: Added missing $ in IPREGEX.
Fixes rlo#14.
2010-12-29 19:48:15 +01:00
Andreas Schneider
3e2f714248 tests: Fixed a assert bug in torture_auth. 2010-12-29 09:13:17 +01:00
Aris Adamantiadis
530c17e2ef First real benchmark : raw SSH speed 2010-12-29 00:19:05 +01:00
Aris Adamantiadis
31043334f4 Export and document timestamp functions 2010-12-29 00:19:05 +01:00
Andreas Schneider
361e37dc66 tests: Added a torture_sftp_static test. 2010-12-28 22:14:47 +01:00
Andreas Schneider
df55918a41 tests: Migrated torture_proxycommand to cmockery. 2010-12-28 22:14:47 +01:00
Andreas Schneider
e6329c72d1 tests: Migrated torture_knownhosts to cmockery. 2010-12-28 22:14:47 +01:00
Andreas Schneider
8bd29736d2 tests: Migrated torture_auth to cmockery. 2010-12-28 22:14:47 +01:00
Andreas Schneider
0b2cf70622 tests: Migrated torture_algorithms to cmockery. 2010-12-28 22:14:47 +01:00
Andreas Schneider
b0446ad55d tests: Migrated torture_rand to cmockery. 2010-12-28 22:14:47 +01:00
Andreas Schneider
d04ce30b03 tests: Migrated torture_options to cmockery. 2010-12-28 22:14:47 +01:00
Andreas Schneider
512b776245 tests: Migrated torture_misc to cmockery. 2010-12-28 22:14:47 +01:00
Andreas Schneider
d44919dfd4 tests: Migrated torture_list to cmockery. 2010-12-28 22:14:47 +01:00
Andreas Schneider
99d45c686c tests: Moved torture_knownhosts to client tests. 2010-12-28 22:14:47 +01:00
Andreas Schneider
2bc03d22a1 tests: Migrated torture_keyfiles to cmockery. 2010-12-28 22:14:47 +01:00
Andreas Schneider
fa17f33d2b tests: Migrated torture_init to cmockery. 2010-12-28 22:14:47 +01:00
Andreas Schneider
400fc350a7 tests: Migrated torture_callbacks to cmockery. 2010-12-28 22:14:47 +01:00
Andreas Schneider
6f65e6ae67 tests: Migrate torture_buffer to cmockery. 2010-12-28 22:14:47 +01:00
Andreas Schneider
635a263f64 tests: Migrate the torture library to cmockery. 2010-12-28 22:14:47 +01:00
Andreas Schneider
17f592d4dd tests: Start to migrate tests to cmockery.
https://code.google.com/p/cmockery/wiki/Cmockery_Unit_Testing_Framework
2010-12-28 22:14:47 +01:00
Aris Adamantiadis
7dc183126a Set variables in the good order 2010-12-28 13:50:34 +01:00
Aris Adamantiadis
4fe1656cf8 Moved benchmarks to the tests/ directory 2010-12-28 13:17:27 +01:00
Aris Adamantiadis
a883330101 New benchmark framework
with pluggable style benchmarks and an original SSH RTT calculator !
2010-12-28 02:19:15 +01:00
Andreas Schneider
f0d811edc6 ctest: Added more valgrind suppressions. 2010-12-28 00:38:11 +01:00
Andreas Schneider
438083542d connect: Use a better IP regex. 2010-12-28 00:24:47 +01:00
Aris Adamantiadis
4fa2e4dde1 Added compression options and allow "yes/no" setting
SSH_OPTION_COMPRESSION and SSH_OPTION_COMPRESSION_LEVEL options have been added. Now, end-level apps may simply choose to enable compression without knowing the relevant algorithms behind it.
2010-12-27 23:28:39 +01:00
Andreas Schneider
32c0e1c99a test: Added openssh checks to the compression tests. 2010-12-27 22:47:37 +01:00
Andreas Schneider
b4c62ac9ea server: Replace gethostbyname() with getaddrinfo().
Fixes rlo#13.
2010-12-27 21:51:55 +01:00
Andreas Schneider
a0e98f585a misc: Fixed a possible memory leak. 2010-12-27 18:08:30 +01:00
Andreas Schneider
7c728acd12 sftp: Fixed a memory leak in sftp_xstat.
Thanks to dsc for the bug report.
2010-12-27 17:52:24 +01:00
Andreas Schneider
38b87aab08 channels: Fixed a build warning. 2010-12-23 10:18:09 +01:00
Andreas Schneider
33c41074a7 libsshpp: Fixed return of non-void function. 2010-12-23 08:54:39 +01:00
Andreas Schneider
936c65f03e options: Remove unused variable. 2010-12-21 21:29:22 +01:00
Andreas Schneider
825581d0dc packet1: Fixed dead assignments.
Found by http://test.libssh.org/scan-build/
2010-12-21 16:29:08 +01:00
Aris Adamantiadis
942b993f57 Add log verbosity to some testcases 2010-12-21 16:21:49 +01:00
Andreas Schneider
e6bc4b4ff9 doc: Added samplessh hint to INSTALL. 2010-12-21 16:21:02 +01:00
Andreas Schneider
04e224c3b4 doc: Updated Changelog. 2010-12-21 15:51:07 +01:00
Andreas Schneider
19ab9a015f doc: Added copyright policy section. 2010-12-21 15:40:36 +01:00
Andreas Schneider
94fe52870b doc: Update README. 2010-12-21 15:24:38 +01:00
Andreas Schneider
55470aaaf1 doc: Remove the note. 2010-12-21 15:13:18 +01:00
Andreas Schneider
6a26335158 doc: Some fixes for linking howto. 2010-12-21 15:07:42 +01:00
Andreas Schneider
256e88690d doc: Make the warning bold. 2010-12-21 15:03:13 +01:00
Andreas Schneider
3a94c94f20 doc: More linking details. 2010-12-21 14:55:39 +01:00
Andreas Schneider
473d3e0b3a ctest: Set the suppression file correctly. 2010-12-21 14:43:14 +01:00
Andreas Schneider
d5df18a14f build: Fixed build warning on FreeBSD. 2010-12-20 15:49:29 +01:00
Andreas Schneider
bffaa86664 build: Fixed some build warnings on FreeBSD. 2010-12-20 15:45:49 +01:00
Aris Adamantiadis
1922341e2a New benchmarks directory 2010-12-19 18:56:16 +01:00
Andreas Schneider
bcfab67daf ctest: Set the memcheck suppression file correctly. 2010-12-19 16:30:23 +01:00
Andreas Schneider
27f170011e ctest: Set suppression file only in CTestConfig. 2010-12-19 12:54:52 +01:00
Andreas Schneider
5cb4c9451f ctest: Make sure we have a clean source tree for each build. 2010-12-19 12:54:52 +01:00
Aris Adamantiadis
80408d5357 Fixed memory leak reported by valgrind 2010-12-19 12:37:21 +01:00
Aris Adamantiadis
47d11734e1 Fix free() on uninitialized data on some cases. 2010-12-19 12:33:31 +01:00
Andreas Schneider
14d6b8856f example: Fixed gcc warning. 2010-12-18 14:05:06 +01:00
Andreas Schneider
48e4df4ac0 TODO server: Fixed server support. 2010-12-18 14:02:53 +01:00
Andreas Schneider
f5d0f232c8 ctest: Fixed git URL. 2010-12-18 12:15:14 +01:00
Andreas Schneider
d6a5e5cb68 test: Fixed the default ctest file. 2010-12-15 19:15:02 +01:00
Andreas Schneider
751f202f56 doc: Follow the current naming convention. 2010-12-10 20:28:59 +01:00
Andreas Schneider
37eeb854e4 doc: Started to write a linking howto. 2010-12-10 20:17:57 +01:00
Andreas Schneider
57d752a1c3 include: Only require LIBSSH_STATIC on Windows. 2010-12-10 20:02:15 +01:00
Andreas Schneider
ef1cfbea70 build: Use the same name for static and shared library. 2010-12-10 20:00:23 +01:00
Andreas Schneider
038c764055 server: Remove channel_write_stderr. 2010-12-08 10:52:15 +01:00
Andreas Schneider
3ea33f9ab6 doc: Some small fixes in server.h. 2010-12-07 21:43:26 +01:00
Andreas Schneider
1758c172a2 doc: Fixed pki doc group. 2010-12-07 21:28:50 +01:00
Andreas Schneider
2a6cbed121 doc: Define a doc group for the callbacks. 2010-12-07 21:25:53 +01:00
Andreas Schneider
92fc2d6993 doc: Added buzzword. 2010-12-07 20:59:08 +01:00
Aris Adamantiadis
2dba4839ad Fix from Oleksandr Shneyder
http://www.libssh.org/archive/libssh/2010-11/0000005.html
2010-12-07 16:13:40 +01:00
Andreas Schneider
0825abd03a doc: Fixed doc namespace to be able to install manpages. 2010-12-05 10:53:39 +01:00
Aris Adamantiadis
f58441f474 Moved declarations from auth.h to various headers 2010-10-30 22:38:09 +02:00
Aris Adamantiadis
0e82cdeadc Moved includes from priv.h to bind.h 2010-10-27 23:06:38 +02:00
Aris Adamantiadis
b6901ec4b9 Fix senddata.c for 32bits machines 2010-10-27 22:53:20 +02:00
Aris Adamantiadis
ea4aa26dbb Split ssh_bind functions in a new .c file 2010-10-20 16:54:22 +02:00
Aris Adamantiadis
98221f4e36 Fixed a bunch of smallish bugs
http://linuxtesting.org/upstream-tracker/test_results/libssh/current/test_results.html
for a whole list
2010-10-20 14:47:11 +02:00
Aris Adamantiadis
8e2699e161 start of work to have callbackbased ssh_bind 2010-10-19 23:51:32 +02:00
Andreas Schneider
01eb20e13f cmake: Fixed a problem with ccache. 2010-10-19 11:50:29 +02:00
Aris Adamantiadis
b129181809 Adapt comments in options to give parameters types 2010-10-15 16:53:18 +02:00
Aris Adamantiadis
3253ece2a2 Oops, libssh.h did not compile anymore 2010-10-15 16:43:38 +02:00
Aris Adamantiadis
4b462449cf Fix OPTIONS_BINDADDR, PROXYCOMMAND constant change 2010-10-14 11:53:30 +02:00
Aris Adamantiadis
4f8907a524 Removed the global poll ctx in fav. of /session ctx 2010-10-12 17:57:15 +02:00
Aris Adamantiadis
7b1359042c Add zlib@openssh.com on the list of compression 2010-10-04 16:23:43 +02:00
Aris Adamantiadis
da9cd2e64d Implemented zlib@openssh.com compression 2010-10-04 16:19:20 +02:00
Aris Adamantiadis
5d1636985b Resolved the server blocked bug 2010-10-03 21:36:03 +02:00
Aris Adamantiadis
088b86d4fe Fix doxygen warnings 2010-10-03 16:16:30 +02:00
Aris Adamantiadis
9a89fba332 resolve memory consumption bug 2010-10-03 13:31:02 +02:00
Aris Adamantiadis
0bc032726d Fix prepend bug 2010-10-03 13:01:21 +02:00
Aris Adamantiadis
b2f571e544 test the buffer_prepend_data function 2010-10-03 12:25:33 +02:00
Aris Adamantiadis
338a3d9b05 Removed references to ssh_buffer_get_begin 2010-10-03 12:07:00 +02:00
Aris Adamantiadis
5687d6e79a Added buffer test case 2010-10-03 12:06:47 +02:00
Aris Adamantiadis
a9ec8b055f Fix warnings on testcases 2010-10-02 23:27:26 +02:00
Aris Adamantiadis
5f69d494ad Fix documentation of ssh_set_message_callback 2010-10-02 23:24:19 +02:00
milo
3d8cfa9973 Don't grow window if there is no space in the buffer 2010-10-02 22:55:53 +02:00
Aris Adamantiadis
0d5cc01f1c Fix the window not growing problem
Fix conflict with patch from milo
Conflicts:

	src/channels.c
2010-10-02 22:54:59 +02:00
milo
d7581c4daa Change path to ../src instead of the old ../libssh 2010-10-02 22:52:24 +02:00
milo
524302ca7e Added ssh_channel_write_stderr() for the server 2010-10-02 22:52:06 +02:00
milo
2617024136 Added channel features on the server
- ssh_channel_request_send_exit_status()
- ssh_channel_request_send_exit_signal()

- enhanced these features client-side
2010-10-02 22:51:49 +02:00
milo
26d40b5354 Handle global requests and reverse forwarding 2010-10-02 22:51:35 +02:00
milo
c4356531f7 Add new callbacks in session and channels 2010-10-02 22:51:14 +02:00
Aris Adamantiadis
873e02fc6a First step getting rid of ssh_buffer_get_begin 2010-10-01 23:41:04 +02:00
Aris Adamantiadis
985db35173 Rewrote channel_read_buffer to use ssh_channel_read 2010-10-01 23:03:08 +02:00
Aris Adamantiadis
c4e67730a3 Convert sftp.c to ssh_channel_read 2010-10-01 21:41:56 +02:00
Aris Adamantiadis
9f7e2c3252 Update the window *after* effective read 2010-10-01 18:56:57 +02:00
Aris Adamantiadis
5675fbe73e Fix the behaviour of channel window handling 2010-10-01 18:38:08 +02:00
Aris Adamantiadis
5b1c985a0e Changed the threads cbks from struct to publ func 2010-09-30 11:10:08 +02:00
Aris Adamantiadis
bedc65313f Removed the extern char *environ 2010-09-30 10:42:55 +02:00
Aris Adamantiadis
9f53906209 Remove extern environ from the requirements 2010-09-29 17:06:54 +02:00
Andreas Schneider
be837cdbc2 misc: Fixed a typo. 2010-09-29 14:19:07 +02:00
Andreas Schneider
38359672a5 misc: Make sure ssh_analyze_banner has proper length checks. 2010-09-29 12:12:14 +02:00
Andreas Schneider
1b471256d4 misc: Differentiate between client and server in ssh_analyze_banner. 2010-09-29 12:11:43 +02:00
Andreas Schneider
30e22fed6e misc: Fixed a possible data overread and crash bug. 2010-09-29 11:29:37 +02:00
Andreas Schneider
8b719e51cf misc: Move ssh_analyze_banner to a common location.
Don't duplicate functions!
2010-09-29 11:26:35 +02:00
Andreas Schneider
72b62d3064 build: Fixed the unit test build. 2010-09-29 11:26:16 +02:00
Andreas Schneider
5f24a84298 known_hosts: Added missing include.
Thanks miloj ;)
2010-09-29 11:17:46 +02:00
Andreas Schneider
1eaf55c5f6 keyfiles: Fixed unlink warning. 2010-09-28 19:16:42 +02:00
Andreas Schneider
9d3b84c914 threads: Fixed windows build.
MSVC isn't C99.
2010-09-28 19:12:01 +02:00
Andreas Schneider
b391a7603a pki: Create a file for known_hosts functions. 2010-09-28 19:09:29 +02:00
Andreas Schneider
45b551d4f7 build: Remove unneeded include directories. 2010-09-28 19:08:11 +02:00
Andreas Schneider
15e4ec38f2 pki: Added GPL to header file. 2010-09-28 19:07:16 +02:00
Andreas Schneider
8c318fcb21 keyfiles: Fixed the windows defines. 2010-09-28 19:06:49 +02:00
Andreas Schneider
a2fe4b2b2c options: Rename HOSTKEYCHECK to STRICTHOSTKEYCHECK.
Looks like people are confused by the name and think this is normal host
key checking.
2010-09-28 14:13:18 +02:00
Andreas Schneider
e36c9c529b options: Fixed documentation of SSH_OPTIONS_HOSTKEYCHECK. 2010-09-28 14:10:15 +02:00
Aris Adamantiadis
41c4e1f5c8 Completed senddata example to exit someday 2010-09-26 23:11:07 +02:00
Aris Adamantiadis
75a0281a6b Fixed outgoing flow control + writes behaviours 2010-09-26 22:33:58 +02:00
Vic Lee
a92545517a socket.c: Fixed setting max_fd which breaks ssh_select().
Signed-off-by: Andreas Schneider <asn@cynapses.org>
2010-09-20 19:22:19 +02:00
Andreas Schneider
fe31fcaeef pki: Fixed a possible crash. 2010-09-18 20:59:29 +02:00
Aris Adamantiadis
f7ea9a3f27 Added documentation for threading 2010-09-12 22:34:38 +02:00
Aris Adamantiadis
b0c03280d1 ssh_threads_init is private 2010-09-12 22:01:21 +02:00
Aris Adamantiadis
5eb7c7b6ec Added initialisation logs for threading 2010-09-12 21:53:42 +02:00
Aris Adamantiadis
b7af2b2959 Changed callbacks type 2010-09-12 21:45:53 +02:00
Andreas Schneider
9f02a817ff build: Added -pedantic-errors. 2010-09-10 21:46:36 +02:00
Andreas Schneider
6345afabf8 build: Remove unneeded debug message. 2010-09-09 20:09:44 +02:00
Aris Adamantiadis
899db7cf22 Fix #ifdef'ed erroneous debug code in buffer.c 2010-09-09 10:01:29 +02:00
Andreas Schneider
f45dc29eb2 build: Improve pthread detection. 2010-09-08 16:51:55 +02:00
Andreas Schneider
d2f38da094 build: Make sure LIBSSH_THREADS_LINK_LIBRARIES is in the cache. 2010-09-08 16:43:55 +02:00
Andreas Schneider
697d51cd93 build: Make sure to link against all required thread libraries. 2010-09-08 16:32:54 +02:00
Andreas Schneider
f9b0dca7bd build: Fixed options parsing. 2010-09-08 16:29:50 +02:00
Andreas Schneider
03087e020c build: Improve the check for argp. 2010-09-08 11:41:14 +02:00
Andreas Schneider
4f75fdcd14 build: There is no need to check for system libraries on Linux. 2010-09-08 11:20:10 +02:00
Andreas Schneider
031c06419b build: Added DefinePlatformDefaults cmake file. 2010-09-08 11:20:10 +02:00
Andreas Schneider
254a08f540 build: Cleanup DefineCompilerFlags. 2010-09-08 11:20:10 +02:00
Andreas Schneider
76ead916ce build: Fixed linking against libssh in thread library. 2010-09-08 10:50:06 +02:00
Andreas Schneider
ab2dafc44a socket: Make code easier to read and debug. 2010-09-07 18:50:38 +02:00
Andreas Schneider
325cc4e395 session: Fixed a memory leak with session->bindaddr. 2010-09-07 17:30:10 +02:00
Andreas Schneider
c1604eff08 misc: Fixed a memory leak. 2010-09-07 17:26:07 +02:00
Andreas Schneider
77b52a5e69 doc: Added links to the RFCs. 2010-09-07 10:27:46 +02:00
Andreas Schneider
d414c4f500 doc: Fixed doxygen config. 2010-09-07 09:55:15 +02:00
Éric Bischoff
398bc769ce doc: More work on the tutorial. 2010-09-07 09:54:42 +02:00
Aris Adamantiadis
49f57a8d0d Implemented the noop and native pointers 2010-09-06 16:52:14 +02:00
Andreas Schneider
fbe102bada threads: Build a libssh threading library. 2010-09-06 15:17:03 +02:00
Aris Adamantiadis
2cca490076 Moved pthread specific code in src/threads/pthread.c
pthread example doesn't compile du to the lack of
libssh_threads_native.so library
2010-09-06 14:51:01 +02:00
Andreas Schneider
f7842e3a4b misc: Rename libssh/ to src/ 2010-09-06 14:28:38 +02:00
Éric Bischoff
38421403d2 doc: Some corrections for shell execution. 2010-09-06 11:03:00 +02:00
Andreas Schneider
461dde231c build: Fixed a wrong if statement. 2010-09-05 13:11:19 +02:00
Andreas Schneider
0785c522f0 build: Fixed build with gcc 3.4.
The -fvisibility=hidden flag is broken in gcc 3.4. This fixes the build
on CentOS, bug #74.
2010-09-05 12:56:01 +02:00
Andreas Schneider
2656c6b4ac server: Fixed a shadowed variable. 2010-09-05 12:34:12 +02:00
Andreas Schneider
ed5ebe7458 tests: Fixed cmdline parsing. 2010-09-05 12:34:12 +02:00
Andreas Schneider
d71d6afa34 tests: Disable options parsing if argp isn't available. 2010-09-03 15:44:41 +02:00
Andreas Schneider
2f8f230f61 build: Added support to find argp on BSD. 2010-09-03 15:38:12 +02:00
Aris Adamantiadis
285388409f Made pthread threading a user macro 2010-09-03 12:03:04 +02:00
Andreas Schneider
aff5786ed3 thread: Fixed detection of thread libraries on Windows. 2010-09-02 12:31:59 +02:00
Andreas Schneider
f97928c740 build: Fixed checking for printf function on Windows. 2010-09-02 11:50:21 +02:00
Andreas Schneider
bca73b8340 poll: Fixed the Windows build on Vista and newer. 2010-09-01 23:31:24 +02:00
Aris Adamantiadis
e67d834156 Fix initialization of threading 2010-09-01 16:05:06 +02:00
Andreas Schneider
a93f2d8bfe build: Fixed pthread detection. 2010-09-01 15:15:17 +02:00
Aris Adamantiadis
8c55294ea9 Openssl implementation of threading + default imp 2010-09-01 14:07:45 +02:00
Aris Adamantiadis
50d8d75d89 some more work on threading but not complete yet 2010-08-31 16:49:55 +02:00
Aris Adamantiadis
bcc2d8474c Begin of a solution for threading 2010-08-30 23:44:03 +02:00
Aris Adamantiadis
e34da1b94d Added "fix" for libgcrypt threading, ...
... but it doesn't seem to work. This is however the recommanded
way of initializing threading :
http://lists.gnupg.org/pipermail/gcrypt-devel/2009-February/001452.html
2010-08-30 14:39:35 +02:00
Aris Adamantiadis
717eff71dd Added test for the openssl threading 2010-08-30 14:08:07 +02:00
Éric Bischoff
ad95cbc542 doc: Added documentation for tunnels. 2010-08-29 16:25:31 +02:00
Aris Adamantiadis
b30aff6d4d Mark channel_read_buffer as deprecated in doxygen 2010-08-29 00:12:01 +02:00
Aris Adamantiadis
bf9a82ad9a Limit the size of packets in ssh_channel_write* 2010-08-28 23:59:18 +02:00
Aris Adamantiadis
c1efcd28f5 Fixes bug #99
returns error when no cryptographic context is available
2010-08-28 23:35:59 +02:00
Aris Adamantiadis
1fa9409554 ssh_channel_forward_* -> ssh_forward_*
Fixes bug #108
2010-08-28 23:31:07 +02:00
Aris Adamantiadis
adcd2e38e9 libsshpp: do not use deprecated functions 2010-08-28 22:53:18 +02:00
Aris Adamantiadis
c19fb5656b Fixed missing libsshpp methods 2010-08-28 22:51:23 +02:00
Aris Adamantiadis
74939b8b8d Added missing /** in doxygen @}'s 2010-08-28 21:32:08 +02:00
Aris Adamantiadis
29a229724b Fix a few documentation issues 2010-08-28 21:05:24 +02:00
Aris Adamantiadis
a9fafc32a8 Near to end of implementation of the C++ wrapper 2010-08-28 13:59:24 +02:00
Andreas Schneider
2de227a88b doc: Fixed section names. 2010-08-27 16:22:38 +02:00
Éric Bischoff
31ad140d20 doc: More work on the tutorial. 2010-08-27 16:20:17 +02:00
Aris Adamantiadis
bcf4e56fe0 Fix C++ documentation about the exceptions 2010-08-27 12:01:42 +02:00
Aris Adamantiadis
1834ca3820 Added a SSH_NO_CPP_EXCEPTIONS mode to libsshpp.h 2010-08-27 11:53:38 +02:00
Andreas Schneider
ad4a4120b7 doc: Add more details to the mainpage. 2010-08-27 11:45:13 +02:00
Andreas Schneider
0800f7ba56 doc: Added a newline on the mainpage. 2010-08-27 11:33:43 +02:00
Andreas Schneider
36576babe8 doc: Document the server responses. 2010-08-27 11:27:42 +02:00
Éric Bischoff
ba9f5b7d95 doc: Improved the tutorial. 2010-08-27 11:11:08 +02:00
Andreas Schneider
11a5383604 poll: Fixed the ssh_poll_(init/cleanup) functions. 2010-08-25 23:11:54 +02:00
Andreas Schneider
d991606493 poll: Fixed the usage of WSAPoll() on Windows.
This should fix ticket #101.
2010-08-25 23:11:54 +02:00
Aris Adamantiadis
14048354d5 Fix conflicts/ missing /** */ in doxygen 2010-08-23 21:21:57 +02:00
Eric Bischoff
94b689e19d New update of doxygen documentation 2010-08-23 21:00:35 +02:00
Aris Adamantiadis
8066100f53 Doxygen fixes 2010-08-23 20:48:30 +02:00
Aris Adamantiadis
f60c22628a lot of C++ wrapper work 2010-08-23 20:34:17 +02:00
Aris Adamantiadis
53e608cbc4 Changed SSH_SUCCESS to SSH_OK 2010-08-20 13:01:12 +02:00
Aris Adamantiadis
d10e73ffd7 Fixed "@deprecated" in doxygen 2010-08-20 13:00:10 +02:00
Aris Adamantiadis
1e75841036 Obsoletes ssh_auth_list, comment ssh_userauth_list 2010-08-19 19:51:18 +02:00
Eric Bischoff
32bf28e7ef doc: Improve the tutorial. 2010-08-19 15:06:38 +02:00
Aris Adamantiadis
fd5aeba117 Change SOversion to 4.2.0 instead of 5.0.0 2010-08-18 23:18:57 +02:00
Milo Jhoran
24b524040b server: Added an API entry for the message callback.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
2010-08-13 11:17:18 +02:00
milo
e533c3f33b server: Fix missing socket close notification.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
2010-08-13 11:17:09 +02:00
Aris Adamantiadis
41ab19e1d0 Log Proxycommand command executed 2010-08-10 14:32:03 +02:00
Andreas Schneider
77475bdd55 misc: Added %p for port to ssh_path_expand_escape(). 2010-08-10 11:10:26 +02:00
Milo Jhoran
0c70e80d47 Fix typos in port forwarding (server side) 2010-08-10 00:49:24 +02:00
Andreas Schneider
5aa4592f0c example: Fixed build of samplesshd. 2010-08-10 00:32:51 +02:00
milo
855b73de87 server: Split ssh_bind_accept and create ssh_handle_key_exchange.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
2010-08-10 00:30:25 +02:00
Aris Adamantiadis
136f4d3b0d Removed unnecessary headers in samplesshd 2010-08-09 22:08:43 +02:00
Aris Adamantiadis
714edcb8d9 Moved content from deprecated.c to legacy.c 2010-08-09 22:05:33 +02:00
Andreas Schneider
a6b6a61775 server: Make ssh_accept a depreacted function to not break the API. 2010-08-09 21:39:32 +02:00
Andreas Schneider
39c9a6dfed server: Merge ssh_bind_accept. 2010-08-09 21:28:47 +02:00
Andreas Schneider
561df8d9a2 server: Rename ssh_accept to ssh_bind_accept. 2010-08-09 20:54:43 +02:00
milo
48a20a6137 example: Fixed the sample ssh server implementation.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
2010-08-09 20:54:40 +02:00
milo
8ef0fbc294 server: Fixed the server implementation.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
2010-08-09 20:54:32 +02:00
milo
51a21823f9 server: Added a define to set the server status.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
2010-08-09 20:54:28 +02:00
milo
7a68331fcd messages: Make sure we pop the message at the beginning.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
2010-08-09 20:54:23 +02:00
milo
d896d6393b wrapper: Added a log message if client kex is empty.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
2010-08-09 20:54:17 +02:00
milo
6d531ed0a6 session: Set needed poll events for handling packets.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
2010-08-09 20:54:13 +02:00
milo
06df7c1b31 socket: Make sure we only transmit data if we have some.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
2010-08-09 20:54:06 +02:00
milo
2b108483ce pcap: Zero the pcap structure.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
2010-08-09 20:54:01 +02:00
milo
23c745d335 kex: Fixed initialization of server kex.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
2010-08-09 20:53:56 +02:00
milo
eb361626cb session: Added callback for the connection per session.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
2010-08-09 20:53:49 +02:00
milo
b0f8ca556b session: Fixed the type of the session dh_handshake_state.
Signed-off-by: Andreas Schneider <asn@cynapses.org>
2010-08-09 20:53:03 +02:00
Andreas Schneider
e41e28744f build: Added a check for NSIS. 2010-08-03 18:13:59 +02:00
Andreas Schneider
e862f04527 build: Set a default zlib search path for windows. 2010-08-03 18:13:59 +02:00
Andreas Schneider
42519db55d build: Set a default openssl search path for windows. 2010-08-03 18:13:59 +02:00
Andreas Schneider
019cb77b84 build: Don't test for big endian on Windows.
Visual Studio 2010 has problems running the test.
2010-08-03 18:13:59 +02:00
Andreas Schneider
296f6a9217 build: Fixed the Windows preprocessor macros and defines. 2010-08-03 18:13:59 +02:00
Aris Adamantiadis
d688ed2553 Begining of zlib@openssh.org implementation 2010-07-23 16:49:28 +02:00
Aris Adamantiadis
b4c0b03694 Added the client unit testing information 2010-07-23 11:04:09 +02:00
Aris Adamantiadis
e721c122d3 Continue removing old flushing code 2010-07-23 11:01:06 +02:00
Aris Adamantiadis
8cd0d0040e Removed obsolete socket functions 2010-07-23 08:27:05 +02:00
Aris Adamantiadis
e5542b027b State error in server.c 2010-07-23 08:18:37 +02:00
Aris Adamantiadis
5aa9cf2fcf Add consistency check to ssh_set_callbacks 2010-07-23 08:09:57 +02:00
Aris Adamantiadis
a924869096 Receive and send SSH_MSG_UNIMPLEMENTED 2010-07-18 00:39:51 +02:00
Aris Adamantiadis
8c08b062d0 Fixed channel opening failures (infinite loop) 2010-07-17 23:51:15 +02:00
Aris Adamantiadis
96b06e8bb4 Fixed keepalive problem on older openssh servers
Conflicts:

	libssh/channels.c
2010-07-16 23:16:04 +02:00
Aris Adamantiadis
a8efffa969 New example for port forwarding
Conflicts:

	examples/CMakeLists.txt
2010-07-16 23:14:47 +02:00
Andreas Schneider
ef0215fcf2 poll: Added poll constants for Windows.
WSAPoll uses different constanst values as the POSIX implementation,
what else ...
2010-07-09 09:49:21 +02:00
Andreas Schneider
82beeea619 options: Added option to bind a client to an ip address.
Thanks to Donatello Boccaforno <donatello.boccaforno@gmail.com>.
2010-07-07 12:43:50 +02:00
Aris Adamantiadis
a18a3813fb Removed dead code in socket.c 2010-07-07 10:19:47 +02:00
Andreas Schneider
b8180f4069 poll: FD_SETSIZE is only for the count value of FD_SET on Windows. 2010-07-06 00:41:00 +02:00
Aris Adamantiadis
94b00cc762 Add ssh_callbacks_exists internal macro + unittest
(first commit with eclipse helios, crossing fingers ...)
2010-06-25 16:19:19 +02:00
Andreas Schneider
e4701e7c86 poll: Another attempt to get bsd_poll() working correctly. 2010-06-24 09:19:34 +02:00
Andreas Schneider
fc625b8a8e poll: Fixed building with poll-emulation on UNIX. 2010-06-24 09:19:26 +02:00
Andreas Schneider
703f125882 agent: Use the our poll typedef. 2010-06-24 09:19:10 +02:00
Andreas Schneider
4581b24b48 poll: Added a comment to the bsd_poll() implementation. 2010-06-22 14:44:35 +02:00
Andreas Schneider
1d84821d93 poll: Handle FD_SETSIZE in bsd_poll(). 2010-06-22 14:44:24 +02:00
Andreas Schneider
07f607ec4c poll: Fixed a comparsion. 2010-06-22 14:43:48 +02:00
Aris Adamantiadis
c3833c6c03 Fix threadsafety issue in zlib code 2010-06-22 12:42:13 +02:00
Aris Adamantiadis
65008e2d3c Fixes leak reports in valgrind 2010-06-21 15:47:34 +02:00
Andreas Schneider
d33a97b663 poll: Fixed a typo. 2010-06-21 15:41:18 +02:00
Andreas Schneider
6f9fea7fd5 poll: Check if maxfd has been set. 2010-06-20 21:18:46 +02:00
Andreas Schneider
c8d978f4e9 ctest: Update config file for new cdash board. 2010-06-20 10:29:25 +02:00
Andreas Schneider
558f889aae Fixed more fd checks. 2010-06-17 13:47:29 +02:00
Andreas Schneider
937268eb3e torture: Fixed fd check. 2010-06-17 13:38:13 +02:00
Andreas Schneider
8be7ece1f5 client: Fixed fd checks. 2010-06-17 13:37:42 +02:00
Andreas Schneider
6127da58f2 server: Fixed types and checks of fd's. 2010-06-17 13:29:14 +02:00
Andreas Schneider
15e4e7e9da poll: Fixed type of the fd variables and use SSH_INVALID_SOCKET. 2010-06-17 13:25:45 +02:00
Andreas Schneider
d484d4e129 channel: Fixed the type of the max fd variable in ssh_channel_select(). 2010-06-17 13:23:03 +02:00
Andreas Schneider
985019ab64 agent: Use ssh_poll in agent code. 2010-06-17 13:21:22 +02:00
Andreas Schneider
870c9a7a08 socket: Rename INVALID_SOCKET_T to SSH_INVALID_SOCKET. 2010-06-17 13:19:24 +02:00
Andreas Schneider
2a6341c08c socket: Fixed checks for max fd. 2010-06-17 13:13:35 +02:00
Andreas Schneider
78e7873e92 socket: Fixed prototype of ssh_socket_pollcallback(). 2010-06-17 13:09:58 +02:00
Andreas Schneider
7ecec3eb94 poll: Fixed brackets. 2010-06-17 12:01:27 +02:00
Andreas Schneider
f4facc4e10 poll: Fixed another wrong invalid fd check in bsd_poll. 2010-06-17 11:47:39 +02:00
Andreas Schneider
edffc2a291 poll: Some code cleanup for easier debugging. 2010-06-17 11:19:05 +02:00
Andreas Schneider
c30a25e64c poll: Fixed a malfunction with wrong max fd value check. 2010-06-17 11:16:24 +02:00
Andreas Schneider
b9a9f54c45 string: Added a function to delete a char basesd stirng object. 2010-06-11 11:05:37 +02:00
Andreas Schneider
f57d2c3277 build: Fixed building without zlib. 2010-06-11 10:43:02 +02:00
Andreas Schneider
11a1ae59f4 tests: Moved proxycommand test to client tests. 2010-06-03 16:55:45 +02:00
Andreas Schneider
cd1129b9b8 config: Use ssh log and error functions for problems. 2010-06-03 16:45:23 +02:00
Andreas Schneider
216cabc563 tests: Move getpwuid_r to a setup function. 2010-06-03 16:44:47 +02:00
Andreas Schneider
5dd4f7604f tests: Move client tests to a seperate directory.
Tests which require a running sshd should go to tests/client.
2010-06-03 12:36:00 +02:00
Andreas Schneider
94ce1ea451 tests: Fixed the misc torture test. 2010-06-03 12:29:32 +02:00
Andreas Schneider
f3697a0d5c keyfiles: Move the auth callback inside the HAVE_LIBGCRYPT ifdef. 2010-06-03 12:29:31 +02:00
Andreas Schneider
8f0d40a1dd cpp: Fixed return value of userauthAutopubkey. 2010-06-02 10:01:46 +02:00
Andreas Schneider
a138a52021 doc: Fixed ssh_path_expand_tilde documentation. 2010-06-01 23:11:00 +02:00
Andreas Schneider
518a9b8d8c doc: Group the poll functions and add a description. 2010-06-01 23:10:01 +02:00
Andreas Schneider
64ae0525cf socket: According to execle(2) environ shouldn't be const. 2010-06-01 21:50:03 +02:00
Aris Adamantiadis
dc88a937f0 Fix warning for snprintf 2010-05-31 11:19:27 +02:00
Aris Adamantiadis
ac93e2aea7 Fix unclean null termination in ~ expending 2010-05-31 11:19:10 +02:00
Andreas Schneider
560e938038 misc: Move size check down in ssh_path_expand_escape(). 2010-05-31 09:17:54 +02:00
Andreas Schneider
2a5d71971c misc: Make sure the expanded string is null-terminated. 2010-05-30 10:59:47 +02:00
Andreas Schneider
a59e65336d session: Fixed setting up default identity files. 2010-05-28 10:46:50 +02:00
Andreas Schneider
55ef7bc012 options: Make sure that we have always have default options set. 2010-05-21 10:23:19 +02:00
Andreas Schneider
d3f1d094f7 options: Set the local username if still not set. 2010-05-21 10:22:27 +02:00
Andreas Schneider
421fb2a829 keyfiles: Fixed possible problem with known_hosts path. 2010-05-21 10:08:26 +02:00
Aris Adamantiadis
517e58d3dc Fixed keyboard-interactive and unit test 2010-05-19 14:07:40 +02:00
Aris Adamantiadis
0eaa650e32 Fix authentication test 2010-05-19 11:13:47 +02:00
Aris Adamantiadis
4fbe572c02 Added verbosity flag for unit tests 2010-05-18 23:02:41 +02:00
Aris Adamantiadis
7c0ce909ed Added unit test for kbdint and password auth.
The kbdint test still doesn't pass
2010-05-18 22:49:22 +02:00
Aris Adamantiadis
f95157297e Factorize all the main functions in unit tests 2010-05-18 22:25:06 +02:00
Aris Adamantiadis
89993dd757 Fixed unittest name 2010-05-18 22:11:41 +02:00
Andreas Schneider
75e7c30594 cmake: Fixed doxygen. 2010-05-18 00:33:58 +02:00
Andreas Schneider
5032a9f13c doxygen: Fixed latex pdf generation. 2010-05-18 00:33:44 +02:00
Andreas Schneider
4f34062623 sftp: Fixed sftp_chown. 2010-05-17 23:37:11 +02:00
Andreas Schneider
255f5bd73f Install missing legacy header file. 2010-05-17 23:36:39 +02:00
Aris Adamantiadis
0ec847bbe7 Added some other junk test file 2010-05-17 20:08:11 +02:00
Aris Adamantiadis
08bc076a0a New sample that writes a lot of data on channel 2010-05-17 20:08:10 +02:00
Aris Adamantiadis
2c014256f7 Fix sftp_rename on sftp3 2010-05-17 20:08:10 +02:00
Andreas Schneider
488e822c8d poll: Added a cleanup function to free the ws2_32 library. 2010-05-17 11:19:31 +02:00
Aris Adamantiadis
2234c115f2 Separation work between openssl and libgcrypt 2010-05-14 01:22:22 +02:00
Aris Adamantiadis
b23b3f1d99 Sanitize libssh namespace + legacy wrappers 2010-05-14 00:51:08 +02:00
Andreas Schneider
46b249f5ce connect: Fixed signedness warnings from MSVC. 2010-05-12 21:01:18 +02:00
Andreas Schneider
b1b42aeb9c win: Added missing includes with newer MSCV. 2010-05-12 21:01:18 +02:00
Andreas Schneider
56c867edfa connect: Don't shadow errno. 2010-05-12 20:30:52 +02:00
Andreas Schneider
40c1a7e91f connect: Make sure that we use float values for the status. 2010-05-12 20:27:15 +02:00
Andreas Schneider
9739dae794 proxycommand: check the return values of pipe(). 2010-05-12 19:29:13 +02:00
Andreas Schneider
81793de030 Fixed building libssh with DEBUG_CRYPTO. 2010-05-12 19:24:22 +02:00
Andreas Schneider
a5157e69b1 Increment the soversion number. 2010-05-12 19:01:25 +02:00
Andreas Schneider
101a65378c Merge branch 'look' 2010-05-12 18:42:20 +02:00
Andreas Schneider
91ef298e7d Added runtime detection of WSAPoll().
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2010-05-12 18:22:09 +02:00
Andreas Schneider
739234afb9 Added the possibility to define _OPENSSL_DIR and _ZLIB_DIR. 2010-05-12 13:55:32 +02:00
Andreas Schneider
4ecefb5017 Fixed linking errors on Windows. 2010-05-12 13:53:25 +02:00
Andreas Schneider
444008aabc Fixed build of ssh_lowercase and ssh_hostport on Windows. 2010-05-12 13:47:28 +02:00
Andreas Schneider
45857bc606 Fixed windows include files in pcap support. 2010-05-12 13:39:44 +02:00
Andreas Schneider
da9b2e25f6 Fixed Windows build warnings. 2010-05-12 13:08:45 +02:00
Andreas Schneider
fc508f9494 Fixed Windows build. 2010-05-12 12:46:50 +02:00
Andreas Schneider
3573bd4d87 Use the new expand functions. 2010-05-11 09:40:33 +02:00
Andreas Schneider
c7ee14e786 Added a torture test for ssh_path_expand_escape(). 2010-05-11 02:10:55 +02:00
Andreas Schneider
fac56bae32 Added a function to expand an escaped string. 2010-05-11 02:10:55 +02:00
Andreas Schneider
c5c1698cde Added a torture test for ssh_path_expand_tilde(). 2010-05-11 02:10:55 +02:00
Andreas Schneider
4df7daec82 Added a function to expand the tilde from a path. 2010-05-11 02:10:55 +02:00
Aris Adamantiadis
26d04ff037 Fix style in ssh_poll_ctx_dopoll
Also do a rescan of polled events when a poll object has been deleted.
2010-05-10 23:19:39 +02:00
Aris Adamantiadis
5713481838 Fix options copy 2010-05-10 22:46:20 +02:00
Aris Adamantiadis
74c9c1afa9 Added code to test proxycommand
Conflicts:

	examples/sample.c
2010-05-10 22:44:06 +02:00
Aris Adamantiadis
e159f04df8 make compression not mandatory in options_getopt 2010-05-10 22:17:29 +02:00
Aris Adamantiadis
4a21b6f168 Some grammarnazi things + fix int->socket_t 2010-05-10 22:01:09 +02:00
Aris Adamantiadis
fe16cce405 Fix crash in testcase proxycommand 2010-05-10 21:50:03 +02:00
Andreas Schneider
8ba02b6f4c Use configure checks to define vsnprintf and strncpy. 2010-05-10 15:32:17 +02:00
Andreas Schneider
f5191ec222 Added configure checks for _vsnprintf_s and strncpy. 2010-05-10 15:27:40 +02:00
Andreas Schneider
144126789c Added configure checks for vsnprintf and _vsnprintf. 2010-05-10 15:24:52 +02:00
Andreas Schneider
8dcfc9849e Fixed building libssh with VC9. 2010-05-10 14:40:00 +02:00
Andreas Schneider
b28fb6654c Fixed a MSVC build error. 2010-05-10 13:18:16 +02:00
Aris Adamantiadis
9294c3284c Changed test name + test with invalid proxycommand 2010-05-10 11:08:32 +02:00
Andreas Schneider
9278dc0666 Added more defines to use secure VC functions. 2010-05-10 10:41:47 +02:00
Aris Adamantiadis
af519d73ae Fix doc and actually make the test run :) 2010-05-09 01:05:12 +02:00
Aris Adamantiadis
3a326793fd Test case for proxycommand 2010-05-09 00:54:37 +02:00
Aris Adamantiadis
f31a14b793 ssh_socket support for 2 fd + Proxyhost command 2010-05-09 00:48:10 +02:00
Aris Adamantiadis
7886326aa8 Fix u_int_x_t -> uint_x_t 2010-05-08 22:23:05 +02:00
Aris Adamantiadis
31cc03f8e6 added test for ntohll 2010-05-08 22:22:06 +02:00
Aris Adamantiadis
cf7449c525 Added tests for ssh_dirname and ssh_basename 2010-05-08 22:13:35 +02:00
Aris Adamantiadis
b0cdbf5b22 Added test for zlib compression method
Unfortunately the test doesn't pass. (my host doesn't support zlib, only zlib@openssh.com)
2010-05-07 13:51:10 +02:00
Aris Adamantiadis
231e378157 Added torture_algorithms test case
tests for all supported cipher types
2010-05-07 13:39:38 +02:00
Aris Adamantiadis
431d8fe7c7 The actual init test 2010-05-07 13:39:08 +02:00
Aris Adamantiadis
9ee4d6c697 Added torture_ssh_init unit test 2010-05-07 13:16:42 +02:00
Aris Adamantiadis
3f14d7a54a More detailed tests 2010-05-05 14:57:47 +02:00
Aris Adamantiadis
52acb3fcac Make unit test spit libssh error messages 2010-05-05 14:26:30 +02:00
Aris Adamantiadis
a8d08a9478 Fixed a typo in tutorial 2010-05-03 21:15:24 +02:00
Aris Adamantiadis
c691aa3e32 Forgot the pki files 2010-05-02 00:03:06 +02:00
Aris Adamantiadis
430e570629 Added pki.[ch] files as a new standard API for PKs
Right now it's just a wrapper to the existing calls
but soon it's gona be the effective implementation and
other calls will be wrappers.
2010-05-01 20:32:27 +02:00
Aris Adamantiadis
65dc4f1186 Match hashed [host]:port format knownhosts 2010-05-01 16:52:46 +02:00
Aris Adamantiadis
6b320a00a0 knownhosts writing and unit test 2010-05-01 12:47:44 +02:00
Aris Adamantiadis
22be109956 First implementation of known_hosts with port read 2010-05-01 00:40:10 +02:00
Aris Adamantiadis
4bb790fb5d Fix uninitialized variable used 2010-04-28 20:22:05 +02:00
Aris Adamantiadis
7d32ec5d28 Fix warnings found with clang analyzer 2010-04-28 19:36:39 +02:00
Aris Adamantiadis
20e7ec96ae Fix bugs found by clang analyzer 2010-04-28 18:43:41 +02:00
Aris Adamantiadis
2e563e0fa8 Fix documentation of MacroCheckCCompilerFlagSSP 2010-04-28 18:31:07 +02:00
Aris Adamantiadis
cbd0a8f4b5 Change the test file for stackprotector for clang
Now compiles with clang !
2010-04-28 18:01:15 +02:00
Aris Adamantiadis
ecbe577be3 Fixed warnings with clang 2010-04-28 17:23:47 +02:00
Aris Adamantiadis
84db436e3b Fix doc and libgcrypt build 2010-04-28 12:48:47 +02:00
Aris Adamantiadis
904c6ed853 Renamed private type TYPE_RSA to SSH_KEYTYPE_*
Also made this enum public
2010-04-28 12:14:03 +02:00
Aris Adamantiadis
186e07b415 Added ssh_privatekey_type public function 2010-04-28 11:51:42 +02:00
Aris Adamantiadis
4ab63d3d8c Added first unittest-based bug found :) 2010-04-27 23:48:54 +02:00
Aris Adamantiadis
696ef7aecc Added privatekey_from_file with passphrase test 2010-04-27 23:48:18 +02:00
Aris Adamantiadis
9603f2520b make torture_keyfiles silent 2010-04-27 23:28:18 +02:00
Aris Adamantiadis
a5a806f7ee Added test for privatekey_from_file 2010-04-27 23:25:21 +02:00
Aris Adamantiadis
fa294e8603 Fix select loop in sample 2010-04-24 23:22:00 +02:00
Aris Adamantiadis
97d2f755c4 Do not send twice ssh_userauth_none requests
Thanks to Xi Wang for the bug report
2010-04-24 23:01:18 +02:00
Aris Adamantiadis
83536ab7d1 Fixes \r in SSH1 banner
Thanks to Xi Wang for the patch
WARNING: this may cause backward compatibility
issues with SSH1, revert if there are problems
2010-04-24 22:47:34 +02:00
Aris Adamantiadis
6cdbc01208 Fixes infinite loops
Thanks to Xi Wang for the patches
2010-04-24 22:46:19 +02:00
Andreas Schneider
833903e8ec torture: Fix compiling options test if NSS_BUFLEN_PASSWD isn't defined.
Thanks to Xi Wang for the patch.
2010-04-20 13:30:07 +02:00
Andreas Schneider
c53383a316 session: Fixed a memory leak.
Thanks to Xi Wang for the patch.
2010-04-20 13:29:50 +02:00
Andreas Schneider
dfc35699ea packet: Fixed linking if we build without server support.
Thanks to Xi Wang for the patch.
2010-04-20 13:28:54 +02:00
Andreas Schneider
b7a7c816df kex: Fixed a memory leak.
Thanks to Xi Wang for the patch.
2010-04-20 13:28:12 +02:00
Andreas Schneider
090f036205 channels: Don't use signal as a name.
Thanks to Xi Wang for the patch.
2010-04-20 13:27:12 +02:00
Andreas Schneider
8738e93dc0 cmake: Fixed openssl detection.
Thanks to Xi Wang for the patch.
2010-04-20 13:25:46 +02:00
Aris Adamantiadis
ee2bee88ee Fix warnings 2010-04-14 21:20:42 +02:00
Aris Adamantiadis
6ffd38d25e Fix doublefree happening after a negociation error
Fix the cherry-pick merge
Conflicts:

	libssh/client.c
2010-04-14 21:14:32 +02:00
Aris Adamantiadis
250273cf1a Do not compile aes*-ctr with <=OpenSSL 0.9.7b 2010-04-14 21:11:29 +02:00
Aris Adamantiadis
bc15f7b7aa Fix missing string_data() in crypto debug code 2010-04-14 21:11:19 +02:00
Aris Adamantiadis
7c3040c624 First experiment at trying to make libssh c89 2010-04-07 13:20:30 +02:00
Andreas Schneider
c584b55488 Added the copyright policy to the README. 2010-04-07 11:29:47 +02:00
Ruben Garcia Azuara
5a2abd34ce Added support for StrictHostKeyChecking and UserKnownHostsFile parameters.
Added OpenSSH parameters to libssh:
  - StrictHostKeyChecking
  - UserKnownHostsFile

This parameters are useful to avoid checking the fingerprint. Eg:

~/.ssh/config:
    Host 192.10.20.30
    StrictHostKeyChecking no
    UserKnownHostsFile /dev/null

Signed-off-by: Ruben Garcia Azuara <rubenga@tid.es>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2010-04-07 11:29:47 +02:00
Ruben Garcia Azuara
14eb593af3 Fixed solaris compilation warning and ignore case at host parameter.
- Suppress compilation warning in solaris caused by a comma at the end of
    the last value.
  - Ignore case at host parameter in config file

Signed-off-by: Ruben Garcia Azuara <rubenga@tid.es>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2010-04-07 11:29:47 +02:00
Aris Adamantiadis
b2b7bc3b77 Fix building on win32/vs7 2010-04-06 23:24:25 +02:00
Andreas Schneider
fddbf1f94c Added a select(2) based poll-emulation if poll(2) is not available. 2010-04-04 17:38:50 +02:00
Andreas Schneider
5d5f6cc60c Fixed the group of the pcap functions. 2010-04-04 17:38:50 +02:00
Andreas Schneider
ae64c19f20 Fixed the group of the server functions. 2010-04-04 17:38:50 +02:00
Andreas Schneider
e5abc065aa Fixed the documentation of the scp functions. 2010-04-04 17:37:05 +02:00
Andreas Schneider
4ce265b105 Fixed the documentation of the SSH messages. 2010-04-04 17:37:05 +02:00
Andreas Schneider
154e99f2ba Fixed the documentation of channels.c. 2010-04-04 17:37:05 +02:00
Andreas Schneider
dab450be32 Fixed the doxygen group of the libssh c++ wrapper. 2010-04-04 17:37:05 +02:00
Andreas Schneider
a3db621899 Fixed documentation of socket functions. 2010-04-04 15:51:54 +02:00
Andreas Schneider
e26c6d20fe Fixed documenation of ssh_select(). 2010-04-04 15:51:54 +02:00
Andreas Schneider
a75a2bf533 Fixed documentation of dh functions. 2010-04-04 15:51:54 +02:00
Andreas Schneider
8dcfc3c94a Fixed the documentation of the client code. 2010-04-04 15:51:54 +02:00
Andreas Schneider
19c4027194 Fixed the group of the options. 2010-04-04 15:51:54 +02:00
Andreas Schneider
0efd50df26 Fixed the documentation of key functions. 2010-04-04 15:51:54 +02:00
Andreas Schneider
a127c8827a Fixed the documentation of log.c 2010-04-04 15:51:54 +02:00
Andreas Schneider
dcb5a81735 Fixed the documentation of misc.c 2010-04-04 15:51:54 +02:00
Andreas Schneider
4abdf47923 Fixed the documentation of error.c 2010-04-04 15:51:54 +02:00
Andreas Schneider
d39dce85b4 Fixed the documentation of buffer.c 2010-04-04 15:51:54 +02:00
Andreas Schneider
e736725d35 Fixed the documentation of auth.c 2010-04-04 15:51:54 +02:00
Andreas Schneider
d61a699543 Removed the unneeded dependency to doxygen. 2010-04-04 15:51:54 +02:00
Andreas Schneider
320b6c0cd8 Added an improved version of UseDoxygen.cmake which handles trac doc. 2010-04-04 14:10:10 +02:00
Andreas Schneider
7cf05075a0 Added a doxygen configuration for trac. 2010-04-04 14:10:00 +02:00
Andreas Schneider
3e0959fa1b Fixed config parsing wich has overwritten user specified values. 2010-04-04 14:03:44 +02:00
Andreas Schneider
d87b29b678 Fixed Check cmake module. 2010-03-29 23:20:59 +02:00
Andreas Schneider
2c16a3c0e8 Fixed ZLIB cmake module. 2010-03-29 23:20:43 +02:00
Andreas Schneider
dc3d9bb2ab Fixed GCrypt find module. 2010-03-29 23:20:22 +02:00
Andreas Schneider
fd4ed3909e Fixed OpenSSL find module. 2010-03-29 23:14:04 +02:00
Andreas Schneider
3f29a3d4fa Fixed a build warning in sftp. 2010-03-29 23:13:39 +02:00
Andreas Schneider
1a894b65d4 Fixed build warning in the sshd example. 2010-03-29 22:47:22 +02:00
Andreas Schneider
6e82193175 Fixed build warnings of the scp example. 2010-03-29 22:46:03 +02:00
Andreas Schneider
32ac1e04ec Fixed build warnings of the ssh client example. 2010-03-29 22:44:20 +02:00
Andreas Schneider
a47a9ecad1 Fixed build warnings in the knownhosts example. 2010-03-29 22:38:38 +02:00
Andreas Schneider
d07aef725e Fixed build warnings in the exec example. 2010-03-29 22:38:21 +02:00
Andreas Schneider
b5eb08ad09 Fixed the torture_keyfiles test. 2010-03-28 23:46:56 +02:00
Aris Adamantiadis
3ce7d7a28c Workaround for check linkage on ubuntu amd64 2010-03-28 23:17:13 +02:00
Aris Adamantiadis
9da13d4ff8 Fixes the broken algorithm choice for server 2010-03-28 21:59:11 +02:00
Aris Adamantiadis
7d49e49e74 Fix crash when no callback is defined 2010-03-28 21:58:59 +02:00
Andreas Schneider
0689304cff Fixed build warnings on Windows. 2010-03-25 16:48:30 +01:00
Andreas Schneider
8dd4972fda Fixed a build warning. 2010-03-25 15:30:56 +01:00
Andreas Schneider
51436cc3a3 Fixed a build warning in ssh_userauth_autopubkey. 2010-03-25 15:30:23 +01:00
Andreas Schneider
b168b8f03f Fixed a typo that we don't export all symbols. 2010-03-25 14:04:13 +01:00
Andreas Schneider
9e9e7e95ee Fixed spelling. 2010-03-25 13:46:09 +01:00
Andreas Schneider
c805f0cdcb Fix revision. 2010-03-25 13:42:30 +01:00
Andreas Schneider
e4bbba2b15 Added comments to the so version to increment it correctly in future. 2010-03-25 13:26:37 +01:00
Andreas Schneider
3a5af7fb61 Build examples only on the Linux plattform. 2010-03-17 10:12:03 +01:00
Andreas Schneider
34f2d50e29 Require check if testing is enabled. 2010-03-15 16:09:16 +01:00
Andreas Schneider
40d0ca7963 Added options for memcheck and coverage.
Disable it by default as only one machine should do this.
2010-03-15 16:09:05 +01:00
Andreas Schneider
095f348172 Added a ctest script for nightly builds. 2010-03-13 21:17:59 +01:00
Andreas Schneider
67c062e45e Added a valgrind suppression file to ignore check errors. 2010-03-13 17:10:53 +01:00
Andreas Schneider
4516e7bdcb Fixed a memory leak in the torture_get_user_home_dir test. 2010-03-13 16:59:26 +01:00
Andreas Schneider
90d72c214e Fixed the torture_pubkey_generate_from_privkey test. 2010-03-13 16:51:52 +01:00
Andreas Schneider
8fd6c8bc02 Fixed a memory leak in keyfile torture test. 2010-03-13 16:38:43 +01:00
Andreas Schneider
863cd6fcba Added a CTestConfig file to be able to submit to the dashboard. 2010-03-13 14:59:29 +01:00
Andreas Schneider
38fda265e8 Fixed a memory leak in ssh_try_publickey_from_file. 2010-03-13 14:59:02 +01:00
Andreas Schneider
72058bfbcc Added tests for ssh options. 2010-03-13 14:21:23 +01:00
Andreas Schneider
74e23a7fa2 Added missing SSH_OPTIONS_FD option. 2010-03-13 14:21:01 +01:00
Andreas Schneider
6372f671ed Remove support for SSHv1 Cipher variable. 2010-03-12 19:01:50 +01:00
Andreas Schneider
8501ca2ea0 Added some tests for ssh_list. 2010-03-06 12:55:56 +01:00
Andreas Schneider
1264557f0e Added a test for keyfiles.c. 2010-03-04 20:41:21 +01:00
Andreas Schneider
f34cd24f80 Fixed and added support for several identity files. 2010-03-04 20:41:17 +01:00
Andreas Schneider
9cd5e97596 Fixed linking of the tests. 2010-03-04 20:08:04 +01:00
Andreas Schneider
9f59be3224 Rename ssh_list_add to ssh_list_append. 2010-03-04 20:08:04 +01:00
Andreas Schneider
dea644bbd6 Added a prepend function for ssh_list. 2010-03-04 20:08:04 +01:00
Andreas Schneider
8bcb835aa4 Fixed unit testing. 2010-03-02 23:49:21 +01:00
Andreas Schneider
eec3532955 Simplify the build option output. 2010-03-02 23:37:49 +01:00
Andreas Schneider
8424c7a747 Fixed sftp_parse_longname() on Windows.
There is no strndup function on Windows.
2010-03-02 14:15:20 +01:00
Andreas Schneider
464176d511 Added unit testing support using check. 2010-03-02 13:54:14 +01:00
Aris Adamantiadis
e8a1d135e2 Fix a race condition bug in ssh_scp_close()
Conflicts:

	libssh/scp.c
2010-03-01 20:00:02 +01:00
Aris Adamantiadis
b707b5e2a4 Answer to openssh's keepalives 2010-03-01 18:54:52 +01:00
Aris Adamantiadis
c987fd8c53 renamed ssh_list_get_head to ssh_list_pop_head 2010-03-01 18:11:40 +01:00
Aris Adamantiadis
d083554dff Fixed documentation in scp code 2010-02-26 18:48:38 +01:00
Andreas Schneider
ec3af2c5cb Added printout of owner and group in the sftp example. 2010-02-24 00:27:02 +01:00
Andreas Schneider
f857d4aff7 Fixed longname parsing, this only workings with readdir. 2010-02-24 00:26:51 +01:00
Andreas Schneider
39d6ef884a Added owner and group information in sftp attributes.
Parse the longname which is the output of 'ls -l' and set the owner and
group if we are talking to an openssh server.
2010-02-23 22:50:43 +01:00
Andreas Schneider
492d1f24c8 Set CFLAGS correctly. 2010-02-13 12:47:28 +01:00
Aris Adamantiadis
60e5a32d27 Small doc fix 2010-02-12 23:29:24 +01:00
Aris Adamantiadis
f8d0055503 More C++ work 2010-02-12 22:17:50 +01:00
Aris Adamantiadis
8baaf64a72 Fix compilation of opensolaris 2010-02-12 10:08:54 +01:00
Andreas Schneider
6ae69e0df0 Try zlib compression and fallback to none if not available. 2010-02-11 23:27:25 +01:00
Aris Adamantiadis
92ca76721a More C++ wrapper work.
Wrote stubs of functions needed in the wrapper
Created an Exception class which greatly simplifies
the use of libssh in C++
2010-02-11 23:08:07 +01:00
Aris Adamantiadis
6af2e3fc10 Fix closesocket() portbug for win32 2010-02-11 22:42:28 +01:00
Aris Adamantiadis
9bec3ee48e Use closesocket in server.c for win32
Resolves #56
2010-02-11 19:56:23 +01:00
Aris Adamantiadis
17ca9d9da7 Make better error messages for SSH1 errors 2010-02-10 18:20:21 +01:00
Aris Adamantiadis
c1711243f0 aes192-ctr and aes256-ctr working on libcrypto 2010-02-09 22:29:43 +01:00
Aris Adamantiadis
fdfd12716e aes128-ctr aes192-ctr aes256-ctr for libgcrypt 2010-02-09 22:24:04 +01:00
Aris Adamantiadis
dc0d945f28 Added aes128-ctr support for libcrypto (openssl) 2010-02-09 21:21:11 +01:00
Aris Adamantiadis
96465a52ee KEX bug: client preference should be prioritary 2010-02-09 21:20:17 +01:00
Aris Adamantiadis
512fa6e601 Added summary of build options in Cmake 2010-02-08 16:55:03 +01:00
Andreas Schneider
12d43e2967 Rename the libssh sftp documentation group. 2010-02-07 22:36:03 +01:00
Andreas Schneider
e8648416b8 Describe the main group a bit. 2010-02-07 22:36:03 +01:00
Andreas Schneider
b971834d10 Respect known_hosts file set by the user.
Thanks to contact@leblanc-simon.eu for the patch.
2010-02-07 22:35:38 +01:00
Andreas Schneider
94ee9effe6 Improve the SSH string documentation. 2010-02-07 21:50:38 +01:00
Aris Adamantiadis
81bc13e066 Expend macros in doxygen generation 2010-02-06 23:49:41 +01:00
Andreas Schneider
1297da380e Improve the session documentation. 2010-02-05 18:34:39 +01:00
Andreas Schneider
4ee3b28ecb Update the doxygen config. 2010-02-05 18:34:13 +01:00
Andreas Schneider
757f8a6323 Set the soversion to 4.1 as we didn't break something.
yet?
2010-02-05 12:34:20 +01:00
Andreas Schneider
a25b06ecfc Increase version number. 2010-02-05 12:07:50 +01:00
Aris Adamantiadis
6b703b8d6a Update c++ prototypes 2010-02-02 18:30:26 +01:00
Aris Adamantiadis
c97d0d1220 add missing leave_function() 2010-02-02 18:20:23 +01:00
Aris Adamantiadis
7520d9c7b9 Handle timeout correctly 2010-02-02 18:16:46 +01:00
Vic Lee
2577214517 The ssh_message object needs to be freed after processing in channel_accept().
Signed-off-by: Vic Lee <llyzs@163.com>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2010-02-01 17:26:50 +01:00
Aris Adamantiadis
8e7bd43016 Fix compilation without WITH_SSH1 2010-01-30 20:36:00 +01:00
Aris Adamantiadis
e7b74c57f3 Hacked SSH1 to get past authentication
Also resolved some bugs that may impact 0.4. need to check
2010-01-25 23:23:01 +01:00
Aris Adamantiadis
cfdd4296a8 Fix poll not waking up on connect on win32
Under windows, poll does not detect connected socket using
POLLOUT but POLLWRNORM.
"Pending connect requests are indicated in the returned revents member of WSAPOLLFD structure by POLLWRNORM."
http://msdn.microsoft.com/en-us/library/ms741669%28VS.85%29.aspx
However, I did not test that fix. (no windows at hands). I also don't know
if the poll emulation layer works with that too.
2010-01-25 19:48:38 +01:00
Aris Adamantiadis
3407509ed7 Correctly handle channel failures and chan states 2010-01-24 23:03:56 +01:00
Aris Adamantiadis
3ac62dda51 Made packet handlers independant of session buffer 2010-01-24 22:43:52 +01:00
Aris Adamantiadis
3465b592e7 Few function name changes 2010-01-24 22:30:43 +01:00
Aris Adamantiadis
ca499a5495 Made ssh_packet_read asynchronous
Normally that's all that was needed into making SSH1 compliant
with the new API.
Beware, I have only implemented it, not actually tested it.
2010-01-24 22:27:44 +01:00
Aris Adamantiadis
8a1d832f80 Removed last calls to packet_read 2010-01-24 22:08:20 +01:00
Aris Adamantiadis
758df26582 Made parts of SSH asynchronous (inc kex1) 2010-01-24 21:03:03 +01:00
Aris Adamantiadis
6ae558b541 Beginning of async solution for SSH1 2010-01-24 01:07:08 +01:00
Aris Adamantiadis
68f53540df Move SSH-1 specific packet functions in packet1.c 2010-01-23 22:59:10 +01:00
Aris Adamantiadis
48ba9c9bc1 stub of C++ wrapper for libssh 2010-01-21 21:54:20 +01:00
Aris Adamantiadis
245deb2abe Fixed error message when connection failed 2010-01-16 18:47:32 +01:00
Aris Adamantiadis
549ea0d7ba Fix SSH1 related warning 2010-01-16 18:38:49 +01:00
Aris Adamantiadis
94d1112c55 SSH-1 cleanup and compile
Not tested, probably not working correctly yet
2010-01-10 21:05:46 +01:00
Aris Adamantiadis
0c47227144 Fix typo in build_make script 2010-01-10 20:07:37 +01:00
Aris Adamantiadis
a2505078da Set socket blocking after connexion 2010-01-08 23:28:55 +01:00
Aris Adamantiadis
35532a63fe Enforce NULL ptr verification in scp.c 2010-01-08 23:14:10 +01:00
Aris Adamantiadis
514ab6eed2 Fixed blocking bug in channel_poll 2010-01-08 23:05:10 +01:00
Aris Adamantiadis
c41e3a8e68 Cosmetics for packet numbering 2010-01-08 22:49:16 +01:00
Aris Adamantiadis
7d71340241 Oops, forgot the callback for server DH 2010-01-08 22:37:18 +01:00
Aris Adamantiadis
40bcc0bed8 No more packet_read2() ! 2010-01-08 22:33:58 +01:00
Aris Adamantiadis
74009e2be5 Prefix message_new with ssh_ 2010-01-08 22:28:40 +01:00
Aris Adamantiadis
40871ab1cc Prefix message_handle_channel_request with ssh_ 2010-01-08 22:27:16 +01:00
Aris Adamantiadis
2fc4c7e335 Dequeue the processed messages 2010-01-08 22:25:26 +01:00
Aris Adamantiadis
da8263b3f6 Renamed message_queue to ssh_message_queue 2010-01-08 22:16:00 +01:00
Aris Adamantiadis
12db7c4bc1 Merged the channel_request hdlrs and clean hdlrs 2010-01-08 22:14:31 +01:00
Aris Adamantiadis
db3ef37771 ssh_packet_userauth_request with new system 2010-01-08 21:09:40 +01:00
Aris Adamantiadis
7f32558e08 Converted message handlers to new system 2010-01-07 22:41:38 +01:00
Aris Adamantiadis
228ac78397 Changes to messages for async message handling 2010-01-07 22:02:21 +01:00
Aris Adamantiadis
b6656a1525 Removed packet_wait for SSH2 2010-01-06 22:53:10 +01:00
Aris Adamantiadis
84ec17964e Made the server DH asynchronous.
It still needs testing and cleanup, it was done with less
care than the client-side.
The socket listening and connexion is still synchronous
2010-01-06 22:49:40 +01:00
Aris Adamantiadis
ef5dc6cd2b Add support for async global requests
Normally the infamous packet_wait() synchronous call
is gone in all SSH2 client code.
2010-01-06 21:48:44 +01:00
Aris Adamantiadis
84e6aca5c5 Fixed typos from a* to error.c 2010-01-06 21:12:00 +01:00
Aris Adamantiadis
ebd0987376 Fix build when WITH_SSH1 undefined 2010-01-06 13:34:56 +01:00
Aris Adamantiadis
20baf4f5b6 Part of kex.c is SSH-1 specific 2010-01-03 23:38:37 +01:00
Aris Adamantiadis
335a0fe768 Remove some references to packet_wait() 2010-01-03 23:36:06 +01:00
Aris Adamantiadis
b25ebf4bdb Removed channel_handle now unused function 2010-01-03 23:23:56 +01:00
Aris Adamantiadis
804bb44eda Channel requests are asynchronous
Exec example also runs perfectly now.
2010-01-03 23:16:14 +01:00
Aris Adamantiadis
1b15896e8b Fix infinite loop in exec example 2010-01-03 23:15:55 +01:00
Aris Adamantiadis
055fbe1d87 Explicitely use the packet buffer arg in channels 2010-01-03 22:34:48 +01:00
Aris Adamantiadis
648e5d62ba Some work for async channel requests 2010-01-03 22:14:21 +01:00
Andreas Schneider
49de20aa5c Fixed cmake warning.
There is no CMakeLists.txt in tests and we don't build something
in the root CMakeLists.txt.
2009-12-30 19:08:03 +01:00
Vic Lee
13d534e89a Add pkg-config file libssh.pc
Signed-off-by: Vic Lee <llyzs@163.com>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-12-30 19:05:48 +01:00
Vic Lee
1944dc8b5f Add new API function ssh_userauth_privatekey_file().
Signed-off-by: Vic Lee <llyzs@163.com>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-12-30 19:05:37 +01:00
Vic Lee
f2ca2d50b5 In ssh_userauth_pubkey, if publickey argument is NULL, generate it from privatekey.
Signed-off-by: Vic Lee <llyzs@163.com>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-12-30 19:05:29 +01:00
Aris Adamantiadis
b361fb5898 Fix use-without-initialization 2009-12-28 22:29:50 +01:00
Aris Adamantiadis
8d1faa0dbc Made channel_open_session partially asynchronous 2009-12-27 00:06:34 +01:00
Aris Adamantiadis
77baa2df15 Fix a few log strings and levels in auth.c 2009-12-26 22:12:08 +01:00
Aris Adamantiadis
a229cb4676 Asynchronous authentication works ! 2009-12-26 21:59:37 +01:00
Aris Adamantiadis
682ed18123 New packet handler for SSH_USERAUTH_BANNER 2009-12-26 20:24:07 +01:00
Aris Adamantiadis
3aae59c224 Fix tricky bug within packet decoding 2009-12-26 17:03:27 +01:00
Aris Adamantiadis
6f3505bf6b Asynchronous service request 2009-12-26 16:51:33 +01:00
Aris Adamantiadis
bfdc48e320 Simplification of the "exec" sample 2009-12-24 10:46:46 +01:00
Vic Lee
fcda8beb1c File handle need to be closed in case of errors in privatekey_from_file
Signed-off-by: Vic Lee <llyzs@163.com>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-12-23 09:37:35 +01:00
Andreas Schneider
d0647afae5 Added an example for exec. 2009-12-22 18:34:23 +01:00
Aris Adamantiadis
a6383cec51 Fix typos in doc 2009-12-22 10:20:19 +01:00
Vic Lee
44fd5ff451 Added private key type detection feature in privatekey_from_file
Signed-off-by: Vic Lee <llyzs@163.com>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-12-22 09:02:10 +01:00
Andreas Schneider
ea34f37d43 Generate the APPLICATION_VERSION. 2009-12-21 15:56:21 +01:00
Andreas Schneider
23dcc2c7f3 Fixed ssh_get_user_home_dir() to be thread safe. 2009-12-21 12:32:58 +01:00
Aris Adamantiadis
91f7d127ea Tutorial doxyginized and updated up to auth sect. 2009-12-20 23:21:59 +01:00
Aris Adamantiadis
43c1245396 Some options functions did not show up in doxygen 2009-12-20 20:23:58 +01:00
Aris Adamantiadis
43288bc4f2 added ssh_message_auth_reply_pk_ok_simple 2009-12-20 18:51:37 +01:00
Aris Adamantiadis
2e22d6ef99 Add key validation in server side authentication 2009-12-20 18:05:02 +01:00
Andreas Schneider
6509b6e742 Started to add the tutorial to doxygen. 2009-12-19 00:31:47 +01:00
Aris Adamantiadis
d2ce0042b3 Deleted obsolete doxygen files 2009-12-19 00:10:54 +01:00
Aris Adamantiadis
0dcb63ff5e Merge branch 'master' of git://git.libssh.org/projects/libssh/libssh 2009-12-19 00:10:13 +01:00
Andreas Schneider
bebbac1bd8 Improved doxygen output of ssh_options_set(). 2009-12-19 00:08:54 +01:00
Aris Adamantiadis
a1870a62cf Documentation callbacks.h + standardization 2009-12-18 23:56:59 +01:00
Andreas Schneider
1ef1a77421 Disabled caller graphs as they are only of internal interest. 2009-12-18 23:54:31 +01:00
Andreas Schneider
98819f92e3 Updated the doxygen file. 2009-12-18 23:41:25 +01:00
Andreas Schneider
ebce70eba1 Fixed documentation of buffer struct. 2009-12-18 23:41:01 +01:00
Andreas Schneider
ed257b982a Fixed documentation of ssh_options_copy(). 2009-12-18 23:38:27 +01:00
Andreas Schneider
1b7877f6ed Moved the doxygen mainpage to doc/mainpage.dox 2009-12-18 23:35:41 +01:00
Andreas Schneider
7500b0564c Document the callback structure correctly. 2009-12-18 23:19:37 +01:00
Andreas Schneider
0c992ece3b Added a mainpage to doxygen. 2009-12-18 23:12:47 +01:00
Andreas Schneider
e124249a8b Fixed the doxygen documentation. 2009-12-18 23:12:37 +01:00
Aris Adamantiadis
d950d6af52 Optional compilation of developper's doc 2009-12-16 23:19:18 +01:00
Aris Adamantiadis
55abcfeef6 These docs are outdated too 2009-12-15 23:53:28 +01:00
Aris Adamantiadis
49b3712891 Stub for doxygen main documentation 2009-12-15 23:50:16 +01:00
Aris Adamantiadis
b9a8b22728 Doxygen now outputs on stderr, inputs from doc/ 2009-12-15 23:48:51 +01:00
Aris Adamantiadis
65f8e86e41 Deleted obsolete documentation draft 2009-12-15 23:37:53 +01:00
Aris Adamantiadis
9780f22866 Made packet_wait issue warnings 2009-12-13 20:49:47 +01:00
Aris Adamantiadis
46b2b99f63 Fix strange error message in sample authentication 2009-12-13 19:53:32 +01:00
Aris Adamantiadis
c92f54102e Key exchange currently done asynchronously
Fixed an important bug in packet buffering (two packets received in the same recv would'nt be processed correctly)
2009-12-13 18:20:05 +01:00
Aris Adamantiadis
964d5f88cc ssh_poll_handle detaches from context before free 2009-12-13 17:04:23 +01:00
Aris Adamantiadis
ad7e9d88fb packet SSH_KEXINIT received and parsed
Resolved some bugs in the callback mechanism as well
2009-12-12 00:23:53 +01:00
Aris Adamantiadis
3ace7817b4 Async connection + banner fetch is working 2009-12-11 23:26:25 +01:00
Aris Adamantiadis
0de35ca8f0 Fix logging problem in match_known_host 2009-12-11 21:23:52 +01:00
Aris Adamantiadis
80b6cf77b0 Added a global poll context 2009-12-11 21:11:23 +01:00
Andreas Schneider
79b4bf4ac2 Don't install crypto.h which is an internal header file. 2009-12-10 13:55:42 +01:00
Aris Adamantiadis
ab6b510408 More doxygen stuff 2009-12-09 20:27:10 +01:00
Aris Adamantiadis
ab52ca01ad Resolving doxygen errors in internal mode 2009-12-09 19:53:58 +01:00
Aris Adamantiadis
64b72f8d3a Fix some doxygen errors 2009-12-09 19:43:16 +01:00
Andreas Schneider
ffc9806e6d Remove socklen_t definition.
Tthe problem is that winsock2.h defines socklen_t as a typedef, not as a
define, so depending on the order of includes you can get errors in
ws2tcpip.h with msvc.
2009-12-09 13:02:48 +01:00
Aris Adamantiadis
984fb41b98 Moved #defines into an enum 2009-12-06 23:47:58 +01:00
Aris Adamantiadis
a1e05c62ae struct socket -> struct ssh_socket_struct +typedef 2009-12-06 22:48:56 +01:00
Aris Adamantiadis
076e884873 More callback stuff in connection
I have coded it, not actually tested it :) It still needs
work to get past the banner exchange.
2009-12-05 15:05:02 +01:00
Aris Adamantiadis
2f6fbbd706 Trying to adapt client.c to use callbacks 2009-12-03 23:55:46 +01:00
Aris Adamantiadis
4924ac8099 Asynchronous sockets work !
Still need a bit of tuning but it's stable enough
for our current needs
2009-12-01 23:34:55 +01:00
Andreas Schneider
7962029bdc Fixed indent. 2009-12-01 16:59:41 +01:00
Andreas Schneider
f83f837de7 Added gettimeofday for Windows.
Thanks to Patrick Spendrin.
2009-12-01 16:57:49 +01:00
Andreas Schneider
48b719cf68 Fixed uint* to work on Windows.
Thanks to Patrick Spendrin.
2009-12-01 16:15:54 +01:00
Aris Adamantiadis
96afa4530c More logging 2009-11-30 23:56:21 +01:00
Aris Adamantiadis
270a8a26fa Fix stupid bug which stops log_verbosity working 2009-11-30 23:55:02 +01:00
Aris Adamantiadis
92a50f731c Socket connect callback working...
Still need to make sure the connect syscall is correctly
called
2009-11-30 23:44:40 +01:00
Aris Adamantiadis
76d6838223 Some brain surgery to add event-based sockets
chapter 1- SSH Socket Connections.
I would like to be able to
-Have a ssh_poll_ctx object
-Add a ssh socket over it
-launch the socket connection (using socket functions)
-ssh_poll_ctx_dopoll()
-Wait for the timeout or have the "connected" callback called
2009-11-30 22:35:43 +01:00
Aris Adamantiadis
0bfb9d476c Standardize callbacks style and add documentation 2009-11-29 22:51:14 +01:00
Aris Adamantiadis
91bb1b2de6 Squashed commit of the following:
commit 43fad8dfd977637c31fade76ace2905f6528c3bc
Author: Aris Adamantiadis <aris@0xbadc0de.be>
Date:   Fri Nov 27 18:39:06 2009 +0100

    adaptation to the new ssh_poll_handle object name

commit 1e5e6ac4605adf10d437d04f0fd4b7e66024853c
Merge: 3fd92a0... 810adad...
Author: Aris Adamantiadis <aris@0xbadc0de.be>
Date:   Fri Nov 27 18:33:06 2009 +0100

    Merge branch 'master' into badcode/libssh_async

commit 3fd92a08eb74b1447a9ff4ca4e1d137475c62cc6
Author: Aris Adamantiadis <aris@0xbadc0de.be>
Date:   Mon Nov 2 14:25:46 2009 +0100

    Compiles again

commit 8910d7b9692418c9ccea0234f6d49674d238dc16
Merge: e83f1b5... cce34a6...
Author: Aris Adamantiadis <aris@0xbadc0de.be>
Date:   Mon Nov 2 12:47:34 2009 +0100

    Merge branch 'master' into libssh_async

    Very big merge !

    Conflicts:
    	include/libssh/callbacks.h
    	include/libssh/priv.h
    	libssh/channels.c
    	libssh/messages.c
    	libssh/packet.c
    	libssh/server.c
    	libssh/session.c
    	libssh/socket.c

commit e83f1b593219e183082b015315f09bfe95a29cfc
Author: Aris Adamantiadis <aris@0xbadc0de.be>
Date:   Mon Nov 2 12:07:01 2009 +0100

    rename callback.h

commit dffa7b730e8f39e2198de18ab69a8e57bef95e58
Merge: 5a8b748... de8808c...
Author: Aris Adamantiadis <aris@0xbadc0de.be>
Date:   Tue Sep 15 10:50:07 2009 +0200

    Merge branch 'master' of git://git.libssh.org/projects/libssh/libssh into libssh_async

commit 5a8b7484f36599d28f2c0c14a23b76bfc7257638
Author: Aris Adamantiadis <aris@0xbadc0de.be>
Date:   Sun Sep 13 12:55:18 2009 +0200

    More updates to callback system

commit 18620c20d5e4e62107093f7fd330e553493253fa
Author: Aris Adamantiadis <aris@0xbadc0de.be>
Date:   Sat Sep 12 22:26:52 2009 +0200

    Same thing with channel_rcv_data

commit fc4a56f6726e409a5866272923f1cbebfc821af3
Author: Aris Adamantiadis <aris@0xbadc0de.be>
Date:   Sat Sep 12 22:17:45 2009 +0200

    added a few packet handlers for channels

commit 4b6bb4fd00b10cf1321a764126f277ab204bffe3
Author: Aris Adamantiadis <aris@0xbadc0de.be>
Date:   Fri Sep 11 23:15:25 2009 +0300

    sample packet handlers + bugfixes

commit 2784d09d6dec0a8f868912d14f90d860233b3f82
Author: Aris Adamantiadis <aris@0xbadc0de.be>
Date:   Fri Sep 11 20:30:50 2009 +0300

    Packet callbacks nearly finished

    Need tests and implementation of some packet callbacks

commit cd3ea43f20c9ae2f54576ca98a0ea75c5d4299d3
Author: Aris Adamantiadis <aris@0xbadc0de.be>
Date:   Thu Sep 10 12:46:02 2009 +0300

    First step of async packet handling

    The socket to packet handler is nearly done (needs testing)
    I still need to define the interface for callbacks.

commit 487f4d2a900a5fe3b90ceda4460ab7d38d7ad722
Author: Aris Adamantiadis <aris@0xbadc0de.be>
Date:   Tue Sep 8 23:24:09 2009 +0300

    Almost complete socket callback system

    Finished the callback function so it bufferizes data when
    callee does not use it.
    Flushes the buffer automaticaly after a ssh_socket_nonblocking_flush

commit 23571f22fac9e40c855dfa99569bba181a39648b
Author: Aris Adamantiadis <aris@0xbadc0de.be>
Date:   Tue Sep 8 22:22:32 2009 +0300

    First draft of a callback system
2009-11-27 20:42:43 +01:00
Aris Adamantiadis
810adadf2e Compile with pcap support by default
This will permit to get pcap debugging out of the box
2009-11-27 18:18:12 +01:00
Aris Adamantiadis
8da712ea61 Compile in stub for pcap funcs when pcap disabled
Avoid that way linking problems
2009-11-27 18:16:10 +01:00
Aris Adamantiadis
56cfb8036f Build the pcap code into example in all cases 2009-11-27 18:08:53 +01:00
Andreas Schneider
f332dd810e Added changelog entries for 0.4 rc2. 2009-11-20 16:11:17 +01:00
Andreas Schneider
d1c6fa9261 Build the pcap source only if enabled. 2009-11-19 09:33:06 +01:00
Aris Adamantiadis
b00e2ad40e Fix compile bug introduced by another bugfix 2009-11-18 20:54:39 +01:00
Aris Adamantiadis
ca9f42a20f Fix another memleak
Use buffer_free instead of SAFE_FREE
2009-11-18 20:53:06 +01:00
Andreas Schneider
e939786836 Fixed possible doulbe free problem found by Bernhard R. Link. 2009-11-18 15:35:15 +01:00
Andreas Schneider
11cc5f5815 Added more error messages and checking to handle_channel_request. 2009-11-18 14:56:12 +01:00
Andreas Schneider
d60b1ec1a2 Fixed a memory leak in channel_new() if we have an error. 2009-11-18 10:30:01 +01:00
Aris Adamantiadis
ae11589205 Pcap: more cleanup and minimalist API 2009-11-16 23:20:16 +01:00
Aris Adamantiadis
70b9475449 Pcap: Fix bug with non-encrypted incoming packets 2009-11-16 22:53:22 +01:00
Aris Adamantiadis
02aecc1278 Improved pcap dumping support 2009-11-16 22:36:31 +01:00
Andreas Schneider
3e90a11599 Improve standard logging. 2009-11-12 12:52:05 +01:00
Andreas Schneider
b4095189d7 Fixed setting the timeout and ssh2 and ssh1 option. 2009-11-12 12:50:31 +01:00
Andreas Schneider
c0b4c4d60c Fixed setting the log verbosity. 2009-11-12 11:44:36 +01:00
Andreas Schneider
12da24c056 Added an option to set log verbosity as string. 2009-11-10 09:12:07 +01:00
Andreas Schneider
d821117033 Always use the poll-emulation on Windows.
Until we we have a solution to use WSAPoll only on Vista and newer.
2009-11-09 20:13:27 +01:00
Aris Adamantiadis
30266f7627 Added explanation in ssh_silent_disconnect doxygen 2009-11-09 13:24:47 +01:00
Aris Adamantiadis
10b625e180 First lines of experimental pcap output support
This will serve to debug packets right under wireshark !
2009-11-08 23:42:41 +01:00
Aris Adamantiadis
10f27457d3 Add an other (simplier ?) polling method to sample 2009-11-08 20:00:23 +01:00
Aris Adamantiadis
af1f431364 change buffer size in sample.c 2009-11-07 17:35:24 +01:00
Aris Adamantiadis
272a4d1e45 Refactorize sample.c 2009-11-07 17:23:06 +01:00
Aris Adamantiadis
3a95ecfe74 move authentication out of sampe.c 2009-11-07 03:45:27 +01:00
Aris Adamantiadis
14ae9a7f0c Moved sftp parts into a new example 2009-11-06 19:21:18 +01:00
Aris Adamantiadis
51f1918109 Update structures name to new convention
SSH_POLL* -> ssh_poll_handle,
SSH_POLL_CTX* -> ssh_poll_ctx
2009-11-06 18:52:49 +01:00
Andreas Schneider
fa27956daf Improve MSVC support. Better binary compatibility.
Patch by Patrick Spendrin from KDE.
2009-11-06 09:57:09 +01:00
Aris Adamantiadis
ab0d8a3828 A few test cases for benchmarks 2009-11-05 18:18:35 +01:00
Andreas Schneider
efded18724 Fixed compilation of samplesshd. 2009-11-05 16:38:05 +01:00
Andreas Schneider
f52bc064e9 Merge branch 'master' of git://git.libssh.org/projects/libssh/libssh 2009-11-05 16:08:49 +01:00
Aris Adamantiadis
75f066dfcd channel_read() won't block until count b. are read 2009-11-05 16:00:05 +01:00
Aris Adamantiadis
535ff07f0f Forgot to update config.h.cmake 2009-11-05 13:09:42 +01:00
Aris Adamantiadis
5e002635fc Fix compilation on freebsd 6.0 which lacks argp.h 2009-11-03 21:04:36 +01:00
Aris Adamantiadis
e71c28f6a0 Fix warnings on old gcc's
they don't like variable names having type names
2009-11-03 21:04:07 +01:00
Aris Adamantiadis
c0e091a52f Fix openssl header inclusion
caused cbc_encrypt to be redefined by an openssl
macro
2009-11-03 21:03:22 +01:00
Andreas Schneider
8ab0f8e51f Increase package version. 2009-10-29 20:22:05 +01:00
Andreas Schneider
cce34a6176 Fixed setting knownhosts in ssh_is_server_known(). 2009-10-29 12:10:44 +01:00
Andreas Schneider
89f0311927 Fixed a segfault on Windows. 2009-10-29 12:10:22 +01:00
Aris Adamantiadis
e455f6f756 Make libssh_scp a little more consistant 2009-10-29 10:50:47 +01:00
Aris Adamantiadis
17f2645a32 Fix server kex again 2009-10-29 10:36:00 +01:00
Aris Adamantiadis
9f034aca9c Fix server kex 2009-10-29 10:02:49 +01:00
Bernhard R. Link
22bdfa3886 improve error reporting of sftp.c
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-10-25 11:12:02 +01:00
Bernhard R. Link
ef8246a592 buffer_get_data returns 0 on error, so checking buffer_get_u* for < 0 makes no sense
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-10-25 09:50:06 +01:00
Aris Adamantiadis
110d201e02 fix stupid bug 2009-10-23 12:48:40 +02:00
Aris Adamantiadis
be4f695c5c Compatibility with (broken) sftp version 2 protocols 2009-10-23 12:19:22 +02:00
Andreas Schneider
792def7a65 Add missing free. 2009-10-23 11:45:44 +02:00
Andreas Schneider
840cecbe0e Fix memory leaks in ssh_bind_options_set() if called twice.
This fixes ticket #36.
2009-10-22 18:56:02 +02:00
Aris Adamantiadis
27d25752e9 Allow use of SSH_DIR/ when expanding key paths 2009-10-17 18:10:42 +02:00
Aris Adamantiadis
a479b30298 Verify existence of callback before using them 2009-10-17 17:54:39 +02:00
Andreas Schneider
86620fc991 Improve example authentication. 2009-10-15 17:56:03 +02:00
Andreas Schneider
b3dfd5cffc Added missing documentation for ssh_bind_options_set. 2009-10-15 17:22:04 +02:00
Andreas Schneider
f0858ff6b2 Added option parsing using GNU argp. 2009-10-15 17:17:58 +02:00
Andreas Schneider
7b7280e728 Added option to set log_verbosity in the server. 2009-10-15 17:17:36 +02:00
Andreas Schneider
2523ed0779 Added an option to set the port as string. 2009-10-15 17:02:51 +02:00
Andreas Schneider
e736b1a40e Fixed ssh_get_user_home_dir on Windows. 2009-10-15 16:37:07 +02:00
Andreas Schneider
cbf012c337 Fixed ssh_get_home_dir and ssh dir to be more portable on UNIX systems.
Thanks to Pino Toscano.
2009-10-15 14:53:11 +02:00
Andreas Schneider
c360ed1d9a Add API changes to README. 2009-10-13 22:23:06 +02:00
Andreas Schneider
22e74e3bab Remove deprecated functions. 2009-10-13 22:14:23 +02:00
Vic Lee
02b3104215 Fix a memory corruption in parse_status_msg
Signed-off-by: Vic Lee <llyzs@163.com>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-10-11 11:11:08 +02:00
Aris Adamantiadis
26a5294116 add logging 2009-10-11 00:20:37 +02:00
Aris Adamantiadis
5e4c78e114 Fix server. Now, it runs 2009-10-11 00:14:21 +02:00
Aris Adamantiadis
e74305c5eb updated the sftp subsystem to follow the type conv 2009-10-10 20:55:17 +02:00
Aris Adamantiadis
499f9aa707 Add structure cleaning in comment 2009-10-10 20:07:52 +02:00
Andreas Schneider
4dee9a3e68 Document the function to set the callbacks and provide an example. 2009-10-10 19:59:14 +02:00
Aris Adamantiadis
399041180f resolve callback crash 2009-10-10 16:25:40 +02:00
Aris Adamantiadis
3f55fb5b22 fix typo in header inclusion 2009-10-10 12:04:35 +02:00
Aris Adamantiadis
37a4a65d60 Add ssh_free at the end 2009-10-10 12:04:16 +02:00
Andreas Schneider
ccd886feb4 Added auth callback function to sample to test callback stuff. 2009-10-10 11:55:42 +02:00
Andreas Schneider
b1bc283e9a Rename callback header file. 2009-10-10 10:52:04 +02:00
Andreas Schneider
be75fac7ff Add a function to set the callback structure to the session. 2009-10-10 10:51:56 +02:00
Aris Adamantiadis
6ec65c6f9d ssh_disconnect doesn't free the session anymore 2009-10-09 22:50:48 +02:00
Aris Adamantiadis
71ab0cf6cc No more SSH_BIND SSH_MESSAGE etc. 2009-10-09 22:37:23 +02:00
Aris Adamantiadis
1e0e8a5493 samplessh uses ssh_options_getopt() 2009-10-09 22:28:03 +02:00
Aris Adamantiadis
4b65aea401 Last nail on SSH_OPTIONS, SSH_SESSION etc. 2009-10-09 22:26:08 +02:00
Aris Adamantiadis
98ff6fbbce get rid of the option structure 2009-10-09 22:24:23 +02:00
Aris Adamantiadis
43e0d73b63 sample.c compiles now 2009-10-09 22:04:56 +02:00
Aris Adamantiadis
58294442d3 Moved samples into examples directory 2009-10-09 21:44:05 +02:00
Aris Adamantiadis
2e9c13dad0 Modified server API 2009-10-09 21:26:15 +02:00
Andreas Schneider
9c667ebc26 Remove functions to set callbacks. 2009-10-09 15:18:06 +02:00
Andreas Schneider
d1b772f1bc Added more error messages to config parser. 2009-10-06 15:49:47 +02:00
Andreas Schneider
876f843f23 Update ChangeLog. 2009-10-06 15:44:12 +02:00
Andreas Schneider
0e2e0983f3 Fixed build temporarily. 2009-10-05 10:41:00 +02:00
Vic Lee
6063a8d09c Fix a segment fault in privatekey_from_file
Signed-off-by: Vic Lee <llyzs@163.com>
2009-10-05 10:02:04 +02:00
Aris Adamantiadis
40778d4ba9 Merge branch 'master' of git://git.libssh.org/projects/libssh/libssh 2009-10-05 10:01:24 +02:00
Bernhard R. Link
60d6954b75 samplesshd: allow overriding KEYS_FOLDER by compiler option
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-10-05 00:05:09 +02:00
Bernhard R. Link
bf376b6d4f do not segfault in ssh_bind_accept if bindaddr is NULL
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-10-05 00:04:38 +02:00
Bernhard R. Link
ff52e3630f improve error handling in options.c
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-10-05 00:04:02 +02:00
Andreas Schneider
f1f17f18dc Fix documentation. 2009-10-05 00:03:47 +02:00
Bernhard R. Link
7c759b9615 add ssh_set_error_oom and ssh_set_error_invalid
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-10-05 00:02:43 +02:00
Bernhard R. Link
d54e9550da proper prototype of ssh_session_new
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-10-05 00:01:50 +02:00
Andreas Schneider
d7c0270c89 Fixed SSHv1 to work with the option changes. 2009-10-04 11:47:26 +02:00
Andreas Schneider
7a37f9faf7 Fixed ssh_options_copy(). 2009-10-04 10:10:19 +02:00
Aris Adamantiadis
149a2b4a18 Temporary server fixup for options structure delet
server_set_kex needs to be rewritten
2009-10-03 23:06:26 +02:00
Andreas Schneider
ab5b4c7cfe Get rid of the options structure. 2009-10-02 20:26:14 +02:00
Andreas Schneider
e78334688f Fixed setting of LFS CFLAGS. 2009-10-02 20:19:48 +02:00
Andreas Schneider
566fda70a5 Fixed LFS support on unix. 2009-10-02 20:17:21 +02:00
Andreas Schneider
62cebe23d9 Fixed build of sample client. 2009-10-02 17:21:59 +02:00
Andreas Schneider
42aacc7106 Remove unused option functions. 2009-10-02 10:18:27 +02:00
Andreas Schneider
8ed9cdce80 Remove --as-needed linker flag. 2009-10-01 10:19:07 +02:00
Aris Adamantiadis
a3a7f17d0f Missed copying of log verbosity 2009-09-30 13:10:59 +02:00
Aris Adamantiadis
571dd56eca libcrypto.so is in /lib on opensolaris 2009-09-29 17:57:37 +02:00
Aris Adamantiadis
f6f0988d10 Fix warnings on opensolaris 2009-09-29 17:57:37 +02:00
Aris Adamantiadis
f9d1542542 resolve warning on opensolaris 2009-09-29 11:46:06 +02:00
Aris Adamantiadis
d32fe11da3 Fix build with SSH1 2009-09-28 10:28:52 +02:00
Aris Adamantiadis
cd7f6bea57 more priv.h splitting 2009-09-26 14:05:58 +02:00
Aris Adamantiadis
c3dc60103f Fix small bug in ssh_options_parse_config 2009-09-26 12:42:47 +02:00
Aris Adamantiadis
2a2616f65c Fix bug in dir_expand_sub 2009-09-26 12:28:03 +02:00
Bernhard R. Link
f643c34ee8 support in ~/ and SSH_DIR/ in filenames instead of %s/
Get rid of snprintf to fixed sized buffers in setting options.
Instead make locations starting with ~/ relative to the
users initial working directory (as libssh does not look into
the home directory but only at the initial home directory).
and starting with SSH_DIR/ relative to the configured ssh directory.
2009-09-26 12:23:30 +02:00
Aris Adamantiadis
0f77578ee2 Fixed doxygen compilation warnings 2009-09-26 01:34:14 +02:00
Aris Adamantiadis
3e314e863c More include file splitting 2009-09-26 01:15:48 +02:00
Aris Adamantiadis
adbb087221 Removed obsolete options 2009-09-26 00:36:02 +02:00
Aris Adamantiadis
3a8d839e86 More include file movings 2009-09-26 00:29:53 +02:00
Aris Adamantiadis
358647f5d9 More comment 2009-09-25 23:56:28 +02:00
Aris Adamantiadis
5e76118512 fix ssh_callbacks_init() macro + documentation
ssh_callbacks_init should not zero' the struct because
it could be used on staticaly declared structures
2009-09-25 23:50:18 +02:00
Aris Adamantiadis
e3bdc393cb callback.h should use public headers 2009-09-25 23:42:29 +02:00
Aris Adamantiadis
04b49d46c1 Fixed building with Gcrypt and arith with void* 2009-09-25 23:38:09 +02:00
Aris Adamantiadis
74b7fb7bba Add an option to let users choose libgcrypt 2009-09-25 23:31:48 +02:00
Aris Adamantiadis
c70694c594 Fix memory leaks found by tysonite 2009-09-25 18:49:26 +02:00
Aris Adamantiadis
fef87793a0 Fix openssl version usage, found by tysonite 2009-09-25 18:34:58 +02:00
Andreas Schneider
79c475c917 Fixed including of config.h.
If there is some option to modify libc behaviour (like if there was some
off_t usage to be modified by some flag to make that 64 bit) that
needs to be done before the first libc header. one could still do -D
there, though (unless cmake wants to do something automatically and puts
that in config.h)
2009-09-25 10:01:56 +02:00
Andreas Schneider
3dd03fec21 Add missing extern C. 2009-09-25 09:59:25 +02:00
Andreas Schneider
e8e07f7376 Fix typo. 2009-09-25 09:37:56 +02:00
Andreas Schneider
1c5ae7dd97 Install callbacks header file. 2009-09-25 09:33:11 +02:00
Andreas Schneider
f65e3566a2 Fixed typo in config.h.cmake.
This closes ticket #24.
2009-09-24 13:22:43 +02:00
Aris Adamantiadis
6b0a89a288 Get rid of CRYPTO 2009-09-23 23:55:07 +02:00
Aris Adamantiadis
f84ebc2e27 Moved lots of declaration out of priv.h 2009-09-23 23:51:04 +02:00
Aris Adamantiadis
b359229a2e Change #defines to enums when it makes sense 2009-09-23 22:42:29 +02:00
Aris Adamantiadis
496a8e12d9 Get rid of SSH_MESSAGE 2009-09-23 22:19:11 +02:00
Aris Adamantiadis
0e8e124d20 get rid of SSH_OPTIONS 2009-09-23 22:13:19 +02:00
Aris Adamantiadis
9a8d4cd0fd get rid of SSH_SESSION 2009-09-23 21:55:54 +02:00
Aris Adamantiadis
ffed8b03bb remove the broken setters for options,cb init macro 2009-09-23 21:40:58 +02:00
Aris Adamantiadis
5bd38a5f37 Changed the current callback sys to be scalable 2009-09-23 21:30:56 +02:00
Aris Adamantiadis
ab60d1d678 Ordered functions in libssh.h alphabeticaly 2009-09-23 20:42:59 +02:00
Aris Adamantiadis
5223fa5740 Shut up warning in libssh_scp 2009-09-23 11:43:06 +02:00
Aris Adamantiadis
95558d54b0 Fix typos in SSH_OPTIONS 2009-09-23 11:21:12 +02:00
Andreas Schneider
068a7dfc49 Fixed bindport in getop function. 2009-09-22 20:36:57 +02:00
Andreas Schneider
abd8b17a04 Fixed options used in server sample. 2009-09-22 20:34:23 +02:00
Andreas Schneider
343e6e482a Added handling of bindport in getopt. 2009-09-22 20:33:58 +02:00
Andreas Schneider
aae1df0589 Use new options interface in sample code. 2009-09-22 20:27:53 +02:00
Aris Adamantiadis
0a57ebb3a9 Fix README file which is really obsolete 2009-09-22 16:51:28 +02:00
Bernhard R. Link
9afad28255 fix copy&paste error
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-09-22 14:04:42 +02:00
Andreas Schneider
8b21b51a78 Use new ssh options interface in auth functions. 2009-09-22 13:32:06 +02:00
Andreas Schneider
2003a81b44 Use new ssh options interface in keyfiles. 2009-09-22 13:20:23 +02:00
Andreas Schneider
abe6c7c728 Use new options interface in server code. 2009-09-22 13:17:35 +02:00
Andreas Schneider
f78045dfd3 Use the new options interface in config parser. 2009-09-22 13:14:23 +02:00
Andreas Schneider
39729bd3de Use the new options function in deprecated functions. 2009-09-22 13:14:23 +02:00
Andreas Schneider
f6d2a66de2 Added a cleaned up interface for setting options. 2009-09-22 13:14:16 +02:00
Andreas Schneider
7de3122b42 Added a userdata generic pointer to the log callback function. 2009-09-22 12:28:07 +02:00
Andreas Schneider
88f4e9ea24 Added more logging output for publickey auth. 2009-09-21 15:54:49 +02:00
Andreas Schneider
4133f484ae Fixed building libssh with MSVC.
Thanks to Carlo Segato for the patch.
2009-09-21 12:23:47 +02:00
Aris Adamantiadis
041aff8060 Fix binding found by Bernhard R. Link 2009-09-19 19:35:55 +02:00
Aris Adamantiadis
7c7096d8f8 Limit the size of acceptable compressed packets 2009-09-16 22:29:22 +02:00
Andreas Schneider
fd7b7bc3b5 Added Solaris support for the build script.
Thanks to tysonite.
2009-09-16 14:47:45 +02:00
Andreas Schneider
bb034e8e1d Set package number to first beta release. 2009-09-15 23:07:24 +02:00
Andreas Schneider
d37a475816 Improve documentation of ssh_options_parse_config(). 2009-09-15 18:06:19 +02:00
Andreas Schneider
4845642611 Added support for ~/.ssh/config. 2009-09-15 17:26:13 +02:00
Andreas Schneider
de8808cb47 Fixed build with mingw. 2009-09-15 10:43:09 +02:00
Aris Adamantiadis
ca978a9e81 Merge branch 'master' of git://git.libssh.org/projects/libssh/libssh 2009-09-14 23:19:11 +02:00
Aris Adamantiadis
ffca268bee Add warning in channel_open_forward documentation
Tell users it does not do magic (yet)
2009-09-14 23:18:07 +02:00
Andreas Schneider
6a3d31acb7 Fix a possible stack overflow in agent code. 2009-09-14 19:01:20 +02:00
Aris Adamantiadis
f28352707a Fix the security bug found by Orange Labs
Verify the length of decrypt operation is a multiple of blocksize
2009-09-13 22:07:01 +02:00
Aris Adamantiadis
4b363928f6 SCP warning request 2009-09-13 14:03:35 +03:00
Aris Adamantiadis
929f5ca25b scp recursive mode 2009-09-13 14:03:34 +03:00
Aris Adamantiadis
7ff80a2666 Add better error detection + EOF request 2009-09-13 14:03:34 +03:00
Aris Adamantiadis
480dfd9050 add scp_download.c example 2009-09-13 14:03:34 +03:00
Aris Adamantiadis
bdb32afa20 Cycle the fetchs, remove the ssh_connect function 2009-09-13 14:03:34 +03:00
Aris Adamantiadis
f90ae73b6d Refactored the connect_ssh example function
into a new file
2009-09-13 14:03:34 +03:00
Aris Adamantiadis
7fed54b1e5 Fix scp pull bug + scp logging 2009-09-13 14:03:34 +03:00
Aris Adamantiadis
d5840aa1f0 add support for local output, scp input
Still needs to be debugged and improved but the idea it there
2009-09-13 14:03:34 +03:00
Aris Adamantiadis
6f2225e8fb fix ssh_scp_string_mode() bug + debug msgs 2009-09-13 14:03:33 +03:00
Aris Adamantiadis
07a9e6b7c6 Change scp API to use integers for perms 2009-09-13 14:03:33 +03:00
Aris Adamantiadis
86e6444656 Begin of scp reading in example 2009-09-13 14:03:33 +03:00
Andreas Schneider
8ef62cf784 Fixed fstatvfs function. 2009-09-10 18:57:58 +02:00
Andreas Schneider
8051ab044c Reformat lowercase function. 2009-09-10 14:37:09 +02:00
Dmitry V. Krivenok
18bce13617 Fixed possible memory leak in lowercase function.
If user passed NULL pointer to lowercase() function, duplicated
string "new" wasn't freed before return.

Signed-off-by: Dmitry V. Krivenok <krivenok@orangesystem.ru>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-09-10 14:35:02 +02:00
Dmitry V. Krivenok
2a10019f82 Fixed "var is uninitialized" bug.
gcc-4.4.1 reported:

/home/krivenok/dev_builds/libssh/libssh/sftp.c:2700: warning: 'sftp' is used uninitialized in this function

sftp is NULL-initialized now.

Signed-off-by: Dmitry V. Krivenok <krivenok@orangesystem.ru>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-09-10 12:35:11 +02:00
Dmitry V. Krivenok
df4c62212c Support for sending signals (RFC 4254, section 6.9).
Added function
int channel_request_send_signal(ssh_channel channel, const char *signal);
which implements signals delivery (as described in RFC 4254).
Only SSH-v2 is currently supported.

Signed-off-by: Dmitry V. Krivenok <krivenok@orangesystem.ru>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-09-10 12:34:58 +02:00
Andreas Schneider
97b6036cbf Add a portable ssh_mkdir function for Windows. 2009-09-09 13:42:00 +02:00
Andreas Schneider
df4f7ed5b8 Fix the free calls and use the safe free macro. 2009-09-03 17:22:34 +02:00
Andreas Schneider
0792c015d6 Add missing NULL pointer checks to crypt_set_algorithms_server.
Thanks to Orange Labs for the report.
2009-09-03 17:20:06 +02:00
Andreas Schneider
8344598910 Fix an integer overflow in buffer_get_data().
Thanks to Orange Labs for the report.
2009-09-03 17:11:42 +02:00
Andreas Schneider
16870abed7 Add more warnings to gcc. 2009-09-01 11:03:48 +02:00
Aris Adamantiadis
65850a1bad Fix "void * ptr used in pointer arithmetic" warng 2009-08-29 19:04:53 +02:00
Aris Adamantiadis
1137f0d48c Change SSH_LOG_RARE to SSH_LOG_PACKET in packet.c 2009-08-29 18:59:13 +02:00
Andreas Schneider
d9a50f04e7 Fix ssh_write_knownhost() if ~/.ssh doesn't exist. 2009-08-26 09:39:21 +02:00
Andreas Schneider
4aa7d73b43 Fix typo. 2009-08-25 15:23:28 +02:00
Andreas Schneider
3804e72e24 Fix linking on solaris.
libresolv and librt are required.
2009-08-25 15:07:29 +02:00
Andreas Schneider
b8508020e5 Link shared libraries with --as-needed by default. 2009-08-25 15:06:56 +02:00
Andreas Schneider
324be0eabd Fix poll sturct, ISO C doesn't allow unnamed unions. 2009-08-25 14:16:41 +02:00
Andreas Schneider
cfe5f83cf8 Fix shadow compiler warning in sample code. 2009-08-25 13:59:40 +02:00
Andreas Schneider
a1ad0deb32 Set gcc to c99 standard and enable pedantic. 2009-08-25 13:58:30 +02:00
Andreas Schneider
7c575a2418 Fix typedef collisons on Solaris. 2009-08-25 13:54:46 +02:00
Aris Adamantiadis
47cac13c0a Merge branch 'master' of git://git.libssh.org/projects/libssh/libssh 2009-08-24 16:08:17 +02:00
Aris Adamantiadis
16d1ef8933 buffer initialization change 2009-08-24 16:07:45 +02:00
Andreas Schneider
b500d76929 Add Solaris search path for libraries. 2009-08-24 14:49:07 +02:00
Aris Adamantiadis
aef9471217 fix memleak through requests 2009-08-23 23:43:07 +02:00
Aris Adamantiadis
f3454d571e ssh_scp_request_get_{filename,permissions,size} 2009-08-23 23:40:30 +02:00
Aris Adamantiadis
1df1f86f7e added ssh_scp_read 2009-08-23 23:24:46 +02:00
Aris Adamantiadis
f9db9c5a9c added ssh_scp_accept_request 2009-08-23 22:43:57 +02:00
Aris Adamantiadis
96bafeca4c corrected errors 2009-08-23 22:40:15 +02:00
Aris Adamantiadis
626d8ec637 forgot to set up state 2009-08-23 22:38:29 +02:00
Aris Adamantiadis
f3b36af50e added ssh_scp_deny_request 2009-08-23 22:36:32 +02:00
Aris Adamantiadis
385b640d1d Implementation of ssh_scp_pull_request
Still needed: code in ssh_scp_init,
implementation of ssh_scp_read
ssh_scp_request_get_filename,
ssh_scp_request_get_size,
ssh_scp_request_get_mode,
ssh_scp_deny_request
ssh_scp_accept_request
!!
2009-08-23 22:04:51 +02:00
Aris Adamantiadis
d4bc6fa954 Merge branch 'master' of git://git.libssh.org/projects/libssh/libssh
Conflicts:
	include/libssh/priv.h
2009-08-23 16:41:29 +02:00
Aris Adamantiadis
8bae43876f experimental callback system 2009-08-23 16:33:59 +02:00
Aris Adamantiadis
fbfea94559 Pending work 2009-08-23 16:29:31 +02:00
Aris Adamantiadis
6a04b43a45 added ssh_scp_request_new,ssh_scp_request_struct 2009-08-23 15:23:48 +02:00
Aris Adamantiadis
049c62098c add ssh_scp_push_directory,ssh_scp_leave_directory
Not yet carefully tested
2009-08-23 14:57:03 +02:00
Aris Adamantiadis
6801959989 Use ssh_basename on ssh_scp_file_push'ed files 2009-08-23 14:28:38 +02:00
Andreas Schneider
8463d9d7c6 Improve header checks on windows. 2009-08-21 15:15:49 +02:00
Andreas Schneider
c497f057a0 Improve detection for required libraries on Solaris. 2009-08-21 15:15:18 +02:00
Andreas Schneider
fc0af0f0d8 Add openssl include dir on Solaris. 2009-08-21 14:54:24 +02:00
Andreas Schneider
330c2004a1 Make the functions public. 2009-08-21 10:17:58 +02:00
Andreas Schneider
0b10493e90 Added ssh_basename() and ssh_dirname(). 2009-08-21 10:16:36 +02:00
Andreas Schneider
d23e64fc52 Add a warning if wspiapi.h doesn't exist. 2009-08-20 12:32:35 +02:00
Andreas Schneider
fd83d69440 Improve the configure checks. 2009-08-20 11:50:49 +02:00
Andreas Schneider
461e46b814 Improve checks for Windows version and wspiapi.h. 2009-08-20 11:43:37 +02:00
Andreas Schneider
4f95146151 Fix build warnings on Windows. 2009-08-20 10:50:02 +02:00
Andreas Schneider
3eb21053d0 Add a portable define to print size_t. 2009-08-20 10:49:27 +02:00
Andreas Schneider
92db6f8c6d Remove DEBUG_CRYPTO variable.
You can enable it with cmake -DWITH_DEBUG_CRYPTO:BOOL=TRUE.
2009-08-20 10:44:31 +02:00
Andreas Schneider
0fd0c6d293 Don't shadow global vairables. 2009-08-19 10:52:30 +02:00
Andreas Schneider
b49973f17b Fix compile warnings. 2009-08-17 08:56:43 +02:00
Andreas Schneider
978d265da8 Build channel_accept() on Windows too. 2009-08-16 19:01:13 +02:00
Vic Lee
cf6dddce34 Fix double free pointer crash in dsa_public_to_string
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-08-16 14:40:19 +02:00
Vic Lee
2c4bbe51dd Fix return code from packet_wait in channel_request
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-08-16 14:40:18 +02:00
Andreas Schneider
756d441f8c Fix channel_accept_x11 on Windows. 2009-08-16 14:40:18 +02:00
Vic Lee
db6aa88bc4 Add forward listening feature
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-08-16 14:40:18 +02:00
Aris Adamantiadis
e707af1cd7 Fix channel_get_exit_status bug reported by VicLee
It would return -1 if the channel received the exit status
and the close message at same time.
2009-08-16 13:51:55 +02:00
Aris Adamantiadis
380a70d650 fix ssh_finalize which didn't clear the flag 2009-08-13 23:26:17 +02:00
Andreas Schneider
2dc3b5c675 Add sftp_extension_supported() function. 2009-08-12 17:13:42 +02:00
Andreas Schneider
63011c29a0 Implement an example for statvfs. 2009-08-12 17:13:42 +02:00
Andreas Schneider
e68c3b09a6 Add support for OpenSSH's statvfs and fstatvfs calls. 2009-08-12 17:13:42 +02:00
Andreas Schneider
0793bf5aa6 Set version number to 0.4.0. 2009-08-12 17:13:04 +02:00
Andreas Schneider
d9b7e4cb7a Fix compilation with visibility flags with mingw.
Thanks to Patrick Spendrin.
2009-08-12 14:05:17 +02:00
Andreas Schneider
8e6ab1809f Enable the debug calltrace by default. 2009-08-12 10:08:20 +02:00
Aris Adamantiadis
86418bfbbe Merge branch 'master' of git://git.libssh.org/projects/libssh/libssh 2009-08-12 00:04:30 +02:00
Aris Adamantiadis
1e1c13f756 some tweaks of scp example 2009-08-12 00:04:04 +02:00
Aris Adamantiadis
8dae851836 Make the calltrace logging optional 2009-08-12 00:03:36 +02:00
Andreas Schneider
db284d60b9 Fix static build.
If you want to link against the static library you have to define
LIBSSH_STATIC and link against ssh_static.

gcc -static -DLIBSSH_STATIC -lssh_static foo.c -o foo
2009-08-11 18:16:43 +02:00
Andreas Schneider
bfc6c7e606 Remove the map file from the sources. 2009-08-11 17:11:44 +02:00
Andreas Schneider
9b13390ad0 Use gcc visibility attribute to get rid of the map file. 2009-08-11 17:10:00 +02:00
Andreas Schneider
81fe4299f7 Fix linking of the static library on Windows. 2009-08-11 16:12:53 +02:00
Andreas Schneider
5e4bc6ec79 Fix compilation with MSVC and use declspec to export functions.
Thanks to Patrick Spendrin <ps_ml@gmx.de> for all the MSVC fixes.
2009-08-11 15:38:49 +02:00
Andreas Schneider
f3612879a8 Remove InstallRequiredSystemLibraries from CPack. 2009-08-11 15:37:52 +02:00
Andreas Schneider
57088c4375 Fix libssh build and installation on MSVC. 2009-08-11 15:37:10 +02:00
Andreas Schneider
011ab7c8fe Suppress warning about "deprecated" functions in MSVC. 2009-08-11 15:36:37 +02:00
Aris Adamantiadis
e4422d6605 Fix memory leak introduced by previous bugfix 2009-08-11 13:15:23 +02:00
Andreas Schneider
14e1d015ee Fix uint8_t. 2009-08-11 09:41:52 +02:00
Andreas Schneider
3da1c17acb Add a NULL check for strdup memory allocation. 2009-08-11 09:41:07 +02:00
Aris Adamantiadis
7e9f0803c5 Latest scp code
The sample is now able to scp a file
2009-08-10 22:59:35 +02:00
Aris Adamantiadis
f989452b3e Fixed stupid "can't parse known host key" bug
due to a dangling \n in the base64 ...
2009-08-10 22:50:16 +02:00
Aris Adamantiadis
a2780d1dd4 I really really broke it
excuse me !
2009-08-10 14:34:04 +02:00
Aris Adamantiadis
ddca45804b oops I broke libssh.map 2009-08-10 14:32:50 +02:00
Aris Adamantiadis
f92e12c7b0 ssh_scp_push_file and ssh_scp_write
still needs tests
2009-08-09 22:51:03 +02:00
Aris Adamantiadis
e4da8b99fe Initial scp implementation in source tree 2009-08-09 02:01:54 +02:00
Aris Adamantiadis
b993579079 Got the scp sample to work
Problem was that the terminal was not needed, and some nul bytes were to be read.
2009-08-09 00:25:09 +02:00
Aris Adamantiadis
807cb635c1 Fixed channel_poll broken when delayed EOF recvd
Previous code returned SSH_EOF even if data was left in buffer
2009-08-09 00:20:42 +02:00
milo
3ad559cc23 Fix buffer overflow in generate_cookie()
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-08-07 12:49:55 +02:00
milo
ec02ce0ec2 Fix a typo: CHANNEL * -> ssh_channel
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-08-07 11:40:07 +02:00
milo
1b9676a0cc Fix possible memory corruption (#14)
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-08-06 10:29:36 +02:00
Andreas Schneider
f4b3ef7604 Remove ssh_fd_poll from map file. 2009-08-05 18:20:32 +02:00
Andreas Schneider
e9974c2053 Remove ssh_fd_poll which is gone. 2009-08-05 17:38:43 +02:00
Andreas Schneider
de532ee550 Move extension structure to the end. 2009-08-01 11:15:53 +02:00
Andreas Schneider
67b44e4417 Don't use the map file if the build type is debug. 2009-08-01 11:05:19 +02:00
Andreas Schneider
83f65031c0 Fixed libssh compilation without server support. 2009-07-31 12:31:46 +02:00
Vic Lee
63053541e6 Add x11 forwarding support for ssh client
Signed-off-by: Vic Lee <llyzs@163.com>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-07-31 11:17:51 +02:00
Andreas Schneider
a040e2e3db Cleanup the map file and oder it alphabetically. 2009-07-30 12:02:05 +02:00
Andreas Schneider
678d445075 Export public functions on Windows. 2009-07-30 12:01:39 +02:00
Andreas Schneider
3558b9e6b6 Fix Windows build. 2009-07-30 11:40:28 +02:00
Andreas Schneider
590c3e2f51 Add strange names for Windows. 2009-07-30 11:38:38 +02:00
Andreas Schneider
28a7343320 Fix project name in examples. 2009-07-30 11:11:00 +02:00
Andreas Schneider
766bae9d76 Fix build with MSVC. 2009-07-30 10:45:58 +02:00
Andreas Schneider
94a57df0c9 Compile the library with the map file again. 2009-07-30 00:46:57 +02:00
Andreas Schneider
5f93742c5e Add missing functions to map file. 2009-07-30 00:46:45 +02:00
Andreas Schneider
9457c770df Change the library so version. 2009-07-30 00:46:07 +02:00
Andreas Schneider
bccb9b16a5 Move channel_write_stderr to server.c. 2009-07-29 23:21:01 +02:00
Andreas Schneider
1355029ec9 Fix indent. 2009-07-29 23:02:12 +02:00
Andreas Schneider
5dc8d6069d Update map file and introduce a new version.
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-07-29 18:42:16 +02:00
Andreas Schneider
60837b1538 Add channel_write_stderr prototype to the right header file.
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-07-29 18:42:10 +02:00
Andreas Schneider
debfd1f3a3 Fix build errors in new messages functions.
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-07-29 18:42:05 +02:00
Preston A. Elder
4f70cc13e2 Fleshed out server interface
- Enables channel_request_open types of DIRECT_TCPIP, FORWARDED_TCPIP and X11 (ie. implemented the handling of those channel_request_open types).
- Adds functions to retrieve the extra information relating to channel_request_open messages and channel_request messages.
- Adds a channel_write_stderr method (obviously for writing to the STDERR channel from server side) - well, technically just converted the exiting channel_write to take an extra argument and created two wrapper functions.
- Actually does the invoking of message_handle() from channel_recv_request.
- Implemented the handling of the window-change and env channel_requests.
- Implemented a few functions in server.h that were declared but not defined (eg. ssh_message_channel_request_channel).

Signed-off-by: Preston A. Elder <prez@neuromancy.net>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-07-29 18:41:48 +02:00
Andreas Schneider
b4111c5c18 Add functions to get the extension count, name and data. 2009-07-28 14:13:22 +02:00
Andreas Schneider
b9b7174d85 Add support to read and store sftp extensions. 2009-07-28 13:25:35 +02:00
Andreas Schneider
69ceaae9a9 Check for OpenSSH and implement sftp_symlink correct.
When OpenSSH's sftp-server was implemented, the order of the arguments
to the SSH_FXP_SYMLINK method was inadvertently reversed. Unfortunately,
the reversal was not noticed until the server was widely deployed.
Since fixing this to follow the specification would cause
incompatibility, the current order was retained.
2009-07-28 13:25:26 +02:00
Andreas Schneider
1abdb28995 Fix SSH1 compilation. 2009-07-27 23:17:35 +02:00
Andreas Schneider
81dab99afc Fix stdint type. 2009-07-27 23:14:04 +02:00
Andreas Schneider
291522772d Fix SSH1 and stdint in SSH1 code. 2009-07-27 23:13:24 +02:00
milo
26d1ac325b Fix potential memory corruption bug 2009-07-27 20:53:01 +02:00
milo
1311d03415 Fix typo orignator_port -> originator_port 2009-07-27 20:52:36 +02:00
Andreas Schneider
549fd32574 Fix compile errors in keyfiles. 2009-07-27 20:49:38 +02:00
Andreas Schneider
9f14bbd6ad Remove double SSH2_MSG_USERAUTH_PK_OK. 2009-07-27 20:30:27 +02:00
milo
e8f7801540 Public key authentication server side 2009-07-27 20:27:07 +02:00
Andreas Schneider
cdde79418a Add ssh_file_readaccess_ok to check read access on a file. 2009-07-27 14:20:32 +02:00
Andreas Schneider
9b97da65e6 Add a function to close the socket.
This fixes ssh_connect on Windows.
2009-07-27 14:19:06 +02:00
Andreas Schneider
1dcaebe1ce Fix a typo. 2009-07-27 13:20:29 +02:00
Andreas Schneider
28b5d0f875 Switch completly to stdint types. 2009-07-25 23:19:41 +02:00
Aris Adamantiadis
ba217dec1c First implementation of a scp transfer tool
Doesn't work yet. I've got a headache and debugging doesn't help.
2009-07-25 22:29:12 +02:00
Andreas Schneider
3b8c4dc750 Fix conflicting declarations of ssh_session and ssh_kbdint. 2009-07-25 20:26:56 +02:00
Andreas Schneider
5d1fa1be24 Fix return value of sftp_tell64(). 2009-07-25 19:52:07 +02:00
Andreas Schneider
c8e82528fc Update map file for ssh_clean_pubkey_hash; 2009-07-25 18:00:36 +02:00
Andreas Schneider
104e6d39ab Add a sftp_tel64() function. 2009-07-25 17:55:58 +02:00
Andreas Schneider
3f778d9a31 Add ssh_clean_pubkey_hash() which is needed on Windows. 2009-07-25 17:52:00 +02:00
Aris Adamantiadis
a935ad1857 New example directory with the begining of a scp 2009-07-25 17:03:01 +02:00
Aris Adamantiadis
7abb3941c8 Bumped the version numbers to 0.4.0 in HEAD 2009-07-25 16:32:10 +02:00
Andreas Schneider
194880b869 Update map file. 2009-07-25 11:56:59 +02:00
Andreas Schneider
737f588b3b Fix a typo. 2009-07-25 11:55:42 +02:00
Andreas Schneider
6d5b36fb79 Add symlink and readlink test to sample. 2009-07-25 11:55:42 +02:00
Andreas Schneider
8ce6bd3459 Add sftp_readlink function. 2009-07-25 11:55:42 +02:00
Andreas Schneider
5b8338d115 Add sftp_symlink function. 2009-07-25 11:55:33 +02:00
Aris Adamantiadis
e73cbbe18c Added a threading + sftp stress testcase 2009-07-24 22:52:10 +02:00
Aris Adamantiadis
69a01b3657 move all u32,u16,u8 and u64 declarations in priv.h
And fix all headers which need u32,u8,u64
2009-07-24 22:31:39 +02:00
Aris Adamantiadis
e406b81d34 Missed something in channel_select for CHANNEL 2009-07-24 22:24:10 +02:00
Aris Adamantiadis
fdc2751952 Make the SSH_SAFE_NAMESPACE flag active 2009-07-24 22:20:41 +02:00
Aris Adamantiadis
fa11083fcb Change refs from AGENT * to ssh_agent
Fixes also a typo in ssh_agent declaration
2009-07-24 22:19:40 +02:00
Aris Adamantiadis
2bc8819e8f Changes all CHANNEL * to ssh_channel 2009-07-24 22:15:33 +02:00
Aris Adamantiadis
23b6c95e04 Change PRIVATE_KEY * to ssh_private_key 2009-07-24 22:08:04 +02:00
Aris Adamantiadis
c041bcc6d9 Forgot sample* in previous BUFFER change 2009-07-24 22:03:36 +02:00
Aris Adamantiadis
fc5dd23afa Changed all PUBLIC_KEY * to ssh_public_key 2009-07-24 22:02:32 +02:00
Aris Adamantiadis
91d0660cc3 Changed all occurences of BUFFER * to ssh_buffer 2009-07-24 21:56:11 +02:00
Aris Adamantiadis
fb5769b4be You always forget SSH1 ... 2009-07-24 21:47:23 +02:00
Aris Adamantiadis
56ee212641 Change all occurences of STRING * to ssh_string 2009-07-24 21:45:41 +02:00
Aris Adamantiadis
8f3891e968 moved try_publickey_from_file in priv.h
Had nothing to do in libssh.h. 100% sure nobody
used it since one of the structure declaration
was not public.
2009-07-24 21:23:07 +02:00
Aris Adamantiadis
958a775afa replacing keys_struct with ssh_keys_struct 2009-07-24 21:18:15 +02:00
Aris Adamantiadis
e776dc16c9 Fixed namespace problem in public structures
changed
struct string_struct to ssh_string_struct
buffer_struct to ssh_buffer_struct
and so on.

Should not break apps using the caps version of these
2009-07-24 20:49:46 +02:00
Andreas Schneider
9450a3c987 Fix a possible segfault in sftp_canonicalize_path(). 2009-07-23 18:34:25 +02:00
Andreas Schneider
1939a55c3c Fix getaddrinfo and gethostbyname build problems on Solaris. 2009-07-23 11:57:17 +02:00
Andreas Schneider
2a116bb291 Fix OpenSSL include file checks on Solaris. 2009-07-23 11:54:32 +02:00
Andreas Schneider
d01c7320f9 Fix finding OpenSSL on Solaris. 2009-07-23 09:30:14 +02:00
Andreas Schneider
ea0315ed88 Add cmake check for big endian. 2009-07-23 09:25:36 +02:00
Andreas Schneider
85a5eb9499 Fix a segfault if a NULL pointer is passed to ssh_disconnect(). 2009-07-22 16:04:41 +02:00
Andreas Schneider
3cd06a1f26 Don't segfault if the session or the answer is NULL. 2009-07-22 12:18:34 +02:00
Andreas Schneider
19c3d02805 Merge branch 'master' of git://git.libssh.org/projects/libssh/libssh 2009-07-21 14:12:25 +02:00
Andreas Schneider
b534bfc520 Fix ssh_write_knownhost() which always returned -1.
fwrite() return the the number of items written not the size of the
buffer.
2009-07-21 14:07:23 +02:00
Andreas Schneider
ef2c8d66f1 Add compile flags and test for compiler options only if we use gcc. 2009-07-21 11:14:54 +02:00
Andreas Schneider
1a6038baa5 Only add additional warnings if we have a GNU compiler. 2009-07-21 11:10:09 +02:00
Andreas Schneider
41a8fb5810 Make the ssh_userauth_kbdint functions to get the prompts const.
They shouldn't be modified or free'd by a user.
2009-07-21 10:34:21 +02:00
Andreas Schneider
8843d8b68d Fix sol8 + ss11 compile errors.
Thanks to tysonite@gmail.com.
2009-07-20 22:50:45 +02:00
Andreas Schneider
2aec79ce36 Add missing changelog entries. 2009-07-14 11:10:22 +02:00
Aris Adamantiadis
bbcbc8425c Fix doxygen to match SSH_SERVER_FILE_NOT_FOUND fix 2009-07-14 10:09:18 +02:00
Andreas Schneider
ed8178f3c3 Fix build on windows, missing include. 2009-07-13 13:33:52 +02:00
Aris Adamantiadis
933527fc77 Put #ifdef around AI_NUMERICSERV which doesn't seem std 2009-07-13 13:29:00 +02:00
Aris Adamantiadis
bf8d139b2d Enable conditional compiling for IP regex code. 2009-07-13 12:32:06 +02:00
Aris Adamantiadis
093983b804 forgot init.c in copyright updates 2009-07-13 00:25:04 +02:00
Aris Adamantiadis
103292dd99 Fixed copyright notices 2009-07-13 00:23:42 +02:00
Aris Adamantiadis
76b6b1c694 typo in sample.c 2009-07-13 00:19:47 +02:00
Aris Adamantiadis
1301864f92 Reflect the SSH_SERVER_NOT_KNOWN add-on in sample 2009-07-12 23:17:12 +02:00
Aris Adamantiadis
d5b6f6cc37 Added return code SSH_SERVER_FILE_NOT_FOUND
This error is returned by ssh_is_server_known when known_hosts
file does not exist and gives more action to the developer.
2009-07-12 23:13:21 +02:00
Aris Adamantiadis
052073c36d Set correct hint when connecting to an IP address
libssh now uses a regular expression against destination
hostnames to match numerical IP addresses and set the
appropriate hint.

Patches also add init and finalize code to compile the regexp
2009-07-12 23:01:43 +02:00
Aris Adamantiadis
60c778ad7f fix int -> socket_t in SSH_POLL 2009-07-04 14:16:13 +02:00
Aris Adamantiadis
71100dadcd Temporary move of ssh_poll_* back to priv.h
We'll see later what needs to be put back in public
functions
2009-07-04 13:52:34 +02:00
Aris Adamantiadis
5ba33438f3 Move doxygen tags into C files 2009-07-04 13:47:57 +02:00
Aris Adamantiadis
708c0d32a2 Put back the poll declarations into priv.h
That are, poll constants.
2009-07-04 13:41:16 +02:00
Aleksandar Kanchev
3659e8c04a Add a generic way to handle sockets asynchronously.
It's based on poll objects, each of which store a socket, it's events and a callback,
which gets called whenever an event is set. The poll objects are attached to a poll
context, which should be allocated on per thread basis.

Polling the poll context will poll all the attached poll objects and call their
callbacks (handlers) if any of the socket events are set. This should be done within
the main loop of an application.

This is intended as a ground work for making libssh asynchronous.

Signed-off-by: Aleksandar Kanchev <aleksandar.kanchev@googlemail.com>
2009-07-03 21:53:53 +02:00
Aris Adamantiadis
c4cf349729 Add logging of the sftp flags used to open a file
Should be used to debug weird behaviour when using libssh on windows with different compiler chains.
2009-06-30 22:35:01 +02:00
Aris Adamantiadis
2c99566697 Fixed Could not write as much data as expected msg
Bug caused by verifying the size of the buffer in the wrong place
2009-06-30 22:17:35 +02:00
Aleksandar Kanchev
42470857e2 Fixed make condition in build_make.sh.
Signed-off-by: Aleksandar Kanchev <aleksandar.kanchev@googlemail.com>
Signed-off-by: Andreas Schneider <mail@cynapses.org>
2009-06-25 18:02:57 +02:00
Aris Adamantiadis
8724f97a19 Fixed memory leak in ssh_is_server_known() 2009-06-22 23:30:50 +02:00
Aris Adamantiadis
8960992267 Fixed yet another read-after-free bug
read of a buffer len after free in sftp_write()
2009-06-21 22:30:28 +02:00
Aris Adamantiadis
730af24de8 Fixed a use-after-free in match_hashed_host() 2009-06-21 22:09:19 +02:00
Aris Adamantiadis
a3fa6f3099 fix stupid "use unallocated memory" code in sample
it confused valgrind and wasted 2 precious hours of my life
2009-06-21 21:53:12 +02:00
Aris Adamantiadis
4dafc25927 Added a macro to test buffer_struct integrity
Nothing yet in cmake and config.h.in for this
2009-06-21 20:29:29 +02:00
Aris Adamantiadis
e671ebcd99 Modified the sftp test case so it creates 0700 fil 2009-06-21 20:14:10 +02:00
Aris Adamantiadis
bab8508eba Fix doublefree bug found by Cyril 2009-06-21 19:25:51 +02:00
Andreas Schneider
77cd4795c5 Remove unneeded printf. 2009-06-19 22:46:41 +02:00
Andreas Schneider
dc83f36a00 Add a git ignore file. 2009-06-19 10:25:51 +02:00
Aris Adamantiadis
8336c91e9c Verify memory return codes in ssh_list functions 2009-06-19 10:18:24 +02:00
Aris Adamantiadis
1bea53375b added ssh_message_callback support.
Not fully working yet. User can set his ssh_message_callback, and the function ssh_execute_message_callbacks will call them when appropriate. Messages are correctly stacked (in packet_parse) but no call to ssh_execute_callbacks exists yet.
2009-06-18 23:48:55 +02:00
Aris Adamantiadis
3af55a4f49 Created general singlelinked list implementation 2009-06-18 23:01:05 +02:00
Aris Adamantiadis
cf482ae3bf Begin of asynchronous SSH message parsing 2009-06-17 23:53:00 +02:00
Aris Adamantiadis
916958a2bb Fixed potential format string attacks
Potential format string attacks on error reporting in channels.c
2009-06-17 23:42:07 +02:00
Aris Adamantiadis
e2af94289f ssh_message_retrieve + memoryleak fixed in ssh_message_free
ssh_message_retrieve parses a specific SSH message and returns a pointer to it.
Hacked ssh_message_get to use it. This is the first step to have asynchronous ssh messages callbacks.
2009-06-17 23:28:05 +02:00
Aris Adamantiadis
fa4c81cfb9 Url change in README 2009-06-16 16:45:39 +02:00
Aris Adamantiadis
7dbc66e4a3 ssh_init()
fixes in client.c and server.c for this


git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@778 7dcaeef0-15fb-0310-b436-a5af3365683c
2009-06-15 15:31:23 +00:00
273 changed files with 65878 additions and 26495 deletions

13
.clang_complete Normal file
View File

@@ -0,0 +1,13 @@
-DWITH_SERVER=1
-DWITH_GSSAPI=1
-DWITH_ZLIB=1
-DWITH_SFTP=1
-DWITH_SSH1=1
-DWITH_PCAP=1
-DHAVE_ECDH=1
-DHAVE_ECC=1
-Iinclude/libssh
-Iinclude
-Ibuild
-Itests
-Isrc

5
.gitignore vendored
View File

@@ -1,6 +1,9 @@
*.a
*.o
.*
*.swp
*~$
build
obj
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

@@ -1,19 +1,26 @@
project(libssh C)
# Required cmake version
cmake_minimum_required(VERSION 2.6.0)
cmake_minimum_required(VERSION 2.8.5)
# global needed variables
set(APPLICATION_NAME ${PROJECT_NAME})
set(APPLICATION_VERSION "0.3.4")
set(APPLICATION_VERSION_MAJOR "0")
set(APPLICATION_VERSION_MINOR "3")
set(APPLICATION_VERSION_PATCH "4")
set(APPLICATION_VERSION_MINOR "7")
set(APPLICATION_VERSION_PATCH "0")
set(LIBRARY_VERSION "3.4.0")
set(LIBRARY_SOVERSION "3")
set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
# SOVERSION scheme: CURRENT.AGE.REVISION
# If there was an incompatible interface change:
# Increment CURRENT. Set AGE and REVISION to 0
# If there was a compatible interface change:
# Increment AGE. Set REVISION to 0
# If the source code was changed, but there were no interface changes:
# Increment REVISION.
set(LIBRARY_VERSION "4.4.0")
set(LIBRARY_SOVERSION "4")
# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
set(CMAKE_MODULE_PATH
@@ -22,6 +29,7 @@ set(CMAKE_MODULE_PATH
# add definitions
include(DefineCMakeDefaults)
include(DefinePlatformDefaults)
include(DefineCompilerFlags)
include(DefineInstallationPaths)
include(DefineOptions.cmake)
@@ -31,21 +39,40 @@ 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
find_package(ZLIB REQUIRED)
if (WITH_ZLIB)
find_package(ZLIB REQUIRED)
endif (WITH_ZLIB)
find_package(OpenSSL)
if (NOT CRYPTO_FOUND)
find_package(GCrypt)
if (WITH_GCRYPT)
find_package(GCrypt 1.5.0 REQUIRED)
if (NOT GCRYPT_FOUND)
message(FATAL_ERROR "Could not find OpenSSL or GCrypt")
message(FATAL_ERROR "Could not find GCrypt")
endif (NOT GCRYPT_FOUND)
endif (NOT CRYPTO_FOUND)
else (WITH_GCRYPT)
find_package(OpenSSL)
if (NOT OPENSSL_FOUND)
find_package(GCrypt)
if (NOT GCRYPT_FOUND)
message(FATAL_ERROR "Could not find OpenSSL or GCrypt")
endif (NOT GCRYPT_FOUND)
endif (NOT OPENSSL_FOUND)
endif(WITH_GCRYPT)
# Find out if we have threading available
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)
@@ -54,17 +81,71 @@ configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
# check subdirectories
add_subdirectory(doc)
add_subdirectory(include)
add_subdirectory(libssh)
add_subdirectory(src)
# build samples
include_directories(${CMAKE_SOURCE_DIR}/include)
# pkg-config file
configure_file(libssh.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libssh.pc)
configure_file(libssh_threads.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libssh_threads.pc)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/libssh.pc
${CMAKE_CURRENT_BINARY_DIR}/libssh_threads.pc
DESTINATION
${LIB_INSTALL_DIR}/pkgconfig
COMPONENT
pkgconfig
)
if (UNIX AND NOT WIN32)
if (WITH_SFTP AND WITH_SERVER)
add_executable(samplessh sample.c)
add_executable(samplesshd samplesshd.c)
# 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(CMocka REQUIRED)
include(AddCMockaTest)
add_subdirectory(tests)
endif (WITH_TESTING)
message(STATUS "********************************************")
message(STATUS "********** ${PROJECT_NAME} build options : **********")
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)
message(STATUS "Internal documentation generation")
else (WITH_INTERNAL_DOC)
message(STATUS "Public API documentation generation")
endif (WITH_INTERNAL_DOC)
message(STATUS "Benchmarks: ${WITH_BENCHMARKS}")
message(STATUS "********************************************")
target_link_libraries(samplessh ${LIBSSH_SHARED_LIBRARY})
target_link_libraries(samplesshd ${LIBSSH_SHARED_LIBRARY})
endif (WITH_SFTP AND WITH_SERVER)
endif (UNIX AND NOT WIN32)

View File

@@ -1,5 +1,3 @@
include(InstallRequiredSystemLibraries)
# For help take a look at:
# http://www.cmake.org/Wiki/CMake:CPackConfiguration
@@ -13,27 +11,32 @@ set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING")
### versions
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "3")
set(CPACK_PACKAGE_VERSION_PATCH "4")
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)
set(CPACK_GENERATOR "ZIP")
### nsis generator
set(CPACK_GENERATOR "NSIS")
### nsis generator
find_package(NSIS)
if (NSIS_MAKE)
set(CPACK_GENERATOR "${CPACK_GENERATOR};NSIS")
set(CPACK_NSIS_DISPLAY_NAME "The SSH Library")
set(CPACK_NSIS_COMPRESSOR "/SOLID zlib")
set(CPACK_NSIS_MENU_LINKS "http://www.libssh.org/" "libssh homepage")
endif (NSIS_MAKE)
endif (WIN32)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "libssh")
set(CPACK_NSIS_DISPLAY_NAME "The SSH Library")
set(CPACK_NSIS_COMPRESSOR "/SOLID zlib")
set(CPACK_NSIS_MENU_LINKS "http://www.libssh.org/" "libssh homepage")
set(CPACK_PACKAGE_FILE_NAME ${APPLICATION_NAME}-${CPACK_PACKAGE_VERSION})
set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries")

9
CTestConfig.cmake Normal file
View File

@@ -0,0 +1,9 @@
set(UPDATE_TYPE "true")
set(CTEST_PROJECT_NAME "libssh")
set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC")
set(CTEST_DROP_METHOD "https")
set(CTEST_DROP_SITE "test.libssh.org")
set(CTEST_DROP_LOCATION "/submit.php?project=libssh")
set(CTEST_DROP_SITE_CDASH TRUE)

268
ChangeLog
View File

@@ -1,6 +1,266 @@
ChangeLog
==========
version 0.7.0 (released 2015-05-11)
* Added support for ed25519 keys
* Added SHA2 algorithms for HMAC
* Added improved and more secure buffer handling code
* Added callback for auth_none_function
* Added support for ECDSA private key signing
* Added more tests
* Fixed a lot of bugs
* Improved API documentation
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.
* Fixed bugged lists.
* Fixed use-after-free + inconsistent callbacks call in poll.
* Fixed scp documentation.
* Fixed possible infinite loop in channel_read().
* Fixed handling of short reads of sftp_async_read().
* Fixed handling request service timeout in blocking mode.
* Fixed ssh_auth_list() documentation.
* Fixed incorrect return values in ssh_channel_write().
* Fixed an infinite loop in the termination callback.
* Fixed handling of SSH_AGAIN in channel_open().
* Fixed "status -5 inflating zlib packet"
version 0.5.1 (released 2011-08-09)
* Added checks for NULL pointers in string.c.
* Set the channel max packet size to 32768.
* Don't (de)compress empty buffers.
* Fixed ssh_scp_write so it works when doing recursive copy.
* Fixed another source of endless wait.
* Fixed an endless loop in case of a channel_open error.
* Fixed session timeout handling.
* Fixed ssh_channel_from_local() loop.
* Fixed permissions of scp example when we copy a file.
* Workaround ssh_get_user_home_dir on LDAP users.
* Added pkg-config support for libssh_threads.
* Fixed compilation without server and sftp modes.
* Fix static .lib overwriting on Windows.
version 0.5.0 (released 2011-06-01)
* Added ssh_ prefix to all functions.
* Added complete Windows support.
* Added improved server support.
* Added unit tests for a lot of functions.
* Added asynchronous service request.
* Added a multiplatform ssh_getpass() function.
* Added a tutorial.
* Added a lot of documentation.
* Fixed a lot of bugs.
* Fixed several memory leaks.
version 0.4.8 (released 2011-01-15)
* Fixed memory leaks in session signing.
* Fixed memory leak in ssh_print_hexa.
* Fixed problem with ssh_connect w/ timeout and fd > 1024.
* Fixed some warnings on OS/2.
* Fixed installation path for OS/2.
version 0.4.7 (released 2010-12-28)
* Fixed a possible memory leak in ssh_get_user_home().
* Fixed a memory leak in sftp_xstat.
* Fixed uninitialized fd->revents member.
* Fixed timout value in ssh_channel_accept().
* Fixed length checks in ssh_analyze_banner().
* Fixed a possible data overread and crash bug.
* Fixed setting max_fd which breaks ssh_select().
* Fixed some pedantic build warnings.
* Fixed a memory leak with session->bindaddr.
version 0.4.6 (released 2010-09-03)
* Added a cleanup function to free the ws2_32 library.
* Fixed build with gcc 3.4.
* Fixed the Windows build on Vista and newer.
* Fixed the usage of WSAPoll() on Windows.
* Fixed "@deprecated" in doxygen
* Fixed some mingw warnings.
* Fixed handling of opened channels.
* Fixed keepalive problem on older openssh servers.
* Fixed testing for big endian on Windows.
* Fixed the Windows preprocessor macros and defines.
version 0.4.5 (released 2010-07-13)
* Added option to bind a client to an ip address.
* Fixed the ssh socket polling function.
* Fixed Windows related bugs in bsd_poll().
* Fixed serveral build warnings.
version 0.4.4 (released 2010-06-01)
* Fixed a bug in the expand function for escape sequences.
* Fixed a bug in the tilde expand function.
* Fixed a bug in setting the options.
version 0.4.3 (released 2010-05-18)
* Added global/keepalive responses.
* Added runtime detection of WSAPoll().
* Added a select(2) based poll-emulation if poll(2) is not available.
* Added a function to expand an escaped string.
* Added a function to expand the tilde from a path.
* Added a proxycommand support.
* Added ssh_privatekey_type public function
* Added the possibility to define _OPENSSL_DIR and _ZLIB_DIR.
* Fixed sftp_chown.
* Fixed sftp_rename on protocol version 3.
* Fixed a blocking bug in channel_poll.
* Fixed config parsing wich has overwritten user specified values.
* Fixed hashed [host]:port format in knownhosts
* Fixed Windows build.
* Fixed doublefree happening after a negociation error.
* Fixed aes*-ctr with <= OpenSSL 0.9.7b.
* Fixed some documentation.
* Fixed exec example which has broken read usage.
* Fixed broken algorithm choice for server.
* Fixed a typo that we don't export all symbols.
* Removed the unneeded dependency to doxygen.
* Build examples only on the Linux plattform.
version 0.4.2 (released 2010-03-15)
* Added owner and group information in sftp attributes.
* Added missing SSH_OPTIONS_FD option.
* Added printout of owner and group in the sftp example.
* Added a prepend function for ssh_list.
* Added send back replies to openssh's keepalives.
* Fixed documentation in scp code
* Fixed longname parsing, this only workings with readdir.
* Fixed and added support for several identity files.
* Fixed sftp_parse_longname() on Windows.
* Fixed a race condition bug in ssh_scp_close()
* Remove config support for SSHv1 Cipher variable.
* Rename ssh_list_add to ssh_list_append.
* Rename ssh_list_get_head to ssh_list_pop_head
version 0.4.1 (released 2010-02-13)
* Added support for aes128-ctr, aes192-ctr and aes256-ctr encryption.
* Added an example for exec.
* Added private key type detection feature in privatekey_from_file().
* Fixed zlib compression fallback.
* Fixed kex bug that client preference should be prioritary
* Fixed known_hosts file set by the user.
* Fixed a memleak in channel_accept().
* Fixed underflow when leave_function() are unbalanced
* Fixed memory corruption in handle_channel_request_open().
* Fixed closing of a file handle case of errors in privatekey_from_file().
* Fixed ssh_get_user_home_dir() to be thread safe.
* Fixed the doxygen documentation.
version 0.4.0 (released 2009-12-10)
* Added scp support.
* Added support for sending signals (RFC 4254, section 6.9).
* Added MSVC support.
* Added support for ~/.ssh/config.
* Added sftp extension support.
* Added X11 forwarding support for client.
* Added forward listening.
* Added support for openssh extensions (statvfs, fstatvfs).
* Added a cleaned up interface for setting options.
* Added a generic way to handle sockets asynchronously.
* Added logging of the sftp flags used to open a file.
* Added full poll() support and poll-emulation for win32.
* Added missing 64bit functions in sftp.
* Added support for ~/ and SSH_DIR/ in filenames instead of %s/.
* Fixed Fix channel_get_exit_status bug.
* Fixed calltrace logging to make it optional.
* Fixed compilation on Solaris.
* Fixed resolving of ip addresses.
* Fixed libssh compilation without server support.
* Fixed possible memory corruptions (ticket #14).
version 0.3.4 (released 2009-09-14)
* Added ssh_basename and ssh_dirname.
* Added a portable ssh_mkdir function.
@@ -28,6 +288,14 @@ version 0.3.2 (released 2009-08-05)
* Fixed compilation on Solaris.
* Fixed SSHv1 compilation.
version 0.3.1 (released 2009-07-14)
* Added return code SSH_SERVER_FILE_NOT_FOUND.
* Fixed compilation of SSHv1.
* Fixed several memory leaks.
* Fixed possible infinite loops.
* Fixed a possible crash bug.
* Fixed build warnings.
* Fixed cmake on BSD.
version 0.3.1 (released 2009-07-14)
* Added return code SSH_SERVER_FILE_NOT_FOUND.
* Fixed compilation of SSHv1.

View File

@@ -4,6 +4,7 @@ include(CheckFunctionExists)
include(CheckLibraryExists)
include(CheckTypeSize)
include(CheckCXXSourceCompiles)
include(TestBigEndian)
set(PACKAGE ${APPLICATION_NAME})
set(VERSION ${APPLICATION_VERSION})
@@ -15,42 +16,241 @@ set(SYSCONFDIR ${SYSCONF_INSTALL_DIR})
set(BINARYDIR ${CMAKE_BINARY_DIR})
set(SOURCEDIR ${CMAKE_SOURCE_DIR})
function(COMPILER_DUMPVERSION _OUTPUT_VERSION)
# Remove whitespaces from the argument.
# This is needed for CC="ccache gcc" cmake ..
string(REPLACE " " "" _C_COMPILER_ARG "${CMAKE_C_COMPILER_ARG1}")
execute_process(
COMMAND
${CMAKE_C_COMPILER} ${_C_COMPILER_ARG} -dumpversion
OUTPUT_VARIABLE _COMPILER_VERSION
)
string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2"
_COMPILER_VERSION "${_COMPILER_VERSION}")
set(${_OUTPUT_VERSION} ${_COMPILER_VERSION} PARENT_SCOPE)
endfunction()
if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
compiler_dumpversion(GNUCC_VERSION)
if (NOT GNUCC_VERSION EQUAL 34)
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)
# HEADER FILES
check_include_file(argp.h HAVE_ARGP_H)
check_include_file(pty.h HAVE_PTY_H)
check_include_file(terminos.h HAVE_TERMIOS_H)
check_include_file(utmp.h HAVE_UTMP_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(libutil.h HAVE_LIBUTIL_H)
check_include_file(sys/time.h HAVE_SYS_TIME_H)
check_include_file(sys/param.h HAVE_SYS_PARAM_H)
check_include_file(arpa/inet.h HAVE_ARPA_INET_H)
check_include_file(openssl/aes.h HAVE_OPENSSL_AES_H)
check_include_file(openssl/blowfish.h HAVE_OPENSSL_BLOWFISH_H)
check_include_file(openssl/des.h HAVE_OPENSSL_DES_H)
# FUNCTIONS
check_function_exists(cfmakeraw HAVE_CFMAKERAW)
if (WIN32)
set(HAVE_GETADDRINFO TRUE)
set(HAVE_GETHOSTBYNAME TRUE)
set(HAVE_SELECT TRUE)
else (WIN32)
check_function_exists(getaddrinfo HAVE_GETADDRINFO)
check_function_exists(gethostbyname HAVE_GETHOSTBYNAME)
check_function_exists(poll HAVE_POLL)
check_function_exists(select HAVE_SELECT)
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_files("winsock2.h;ws2tcpip.h" HAVE_WS2TCPIP_H)
endif (WIN32)
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
check_include_file(openssl/aes.h HAVE_OPENSSL_AES_H)
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
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(HAVE_GETADDRINFO TRUE)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} socket)
endif (HAVE_LIBSOCKET)
# libnsl/inet_pton (Solaris)
check_library_exists(nsl inet_pton "" HAVE_LIBNSL)
if (HAVE_LIBNSL)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} nsl)
endif (HAVE_LIBNSL)
# librt
check_library_exists(rt nanosleep "" HAVE_LIBRT)
endif (NOT LINUX)
check_library_exists(rt clock_gettime "" HAVE_CLOCK_GETTIME)
if (HAVE_LIBRT OR HAVE_CLOCK_GETTIME)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt)
endif (HAVE_LIBRT OR HAVE_CLOCK_GETTIME)
check_library_exists(util forkpty "" HAVE_LIBUTIL)
check_function_exists(cfmakeraw HAVE_CFMAKERAW)
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")
# LIBRARIES
if (CRYPTO_FOUND)
if (OPENSSL_FOUND)
set(HAVE_LIBCRYPTO 1)
endif (CRYPTO_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 (Z_LIBRARY)
set(HAVE_LIBZ 1)
endif (Z_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>
#define __VA_NARG__(...) (__VA_NARG_(_0, ## __VA_ARGS__, __RSEQ_N()) - 1)
#define __VA_NARG_(...) __VA_ARG_N(__VA_ARGS__)
#define __VA_ARG_N( _1, _2, _3, _4, _5, _6, _7, _8, _9,_10,N,...) N
#define __RSEQ_N() 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
#define myprintf(format, ...) printf((format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__)
int main(void) {
myprintf(\"%d %d %d %d\",1,2,3);
return 0;
}" HAVE_GCC_NARG_MACRO)
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)
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)
endif (NOT WIN32)

View File

@@ -1,6 +1,33 @@
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)
option(WITH_STATIC_LIB "Build with a static library" OFF)
option(WITH_DEBUG_CRYPTO "Build with cryto debut output" OFF)
option(WITH_DEBUG_CRYPTO "Build with cryto debug output" OFF)
option(WITH_DEBUG_CALLTRACE "Build with calltrace debug output" ON)
option(WITH_GCRYPT "Compile against libgcrypt" OFF)
option(WITH_PCAP "Compile with Pcap generation support" ON)
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)
endif(WITH_BENCHMARKS)
if (WITH_TESTING)
set(WITH_STATIC_LIB ON)
endif (WITH_TESTING)
if (WITH_NACL)
set(WITH_NACL ON)
endif (WITH_NACL)

1272
Doxyfile

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

29
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,9 @@ 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.
## About this document

164
README
View File

@@ -1,14 +1,21 @@
The libSSH and its client
~~~~~~~~~~~~~~~~~~~~~~~~~
-Aris Adamantiadis
_ _ _ _
(_) (_) (_) (_)
(_) _ (_) _ _ _ _ _ (_) _
(_) (_) (_)(_) _ (_)(_) (_)(_) (_)(_) _
(_) (_) (_) (_) _ (_) _ (_) (_) (_)
(_) (_) (_)(_)(_) (_)(_) (_)(_) (_) (_).org
The SSH library
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1* Why ?
-_-_-_-_-_
Why not ? :) I've began to work on my own implementation of the ssh protocol
because i didn't like the currently public ones.
Not any allow you to import and use the functions as a library, and so i
worked on a library-based SSH implementation.
Not any allowed you to import and use the functions as a powerful library,
and so i worked on a library-based SSH implementation which was non-existing
in the free and open source software world.
2* How/Who ?
@@ -16,24 +23,141 @@ worked on a library-based SSH implementation.
If you downloaded this file, you must know what it is : a library for
accessing ssh client services through C libraries calls in a simple manner.
The client is there as a programming example and isn't at all doing its job
correctly (doesn't verify public key hashes with the ones in ~/.ssh/
and doesn't handle TERM - yet)
Everybody can use this software under the terms of the LGPL - see the COPYING
file
3* What ?
-_-_-_-_-_
If you ask yourself how to compile libssh, please read INSTALL before anything.
The SSH library features :
-Full C library functions for manipulating a client-side SSH connection
-Fully configurable sessions
-Support for AES-128,AES-192,AES-256,blowfish, in cbc mode
-use multiple SSH connections in a same process, at same time.
-usable SFTP implementation
-Public key and password authentication
4* Where ?
3* Where ?
-_-_-_-_-_-_
http://0xbadc0de.be/?part=libssh
http://www.libssh.org
4* API Changes !
-_-_-_-_-_-_-_-_-_
Changes between 0.4 and 0.5
---------------------------
We use the ssh_ prefix as namespace for every function now. There is a legacy.h
which could be used to get the old function names.
Changes between 0.3 and 0.4
---------------------------
We changed libssh to be typesafe now:
SSH_SESSION *session -> ssh_session session
SFTP_SESSION *sftp -> sftp_session sftp
CHANNEL *channel -> ssh_channel channel
STRING *string -> ssh_string string
...
The options structure has been removed and there is a new function. This
function can set all available options now. You can find the enum in the
header file and it is documented. Example:
ssh_options_set(session, SSH_OPTIONS_HOST, "localhost");
5* Copyright policy
-_-_-_-_-_-_-_-_-_-_
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.
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.
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

354
README.CodingStyle Normal file
View File

@@ -0,0 +1,354 @@
Coding conventions in the libssh tree
======================================
===========
Quick Start
===========
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 (See
Documentation/CodingStyle in the kernel source tree). This closely matches what
libssh developers use already anyways, with a few exceptions as mentioned
below.
But to save you the trouble of reading the Linux kernel style guide, 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 Whitespace
Clean up your files before committing.
* 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?
=============
Editor Hints
=============
Emacs
------
Add the follow to your $HOME/.emacs file:
(add-hook 'c-mode-hook
(lambda ()
(c-set-style "linux")
(c-toggle-auto-state)))
Vim
----
For the basic vi editor included with all variants of \*nix, add the
following to $HOME/.vimrc:
set ts=4 sw=4 et cindent
You can use the Vim gitmodline plugin to store this in the git config:
http://git.cryptomilk.org/projects/vim-gitmodeline.git/
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.\+/'
==========================
FAQ & Statement Reference
==========================
Comments
---------
Comments should always use the standard C syntax. C++ style comments are not
currently allowed.
The lines before a comment should be empty. If the comment directly belongs to
the following code, there should be no empty line after the comment, except if
the comment contains a summary of multiple following code blocks.
This is good:
...
int i;
/*
* This is a multi line comment,
* which explains the logical steps we have to do:
*
* 1. We need to set i=5, because...
* 2. We need to call complex_fn1
*/
/* This is a one line comment about i = 5. */
i = 5;
/*
* This is a multi line comment,
* explaining the call to complex_fn1()
*/
ret = complex_fn1();
if (ret != 0) {
...
/**
* @brief This is a doxygen comment.
*
* This is a more detailed explanation of
* this simple function.
*
* @param[in] param1 The parameter value of the function.
*
* @param[out] result1 The result value of the function.
*
* @return 0 on success and -1 on error.
*/
int example(int param1, int *result1);
This is bad:
...
int i;
/*
* This is a multi line comment,
* which explains the logical steps we have to do:
*
* 1. We need to set i=5, because...
* 2. We need to call complex_fn1
*/
/* This is a one line comment about i = 5. */
i = 5;
/*
* This is a multi line comment,
* explaining the call to complex_fn1()
*/
ret = complex_fn1();
if (ret != 0) {
...
/*This is a one line comment.*/
/* This is a multi line comment,
with some more words...*/
/*
* This is a multi line comment,
* with some more words...*/
Indention & Whitespace & 80 columns
------------------------------------
To avoid confusion, indentations have to be 4 spaces. Do not use tabs!. When
wrapping parameters for function calls, align the parameter list with the first
parameter on the previous line. For example,
var1 = foo(arg1,
arg2,
arg3);
The previous example is intended to illustrate alignment of function
parameters across lines and not as encourage for gratuitous line
splitting. Never split a line before columns 70 - 79 unless you
have a really good reason. Be smart about formatting.
If, switch, & Code blocks
--------------------------
Always follow an 'if' keyword with a space but don't include additional
spaces following or preceding the parentheses in the conditional.
This is good:
if (x == 1)
This is bad:
if ( x == 1 )
or
if (x==1)
Yes we have a lot of code that uses the second and third form and we are trying
to clean it up without being overly intrusive.
Note that this is a rule about parentheses following keywords and not
functions. Don't insert a space between the name and left parentheses when
invoking functions.
Braces for code blocks used by for, if, switch, while, do..while, etc. should
begin on the same line as the statement keyword and end on a line of their own.
You should always include braces, even if the block only contains one
statement. NOTE: Functions are different and the beginning left brace should
be located in the first column on the next line.
If the beginning statement has to be broken across lines due to length, the
beginning brace should be on a line of its own.
The exception to the ending rule is when the closing brace is followed by
another language keyword such as else or the closing while in a do..while loop.
Good examples:
if (x == 1) {
printf("good\n");
}
for (x = 1; x < 10; x++) {
print("%d\n", x);
}
for (really_really_really_really_long_var_name = 0;
really_really_really_really_long_var_name < 10;
really_really_really_really_long_var_name++)
{
print("%d\n", really_really_really_really_long_var_name);
}
do {
printf("also good\n");
} while (1);
Bad examples:
while (1)
{
print("I'm in a loop!\n"); }
for (x=1;
x<10;
x++)
{
print("no good\n");
}
if (i < 10)
print("I should be in braces.\n");
Goto
-----
While many people have been academically taught that "goto"s are fundamentally
evil, they can greatly enhance readability and reduce memory leaks when used as
the single exit point from a function. But in no libssh world what so ever is a
goto outside of a function or block of code a good idea.
Good Examples:
int function foo(int y)
{
int *z = NULL;
int rc = 0;
if (y < 10) {
z = malloc(sizeof(int)*y);
if (z == NULL) {
rc = 1;
goto done;
}
}
print("Allocated %d elements.\n", y);
done:
if (z != NULL) {
free(z);
}
return rc;
}
Typedefs
---------
libssh tries to avoid "typedef struct { .. } x_t;" so we do always try to use
"struct x { .. };". We know there are still such typedefs in the code, but for
new code, please don't do that anymore.
Make use of helper variables
-----------------------------
Please try to avoid passing function calls as function parameters in new code.
This makes the code much easier to read and it's also easier to use the "step"
command within gdb.
Good Example:
char *name;
name = get_some_name();
if (name == NULL) {
...
}
rc = some_function_my_name(name);
...
Bad Example:
rc = some_function_my_name(get_some_name());
...
Please try to avoid passing function return values to if- or while-conditions.
The reason for this is better handling of code under a debugger.
Good example:
x = malloc(sizeof(short) * 10);
if (x == NULL) {
fprintf(stderr, "Unable to alloc memory!\n");
}
Bad example:
if ((x = malloc(sizeof(short)*10)) == NULL ) {
fprintf(stderr, "Unable to alloc memory!\n");
}
There are exceptions to this rule. One example is walking a data structure in
an iterator style:
while ((opt = poptGetNextOpt(pc)) != -1) {
... do something with opt ...
}
But in general, please try to avoid this pattern.
Control-Flow changing macros
-----------------------------
Macros like STATUS_NOT_OK_RETURN that change control flow (return/goto/etc)
from within the macro are considered bad, because they look like function calls
that never change control flow. Please do not introduce them.

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

@@ -0,0 +1,30 @@
# - ADD_CHECK_TEST(test_name test_source linklib1 ... linklibN)
# Copyright (c) 2007 Daniel Gollub <dgollub@suse.de>
# 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.
enable_testing()
include(CTest)
if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
# Profiling
set(CMAKE_C_FLAGS_PROFILING "-g -O0 -Wall -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wwrite-strings -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Compiler Flags")
set(CMAKE_SHARED_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags")
set(CMAKE_MODULE_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags")
set(CMAKE_EXEC_LINKER_FLAGS_PROFILING " -fprofile-arcs -ftest-coverage" CACHE STRING "Profiling Linker Flags")
# Address Sanitizer
set(CMAKE_C_FLAGS_ADDRESSSANITIZER "-g -O1 -fsanitize=address -fno-omit-frame-pointer" CACHE STRING "Address sanitizer compiler flags")
set(CMAKE_SHARED_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address" CACHE STRING "Address sanitizer shared linker flags")
set(CMAKE_MODULE_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address" CACHE STRING "Address sanitizer module linker flags")
set(CMAKE_EXEC_LINKER_FLAGS_ADDRESSSANITIZER "-fsanitize=address" CACHE STRING "Address sanitizer executable linker flags")
endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW)
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_CMOCKA_TEST)

View File

@@ -0,0 +1,26 @@
# - 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 check_c_source_compiles.
# See help for CheckCSourceCompiles for a listing of variables
# that can modify the build.
# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
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,50 +1,84 @@
# define system dependent compiler flags
include(CheckCCompilerFlag)
include(CheckCCompilerFlagSSP)
if (UNIX AND NOT WIN32)
if (CMAKE_COMPILER_IS_GNUCC)
add_definitions(-Wall -Wextra -Wmissing-prototypes -Wdeclaration-after-statement -Wunused)
#
# Define GNUCC compiler flags
#
if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)")
# with -fPIC
check_c_compiler_flag("-fPIC" WITH_FPIC)
if (WITH_FPIC)
add_definitions(-fPIC)
endif (WITH_FPIC)
# 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")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused -Wfloat-equal -Wpointer-arith -Wwrite-strings -Wformat-security")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-format-attribute")
# with -fPIC
check_c_compiler_flag("-fPIC" WITH_FPIC)
if (WITH_FPIC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
endif (WITH_FPIC)
check_c_compiler_flag_ssp("-fstack-protector" WITH_STACK_PROTECTOR)
if (WITH_STACK_PROTECTOR)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
endif (WITH_STACK_PROTECTOR)
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
#
if (CMAKE_SIZEOF_VOID_P MATCHES "8")
# with large file support
execute_process(
COMMAND
getconf LFS64_CFLAGS
OUTPUT_VARIABLE
_lfs_CFLAGS
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# with large file support
execute_process(
COMMAND
getconf LFS64_CFLAGS
OUTPUT_VARIABLE
_lfs_CFLAGS
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
else (CMAKE_SIZEOF_VOID_P MATCHES "8")
# with large file support
execute_process(
COMMAND
getconf LFS_CFLAGS
OUTPUT_VARIABLE
_lfs_CFLAGS
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX REPLACE "[\r\n]" " " "${_lfs_CFLAGS}" "${${_lfs_CFLAGS}}")
add_definitions(${_lfs_CFLAGS})
# with large file support
execute_process(
COMMAND
getconf LFS_CFLAGS
OUTPUT_VARIABLE
_lfs_CFLAGS
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif (CMAKE_SIZEOF_VOID_P MATCHES "8")
if (_lfs_CFLAGS)
string(REGEX REPLACE "[\r\n]" " " "${_lfs_CFLAGS}" "${${_lfs_CFLAGS}}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_lfs_CFLAGS}")
endif (_lfs_CFLAGS)
check_c_compiler_flag("-fstack-protector" WITH_STACK_PROTECTOR)
if (WITH_STACK_PROTECTOR)
add_definitions(-fstack-protector)
endif (WITH_STACK_PROTECTOR)
check_c_compiler_flag("-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE)
if (WITH_FORTIFY_SOURCE)
add_definitions(-D_FORTIFY_SOURCE=2)
endif (WITH_FORTIFY_SOURCE)
endif (CMAKE_COMPILER_IS_GNUCC)
endif (UNIX AND NOT WIN32)
if (MSVC)
# Use secure functions by defaualt and suppress warnings about
#"deprecated" functions
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES=1")
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,4 +1,4 @@
if (UNIX)
if (UNIX OR OS2)
IF (NOT APPLICATION_NAME)
MESSAGE(STATUS "${PROJECT_NAME} is used as APPLICATION_NAME")
SET(APPLICATION_NAME ${PROJECT_NAME})
@@ -47,6 +47,10 @@ if (UNIX)
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})"
@@ -90,18 +94,16 @@ if (UNIX)
"${SHARE_INSTALL_PREFIX}/info"
CACHE PATH "The ${APPLICATION_NAME} info install dir (default prefix/info)"
)
endif (UNIX)
if (WIN32)
else()
# Same same
set(BIN_INSTALL_DIR "." CACHE PATH "-")
set(SBIN_INSTALL_DIR "." CACHE PATH "-")
set(LIB_INSTALL_DIR "lib" CACHE PATH "-")
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 "." CACHE PATH "-")
set(SOUND_INSTALL_DIR "." CACHE PATH "-")
set(ICON_INSTALL_DIR "icons" CACHE PATH "-")
set(SOUND_INSTALL_DIR "soudns" CACHE PATH "-")
set(LOCALE_INSTALL_DIR "lang" CACHE PATH "-")
endif (WIN32)
endif ()

View File

@@ -0,0 +1,32 @@
# Set system vars
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
set(LINUX TRUE)
endif(CMAKE_SYSTEM_NAME MATCHES "Linux")
if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(FREEBSD TRUE)
set(BSD TRUE)
endif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
set(OPENBSD TRUE)
set(BSD TRUE)
endif (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
if (CMAKE_SYSTEM_NAME MATCHES "NetBSD")
set(NETBSD TRUE)
set(BSD TRUE)
endif (CMAKE_SYSTEM_NAME MATCHES "NetBSD")
if (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)")
set(SOLARIS TRUE)
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

@@ -0,0 +1,60 @@
# - Try to find Argp
# Once done this will define
#
# ARGP_FOUND - system has Argp
# ARGP_INCLUDE_DIRS - the Argp include directory
# ARGP_LIBRARIES - Link these to use Argp
# ARGP_DEFINITIONS - Compiler switches required for using Argp
#
# 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 (ARGP_LIBRARIES AND ARGP_INCLUDE_DIRS)
# in cache already
set(ARGP_FOUND TRUE)
else (ARGP_LIBRARIES AND ARGP_INCLUDE_DIRS)
find_path(ARGP_INCLUDE_DIR
NAMES
argp.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
/sw/include
)
find_library(ARGP_LIBRARY
NAMES
argp
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
set(ARGP_INCLUDE_DIRS
${ARGP_INCLUDE_DIR}
)
if (ARGP_LIBRARY)
set(ARGP_LIBRARIES
${ARGP_LIBRARIES}
${ARGP_LIBRARY}
)
endif (ARGP_LIBRARY)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Argp DEFAULT_MSG ARGP_LIBRARIES ARGP_INCLUDE_DIRS)
# show the ARGP_INCLUDE_DIRS and ARGP_LIBRARIES variables only in the advanced view
mark_as_advanced(ARGP_INCLUDE_DIRS ARGP_LIBRARIES)
endif (ARGP_LIBRARIES AND ARGP_INCLUDE_DIRS)

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

@@ -6,72 +6,70 @@
# GCRYPT_LIBRARIES - Link these to use GCrypt
# GCRYPT_DEFINITIONS - Compiler switches required for using GCrypt
#
# Copyright (c) 2009 Andreas Schneider <mail@cynapses.org>
#=============================================================================
# Copyright (c) 2009-2012 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.
# 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(_GCRYPT_ROOT_HINTS
$ENV{GCRYTPT_ROOT_DIR}
${GCRYPT_ROOT_DIR})
if (GCRYPT_LIBRARIES AND GCRYPT_INCLUDE_DIRS)
# in cache already
set(GCRYPT_FOUND TRUE)
else (GCRYPT_LIBRARIES AND GCRYPT_INCLUDE_DIRS)
set(_GCRYPT_ROOT_PATHS
"$ENV{PROGRAMFILES}/libgcrypt")
find_path(GCRYPT_INCLUDE_DIR
set(_GCRYPT_ROOT_HINTS_AND_PATHS
HINTS ${_GCRYPT_ROOT_HINTS}
PATHS ${_GCRYPT_ROOT_PATHS})
find_path(GCRYPT_INCLUDE_DIR
NAMES
gcrypt.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
/sw/include
)
mark_as_advanced(GCRYPT_INCLUDE_DIR)
gcrypt.h
HINTS
${_GCRYPT_ROOT_HINTS_AND_PATHS}
)
find_library(GCRYPT_LIBRARY
find_library(GCRYPT_LIBRARY
NAMES
gcrypt
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
mark_as_advanced(GCRYPT_LIBRARY)
gcrypt
gcrypt11
libgcrypt-11
HINTS
${_GCRYPT_ROOT_HINTS_AND_PATHS}
)
set(GCRYPT_LIBRARIES ${GCRYPT_LIBRARY})
if (GCRYPT_LIBRARY)
set(GCRYPT_FOUND TRUE CACHE INTERNAL "Wether the gcrypt library has been found" FORCE)
endif (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]+\"")
set(GCRYPT_INCLUDE_DIRS
${GCRYPT_INCLUDE_DIR}
)
string(REGEX REPLACE "^.*GCRYPT_VERSION.*([0-9]+.[0-9]+.[0-9]+).*" "\\1" GCRYPT_VERSION "${_gcrypt_version_str}")
endif (GCRYPT_INCLUDE_DIR)
if (GCRYPT_FOUND)
set(GCRYPT_LIBRARIES
${GCRYPT_LIBRARIES}
${GCRYPT_LIBRARY}
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"
)
endif (GCRYPT_FOUND)
if (GCRYPT_INCLUDE_DIRS AND GCRYPT_LIBRARIES)
set(GCRYPT_FOUND TRUE)
endif (GCRYPT_INCLUDE_DIRS AND GCRYPT_LIBRARIES)
if (GCRYPT_FOUND)
if (NOT GCrypt_FIND_QUIETLY)
message(STATUS "Found GCrypt: ${GCRYPT_LIBRARIES}")
endif (NOT GCrypt_FIND_QUIETLY)
else (GCRYPT_FOUND)
if (GCrypt_FIND_REQUIRED)
message(FATAL_ERROR "Could not find GCrypt")
endif (GCrypt_FIND_REQUIRED)
endif (GCRYPT_FOUND)
# 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)
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)
# 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

@@ -0,0 +1,55 @@
# - Try to find NSIS
# Once done this will define
#
# 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-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.
#=============================================================================
#
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}
)
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

@@ -1,159 +0,0 @@
# - Try to find OpenSSL
# Once done this will define
#
# OPENSSL_FOUND - system has OpenSSL
# OPENSSL_INCLUDE_DIRS - the OpenSSL include directory
# OPENSSL_LIBRARIES - Link these to use OpenSSL
# OPENSSL_DEFINITIONS - Compiler switches required for using OpenSSL
#
# Copyright (c) 2009 Andreas Schneider <mail@cynapses.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 (OPENSSL_LIBRARIES AND OPENSSL_INCLUDE_DIRS)
# in cache already
set(OPENSSL_FOUND TRUE)
else (OPENSSL_LIBRARIES AND OPENSSL_INCLUDE_DIRS)
# use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
include(UsePkgConfig)
pkgconfig(openssl _OPENSSL_INCLUDEDIR _OPENSSL_LIBDIR _OPENSSL_LDFLAGS _OPENSSL_CFLAGS)
else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(_OPENSSL openssl)
endif (PKG_CONFIG_FOUND)
endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
find_path(OPENSSL_INCLUDE_DIR
NAMES
openssl/ssl.h
PATHS
${_OPENSSL_INCLUDEDIR}
/usr/include
/usr/local/include
/opt/local/include
/sw/include
)
mark_as_advanced(OPENSSL_INCLUDE_DIR)
find_library(SSL_LIBRARY
NAMES
ssl
PATHS
${_OPENSSL_LIBDIR}
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
mark_as_advanced(SSL_LIBRARY)
find_library(SSLEAY32_LIBRARY
NAMES
ssleay32
PATHS
${_OPENSSL_LIBDIR}
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
mark_as_advanced(SSLEAY32_LIBRARY)
find_library(SSLEAY32MD_LIBRARY
NAMES
ssleay32MD
PATHS
${_OPENSSL_LIBDIR}
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
mark_as_advanced(SSLEAY32MD_LIBRARY)
find_library(CRYPTO_LIBRARY
NAMES
crypto
PATHS
${_OPENSSL_LIBDIR}
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
mark_as_advanced(CRYPTO_LIBRARY)
if (SSL_LIBRARY)
set(SSL_FOUND TRUE CACHE INTERNAL "Wether the ssl library has been found" FORCE)
endif (SSL_LIBRARY)
if (SSLEAY32_LIBRARY)
set(SSLEAY32_FOUND TRUE CACHE INTERNAL "Wether the ssleay32 library has been found" FORCE)
endif (SSLEAY32_LIBRARY)
if (SSLEAY32MD_LIBRARY)
set(SSLEAY32MD_FOUND TRUE CACHE INTERNAL "Wether the ssleay32MD library has been found" FORCE)
endif (SSLEAY32MD_LIBRARY)
if (CRYPTO_LIBRARY)
set(CRYPTO_FOUND TRUE CACHE INTERNAL "Wether the crypto library has been found" FORCE)
endif (CRYPTO_LIBRARY)
set(OPENSSL_INCLUDE_DIRS
${OPENSSL_INCLUDE_DIR}
)
if (SSL_FOUND)
set(OPENSSL_LIBRARIES
${OPENSSL_LIBRARIES}
${SSL_LIBRARY}
)
endif (SSL_FOUND)
if (SSLEAY32_FOUND)
set(OPENSSL_LIBRARIES
${OPENSSL_LIBRARIES}
${SSLEAY32_LIBRARY}
)
endif (SSLEAY32_FOUND)
if (SSLEAY32MD_FOUND)
set(OPENSSL_LIBRARIES
${OPENSSL_LIBRARIES}
${SSLEAY32MD_LIBRARY}
)
endif (SSLEAY32MD_FOUND)
if (CRYPTO_FOUND)
set(OPENSSL_LIBRARIES
${OPENSSL_LIBRARIES}
${CRYPTO_LIBRARY}
)
endif (CRYPTO_FOUND)
if (OPENSSL_INCLUDE_DIRS AND OPENSSL_LIBRARIES)
set(OPENSSL_FOUND TRUE)
endif (OPENSSL_INCLUDE_DIRS AND OPENSSL_LIBRARIES)
if (OPENSSL_FOUND)
if (NOT OpenSSL_FIND_QUIETLY)
message(STATUS "Found OpenSSL: ${OPENSSL_LIBRARIES}")
endif (NOT OpenSSL_FIND_QUIETLY)
else (OPENSSL_FOUND)
if (OpenSSL_FIND_REQUIRED)
message(FATAL_ERROR "Could not find OpenSSL")
endif (OpenSSL_FIND_REQUIRED)
endif (OPENSSL_FOUND)
# show the OPENSSL_INCLUDE_DIRS and OPENSSL_LIBRARIES variables only in the advanced view
mark_as_advanced(OPENSSL_INCLUDE_DIRS OPENSSL_LIBRARIES)
endif (OPENSSL_LIBRARIES AND OPENSSL_INCLUDE_DIRS)

View File

@@ -1,79 +0,0 @@
# - Try to find ZLIB
# Once done this will define
#
# ZLIB_FOUND - system has ZLIB
# ZLIB_INCLUDE_DIRS - the ZLIB include directory
# ZLIB_LIBRARIES - Link these to use ZLIB
# ZLIB_DEFINITIONS - Compiler switches required for using ZLIB
#
# Copyright (c) 2009 Andreas Schneider <mail@cynapses.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 (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)
# in cache already
set(ZLIB_FOUND TRUE)
else (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)
find_path(ZLIB_INCLUDE_DIR
NAMES
zlib.h
PATHS
/usr/include
/usr/local/include
/opt/local/include
/sw/include
)
mark_as_advanced(ZLIB_INCLUDE_DIR)
find_library(Z_LIBRARY
NAMES
z
zlib
zlib1
PATHS
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
mark_as_advanced(Z_LIBRARY)
if (Z_LIBRARY)
set(Z_FOUND TRUE)
endif (Z_LIBRARY)
set(ZLIB_INCLUDE_DIRS
${ZLIB_INCLUDE_DIR}
)
if (Z_FOUND)
set(ZLIB_LIBRARIES
${ZLIB_LIBRARIES}
${Z_LIBRARY}
)
endif (Z_FOUND)
if (ZLIB_INCLUDE_DIRS AND ZLIB_LIBRARIES)
set(ZLIB_FOUND TRUE)
endif (ZLIB_INCLUDE_DIRS AND ZLIB_LIBRARIES)
if (ZLIB_FOUND)
if (NOT ZLIB_FIND_QUIETLY)
message(STATUS "Found ZLIB: ${ZLIB_LIBRARIES}")
endif (NOT ZLIB_FIND_QUIETLY)
else (ZLIB_FOUND)
if (ZLIB_FIND_REQUIRED)
message(FATAL_ERROR "Could not find ZLIB")
endif (ZLIB_FIND_REQUIRED)
endif (ZLIB_FOUND)
# show the ZLIB_INCLUDE_DIRS and ZLIB_LIBRARIES variables only in the advanced view
mark_as_advanced(ZLIB_INCLUDE_DIRS ZLIB_LIBRARIES)
endif (ZLIB_LIBRARIES AND ZLIB_INCLUDE_DIRS)

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

@@ -1,127 +1,140 @@
# -helper macro to add a "doc" target with CMake build system.
# and configure doxy.config.in to doxy.config
# - Run Doxygen
#
# target "doc" allows building the documentation with doxygen/dot on WIN32 and Linux
# Creates .chm windows help file if MS HTML help workshop
# (available from http://msdn.microsoft.com/workshop/author/htmlhelp)
# is installed with its DLLs in PATH.
# 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 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})
# include(UseDoxygen)
# Add the Doxyfile.in and UseDoxygen.cmake files to the projects source directory.
#
#
# Please note, that the tools, e.g.:
# doxygen, dot, latex, dvips, makeindex, gswin32, etc.
# must be in path.
# CONFIGURATION
#
# Note about Visual Studio Projects:
# MSVS has its own path environment which may differ from the shell.
# See "Menu Tools/Options/Projects/VC++ Directories" in VS 7.1
# To configure Doxygen you can edit Doxyfile.in and set some variables in cmake.
# Variables you may define are:
# 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".
#
# author Jan Woetzel 2004-2006
# www.mip.informatik.uni-kiel.de/~jw
#
# 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 type docstring)
if(NOT DEFINED "${name}")
set("${name}" "${value}" CACHE "${type}" "${docstring}")
endif()
endmacro()
find_package(Doxygen)
if(DOXYGEN_FOUND)
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)
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_LATEX YES BOOL "Generate LaTeX API documentation" OFF)
usedoxygen_set_default(DOXYFILE_LATEX_DIR "latex" STRING "LaTex output directory")
mark_as_advanced(DOXYFILE_OUTPUT_DIR DOXYFILE_HTML_DIR DOXYFILE_LATEX_DIR
DOXYFILE_SOURCE_DIR DOXYFILE_EXTRA_SOURCE_DIRS DOXYFILE_IN)
FIND_PACKAGE(Doxygen)
set_property(DIRECTORY
APPEND PROPERTY
ADDITIONAL_MAKE_CLEAN_FILES
"${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_HTML_DIR}")
IF (DOXYGEN_FOUND)
add_custom_target(doxygen
COMMAND "${DOXYGEN_EXECUTABLE}"
"${DOXYFILE}"
COMMENT "Writing documentation to ${DOXYFILE_OUTPUT_DIR}..."
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
# click+jump in Emacs and Visual Studio (for doxy.config) (jw)
IF (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)")
SET(DOXY_WARN_FORMAT "\"$file($line) : $text \"")
ELSE (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)")
SET(DOXY_WARN_FORMAT "\"$file:$line: $text \"")
ENDIF (CMAKE_BUILD_TOOL MATCHES "(msdev|devenv)")
set(DOXYFILE_DOT "NO")
if(DOXYGEN_DOT_EXECUTABLE)
set(DOXYFILE_DOT "YES")
endif()
# we need latex for doxygen because of the formulas
FIND_PACKAGE(LATEX)
IF (NOT LATEX_COMPILER)
MESSAGE(STATUS "latex command LATEX_COMPILER not found but usually required. You will probably get warnings and user inetraction on doxy run.")
ENDIF (NOT LATEX_COMPILER)
IF (NOT MAKEINDEX_COMPILER)
MESSAGE(STATUS "makeindex command MAKEINDEX_COMPILER not found but usually required.")
ENDIF (NOT MAKEINDEX_COMPILER)
IF (NOT DVIPS_CONVERTER)
MESSAGE(STATUS "dvips command DVIPS_CONVERTER not found but usually required.")
ENDIF (NOT DVIPS_CONVERTER)
FIND_PROGRAM(DOXYGEN_DOT_EXECUTABLE_PATH NAMES dot)
IF (DOXYGEN_DOT_EXECUTABLE_PATH)
SET(DOXYGEN_DOT_FOUND "YES")
ENDIF (DOXYGEN_DOT_EXECUTABLE_PATH)
## LaTeX
set(DOXYFILE_PDFLATEX "NO")
IF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in")
MESSAGE(STATUS "Generate ${CMAKE_CURRENT_BINARY_DIR}/doxy.config from doxy.config.in")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in
${CMAKE_CURRENT_BINARY_DIR}/doxy.config
@ONLY )
# use (configured) doxy.config from (out of place) BUILD tree:
SET(DOXY_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/doxy.config")
ELSE (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in")
# use static hand-edited doxy.config from SOURCE tree:
SET(DOXY_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config")
IF (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config")
MESSAGE(STATUS "WARNING: using existing ${CMAKE_CURRENT_SOURCE_DIR}/doxy.config instead of configuring from doxy.config.in file.")
ELSE (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config")
IF (EXISTS "${CMAKE_MODULE_PATH}/doxy.config.in")
# using template doxy.config.in
MESSAGE(STATUS "Generate ${CMAKE_CURRENT_BINARY_DIR}/doxy.config from doxy.config.in")
CONFIGURE_FILE(${CMAKE_MODULE_PATH}/doxy.config.in
${CMAKE_CURRENT_BINARY_DIR}/doxy.config
@ONLY )
SET(DOXY_CONFIG "${CMAKE_CURRENT_BINARY_DIR}/doxy.config")
ELSE (EXISTS "${CMAKE_MODULE_PATH}/doxy.config.in")
# failed completely...
MESSAGE(SEND_ERROR "Please create ${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in (or doxy.config as fallback)")
ENDIF(EXISTS "${CMAKE_MODULE_PATH}/doxy.config.in")
set_property(DIRECTORY APPEND PROPERTY
ADDITIONAL_MAKE_CLEAN_FILES
"${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}")
ENDIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config")
ENDIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/doxy.config.in")
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_CUSTOM_TARGET(doc ${DOXYGEN_EXECUTABLE} ${DOXY_CONFIG} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/doxy.config)
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()
# create a windows help .chm file using hhc.exe
# HTMLHelp DLL must be in path!
# fallback: use hhw.exe interactively
IF (WIN32)
FIND_PACKAGE(HTMLHelp)
IF (HTML_HELP_COMPILER)
SET (TMP "${CMAKE_CURRENT_BINARY_DIR}\\doc\\html\\index.hhp")
STRING(REGEX REPLACE "[/]" "\\\\" HHP_FILE ${TMP} )
# MESSAGE(SEND_ERROR "DBG HHP_FILE=${HHP_FILE}")
ADD_CUSTOM_TARGET(winhelp ${HTML_HELP_COMPILER} ${HHP_FILE})
ADD_DEPENDENCIES (winhelp doc)
IF (NOT TARGET_DOC_SKIP_INSTALL)
# install windows help?
# determine useful name for output file
# should be project and version unique to allow installing
# multiple projects into one global directory
IF (EXISTS "${PROJECT_BINARY_DIR}/doc/html/index.chm")
IF (PROJECT_NAME)
SET(OUT "${PROJECT_NAME}")
ELSE (PROJECT_NAME)
SET(OUT "Documentation") # default
ENDIF(PROJECT_NAME)
IF (${PROJECT_NAME}_VERSION_MAJOR)
SET(OUT "${OUT}-${${PROJECT_NAME}_VERSION_MAJOR}")
IF (${PROJECT_NAME}_VERSION_MINOR)
SET(OUT "${OUT}.${${PROJECT_NAME}_VERSION_MINOR}")
IF (${PROJECT_NAME}_VERSION_PATCH)
SET(OUT "${OUT}.${${PROJECT_NAME}_VERSION_PATCH}")
ENDIF(${PROJECT_NAME}_VERSION_PATCH)
ENDIF(${PROJECT_NAME}_VERSION_MINOR)
ENDIF(${PROJECT_NAME}_VERSION_MAJOR)
# keep suffix
SET(OUT "${OUT}.chm")
#MESSAGE("DBG ${PROJECT_BINARY_DIR}/doc/html/index.chm \n${OUT}")
# create target used by install and package commands
INSTALL(FILES "${PROJECT_BINARY_DIR}/doc/html/index.chm"
DESTINATION "doc"
RENAME "${OUT}"
)
ENDIF(EXISTS "${PROJECT_BINARY_DIR}/doc/html/index.chm")
ENDIF(NOT TARGET_DOC_SKIP_INSTALL)
ENDIF(HTML_HELP_COMPILER)
# MESSAGE(SEND_ERROR "HTML_HELP_COMPILER=${HTML_HELP_COMPILER}")
ENDIF (WIN32)
ENDIF(DOXYGEN_FOUND)
configure_file("${DOXYFILE_IN}" "${DOXYFILE}" @ONLY)
add_custom_target(doc)
add_dependencies(doc doxygen)
endif()

View File

@@ -14,38 +14,122 @@
/************************** HEADER FILES *************************/
/* Define to 1 if you have the <argp.h> header file. */
#cmakedefine HAVE_ARGP_H 1
/* Define to 1 if you have the <aprpa/inet.h> header file. */
#cmakedefine HAVE_ARPA_INET_H 1
/* Define to 1 if you have the <pty.h> header file. */
#cmakedefine HAVE_PTY_H 1
/* Define to 1 if you have the <utmp.h> header file. */
#cmakedefine HAVE_UTMP_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 <libutil.h> header file. */
#cmakedefine HAVE_LIBUTIL_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
/* Define to 1 if you have the <wspiapi.h> header file. */
#cmakedefine HAVE_WSPIAPI_H 1
/* Define to 1 if you have the <openssl/blowfish.h> header file. */
#cmakedefine HAVE_OPENSSL_BLOWFISH_H 1
/* 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 ***************************/
/* Define to 1 if you have the `snprintf' function. */
#cmakedefine HAVE_SNPRINTF 1
/* Define to 1 if you have the `_snprintf' function. */
#cmakedefine HAVE__SNPRINTF 1
/* Define to 1 if you have the `_snprintf_s' function. */
#cmakedefine HAVE__SNPRINTF_S 1
/* Define to 1 if you have the `vsnprintf' function. */
#cmakedefine HAVE_VSNPRINTF 1
/* Define to 1 if you have the `_vsnprintf' function. */
#cmakedefine HAVE__VSNPRINTF 1
/* 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
/* Define to 1 if you have the `cfmakeraw' function. */
#cmakedefine HAVE_CFMAKERAW 1
/* Define to 1 if you have the `getaddrinfo' function. */
#cmakedefine HAVE_GETADDRINFO 1
/* Define to 1 if you have the `gethostbyname' function. */
#cmakedefine HAVE_GETHOSTBYNAME 1
/* Define to 1 if you have the `poll' function. */
#cmakedefine HAVE_POLL 1
/* Define to 1 if you have the `select' function. */
#cmakedefine HAVE_SELECT 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). */
@@ -54,15 +138,27 @@
/* 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 ****************************/
/* Define to 1 if you want to enable ZLIB */
#cmakedefine WITH_LIBZ 1
#cmakedefine HAVE_GCC_THREAD_LOCAL_STORAGE 1
#cmakedefine HAVE_MSC_THREAD_LOCAL_STORAGE 1
/* Define to 1 if you want to enable SSH1 */
#cmakedefine HAVE_GCC_VOLATILE_MEMORY_PROTECTION 1
#cmakedefine HAVE_GCC_NARG_MACRO 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_ZLIB 1
/* Define to 1 if you want to enable SFTP */
#cmakedefine WITH_SFTP 1
/* Define to 1 if you want to enable SSH1 */
@@ -74,14 +170,17 @@
/* Define to 1 if you want to enable debug output for crypto functions */
#cmakedefine DEBUG_CRYPTO 1
/* Define to 1 if you want to enable pcap output support (experimental) */
#cmakedefine WITH_PCAP 1
/* 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
significant byte first (like Motorola and SPARC, unlike Intel). */
#if defined AC_APPLE_UNIVERSAL_BUILD
# if defined __BIG_ENDIAN__
# define WORDS_BIGENDIAN 1
# endif
#else
# ifndef WORDS_BIGENDIAN
/* # undef WORDS_BIGENDIAN */
# endif
#endif
#cmakedefine WORDS_BIGENDIAN 1

View File

@@ -1,886 +0,0 @@
<!DOCTYPE HTML SYSTEM>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<head>
<title>
Libssh's Documentation
</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<div id="titre">
<div align="center">
LIBSSH API GUIDE <br>
Or everything you ever wanted to know about a simple and fast ssh library.
</div>
</div>
<h2> 0 Introduction</h2>
<div class="tout">
Before inserting ssh hooks into your programs, you must know some basics about
the ssh protocol, and understand why the ssh library must implement them. <br>
Lot of the protocols specifications are hidden by the ssh library API (of
course !) but some still needs an attention from the end-user programmer.<br>
Note that libssh is still an alpha product, and the API may vary from one
version to another. The only guess I can make is that the API won't radically
change. <br>
The SSH protocol was designed for some goals which I resume here : <br>
-Privacy of data<br>
-Security<br>
-Authentication of the server<br>
-Authentication of the client.<br>
The client MUST be sure who's speaking to before entering into any
authentication way. That's where the end programmer must ensure the given
fingerprints *are* from the legitimate server. A ssh connection must follow
the following steps:<br>
<br>
1- Before connecting the socket, you can set up if you wish one or other
server public key authentication ie. DSA or RSA.
You can choose cryptographic algorithms you trust and compression algorithms
if any.<br>
2- The connection is made. A secure handshake is made, and resulting from it,
a public key from the server is gained.
You MUST verify that the public key is legitimate.<br>
3- The client must authenticate : the two implemented ways are password, and
public keys (from dsa and rsa key-pairs generated by openssh). It is
harmless to authenticate to a fake server with these keys because the
protocol ensures the data you sign can't be used twice. It just avoids
man-in-the-middle attacks.<br>
4- Now that the user has been authenticated, you must open one or several
channels. channels are different subways for information into a single ssh
connection. Each channel has a standard stream (stdout) and an error
stream (stderr). You can theoretically open an infinity of channel.<br>
5- With the channel you opened, you can do several things :<br>
-Open a shell. You may want to request a pseudo virtual terminal before <br>
-Execute a command. The virtual terminal is usable, too<br>
-Invoke the sftp subsystem. (look at chapter 6)<br>
-invoke your own subsystem. This is out the scope of this
document but it is easy to do.<br>
6- When everything is finished, just close the channels, and then the
connection.<br>
<br>
At every place, a function which returns an error code (typically -1 for int
values, NULL for pointers) also sets an error message and an error code.
I high-lined the main steps, now that's you to follow them :)
<br>
</div>
<h2> 1- Setting the options </h2>
<div class="tout">
The options mechanism will change during updates of the library, but the
functions which exists now will certainly be kept.
<br><br>
The ssh system needs to know the preferences of the user, the trust into one
or another algorithm and such. More important informations have to be given
before connecting : the host name of the server, the port (if non default),
the binding address, the default username, ... <br>
The options structure is given to a ssh_connect function, then this option
structure is used again and again by the ssh implementation. you shall not
free it manually, and you shall not share it with multiple sessions.<br>
Two ways are given for setting the options : the easy one (of course !) and
the long-but-accurate one.<br><br>
</div>
<h3>a) the easy way</h3><br>
<div class="tout">
Lot of ssh options in fact come from the command line of the program... <br>
you could parse them and then use the long way for every argument, but libssh
has a mechanism to do that for you, automatically.<br>
<br>
<div class="prot">
SSH_OPTIONS *ssh_getopt(int *argcptr, char **argv);
</div>
this function will return you a new options pointer based on the arguments
you give in parameters. <br> better, they clean the argv array from used parameters
so you can use them after in your own program<br>
<div class="ex">
int main(int argc, char **argv){<br>
SSH_OPTIONS *opt;<br>
opt=ssh_getopt(&argc, argv);<br>
if(!opt){<br>
...<br>
}<br>
</div>
the function will return NULL if some problem is appearing.<br>
As a matter of portability for you own programs, the hostname isn't always<br>
the first argument from the command line, so the single arguments (not
preceded by a -something) won't be parsed.<br>
<div class="ex">
example: <br>
user@host:~$ myssh -u aris localhost <br>
-u aris will be caught, localhost will not.<br>
</div>
cfr the options_set_user() function in the next part for more informations
about it.<br>
</div>
<h3>b) the long way</h3>
<div class="tout">
<div class="prot">
SSH_OPTIONS *options_new();
</div>
This function returns an empty but initialized option structure pointer.<br>
The structure is freed by ssh_disconnect described later, so don't use the
existing function options_free() (it's an internal function).<br>
So : use it only for <b>one</b> ssh_connect(), <b>never</b> free it.<br>
<br>
<div class="prot">
SSH_OPTIONS *options_copy(SSH_OPTIONS *opt);
</div>
If you need to replicate an option object before using it, use this function.
<br><br>
The following functions are all of the following form : <br>
<div class="prot">
int options_set_something(SSH_OPTIONS *opt, something);
</div>
the something parameters are always internaly copied, so you don't have to
strdup them.<br>
some return eather 0 or -1, in which case an error message appears in the
error functions, others never fail (return void)<br>
the error codes and descriptions for these functions are recoverable throught <i>ssh_get_error(NULL);</i>
<br>
<div class="prot">
int options_set_wanted_method(SSH_OPTIONS *opt,int method, char *list);
</div>
Passing an option structure, a ssh macro for the method, and a list of allowed
parameters indicates libssh you want to use these.<br>
The macros are :<br>
KEX_ALGO<br>
KEX_HOSTKEY Server public key type expected<br>
KEX_CRYPT_C_S 2 Cryptographic algorithm client->server<br>
KEX_CRYPT_S_C 3 Cryptographic algorithm server->client<br>
KEX_MAC_C_S 4<br>
KEX_MAC_S_C 5<br>
KEX_COMP_C_S 6 Compression method for the stream ("zlib" or "none"), client to server<br>
KEX_COMP_S_C 7 Compression method for the stream ("zlib" or "none"), server to client<br>
KEX_LANG_C_S 8<br>
KEX_LANG_S_C 9<br>
<br>
Currently, only KEX_HOSTKEY and ,KEX_CRYPT_C_S,S_C, KEX_COMP_C_S and S_C work
as expected. the list is a comma separated string of prefered
algorithms/methods, in order of preference.<br>
<br>
<div class="ex">
example : this sets the ssh stream to be compressed in client->server mode only
<br>
ret = option_set_wanted_method(options,KEX_COMP_C_S,"zlib");
</div>
<div class="ex">
example: this will set the cryptographic algorithms wanted from server to
client to aes128-cbc and then aes192-cbc if the first one isn't supported by
server:<br>
ret = option_set_wanted_method(options,KEX_CRYPT_S_C,"aes128-cbc,aes192-cbc");
</div>
<div class="ex">
if you prefer getting the Dss key from a server instead of rsa, but you still
accept rsa if dss isn't available :<br>
options_set_wanted_method(options,KEX_HOSTKEY,"ssh-dss,ssh-rsa");
</div>
return value: <br>0 if the option is valid, -1 else.<br> An error is set in that case.
<br><br>
<div class="prot">
void options_set_port(SSH_OPTIONS *opt, unsigned int port);
</div>
this function sets the server port.
<div class="prot">
void options_set_host(SSH_OPTIONS *opt, const char *hostname);
</div>
this function sets the hostname of the server. It also supports
"user@hostname" syntax in which case the user options is set too.
<div class="prot">
void options_set_fd(SSH_OPTIONS *opt, int fd);
</div>
permits you to specify an opened file descriptor you've opened yourself.
<br>
It's a good way of bypassing the internal FD opening in libssh, but there are things you should take care of : <br>
-The file descriptor should be returned to libssh without nonblocking settings<br>
-If you wish to use <i>is_server_known()</i> You should also set <i>options_set_host</i>... Otherwise libssh won't have any mean of certifying the server is known or not.<br><br>
<div class="prot">
void options_set_bindaddr(SSH_OPTIONS *opt, char *bindaddr);
</div>
this function allows you to set the binding address, in case your computer has
multiple IP or interfaces. it supports both hostnames and IP's
<br><br>
<div class="prot">
void options_set_username(SSH_OPTIONS *opt,char *username);
</div>
sets username for authenticating in this session.
<br><br>
<div class="prot">
void option_set_timeout(SSH_OPTIONS *opt,long seconds, long usec);
</div>
sets the timeout for connecting to the socket. It does not include a timeout for the name resolving or handshake.
<br>
<br>
<div class="prot">
void options_set_ssh_dir(SSH_OPTIONS *opt, char *dir);
</div>
this function sets the .ssh/ directory used by libssh. You may use a %s
which will be replaced by the home directory of the user.
NEVER accept parameters others than the user's one, they may contain
format strings which are a security hole if a malicious agent gives it.
<br><br>
<div class="prot">
void options_set_known_hosts_file(SSH_OPTIONS *opt, char *dir);
</div>
same than <i>options_set_ssh_dir()</i> for known_hosts file.
<br><br>
<div class="prot">
void options_set_identity(SSH_OPTIONS *opt, char *identity);
</div>
same than upper for the identity file (they come by pair, the one asked is the file without the .pub suffix)
<br><br>
<div class="prot">
void options_set_status_callback(SSH_OPTIONS *opt, void (*callback)(void *arg, float status), void *arg);
</div>
Because more and more developpers use libssh with GUI, I've added this function to make the ssh_connect function more
interactive. This permits to set a callback of the form
<div class="prot">void function(void *userarg, float status);</div> with status going from 0 to 1 during ssh_connect. The callback won't ever be called after the connection is made.
<br><br>
</div>
<h2>
2- Connecting the ssh server
</H2>
<div class="tout">
The API provides an abstract data type, SSH_SESSION, which describes the
connection to one particular server. You can make several connections to
different servers under the same process because of this structure.
<br>
<br>
<div class="prot">
SSH_SESSION *ssh_connect(SSH_OPTIONS *options);
</div>
This function returns a handle on the newly connection. This function expects
to have a pre-set options structure.
<br>
It returns NULL in case of error, in which case you can look at error messages
for more informations.
<br><br>
<div class="prot">
void ssh_disconnect(SSH_SESSION *session);
</div>
This function sends a polite disconnect message, and does clean the session.<br>
This is the proper way of finishing a ssh connection.<br>
<br>
<div class="prot">
int ssh_get_pubkey_hash(SSH_SESSION *session, char hash[MD5_DIGEST_LEN]);
</div>
This function places the MD5 hash of the server public key into the hash array.<br>
It's IMPORTANT to verify it matches the previous known value. One server always
have the same hash. No other server/attacker can emulate it (or it'd be caught
by the public key verification procedure automatically made by libssh).
<br>
You can skip this step if you correctly handle <i>is_server_known()</i>
<br><br>
<div class="prot">
int ssh_is_server_known(SSH_SESSION *session);
</div>
Checks the user's known host file to look for a previous connection to the specified server. Return values:<br>
SSH_SERVER_KNOWN_OK : the host is known and the key has not changed<br>
SSH_SERVER_KNOWN_CHANGED : The host's key has changed. Either you are under
an active attack or the key changed. The API doesn't give any way to modify the key in known hosts yet. I Urge end developers to WARN the user about the possibility of an attack.<br>
SSH_SERVER_FOUND_OTHER: The host gave us a public key of one type, which does
not exist yet in our known host file, but there is an other type of key which is know.<br>
IE server sent a DSA key and we had a RSA key.<br>
Be carreful it's a possible attack (coder should use option_set_wanted_method() to specify
which key to use).<br>
SSH_SERVER_NOT_KNOWN: the server is unknown in known hosts. Possible reasons :
case not matching, alias, ... In any case the user MUST confirm the Md5 hash is correct.<br>
SSH_SERVER_ERROR : Some error happened while opening known host file.<br>
<br>
<div class="prot">
int ssh_write_knownhost(SSH_SESSION *session);
</div>
write the current connected host as known in the known host file. returns a negative value if something went wrong. You generaly use it when ssh_is_server_known returned SSH_SERVER_NOT_KNOWN.
<br><br>
<div class="prot">
int pubkey_get_hash(SSH_SESSION *session,char hash[MD5_DIGEST_LEN]);
</div>
deprecated but left for binary compatibility (will be removed in newer versions).
</div>
<h2>3- Authenticating to server</h2>
<div class="tout">
The ssh library supports the two most used authentication methods from SSH.
In every function, there is a "username" argument. If null is given instead,
the server will use the default username (which is guessed from what you gave
to options_set_user or options_set_hostname or even the local user running the code).
<br>
Authentication methods :<br>
<h3>A) Public keys</h3><br>
The public key is the only method which does not compromise your key if the
remote host has been compromised (the server can't do anything more than
getting your public key). This is not the case of a password authentication
(the server can get your plaintext password).<br>
Libssh is obviously fully compatible with the openssh public and private keys.<br>
The things go this way : you scan a list of files which contain public keys.<br>
For each key, you send it to ssh server until the server acknowledges a key
(a key it knows). Then, you get the private key for this key and send a
message proving you own that private key.<br>
Here again, two ways for the public key authentication... the easy and the
complicated one.<br>
<br>
<h4> easy way:</h4>
<div class="prot">
int ssh_userauth_autopubkey(SSH_SESSION *session);
</div>
This function will try the most common places for finding the public and
private keys (your home directory) or eventualy the identity files asked by
the <i>options_set_identity()</i> function.<br>
The return values are :<br>
SSH_AUTH_ERROR : some serious error happened during authentication<br>
SSH_AUTH_DENIED : no key matched<br>
SSH_AUTH_SUCCESS : you are now authenticated<br>
SSH_AUTH_PARTIAL : some key matched but you still have to give an other mean
of authentication (like password).<br>
<br>
<h4> peanful way:</h4>
there are three steps : you get a public key, you ask the server if the key
matches a known one, if true, you get the private key and authenticate with
it.<br>
<div class="prot">
STRING *publickey_from_file(char *filename,int *_type);
</div>
will return an handle on a public key. if you give a pointer to an int,
a symbolic value will be placed there. Do it because you need it in next
step.<br><br>
<div class="prot">
int ssh_userauth_offer_pubkey(SSH_SESSION *session, char *username,
int type, STRING *publickey);
</div>
this function will offer a public key to the server. SSH_AUTH_SUCCESS is
returned if the key is accepted (in which case you'll want to get the
private key), SSH_AUTH_DENIED otherwise.<br>
Still watch for SSH_AUTH_ERROR as connection problems might happen.
<br>
in case of SSH_AUTH_SUCCESS,
<br>
<div class="prot">
PRIVATE_KEY *privatekey_from_file(SSH_SESSION *session,char *filename,
int type,char *passphrase);
</div>
will get the privatekey from the filename previously set by
publickey_from_next_file(). You can call it with a passphrase for
unlocking the key. If passphrase==NULL, the default prompt will be used.<br>
The function returns NULL if the private key wasn't opened
(ie bad passphrase or missing file).<br>
<br>
<div class="prot">
int ssh_userauth_pubkey(SSH_SESSION *session, char *username,
STRING *publickey, PRIVATE_KEY *privatekey);
</div>
Will try to authenticate using the public and private key. It shall return
SSH_AUTH_SUCCESS if you are authenticated, SSH_AUTH_ERROR, SSH_AUTH_DENIED or
SSH_AUTH_PARTIAL depending of return condition.<br>
each public key (of type STRING) must be freed with the libc "free" function.<br>
The private key must be freed with private_key_free(PRIVATE_KEY *) which
will clean the memory before (don't worry about passphrase leaking).<br>
<br>
<h3> B) Password</h3><br>
<div class="prot">
int ssh_userauth_password(SSH_SESSION *session,char *username,char *password);
</div>
Will return SSH_AUTH_SUCCESS if the password matched, one of other constants
otherwise. It's your work to ask the password and to free it in a secure
manner.<br><br>
<h3> C) Keyboard-interactive</h3><br>
<div class="prot">
int ssh_userauth_kbdint(SSH_SESSION *session, char *user, char *submethods);
</div>
This is the main keyboard-interactive function. It will return SSH_AUTH_SUCCESS,SSH_AUTH_DENIED, SSH_AUTH_PARTIAL, SSH_AUTH_ERROR depending on the result of the request.<br>
The keyboard-interactive authentication method of SSH2 is a feature which permits the server to ask a certain number of questions in an interactive manner to the client, until it decides to accept or deny the login.<br>
To begin, you call this function (you can omit user if it was set previously and omit submethods - instead you know what you do - just put them to NULL) and store the answer.
If the answer is SSH_AUTH_INFO, it means the server has sent a few questions to ask your user, which you can retrieve with the following functions. Then, set the answers and call back ssh_userauth_kbdint with same arguments. It may again ask a few other questions etc. until you get an other SSH_AUTH code than SSH_AUTH_INFO.<br>
Few remarks :<br>
-Even the first call can return SSH_AUTH_DENIED or SSH_AUTH_SUCCESS.<br>
-The server can send an empty question set (this is the default behavior on my system) after you have sent the answers to the first questions.
you must still parse the answer, it might contain some message from the server saying hello or such things. Just call ssh_userauth_kbdint() once more<br>
<br>
<div class="prot">
int ssh_userauth_kbdint_getnprompts(SSH_SESSION *session);
</div>
After you called ssh_userauth_kbdint and got SSH_AUTH_INFO, the session contains a few questions (or prompts) from the server. This function returns the number of prompts and answers.<br>
It could be zero, in which case you must act as said previously.<br>
<div class="prot">
char *ssh_userauth_kbdint_getname(SSH_SESSION *session);
</div>
this functions returns the "name" of the message block. The meaning is explained later.<br>
This function returns a pointer that stays valid until the next ssh_userauth_kbdint() call and must not be freed.<br>
<div class="prot">
char *ssh_userauth_kbdint_getinstruction(SSH_SESSION *session);
</div>
this functions returns the "instruction" of the message block. The meaning is explained later.<br>
This function returns a pointer that stays valid until the next ssh_userauth_kbdint() call and must not be freed.<br>
<div class="prot">
char *ssh_userauth_kbdint_getprompt(SSH_SESSION *session,int i, char *echo);
</div>
This functions returns a pointer to the nth prompt. The character pointed by echo, if different from null, will contain a boolean value after the call, which means that the user prompt must be echoed or not.<br>
zero means that the echo is Off (like for a password prompt).<br>
any other value means the echo is on.<br>
This function returns a pointer that stays valid until the next ssh_userauth_kbdint() call and must not be freed.<br>
<div class="prot">
void ssh_userauth_kbdint_setanswer(SSH_SESSION *session, unsigned int i, char *a
nswer);
</div>
This function sets the ith answer. The string you give will be duplicated, and this copy will be discarded once it is no longer necessary.<br>
care must be taken so you discard the content of the original string after this function call.<br>
<h3> A little note about how to use the informations from keyboard-interactive authentication</h3>
<br>
The words from the original drafts explain everything
<div class="prot">
3.3 User Interface
Upon receiving a request message, the client SHOULD prompt the user
as follows:<br>
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.<br>
<br>
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 the prompt(s) are presented. In that dialog window, the
instruction field would be a text message, and the prompts would be
labels for text entry fields. All fields SHOULD be presented to the
user, for example an implementation SHOULD NOT discard the name field
because its windows lack 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.<br>
<br>
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.<br>
The instruction field SHOULD NOT be truncated.<br>
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.<br>
<br>
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 prompts in the request message. If a client does not honor
the echo field for whatever reason, then the client MUST err on the
side of masking input. A GUI client might like to have a checkbox
toggling echo/mask. Clients SHOULD NOT add any additional characters
to the prompt such as ": " (colon-space); the server is responsible
for supplying all text to be displayed to the user. Clients MUST
also accept empty responses from the user and pass them on as empty
strings.<br>
</div>
<br>
<h3> D) "none"</h3><br>
In fact this mode only serve to get the list of supported authentications.<br>
however, it also serves to get the banner message from the server, if any.<br>
You should firstly try this method, at least for getting the banner, then to enter if there is no password at all.<br>
<div class="prot">
int ssh_userauth_none(SSH_SESSION *session, char *username);
</div>
if the account has no password (and the server is configured to let you
pass), the function might answer SSH_AUTH_SUCCESS. That's why
ssh_auth_autopubkey already calls it for you.
<br><br>
<div class="prot">
char *ssh_get_issue_banner(SSH_SESSION *session);
</div>
if during authentication, the server has given a banner, you can get it
this way. the function returns NULL if no banner exists, and you have to
free the returned pointer.<br><br>
</div>
<h2>4- Opening a channel</h2>
<div class="tout">
Maybe you want to use the sftp subsystem : all this is done for you, you
better read at the end of the paper how to use the sftp functions.<br>
You probably want to open one or more shells, or call one or more programs.<br>
So you need a channel.<br>
<div class="prot">
CHANNEL *channel;
</div>
This is an handler to a channel object. it describes your channel.
<br>
<div class="prot">
CHANNEL *channel_open_session(SSH_SESSION *session);
</div>
This will open a channel for use into a session (which can be used for executing
a command or a shell. Not for tcp forwarding).<br>
The function returns NULL if for a reason or another the channel can't be
opened.<br>
<i>
CHANNEL *open_session_channel(...)</i> is deprecated and should not be used in future
applications.<br><br>
<div class="prot">
CHANNEL *channel_open_forward(SSH_SESSION *session, char *remotehost,
int remoteport, char *sourcehost, int localport);
</div>
Ask the server to tunnel a TCP connection. The server will connect to
remotehost:remoteport and libssh will return an handle to the channel if it is allowed.<br>
Otherwise, NULL will be returned. sourcehost and localport are generaly
used in message debugging purpose and have no effect on the result.<br>
<br>
When you've finished with your channel, you may send an EOF message and
then close it :<br>
<div class="prot">
void channel_send_eof(CHANNEL *channel);
</div>
sends an end of file into channel. It doesn't close the channel and you can still read it.<br><br>
<div class="prot">
void channel_free(CHANNEL *channel);
</div>
closes and destroy the channel.
<br>
<div class="prot">
void channel_close(CHANNEL *channel);
</div>
sends an EOF and close the channel. (if you don't know what to do, use channel_free). It doesn't free the channel.
</div>
<h2>5- The shell</h2>
<div class="tout">
<div class="prot">
int channel_request_env(CHANNEL *channel, char *name, char *value);
</div>
Ask the server to set the "name" environment variable to "value". For security
reasons, some variables won't be accepted by the server. It returns 0 otherwise.<br><br>
<div class="prot">
int channel_request_pty(CHANNEL *channel);
</div>
ask the server to allocate a pseudo terminal for the current channel.<br>
the function returns 0 on success.<br><br>
<div class="prot">
int channel_request_pty_size(CHANNEL *channel, char *terminal, int cols, int rows);
</div>
ask the server to allocate a pty. The terminal parameter is the type of pty
(vt100,xterm,...), cols and rows are the size of the new terminal (80x24 by example).<br><br>
<div class="prot">
int channel_change_pty_size(CHANNEL *channel, int cols,int rows);
</div>
changes the window size (terminal) of the current session;<br><br>
<div class="prot">
int channel_request_shell(CHANNEL *channel);
</div>
This function requests a shell. After its success, a shell is running at the other side of the channel.<br><br>
<div class="prot">
int channel_request_exec(CHANNEL *channel, char *cmd);
</div>
run a shell command without an interactive shell, ie $SHELL -c "command".<br>
returns 0 on success.<br><br>
You might ask the server to open a subsystem for you. this is done this way :
<div class="prot">
int channel_request_subsystem(CHANNEL *channel, char *subsystem);
</div>
There are some functions used to manipulate the channels :
<br><br>
<div class="prot">
int channel_write(CHANNEL *channel,void *data,int len);
</div>
writes len bytes of data into the channel. It returns the number of bytes written. The current implementation is a blocking write
of the complete data buffer, but it may vary.<br><br>
<div class="prot">
int channel_read(CHANNEL *channel, BUFFER *buffer,int bytes,int is_stderr);
</div>
It makes a blocking read on the channel, of "bytes" bytes and returns the
result into an allocated buffer you passed in. (with <i>buffer_new()</i>).<br>
it will read on stderr, if is_stderr is set.<br>
The function might read less bytes than "bytes" variable if an End of File
happened. Otherwise, the function will always block reading until "bytes"
bytes are read.<br>
with "bytes"=0, <i>channel_read()</i> will read the current state of the read buffer, but will read at least one byte (and block if nothing is available, except EOF case).<br>
You don't need to free and allocate a new buffer each time you call this function, just pass the same object each time.<br>
look at the <i>buffer_</i> functions further for the correct way of retrieving the data.<br><br>
<div class="prot">
int channel_read_nonblocking (CHANNEL *channel, char *dest, int len, int is_stderr);
</div>
Non-blocking read on channel, at most len bytes of data are read. Returns 0 if EOF or if no data available.
<br><br>
<div class="prot">
int channel_is_open(CHANNEL *channel);
</div>
returns 0 if the channel has been closed by remote host, something else otherwise.<br><br>
<div class="prot">
int channel_poll(CHANNEL *channel, int is_stderr);
</div>
This nonblocking function returns the number of bytes immediatly available for
reading on the channel and stdin/stderr.<br><br>
More interesting, if you are going to do channel multiplexing, this function
is for you :<br><br>
<div class="prot">
int ssh_select(CHANNEL **channels,CHANNEL **outchannels, int maxfd,
fd_set *readfds, struct timeval *timeout);
</div>
channels is an array of channel pointers, finished by a NULL pointer.<br>
It can be used ever and ever, as it is never written.<br>
outchannels is an array of size at least greater or equal to "channels".<br>
It hasn't to be initialized.<br>
maxfd is the maximum file descriptor from your own filedescriptors.<br>
readfds is a pointer to a fd_set structure, like in the original
select implementation (man select).<br>
the struct timeval *timeout has the same meaning than in
select(2) (man select).<br>
There is no support for writing or special events as in <i>select(2)</i> yet.<br>
The function returns -1 if an error occured, or SSH_EINTR if select was interrupted by a syscall. This is not an error, you may restart the function.<br>
<b>note about signals:</b> libssh is not threadsafe, and most functions are not
reetrant when using the same data structures : it means you *cannot* do anything
with a channel from a ssh session passed to <i>ssh_select</i> during a signal.
<br>take a look at sample.c on how to bypass that limitation.<br>
the function works this way : it returns in the readfds the filedescriptors which have data ready for reading (the given filedescriptors have a greatest priority).<br>
Then, if no file descriptor can be read, the function looks for every
channel from the array to get a channel with data bufferized. If nothing is
available, it waits for activity on any channel/file descriptor and returns
immediatly, or waits until timeout.<br>
You will find the channels that can be read in the outchannels array (finished by NULL) and the filedescriptors in your fd_set (man FD_ISSET).<br>
this is the "heart" of your main loop.<br>
<br>
<h3>The BUFFER object.</h3>
Reading is done through the BUFFER object. here is the public interface :
<br>
<div class="prot">
BUFFER *buffer_new();
</div>
creates a buffer object.
<br><br>
<div class="prot">
void *buffer_get(BUFFER *buffer);
</div>
returns a pointer to the begining of buffer.
<br><br>
<div class="prot">
int buffer_get_len(BUFFER *buffer);
</div>
returns buffer's data size.
<br><br>
<div class="prot">
void buffer_free(BUFFER *buffer);
</div>
destoys the buffer.
<br>
<br>
How to use the buffer system when you've read something:<br>
I've seen people doing such code:<br>
<div class="prot">
char buffer[256];<br>
channel_read(channel,buf,1234,0);<br>
strcpy(buffer,buf.data);<br>
</div>
The correct way of doing this:
<div class="prot">
char buffer[256];<br>
int i;<br>
i=channel_read(channel,buf,1234,0);<br>
if(i<=0)<br>
&nbsp;&nbsp;&nbsp;&nbsp;go_out()...<br>
if(i>=256)<br>
&nbsp;&nbsp;&nbsp;&nbsp;i=255;<br>
memcpy(buffer,buffer_get(buf),i);<br>
buffer[i]=0;
</div>
Do not expect the buffer to be null-terminated. Don't access the internal structure of buffer. Check the sizes before copying.<br>
</div>
<h2>6- The SFTP subsystem</h2>
<div class="tout">
SFTP is a secure implementation of a file transfer protocol. The current
implemented version is 3. All functions aren't implemented yet but the most
important are.<br>
<br>
<h3>A) Opening the session</h3>
<div class="prot">
SFTP_SESSION *sftp_new(SSH_SESSION *session);
int sftp_init(SFTP_SESSION *sftp);
</div>
The former returns a SFTP_SESSION handle. It returns NULL if things didn't
work as expected.<br>
sftp_init makes some initialisation work. It returns 0 if things went right.
Both of them must be called.<br>
<h3>B) Opening and reading a directory</h3>
<div class="prot">
SFTP_DIR *sftp_opendir(SFTP_SESSION *session, char *path);
</div>
opens a directory for file listing. Returns NULL in error case.
<br><br>
<div class="prot">
SFTP_ATTRIBUTES *sftp_readdir(SFTP_SESSION *session, SFTP_DIR *dir);
</div>
This function reads one file attribute from an opened directory. It
returns NULL if the directory is EOF, or if something wrong happened.
<br><br>
<div class="prot">
int sftp_dir_eof(SFTP_DIR *dir);
</div>
When a <i>sftp_readdir()</i> returned NULL, you can use this function to
tell if an EOF occured. the function returns 0 if no EOF occured.
<br><br>
<div class="prot">
void sftp_attributes_free(SFTP_ATTRIBUTES *file);
</div>
You have to free any SFTP_ATTRIBUTE structure given by an other function
with it.<br><br>
<div class="prot">
int sftp_dir_close(SFTP_DIR *dir);
</div>
closes an opened directory. returns 0 when no error occured.
<br><br>
<h3>C) Opening, reading, writing files</h3>
<div class="prot">
SFTP_FILE *sftp_open(SFTP_SESSION *session, char *file, int access,
SFTP_ATTRIBUTES *attr);
</div>
Opens a file. The access flags are the same than the stdio flags.<br>
see open(2) for more details.<br>
attr are the wanted attributes for the new file. If you supply NULL,
default values will be used.<br>
rem: more work is going on parsing/making the attributes structure
<br><br>
<div class="prot">
int sftp_read(SFTP_FILE *file, void *dest, int len);
</div>
read on a file. Works as the fread() function. It is blocking by default but you can change the default behaviour with <i>sftp_file_set_nonblocking()</i>.
<br><br>
<div class="prot">
void sftp_file_set_nonblocking(SFTP_FILE *file);
</div>
sets the file non blocking. reads on this file won't ever block. You can't detect end of files this way.<br>
*** TODO more work going there for EOF ****
<br><br>
<div class="prot">
void sftp_file_set_blocking(SFTP_FILE *file);
</div>
restore the default setting of sftp_read.
<br><br>
<div class="prot">
int sftp_write(SFTP_FILE *file, void *source, int len);
</div>
works as fwrite() function. It is a blocking write.<br>
<br>
<div class="prot">
void sftp_seek(SFTP_FILE *file, int new_offset);
</div>
seek into the file for reading/writing at an other place.
<br><br>
<div class="prot">
unsigned long sftp_tell(SFTP_FILE *file);
</div>
returns the current offset (both writing and reading) into the opened file.
<br><br>
<div class="prot">
void sftp_rewind(SFTP_FILE *file);
</div>
same as sftp_seek(file,0);
<br><br>
<div class="prot">
int sftp_file_close(SFTP_FILE *file);
</div>
closes a file handle. returns 0 in no error case.
<br><br>
<div class="prot">
int sftp_rm(SFTP_SESSION *sftp, char *file);
</div>
deletes a file.
<br><br>
<div class="prot">
int sftp_rmdir(SFTP_SESSION *sftp, char *directory);
</div>
<br>
deletes a directory.
<br><br>
<div class="prot">
int sftp_mkdir(SFTP_SESSION *sftp, char *directory, SFTP_ATTRIBUTES *attr);
</div>
makes a directory, with the given attributes. You can't pass NULL for attr and hope it works.
<br><br>
<div class="prot">
int sftp_rename(SFTP_SESSION *sftp, char *original, char *newname);
</div>
changes the name of a file or directory.
<br><br>
<div class="prot">
int sftp_setstat(SFTP_SESSION *sftp, char *file, SFTP_ATTRIBUTES *attr);
</div>
changes the attributes of a file or directory.
<br><br>
<div class="prot">
char *sftp_canonicalize_path(SFTP_SESSION *sftp, char *path);
</div>
gives the canonicalized form of some path. You have to
free the pointer given in return.<br>
(returns NULL if error).
<br><br>
(a function to make proper SFTP_ATTRIBUTES structures is on the way )
<h3>D) Closing the session</h3>
<div class="prot">
void sftp_free(SFTP_SESSION *sftp);
</div>
it closes the sftp channel and subsystem.
</div>
<h2>7- Handling the errors</h2>
<div class="tout">
When some function returns an error code, it's allways possible to get an
english message describing the problem. the function ssh_get_error()
returns a pointer to the static error buffer.<br>
ssh_error_code() returns the error code number. it's declared as an enum:<br>
SSH_NO_ERROR, SSH_REQUEST_DENIED, SSH_INVALID_REQUEST, SSH_CONNECTION_LOST,
SSH_FATAL, SSH_INVALID_DATA.<br><br>
SSH_REQUEST_DENIED means the ssh server refused your request but the situation is
recoverable. the others mean something happened to the connection (some
encryption problems, server problems, library bug, ...).<br>
SSH_INVALID_REQUEST means the library got some garbage from server. (But might be
recoverable).<br>
SSH_FATAL means the connection has an important problem and isn't probably
recoverable.<br>
<br>
Most of time, the error returned are SSH_FATAL, but some functions (generaly the
<i>ssh_request_*</i> ones) may fail because of server denying request. In these cases, SSH_REQUEST_DENIED is returned.<br><br>
You'll see in the prototype SSH_SESSION *session. That's because for thread
safety, error messages that can be attached to a session aren't static
anymore. So, any error that could happen during ssh_getopt(), options_* or
ssh_connect() will be retreavable giving NULL as argument.<br>
<br>
<div class="prot">
char *ssh_get_error(SSH_SESSION *session);
</div>
returns a pointer to a static message error from the given session. No
message freeing is needed.<br><br>
<div class="prot">
enum ssh_error ssh_get_error_code(SSH_SESSION *session);
</div>
returns the error code that last happened along with the message.
<br><br>
</div>
<h2>8- Final word</h2>
<div class="tout">
I made this library because nothing in the Open source or free software community was existing yet. This project is a very personnal one as it's the first "useful" thing I ever wrote.
I hope it fits your needs, but remember the experimental state of libssh : if
something doesn't work, please mail me. If something lacks, please ask for it.
If something stinks, please write a patch and send it !
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

375
doc/authentication.dox Normal file
View File

@@ -0,0 +1,375 @@
/**
@page libssh_tutor_authentication Chapter 2: A deeper insight on authentication
@section authentication_details A deeper insight on authentication
In our guided tour, we merely mentioned that the user needed to authenticate.
We didn't explain much in detail how that was supposed to happen.
This chapter explains better the four authentication methods: with public keys,
with a password, with challenges and responses (keyboard-interactive), and with
no authentication at all.
If your software is supposed to connect to an arbitrary server, then you
might need to support all authentication methods. If your software will
connect only to a given server, then it might be enough for your software
to support only the authentication methods used by that server. If you are
the administrator of the server, it might be your call to choose those
authentication methods.
It is not the purpose of this document to review in detail the advantages
and drawbacks of each authentication method. You are therefore invited
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
libssh is fully compatible with the openssh public and private keys. You
can either use the automatic public key authentication method provided by
libssh, or roll your own using the public key functions.
The process of authenticating by public key to a server is the following:
- you scan a list of files that contain public keys. each key is sent to
the SSH server, until the server acknowledges a key (a key it knows can be
used to authenticate the user).
- then, you retrieve the private key for this key and send a message
proving that you know that private key.
The function ssh_userauth_autopubkey() does this using the available keys in
"~/.ssh/". The return values are the following:
- SSH_AUTH_ERROR: some serious error happened during authentication
- 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).
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 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 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:
@code
int authenticate_pubkey(ssh_session session)
{
int rc;
rc = ssh_userauth_publickey_auto(session, NULL);
if (rc == SSH_AUTH_ERROR)
{
fprintf(stderr, "Authentication failed: %s\n",
ssh_get_error(session));
return SSH_AUTH_ERROR;
}
return rc;
}
@endcode
@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
The function ssh_userauth_password() serves the purpose of authenticating
using a password. It will return SSH_AUTH_SUCCESS if the password worked,
or one of other constants otherwise. It's your work to ask the password
and to deallocate it in a secure manner.
If your server complains that the password is wrong, but you can still
authenticate using openssh's client (issuing password), it's probably
because openssh only accept keyboard-interactive. Switch to
keyboard-interactive authentication, or try to configure plain text passwords
on the SSH server.
Here is a small example of password authentication:
@code
int authenticate_password(ssh_session session)
{
char *password;
int rc;
password = getpass("Enter your password: ");
rc = ssh_userauth_password(session, NULL, password);
if (rc == SSH_AUTH_ERROR)
{
fprintf(stderr, "Authentication failed: %s\n",
ssh_get_error(session));
return SSH_AUTH_ERROR;
}
return rc;
}
@endcode
@see ssh_userauth_password
@subsection keyb_int The keyboard-interactive authentication method
The keyboard-interactive method is, as its name tells, interactive. The
server will issue one or more challenges that the user has to answer,
until the server takes an authentication decision.
ssh_userauth_kbdint() is the the main keyboard-interactive function.
It will return SSH_AUTH_SUCCESS,SSH_AUTH_DENIED, SSH_AUTH_PARTIAL,
SSH_AUTH_ERROR, or SSH_AUTH_INFO, depending on the result of the request.
The keyboard-interactive authentication method of SSH2 is a feature that
permits the server to ask a certain number of questions in an interactive
manner to the client, until it decides to accept or deny the login.
To begin, you call ssh_userauth_kbdint() (just set user and submethods to
NULL) and store the answer.
If the answer is SSH_AUTH_INFO, it means that the server has sent a few
questions that you should ask the user. You can retrieve these questions
with the following functions: ssh_userauth_kbdint_getnprompts(),
ssh_userauth_kbdint_getname(), ssh_userauth_kbdint_getinstruction(), and
ssh_userauth_kbdint_getprompt().
Set the answer for each question in the challenge using
ssh_userauth_kbdint_setanswer().
Then, call again ssh_userauth_kbdint() and start the process again until
these functions returns something else than SSH_AUTH_INFO.
Here are a few remarks:
- Even the first call can return SSH_AUTH_DENIED or SSH_AUTH_SUCCESS.
- The server can send an empty question set (this is the default behavior
on my system) after you have sent the answers to the first questions.
You must still parse the answer, it might contain some
message from the server saying hello or such things. Just call
ssh_userauth_kbdint() until needed.
- The meaning of "name", "prompt", "instruction" may be a little
confusing. An explanation is given in the RFC section that follows.
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
the prompt(s) are presented. In that dialog window, the instruction field
would be a text message, and the prompts would be labels for text entry
fields. All fields SHOULD be presented to the user, for example an
implementation SHOULD NOT discard the name field because its windows lack
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
prompts in the request message. If a client does not honor the echo field
for whatever reason, then the client MUST err on the side of
masking input. A GUI client might like to have a checkbox toggling
echo/mask. Clients SHOULD NOT add any additional characters to the prompt
such as ": " (colon-space); the server is responsible for supplying all
text to be displayed to the user. Clients MUST also accept empty responses
from the user and pass them on as empty strings.
@endverbatim
The following example shows how to perform keyboard-interactive authentication:
@code
int authenticate_kbdint(ssh_session session)
{
int rc;
rc = ssh_userauth_kbdint(session, NULL, NULL);
while (rc == SSH_AUTH_INFO)
{
const char *name, *instruction;
int nprompts, iprompt;
name = ssh_userauth_kbdint_getname(session);
instruction = ssh_userauth_kbdint_getinstruction(session);
nprompts = ssh_userauth_kbdint_getnprompts(session);
if (strlen(name) > 0)
printf("%s\n", name);
if (strlen(instruction) > 0)
printf("%s\n", instruction);
for (iprompt = 0; iprompt < nprompts; iprompt++)
{
const char *prompt;
char echo;
prompt = ssh_userauth_kbdint_getprompt(session, iprompt, &echo);
if (echo)
{
char buffer[128], *ptr;
printf("%s", prompt);
if (fgets(buffer, sizeof(buffer), stdin) == NULL)
return SSH_AUTH_ERROR;
buffer[sizeof(buffer) - 1] = '\0';
if ((ptr = strchr(buffer, '\n')) != NULL)
*ptr = '\0';
if (ssh_userauth_kbdint_setanswer(session, iprompt, buffer) < 0)
return SSH_AUTH_ERROR;
memset(buffer, 0, strlen(buffer));
}
else
{
char *ptr;
ptr = getpass(prompt);
if (ssh_userauth_kbdint_setanswer(session, iprompt, ptr) < 0)
return SSH_AUTH_ERROR;
}
}
rc = ssh_userauth_kbdint(session, NULL, NULL);
}
return rc;
}
@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_setanswer()
@subsection none Authenticating with "none" method
The primary purpose of the "none" method is to get authenticated **without**
any credential. Don't do that, use one of the other authentication methods,
unless you really want to grant anonymous access.
If the account has no password, and if the server is configured to let you
pass, ssh_userauth_none() might answer SSH_AUTH_SUCCESS.
The following example shows how to perform "none" authentication:
@code
int authenticate_kbdint(ssh_session session)
{
int rc;
rc = ssh_userauth_none(session, NULL);
return rc;
}
@endcode
@subsection auth_list Getting the list of supported authentications
You are not meant to choose a given authentication method, you can
let the server tell you which methods are available. Once you know them,
you try them one after the other.
The following example shows how to get the list of available authentication
methods with ssh_userauth_list() and how to use the result:
@code
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)
{ // For the source code of function authenticate_none(),
// refer to the corresponding example
rc = authenticate_none(session);
if (rc == SSH_AUTH_SUCCESS) return rc;
}
if (method & SSH_AUTH_METHOD_PUBLICKEY)
{ // For the source code of function authenticate_pubkey(),
// refer to the corresponding example
rc = authenticate_pubkey(session);
if (rc == SSH_AUTH_SUCCESS) return rc;
}
if (method & SSH_AUTH_METHOD_INTERACTIVE)
{ // For the source code of function authenticate_kbdint(),
// refer to the corresponding example
rc = authenticate_kbdint(session);
if (rc == SSH_AUTH_SUCCESS) return rc;
}
if (method & SSH_AUTH_METHOD_PASSWORD)
{ // For the source code of function authenticate_password(),
// refer to the corresponding example
rc = authenticate_password(session);
if (rc == SSH_AUTH_SUCCESS) return rc;
}
return SSH_AUTH_ERROR;
}
@endcode
@subsection banner Getting the banner
The SSH server might send a banner, which you can retrieve with
ssh_get_issue_banner(), then display to the user.
The following example shows how to retrieve and dispose the issue banner:
@code
int display_banner(ssh_session session)
{
int rc;
char *banner;
/*
*** Does not work without calling ssh_userauth_none() first ***
*** That will be fixed ***
*/
rc = ssh_userauth_none(session, NULL);
if (rc == SSH_AUTH_ERROR)
return rc;
banner = ssh_get_issue_banner(session);
if (banner)
{
printf("%s\n", banner);
free(banner);
}
return rc;
}
@endcode
*/

94
doc/command.dox Normal file
View File

@@ -0,0 +1,94 @@
/**
@page libssh_tutor_command Chapter 4: Passing a remote command
@section remote_command Passing a remote command
Previous chapter has shown how to open a full shell session, with an attached
terminal or not. If you only need to execute a command on the remote end,
you don't need all that complexity.
The method described here is suited for executing only one remote command.
If you need to issue several commands in a row, you should consider using
a non-interactive remote shell, as explained in previous chapter.
@see shell
@subsection exec_remote Executing a remote command
The first steps for executing a remote command are identical to those
for opening remote shells. You first need a SSH channel, and then
a SSH session that uses this channel:
@code
int show_remote_files(ssh_session session)
{
ssh_channel channel;
int rc;
channel = ssh_channel_new(session);
if (channel == NULL) return SSH_ERROR;
rc = ssh_channel_open_session(channel);
if (rc != SSH_OK)
{
ssh_channel_free(channel);
return rc;
}
@endcode
Once a session is open, you can start the remote command with
ssh_channel_request_exec():
@code
rc = ssh_channel_request_exec(channel, "ls -l");
if (rc != SSH_OK)
{
ssh_channel_close(channel);
ssh_channel_free(channel);
return rc;
}
@endcode
If the remote command displays data, you get them with ssh_channel_read().
This function returns the number of bytes read. If there is no more
data to read on the channel, this function returns 0, and you can go to next step.
If an error has been encountered, it returns a negative value:
@code
char buffer[256];
unsigned int nbytes;
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
while (nbytes > 0)
{
if (fwrite(buffer, 1, nbytes, stdout) != nbytes)
{
ssh_channel_close(channel);
ssh_channel_free(channel);
return SSH_ERROR;
}
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
}
if (nbytes < 0)
{
ssh_channel_close(channel);
ssh_channel_free(channel);
return SSH_ERROR;
}
@endcode
Once you read the result of the remote command, you send an
end-of-file to the channel, close it, and free the memory
that it used:
@code
ssh_channel_send_eof(channel);
ssh_channel_close(channel);
ssh_channel_free(channel);
return SSH_OK;
}
@endcode
*/

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 strengths 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 attempt 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

230
doc/forwarding.dox Normal file
View File

@@ -0,0 +1,230 @@
/**
@page libssh_tutor_forwarding Chapter 7: Forwarding connections (tunnel)
@section forwarding_connections Forwarding connections
Port forwarding comes in SSH protocol in two different flavours:
direct or reverse port forwarding. Direct port forwarding is also
named local port forwardind, and reverse port forwarding is also called
remote port forwarding. SSH also allows X11 tunnels.
@subsection forwarding_direct Direct port forwarding
Direct port forwarding is from client to server. The client opens a tunnel,
and forwards whatever data to the server. Then, the server connects to an
end point. The end point can reside on another machine or on the SSH
server itself.
Example of use of direct port forwarding:
@verbatim
Mail client application Google Mail
| ^
5555 (arbitrary) |
| 143 (IMAP2)
V |
SSH client =====> SSH server
Legend:
--P-->: port connexion through port P
=====>: SSH tunnel
@endverbatim
A mail client connects to port 5555 of a client. An encrypted tunnel is
established to the server. The server connects to port 143 of Google Mail (the
end point). Now the local mail client can retreive mail.
@subsection forwarding_reverse Reverse port forwarding
The reverse forwarding is slightly different. It goes from server to client,
even though the client has the initiative of establishing the tunnel.
Once the tunnel is established, the server will listen on a port. Whenever
a connection to this port is made, the server forwards the data to the client.
Example of use of reverse port forwarding:
@verbatim
Local mail server Mail client application
^ |
| 5555 (arbitrary)
143 (IMAP2) |
| V
SSH client <===== SSH server
Legend:
--P-->: port connexion through port P
=====>: SSH tunnel
@endverbatim
In this example, the SSH client establishes the tunnel,
but it is used to forward the connections established at
the server to the client.
@subsection forwarding_x11 X11 tunnels
X11 tunnels allow a remote application to display locally.
Example of use of X11 tunnels:
@verbatim
Local display Graphical application
(X11 server) (X11 client)
^ |
| V
SSH client <===== SSH server
Legend:
----->: X11 connection through X11 display number
=====>: SSH tunnel
@endverbatim
The SSH tunnel is established by the client.
How to establish X11 tunnels with libssh has already been described in
this tutorial.
@see x11
@subsection libssh_direct Doing direct port forwarding with libssh
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
so that they can be logged on that server.
If you don't plan to forward the data you will receive to any local port,
just put fake values like "localhost" and 5555 as your local host and port.
The example below shows how to open a direct channel that would be
used to retrieve google's home page from the remote SSH server.
@code
int direct_forwarding(ssh_session session)
{
ssh_channel forwarding_channel;
int rc;
char *http_get = "GET / HTTP/1.1\nHost: www.google.com\n\n";
int nbytes, nwritten;
forwarding_channel = ssh_channel_new(session);
if (forwarding_channel == NULL) {
return rc;
}
rc = ssh_channel_open_forward(forwarding_channel,
"www.google.com", 80,
"localhost", 5555);
if (rc != SSH_OK)
{
ssh_channel_free(forwarding_channel);
return rc;
}
nbytes = strlen(http_get);
nwritten = ssh_channel_write(forwarding_channel,
http_get,
nbytes);
if (nbytes != nwritten)
{
ssh_channel_free(forwarding_channel);
return SSH_ERROR;
}
...
ssh_channel_free(forwarding_channel);
return SSH_OK;
}
@endcode
The data sent by Google can be retrieved for example with ssh_select()
and ssh_channel_read(). Goggle's home page can then be displayed on the
local SSH client, saved into a local file, made available on a local port,
or whatever use you have for it.
@subsection libssh_reverse Doing reverse port forwarding with libssh
To do reverse port forwarding, call ssh_channel_listen_forward(),
then ssh_channel_accept_forward().
When you call ssh_channel_listen_forward(), 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
(port number < 1024).
Below is an example of a very rough web server waiting for connections on port
8080 of remote SSH server. The incoming connections are passed to the
local libssh application, which handles them:
@code
int web_server(ssh_session session)
{
int rc;
ssh_channel channel;
char buffer[256];
int nbytes, nwritten;
int port = 0;
char *helloworld = ""
"HTTP/1.1 200 OK\n"
"Content-Type: text/html\n"
"Content-Length: 113\n"
"\n"
"<html>\n"
" <head>\n"
" <title>Hello, World!</title>\n"
" </head>\n"
" <body>\n"
" <h1>Hello, World!</h1>\n"
" </body>\n"
"</html>\n";
rc = ssh_channel_listen_forward(session, NULL, 8080, NULL);
if (rc != SSH_OK)
{
fprintf(stderr, "Error opening remote port: %s\n",
ssh_get_error(session));
return rc;
}
channel = ssh_channel_accept_forward(session, 60000, &port);
if (channel == NULL)
{
fprintf(stderr, "Error waiting for incoming connection: %s\n",
ssh_get_error(session));
return SSH_ERROR;
}
while (1)
{
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
if (nbytes < 0)
{
fprintf(stderr, "Error reading incoming data: %s\n",
ssh_get_error(session));
ssh_channel_send_eof(channel);
ssh_channel_free(channel);
return SSH_ERROR;
}
if (strncmp(buffer, "GET /", 5)) continue;
nbytes = strlen(helloworld);
nwritten = ssh_channel_write(channel, helloworld, nbytes);
if (nwritten != nbytes)
{
fprintf(stderr, "Error sending answer: %s\n",
ssh_get_error(session));
ssh_channel_send_eof(channel);
ssh_channel_free(channel);
return SSH_ERROR;
}
printf("Sent answer\n");
}
ssh_channel_send_eof(channel);
ssh_channel_free(channel);
return SSH_OK;
}
@endcode
*/

454
doc/guided_tour.dox Normal file
View File

@@ -0,0 +1,454 @@
/**
@page libssh_tutor_guided_tour Chapter 1: A typical SSH session
@section ssh_session A typical SSH session
A SSH session goes through the following steps:
- Before connecting to the server, you can set up if you wish one or other
server public key authentication, i.e. DSA or RSA. You can choose
cryptographic algorithms you trust and compression algorithms if any. You
must of course set up the hostname.
- The connection is established. A secure handshake is made, and resulting from
it, a public key from the server is gained. You MUST verify that the public
key is legitimate, using for instance the MD5 fingerprint or the known hosts
file.
- The client must authenticate: the classical ways are password, or
public keys (from dsa and rsa key-pairs generated by openssh).
If a SSH agent is running, it is possible to use it.
- Now that the user has been authenticated, you must open one or several
channels. Channels are different subways for information into a single ssh
connection. Each channel has a standard stream (stdout) and an error stream
(stderr). You can theoretically open an infinity of channels.
- With the channel you opened, you can do several things:
- Execute a single command.
- Open a shell. You may want to request a pseudo-terminal before.
- Invoke the sftp subsystem to transfer files.
- Invoke the scp subsystem to transfer files.
- Invoke your own subsystem. This is outside the scope of this document,
but can be done.
- When everything is finished, just close the channels, and then the connection.
The sftp and scp subsystems use channels, but libssh hides them to
the programmer. If you want to use those subsystems, instead of a channel,
you'll usually open a "sftp session" or a "scp session".
@subsection setup Creating the session and setting options
The most important object in a SSH connection is the SSH session. In order
to allocate a new SSH session, you use ssh_new(). Don't forget to
always verify that the allocation successed.
@code
#include <libssh/libssh.h>
#include <stdlib.h>
int main()
{
ssh_session my_ssh_session = ssh_new();
if (my_ssh_session == NULL)
exit(-1);
...
ssh_free(my_ssh_session);
}
@endcode
libssh follows the allocate-it-deallocate-it pattern. Each object that you allocate
using xxxxx_new() must be deallocated using xxxxx_free(). In this case, ssh_new()
does the allocation and ssh_free() does the contrary.
The ssh_options_set() function sets the options of the session. The most important options are:
- SSH_OPTIONS_HOST: the name of the host you want to connect to
- SSH_OPTIONS_PORT: the used port (default is port 22)
- SSH_OPTIONS_USER: the system user under which you want to connect
- SSH_OPTIONS_LOG_VERBOSITY: the quantity of messages that are printed
The complete list of options can be found in the documentation of ssh_options_set().
The only mandatory option is SSH_OPTIONS_HOST. If you don't use SSH_OPTIONS_USER,
the local username of your account will be used.
Here is a small example of how to use it:
@code
#include <libssh/libssh.h>
#include <stdlib.h>
int main()
{
ssh_session my_ssh_session;
int verbosity = SSH_LOG_PROTOCOL;
int port = 22;
my_ssh_session = ssh_new();
if (my_ssh_session == NULL)
exit(-1);
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
ssh_options_set(my_ssh_session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &port);
...
ssh_free(my_ssh_session);
}
@endcode
Please notice that all parameters are passed to ssh_options_set() as pointers,
even if you need to set an integer value.
@see ssh_new
@see ssh_free
@see ssh_options_set
@see ssh_options_parse_config
@see ssh_options_copy
@see ssh_options_getopt
@subsection connect Connecting to the server
Once all settings have been made, you can connect using ssh_connect(). That
function will return SSH_OK if the connection worked, SSH_ERROR otherwise.
You can get the English error string with ssh_get_error() in order to show the
user what went wrong. Then, use ssh_disconnect() when you want to stop
the session.
Here's an example:
@code
#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
ssh_session my_ssh_session;
int rc;
my_ssh_session = ssh_new();
if (my_ssh_session == NULL)
exit(-1);
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
rc = ssh_connect(my_ssh_session);
if (rc != SSH_OK)
{
fprintf(stderr, "Error connecting to localhost: %s\n",
ssh_get_error(my_ssh_session));
exit(-1);
}
...
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
}
@endcode
@subsection serverauth Authenticating the server
Once you're connected, the following step is mandatory: you must check that the server
you just connected to is known and safe to use (remember, SSH is about security and
authentication).
There are two ways of doing this:
- The first way (recommended) is to use the ssh_is_server_known()
function. This function will look into the known host file
(~/.ssh/known_hosts on UNIX), look for the server hostname's pattern,
and determine whether this host is present or not in the list.
- The second way is to use ssh_get_pubkey_hash() to get a binary version
of the public key hash value. You can then use your own database to check
if this public key is known and secure.
You can also use the ssh_get_pubkey_hash() to show the public key hash
value to the user, in case he knows what the public key hash value is
(some paranoid people write their public key hash values on paper before
going abroad, just in case ...).
If the remote host is being used to for the first time, you can ask the user whether
he/she trusts it. Once he/she concluded that the host is valid and worth being
added in the known hosts file, you use ssh_write_knownhost() to register it in
the known hosts file, or any other way if you use your own database.
The following example is part of the examples suite available in the
examples/ directory:
@code
#include <errno.h>
#include <string.h>
int verify_knownhost(ssh_session session)
{
int state, hlen;
unsigned char *hash = NULL;
char *hexa;
char buf[10];
state = ssh_is_server_known(session);
hlen = ssh_get_pubkey_hash(session, &hash);
if (hlen < 0)
return -1;
switch (state)
{
case SSH_SERVER_KNOWN_OK:
break; /* ok */
case SSH_SERVER_KNOWN_CHANGED:
fprintf(stderr, "Host key for server changed: it is now:\n");
ssh_print_hexa("Public key hash", hash, hlen);
fprintf(stderr, "For security reasons, connection will be stopped\n");
free(hash);
return -1;
case SSH_SERVER_FOUND_OTHER:
fprintf(stderr, "The host key for this server was not found but an other"
"type of key exists.\n");
fprintf(stderr, "An attacker might change the default server key to"
"confuse your client into thinking the key does not exist\n");
free(hash);
return -1;
case SSH_SERVER_FILE_NOT_FOUND:
fprintf(stderr, "Could not find known host file.\n");
fprintf(stderr, "If you accept the host key here, the file will be"
"automatically created.\n");
/* fallback to SSH_SERVER_NOT_KNOWN behavior */
case SSH_SERVER_NOT_KNOWN:
hexa = ssh_get_hexa(hash, hlen);
fprintf(stderr,"The server is unknown. Do you trust the host key?\n");
fprintf(stderr, "Public key hash: %s\n", hexa);
free(hexa);
if (fgets(buf, sizeof(buf), stdin) == NULL)
{
free(hash);
return -1;
}
if (strncasecmp(buf, "yes", 3) != 0)
{
free(hash);
return -1;
}
if (ssh_write_knownhost(session) < 0)
{
fprintf(stderr, "Error %s\n", strerror(errno));
free(hash);
return -1;
}
break;
case SSH_SERVER_ERROR:
fprintf(stderr, "Error %s", ssh_get_error(session));
free(hash);
return -1;
}
free(hash);
return 0;
}
@endcode
@see ssh_connect
@see ssh_disconnect
@see ssh_get_error
@see ssh_get_error_code
@see ssh_get_pubkey_hash
@see ssh_is_server_known
@see ssh_write_knownhost
@subsection auth Authenticating the user
The authentication process is the way a service provider can identify a
user and verify his/her identity. The authorization process is about enabling
the authenticated user the access to ressources. In SSH, the two concepts
are linked. After authentication, the server can grant the user access to
several ressources such as port forwarding, shell, sftp subsystem, and so on.
libssh supports several methods of authentication:
- "none" method. This method allows to get the available authentications
methods. It also gives the server a chance to authenticate the user with
just his/her login. Some very old hardware uses this feature to fallback
the user on a "telnet over SSH" style of login.
- password method. A password is sent to the server, which accepts it or not.
- keyboard-interactive method. The server sends several challenges to the
user, who must answer correctly. This makes possible the authentication
via a codebook for instance ("give code at 23:R on page 3").
- public key method. The host knows the public key of the user, and the
user must prove he knows the associated private key. This can be done
manually, or delegated to the SSH agent as we'll see later.
All these methods can be combined. You can for instance force the user to
authenticate with at least two of the authentication methods. In that case,
one speaks of "Partial authentication". A partial authentication is a
response from authentication functions stating that your credential was
accepted, but yet another one is required to get in.
The example below shows an authentication with password:
@code
#include <libssh/libssh.h>
#include <stdlib.h>
#include <stdio.h>
int main()
{
ssh_session my_ssh_session;
int rc;
char *password;
// Open session and set options
my_ssh_session = ssh_new();
if (my_ssh_session == NULL)
exit(-1);
ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, "localhost");
// Connect to server
rc = ssh_connect(my_ssh_session);
if (rc != SSH_OK)
{
fprintf(stderr, "Error connecting to localhost: %s\n",
ssh_get_error(my_ssh_session));
ssh_free(my_ssh_session);
exit(-1);
}
// Verify the server's identity
// For the source code of verify_knowhost(), check previous example
if (verify_knownhost(my_ssh_session) < 0)
{
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
exit(-1);
}
// Authenticate ourselves
password = getpass("Password: ");
rc = ssh_userauth_password(my_ssh_session, NULL, password);
if (rc != SSH_AUTH_SUCCESS)
{
fprintf(stderr, "Error authenticating with password: %s\n",
ssh_get_error(my_ssh_session));
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
exit(-1);
}
...
ssh_disconnect(my_ssh_session);
ssh_free(my_ssh_session);
}
@endcode
@see @ref authentication_details
@subsection using_ssh Doing something
At this point, the authenticity of both server and client is established.
Time has come to take advantage of the many possibilities offered by the SSH
protocol: execute a remote command, open remote shells, transfer files,
forward ports, etc.
The example below shows how to execute a remote command:
@code
int show_remote_processes(ssh_session session)
{
ssh_channel channel;
int rc;
char buffer[256];
unsigned int nbytes;
channel = ssh_channel_new(session);
if (channel == NULL)
return SSH_ERROR;
rc = ssh_channel_open_session(channel);
if (rc != SSH_OK)
{
ssh_channel_free(channel);
return rc;
}
rc = ssh_channel_request_exec(channel, "ps aux");
if (rc != SSH_OK)
{
ssh_channel_close(channel);
ssh_channel_free(channel);
return rc;
}
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
while (nbytes > 0)
{
if (write(1, buffer, nbytes) != nbytes)
{
ssh_channel_close(channel);
ssh_channel_free(channel);
return SSH_ERROR;
}
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
}
if (nbytes < 0)
{
ssh_channel_close(channel);
ssh_channel_free(channel);
return SSH_ERROR;
}
ssh_channel_send_eof(channel);
ssh_channel_close(channel);
ssh_channel_free(channel);
return SSH_OK;
}
@endcode
@see @ref opening_shell
@see @ref remote_command
@see @ref sftp_subsystem
@see @ref scp_subsystem
@subsection errors Handling the errors
All the libssh functions which return an error value also set an English error message
describing the problem.
Error values are typically SSH_ERROR for integer values, or NULL for pointers.
The function ssh_get_error() returns a pointer to the static error message.
ssh_error_code() returns the error code number : SSH_NO_ERROR,
SSH_REQUEST_DENIED, SSH_INVALID_REQUEST, SSH_CONNECTION_LOST, SSH_FATAL,
or SSH_INVALID_DATA. SSH_REQUEST_DENIED means the ssh server refused your
request, but the situation is recoverable. The others mean something happened
to the connection (some encryption problems, server problems, ...).
SSH_INVALID_REQUEST means the library got some garbage from server, but
might be recoverable. SSH_FATAL means the connection has an important
problem and isn't probably recoverable.
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.
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.
*/

49
doc/introduction.dox Normal file
View File

@@ -0,0 +1,49 @@
/**
@page libssh_tutorial The Tutorial
@section introduction Introduction
libssh is a C library that enables you to write a program that uses the
SSH protocol. With it, you can remotely execute programs, transfer
files, or use a secure and transparent tunnel for your remote programs.
The SSH protocol is encrypted, ensures data integrity, and provides strong
means of authenticating both the server of the client. The library hides
a lot of technical details from the SSH protocol, but this does not
mean that you should not try to know about and understand these details.
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 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),
you'll have to jump to the end of this document.
This tutorial describes libssh version 0.5.0. This version is a little different
from the 0.4.X series. However, the examples should work with
little changes on versions like 0.4.2 and later.
Table of contents:
@subpage libssh_tutor_guided_tour
@subpage libssh_tutor_authentication
@subpage libssh_tutor_shell
@subpage libssh_tutor_command
@subpage libssh_tutor_sftp
@subpage libssh_tutor_scp
@subpage libssh_tutor_forwarding
@subpage libssh_tutor_threads
@subpage libssh_tutor_todo
*/

View File

@@ -1,385 +0,0 @@
The new libssh 0.2 API
----------------------
Version 1
A. Introduction
---------------
With the time from the first release of libssh, I have received lots of
comments about the current API. Myself, I found it quite limiting when doing
my first libssh-server drafts. Thus, I am moving to a stronger API.
This API must still be simple. I am not introducing complex changes. An API
well designed must hide the implementation details. Implementation can change
easily within bugfixes - but API cannot change each release.
To the people already using libssh 0.11 : sorry. Once I have the complete API
redesigned, I will write a migration paper. It won't be too hard normally.
Here are the things that were lacking in the previous API and *must* change:
* A non-blocking mode connection type
* Functions to relegate File descriptor listening to Calling functions and to
the programmer. (I'll explain later).
* Along with that, good buffering system (well, it's not an API but).
* Leave the "functions returns a pointer when it works and NULL when it does
not work". It gives serious problems to implement bindings (A C++
constructor should not fail and should not depend on a network thing
* Make the Session structure an abstract structure that can work with both
client and *servers*. That mean we should have a Server object which listen
to clients on a bound port, does the different handshakes and return a
session.
Since C is not per se an Object language, I won't use inheritance between
objects.
* This same server thing must provide the reverse capabilities than the
client. That is, accept the handshake, in a nonblocking way. Accept channel
requests, or send them to the controller program.
* Support for program forking : Imagine you have a Ssh server object. You
accept a connection and receive a session, then you receive a channel. You
may want to keep the good old days fork() tricks. Libssh will give a way to
destroy handlers from sessions which belong to an other process without
disturbing the session.
* So often I received the comment back saying that it was not clear why a
session or a channel was terminated. This is over.
* And of course I received lot of mails about the fact I'm doing namespace
polution. this will be resolved this time.
So, please read this draft not as a formal documentation but like a roadmap of
things that each kind of object must do.
B. Description of objects and functions
Initialization and finalization
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Initialization is for now called automatically, so you don't have to take care
of that.
As for finalization, we need to finalize the underlying cryptographic library
(either OpenSSL or libgcrypt). Be sure that you call ssh_finalize when this
library won't be used anymore, even by other libraries (i.e. if you use libssh
and another library that uses OpenSSL, call ssh_finalize when any function of
both these libraries won't be called).
If you trust your operating system to clean up the mess after a process
terminates, you can skip this call.
Options structure
~~~~~~~~~~~~~~~~~
struct ssh_options *ssh_options_new()
ssh_options_getopt(options, *argc, argv)
ssh_options_copy(options)
char ** ssh_options_get_supported_algos(options,type)
returns a list of the algos supported by libssh, type being one of
SSH_HOSTKEYS, SSH_KEX, SSH_CRYPT, SSH_MAC, SSH_COMP, SSH_LANG
ssh_options_set_wanted_algos(options,type, char *list)
list being comma-separated list of algos, and type being the upper constants
but with _C_S or _S_V added to them.
ssh_options_set_port(options, port)
ssh_options_set_host(options, host)
ssh_options_set_fd(options, fd)
ssh_options_set_bind(options, bindaddr, port)
this options sets the address to bind for a client *or* a server. a port of
zero means whatever port is free (what most clients want).
ssh_options_set_username(options, username)
ssh_options_set_connect_timeout(options, seconds, usec)
ssh_options_set_ssh_dir(options, dir)
ssh_options_set_known_hosts_file(options, file)
ssh_options_set_identity(options, file)
ssh_options_set_banner(options, banner)
ssh_options_allow_ssh1(options, bool allow)
ssh_options_allow_ssh2(options, bool allow)
options_set_status_callback has moved into ssh_* functions.
ssh_session Structure
~~~~~~~~~~~~~~~~~~~~~
This session structure represents a ssh socket to a server *or* a client.
ssh_session *ssh_new()
ssh_set_options(ssh_session,ssh_options)
ssh_connect(session);
it will return some status describing at which point of the connection it is,
or an error code. If the connection method is non-blocking, the function
will be called more than once, though the return value SSH_AGAIN.
ssh_set_blocking(session, bool blocking)
set blocking mode or non blocking mode.
ssh_get_fd(session)
get the currently used connection file descriptor or equivalent (windows)
ssh_set_fd_toread(session)
ssh_set_fd_towrite(session)
ssh_set_fd_except(session)
Serve to notify the library that data is actualy available to be read on the
file descriptor socket. why ? because on most platforms select can't be done
twice on the same socket when the first reported data to read or to write
ssh_get_status(session)
Returns the current status bitmask : connection Open or closed, data
pending to read or not (even if connection closed), connection closed on
error or on an exit message
ssh_get_disconnect_message(session)
Returns the connection disconnect error/exit message
ssh_get_pubkey_hash(session, hash)
get the public key hash from the server.
ssh_is_server_known(session)
ssh_write_knownhost(session)
these 2 functions will be kept
ssh_disconnect(session)
standard disconnect
ssh_disconnect_error(session,error code, message)
disconnect with a message
ssh_set_username(session)
set the user name to log in
ssh_userauth_* functions will be kept as they are now, excepted the fact that
the username field will disapear.
the public key mechanism may get some more functions, like retrieving a public
key from a private key and authenticating without a public key.
ssh_get_issue_banner(session)
get the issue banner from the server, that is the welcome message.
ssh_silent_free(session)
This function silently free all data structures used by the session and
closes the socket. It may be used for instance when the process forked and
doesn't want to keep track of this session. This is obviously not possible to
do with separate channels.
The channel_struct structure
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The channels will change a bit. the constructor thing will change, and the way
to multiplex different connections will change too. channel functions will be
prefixed with "ssh_"
struct channel_struct *ssh_channel_new()
ssh_channel_open_session(channel)
will return if the channel allocation failed or not.
ssh_channel_open_forward(channel, ...) won't change. it will report an error if
the channel allocation failed.
ssh_channel_send_eof(channel)
send EOF
ssh_channel_close(channel)
closes a channel but doesn't destroy it. you may read unread data still in
the buffer. Once you closed the buffer, the other party can't send you data,
while it could still do it if you only sent an EOF.
ssh_channel_is_closed(channel)
returns true if the channel was closed at one of both sides. a closed chan
may still have data to read, if you closed yourself the connection. otherwise
(you didn't close it) the closed notification only comes when you read the
last buffer byte, or when trying to write into the channel (the SIGPIPE-like
behaviour).
ssh_channel_is_eof(channel)
reports if the other side has sent an EOF. This functions returns FALSE if
there is still data to read. A closed channel is always EOF.
ssh_channel_free(channel)
completely free the channel. closes it before if it was not done.
ssh_channel_request_env(channel, name, value)
set an environment variable.
ssh_channel_request_pty(channel)
ssh_channel_request_pty_size()
ssh_channel_change_pty_size()
ssh_channel_request_shell()
ssh_channel_request_exec()
ssh_channel_request_subsystem()
These functions won't change.
int ssh_channel_write(channel,data, len,stderr)
Depending on the blocking/non blocking mode of the channel, the behaviour may
change.
stderr is the extended buffer. It's generaly only a server->client stream.
ssh_channel_set_blocking(bool blocking)
int ssh_channel_read(channel, buffer, maxlen, is_stderr)
the behaviour will be this one:
-if the chan is in non blocking mode, it will poll what's available to read
and return this. otherwise (nothing to read) it will return 0.
-if the chan is blocking, it will block until at least one byte is
available.
ssh_channel_nonblocking disapears for the later reason.
int channel_poll(channel, is_stderr)
polls the network and reports the number of bytes ready to be read in the
chan.
ssh_session ssh_channel_get_session(channel)
returns the session pointer associated to the channel, for simplicity
reasons.
int ssh_channel_select(CHANNELS *readchans, CHANNELS *writechans, CHANNELS
*exceptchans, struct timeval *timeout)
This function won't work the same way ssh_select did.
I removed the custom file descriptor thing for 2 reasons:
1- it's not windows compliant. D'ouh !
2- most programmers won't want to depend on libssh for socket multiplexing.
that's why i let the programmer poll the fds himself and then use
ssh_set_fd_toread, towrite or except. Then, he may use ssh_channel_select
with a NULL timeout to poll which channels have something to read, write or
error report.
Here is how it's going to work. The coder sets 3 different arrays with the
channels he wants to select(), the last entry being a NULL pointer. The
function will first poll them and return the chans that must be
read/write/excepted. If nothing has this state, the function will select()
using the timeout.
The function will return 0 if everything is ok, SSH_TIMEOUT or SSH_EINTR if
the select was interrupted by a signal. It is dangerous to execute any
channel-related functions into signal handlers. they should set a flag that
you read into your loop. this "trap" (SSH_EINTR) will permit you to catch
them faster and make your program responsive and look fast.
the function will return -1 if a serious problem happens.
Error handling
~~~~~~~~~~~~~~
when an error happens, the programmer can get the error code and description
with ssh_get_error(session). the creation of a failess constructor for
ssh_session was needed for this reason.
ssh_get_error_code(session) will return an error code into this subset:
SSH_NO_ERROR : no error :)
SSH_REQUEST_DENIED : you request for a functionality or a service that is not
allowed. The session can continue.
SSH_FATAL : Unrecoverable error. The session can't continue and you should
disconnect the session. It includes the connection being cut without a
disconnect() message.
If a disconnect() message or the channel was closed, a read on such a channel
won't produce an error. otherwise it will return -1 with a SSH_FATAL error
code.
Server socket binding
~~~~~~~~~~~~~~~~~~~~~
It is not possible to bind a socket for ssh with a SSH_SESSION type, because a
single bound port may lead to multiple ssh connections. That's why the
SSH_BIND structure must be created. It uses options from the SSH_OPTIONS
structure.
SSH_BIND *ssh_bind_new()
creates a structure
ssh_bind_set_options(bind, options)
set the option structure
int ssh_bind_listen(bind)
bind and listen to the port. This call is not blocking. if some error
happens, it returns -1 and the error code can be found with perror().
ssh_bind_set_blocking(bind, bool blocking)
should ssh_bind_accept() block or not.
int ssh_bind_get_fd(bind)
return the bound file descriptor, that is the listener socket. you may put it
into a select() in your code to detect a connection attempt.
ssh_bind_set_fd_toaccept(bind)
say that the listener socket has a connection to accept (to avoid
ssh_bind_accept() to do a select on it).
SSH_SESSION *ssh_bind_accept(bind)
return a server handle to a ssh session. if the mode is blocking, the
function will always return a pointer to a session. if the mode is not
blocking, the function can return NULL if there is no connection to accept.
This SSH_SESSION handle must then pass through the functions explained above.
*server functions *
int ssh_accept(session)
when a new connection is accepted, the handshake must be done. this function
will do the banner handshake and the key exchange.
it will return SSH_AGAIN if the session mode is non blocking, and the
function must be called again until an error occurs or the kex is done.
Here, I had a few choises about *how* to implement the message parsing as a
server. There are multiple ways to do it, one being callbacks and one being
"Message" reading, parsing and then choice going to the user to use it and
answer. I've choosen the latter because i believe it's the stronger method.
A ssh server can receive 30 different kind of messages having to be dealt by
the high level routines, like channel request_shell or authentication. Having
a callback for all of them would produce a huge kludge of callbacks, with
no relations on when there were called etc.
A message based parsing allows the user to filtrate the messages he's
interested into and to use a default answer for the others. Then, the callback
thing is still possible to handle through a simple message code/callback
function array.
I did not define yet what it would look like, but i'm sure there will be a
SSH_MESSAGE (they won't have a 1/1 correspondance with ssh packets) which will
be read through
SSH_MESSAGE *ssh_server_read_message(session).
with all of the non-blocking stuff in head like returning NULL if the message
is not full.
Then, the message can be parsed, ie
int ssh_message_get_code(message)
which will return SSH_MESSAGE_AUTH
then
int ssh_message_get_subcode(message)
which then will returh SSH_MESSAGE_AUTH_PASSWORD or _NONE or _PUBKEY etc.
Then, once the message was parsed, the message will have to be answered, ie
with the generic functions like
ssh_message_accept(message) which says 'Ok your request is accepted' or
ssh_message_deny(message) which says 'Your request is refused'.
There would be specific message answer functions for some kind of messages
like the authentication one. you may want to reply that the authentication is
Partial rather than denied, and that you still accept some kind of auths, like
ssh_message_auth_reply(message,SSH_AUTH_PARTIAL,SSH_AUTH_PASSWORD |
SSH_AUTH_PUBKEY | SSH_AUTH_KEYBINT);
I won't let the user have to deal with the channels himself. When a channel is
going to be created by the remote size, a message will come asking to open a
channel. the programmer can either deny or accept, in which case a CHANNEL
object will be created and returned to the programmer. then, all standard
channel functions will run.
C. Change log of this document
3. Add paragraph about initalization and finalization.
2. ssh_options_set_username finaly is kept into the options, because it can be
set by ssh_options_getopt()
1. first release
D. End notes
I think libssh must have a very simple to use, powerful and exhaustive API. It
must have no design flaw either.
While I got some good experience at the SSH protocol, I've never writen
more-than-100 lines programs than use libssh and I don't really know the
problems of the library. I'd like people who don't understand some detail into
the API I describe here, who have comments or opinions about it to write me
the soonest possible to limit the damages if I made something the completely
wrong way.
Thanks for your patience.

30
doc/linking.dox Normal file
View File

@@ -0,0 +1,30 @@
/**
@page libssh_linking The Linking HowTo
@section dynamic Dynamic Linking
On UNIX and Windows systems its the same, you need at least the libssh.h
header file and the libssh shared library.
@section static Static Linking
@warning <b>The libssh library is licensed under the LGPL! Make sure you
understand what this means to your codebase if you want to distribute
binaries and link statically against LGPL code!</b>
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.
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
*/

224
doc/mainpage.dox Normal file
View File

@@ -0,0 +1,224 @@
/**
@mainpage
This is the online reference for developing with the libssh library. It
documents the libssh C API and the C++ wrapper.
@section main-linking Linking
We created a small howto how to link libssh against your application, read
@subpage libssh_linking.
@section main-tutorial Tutorial
You should start by reading @subpage libssh_tutorial, then reading the documentation of
the interesting functions as you go.
@section main-features Features
The libssh library provides:
- <strong>Key Exchange Methods</strong>: <i>curve25519-sha256@libssh.org, 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
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.
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.
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
@subsection main-rfc-secsh Secure Shell (SSH)
The following RFC documents described SSH-2 protcol as an Internet standard.
- <a href="http://tools.ietf.org/html/rfc4250" target="_blank">RFC 4250</a>,
The Secure Shell (SSH) Protocol Assigned Numbers
- <a href="http://tools.ietf.org/html/rfc4251" target="_blank">RFC 4251</a>,
The Secure Shell (SSH) Protocol Architecture
- <a href="http://tools.ietf.org/html/rfc4252" target="_blank">RFC 4252</a>,
The Secure Shell (SSH) Authentication Protocol
- <a href="http://tools.ietf.org/html/rfc4253" target="_blank">RFC 4253</a>,
The Secure Shell (SSH) Transport Layer Protocol
- <a href="http://tools.ietf.org/html/rfc4254" target="_blank">RFC 4254</a>,
The Secure Shell (SSH) Connection Protocol
- <a href="http://tools.ietf.org/html/rfc4255" target="_blank">RFC 4255</a>,
Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints
- <a href="http://tools.ietf.org/html/rfc4256" target="_blank">RFC 4256</a>,
Generic Message Exchange Authentication for the Secure Shell Protocol (SSH)
- <a href="http://tools.ietf.org/html/rfc4335" target="_blank">RFC 4335</a>,
The Secure Shell (SSH) Session Channel Break Extension
- <a href="http://tools.ietf.org/html/rfc4344" target="_blank">RFC 4344</a>,
The Secure Shell (SSH) Transport Layer Encryption Modes
- <a href="http://tools.ietf.org/html/rfc4345" target="_blank">RFC 4345</a>,
Improved Arcfour Modes for the Secure Shell (SSH) Transport Layer Protocol
It was later modified and expanded by the following RFCs.
- <a href="http://tools.ietf.org/html/rfc4419" target="_blank">RFC 4419</a>,
Diffie-Hellman Group Exchange for the Secure Shell (SSH) Transport Layer
Protocol
- <a href="http://tools.ietf.org/html/rfc4432" target="_blank">RFC 4432</a>,
RSA Key Exchange for the Secure Shell (SSH) Transport Layer Protocol
- <a href="http://tools.ietf.org/html/rfc4462" target="_blank">RFC 4462</a>,
Generic Security Service Application Program Interface (GSS-API)
Authentication and Key Exchange for the Secure Shell (SSH) Protocol
- <a href="http://tools.ietf.org/html/rfc4716" target="_blank">RFC 4716</a>,
The Secure Shell (SSH) Public Key File Format
- <a href="http://tools.ietf.org/html/rfc5647" target="_blank">RFC 5647</a>,
AES Galois Counter Mode for the Secure Shell Transport Layer Protocol
- <a href="http://tools.ietf.org/html/rfc5656" target="_blank">RFC 5656</a>,
Elliptic Curve Algorithm Integration in the Secure Shell Transport Layer
Interesting cryptography documents:
- <a href="http://www.cryptsoft.com/pkcs11doc/" target="_blank">PKCS #11</a>, PKCS #11 reference documents, describing interface with smartcards.
@subsection main-rfc-sftp Secure Shell File Transfer Protocol (SFTP)
The protocol is not an Internet standard but it is still widely implemented.
OpenSSH and most other implementation implement Version 3 of the protocol. We
do the same in libssh.
- <a href="http://tools.ietf.org/html/draft-ietf-secsh-filexfer-02" target="_blank">
draft-ietf-secsh-filexfer-02.txt</a>,
SSH File Transfer Protocol
@subsection main-rfc-extensions Secure Shell Extensions
The libssh project has an extension to support Curve25519 which is also supported by
the OpenSSH project.
- <a href="http://git.libssh.org/projects/libssh.git/tree/doc/curve25519-sha256@libssh.org.txt" target="_blank">curve25519-sha256@libssh.org</a>,
Curve25519-SHA256 for ECDH KEX
The OpenSSH project has defined some extensions to the protocol. We support some of
them like the statvfs calls in SFTP or the ssh-agent.
- <a href="http://api.libssh.org/rfc/PROTOCOL" target="_blank">
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>
*/

268
doc/scp.dox Normal file
View File

@@ -0,0 +1,268 @@
/**
@page libssh_tutor_scp Chapter 6: The SCP subsystem
@section scp_subsystem The SCP subsystem
The SCP subsystem has far less functionnality than the SFTP subsystem.
However, if you only need to copy files from and to the remote system,
it does its job.
@subsection scp_session Opening and closing a SCP session
Like in the SFTP subsystem, you don't handle the SSH channels directly.
Instead, you open a "SCP session".
When you open your SCP session, you have to choose between read or write mode.
You can't do both in the same session. So you specify either SSH_SCP_READ or
SSH_SCP_WRITE as the second parameter of function ssh_scp_new().
Another important mode flag for opening your SCP session is SSH_SCP_RECURSIVE.
When you use SSH_SCP_RECURSIVE, you declare that you are willing to emulate
the behaviour of "scp -r" command in your program, no matter it is for
reading or for writing.
Once your session is created, you initialize it with ssh_scp_init(). When
you have finished transferring files, you terminate the SCP connection with
ssh_scp_close(). Finally, you can dispose the SCP connection with
ssh_scp_free().
The example below does the maintenance work to open a SCP connection for writing in
recursive mode:
@code
int scp_write(ssh_session session)
{
ssh_scp scp;
int rc;
scp = ssh_scp_new
(session, SSH_SCP_WRITE | SSH_SCP_RECURSIVE, ".");
if (scp == NULL)
{
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));
ssh_scp_free(scp);
return rc;
}
...
ssh_scp_close(scp);
ssh_scp_free(scp);
return SSH_OK;
}
@endcode
The example below shows how to open a connection to read a single file:
@code
int scp_read(ssh_session session)
{
ssh_scp scp;
int rc;
scp = ssh_scp_new
(session, SSH_SCP_READ, "helloworld/helloworld.txt");
if (scp == NULL)
{
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));
ssh_scp_free(scp);
return rc;
}
...
ssh_scp_close(scp);
ssh_scp_free(scp);
return SSH_OK;
}
@endcode
@subsection scp_write Creating files and directories
You create directories with ssh_scp_push_directory(). In recursive mode,
you are placed in this directory once it is created. If the directory
already exists and if you are in recursive mode, you simply enter that
directory.
Creating files is done in two steps. First, you prepare the writing with
ssh_scp_push_file(). Then, you write the data with ssh_scp_write().
The length of the data to write must be identical between both function calls.
There's no need to "open" nor "close" the file, this is done automatically
on the remote end. If the file already exists, it is overwritten and truncated.
The following example creates a new directory named "helloworld/", then creates
a file named "helloworld.txt" in that directory:
@code
int scp_helloworld(ssh_session session, ssh_scp scp)
{
int rc;
const char *helloworld = "Hello, world!\n";
int length = strlen(helloworld);
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));
return rc;
}
rc = ssh_scp_push_file
(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));
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));
return rc;
}
return SSH_OK;
}
@endcode
@subsection scp_recursive_write Copying full directory trees to the remote server
Let's say you want to copy the following tree of files to the remote site:
@verbatim
+-- file1
+-- B --+
| +-- file2
-- A --+
| +-- file3
+-- C --+
+-- file4
@endverbatim
You would do it that way:
- open the session in recursive mode
- enter directory A
- enter its subdirectory B
- create file1 in B
- create file2 in B
- leave directory B
- enter subdirectory C
- create file3 in C
- create file4 in C
- leave directory C
- leave directory A
To leave a directory, call ssh_scp_leave_directory().
@subsection scp_read Reading files and directories
To receive files, you pull requests from the other side with ssh_scp_pull_request().
If this function returns SSH_SCP_REQUEST_NEWFILE, then you must get ready for
the reception. You can get the size of the data to receive with ssh_scp_request_get_size()
and allocate a buffer accordingly. When you are ready, you accept the request with
ssh_scp_accept_request(), then read the data with ssh_scp_read().
The following example receives a single file. The name of the file to
receive has been given earlier, when the scp session was opened:
@code
int scp_receive(ssh_session session, ssh_scp scp)
{
int rc;
int size, mode;
char *filename, *buffer;
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));
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);
free(filename);
buffer = malloc(size);
if (buffer == NULL)
{
fprintf(stderr, "Memory allocation error\n");
return SSH_ERROR;
}
ssh_scp_accept_request(scp);
rc = ssh_scp_read(scp, buffer, size);
if (rc == SSH_ERROR)
{
fprintf(stderr, "Error receiving file data: %s\n",
ssh_get_error(session));
free(buffer);
return rc;
}
printf("Done\n");
write(1, buffer, size);
free(buffer);
rc = ssh_scp_pull_request(scp);
if (rc != SSH_SCP_REQUEST_EOF)
{
fprintf(stderr, "Unexpected request: %s\n",
ssh_get_error(session));
return SSH_ERROR;
}
return SSH_OK;
}
@endcode
In this example, since we just requested a single file, we expect ssh_scp_request()
to return SSH_SCP_REQUEST_NEWFILE first, then SSH_SCP_REQUEST_EOF. That's quite a
naive approach; for example, the remote server might send a warning as well
(return code SSH_SCP_REQUEST_WARNING) and the example would fail. A more comprehensive
reception program would receive the requests in a loop and analyze them carefully
until SSH_SCP_REQUEST_EOF has been received.
@subsection scp_recursive_read Receiving full directory trees from the remote server
If you opened the SCP session in recursive mode, the remote end will be
telling you when to change directory.
In that case, when ssh_scp_pull_request() answers
SSH_SCP_REQUEST_NEWDIRECTORY, you should make that local directory (if
it does not exist yet) and enter it. When ssh_scp_pull_request() answers
SSH_SCP_REQUEST_ENDDIRECTORY, you should leave the current directory.
*/

431
doc/sftp.dox Normal file
View File

@@ -0,0 +1,431 @@
/**
@page libssh_tutor_sftp Chapter 5: The SFTP subsystem
@section sftp_subsystem The SFTP subsystem
SFTP stands for "Secure File Transfer Protocol". It enables you to safely
transfer files between the local and the remote computer. It reminds a lot
of the old FTP protocol.
SFTP is a rich protocol. It lets you do over the network almost everything
that you can do with local files:
- send files
- modify only a portion of a file
- receive files
- receive only a portion of a file
- get file owner and group
- get file permissions
- set file owner and group
- set file permissions
- remove files
- rename files
- create a directory
- remove a directory
- retrieve the list of files in a directory
- get the target of a symbolic link
- create symbolic links
- get information about mounted filesystems.
The current implemented version of the SFTP protocol is version 3. All functions
aren't implemented yet, but the most important are.
@subsection sftp_session Opening and closing a SFTP session
Unlike with remote shells and remote commands, when you use the SFTP subsystem,
you don't handle directly the SSH channels. Instead, you open a "SFTP session".
The function sftp_new() creates a new SFTP session. The function sftp_init()
initializes it. The function sftp_free() deletes it.
As you see, all the SFTP-related functions start with the "sftp_" prefix
instead of the usual "ssh_" prefix.
The example below shows how to use these functions:
@code
#include <libssh/sftp.h>
int sftp_helloworld(ssh_session session)
{
sftp_session sftp;
int rc;
sftp = sftp_new(session);
if (sftp == NULL)
{
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));
sftp_free(sftp);
return rc;
}
...
sftp_free(sftp);
return SSH_OK;
}
@endcode
@subsection sftp_errors Analyzing SFTP errors
In case of a problem, the function sftp_get_error() returns a SFTP-specific
error number, in addition to the regular SSH error number returned by
ssh_get_error_number().
Possible errors are:
- SSH_FX_OK: no error
- SSH_FX_EOF: end-of-file encountered
- SSH_FX_NO_SUCH_FILE: file does not exist
- SSH_FX_PERMISSION_DENIED: permission denied
- SSH_FX_FAILURE: generic failure
- SSH_FX_BAD_MESSAGE: garbage received from server
- SSH_FX_NO_CONNECTION: no connection has been set up
- SSH_FX_CONNECTION_LOST: there was a connection, but we lost it
- SSH_FX_OP_UNSUPPORTED: operation not supported by libssh yet
- SSH_FX_INVALID_HANDLE: invalid file handle
- SSH_FX_NO_SUCH_PATH: no such file or directory path exists
- SSH_FX_FILE_ALREADY_EXISTS: an attempt to create an already existing file or directory has been made
- SSH_FX_WRITE_PROTECT: write-protected filesystem
- SSH_FX_NO_MEDIA: no media was in remote drive
@subsection sftp_mkdir Creating a directory
The function sftp_mkdir() tahes the "SFTP session" we juste created as
its first argument. It also needs the name of the file to create, and the
desired permissions. The permissions are the same as for the usual mkdir()
function. To get a comprehensive list of the available permissions, use the
"man 2 stat" command. The desired permissions are combined with the remote
user's mask to determine the effective permissions.
The code below creates a directory named "helloworld" in the current directory that
can be read and written only by its owner:
@code
#include <libssh/sftp.h>
#include <sys/stat.h>
int sftp_helloworld(ssh_session session, sftp_session sftp)
{
int rc;
rc = sftp_mkdir(sftp, "helloworld", S_IRWXU);
if (rc != SSH_OK)
{
if (sftp_get_error(sftp) != SSH_FX_FILE_ALREADY_EXISTS)
{
fprintf(stderr, "Can't create directory: %s\n",
ssh_get_error(session));
return rc;
}
}
...
return SSH_OK;
}
@endcode
Unlike its equivalent in the SCP subsystem, this function does NOT change the
current directory to the newly created subdirectory.
@subsection sftp_write Copying a file to the remote computer
You handle the contents of a remote file just like you would do with a
local file: you open the file in a given mode, move the file pointer in it,
read or write data, and close the file.
The sftp_open() function is very similar to the regular open() function,
excepted that it returns a file handle of type sftp_file. This file handle
is then used by the other file manipulation functions and remains valid
until you close the remote file with sftp_close().
The example below creates a new file named "helloworld.txt" in the
newly created "helloworld" directory. If the file already exists, it will
be truncated. It then writes the famous "Hello, World!" sentence to the
file, followed by a new line character. Finally, the file is closed:
@code
#include <libssh/sftp.h>
#include <sys/stat.h>
#include <fcntl.h>
int sftp_helloworld(ssh_session session, sftp_session sftp)
{
int access_type = O_WRONLY | O_CREAT | O_TRUNC;
sftp_file file;
const char *helloworld = "Hello, World!\n";
int length = strlen(helloworld);
int rc, nwritten;
...
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));
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));
sftp_close(file);
return SSH_ERROR;
}
rc = sftp_close(file);
if (rc != SSH_OK)
{
fprintf(stderr, "Can't close the written file: %s\n",
ssh_get_error(session));
return rc;
}
return SSH_OK;
}
@endcode
@subsection sftp_read Reading a file from the remote computer
The nice thing with reading a file over the network through SFTP is that it
can be done both in a synchronous way or an asynchronous way. If you read the file
asynchronously, your program can do something else while it waits for the
results to come.
Synchronous read is done with sftp_read().
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[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;
}
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;
}
return SSH_OK;
}
@endcode
Asynchronous read is done in two steps, first sftp_async_read_begin(), which
returns a "request handle", and then sftp_async_read(), which uses that request handle.
If the file has been opened in nonblocking mode, then sftp_async_read()
might return SSH_AGAIN, which means that the request hasn't completed yet
and that the function should be called again later on. Otherwise,
sftp_async_read() waits for the data to come. To open a file in nonblocking mode,
call sftp_file_set_nonblocking() right after you opened it. Default is blocking mode.
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[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));
return SSH_ERROR;
}
sftp_file_set_nonblocking(file);
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 (nbytes < 0) {
fprintf(stderr, "Error while reading file: %s\n",
ssh_get_error(session));
sftp_close(file);
return SSH_ERROR;
}
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));
return rc;
}
return SSH_OK;
}
@endcode
@subsection sftp_ls Listing the contents of a directory
The functions sftp_opendir(), sftp_readdir(), sftp_dir_eof(),
and sftp_closedir() enable to list the contents of a directory.
They use a new handle_type, "sftp_dir", which gives access to the
directory being read.
In addition, sftp_readdir() returns a "sftp_attributes" which is a pointer
to a structure with informations about a directory entry:
- name: the name of the file or directory
- size: its size in bytes
- etc.
sftp_readdir() might return NULL under two conditions:
- when the end of the directory has been met
- when an error occured
To tell the difference, call sftp_dir_eof().
The attributes must be freed with sftp_attributes_free() when no longer
needed.
The following example reads the contents of some remote directory:
@code
int sftp_list_dir(ssh_session session, sftp_session sftp)
{
sftp_dir dir;
sftp_attributes attributes;
int rc;
dir = sftp_opendir(sftp, "/var/log");
if (!dir)
{
fprintf(stderr, "Directory not opened: %s\n",
ssh_get_error(session));
return SSH_ERROR;
}
printf("Name Size Perms Owner\tGroup\n");
while ((attributes = sftp_readdir(sftp, dir)) != NULL)
{
printf("%-20s %10llu %.8o %s(%d)\t%s(%d)\n",
attributes->name,
(long long unsigned int) attributes->size,
attributes->permissions,
attributes->owner,
attributes->uid,
attributes->group,
attributes->gid);
sftp_attributes_free(attributes);
}
if (!sftp_dir_eof(dir))
{
fprintf(stderr, "Can't list directory: %s\n",
ssh_get_error(session));
sftp_closedir(dir);
return SSH_ERROR;
}
rc = sftp_closedir(dir);
if (rc != SSH_OK)
{
fprintf(stderr, "Can't close directory: %s\n",
ssh_get_error(session));
return rc;
}
}
@endcode
*/

361
doc/shell.dox Normal file
View File

@@ -0,0 +1,361 @@
/**
@page libssh_tutor_shell Chapter 3: Opening a remote shell
@section opening_shell Opening a remote shell
We already mentioned that a single SSH connection can be shared
between several "channels". Channels can be used for different purposes.
This chapter shows how to open one of these channels, and how to use it to
start a command interpreter on a remote computer.
@subsection open_channel Opening and closing a channel
The ssh_channel_new() function creates a channel. It returns the channel as
a variable of type ssh_channel.
Once you have this channel, you open a SSH session that uses it with
ssh_channel_open_session().
Once you don't need the channel anymore, you can send an end-of-file
to it with ssh_channel_close(). At this point, you can destroy the channel
with ssh_channel_free().
The code sample below achieves these tasks:
@code
int shell_session(ssh_session session)
{
ssh_channel channel;
int rc;
channel = ssh_channel_new(session);
if (channel == NULL)
return SSH_ERROR;
rc = ssh_channel_open_session(channel);
if (rc != SSH_OK)
{
ssh_channel_free(channel);
return rc;
}
...
ssh_channel_close(channel);
ssh_channel_send_eof(channel);
ssh_channel_free(channel);
return SSH_OK;
}
@endcode
@subsection interactive Interactive and non-interactive sessions
A "shell" is a command interpreter. It is said to be "interactive"
if there is a human user typing the commands, one after the
other. The contrary, a non-interactive shell, is similar to
the execution of commands in the background: there is no attached
terminal.
If you plan using an interactive shell, you need to create a
pseud-terminal on the remote side. A remote terminal is usually referred
to as a "pty", for "pseudo-teletype". The remote processes won't see the
difference with a real text-oriented terminal.
If needed, you request the pty with the function ssh_channel_request_pty().
Then you define its dimensions (number of rows and columns)
with ssh_channel_change_pty_size().
Be your session interactive or not, the next step is to request a
shell with ssh_channel_request_shell().
@code
int interactive_shell_session(ssh_channel channel)
{
int rc;
rc = ssh_channel_request_pty(channel);
if (rc != SSH_OK) return rc;
rc = ssh_channel_change_pty_size(channel, 80, 24);
if (rc != SSH_OK) return rc;
rc = ssh_channel_request_shell(channel);
if (rc != SSH_OK) return rc;
...
return rc;
}
@endcode
@subsection read_data Displaying the data sent by the remote computer
In your program, you will usually need to receive all the data "displayed"
into the remote pty. You will usually analyse, log, or display this data.
ssh_channel_read() and ssh_channel_read_nonblocking() are the simplest
way to read data from a channel. If you only need to read from a single
channel, they should be enough.
The example below shows how to wait for remote data using ssh_channel_read():
@code
int interactive_shell_session(ssh_channel channel)
{
int rc;
char buffer[256];
int nbytes;
rc = ssh_channel_request_pty(channel);
if (rc != SSH_OK) return rc;
rc = ssh_channel_change_pty_size(channel, 80, 24);
if (rc != SSH_OK) return rc;
rc = ssh_channel_request_shell(channel);
if (rc != SSH_OK) return rc;
while (ssh_channel_is_open(channel) &&
!ssh_channel_is_eof(channel))
{
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
if (nbytes < 0)
return SSH_ERROR;
if (nbytes > 0)
write(1, buffer, nbytes);
}
return rc;
}
@endcode
Unlike ssh_channel_read(), ssh_channel_read_nonblocking() never waits for
remote data to be ready. It returns immediately.
If you plan to use ssh_channel_read_nonblocking() repeatedly in a loop,
you should use a "passive wait" function like usleep(3) in the same
loop. Otherwise, your program will consume all the CPU time, and your
computer might become unresponsive.
@subsection write_data Sending user input to the remote computer
User's input is sent to the remote site with ssh_channel_write().
The following example shows how to combine a nonblocking read from a SSH
channel with a nonblocking read from the keyboard. The local input is then
sent to the remote computer:
@code
/* Under Linux, this function determines whether a key has been pressed.
Under Windows, it is a standard function, so you need not redefine it.
*/
int kbhit()
{
struct timeval tv = { 0L, 0L };
fd_set fds;
FD_ZERO(&fds);
FD_SET(0, &fds);
return select(1, &fds, NULL, NULL, &tv);
}
/* A very simple terminal emulator:
- print data received from the remote computer
- send keyboard input to the remote computer
*/
int interactive_shell_session(ssh_channel channel)
{
/* Session and terminal initialization skipped */
...
char buffer[256];
int nbytes, nwritten;
while (ssh_channel_is_open(channel) &&
!ssh_channel_is_eof(channel))
{
nbytes = ssh_channel_read_nonblocking(channel, buffer, sizeof(buffer), 0);
if (nbytes < 0) return SSH_ERROR;
if (nbytes > 0)
{
nwritten = write(1, buffer, nbytes);
if (nwritten != nbytes) return SSH_ERROR;
if (!kbhit())
{
usleep(50000L); // 0.05 second
continue;
}
nbytes = read(0, buffer, sizeof(buffer));
if (nbytes < 0) return SSH_ERROR;
if (nbytes > 0)
{
nwritten = ssh_channel_write(channel, buffer, nbytes);
if (nwritten != nbytes) return SSH_ERROR;
}
}
return rc;
}
@endcode
Of course, this is a poor terminal emulator, since the echo from the keys
pressed should not be done locally, but should be done by the remote side.
Also, user's input should not be sent once "Enter" key is pressed, but
immediately after each key is pressed. This can be accomplished
by setting the local terminal to "raw" mode with the cfmakeraw(3) function.
cfmakeraw() is a standard function under Linux, on other systems you can
recode it with:
@code
static void cfmakeraw(struct termios *termios_p)
{
termios_p->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
termios_p->c_oflag &= ~OPOST;
termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
termios_p->c_cflag &= ~(CSIZE|PARENB);
termios_p->c_cflag |= CS8;
}
@endcode
If you are not using a local terminal, but some kind of graphical
environment, the solution to this kind of "echo" problems will be different.
@subsection select_loop A more elaborate way to get the remote data
*** Warning: ssh_select() and ssh_channel_select() are not relevant anymore,
since libssh is about to provide an easier system for asynchronous
communications. This subsection should be removed then. ***
ssh_channel_read() and ssh_channel_read_nonblocking() functions are simple,
but they are not adapted when you expect data from more than one SSH channel,
or from other file descriptors. Last example showed how getting data from
the standard input (the keyboard) at the same time as data from the SSH
channel was complicated. The functions ssh_select() and ssh_channel_select()
provide a more elegant way to wait for data coming from many sources.
The functions ssh_select() and ssh_channel_select() remind of the standard
UNIX select(2) function. The idea is to wait for "something" to happen:
incoming data to be read, outcoming data to block, or an exception to
occur. Both these functions do a "passive wait", i.e. you can safely use
them repeatedly in a loop, it will not consume exaggerate processor time
and make your computer unresponsive. It is quite common to use these
functions in your application's main loop.
The difference between ssh_select() and ssh_channel_select() is that
ssh_channel_select() is simpler, but allows you only to watch SSH channels.
ssh_select() is more complete and enables watching regular file descriptors
as well, in the same function call.
Below is an example of a function that waits both for remote SSH data to come,
as well as standard input from the keyboard:
@code
int interactive_shell_session(ssh_session session, ssh_channel channel)
{
/* Session and terminal initialization skipped */
...
char buffer[256];
int nbytes, nwritten;
while (ssh_channel_is_open(channel) &&
!ssh_channel_is_eof(channel))
{
struct timeval timeout;
ssh_channel in_channels[2], out_channels[2];
fd_set fds;
int maxfd;
timeout.tv_sec = 30;
timeout.tv_usec = 0;
in_channels[0] = channel;
in_channels[1] = NULL;
FD_ZERO(&fds);
FD_SET(0, &fds);
FD_SET(ssh_get_fd(session), &fds);
maxfd = ssh_get_fd(session) + 1;
ssh_select(in_channels, out_channels, maxfd, &fds, &timeout);
if (out_channels[0] != NULL)
{
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
if (nbytes < 0) return SSH_ERROR;
if (nbytes > 0)
{
nwritten = write(1, buffer, nbytes);
if (nwritten != nbytes) return SSH_ERROR;
}
}
if (FD_ISSET(0, &fds))
{
nbytes = read(0, buffer, sizeof(buffer));
if (nbytes < 0) return SSH_ERROR;
if (nbytes > 0)
{
nwritten = ssh_channel_write(channel, buffer, nbytes);
if (nbytes != nwritten) return SSH_ERROR;
}
}
}
return rc;
}
@endcode
@subsection x11 Using graphical applications on the remote side
If your remote application is graphical, you can forward the X11 protocol to
your local computer.
To do that, you first declare that you accept X11 connections with
ssh_channel_accept_x11(). Then you create the forwarding tunnel for
the X11 protocol with ssh_channel_request_x11().
The following code performs channel initialization and shell session
opening, and handles a parallel X11 connection:
@code
int interactive_shell_session(ssh_channel channel)
{
int rc;
ssh_channel x11channel;
rc = ssh_channel_request_pty(channel);
if (rc != SSH_OK) return rc;
rc = ssh_channel_change_pty_size(channel, 80, 24);
if (rc != SSH_OK) return rc;
rc = ssh_channel_request_x11(channel, 0, NULL, NULL, 0);
if (rc != SSH_OK) return rc;
rc = ssh_channel_request_shell(channel);
if (rc != SSH_OK) return rc;
/* Read the data sent by the remote computer here */
...
}
@endcode
Don't forget to set the $DISPLAY environment variable on the remote
side, or the remote applications won't try using the X11 tunnel:
@code
$ export DISPLAY=:0
$ xclock &
@endcode
*/

View File

@@ -1,184 +0,0 @@
body {
background-color:#ddf;
/*background-image:url(../back6.jpg);*/
margin:10px 10px 10px 10px;
}
h1 {
font-family:verdana, sans-serif;
font-size:80%;
color:black;
background-color:transparent;
text-align:left;
}
h2 {
font-family:verdana, sans-serif;
font-size:100%;
color:black;
background-color:transparent;
text-align:left;
}
h3 {
font-family:verdana, sans-serif;
font-size:80%;
color:black;
background-color:transparent;
text-align:left;
}
p {
font-family:verdana, sans-serif;
font-size:80%;
color:black;
background-color:transparent;
text-align:left;
margin-left:0px;
margin-right:0px;
}
li {
font-family:verdana, sans-serif;
font-size:80%;
color:black;
background-color:transparent;
text-align:left;
margin-left:0px;
margin-right:0px;
}
a:link {
font-family:verdana, sans-serif;
font-size:100%;
color:black;
background-color:transparent;
text-decoration:underline;
}
a:visited {
font-family:verdana, sans-serif;
font-size:100%;
color:black;
background-color:transparent;
text-decoration:underline;
}
a:hover {
font-family:verdana, sans-serif;
font-size:100%;
color:black;
background-color:transparent;
text-decoration:underline;
}
table {
border-color:transparent;
border-style:solid;
border-width:1px;
}
td {
font-family:verdana, sans-serif;
font-size:80%;
color:black;
text-align:left;
background-color:transparent;
border-color:transparent;
border-style:solid;
border-width:1px;
}
.tout {
margin: 5px;
padding: 0px;
border: 2px solid #aac;
background: #eef;
}
.prot {
border-style:solid;
border-width:2px;
border-color:#88F;
padding: 4px;
background-color:#cce;
margin: 5px 5px 5px 5px;
}
.ex {
border-style:solid;
border-width:2px;
border-color:#aaF;
padding: 4px;
background-color:#dde;
margin: 5px 5px 5px 5px;
}
.desc {
border-style:solid;
border-width:3px;
border-color:#66F;
padding: 4px;
background-color:#aac;
margin: 15px 5px 20px 5px;
}
#titre {
margin: 5px;
padding: 0px;
border: 5px solid #aac;
background: #eef;
}
#gauche {
float:left;
margin: 5px;
padding: 4px;
border: 5px solid #aac;
background: #bbf;
width: 130px;
}
#droite {
position: relative;
top:5px;
left:165px;
margin: 5px 170px 5px 5px;
padding: 10px;
border: 5px solid #aac;
background: #bbf;
}
/* boutons */
a.bouton:link{
width:128px;
height:34px;
text-decoration:none;
color:#aaa;
text-align:center;
font-weight:bold;
/*background-color:#444;*/
background-image:url(noclicked.png);
}
a.bouton:visited{
width:128px;
height:34px;
text-decoration:none;
color:#aaa;
text-align:center;
font-weight:bold;
/*background-color:#444;*/
background-image:url(noclicked.png);
}
a.bouton:hover{
width:128px;
height:34px;
text-decoration:none;
color:white;
text-align:center;
font-weight:bold;
/*background-color:#888;*/
background-image:url(clicked.png);
}
.bouton{
text-align:center;
display:block;
}

14
doc/tbd.dox Normal file
View File

@@ -0,0 +1,14 @@
/**
@page libssh_tutor_todo To be done
*** To be written ***
@section sshd Writing a libssh-based server
*** To be written ***
@section cpp The libssh C++ wrapper
*** To be written ***
*/

66
doc/threading.dox Normal file
View File

@@ -0,0 +1,66 @@
/**
@page libssh_tutor_threads Chapter 8: Threads with libssh
@section threads_with_libssh How to use libssh with threads
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 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 *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
To initialize threading, you must first select the threading model you want to
use, using ssh_threads_set_callbacks(), then call ssh_init().
@code
#include <libssh/callbacks.h>
...
ssh_threads_set_callbacks(ssh_threads_get_noop());
ssh_init();
@endcode
ssh_threads_noop is the threading structure that does nothing. It's the
threading callbacks being used by default when you're not using threading.
@subsection threads_pthread Using libpthread with libssh
If your application is using libpthread, you may simply use the libpthread
threading backend:
@code
#include <libssh/callbacks.h>
...
ssh_threads_set_callbacks(ssh_threads_get_pthread());
ssh_init();
@endcode
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
@endcode
@subsection threads_other Using another threading library
You must find your way in the ssh_threads_callbacks_struct structure. You must
implement the following methods :
- mutex_lock
- mutex_unlock
- mutex_init
- 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 !
*/

66
examples/CMakeLists.txt Normal file
View File

@@ -0,0 +1,66 @@
project(libssh-examples C CXX)
set(examples_SRCS
authentication.c
knownhosts.c
connect_ssh.c
)
include_directories(
${LIBSSH_PUBLIC_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}
)
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(sshnetcat sshnetcat.c ${examples_SRCS})
target_link_libraries(sshnetcat ${LIBSSH_SHARED_LIBRARY})
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)
if (HAVE_LIBUTIL)
add_executable(ssh_server_fork ssh_server_fork.c)
target_link_libraries(ssh_server_fork ${LIBSSH_SHARED_LIBRARY} ${ARGP_LIBRARIES} util)
endif (HAVE_LIBUTIL)
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 (UNIX AND NOT WIN32)
add_executable(exec exec.c ${examples_SRCS})
target_link_libraries(exec ${LIBSSH_SHARED_LIBRARY})
add_executable(senddata senddata.c ${examples_SRCS})
target_link_libraries(senddata ${LIBSSH_SHARED_LIBRARY})
add_executable(libsshpp libsshpp.cpp)
target_link_libraries(libsshpp ${LIBSSH_SHARED_LIBRARY})
add_executable(libsshpp_noexcept libsshpp_noexcept.cpp)
target_link_libraries(libsshpp_noexcept ${LIBSSH_SHARED_LIBRARY})

176
examples/authentication.c Normal file
View File

@@ -0,0 +1,176 @@
/*
* authentication.c
* This file contains an example of how to do an authentication to a
* SSH server using libssh
*/
/*
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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libssh/libssh.h>
#include "examples_common.h"
int authenticate_kbdint(ssh_session session, const char *password) {
int err;
err = ssh_userauth_kbdint(session, NULL, NULL);
while (err == SSH_AUTH_INFO) {
const char *instruction;
const char *name;
char buffer[128];
int i, n;
name = ssh_userauth_kbdint_getname(session);
instruction = ssh_userauth_kbdint_getinstruction(session);
n = ssh_userauth_kbdint_getnprompts(session);
if (name && strlen(name) > 0) {
printf("%s\n", name);
}
if (instruction && strlen(instruction) > 0) {
printf("%s\n", instruction);
}
for (i = 0; i < n; i++) {
const char *answer;
const char *prompt;
char echo;
prompt = ssh_userauth_kbdint_getprompt(session, i, &echo);
if (prompt == NULL) {
break;
}
if (echo) {
char *p;
printf("%s", prompt);
if (fgets(buffer, sizeof(buffer), stdin) == NULL) {
return SSH_AUTH_ERROR;
}
buffer[sizeof(buffer) - 1] = '\0';
if ((p = strchr(buffer, '\n'))) {
*p = '\0';
}
if (ssh_userauth_kbdint_setanswer(session, i, buffer) < 0) {
return SSH_AUTH_ERROR;
}
memset(buffer, 0, strlen(buffer));
} else {
if (password && strstr(prompt, "Password:")) {
answer = password;
} else {
buffer[0] = '\0';
if (ssh_getpass(prompt, buffer, sizeof(buffer), 0, 0) < 0) {
return SSH_AUTH_ERROR;
}
answer = buffer;
}
err = ssh_userauth_kbdint_setanswer(session, i, answer);
memset(buffer, 0, sizeof(buffer));
if (err < 0) {
return SSH_AUTH_ERROR;
}
}
}
err=ssh_userauth_kbdint(session,NULL,NULL);
}
return err;
}
static void error(ssh_session session){
fprintf(stderr,"Authentication failed: %s\n",ssh_get_error(session));
}
int authenticate_console(ssh_session session){
int rc;
int method;
char password[128] = {0};
char *banner;
// Try to authenticate
rc = ssh_userauth_none(session, NULL);
if (rc == SSH_AUTH_ERROR) {
error(session);
return rc;
}
method = ssh_userauth_list(session, NULL);
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_publickey_auto(session, NULL, NULL);
if (rc == SSH_AUTH_ERROR) {
error(session);
return rc;
} else if (rc == SSH_AUTH_SUCCESS) {
break;
}
}
// Try to authenticate with keyboard interactive";
if (method & SSH_AUTH_METHOD_INTERACTIVE) {
rc = authenticate_kbdint(session, NULL);
if (rc == SSH_AUTH_ERROR) {
error(session);
return rc;
} else if (rc == SSH_AUTH_SUCCESS) {
break;
}
}
if (ssh_getpass("Password: ", password, sizeof(password), 0, 0) < 0) {
return SSH_AUTH_ERROR;
}
// Try to authenticate with password
if (method & SSH_AUTH_METHOD_PASSWORD) {
rc = ssh_userauth_password(session, NULL, password);
if (rc == SSH_AUTH_ERROR) {
error(session);
return rc;
} else if (rc == SSH_AUTH_SUCCESS) {
break;
}
}
memset(password, 0, sizeof(password));
}
banner = ssh_get_issue_banner(session);
if (banner) {
printf("%s\n",banner);
ssh_string_free_char(banner);
}
return rc;
}

67
examples/connect_ssh.c Normal file
View File

@@ -0,0 +1,67 @@
/*
* connect_ssh.c
* This file contains an example of how to connect to a
* SSH server using libssh
*/
/*
Copyright 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 <libssh/libssh.h>
#include "examples_common.h"
#include <stdio.h>
ssh_session connect_ssh(const char *host, const char *user,int verbosity){
ssh_session session;
int auth=0;
session=ssh_new();
if (session == NULL) {
return NULL;
}
if(user != NULL){
if (ssh_options_set(session, SSH_OPTIONS_USER, user) < 0) {
ssh_free(session);
return NULL;
}
}
if (ssh_options_set(session, SSH_OPTIONS_HOST, host) < 0) {
ssh_free(session);
return NULL;
}
ssh_options_set(session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity);
if(ssh_connect(session)){
fprintf(stderr,"Connection failed : %s\n",ssh_get_error(session));
ssh_disconnect(session);
ssh_free(session);
return NULL;
}
if(verify_knownhost(session)<0){
ssh_disconnect(session);
ssh_free(session);
return NULL;
}
auth=authenticate_console(session);
if(auth==SSH_AUTH_SUCCESS){
return session;
} else if(auth==SSH_AUTH_DENIED){
fprintf(stderr,"Authentication failed\n");
} else {
fprintf(stderr,"Error while authenticating : %s\n",ssh_get_error(session));
}
ssh_disconnect(session);
ssh_free(session);
return NULL;
}

View File

@@ -0,0 +1,22 @@
/*
Copyright 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.
*/
#ifndef EXAMPLES_COMMON_H_
#define EXAMPLES_COMMON_H_
#include <libssh/libssh.h>
int authenticate_console(ssh_session session);
int authenticate_kbdint(ssh_session session, const char *password);
int verify_knownhost(ssh_session session);
ssh_session connect_ssh(const char *hostname, const char *user, int verbosity);
#endif /* EXAMPLES_COMMON_H_ */

66
examples/exec.c Normal file
View File

@@ -0,0 +1,66 @@
/* simple exec example */
#include <stdio.h>
#include <libssh/libssh.h>
#include "examples_common.h"
int main(void) {
ssh_session session;
ssh_channel channel;
char buffer[256];
int nbytes;
int rc;
session = connect_ssh("localhost", NULL, 0);
if (session == NULL) {
ssh_finalize();
return 1;
}
channel = ssh_channel_new(session);;
if (channel == NULL) {
ssh_disconnect(session);
ssh_free(session);
ssh_finalize();
return 1;
}
rc = ssh_channel_open_session(channel);
if (rc < 0) {
goto failed;
}
rc = ssh_channel_request_exec(channel, "lsof");
if (rc < 0) {
goto failed;
}
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
while (nbytes > 0) {
if (fwrite(buffer, 1, nbytes, stdout) != (unsigned int) nbytes) {
goto failed;
}
nbytes = ssh_channel_read(channel, buffer, sizeof(buffer), 0);
}
if (nbytes < 0) {
goto failed;
}
ssh_channel_send_eof(channel);
ssh_channel_close(channel);
ssh_channel_free(channel);
ssh_disconnect(session);
ssh_free(session);
ssh_finalize();
return 0;
failed:
ssh_channel_close(channel);
ssh_channel_free(channel);
ssh_disconnect(session);
ssh_free(session);
ssh_finalize();
return 1;
}

110
examples/knownhosts.c Normal file
View File

@@ -0,0 +1,110 @@
/*
* knownhosts.c
* This file contains an example of how verify the identity of a
* SSH server using libssh
*/
/*
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 <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libssh/libssh.h>
#include "examples_common.h"
#ifdef _WIN32
#define strncasecmp _strnicmp
#endif
int verify_knownhost(ssh_session session){
char *hexa;
int state;
char buf[10];
unsigned char *hash = NULL;
size_t hlen;
ssh_key srv_pubkey;
int rc;
state=ssh_is_server_known(session);
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 */
case SSH_SERVER_KNOWN_CHANGED:
fprintf(stderr,"Host key for server changed : server's one is now :\n");
ssh_print_hexa("Public key hash",hash, hlen);
ssh_clean_pubkey_hash(&hash);
fprintf(stderr,"For security reason, connection will be stopped\n");
return -1;
case SSH_SERVER_FOUND_OTHER:
fprintf(stderr,"The host key for this server was not found but an other type of key exists.\n");
fprintf(stderr,"An attacker might change the default server key to confuse your client"
"into thinking the key does not exist\n"
"We advise you to rerun the client with -d or -r for more safety.\n");
return -1;
case SSH_SERVER_FILE_NOT_FOUND:
fprintf(stderr,"Could not find known host file. If you accept the host key here,\n");
fprintf(stderr,"the file will be automatically created.\n");
/* fallback to SSH_SERVER_NOT_KNOWN behavior */
case SSH_SERVER_NOT_KNOWN:
hexa = ssh_get_hexa(hash, hlen);
fprintf(stderr,"The server is unknown. Do you trust the host key ?\n");
fprintf(stderr, "Public key hash: %s\n", hexa);
ssh_string_free_char(hexa);
if (fgets(buf, sizeof(buf), stdin) == NULL) {
ssh_clean_pubkey_hash(&hash);
return -1;
}
if(strncasecmp(buf,"yes",3)!=0){
ssh_clean_pubkey_hash(&hash);
return -1;
}
fprintf(stderr,"This new key will be written on disk for further usage. do you agree ?\n");
if (fgets(buf, sizeof(buf), stdin) == NULL) {
ssh_clean_pubkey_hash(&hash);
return -1;
}
if(strncasecmp(buf,"yes",3)==0){
if (ssh_write_knownhost(session) < 0) {
ssh_clean_pubkey_hash(&hash);
fprintf(stderr, "error %s\n", strerror(errno));
return -1;
}
}
break;
case SSH_SERVER_ERROR:
ssh_clean_pubkey_hash(&hash);
fprintf(stderr,"%s",ssh_get_error(session));
return -1;
}
ssh_clean_pubkey_hash(&hash);
return 0;
}

328
examples/libssh_scp.c Normal file
View File

@@ -0,0 +1,328 @@
/* libssh_scp.c
* Sample implementation of a SCP client
*/
/*
Copyright 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <libssh/libssh.h>
#include "examples_common.h"
static char **sources;
static int nsources;
static char *destination;
static int verbosity=0;
struct location {
int is_ssh;
char *user;
char *host;
char *path;
ssh_session session;
ssh_scp scp;
FILE *file;
};
enum {
READ,
WRITE
};
static void usage(const char *argv0){
fprintf(stderr,"Usage : %s [options] [[user@]host1:]file1 ... \n"
" [[user@]host2:]destination\n"
"sample scp client - libssh-%s\n",
// "Options :\n",
// " -r : use RSA to verify host public key\n",
argv0,
ssh_version(0));
exit(0);
}
static int opts(int argc, char **argv){
int i;
while((i=getopt(argc,argv,"v"))!=-1){
switch(i){
case 'v':
verbosity++;
break;
default:
fprintf(stderr,"unknown option %c\n",optopt);
usage(argv[0]);
return -1;
}
}
nsources=argc-optind-1;
if(nsources < 1){
usage(argv[0]);
return -1;
}
sources=malloc((nsources + 1) * sizeof(char *));
if(sources == NULL)
return -1;
for(i=0;i<nsources;++i){
sources[i] = argv[optind];
optind++;
}
sources[i]=NULL;
destination=argv[optind];
return 0;
}
static struct location *parse_location(char *loc){
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){
location->is_ssh=1;
location->path=strdup(ptr+1);
*ptr='\0';
ptr=strchr(loc,'@');
if(ptr != NULL){
location->host=strdup(ptr+1);
*ptr='\0';
location->user=strdup(loc);
} else {
location->host=strdup(loc);
}
} else {
location->is_ssh=0;
location->path=strdup(loc);
}
return location;
}
static int open_location(struct location *loc, int flag){
if(loc->is_ssh && flag==WRITE){
loc->session=connect_ssh(loc->host,loc->user,verbosity);
if(!loc->session){
fprintf(stderr,"Couldn't connect to %s\n",loc->host);
return -1;
}
loc->scp=ssh_scp_new(loc->session,SSH_SCP_WRITE,loc->path);
if(!loc->scp){
fprintf(stderr,"error : %s\n",ssh_get_error(loc->session));
return -1;
}
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;
} else if(loc->is_ssh && flag==READ){
loc->session=connect_ssh(loc->host, loc->user,verbosity);
if(!loc->session){
fprintf(stderr,"Couldn't connect to %s\n",loc->host);
return -1;
}
loc->scp=ssh_scp_new(loc->session,SSH_SCP_READ,loc->path);
if(!loc->scp){
fprintf(stderr,"error : %s\n",ssh_get_error(loc->session));
return -1;
}
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;
} else {
loc->file=fopen(loc->path,flag==READ ? "r":"w");
if(!loc->file){
if(errno==EISDIR){
if(chdir(loc->path)){
fprintf(stderr,"Error changing directory to %s: %s\n",loc->path,strerror(errno));
return -1;
}
return 0;
}
fprintf(stderr,"Error opening %s: %s\n",loc->path,strerror(errno));
return -1;
}
return 0;
}
return -1;
}
/** @brief copies files from source location to destination
* @param src source location
* @param dest destination location
* @param recursive Copy also directories
*/
static int do_copy(struct location *src, struct location *dest, int recursive){
int size;
socket_t fd;
struct stat s;
int w,r;
char buffer[16384];
int total=0;
int mode;
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);
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);
} else {
size=0;
do {
r=ssh_scp_pull_request(src->scp);
if(r==SSH_SCP_REQUEST_NEWDIR){
ssh_scp_deny_request(src->scp,"Not in recursive mode");
continue;
}
if(r==SSH_SCP_REQUEST_NEWFILE){
size=ssh_scp_request_get_size(src->scp);
filename=strdup(ssh_scp_request_get_filename(src->scp));
mode=ssh_scp_request_get_permissions(src->scp);
//ssh_scp_accept_request(src->scp);
break;
}
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);
}
if(dest->is_ssh){
r=ssh_scp_push_file(dest->scp,src->path, size, mode);
// 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);
dest->scp = NULL;
return -1;
}
} else {
if(!dest->file){
dest->file=fopen(filename,"w");
if(!dest->file){
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;
}
}
if(src->is_ssh){
ssh_scp_accept_request(src->scp);
}
}
do {
if(src->is_ssh){
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)
break;
} else {
r=fread(buffer,1,sizeof(buffer),src->file);
if(r==0)
break;
if(r<0){
fprintf(stderr,"Error reading file: %s\n",strerror(errno));
ssh_string_free_char(filename);
return -1;
}
}
if(dest->is_ssh){
w=ssh_scp_write(dest->scp,buffer,r);
if(w == SSH_ERROR){
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;
}
int main(int argc, char **argv){
struct location *dest, *src;
int i;
int r;
if(opts(argc,argv)<0)
return EXIT_FAILURE;
dest=parse_location(destination);
if(open_location(dest,WRITE)<0)
return EXIT_FAILURE;
for(i=0;i<nsources;++i){
src=parse_location(sources[i]);
if(open_location(src,READ)<0){
return EXIT_FAILURE;
}
if(do_copy(src,dest,0) < 0){
break;
}
}
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));
ssh_scp_free(dest->scp);
dest->scp=NULL;
return -1;
}
} else {
fclose(dest->file);
dest->file=NULL;
}
ssh_disconnect(dest->session);
ssh_finalize();
return 0;
}

33
examples/libsshpp.cpp Normal file
View File

@@ -0,0 +1,33 @@
/*
Copyright 2010 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.
*/
/* This file demonstrates the use of the C++ wrapper to libssh */
#include <iostream>
#include <string>
#include <libssh/libsshpp.hpp>
int main(int argc, const char **argv){
ssh::Session session;
try {
if(argc>1)
session.setOption(SSH_OPTIONS_HOST,argv[1]);
else
session.setOption(SSH_OPTIONS_HOST,"localhost");
session.connect();
session.userauthPublickeyAuto();
session.disconnect();
} catch (ssh::SshException e){
std::cout << "Error during connection : ";
std::cout << e.getError() << std::endl;
}
return 0;
}

View File

@@ -0,0 +1,41 @@
/*
Copyright 2010 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.
*/
/* This file demonstrates the use of the C++ wrapper to libssh
* specifically, without C++ exceptions
*/
#include <iostream>
#define SSH_NO_CPP_EXCEPTIONS
#include <libssh/libsshpp.hpp>
int main(int argc, const char **argv){
ssh::Session session,s2;
int err;
if(argc>1)
err=session.setOption(SSH_OPTIONS_HOST,argv[1]);
else
err=session.setOption(SSH_OPTIONS_HOST,"localhost");
if(err==SSH_ERROR)
goto error;
err=session.connect();
if(err==SSH_ERROR)
goto error;
err=session.userauthPublickeyAuto();
if(err==SSH_ERROR)
goto error;
return 0;
error:
std::cout << "Error during connection : ";
std::cout << session.getError() << std::endl;
return 1;
}

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;
}

523
examples/sample.c Normal file
View File

@@ -0,0 +1,523 @@
/* client.c */
/*
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 <stdio.h>
#include <stdlib.h>
#include <string.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 "examples_common.h"
#define MAXCMD 10
static char *host;
static char *user;
static char *cmds[MAXCMD];
static struct termios terminal;
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) {
(void) verify;
(void) userdata;
return ssh_getpass(prompt, buf, len, echo, verify);
}
struct ssh_callbacks_struct cb = {
.auth_function=auth_callback,
.userdata=NULL
};
static void add_cmd(char *cmd){
int n;
for (n = 0; (n < MAXCMD) && cmds[n] != NULL; n++);
if (n == MAXCMD) {
return;
}
cmds[n]=strdup(cmd);
}
static void usage(){
fprintf(stderr,"Usage : ssh [options] [login@]hostname\n"
"sample client - libssh-%s\n"
"Options :\n"
" -l user : log in as user\n"
" -p port : connect to port\n"
" -d : use DSS to verify host public key\n"
" -r : use RSA to verify host public key\n"
#ifdef WITH_PCAP
" -P file : create a pcap debugging file\n"
#endif
#ifndef _WIN32
" -T proxycommand : command to execute as a socket proxy\n"
#endif
,
ssh_version(0));
exit(0);
}
static int opts(int argc, char **argv){
int i;
// for(i=0;i<argc;i++)
// printf("%d : %s\n",i,argv[i]);
/* insert your own arguments here */
while((i=getopt(argc,argv,"T:P:"))!=-1){
switch(i){
case 'P':
pcap_file=optarg;
break;
#ifndef _WIN32
case 'T':
proxycommand=optarg;
break;
#endif
default:
fprintf(stderr,"unknown option %c\n",optopt);
usage();
}
}
if(optind < argc)
host=argv[optind++];
while(optind < argc)
add_cmd(argv[optind++]);
if(host==NULL)
usage();
return 0;
}
#ifndef HAVE_CFMAKERAW
static void cfmakeraw(struct termios *termios_p){
termios_p->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
termios_p->c_oflag &= ~OPOST;
termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
termios_p->c_cflag &= ~(CSIZE|PARENB);
termios_p->c_cflag |= CS8;
}
#endif
static void do_cleanup(int i) {
/* unused variable */
(void) i;
tcsetattr(0,TCSANOW,&terminal);
}
static void do_exit(int i) {
/* unused variable */
(void) i;
do_cleanup(0);
exit(0);
}
ssh_channel chan;
int signal_delayed=0;
static void sigwindowchanged(int i){
(void) i;
signal_delayed=1;
}
static void setsignal(void){
signal(SIGWINCH, sigwindowchanged);
signal_delayed=0;
}
static void sizechanged(void){
struct winsize win = { 0, 0, 0, 0 };
ioctl(1, TIOCGWINSZ, &win);
ssh_channel_change_pty_size(chan,win.ws_col, win.ws_row);
// printf("Changed pty size\n");
setsignal();
}
/* There are two flavors of select loop: the one based on
* ssh_select and the one based on channel_select.
* The ssh_select one permits you to give your own file descriptors to
* follow. It is thus a complete select loop.
* The second one only selects on channels. It is simplier to use
* but doesn't permit you to fill in your own file descriptor. It is
* more adapted if you can't use ssh_select as a main loop (because
* you already have another main loop system).
*/
#ifdef USE_CHANNEL_SELECT
/* channel_select base main loop, with a standard select(2)
*/
static void select_loop(ssh_session session,ssh_channel channel){
fd_set fds;
struct timeval timeout;
char buffer[4096];
ssh_buffer readbuf=ssh_buffer_new();
ssh_channel channels[2];
int lus;
int eof=0;
int maxfd;
int ret;
while(channel){
/* when a signal is caught, ssh_select will return
* with SSH_EINTR, which means it should be started
* again. It lets you handle the signal the faster you
* can, like in this window changed example. Of course, if
* your signal handler doesn't call libssh at all, you're
* free to handle signals directly in sighandler.
*/
do{
FD_ZERO(&fds);
if(!eof)
FD_SET(0,&fds);
timeout.tv_sec=30;
timeout.tv_usec=0;
FD_SET(ssh_get_fd(session),&fds);
maxfd=ssh_get_fd(session)+1;
ret=select(maxfd,&fds,NULL,NULL,&timeout);
if(ret==EINTR)
continue;
if(FD_ISSET(0,&fds)){
lus=read(0,buffer,sizeof(buffer));
if(lus)
ssh_channel_write(channel,buffer,lus);
else {
eof=1;
ssh_channel_send_eof(channel);
}
}
if(FD_ISSET(ssh_get_fd(session),&fds)){
ssh_set_fd_toread(session);
}
channels[0]=channel; // set the first channel we want to read from
channels[1]=NULL;
ret=ssh_channel_select(channels,NULL,NULL,NULL); // no specific timeout - just poll
if(signal_delayed)
sizechanged();
} while (ret==EINTR || ret==SSH_EINTR);
// we already looked for input from stdin. Now, we are looking for input from the channel
if(channel && ssh_channel_is_closed(channel)){
ssh_channel_free(channel);
channel=NULL;
channels[0]=NULL;
}
if(channels[0]){
while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,0)>0){
lus=channel_read_buffer(channel,readbuf,0,0);
if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n",
ssh_get_error(session));
return;
}
if(lus==0){
ssh_channel_free(channel);
channel=channels[0]=NULL;
} else
if (write(1,ssh_buffer_get_begin(readbuf),lus) < 0) {
fprintf(stderr, "Error writing to buffer\n");
return;
}
}
while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,1)>0){ /* stderr */
lus=channel_read_buffer(channel,readbuf,0,1);
if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n",
ssh_get_error(session));
return;
}
if(lus==0){
ssh_channel_free(channel);
channel=channels[0]=NULL;
} else
if (write(2,ssh_buffer_get_begin(readbuf),lus) < 0) {
fprintf(stderr, "Error writing to buffer\n");
return;
}
}
}
if(channel && ssh_channel_is_closed(channel)){
ssh_channel_free(channel);
channel=NULL;
}
}
ssh_buffer_free(readbuf);
}
#else /* CHANNEL_SELECT */
static void select_loop(ssh_session session,ssh_channel channel){
fd_set fds;
struct timeval timeout;
char buffer[4096];
/* channels will be set to the channels to poll.
* outchannels will contain the result of the poll
*/
ssh_channel channels[2], outchannels[2];
int lus;
int eof=0;
int maxfd;
unsigned int r;
int ret;
while(channel){
do{
int fd;
FD_ZERO(&fds);
if(!eof)
FD_SET(0,&fds);
timeout.tv_sec=30;
timeout.tv_usec=0;
fd = ssh_get_fd(session);
if (fd < 0) {
fprintf(stderr, "Error getting fd\n");
return;
}
FD_SET(fd, &fds);
maxfd = fd + 1;
channels[0]=channel; // set the first channel we want to read from
channels[1]=NULL;
ret=ssh_select(channels,outchannels,maxfd,&fds,&timeout);
if(signal_delayed)
sizechanged();
if(ret==EINTR)
continue;
if(FD_ISSET(0,&fds)){
lus=read(0,buffer,sizeof(buffer));
if(lus)
ssh_channel_write(channel,buffer,lus);
else {
eof=1;
ssh_channel_send_eof(channel);
}
}
if(channel && ssh_channel_is_closed(channel)){
ssh_channel_free(channel);
channel=NULL;
channels[0]=NULL;
}
if(outchannels[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_channel_free(channel);
channel=channels[0]=NULL;
} else
if (write(1,buffer,lus) < 0) {
fprintf(stderr, "Error writing to buffer\n");
return;
}
}
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_channel_free(channel);
channel=channels[0]=NULL;
} else
if (write(2,buffer,lus) < 0) {
fprintf(stderr, "Error writing to buffer\n");
return;
}
}
}
if(channel && ssh_channel_is_closed(channel)){
ssh_channel_free(channel);
channel=NULL;
}
} while (ret==EINTR || ret==SSH_EINTR);
}
}
#endif
static void shell(ssh_session session){
ssh_channel channel;
struct termios terminal_local;
int interactive=isatty(0);
channel = ssh_channel_new(session);
if(interactive){
tcgetattr(0,&terminal_local);
memcpy(&terminal,&terminal_local,sizeof(struct termios));
}
if(ssh_channel_open_session(channel)){
printf("error opening channel : %s\n",ssh_get_error(session));
return;
}
chan=channel;
if(interactive){
ssh_channel_request_pty(channel);
sizechanged();
}
if(ssh_channel_request_shell(channel)){
printf("Requesting shell : %s\n",ssh_get_error(session));
return;
}
if(interactive){
cfmakeraw(&terminal_local);
tcsetattr(0,TCSANOW,&terminal_local);
setsignal();
}
signal(SIGTERM,do_cleanup);
select_loop(session,channel);
if(interactive)
do_cleanup(0);
}
static void batch_shell(ssh_session session){
ssh_channel channel;
char buffer[1024];
int i,s=0;
for(i=0;i<MAXCMD && cmds[i];++i) {
s+=snprintf(buffer+s,sizeof(buffer)-s,"%s ",cmds[i]);
free(cmds[i]);
cmds[i] = NULL;
}
channel=ssh_channel_new(session);
ssh_channel_open_session(channel);
if(ssh_channel_request_exec(channel,buffer)){
printf("error executing \"%s\" : %s\n",buffer,ssh_get_error(session));
return;
}
select_loop(session,channel);
}
static int client(ssh_session session){
int auth=0;
char *banner;
int state;
if (user)
if (ssh_options_set(session, SSH_OPTIONS_USER, user) < 0)
return -1;
if (ssh_options_set(session, SSH_OPTIONS_HOST ,host) < 0)
return -1;
if (proxycommand != NULL){
if(ssh_options_set(session, SSH_OPTIONS_PROXYCOMMAND, proxycommand))
return -1;
}
ssh_options_parse_config(session, NULL);
if(ssh_connect(session)){
fprintf(stderr,"Connection failed : %s\n",ssh_get_error(session));
return -1;
}
state=verify_knownhost(session);
if (state != 0)
return -1;
ssh_userauth_none(session, NULL);
banner=ssh_get_issue_banner(session);
if(banner){
printf("%s\n",banner);
free(banner);
}
auth=authenticate_console(session);
if(auth != SSH_AUTH_SUCCESS){
return -1;
}
if(!cmds[0])
shell(session);
else
batch_shell(session);
return 0;
}
ssh_pcap_file pcap;
void set_pcap(ssh_session session);
void set_pcap(ssh_session session){
if(!pcap_file)
return;
pcap=ssh_pcap_file_new();
if(!pcap)
return;
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);
}
void cleanup_pcap(void);
void cleanup_pcap(){
if(pcap)
ssh_pcap_file_free(pcap);
pcap=NULL;
}
int main(int argc, char **argv){
ssh_session session;
session = ssh_new();
ssh_callbacks_init(&cb);
ssh_set_callbacks(session,&cb);
if(ssh_options_getopt(session, &argc, argv)) {
fprintf(stderr, "error parsing command line :%s\n",
ssh_get_error(session));
usage();
}
opts(argc,argv);
signal(SIGTERM, do_exit);
set_pcap(session);
client(session);
ssh_disconnect(session);
ssh_free(session);
cleanup_pcap();
ssh_finalize();
return 0;
}

268
examples/samplesftp.c Normal file
View File

@@ -0,0 +1,268 @@
/*
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 <sys/statvfs.h>
#include <stdio.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>
#include "examples_common.h"
#ifdef WITH_SFTP
static int verbosity;
static char *destination;
#define DATALEN 65536
static void do_sftp(ssh_session session){
sftp_session sftp=sftp_new(session);
sftp_dir dir;
sftp_attributes file;
sftp_statvfs_t sftpstatvfs;
struct statvfs sysstatvfs;
sftp_file fichier;
sftp_file to;
int len=1;
unsigned int i;
char data[DATALEN]={0};
char *lnk;
unsigned int count;
if(!sftp){
fprintf(stderr, "sftp error initialising channel: %s\n",
ssh_get_error(session));
return;
}
if(sftp_init(sftp)){
fprintf(stderr, "error initialising sftp: %s\n",
ssh_get_error(session));
return;
}
printf("Additional SFTP extensions provided by the server:\n");
count = sftp_extensions_get_count(sftp);
for (i = 0; i < count; i++) {
printf("\t%s, version: %s\n",
sftp_extensions_get_name(sftp, i),
sftp_extensions_get_data(sftp, i));
}
/* test symlink and readlink */
if (sftp_symlink(sftp, "/tmp/this_is_the_link",
"/tmp/sftp_symlink_test") < 0) {
fprintf(stderr, "Could not create link (%s)\n", ssh_get_error(session));
return;
}
lnk = sftp_readlink(sftp, "/tmp/sftp_symlink_test");
if (lnk == NULL) {
fprintf(stderr, "Could not read link (%s)\n", ssh_get_error(session));
return;
}
printf("readlink /tmp/sftp_symlink_test: %s\n", lnk);
sftp_unlink(sftp, "/tmp/sftp_symlink_test");
if (sftp_extension_supported(sftp, "statvfs@openssh.com", "2")) {
sftpstatvfs = sftp_statvfs(sftp, "/tmp");
if (sftpstatvfs == NULL) {
fprintf(stderr, "statvfs failed (%s)\n", ssh_get_error(session));
return;
}
printf("sftp statvfs:\n"
"\tfile system block size: %llu\n"
"\tfundamental fs block size: %llu\n"
"\tnumber of blocks (unit f_frsize): %llu\n"
"\tfree blocks in file system: %llu\n"
"\tfree blocks for non-root: %llu\n"
"\ttotal file inodes: %llu\n"
"\tfree file inodes: %llu\n"
"\tfree file inodes for to non-root: %llu\n"
"\tfile system id: %llu\n"
"\tbit mask of f_flag values: %llu\n"
"\tmaximum filename length: %llu\n",
(unsigned long long) sftpstatvfs->f_bsize,
(unsigned long long) sftpstatvfs->f_frsize,
(unsigned long long) sftpstatvfs->f_blocks,
(unsigned long long) sftpstatvfs->f_bfree,
(unsigned long long) sftpstatvfs->f_bavail,
(unsigned long long) sftpstatvfs->f_files,
(unsigned long long) sftpstatvfs->f_ffree,
(unsigned long long) sftpstatvfs->f_favail,
(unsigned long long) sftpstatvfs->f_fsid,
(unsigned long long) sftpstatvfs->f_flag,
(unsigned long long) sftpstatvfs->f_namemax);
sftp_statvfs_free(sftpstatvfs);
if (statvfs("/tmp", &sysstatvfs) < 0) {
fprintf(stderr, "statvfs failed (%s)\n", strerror(errno));
return;
}
printf("sys statvfs:\n"
"\tfile system block size: %llu\n"
"\tfundamental fs block size: %llu\n"
"\tnumber of blocks (unit f_frsize): %llu\n"
"\tfree blocks in file system: %llu\n"
"\tfree blocks for non-root: %llu\n"
"\ttotal file inodes: %llu\n"
"\tfree file inodes: %llu\n"
"\tfree file inodes for to non-root: %llu\n"
"\tfile system id: %llu\n"
"\tbit mask of f_flag values: %llu\n"
"\tmaximum filename length: %llu\n",
(unsigned long long) sysstatvfs.f_bsize,
(unsigned long long) sysstatvfs.f_frsize,
(unsigned long long) sysstatvfs.f_blocks,
(unsigned long long) sysstatvfs.f_bfree,
(unsigned long long) sysstatvfs.f_bavail,
(unsigned long long) sysstatvfs.f_files,
(unsigned long long) sysstatvfs.f_ffree,
(unsigned long long) sysstatvfs.f_favail,
(unsigned long long) sysstatvfs.f_fsid,
(unsigned long long) sysstatvfs.f_flag,
(unsigned long long) sysstatvfs.f_namemax);
}
/* the connection is made */
/* opening a directory */
dir=sftp_opendir(sftp,"./");
if(!dir) {
fprintf(stderr, "Directory not opened(%s)\n", ssh_get_error(session));
return ;
}
/* reading the whole directory, file by file */
while((file=sftp_readdir(sftp,dir))){
fprintf(stderr, "%30s(%.8o) : %s(%.5d) %s(%.5d) : %.10llu bytes\n",
file->name,
file->permissions,
file->owner,
file->uid,
file->group,
file->gid,
(long long unsigned int) file->size);
sftp_attributes_free(file);
}
/* when file=NULL, an error has occured OR the directory listing is end of file */
if(!sftp_dir_eof(dir)){
fprintf(stderr, "Error: %s\n", ssh_get_error(session));
return;
}
if(sftp_closedir(dir)){
fprintf(stderr, "Error: %s\n", ssh_get_error(session));
return;
}
/* this will open a file and copy it into your /home directory */
/* the small buffer size was intended to stress the library. of course, you can use a buffer till 20kbytes without problem */
fichier=sftp_open(sftp,"/usr/bin/ssh",O_RDONLY, 0);
if(!fichier){
fprintf(stderr, "Error opening /usr/bin/ssh: %s\n",
ssh_get_error(session));
return;
}
/* open a file for writing... */
to=sftp_open(sftp,"ssh-copy",O_WRONLY | O_CREAT, 0700);
if(!to){
fprintf(stderr, "Error opening ssh-copy for writing: %s\n",
ssh_get_error(session));
return;
}
while((len=sftp_read(fichier,data,4096)) > 0){
if(sftp_write(to,data,len)!=len){
fprintf(stderr, "Error writing %d bytes: %s\n",
len, ssh_get_error(session));
return;
}
}
printf("finished\n");
if(len<0)
fprintf(stderr, "Error reading file: %s\n", ssh_get_error(session));
sftp_close(fichier);
sftp_close(to);
printf("fichiers ferm\n");
to=sftp_open(sftp,"/tmp/grosfichier",O_WRONLY|O_CREAT, 0644);
for(i=0;i<1000;++i){
len=sftp_write(to,data,DATALEN);
printf("wrote %d bytes\n",len);
if(len != DATALEN){
printf("chunk %d : %d (%s)\n",i,len,ssh_get_error(session));
}
}
sftp_close(to);
/* close the sftp session */
sftp_free(sftp);
printf("sftp session terminated\n");
}
static void usage(const char *argv0){
fprintf(stderr,"Usage : %s [-v] remotehost\n"
"sample sftp test client - libssh-%s\n"
"Options :\n"
" -v : increase log verbosity\n",
argv0,
ssh_version(0));
exit(0);
}
static int opts(int argc, char **argv){
int i;
while((i=getopt(argc,argv,"v"))!=-1){
switch(i){
case 'v':
verbosity++;
break;
default:
fprintf(stderr,"unknown option %c\n",optopt);
usage(argv[0]);
return -1;
}
}
destination=argv[optind];
if(destination == NULL){
usage(argv[0]);
return -1;
}
return 0;
}
int main(int argc, char **argv){
ssh_session session;
if(opts(argc,argv)<0)
return EXIT_FAILURE;
session=connect_ssh(destination,NULL,verbosity);
if(session == NULL)
return EXIT_FAILURE;
do_sftp(session);
ssh_disconnect(session);
ssh_free(session);
return 0;
}
#endif

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;
}

175
examples/scp_download.c Normal file
View File

@@ -0,0 +1,175 @@
/* scp_download.c
* Sample implementation of a tiny SCP downloader client
*/
/*
Copyright 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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <libssh/libssh.h>
#include "examples_common.h"
int verbosity=0;
const char *createcommand="rm -fr /tmp/libssh_tests && mkdir /tmp/libssh_tests && cd /tmp/libssh_tests && date > a && date > b && mkdir c && date > d";
char *host=NULL;
static void usage(const char *argv0){
fprintf(stderr,"Usage : %s [options] host\n"
"sample tiny scp downloader client - libssh-%s\n"
"This program will create files in /tmp and try to fetch them\n",
// "Options :\n",
// " -r : use RSA to verify host public key\n",
argv0,
ssh_version(0));
exit(0);
}
static int opts(int argc, char **argv){
int i;
while((i=getopt(argc,argv,"v"))!=-1){
switch(i){
case 'v':
verbosity++;
break;
default:
fprintf(stderr,"unknown option %c\n",optopt);
usage(argv[0]);
return -1;
}
}
host = argv[optind];
if(host == NULL)
usage(argv[0]);
return 0;
}
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);
}
if(ssh_channel_open_session(channel) != SSH_OK){
fprintf(stderr,"Error creating channel: %s\n",ssh_get_error(session));
ssh_channel_free(channel);
exit(EXIT_FAILURE);
}
if(ssh_channel_request_exec(channel,createcommand) != SSH_OK){
fprintf(stderr,"Error executing command: %s\n",ssh_get_error(session));
ssh_channel_close(channel);
ssh_channel_free(channel);
exit(EXIT_FAILURE);
}
while(!ssh_channel_is_eof(channel)){
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);
return;
}
}
ssh_channel_close(channel);
ssh_channel_free(channel);
}
static int fetch_files(ssh_session session){
int size;
char buffer[16384];
int mode;
char *filename;
int r;
ssh_scp scp=ssh_scp_new(session, SSH_SCP_READ | SSH_SCP_RECURSIVE, "/tmp/libssh_tests/*");
if(ssh_scp_init(scp) != SSH_OK){
fprintf(stderr,"error initializing scp: %s\n",ssh_get_error(session));
ssh_scp_free(scp);
return -1;
}
printf("Trying to download 3 files (a,b,d) and 1 directory (c)\n");
do {
r=ssh_scp_pull_request(scp);
switch(r){
case SSH_SCP_REQUEST_NEWFILE:
size=ssh_scp_request_get_size(scp);
filename=strdup(ssh_scp_request_get_filename(scp));
mode=ssh_scp_request_get_permissions(scp);
printf("downloading file %s, size %d, perms 0%o\n",filename,size,mode);
free(filename);
ssh_scp_accept_request(scp);
r=ssh_scp_read(scp,buffer,sizeof(buffer));
if(r==SSH_ERROR){
fprintf(stderr,"Error reading scp: %s\n",ssh_get_error(session));
ssh_scp_close(scp);
ssh_scp_free(scp);
return -1;
}
printf("done\n");
break;
case SSH_ERROR:
fprintf(stderr,"Error: %s\n",ssh_get_error(session));
ssh_scp_close(scp);
ssh_scp_free(scp);
return -1;
case SSH_SCP_REQUEST_WARNING:
fprintf(stderr,"Warning: %s\n",ssh_scp_request_get_warning(scp));
break;
case SSH_SCP_REQUEST_NEWDIR:
filename=strdup(ssh_scp_request_get_filename(scp));
mode=ssh_scp_request_get_permissions(scp);
printf("downloading directory %s, perms 0%o\n",filename,mode);
free(filename);
ssh_scp_accept_request(scp);
break;
case SSH_SCP_REQUEST_ENDDIR:
printf("End of directory\n");
break;
case SSH_SCP_REQUEST_EOF:
printf("End of requests\n");
goto end;
}
} while (1);
end:
ssh_scp_close(scp);
ssh_scp_free(scp);
return 0;
}
int main(int argc, char **argv){
ssh_session session;
if(opts(argc,argv)<0)
return EXIT_FAILURE;
session=connect_ssh(host,NULL,verbosity);
if(session == NULL)
return EXIT_FAILURE;
create_files(session);
fetch_files(session);
ssh_disconnect(session);
ssh_free(session);
ssh_finalize();
return 0;
}

64
examples/senddata.c Normal file
View File

@@ -0,0 +1,64 @@
#include <stdio.h>
#include <libssh/libssh.h>
#include "examples_common.h"
#define LIMIT 0x100000000
int main(void) {
ssh_session session;
ssh_channel channel;
char buffer[1024*1024];
int rc;
uint64_t total=0;
uint64_t lastshown=4096;
session = connect_ssh("localhost", NULL, 0);
if (session == NULL) {
return 1;
}
channel = ssh_channel_new(session);;
if (channel == NULL) {
ssh_disconnect(session);
return 1;
}
rc = ssh_channel_open_session(channel);
if (rc < 0) {
ssh_channel_close(channel);
ssh_disconnect(session);
return 1;
}
rc = ssh_channel_request_exec(channel, "cat > /dev/null");
if (rc < 0) {
ssh_channel_close(channel);
ssh_disconnect(session);
return 1;
}
while ((rc = ssh_channel_write(channel, buffer, sizeof(buffer))) > 0) {
total += rc;
if(total/2 >= lastshown){
printf("written %llx\n", (long long unsigned int) total);
lastshown=total;
}
if(total > LIMIT)
break;
}
if (rc < 0) {
printf("error : %s\n",ssh_get_error(session));
ssh_channel_close(channel);
ssh_disconnect(session);
return 1;
}
ssh_channel_send_eof(channel);
ssh_channel_close(channel);
ssh_disconnect(session);
return 0;
}

697
examples/ssh_server_fork.c Normal file
View File

@@ -0,0 +1,697 @@
/* This is a sample implementation of a libssh based SSH server */
/*
Copyright 2014 Audrius Butkevicius
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.
*/
#include "config.h"
#include <libssh/callbacks.h>
#include <libssh/poll.h>
#include <libssh/server.h>
#ifdef HAVE_ARGP_H
#include <argp.h>
#endif
#include <fcntl.h>
#ifdef HAVE_LIBUTIL_H
#include <libutil.h>
#endif
#ifdef HAVE_PTY_H
#include <pty.h>
#endif
#include <signal.h>
#include <stdlib.h>
#ifdef HAVE_UTMP_H
#include <utmp.h>
#endif
#ifdef HAVE_UTIL_H
#include <util.h>
#endif
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <stdio.h>
#ifndef KEYS_FOLDER
#ifdef _WIN32
#define KEYS_FOLDER
#else
#define KEYS_FOLDER "/etc/ssh/"
#endif
#endif
#define USER "myuser"
#define PASS "mypassword"
#define BUF_SIZE 1048576
#define SESSION_END (SSH_CLOSED | SSH_CLOSED_ERROR)
#define SFTP_SERVER_PATH "/usr/lib/sftp-server"
static void set_default_keys(ssh_bind sshbind,
int rsa_already_set,
int dsa_already_set,
int ecdsa_already_set) {
if (!rsa_already_set) {
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY,
KEYS_FOLDER "ssh_host_rsa_key");
}
if (!dsa_already_set) {
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY,
KEYS_FOLDER "ssh_host_dsa_key");
}
if (!ecdsa_already_set) {
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_ECDSAKEY,
KEYS_FOLDER "ssh_host_ecdsa_key");
}
}
#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 a host key. Can be used multiple times. "
"Implies no default keys.",
.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 = "ecdsakey",
.key = 'e',
.arg = "FILE",
.flags = 0,
.doc = "Set the ecdsa key.",
.group = 0
},
{
.name = "no-default-keys",
.key = 'n',
.arg = NULL,
.flags = 0,
.doc = "Do not set default key locations.",
.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;
static int no_default_keys = 0;
static int rsa_already_set = 0, dsa_already_set = 0, ecdsa_already_set = 0;
switch (key) {
case 'n':
no_default_keys = 1;
break;
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);
dsa_already_set = 1;
break;
case 'k':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, arg);
/* We can't track the types of keys being added with this
option, so let's ensure we keep the keys we're adding
by just not setting the default keys */
no_default_keys = 1;
break;
case 'r':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, arg);
rsa_already_set = 1;
break;
case 'e':
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_ECDSAKEY, arg);
ecdsa_already_set = 1;
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);
}
if (!no_default_keys) {
set_default_keys(sshbind,
rsa_already_set,
dsa_already_set,
ecdsa_already_set);
}
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 */
/* A userdata struct for channel. */
struct channel_data_struct {
/* pid of the child process the channel will spawn. */
pid_t pid;
/* For PTY allocation */
socket_t pty_master;
socket_t pty_slave;
/* For communication with the child process. */
socket_t child_stdin;
socket_t child_stdout;
/* Only used for subsystem and exec requests. */
socket_t child_stderr;
/* Event which is used to poll the above descriptors. */
ssh_event event;
/* Terminal size struct. */
struct winsize *winsize;
};
/* A userdata struct for session. */
struct session_data_struct {
/* Pointer to the channel the session will allocate. */
ssh_channel channel;
int auth_attempts;
int authenticated;
};
static int data_function(ssh_session session, ssh_channel channel, void *data,
uint32_t len, int is_stderr, void *userdata) {
struct channel_data_struct *cdata = (struct channel_data_struct *) userdata;
(void) session;
(void) channel;
(void) is_stderr;
if (len == 0 || cdata->pid < 1 || kill(cdata->pid, 0) < 0) {
return 0;
}
return write(cdata->child_stdin, (char *) data, len);
}
static int pty_request(ssh_session session, ssh_channel channel,
const char *term, int cols, int rows, int py, int px,
void *userdata) {
struct channel_data_struct *cdata = (struct channel_data_struct *)userdata;
(void) session;
(void) channel;
(void) term;
cdata->winsize->ws_row = rows;
cdata->winsize->ws_col = cols;
cdata->winsize->ws_xpixel = px;
cdata->winsize->ws_ypixel = py;
if (openpty(&cdata->pty_master, &cdata->pty_slave, NULL, NULL,
cdata->winsize) != 0) {
fprintf(stderr, "Failed to open pty\n");
return SSH_ERROR;
}
return SSH_OK;
}
static int pty_resize(ssh_session session, ssh_channel channel, int cols,
int rows, int py, int px, void *userdata) {
struct channel_data_struct *cdata = (struct channel_data_struct *)userdata;
(void) session;
(void) channel;
cdata->winsize->ws_row = rows;
cdata->winsize->ws_col = cols;
cdata->winsize->ws_xpixel = px;
cdata->winsize->ws_ypixel = py;
if (cdata->pty_master != -1) {
return ioctl(cdata->pty_master, TIOCSWINSZ, cdata->winsize);
}
return SSH_ERROR;
}
static int exec_pty(const char *mode, const char *command,
struct channel_data_struct *cdata) {
switch(cdata->pid = fork()) {
case -1:
close(cdata->pty_master);
close(cdata->pty_slave);
fprintf(stderr, "Failed to fork\n");
return SSH_ERROR;
case 0:
close(cdata->pty_master);
if (login_tty(cdata->pty_slave) != 0) {
exit(1);
}
execl("/bin/sh", "sh", mode, command, NULL);
exit(0);
default:
close(cdata->pty_slave);
/* pty fd is bi-directional */
cdata->child_stdout = cdata->child_stdin = cdata->pty_master;
}
return SSH_OK;
}
static int exec_nopty(const char *command, struct channel_data_struct *cdata) {
int in[2], out[2], err[2];
/* Do the plumbing to be able to talk with the child process. */
if (pipe(in) != 0) {
goto stdin_failed;
}
if (pipe(out) != 0) {
goto stdout_failed;
}
if (pipe(err) != 0) {
goto stderr_failed;
}
switch(cdata->pid = fork()) {
case -1:
goto fork_failed;
case 0:
/* Finish the plumbing in the child process. */
close(in[1]);
close(out[0]);
close(err[0]);
dup2(in[0], STDIN_FILENO);
dup2(out[1], STDOUT_FILENO);
dup2(err[1], STDERR_FILENO);
close(in[0]);
close(out[1]);
close(err[1]);
/* exec the requested command. */
execl("/bin/sh", "sh", "-c", command, NULL);
exit(0);
}
close(in[0]);
close(out[1]);
close(err[1]);
cdata->child_stdin = in[1];
cdata->child_stdout = out[0];
cdata->child_stderr = err[0];
return SSH_OK;
fork_failed:
close(err[0]);
close(err[1]);
stderr_failed:
close(out[0]);
close(out[1]);
stdout_failed:
close(in[0]);
close(in[1]);
stdin_failed:
return SSH_ERROR;
}
static int exec_request(ssh_session session, ssh_channel channel,
const char *command, void *userdata) {
struct channel_data_struct *cdata = (struct channel_data_struct *) userdata;
(void) session;
(void) channel;
if(cdata->pid > 0) {
return SSH_ERROR;
}
if (cdata->pty_master != -1 && cdata->pty_slave != -1) {
return exec_pty("-c", command, cdata);
}
return exec_nopty(command, cdata);
}
static int shell_request(ssh_session session, ssh_channel channel,
void *userdata) {
struct channel_data_struct *cdata = (struct channel_data_struct *) userdata;
(void) session;
(void) channel;
if(cdata->pid > 0) {
return SSH_ERROR;
}
if (cdata->pty_master != -1 && cdata->pty_slave != -1) {
return exec_pty("-l", NULL, cdata);
}
/* Client requested a shell without a pty, let's pretend we allow that */
return SSH_OK;
}
static int subsystem_request(ssh_session session, ssh_channel channel,
const char *subsystem, void *userdata) {
/* subsystem requests behave simillarly to exec requests. */
if (strcmp(subsystem, "sftp") == 0) {
return exec_request(session, channel, SFTP_SERVER_PATH, userdata);
}
return SSH_ERROR;
}
static int auth_password(ssh_session session, const char *user,
const char *pass, void *userdata) {
struct session_data_struct *sdata = (struct session_data_struct *) userdata;
(void) session;
if (strcmp(user, USER) == 0 && strcmp(pass, PASS) == 0) {
sdata->authenticated = 1;
return SSH_AUTH_SUCCESS;
}
sdata->auth_attempts++;
return SSH_AUTH_DENIED;
}
static ssh_channel channel_open(ssh_session session, void *userdata) {
struct session_data_struct *sdata = (struct session_data_struct *) userdata;
sdata->channel = ssh_channel_new(session);
return sdata->channel;
}
static int process_stdout(socket_t fd, int revents, void *userdata) {
char buf[BUF_SIZE];
int n = -1;
ssh_channel channel = (ssh_channel) userdata;
if (channel != NULL && (revents & POLLIN) != 0) {
n = read(fd, buf, BUF_SIZE);
if (n > 0) {
ssh_channel_write(channel, buf, n);
}
}
return n;
}
static int process_stderr(socket_t fd, int revents, void *userdata) {
char buf[BUF_SIZE];
int n = -1;
ssh_channel channel = (ssh_channel) userdata;
if (channel != NULL && (revents & POLLIN) != 0) {
n = read(fd, buf, BUF_SIZE);
if (n > 0) {
ssh_channel_write_stderr(channel, buf, n);
}
}
return n;
}
static void handle_session(ssh_event event, ssh_session session) {
int n, rc;
/* Structure for storing the pty size. */
struct winsize wsize = {
.ws_row = 0,
.ws_col = 0,
.ws_xpixel = 0,
.ws_ypixel = 0
};
/* Our struct holding information about the channel. */
struct channel_data_struct cdata = {
.pid = 0,
.pty_master = -1,
.pty_slave = -1,
.child_stdin = -1,
.child_stdout = -1,
.child_stderr = -1,
.event = NULL,
.winsize = &wsize
};
/* Our struct holding information about the session. */
struct session_data_struct sdata = {
.channel = NULL,
.auth_attempts = 0,
.authenticated = 0
};
struct ssh_channel_callbacks_struct channel_cb = {
.userdata = &cdata,
.channel_pty_request_function = pty_request,
.channel_pty_window_change_function = pty_resize,
.channel_shell_request_function = shell_request,
.channel_exec_request_function = exec_request,
.channel_data_function = data_function,
.channel_subsystem_request_function = subsystem_request
};
struct ssh_server_callbacks_struct server_cb = {
.userdata = &sdata,
.auth_password_function = auth_password,
.channel_open_request_session_function = channel_open,
};
ssh_callbacks_init(&server_cb);
ssh_callbacks_init(&channel_cb);
ssh_set_server_callbacks(session, &server_cb);
if (ssh_handle_key_exchange(session) != SSH_OK) {
fprintf(stderr, "%s\n", ssh_get_error(session));
return;
}
ssh_set_auth_methods(session, SSH_AUTH_METHOD_PASSWORD);
ssh_event_add_session(event, session);
n = 0;
while (sdata.authenticated == 0 || sdata.channel == NULL) {
/* If the user has used up all attempts, or if he hasn't been able to
* authenticate in 10 seconds (n * 100ms), disconnect. */
if (sdata.auth_attempts >= 3 || n >= 100) {
return;
}
if (ssh_event_dopoll(event, 100) == SSH_ERROR) {
fprintf(stderr, "%s\n", ssh_get_error(session));
return;
}
n++;
}
ssh_set_channel_callbacks(sdata.channel, &channel_cb);
do {
/* Poll the main event which takes care of the session, the channel and
* even our child process's stdout/stderr (once it's started). */
if (ssh_event_dopoll(event, -1) == SSH_ERROR) {
ssh_channel_close(sdata.channel);
}
/* If child process's stdout/stderr has been registered with the event,
* or the child process hasn't started yet, continue. */
if (cdata.event != NULL || cdata.pid == 0) {
continue;
}
/* Executed only once, once the child process starts. */
cdata.event = event;
/* If stdout valid, add stdout to be monitored by the poll event. */
if (cdata.child_stdout != -1) {
if (ssh_event_add_fd(event, cdata.child_stdout, POLLIN, process_stdout,
sdata.channel) != SSH_OK) {
fprintf(stderr, "Failed to register stdout to poll context\n");
ssh_channel_close(sdata.channel);
}
}
/* If stderr valid, add stderr to be monitored by the poll event. */
if (cdata.child_stderr != -1){
if (ssh_event_add_fd(event, cdata.child_stderr, POLLIN, process_stderr,
sdata.channel) != SSH_OK) {
fprintf(stderr, "Failed to register stderr to poll context\n");
ssh_channel_close(sdata.channel);
}
}
} while(ssh_channel_is_open(sdata.channel) &&
(cdata.pid == 0 || waitpid(cdata.pid, &rc, WNOHANG) == 0));
close(cdata.pty_master);
close(cdata.child_stdin);
close(cdata.child_stdout);
close(cdata.child_stderr);
/* Remove the descriptors from the polling context, since they are now
* closed, they will always trigger during the poll calls. */
ssh_event_remove_fd(event, cdata.child_stdout);
ssh_event_remove_fd(event, cdata.child_stderr);
/* If the child process exited. */
if (kill(cdata.pid, 0) < 0 && WIFEXITED(rc)) {
rc = WEXITSTATUS(rc);
ssh_channel_request_send_exit_status(sdata.channel, rc);
/* If client terminated the channel or the process did not exit nicely,
* but only if something has been forked. */
} else if (cdata.pid > 0) {
kill(cdata.pid, SIGKILL);
}
ssh_channel_send_eof(sdata.channel);
ssh_channel_close(sdata.channel);
/* Wait up to 5 seconds for the client to terminate the session. */
for (n = 0; n < 50 && (ssh_get_status(session) & SESSION_END) == 0; n++) {
ssh_event_dopoll(event, 100);
}
}
/* SIGCHLD handler for cleaning up dead children. */
static void sigchld_handler(int signo) {
(void) signo;
while (waitpid(-1, NULL, WNOHANG) > 0);
}
int main(int argc, char **argv) {
ssh_bind sshbind;
ssh_session session;
ssh_event event;
struct sigaction sa;
/* Set up SIGCHLD handler. */
sa.sa_handler = sigchld_handler;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART | SA_NOCLDSTOP;
if (sigaction(SIGCHLD, &sa, NULL) != 0) {
fprintf(stderr, "Failed to register SIGCHLD handler\n");
return 1;
}
ssh_init();
sshbind = ssh_bind_new();
#ifdef HAVE_ARGP_H
argp_parse(&argp, argc, argv, 0, 0, sshbind);
#else
(void) argc;
(void) argv;
set_default_keys(sshbind, 0, 0, 0);
#endif /* HAVE_ARGP_H */
if(ssh_bind_listen(sshbind) < 0) {
fprintf(stderr, "%s\n", ssh_get_error(sshbind));
return 1;
}
while (1) {
session = ssh_new();
if (session == NULL) {
fprintf(stderr, "Failed to allocate session\n");
continue;
}
/* Blocks until there is a new incoming connection. */
if(ssh_bind_accept(sshbind, session) != SSH_ERROR) {
switch(fork()) {
case 0:
/* Remove the SIGCHLD handler inherited from parent. */
sa.sa_handler = SIG_DFL;
sigaction(SIGCHLD, &sa, NULL);
/* Remove socket binding, which allows us to restart the
* parent process, without terminating existing sessions. */
ssh_bind_free(sshbind);
event = ssh_event_new();
if (event != NULL) {
/* Blocks until the SSH session ends by either
* child process exiting, or client disconnecting. */
handle_session(event, session);
ssh_event_free(event);
} else {
fprintf(stderr, "Could not create polling context\n");
}
ssh_disconnect(session);
ssh_free(session);
exit(0);
case -1:
fprintf(stderr, "Failed to fork\n");
}
} else {
fprintf(stderr, "%s\n", ssh_get_error(sshbind));
}
/* Since the session has been passed to a child fork, do some cleaning
* up at the parent process. */
ssh_disconnect(session);
ssh_free(session);
}
ssh_bind_free(sshbind);
ssh_finalize();
return 0;
}

265
examples/sshnetcat.c Normal file
View File

@@ -0,0 +1,265 @@
/*
Copyright 2010 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 <stdio.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>
#include <sys/ioctl.h>
#include <errno.h>
#include <libssh/callbacks.h>
#include <libssh/libssh.h>
#include <libssh/sftp.h>
#include <fcntl.h>
#include "examples_common.h"
char *host;
const char *desthost="localhost";
const char *port="22";
#ifdef WITH_PCAP
#include <libssh/pcap.h>
char *pcap_file=NULL;
#endif
static void usage(){
fprintf(stderr,"Usage : sshnetcat [user@]host forwarded_host forwarded_port\n");
exit(1);
}
static int opts(int argc, char **argv){
int i;
while((i=getopt(argc,argv,"P:"))!=-1){
switch(i){
#ifdef WITH_PCAP
case 'P':
pcap_file=optarg;
break;
#endif
default:
fprintf(stderr,"unknown option %c\n",optopt);
usage();
}
}
if(optind < argc)
host=argv[optind++];
if(optind < argc)
desthost=argv[optind++];
if(optind < argc)
port=argv[optind++];
if(host==NULL)
usage();
return 0;
}
static void select_loop(ssh_session session,ssh_channel channel){
fd_set fds;
struct timeval timeout;
char buffer[4096];
/* channels will be set to the channels to poll.
* outchannels will contain the result of the poll
*/
ssh_channel channels[2], outchannels[2];
int lus;
int eof=0;
int maxfd;
int ret;
while(channel){
do{
int fd;
FD_ZERO(&fds);
if(!eof)
FD_SET(0,&fds);
timeout.tv_sec=30;
timeout.tv_usec=0;
fd = ssh_get_fd(session);
if (fd == -1) {
fprintf(stderr, "Error getting the session file descriptor: %s\n",
ssh_get_error(session));
return;
}
FD_SET(fd, &fds);
maxfd = fd + 1;
channels[0]=channel; // set the first channel we want to read from
channels[1]=NULL;
ret=ssh_select(channels,outchannels,maxfd,&fds,&timeout);
if(ret==EINTR)
continue;
if(FD_ISSET(0,&fds)){
lus=read(0,buffer,sizeof(buffer));
if(lus)
ssh_channel_write(channel,buffer,lus);
else {
eof=1;
ssh_channel_send_eof(channel);
}
}
if(channel && ssh_channel_is_closed(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)){
lus = ssh_channel_read(channel,buffer,sizeof(buffer),0);
if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n",
ssh_get_error(session));
return;
}
if(lus==0){
ssh_channel_free(channel);
channel=channels[0]=NULL;
} else {
ret = write(1, buffer, lus);
if (ret < 0) {
fprintf(stderr, "Error writing to stdin: %s",
strerror(errno));
return;
}
}
}
while(channel && ssh_channel_is_open(channel) && ssh_channel_poll(channel,1)){ /* stderr */
lus = ssh_channel_read(channel, buffer, sizeof(buffer), 1);
if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n",
ssh_get_error(session));
return;
}
if(lus==0){
ssh_channel_free(channel);
channel=channels[0]=NULL;
} else {
ret = write(2, buffer, lus);
if (ret < 0) {
fprintf(stderr, "Error writing to stderr: %s",
strerror(errno));
return;
}
}
}
}
if(channel && ssh_channel_is_closed(channel)){
ssh_channel_free(channel);
channel=NULL;
}
} while (ret==EINTR || ret==SSH_EINTR);
}
}
static void forwarding(ssh_session session){
ssh_channel channel;
int r;
channel = ssh_channel_new(session);
r = ssh_channel_open_forward(channel, desthost, atoi(port), "localhost", 22);
if(r<0) {
printf("error forwarding port : %s\n",ssh_get_error(session));
return;
}
select_loop(session,channel);
}
static int client(ssh_session session){
int auth=0;
char *banner;
int state;
if (ssh_options_set(session, SSH_OPTIONS_HOST ,host) < 0)
return -1;
ssh_options_parse_config(session, NULL);
if(ssh_connect(session)){
fprintf(stderr,"Connection failed : %s\n",ssh_get_error(session));
return -1;
}
state=verify_knownhost(session);
if (state != 0)
return -1;
ssh_userauth_none(session, NULL);
banner=ssh_get_issue_banner(session);
if(banner){
printf("%s\n",banner);
free(banner);
}
auth=authenticate_console(session);
if(auth != SSH_AUTH_SUCCESS){
return -1;
}
forwarding(session);
return 0;
}
#ifdef WITH_PCAP
ssh_pcap_file pcap;
void set_pcap(ssh_session session);
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);
}
void cleanup_pcap(void);
void cleanup_pcap(){
ssh_pcap_file_free(pcap);
pcap=NULL;
}
#endif
int main(int argc, char **argv){
ssh_session session;
session = ssh_new();
if(ssh_options_getopt(session, &argc, argv)) {
fprintf(stderr, "error parsing command line :%s\n",
ssh_get_error(session));
usage();
}
opts(argc,argv);
#ifdef WITH_PCAP
set_pcap(session);
#endif
client(session);
ssh_disconnect(session);
ssh_free(session);
#ifdef WITH_PCAP
cleanup_pcap();
#endif
ssh_finalize();
return 0;
}

View File

@@ -1,9 +1,11 @@
project(libssh-headers C)
set(libssh_HDRS
callbacks.h
libssh.h
crypto.h
ssh2.h
legacy.h
libsshpp.hpp
)
if (WITH_SFTP)

View File

@@ -1,6 +1,28 @@
/*
* 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
#include "libssh/libssh.h"
/* Messages for the authentication agent connection. */
#define SSH_AGENTC_REQUEST_RSA_IDENTITIES 1
#define SSH_AGENT_RSA_IDENTITIES_ANSWER 2
@@ -45,5 +67,52 @@
#define SSH_AGENT_OLD_SIGNATURE 0x01
struct ssh_agent_struct {
struct ssh_socket_struct *sock;
ssh_buffer ident;
unsigned int count;
ssh_channel channel;
};
#ifndef _WIN32
/* agent.c */
/**
* @brief Create a new ssh agent structure.
*
* @return An allocated ssh agent structure or NULL on error.
*/
struct ssh_agent_struct *agent_new(struct ssh_session_struct *session);
void agent_close(struct ssh_agent_struct *agent);
/**
* @brief Free an allocated ssh agent structure.
*
* @param agent The ssh agent structure to free.
*/
void agent_free(struct ssh_agent_struct *agent);
/**
* @brief Check if the ssh agent is running.
*
* @param session The ssh session to check for the agent.
*
* @return 1 if it is running, 0 if not.
*/
int agent_is_running(struct ssh_session_struct *session);
int ssh_agent_get_ident_count(struct ssh_session_struct *session);
ssh_key ssh_agent_get_next_ident(struct ssh_session_struct *session,
char **comment);
ssh_key ssh_agent_get_first_ident(struct ssh_session_struct *session,
char **comment);
ssh_string ssh_agent_sign_data(ssh_session session,
const ssh_key pubkey,
struct ssh_buffer_struct *data);
#endif
#endif /* __AGENT_H */
/* vim: set ts=2 sw=2 et cindent: */

111
include/libssh/auth.h Normal file
View File

@@ -0,0 +1,111 @@
/*
* 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 AUTH_H_
#define AUTH_H_
#include "config.h"
#include "libssh/callbacks.h"
SSH_PACKET_CALLBACK(ssh_packet_userauth_banner);
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);
/* auth1.c */
int ssh_userauth1_none(ssh_session session, const char *username);
int ssh_userauth1_offer_pubkey(ssh_session session, const char *username,
int type, ssh_string pubkey);
int ssh_userauth1_password(ssh_session session, const char *username,
const char *password);
#endif
/** @internal
* States of authentication in the client-side. They describe
* what was the last response from the server
*/
enum ssh_auth_state_e {
/** No authentication asked */
SSH_AUTH_STATE_NONE=0,
/** Last authentication response was a partial success */
SSH_AUTH_STATE_PARTIAL,
/** Last authentication response was a success */
SSH_AUTH_STATE_SUCCESS,
/** Last authentication response was failed */
SSH_AUTH_STATE_FAILED,
/** Last authentication was erroneous */
SSH_AUTH_STATE_ERROR,
/** Last state was a keyboard-interactive ask for info */
SSH_AUTH_STATE_INFO,
/** 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,
/** 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
* @brief states of the authentication service request
*/
enum ssh_auth_service_state_e {
/** initial state */
SSH_AUTH_SERVICE_NONE=0,
/** Authentication service request packet sent */
SSH_AUTH_SERVICE_SENT,
/** Service accepted */
SSH_AUTH_SERVICE_ACCEPTED,
/** Access to service denied (fatal) */
SSH_AUTH_SERVICE_DENIED,
/** Specific to SSH1 */
SSH_AUTH_SERVICE_USER_SENT
};
#endif /* AUTH_H_ */

33
include/libssh/bignum.h Normal file
View File

@@ -0,0 +1,33 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2014 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, 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 BIGNUM_H_
#define BIGNUM_H_
#include "libssh/libcrypto.h"
#include "libssh/libgcrypt.h"
bignum make_string_bn(ssh_string string);
void make_string_bn_inplace(ssh_string string, bignum bnout);
ssh_string make_bignum_string(bignum num);
void ssh_print_bignum(const char *which,bignum num);
#endif /* BIGNUM_H_ */

55
include/libssh/bind.h Normal file
View File

@@ -0,0 +1,55 @@
/*
* 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 BIND_H_
#define BIND_H_
#include "libssh/priv.h"
#include "libssh/session.h"
struct ssh_bind_struct {
struct ssh_common_struct common; /* stuff common to ssh_bind and ssh_session */
struct ssh_bind_callbacks_struct *bind_callbacks;
void *bind_callbacks_userdata;
struct ssh_poll_handle_struct *poll;
/* options */
char *wanted_methods[10];
char *banner;
char *ecdsakey;
char *dsakey;
char *rsakey;
char *ed25519key;
ssh_key ecdsa;
ssh_key dsa;
ssh_key rsa;
ssh_key ed25519;
char *bindaddr;
socket_t bindfd;
unsigned int bindport;
int blocking;
int toaccept;
};
struct ssh_poll_handle_struct *ssh_bind_get_poll(struct ssh_bind_struct
*sshbind);
#endif /* BIND_H_ */

87
include/libssh/blf.h Normal file
View File

@@ -0,0 +1,87 @@
/* $OpenBSD: blf.h,v 1.7 2007/03/14 17:59:41 grunk Exp $ */
/*
* Blowfish - a fast block cipher designed by Bruce Schneier
*
* Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Niels Provos.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _BLF_H_
#define _BLF_H_
//#include "includes.h"
#if !defined(HAVE_BCRYPT_PBKDF) && !defined(HAVE_BLH_H)
/* Schneier specifies a maximum key length of 56 bytes.
* This ensures that every key bit affects every cipher
* bit. However, the subkeys can hold up to 72 bytes.
* Warning: For normal blowfish encryption only 56 bytes
* of the key affect all cipherbits.
*/
#define BLF_N 16 /* Number of Subkeys */
#define BLF_MAXKEYLEN ((BLF_N-2)*4) /* 448 bits */
#define BLF_MAXUTILIZED ((BLF_N+2)*4) /* 576 bits */
/* Blowfish context */
typedef struct BlowfishContext {
uint32_t S[4][256]; /* S-Boxes */
uint32_t P[BLF_N + 2]; /* Subkeys */
} blf_ctx;
/* Raw access to customized Blowfish
* blf_key is just:
* Blowfish_initstate( state )
* Blowfish_expand0state( state, key, keylen )
*/
void Blowfish_encipher(blf_ctx *, uint32_t *, uint32_t *);
void Blowfish_decipher(blf_ctx *, uint32_t *, uint32_t *);
void Blowfish_initstate(blf_ctx *);
void Blowfish_expand0state(blf_ctx *, const uint8_t *, uint16_t);
void Blowfish_expandstate
(blf_ctx *, const uint8_t *, uint16_t, const uint8_t *, uint16_t);
/* Standard Blowfish */
void blf_key(blf_ctx *, const uint8_t *, uint16_t);
void blf_enc(blf_ctx *, uint32_t *, uint16_t);
void blf_dec(blf_ctx *, uint32_t *, uint16_t);
void blf_ecb_encrypt(blf_ctx *, uint8_t *, uint32_t);
void blf_ecb_decrypt(blf_ctx *, uint8_t *, uint32_t);
void blf_cbc_encrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t);
void blf_cbc_decrypt(blf_ctx *, uint8_t *, uint8_t *, uint32_t);
/* Converts uint8_t to uint32_t */
uint32_t Blowfish_stream2word(const uint8_t *, uint16_t , uint16_t *);
#endif /* !defined(HAVE_BCRYPT_PBKDF) && !defined(HAVE_BLH_H) */
#endif /* _BLF_H */

100
include/libssh/buffer.h Normal file
View File

@@ -0,0 +1,100 @@
/*
* 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 BUFFER_H_
#define BUFFER_H_
#include <stdarg.h>
#include "libssh/libssh.h"
/*
* Describes a buffer state
* [XXXXXXXXXXXXDATA PAYLOAD XXXXXXXXXXXXXXXXXXXXXXXX]
* ^ ^ ^ ^]
* \_data points\_pos points here \_used points here | /
* here Allocated
*/
struct ssh_buffer_struct {
char *data;
uint32_t used;
uint32_t allocated;
uint32_t pos;
int secure;
};
#define SSH_BUFFER_PACK_END ((uint32_t) 0x4f65feb3)
LIBSSH_API void ssh_buffer_free(ssh_buffer buffer);
LIBSSH_API void *ssh_buffer_get_begin(ssh_buffer buffer);
LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
LIBSSH_API ssh_buffer ssh_buffer_new(void);
void ssh_buffer_set_secure(ssh_buffer buffer);
int buffer_add_ssh_string(ssh_buffer buffer, ssh_string string);
int buffer_add_u8(ssh_buffer buffer, uint8_t data);
int buffer_add_u16(ssh_buffer buffer, uint16_t data);
int buffer_add_u32(ssh_buffer buffer, uint32_t data);
int buffer_add_u64(ssh_buffer buffer, uint64_t data);
int ssh_buffer_add_data(ssh_buffer buffer, const void *data, uint32_t len);
int ssh_buffer_pack_va(struct ssh_buffer_struct *buffer,
const char *format,
int argc,
va_list ap);
int _ssh_buffer_pack(struct ssh_buffer_struct *buffer,
const char *format,
int argc,
...);
#define ssh_buffer_pack(buffer, format, ...) \
_ssh_buffer_pack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
int ssh_buffer_unpack_va(struct ssh_buffer_struct *buffer,
const char *format, int argc,
va_list ap);
int _ssh_buffer_unpack(struct ssh_buffer_struct *buffer,
const char *format,
int argc,
...);
#define ssh_buffer_unpack(buffer, format, ...) \
_ssh_buffer_unpack((buffer), (format), __VA_NARG__(__VA_ARGS__), __VA_ARGS__, SSH_BUFFER_PACK_END)
int buffer_prepend_data(ssh_buffer buffer, const void *data, uint32_t len);
int buffer_add_buffer(ssh_buffer buffer, ssh_buffer source);
int ssh_buffer_reinit(ssh_buffer buffer);
/* buffer_get_rest returns a pointer to the current position into the buffer */
void *buffer_get_rest(ssh_buffer buffer);
/* buffer_get_rest_len returns the number of bytes which can be read */
uint32_t buffer_get_rest_len(ssh_buffer buffer);
/* buffer_read_*() returns the number of bytes read, except for ssh strings */
int buffer_get_u8(ssh_buffer buffer, uint8_t *data);
int buffer_get_u32(ssh_buffer buffer, uint32_t *data);
int buffer_get_u64(ssh_buffer buffer, uint64_t *data);
uint32_t buffer_get_data(ssh_buffer buffer, void *data, uint32_t requestedlen);
/* buffer_get_ssh_string() is an exception. if the String read is too large or invalid, it will answer NULL. */
ssh_string buffer_get_ssh_string(ssh_buffer buffer);
/* gets a string out of a SSH-1 mpint */
ssh_string buffer_get_mpint(ssh_buffer buffer);
/* buffer_pass_bytes acts as if len bytes have been read (used for padding) */
uint32_t buffer_pass_bytes_end(ssh_buffer buffer, uint32_t len);
uint32_t buffer_pass_bytes(ssh_buffer buffer, uint32_t len);
#endif /* BUFFER_H_ */

855
include/libssh/callbacks.h Normal file
View File

@@ -0,0 +1,855 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2009 Aris Adamantiadis <aris@0xbadc0de.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, 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
*/
/* callback.h
* This file includes the public declarations for the libssh callback mechanism
*/
#ifndef _SSH_CALLBACK_H
#define _SSH_CALLBACK_H
#include <libssh/libssh.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup libssh_callbacks The libssh callbacks
* @ingroup libssh
*
* Callback which can be replaced in libssh.
*
* @{
*/
/** @internal
* @brief callback to process simple codes
* @param code value to transmit
* @param user Userdata to pass in callback
*/
typedef void (*ssh_callback_int) (int code, void *user);
/** @internal
* @brief callback for data received messages.
* @param data data retrieved from the socket or stream
* @param len number of bytes available from this stream
* @param user user-supplied pointer sent along with all callback messages
* @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_callback_data) (const void *data, size_t len, void *user);
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 log callback. All logging messages will go through this callback
* @param session Current session handler
* @param priority Priority of the log, the smaller being the more important
* @param message the actual message
* @param userdata Userdata to be passed to the callback function.
*/
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
* @param status Percentage of connection status, going from 0.0 to 1.0
* once connection is done.
* @param userdata Userdata to be passed to the callback function.
*/
typedef void (*ssh_status_callback) (ssh_session session, float status,
void *userdata);
/**
* @brief SSH global request callback. All global request will go through this
* callback.
* @param session Current session handler
* @param message the actual message
* @param userdata Userdata to be passed to the callback function.
*/
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.
*/
struct ssh_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 functions will be called if e.g. a keyphrase is needed.
*/
ssh_auth_callback auth_function;
/**
* This function will be called each time a loggable event happens.
*/
ssh_log_callback log_function;
/**
* This function gets called during connection time to indicate the
* percentage of connection steps completed.
*/
void (*connect_status_function)(void *userdata, float status);
/**
* 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
*/
struct ssh_socket_callbacks_struct {
/**
* User-provided data. User is free to set anything he wants here
*/
void *userdata;
/**
* This function will be called each time data appears on socket. The data
* not consumed will appear on the next data event.
*/
ssh_callback_data data;
/** This function will be called each time a controlflow state changes, i.e.
* the socket is available for reading or writing.
*/
ssh_callback_int controlflow;
/** This function will be called each time an exception appears on socket. An
* exception can be a socket problem (timeout, ...) or an end-of-file.
*/
ssh_callback_int_int exception;
/** This function is called when the ssh_socket_connect was used on the socket
* on nonblocking state, and the connection successed.
*/
ssh_callback_int_int connected;
};
typedef struct ssh_socket_callbacks_struct *ssh_socket_callbacks;
#define SSH_SOCKET_FLOW_WRITEWILLBLOCK 1
#define SSH_SOCKET_FLOW_WRITEWONTBLOCK 2
#define SSH_SOCKET_EXCEPTION_EOF 1
#define SSH_SOCKET_EXCEPTION_ERROR 2
#define SSH_SOCKET_CONNECTED_OK 1
#define SSH_SOCKET_CONNECTED_ERROR 2
#define SSH_SOCKET_CONNECTED_TIMEOUT 3
/**
* @brief Initializes an ssh_callbacks_struct
* A call to this macro is mandatory when you have set a new
* ssh_callback_struct structure. Its goal is to maintain the binary
* compatibility with future versions of libssh as the structure
* evolves with time.
*/
#define ssh_callbacks_init(p) do {\
(p)->size=sizeof(*(p)); \
} while(0);
/**
* @internal
* @brief tests if a callback can be called without crash
* verifies that the struct size if big enough
* verifies that the callback pointer exists
* @param p callback pointer
* @param c callback name
* @returns nonzero if callback can be called
*/
#define ssh_callbacks_exists(p,c) (\
(p != NULL) && ( (char *)&((p)-> c) < (char *)(p) + (p)->size ) && \
((p)-> c != NULL) \
)
/** @brief Prototype for a packet callback, to be called when a new packet arrives
* @param session The current session of the packet
* @param type packet type (see ssh2.h)
* @param packet buffer containing the packet, excluding size, type and padding fields
* @param user user argument to the callback
* and are called each time a packet shows up
* @returns SSH_PACKET_USED Packet was parsed and used
* @returns SSH_PACKET_NOT_USED Packet was not used or understood, processing must continue
*/
typedef int (*ssh_packet_callback) (ssh_session session, uint8_t type, ssh_buffer packet, void *user);
/** return values for a ssh_packet_callback */
/** Packet was used and should not be parsed by another callback */
#define SSH_PACKET_USED 1
/** Packet was not used and should be passed to any other callback
* available */
#define SSH_PACKET_NOT_USED 2
/** @brief This macro declares a packet callback handler
* @code
* SSH_PACKET_CALLBACK(mycallback){
* ...
* }
* @endcode
*/
#define SSH_PACKET_CALLBACK(name) \
int name (ssh_session session, uint8_t type, ssh_buffer packet, void *user)
struct ssh_packet_callbacks_struct {
/** Index of the first packet type being handled */
uint8_t start;
/** Number of packets being handled by this callback struct */
uint8_t n_callbacks;
/** A pointer to n_callbacks packet callbacks */
ssh_packet_callback *callbacks;
/**
* User-provided data. User is free to set anything he wants here
*/
void *user;
};
typedef struct ssh_packet_callbacks_struct *ssh_packet_callbacks;
/**
* @brief Set the session callback functions.
*
* This functions sets the callback structure to use your own callback
* functions for auth, logging and status.
*
* @code
* struct ssh_callbacks_struct cb = {
* .userdata = data,
* .auth_function = my_auth_function
* };
* ssh_callbacks_init(&cb);
* ssh_set_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_callbacks(ssh_session session, ssh_callbacks cb);
/**
* @brief SSH channel data callback. Called when data is available on a channel
* @param session Current session handler
* @param channel the actual channel
* @param data the data that has been read on the channel
* @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,
void *data,
uint32_t len,
int is_stderr,
void *userdata);
/**
* @brief SSH channel eof callback. Called when a channel receives EOF
* @param session Current session handler
* @param channel the actual channel
* @param userdata Userdata to be passed to the callback function.
*/
typedef void (*ssh_channel_eof_callback) (ssh_session session,
ssh_channel channel,
void *userdata);
/**
* @brief SSH channel close callback. Called when a channel is closed by remote peer
* @param session Current session handler
* @param channel the actual channel
* @param userdata Userdata to be passed to the callback function.
*/
typedef void (*ssh_channel_close_callback) (ssh_session session,
ssh_channel channel,
void *userdata);
/**
* @brief SSH channel signal callback. Called when a channel has received a signal
* @param session Current session handler
* @param channel the actual channel
* @param signal the signal name (without the SIG prefix)
* @param userdata Userdata to be passed to the callback function.
*/
typedef void (*ssh_channel_signal_callback) (ssh_session session,
ssh_channel channel,
const char *signal,
void *userdata);
/**
* @brief SSH channel exit status callback. Called when a channel has received an exit status
* @param session Current session handler
* @param channel the actual channel
* @param userdata Userdata to be passed to the callback function.
*/
typedef void (*ssh_channel_exit_status_callback) (ssh_session session,
ssh_channel channel,
int exit_status,
void *userdata);
/**
* @brief SSH channel exit signal callback. Called when a channel has received an exit signal
* @param session Current session handler
* @param channel the actual channel
* @param signal the signal name (without the SIG prefix)
* @param core a boolean telling wether a core has been dumped or not
* @param errmsg the description of the exception
* @param lang the language of the description (format: RFC 3066)
* @param userdata Userdata to be passed to the callback function.
*/
typedef void (*ssh_channel_exit_signal_callback) (ssh_session session,
ssh_channel channel,
const char *signal,
int core,
const char *errmsg,
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;
/**
* User-provided data. User is free to set anything he wants here
*/
void *userdata;
/**
* This functions will be called when there is data available.
*/
ssh_channel_data_callback channel_data_function;
/**
* This functions will be called when the channel has received an EOF.
*/
ssh_channel_eof_callback channel_eof_function;
/**
* This functions will be called when the channel has been closed by remote
*/
ssh_channel_close_callback channel_close_function;
/**
* This functions will be called when a signal has been received
*/
ssh_channel_signal_callback channel_signal_function;
/**
* This functions will be called when an exit status has been received
*/
ssh_channel_exit_status_callback channel_exit_status_function;
/**
* 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;
/**
* @brief Set the channel callback functions.
*
* This functions sets the callback structure to use your own callback
* functions for channel data and exceptions
*
* @code
* struct ssh_channel_callbacks_struct cb = {
* .userdata = data,
* .channel_data = my_channel_data_function
* };
* ssh_callbacks_init(&cb);
* ssh_set_channel_callbacks(channel, &cb);
* @endcode
*
* @param channel The channel 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_channel_callbacks(ssh_channel channel,
ssh_channel_callbacks cb);
/** @} */
/** @group libssh_threads
* @{
*/
typedef int (*ssh_thread_callback) (void **lock);
typedef unsigned long (*ssh_thread_id_callback) (void);
struct ssh_threads_callbacks_struct {
const char *type;
ssh_thread_callback mutex_init;
ssh_thread_callback mutex_destroy;
ssh_thread_callback mutex_lock;
ssh_thread_callback mutex_unlock;
ssh_thread_id_callback thread_id;
};
/**
* @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);
/**
* @brief returns a pointer on the pthread threads callbacks, to be used with
* ssh_threads_set_callbacks.
* @warning you have to link with the library ssh_threads.
* @see ssh_threads_set_callbacks
*/
LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_pthread(void);
/**
* @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
}
#endif
#endif /*_SSH_CALLBACK_H */
/* @} */

118
include/libssh/channels.h Normal file
View File

@@ -0,0 +1,118 @@
/*
* 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 CHANNELS_H_
#define CHANNELS_H_
#include "libssh/priv.h"
/** @internal
* Describes the different possible states in a
* outgoing (client) channel request
*/
enum ssh_channel_request_state_e {
/** No request has been made */
SSH_CHANNEL_REQ_STATE_NONE = 0,
/** A request has been made and answer is pending */
SSH_CHANNEL_REQ_STATE_PENDING,
/** A request has been replied and accepted */
SSH_CHANNEL_REQ_STATE_ACCEPTED,
/** A request has been replied and refused */
SSH_CHANNEL_REQ_STATE_DENIED,
/** A request has been replied and an error happend */
SSH_CHANNEL_REQ_STATE_ERROR
};
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;
uint32_t local_window;
int local_eof;
uint32_t local_maxpacket;
uint32_t remote_channel;
uint32_t remote_window;
int remote_eof; /* end of file received */
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 exit_status;
enum ssh_channel_request_state_e request_state;
ssh_channel_callbacks callbacks;
/* counters */
ssh_counter counter;
};
SSH_PACKET_CALLBACK(ssh_packet_channel_open_conf);
SSH_PACKET_CALLBACK(ssh_packet_channel_open_fail);
SSH_PACKET_CALLBACK(ssh_packet_channel_success);
SSH_PACKET_CALLBACK(ssh_packet_channel_failure);
SSH_PACKET_CALLBACK(ssh_request_success);
SSH_PACKET_CALLBACK(ssh_request_denied);
SSH_PACKET_CALLBACK(channel_rcv_change_window);
SSH_PACKET_CALLBACK(channel_rcv_eof);
SSH_PACKET_CALLBACK(channel_rcv_close);
SSH_PACKET_CALLBACK(channel_rcv_request);
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);
void ssh_channel_do_free(ssh_channel channel);
#ifdef WITH_SSH1
SSH_PACKET_CALLBACK(ssh_packet_data1);
SSH_PACKET_CALLBACK(ssh_packet_close1);
SSH_PACKET_CALLBACK(ssh_packet_exist_status1);
/* channels1.c */
int channel_open_session1(ssh_channel channel);
int channel_request_pty_size1(ssh_channel channel, const char *terminal,
int cols, int rows);
int channel_change_pty_size1(ssh_channel channel, int cols, int rows);
int channel_request_shell1(ssh_channel channel);
int channel_request_exec1(ssh_channel channel, const char *cmd);
int channel_write1(ssh_channel channel, const void *data, int len);
ssh_channel ssh_get_channel1(ssh_session session);
#endif
#endif /* CHANNELS_H_ */

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,30 +1,37 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2003 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
*/
/*
* crypto.h is an include file for internal structures of libssh
* It hasn't to be into the final development set of files (and btw
* the filename would cause problems on most systems).
* crypto.h is an include file for internal cryptographic structures of libssh
*/
#ifndef _CRYPTO_H_
#define _CRYPTO_H_
#include "config.h"
#ifdef HAVE_LIBGCRYPT
#include <gcrypt.h>
#endif
#include "libssh/wrapper.h"
#ifdef cbc_encrypt
#undef cbc_encrypt
#endif
@@ -32,11 +39,69 @@
#undef cbc_decrypt
#endif
#ifdef GCRYPT
#include <gcrypt.h>
#ifdef HAVE_OPENSSL_ECDH_H
#include <openssl/ecdh.h>
#endif
#include "libssh/ecdh.h"
#include "libssh/kex.h"
#include "libssh/curve25519.h"
struct crypto_struct {
#define DIGEST_MAX_LEN 64
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;
#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[DIGEST_MAX_LEN];
struct ssh_cipher_struct *in_cipher, *out_cipher; /* the cipher structures/objects */
enum ssh_hmac_e in_hmac, out_hmac; /* the MAC algorithms used */
ssh_string server_pubkey;
const char *server_pubkey_type;
int do_compress_out; /* idem */
int do_compress_in; /* don't set them, set the option instead */
int delayed_compress_in; /* Use of zlib@openssh.org */
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 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 */
@@ -44,25 +109,17 @@ 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 (*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 (*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: */
#endif /* _CRYPTO_H_ */

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_ */

51
include/libssh/dh.h Normal file
View File

@@ -0,0 +1,51 @@
/*
* 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 DH_H_
#define DH_H_
#include "config.h"
#include "libssh/crypto.h"
int dh_generate_e(ssh_session session);
int dh_generate_f(ssh_session session);
int dh_generate_x(ssh_session session);
int dh_generate_y(ssh_session session);
int ssh_crypto_init(void);
void ssh_crypto_finalize(void);
ssh_string dh_get_e(ssh_session session);
ssh_string dh_get_f(ssh_session session);
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);
#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_ */

79
include/libssh/ed25519.h Normal file
View File

@@ -0,0 +1,79 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2014 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 ED25519_H_
#define ED25519_H_
#include "libssh/priv.h"
/**
* @defgroup ed25519 ed25519 API
* @internal
* @brief API for DJB's ed25519
*
* @{ */
#define ED25519_PK_LEN 32
#define ED25519_SK_LEN 64
#define ED25519_SIG_LEN 64
typedef uint8_t ed25519_pubkey[ED25519_PK_LEN];
typedef uint8_t ed25519_privkey[ED25519_SK_LEN];
typedef uint8_t ed25519_signature[ED25519_SIG_LEN];
/** @internal
* @brief generate an ed25519 key pair
* @param[out] pk generated public key
* @param[out] sk generated secret key
* @return 0 on success, -1 on error.
* */
int crypto_sign_ed25519_keypair(ed25519_pubkey pk, ed25519_privkey sk);
/** @internal
* @brief sign a message with ed25519
* @param[out] sm location to store the signed message.
* Its length should be mlen + 64.
* @param[out] smlen pointer to the size of the signed message
* @param[in] m message to be signed
* @param[in] mlen length of the message to be signed
* @param[in] sk secret key to sign the message with
* @return 0 on success.
*/
int crypto_sign_ed25519(
unsigned char *sm,unsigned long long *smlen,
const unsigned char *m,unsigned long long mlen,
const ed25519_privkey sk);
/** @internal
* @brief "open" and verify the signature of a signed message
* @param[out] m location to store the verified message.
* Its length should be equal to smlen.
* @param[out] mlen pointer to the size of the verified message
* @param[in] sm signed message to verify
* @param[in] smlen length of the signed message to verify
* @param[in] pk public key used to sign the message
* @returns 0 on success (supposedly).
*/
int crypto_sign_ed25519_open(
unsigned char *m,unsigned long long *mlen,
const unsigned char *sm,unsigned long long smlen,
const ed25519_pubkey pk);
/** @} */
#endif /* ED25519_H_ */

68
include/libssh/fe25519.h Normal file
View File

@@ -0,0 +1,68 @@
/* $OpenBSD: fe25519.h,v 1.3 2013/12/09 11:03:45 markus Exp $ */
/*
* Public Domain, Authors: Daniel J. Bernstein, Niels Duif, Tanja Lange,
* Peter Schwabe, Bo-Yin Yang.
* Copied from supercop-20130419/crypto_sign/ed25519/ref/fe25519.h
*/
#ifndef FE25519_H
#define FE25519_H
#include "libssh/priv.h"
#define fe25519 crypto_sign_ed25519_ref_fe25519
#define fe25519_freeze crypto_sign_ed25519_ref_fe25519_freeze
#define fe25519_unpack crypto_sign_ed25519_ref_fe25519_unpack
#define fe25519_pack crypto_sign_ed25519_ref_fe25519_pack
#define fe25519_iszero crypto_sign_ed25519_ref_fe25519_iszero
#define fe25519_iseq_vartime crypto_sign_ed25519_ref_fe25519_iseq_vartime
#define fe25519_cmov crypto_sign_ed25519_ref_fe25519_cmov
#define fe25519_setone crypto_sign_ed25519_ref_fe25519_setone
#define fe25519_setzero crypto_sign_ed25519_ref_fe25519_setzero
#define fe25519_neg crypto_sign_ed25519_ref_fe25519_neg
#define fe25519_getparity crypto_sign_ed25519_ref_fe25519_getparity
#define fe25519_add crypto_sign_ed25519_ref_fe25519_add
#define fe25519_sub crypto_sign_ed25519_ref_fe25519_sub
#define fe25519_mul crypto_sign_ed25519_ref_fe25519_mul
#define fe25519_square crypto_sign_ed25519_ref_fe25519_square
#define fe25519_invert crypto_sign_ed25519_ref_fe25519_invert
#define fe25519_pow2523 crypto_sign_ed25519_ref_fe25519_pow2523
typedef struct {
uint32_t v[32];
} fe25519;
void fe25519_freeze(fe25519 *r);
void fe25519_unpack(fe25519 *r, const unsigned char x[32]);
void fe25519_pack(unsigned char r[32], const fe25519 *x);
int fe25519_iszero(const fe25519 *x);
int fe25519_iseq_vartime(const fe25519 *x, const fe25519 *y);
void fe25519_cmov(fe25519 *r, const fe25519 *x, unsigned char b);
void fe25519_setone(fe25519 *r);
void fe25519_setzero(fe25519 *r);
void fe25519_neg(fe25519 *r, const fe25519 *x);
unsigned char fe25519_getparity(const fe25519 *x);
void fe25519_add(fe25519 *r, const fe25519 *x, const fe25519 *y);
void fe25519_sub(fe25519 *r, const fe25519 *x, const fe25519 *y);
void fe25519_mul(fe25519 *r, const fe25519 *x, const fe25519 *y);
void fe25519_square(fe25519 *r, const fe25519 *x);
void fe25519_invert(fe25519 *r, const fe25519 *x);
void fe25519_pow2523(fe25519 *r, const fe25519 *x);
#endif

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

@@ -0,0 +1,43 @@
/* $OpenBSD: ge25519.h,v 1.3 2013/12/09 11:03:45 markus Exp $ */
/*
* Public Domain, Authors: Daniel J. Bernstein, Niels Duif, Tanja Lange,
* Peter Schwabe, Bo-Yin Yang.
* Copied from supercop-20130419/crypto_sign/ed25519/ref/ge25519.h
*/
#ifndef GE25519_H
#define GE25519_H
#include "fe25519.h"
#include "sc25519.h"
#define ge25519 crypto_sign_ed25519_ref_ge25519
#define ge25519_base crypto_sign_ed25519_ref_ge25519_base
#define ge25519_unpackneg_vartime crypto_sign_ed25519_ref_unpackneg_vartime
#define ge25519_pack crypto_sign_ed25519_ref_pack
#define ge25519_isneutral_vartime crypto_sign_ed25519_ref_isneutral_vartime
#define ge25519_double_scalarmult_vartime crypto_sign_ed25519_ref_double_scalarmult_vartime
#define ge25519_scalarmult_base crypto_sign_ed25519_ref_scalarmult_base
typedef struct
{
fe25519 x;
fe25519 y;
fe25519 z;
fe25519 t;
} ge25519;
const ge25519 ge25519_base;
int ge25519_unpackneg_vartime(ge25519 *r, const unsigned char p[32]);
void ge25519_pack(unsigned char r[32], const ge25519 *p);
int ge25519_isneutral_vartime(const ge25519 *p);
void ge25519_double_scalarmult_vartime(ge25519 *r, const ge25519 *p1, const sc25519 *s1, const ge25519 *p2, const sc25519 *s2);
void ge25519_scalarmult_base(ge25519 *r, const sc25519 *s);
#endif

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 */

50
include/libssh/kex.h Normal file
View File

@@ -0,0 +1,50 @@
/*
* 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 KEX_H_
#define KEX_H_
#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_ */

56
include/libssh/keys.h Normal file
View File

@@ -0,0 +1,56 @@
/*
* 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 KEYS_H_
#define KEYS_H_
#include "config.h"
#include "libssh/libssh.h"
#include "libssh/wrapper.h"
struct ssh_public_key_struct {
int type;
const char *type_c; /* Don't free it ! it is static */
#ifdef HAVE_LIBGCRYPT
gcry_sexp_t dsa_pub;
gcry_sexp_t rsa_pub;
#elif HAVE_LIBCRYPTO
DSA *dsa_pub;
RSA *rsa_pub;
#endif
};
struct ssh_private_key_struct {
int type;
#ifdef HAVE_LIBGCRYPT
gcry_sexp_t dsa_priv;
gcry_sexp_t rsa_priv;
#elif defined HAVE_LIBCRYPTO
DSA *dsa_priv;
RSA *rsa_priv;
#endif
};
const char *ssh_type_to_char(int type);
int ssh_type_from_name(const char *name);
ssh_public_key publickey_from_string(ssh_session session, ssh_string pubkey_s);
#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_ */

120
include/libssh/legacy.h Normal file
View File

@@ -0,0 +1,120 @@
/*
* 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
*/
/* Since libssh.h includes legacy.h, it's important that libssh.h is included
* first. we don't define LEGACY_H now because we want it to be defined when
* included from libssh.h
* All function calls declared in this header are deprecated and meant to be
* removed in future.
*/
#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);
SSH_DEPRECATED LIBSSH_API void buffer_free(ssh_buffer buffer);
SSH_DEPRECATED LIBSSH_API void *buffer_get(ssh_buffer buffer);
SSH_DEPRECATED LIBSSH_API uint32_t buffer_get_len(ssh_buffer buffer);
SSH_DEPRECATED LIBSSH_API ssh_buffer buffer_new(void);
SSH_DEPRECATED LIBSSH_API ssh_channel channel_accept_x11(ssh_channel channel, int timeout_ms);
SSH_DEPRECATED LIBSSH_API int channel_change_pty_size(ssh_channel channel,int cols,int rows);
SSH_DEPRECATED LIBSSH_API ssh_channel channel_forward_accept(ssh_session session, int timeout_ms);
SSH_DEPRECATED LIBSSH_API int channel_close(ssh_channel channel);
SSH_DEPRECATED LIBSSH_API int channel_forward_cancel(ssh_session session, const char *address, int port);
SSH_DEPRECATED LIBSSH_API int channel_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
SSH_DEPRECATED LIBSSH_API void channel_free(ssh_channel channel);
SSH_DEPRECATED LIBSSH_API int channel_get_exit_status(ssh_channel channel);
SSH_DEPRECATED LIBSSH_API ssh_session channel_get_session(ssh_channel channel);
SSH_DEPRECATED LIBSSH_API int channel_is_closed(ssh_channel channel);
SSH_DEPRECATED LIBSSH_API int channel_is_eof(ssh_channel channel);
SSH_DEPRECATED LIBSSH_API int channel_is_open(ssh_channel channel);
SSH_DEPRECATED LIBSSH_API ssh_channel channel_new(ssh_session session);
SSH_DEPRECATED LIBSSH_API int channel_open_forward(ssh_channel channel, const char *remotehost,
int remoteport, const char *sourcehost, int localport);
SSH_DEPRECATED LIBSSH_API int channel_open_session(ssh_channel channel);
SSH_DEPRECATED LIBSSH_API int channel_poll(ssh_channel channel, int is_stderr);
SSH_DEPRECATED LIBSSH_API int channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
SSH_DEPRECATED LIBSSH_API int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
int is_stderr);
SSH_DEPRECATED LIBSSH_API int channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
int is_stderr);
SSH_DEPRECATED LIBSSH_API int channel_request_env(ssh_channel channel, const char *name, const char *value);
SSH_DEPRECATED LIBSSH_API int channel_request_exec(ssh_channel channel, const char *cmd);
SSH_DEPRECATED LIBSSH_API int channel_request_pty(ssh_channel channel);
SSH_DEPRECATED LIBSSH_API int channel_request_pty_size(ssh_channel channel, const char *term,
int cols, int rows);
SSH_DEPRECATED LIBSSH_API int channel_request_shell(ssh_channel channel);
SSH_DEPRECATED LIBSSH_API int channel_request_send_signal(ssh_channel channel, const char *signum);
SSH_DEPRECATED LIBSSH_API int channel_request_sftp(ssh_channel channel);
SSH_DEPRECATED LIBSSH_API int channel_request_subsystem(ssh_channel channel, const char *subsystem);
SSH_DEPRECATED LIBSSH_API int channel_request_x11(ssh_channel channel, int single_connection, const char *protocol,
const char *cookie, int screen_number);
SSH_DEPRECATED LIBSSH_API int channel_send_eof(ssh_channel channel);
SSH_DEPRECATED LIBSSH_API int channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct
timeval * timeout);
SSH_DEPRECATED LIBSSH_API void channel_set_blocking(ssh_channel channel, int blocking);
SSH_DEPRECATED LIBSSH_API int channel_write(ssh_channel channel, const void *data, uint32_t len);
LIBSSH_API void privatekey_free(ssh_private_key prv);
LIBSSH_API ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
int type, const char *passphrase);
LIBSSH_API void publickey_free(ssh_public_key key);
LIBSSH_API int ssh_publickey_to_file(ssh_session session, const char *file,
ssh_string pubkey, int type);
LIBSSH_API ssh_string publickey_from_file(ssh_session session, const char *filename,
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);
SSH_DEPRECATED LIBSSH_API void string_burn(ssh_string str);
SSH_DEPRECATED LIBSSH_API ssh_string string_copy(ssh_string str);
SSH_DEPRECATED LIBSSH_API void *string_data(ssh_string str);
SSH_DEPRECATED LIBSSH_API int string_fill(ssh_string str, const void *data, size_t len);
SSH_DEPRECATED LIBSSH_API void string_free(ssh_string str);
SSH_DEPRECATED LIBSSH_API ssh_string string_from_char(const char *what);
SSH_DEPRECATED LIBSSH_API size_t string_len(ssh_string str);
SSH_DEPRECATED LIBSSH_API ssh_string string_new(size_t size);
SSH_DEPRECATED LIBSSH_API char *string_to_char(ssh_string str);
#endif /* LEGACY_H_ */

104
include/libssh/libcrypto.h Normal file
View File

@@ -0,0 +1,104 @@
/*
* 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 LIBCRYPTO_H_
#define LIBCRYPTO_H_
#include "config.h"
#ifdef HAVE_LIBCRYPTO
#include <openssl/dsa.h>
#include <openssl/rsa.h>
#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 SHA512_CTX* SHA384CTX;
typedef SHA512_CTX* SHA512CTX;
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
#define SHA256_DIGEST_LEN SHA256_DIGEST_LENGTH
#define SHA384_DIGEST_LEN SHA384_DIGEST_LENGTH
#define SHA512_DIGEST_LEN SHA512_DIGEST_LENGTH
#ifdef MD5_DIGEST_LEN
#undef MD5_DIGEST_LEN
#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
#if (OPENSSL_VERSION_NUMBER <= OPENSSL_0_9_7b)
#define BROKEN_AES_CTR
#endif
typedef BIGNUM* bignum;
typedef BN_CTX* bignum_CTX;
#define bignum_new() BN_new()
#define bignum_free(num) BN_clear_free(num)
#define bignum_set_word(bn,n) BN_set_word(bn,n)
#define bignum_bin2bn(bn,datalen,data) BN_bin2bn(bn,datalen,data)
#define bignum_bn2dec(num) BN_bn2dec(num)
#define bignum_dec2bn(bn,data) BN_dec2bn(data,bn)
#define bignum_bn2hex(num) BN_bn2hex(num)
#define bignum_rand(rnd, bits, top, bottom) BN_rand(rnd,bits,top,bottom)
#define bignum_ctx_new() BN_CTX_new()
#define bignum_ctx_free(num) BN_CTX_free(num)
#define bignum_mod_exp(dest,generator,exp,modulo,ctx) BN_mod_exp(dest,generator,exp,modulo,ctx)
#define bignum_num_bytes(num) BN_num_bytes(num)
#define bignum_num_bits(num) BN_num_bits(num)
#define bignum_is_bit_set(num,bit) BN_is_bit_set(num,bit)
#define bignum_bn2bin(num,ptr) BN_bn2bin(num,ptr)
#define bignum_cmp(num1,num2) BN_cmp(num1,num2)
SHA256CTX sha256_init(void);
void sha256_update(SHA256CTX c, const void *data, unsigned long len);
void sha256_final(unsigned char *md, SHA256CTX c);
SHA384CTX sha384_init(void);
void sha384_update(SHA384CTX c, const void *data, unsigned long len);
void sha384_final(unsigned char *md, SHA384CTX c);
SHA512CTX sha512_init(void);
void sha512_update(SHA512CTX c, const void *data, unsigned long len);
void sha512_final(unsigned char *md, SHA512CTX c);
struct ssh_cipher_struct *ssh_get_ciphertab(void);
#endif /* HAVE_LIBCRYPTO */
#endif /* LIBCRYPTO_H_ */

View File

@@ -0,0 +1,78 @@
/*
* 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 LIBGCRYPT_H_
#define LIBGCRYPT_H_
#include "config.h"
#ifdef HAVE_LIBGCRYPT
#include <gcrypt.h>
typedef gcry_md_hd_t SHACTX;
typedef gcry_md_hd_t SHA256CTX;
typedef gcry_md_hd_t SHA384CTX;
typedef gcry_md_hd_t SHA512CTX;
typedef gcry_md_hd_t MD5CTX;
typedef gcry_md_hd_t HMACCTX;
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 SHA256_DIGEST_LEN SHA256_DIGEST_LENGTH
#define SHA384_DIGEST_LENGTH 48
#define SHA384_DIGEST_LEN SHA384_DIGEST_LENGTH
#define SHA512_DIGEST_LENGTH 64
#define SHA512_DIGEST_LEN SHA512_DIGEST_LENGTH
#ifndef EVP_MAX_MD_SIZE
#define EVP_MAX_MD_SIZE 64
#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)
#define bignum_bin2bn(bn,datalen,data) gcry_mpi_scan(data,GCRYMPI_FMT_USG,bn,datalen,NULL)
#define bignum_bn2dec(num) my_gcry_bn2dec(num)
#define bignum_dec2bn(num, data) my_gcry_dec2bn(data, num)
#define bignum_bn2hex(num,data) gcry_mpi_aprint(GCRYMPI_FMT_HEX,data,NULL,num)
#define bignum_hex2bn(num,datalen,data) gcry_mpi_scan(num,GCRYMPI_FMT_HEX,data,datalen,NULL)
#define bignum_rand(num,bits) gcry_mpi_randomize(num,bits,GCRY_STRONG_RANDOM),gcry_mpi_set_bit(num,bits-1),gcry_mpi_set_bit(num,0)
#define bignum_mod_exp(dest,generator,exp,modulo) gcry_mpi_powm(dest,generator,exp,modulo)
#define bignum_num_bits(num) gcry_mpi_get_nbits(num)
#define bignum_num_bytes(num) ((gcry_mpi_get_nbits(num)+7)/8)
#define bignum_is_bit_set(num,bit) gcry_mpi_test_bit(num,bit)
#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 ssh_cipher_struct *ssh_get_ciphertab(void);
#endif /* LIBGCRYPT_H_ */

View File

@@ -1,43 +1,70 @@
/*
* This file is part of the SSH Library
*
* Copyright (c) 2003-2008 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
*/
#ifndef _LIBSSH_H
#define _LIBSSH_H
#ifndef _MSC_VER
#include <unistd.h>
#include <inttypes.h>
#if defined _WIN32 || defined __CYGWIN__
#ifdef LIBSSH_STATIC
#define LIBSSH_API
#else
#ifdef LIBSSH_EXPORTS
#ifdef __GNUC__
#define LIBSSH_API __attribute__((dllexport))
#else
#define LIBSSH_API __declspec(dllexport)
#endif
#else
#ifdef __GNUC__
#define LIBSSH_API __attribute__((dllimport))
#else
#define LIBSSH_API __declspec(dllimport)
#endif
#endif
#endif
#else
#if __GNUC__ >= 4 && !defined(__OS2__)
#define LIBSSH_API __attribute__((visibility("default")))
#else
#define LIBSSH_API
#endif
#endif
#ifdef _MSC_VER
/* Visual Studio hasn't inttypes.h so it doesn't know uint32_t */
typedef int int32_t;
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
typedef unsigned long long uint64_t;
typedef int mode_t;
#else /* _MSC_VER */
//visual studio hasn't inttypes.h so it doesn't know uint32_t
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
typedef unsigned long long uint64_t;
#include <unistd.h>
#include <inttypes.h>
#endif /* _MSC_VER */
#ifdef _WIN32
#include <winsock2.h>
#else
#include <sys/select.h> /* for fd_set * */
#include <netdb.h>
#include <winsock2.h>
#else /* _WIN32 */
#include <sys/select.h> /* for fd_set * */
#include <netdb.h>
#endif /* _WIN32 */
#define SSH_STRINGIFY(s) SSH_TOSTRING(s)
@@ -50,8 +77,8 @@ typedef unsigned long long uint64_t;
/* libssh version */
#define LIBSSH_VERSION_MAJOR 0
#define LIBSSH_VERSION_MINOR 3
#define LIBSSH_VERSION_MICRO 4
#define LIBSSH_VERSION_MINOR 7
#define LIBSSH_VERSION_MICRO 0
#define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \
LIBSSH_VERSION_MINOR, \
@@ -67,83 +94,172 @@ typedef unsigned long long uint64_t;
#define PRINTF_ATTRIBUTE(a,b)
#endif /* __GNUC__ */
#ifdef __GNUC__
#define SSH_DEPRECATED __attribute__ ((deprecated))
#else
#define SSH_DEPRECATED
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct string_struct STRING;
typedef struct buffer_struct BUFFER;
typedef struct public_key_struct PUBLIC_KEY;
typedef struct private_key_struct PRIVATE_KEY;
typedef struct ssh_options_struct SSH_OPTIONS;
typedef struct channel_struct CHANNEL;
typedef struct agent_struct AGENT;
typedef struct ssh_session SSH_SESSION;
typedef struct ssh_kbdint SSH_KBDINT;
struct ssh_counter_struct {
uint64_t in_bytes;
uint64_t out_bytes;
uint64_t in_packets;
uint64_t out_packets;
};
typedef struct ssh_counter_struct *ssh_counter;
/* integer values */
typedef uint32_t u32;
typedef uint16_t u16;
typedef uint64_t u64;
typedef uint8_t u8;
typedef struct ssh_agent_struct* ssh_agent;
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_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
#define socket_t SOCKET
#else
#ifndef socket_t
typedef SOCKET socket_t;
#endif /* socket_t */
#else /* _WIN32 */
#ifndef socket_t
typedef int socket_t;
#endif
#endif /* _WIN32 */
#define SSH_INVALID_SOCKET ((socket_t) -1)
/* the offsets of methods */
#define SSH_KEX 0
#define SSH_HOSTKEYS 1
#define SSH_CRYPT_C_S 2
#define SSH_CRYPT_S_C 3
#define SSH_MAC_C_S 4
#define SSH_MAC_S_C 5
#define SSH_COMP_C_S 6
#define SSH_COMP_S_C 7
#define SSH_LANG_C_S 8
#define SSH_LANG_S_C 9
enum ssh_kex_types_e {
SSH_KEX=0,
SSH_HOSTKEYS,
SSH_CRYPT_C_S,
SSH_CRYPT_S_C,
SSH_MAC_C_S,
SSH_MAC_S_C,
SSH_COMP_C_S,
SSH_COMP_S_C,
SSH_LANG_C_S,
SSH_LANG_S_C
};
#define SSH_CRYPT 2
#define SSH_MAC 3
#define SSH_COMP 4
#define SSH_LANG 5
#define SSH_AUTH_SUCCESS 0
#define SSH_AUTH_DENIED 1
#define SSH_AUTH_PARTIAL 2
#define SSH_AUTH_INFO 3
#define SSH_AUTH_ERROR -1
enum ssh_auth_e {
SSH_AUTH_SUCCESS=0,
SSH_AUTH_DENIED,
SSH_AUTH_PARTIAL,
SSH_AUTH_INFO,
SSH_AUTH_AGAIN,
SSH_AUTH_ERROR=-1
};
#define SSH_AUTH_METHOD_PASSWORD 0x0001
#define SSH_AUTH_METHOD_PUBLICKEY 0x0002
#define SSH_AUTH_METHOD_HOSTBASED 0x0004
#define SSH_AUTH_METHOD_INTERACTIVE 0x0008
/* auth flags */
#define SSH_AUTH_METHOD_UNKNOWN 0
#define SSH_AUTH_METHOD_NONE 0x0001
#define SSH_AUTH_METHOD_PASSWORD 0x0002
#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
/* status flags */
/* messages */
enum ssh_requests_e {
SSH_REQUEST_AUTH=1,
SSH_REQUEST_CHANNEL_OPEN,
SSH_REQUEST_CHANNEL,
SSH_REQUEST_SERVICE,
SSH_REQUEST_GLOBAL
};
#define SSH_CLOSED (1<<0)
#define SSH_READ_PENDING (1<<1)
#define SSH_CLOSED_ERROR (1<<2)
enum ssh_channel_type_e {
SSH_CHANNEL_UNKNOWN=0,
SSH_CHANNEL_SESSION,
SSH_CHANNEL_DIRECT_TCPIP,
SSH_CHANNEL_FORWARDED_TCPIP,
SSH_CHANNEL_X11
};
#define SSH_SERVER_ERROR -1
#define SSH_SERVER_NOT_KNOWN 0
#define SSH_SERVER_KNOWN_OK 1
#define SSH_SERVER_KNOWN_CHANGED 2
#define SSH_SERVER_FOUND_OTHER 3
#define SSH_SERVER_FILE_NOT_FOUND 4
enum ssh_channel_requests_e {
SSH_CHANNEL_REQUEST_UNKNOWN=0,
SSH_CHANNEL_REQUEST_PTY,
SSH_CHANNEL_REQUEST_EXEC,
SSH_CHANNEL_REQUEST_SHELL,
SSH_CHANNEL_REQUEST_ENV,
SSH_CHANNEL_REQUEST_SUBSYSTEM,
SSH_CHANNEL_REQUEST_WINDOW_CHANGE,
SSH_CHANNEL_REQUEST_X11
};
enum ssh_global_requests_e {
SSH_GLOBAL_REQUEST_UNKNOWN=0,
SSH_GLOBAL_REQUEST_TCPIP_FORWARD,
SSH_GLOBAL_REQUEST_CANCEL_TCPIP_FORWARD,
};
enum ssh_publickey_state_e {
SSH_PUBLICKEY_STATE_ERROR=-1,
SSH_PUBLICKEY_STATE_NONE=0,
SSH_PUBLICKEY_STATE_VALID=1,
SSH_PUBLICKEY_STATE_WRONG=2
};
/* 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,
SSH_SERVER_NOT_KNOWN=0,
SSH_SERVER_KNOWN_OK,
SSH_SERVER_KNOWN_CHANGED,
SSH_SERVER_FOUND_OTHER,
SSH_SERVER_FILE_NOT_FOUND
};
#ifndef MD5_DIGEST_LEN
#define MD5_DIGEST_LEN 16
#endif
/* errors */
#define SSH_NO_ERROR 0
#define SSH_REQUEST_DENIED 1
#define SSH_FATAL 2
#define SSH_EINTR 3
enum ssh_error_types_e {
SSH_NO_ERROR=0,
SSH_REQUEST_DENIED,
SSH_FATAL,
SSH_EINTR
};
/* some types for keys */
enum ssh_keytypes_e{
SSH_KEYTYPE_UNKNOWN=0,
SSH_KEYTYPE_DSS=1,
SSH_KEYTYPE_RSA,
SSH_KEYTYPE_RSA1,
SSH_KEYTYPE_ECDSA,
SSH_KEYTYPE_ED25519
};
enum ssh_keycmp_e {
SSH_KEY_CMP_PUBLIC = 0,
SSH_KEY_CMP_PRIVATE
};
/* Error return codes */
#define SSH_OK 0 /* No error */
@@ -151,149 +267,240 @@ typedef int socket_t;
#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
#define SSH_EOF -127 /* We have already a eof */
const char *ssh_get_error(void *error);
int ssh_get_error_code(void *error);
/* version checks */
const char *ssh_version(int req_version);
/** \addtogroup ssh_log
/**
* @addtogroup libssh_log
*
* @{
*/
/** \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,
/** High level protocol informations
SSH_LOG_WARNING,
/** High level protocol information
*/
SSH_LOG_PROTOCOL,
/** Lower level protocol infomations, packet level
*/
SSH_LOG_PACKET,
SSH_LOG_PACKET,
/** Every function path
*/
SSH_LOG_FUNCTIONS
SSH_LOG_FUNCTIONS
};
/** @}
/** @} */
#define SSH_LOG_RARE SSH_LOG_WARNING
/**
* @name Logging levels
*
* @brief Debug levels for logging.
* @{
*/
/*#define SSH_LOG_NOLOG 0 // no log
#define SSH_LOG_RARE 1 // rare conditions
#define SSH_LOG_ENTRY 2 // user-accessible entrypoints
#define SSH_LOG_PACKET 3 // packet id and size
#define SSH_LOG_FUNCTIONS 4 // every function in and return
*/
/* log.c */
void ssh_log(SSH_SESSION *session, int prioriry, const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
/* session.c */
SSH_SESSION *ssh_new(void);
socket_t ssh_get_fd(SSH_SESSION *session);
int ssh_get_version(SSH_SESSION *session);
int ssh_get_status(SSH_SESSION *session);
const char *ssh_get_disconnect_message(SSH_SESSION *session);
void ssh_set_options(SSH_SESSION *session, SSH_OPTIONS *options);
void ssh_set_fd_toread(SSH_SESSION *session);
void ssh_set_fd_towrite(SSH_SESSION *session);
void ssh_set_fd_except(SSH_SESSION *session);
void ssh_set_blocking(SSH_SESSION *session, int blocking);
void ssh_silent_disconnect(SSH_SESSION *session);
/** 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
/** @} */
/* client.c */
int ssh_connect(SSH_SESSION *session);
void ssh_disconnect(SSH_SESSION *session);
int ssh_service_request(SSH_SESSION *session, const char *service);
char *ssh_get_issue_banner(SSH_SESSION *session);
int ssh_get_openssh_version(SSH_SESSION *session);
/* get copyright informations */
const char *ssh_copyright(void);
enum ssh_options_e {
SSH_OPTIONS_HOST,
SSH_OPTIONS_PORT,
SSH_OPTIONS_PORT_STR,
SSH_OPTIONS_FD,
SSH_OPTIONS_USER,
SSH_OPTIONS_SSH_DIR,
SSH_OPTIONS_IDENTITY,
SSH_OPTIONS_ADD_IDENTITY,
SSH_OPTIONS_KNOWNHOSTS,
SSH_OPTIONS_TIMEOUT,
SSH_OPTIONS_TIMEOUT_USEC,
SSH_OPTIONS_SSH1,
SSH_OPTIONS_SSH2,
SSH_OPTIONS_LOG_VERBOSITY,
SSH_OPTIONS_LOG_VERBOSITY_STR,
SSH_OPTIONS_CIPHERS_C_S,
SSH_OPTIONS_CIPHERS_S_C,
SSH_OPTIONS_COMPRESSION_C_S,
SSH_OPTIONS_COMPRESSION_S_C,
SSH_OPTIONS_PROXYCOMMAND,
SSH_OPTIONS_BINDADDR,
SSH_OPTIONS_STRICTHOSTKEYCHECK,
SSH_OPTIONS_COMPRESSION,
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,
SSH_OPTIONS_HMAC_C_S,
SSH_OPTIONS_HMAC_S_C,
};
/* string.h */
enum {
/** Code is going to write/create remote files */
SSH_SCP_WRITE,
/** Code is going to read remote files */
SSH_SCP_READ,
SSH_SCP_RECURSIVE=0x10
};
/* You can use these functions, they won't change */
/* string_from_char returns a newly allocated string from a char *ptr */
STRING *string_from_char(const char *what);
/* it returns the string len in host byte orders. str->size is big endian warning ! */
size_t string_len(STRING *str);
STRING *string_new(size_t size);
/* string_fill copies the data in the string. */
int string_fill(STRING *str, const void *data, size_t len);
/* returns a newly allocated char array with the str string and a final nul caracter */
char *string_to_char(STRING *str);
STRING *string_copy(STRING *str);
/* burns the data inside a string */
void string_burn(STRING *str);
void *string_data(STRING *str);
void string_free(STRING *str);
enum ssh_scp_request_types {
/** A new directory is going to be pulled */
SSH_SCP_REQUEST_NEWDIR=1,
/** A new file is going to be pulled */
SSH_SCP_REQUEST_NEWFILE,
/** End of requests */
SSH_SCP_REQUEST_EOF,
/** End of directory */
SSH_SCP_REQUEST_ENDDIR,
/** Warning received */
SSH_SCP_REQUEST_WARNING
};
/* useful for debug */
char *ssh_get_hexa(const unsigned char *what, size_t len);
void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len);
int ssh_get_random(void *where,int len,int strong);
/* this one can be called by the client to see the hash of the public key before accepting it */
int ssh_get_pubkey_hash(SSH_SESSION *session, unsigned char **hash);
STRING *ssh_get_pubkey(SSH_SESSION *session);
/* in connect.c */
int ssh_fd_poll(SSH_SESSION *session,int *write, int *except);
int ssh_select(CHANNEL **channels, CHANNEL **outchannels, socket_t maxfd,
fd_set *readfds, struct timeval *timeout);
void publickey_free(PUBLIC_KEY *key);
/* in keyfiles.c */
PRIVATE_KEY *privatekey_from_file(SSH_SESSION *session, const char *filename,
int type, const char *passphrase);
STRING *publickey_to_string(PUBLIC_KEY *key);
PUBLIC_KEY *publickey_from_privatekey(PRIVATE_KEY *prv);
void privatekey_free(PRIVATE_KEY *prv);
STRING *publickey_from_file(SSH_SESSION *session, const char *filename,
int *type);
int ssh_is_server_known(SSH_SESSION *session);
int ssh_write_knownhost(SSH_SESSION *session);
/* in channels.c */
CHANNEL *channel_new(SSH_SESSION *session);
int channel_open_forward(CHANNEL *channel, const char *remotehost,
LIBSSH_API int ssh_blocking_flush(ssh_session session, int timeout);
LIBSSH_API ssh_channel ssh_channel_accept_x11(ssh_channel channel, int timeout_ms);
LIBSSH_API int ssh_channel_change_pty_size(ssh_channel channel,int cols,int rows);
LIBSSH_API int ssh_channel_close(ssh_channel channel);
LIBSSH_API void ssh_channel_free(ssh_channel channel);
LIBSSH_API int ssh_channel_get_exit_status(ssh_channel channel);
LIBSSH_API ssh_session ssh_channel_get_session(ssh_channel channel);
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);
int channel_open_session(CHANNEL *channel);
void channel_free(CHANNEL *channel);
int channel_request_pty(CHANNEL *channel);
int channel_request_pty_size(CHANNEL *channel, const char *term,
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);
LIBSSH_API int ssh_channel_request_exec(ssh_channel channel, const char *cmd);
LIBSSH_API int ssh_channel_request_pty(ssh_channel channel);
LIBSSH_API int ssh_channel_request_pty_size(ssh_channel channel, const char *term,
int cols, int rows);
int channel_change_pty_size(CHANNEL *channel,int cols,int rows);
int channel_request_shell(CHANNEL *channel);
int channel_request_subsystem(CHANNEL *channel, const char *system);
int channel_request_env(CHANNEL *channel, const char *name, const char *value);
int channel_request_exec(CHANNEL *channel, const char *cmd);
int channel_request_sftp(CHANNEL *channel);
int channel_write(CHANNEL *channel, const void *data, u32 len);
int channel_send_eof(CHANNEL *channel);
int channel_is_eof(CHANNEL *channel);
int channel_read(CHANNEL *channel, void *dest, u32 count, int is_stderr);
int channel_read_buffer(CHANNEL *channel, BUFFER *buffer, u32 count,
int is_stderr);
int channel_poll(CHANNEL *channel, int is_stderr);
int channel_close(CHANNEL *channel);
void channel_set_blocking(CHANNEL *channel, int blocking);
int channel_read_nonblocking(CHANNEL *channel, void *dest, u32 count,
int is_stderr);
int channel_is_open(CHANNEL *channel);
int channel_is_closed(CHANNEL *channel);
int channel_select(CHANNEL **readchans, CHANNEL **writechans, CHANNEL **exceptchans, struct
LIBSSH_API int ssh_channel_request_shell(ssh_channel channel);
LIBSSH_API int ssh_channel_request_send_signal(ssh_channel channel, const char *signum);
LIBSSH_API int ssh_channel_request_sftp(ssh_channel channel);
LIBSSH_API int ssh_channel_request_subsystem(ssh_channel channel, const char *subsystem);
LIBSSH_API int ssh_channel_request_x11(ssh_channel channel, int single_connection, const char *protocol,
const char *cookie, int screen_number);
LIBSSH_API int ssh_channel_send_eof(ssh_channel channel);
LIBSSH_API int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct
timeval * timeout);
SSH_SESSION *channel_get_session(CHANNEL *channel);
int channel_get_exit_status(CHANNEL *channel);
/* in options.c */
LIBSSH_API void ssh_channel_set_blocking(ssh_channel channel, int blocking);
LIBSSH_API void ssh_channel_set_counter(ssh_channel channel,
ssh_counter counter);
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 char *ssh_basename (const char *path);
LIBSSH_API void ssh_clean_pubkey_hash(unsigned char **hash);
LIBSSH_API int ssh_connect(ssh_session session);
LIBSSH_API const char *ssh_copyright(void);
LIBSSH_API void ssh_disconnect(ssh_session session);
LIBSSH_API char *ssh_dirname (const char *path);
LIBSSH_API int ssh_finalize(void);
/* REVERSE PORT FORWARDING */
LIBSSH_API ssh_channel ssh_channel_accept_forward(ssh_session session,
int timeout_ms,
int *destination_port);
LIBSSH_API int ssh_channel_cancel_forward(ssh_session session,
const char *address,
int port);
LIBSSH_API int ssh_channel_listen_forward(ssh_session session,
const char *address,
int port,
int *bound_port);
LIBSSH_API void ssh_free(ssh_session session);
LIBSSH_API const char *ssh_get_disconnect_message(ssh_session session);
LIBSSH_API const char *ssh_get_error(void *error);
LIBSSH_API int ssh_get_error_code(void *error);
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 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);
/* DEPRECATED FUNCTIONS */
SSH_DEPRECATED LIBSSH_API int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash);
SSH_DEPRECATED LIBSSH_API ssh_channel ssh_forward_accept(ssh_session session, int timeout_ms);
SSH_DEPRECATED LIBSSH_API int ssh_forward_cancel(ssh_session session, const char *address, int port);
SSH_DEPRECATED LIBSSH_API int ssh_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
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);
/* 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);
LIBSSH_API ssh_message ssh_message_get(ssh_session session);
LIBSSH_API int ssh_message_subtype(ssh_message msg);
LIBSSH_API int ssh_message_type(ssh_message msg);
LIBSSH_API int ssh_mkdir (const char *pathname, mode_t mode);
LIBSSH_API ssh_session ssh_new(void);
LIBSSH_API int ssh_options_copy(ssh_session src, ssh_session *dest);
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);
/**
* @brief SSH authentication callback.
@@ -311,76 +518,155 @@ int channel_get_exit_status(CHANNEL *channel);
typedef int (*ssh_auth_callback) (const char *prompt, char *buf, size_t len,
int echo, int verify, void *userdata);
SSH_OPTIONS *ssh_options_new(void);
SSH_OPTIONS *ssh_options_copy(SSH_OPTIONS *opt);
void ssh_options_free(SSH_OPTIONS *opt);
int ssh_options_set_wanted_algos(SSH_OPTIONS *opt, int algo, const char *list);
int ssh_options_set_username(SSH_OPTIONS *opt, const char *username);
int ssh_options_set_port(SSH_OPTIONS *opt, unsigned int port);
int ssh_options_getopt(SSH_OPTIONS *options, int *argcptr, char **argv);
int ssh_options_set_host(SSH_OPTIONS *opt, const char *host);
int ssh_options_set_fd(SSH_OPTIONS *opt, socket_t fd);
int ssh_options_set_bind(SSH_OPTIONS *opt, const char *bindaddr, int port);
int ssh_options_set_ssh_dir(SSH_OPTIONS *opt, const char *dir);
int ssh_options_set_known_hosts_file(SSH_OPTIONS *opt, const char *dir);
int ssh_options_set_identity(SSH_OPTIONS *opt, const char *identity);
int ssh_options_set_banner(SSH_OPTIONS *opt, const char *banner);
int ssh_options_set_status_callback(SSH_OPTIONS *opt, void (*callback)
(void *arg, float status), void *arg);
int ssh_options_set_timeout(SSH_OPTIONS *opt, long seconds, long usec);
int ssh_options_allow_ssh1(SSH_OPTIONS *opt, int allow);
int ssh_options_allow_ssh2(SSH_OPTIONS *opt, int allow);
int ssh_options_set_log_function(SSH_OPTIONS *opt,
void (*callback)(const char *message, SSH_SESSION *session, int verbosity));
int ssh_options_set_log_verbosity(SSH_OPTIONS *opt, int verbosity);
int ssh_options_set_dsa_server_key(SSH_OPTIONS *opt, const char *dsakey);
int ssh_options_set_rsa_server_key(SSH_OPTIONS *opt, const char *rsakey);
int ssh_options_set_auth_callback(SSH_OPTIONS *opt, ssh_auth_callback cb,
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);
/* buffer.c */
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);
/** creates a new buffer
*/
BUFFER *buffer_new(void);
void buffer_free(BUFFER *buffer);
/* buffer_get returns a pointer to the begining of the buffer. no position is taken into account */
void *buffer_get(BUFFER *buffer);
/* same here */
u32 buffer_get_len(BUFFER *buffer);
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);
/* in auth.c */
int ssh_auth_list(SSH_SESSION *session);
/* these functions returns AUTH_ERROR is some serious error has happened,
AUTH_SUCCESS if success,
AUTH_PARTIAL if partial success,
AUTH_DENIED if refused */
int ssh_userauth_list(SSH_SESSION *session, const char *username);
int ssh_userauth_none(SSH_SESSION *session, const char *username);
int ssh_userauth_password(SSH_SESSION *session, const char *username, const char *password);
int ssh_userauth_offer_pubkey(SSH_SESSION *session, const char *username, int type, STRING *publickey);
int ssh_userauth_pubkey(SSH_SESSION *session, const char *username, STRING *publickey, PRIVATE_KEY *privatekey);
int ssh_userauth_agent_pubkey(SSH_SESSION *session, const char *username,
PUBLIC_KEY *publickey);
int ssh_userauth_autopubkey(SSH_SESSION *session, const char *passphrase);
int ssh_userauth_kbdint(SSH_SESSION *session, const char *user, const char *submethods);
int ssh_userauth_kbdint_getnprompts(SSH_SESSION *session);
const char *ssh_userauth_kbdint_getname(SSH_SESSION *session);
const char *ssh_userauth_kbdint_getinstruction(SSH_SESSION *session);
const char *ssh_userauth_kbdint_getprompt(SSH_SESSION *session, unsigned int i, char *echo);
int ssh_userauth_kbdint_setanswer(SSH_SESSION *session, unsigned int i,
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);
LIBSSH_API void ssh_scp_free(ssh_scp scp);
LIBSSH_API int ssh_scp_init(ssh_scp scp);
LIBSSH_API int ssh_scp_leave_directory(ssh_scp scp);
LIBSSH_API ssh_scp ssh_scp_new(ssh_session session, int mode, const char *location);
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_counters(ssh_session session, ssh_counter scounter,
ssh_counter rcounter);
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(ssh_session session,
const char *username);
#endif
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_gssapi(ssh_session session);
LIBSSH_API const char *ssh_version(int req_version);
LIBSSH_API int ssh_write_knownhost(ssh_session session);
/* misc.c */
int ssh_mkdir (const char *pathname, mode_t mode);
char *ssh_dirname (const char *path);
char *ssh_basename (const char *path);
LIBSSH_API void ssh_string_burn(ssh_string str);
LIBSSH_API ssh_string ssh_string_copy(ssh_string str);
LIBSSH_API void *ssh_string_data(ssh_string str);
LIBSSH_API int ssh_string_fill(ssh_string str, const void *data, size_t len);
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);
/* init.c */
int ssh_init(void);
int ssh_finalize(void);
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_kex_algo(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);
LIBSSH_API const char* ssh_get_hmac_in(ssh_session session);
LIBSSH_API const char* ssh_get_hmac_out(ssh_session session);
#ifndef LIBSSH_LEGACY_0_4
#include "libssh/legacy.h"
#endif
#ifdef __cplusplus
}

614
include/libssh/libsshpp.hpp Normal file
View File

@@ -0,0 +1,614 @@
/*
* 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 LIBSSHPP_HPP_
#define LIBSSHPP_HPP_
/**
* @defgroup ssh_cpp The libssh C++ wrapper
*
* The C++ bindings for libssh are completely embedded in a single .hpp file, and
* this for two reasons:
* - C++ is hard to keep binary compatible, C is easy. We try to keep libssh C version
* as much as possible binary compatible between releases, while this would be hard for
* C++. If you compile your program with these headers, you will only link to the C version
* of libssh which will be kept ABI compatible. No need to recompile your C++ program
* each time a new binary-compatible version of libssh is out
* - Most of the functions in this file are really short and are probably worth the "inline"
* linking mode, which the compiler can decide to do in some case. There would be nearly no
* performance penalty of using the wrapper rather than native calls.
*
* Please visit the documentation of ssh::Session and ssh::Channel
* @see ssh::Session
* @see ssh::Channel
*
* If you wish not to use C++ exceptions, please define SSH_NO_CPP_EXCEPTIONS:
* @code
* #define SSH_NO_CPP_EXCEPTIONS
* #include <libssh/libsshpp.hpp>
* @endcode
* All functions will then return SSH_ERROR in case of error.
* @{
*/
/* do not use deprecated functions */
#define LIBSSH_LEGACY_0_4
#include <libssh/libssh.h>
#include <libssh/server.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string>
namespace ssh {
class Channel;
/** Some people do not like C++ exceptions. With this define, we give
* the choice to use or not exceptions.
* @brief if defined, disable C++ exceptions for libssh c++ wrapper
*/
#ifndef SSH_NO_CPP_EXCEPTIONS
/** @brief This class describes a SSH Exception object. This object can be thrown
* by several SSH functions that interact with the network, and may fail because of
* socket, protocol or memory errors.
*/
class SshException{
public:
SshException(ssh_session csession){
code=ssh_get_error_code(csession);
description=std::string(ssh_get_error(csession));
}
SshException(const SshException &e){
code=e.code;
description=e.description;
}
/** @brief returns the Error code
* @returns SSH_FATAL Fatal error happened (not recoverable)
* @returns SSH_REQUEST_DENIED Request was denied by remote host
* @see ssh_get_error_code
*/
int getCode(){
return code;
}
/** @brief returns the error message of the last exception
* @returns pointer to a c string containing the description of error
* @see ssh_get_error
*/
std::string getError(){
return description;
}
private:
int code;
std::string description;
};
/** @internal
* @brief Macro to throw exception if there was an error
*/
#define ssh_throw(x) if((x)==SSH_ERROR) throw SshException(getCSession())
#define ssh_throw_null(CSession,x) if((x)==NULL) throw SshException(CSession)
#define void_throwable void
#define return_throwable return
#else
/* No exception at all. All functions will return an error code instead
* of an exception
*/
#define ssh_throw(x) if((x)==SSH_ERROR) return SSH_ERROR
#define ssh_throw_null(CSession,x) if((x)==NULL) return NULL
#define void_throwable int
#define return_throwable return SSH_OK
#endif
/**
* The ssh::Session class contains the state of a SSH connection.
*/
class Session {
friend class Channel;
public:
Session(){
c_session=ssh_new();
}
~Session(){
ssh_free(c_session);
c_session=NULL;
}
/** @brief sets an SSH session options
* @param type Type of option
* @param option cstring containing the value of option
* @throws SshException on error
* @see ssh_options_set
*/
void_throwable setOption(enum ssh_options_e type, const char *option){
ssh_throw(ssh_options_set(c_session,type,option));
return_throwable;
}
/** @brief sets an SSH session options
* @param type Type of option
* @param option long integer containing the value of option
* @throws SshException on error
* @see ssh_options_set
*/
void_throwable setOption(enum ssh_options_e type, long int option){
ssh_throw(ssh_options_set(c_session,type,&option));
return_throwable;
}
/** @brief sets an SSH session options
* @param type Type of option
* @param option void pointer containing the value of option
* @throws SshException on error
* @see ssh_options_set
*/
void_throwable setOption(enum ssh_options_e type, void *option){
ssh_throw(ssh_options_set(c_session,type,option));
return_throwable;
}
/** @brief connects to the remote host
* @throws SshException on error
* @see ssh_connect
*/
void_throwable connect(){
int ret=ssh_connect(c_session);
ssh_throw(ret);
return_throwable;
}
/** @brief Authenticates automatically using public key
* @throws SshException on error
* @returns SSH_AUTH_SUCCESS, SSH_AUTH_PARTIAL, SSH_AUTH_DENIED
* @see ssh_userauth_autopubkey
*/
int userauthPublickeyAuto(void){
int ret=ssh_userauth_publickey_auto(c_session, NULL, NULL);
ssh_throw(ret);
return ret;
}
/** @brief Authenticates using the "none" method. Prefer using autopubkey if
* possible.
* @throws SshException on error
* @returns SSH_AUTH_SUCCESS, SSH_AUTH_PARTIAL, SSH_AUTH_DENIED
* @see ssh_userauth_none
* @see Session::userauthAutoPubkey
*/
int userauthNone(){
int ret=ssh_userauth_none(c_session,NULL);
ssh_throw(ret);
return ret;
}
/** @brief Authenticates using the password method.
* @param[in] password password to use for authentication
* @throws SshException on error
* @returns SSH_AUTH_SUCCESS, SSH_AUTH_PARTIAL, SSH_AUTH_DENIED
* @see ssh_userauth_password
*/
int userauthPassword(const char *password){
int ret=ssh_userauth_password(c_session,NULL,password);
ssh_throw(ret);
return ret;
}
/** @brief Try to authenticate using the publickey method.
* @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_try_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] 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 userauthPublickey(ssh_key privkey){
int ret=ssh_userauth_publickey(c_session, NULL, privkey);
ssh_throw(ret);
return ret;
}
int userauthPrivatekeyFile(const char *filename,
const char *passphrase);
/** @brief Returns the available authentication methods from the server
* @throws SshException on error
* @returns Bitfield of available methods.
* @see ssh_userauth_list
*/
int getAuthList(){
int ret=ssh_userauth_list(c_session, NULL);
ssh_throw(ret);
return ret;
}
/** @brief Disconnects from the SSH server and closes connection
* @see ssh_disconnect
*/
void disconnect(){
ssh_disconnect(c_session);
}
/** @brief Returns the disconnect message from the server, if any
* @returns pointer to the message, or NULL. Do not attempt to free
* the pointer.
*/
const char *getDisconnectMessage(){
const char *msg=ssh_get_disconnect_message(c_session);
return msg;
}
/** @internal
* @brief gets error message
*/
const char *getError(){
return ssh_get_error(c_session);
}
/** @internal
* @brief returns error code
*/
int getErrorCode(){
return ssh_get_error_code(c_session);
}
/** @brief returns the file descriptor used for the communication
* @returns the file descriptor
* @warning if a proxycommand is used, this function will only return
* one of the two file descriptors being used
* @see ssh_get_fd
*/
socket_t getSocket(){
return ssh_get_fd(c_session);
}
/** @brief gets the Issue banner from the ssh server
* @returns the issue banner. This is generally a MOTD from server
* @see ssh_get_issue_banner
*/
std::string getIssueBanner(){
char *banner=ssh_get_issue_banner(c_session);
std::string ret= std::string(banner);
::free(banner);
return ret;
}
/** @brief returns the OpenSSH version (server) if possible
* @returns openssh version code
* @see ssh_get_openssh_version
*/
int getOpensshVersion(){
return ssh_get_openssh_version(c_session);
}
/** @brief returns the version of the SSH protocol being used
* @returns the SSH protocol version
* @see ssh_get_version
*/
int getVersion(){
return ssh_get_version(c_session);
}
/** @brief verifies that the server is known
* @throws SshException on error
* @returns Integer value depending on the knowledge of the
* server key
* @see ssh_is_server_known
*/
int isServerKnown(){
int ret=ssh_is_server_known(c_session);
ssh_throw(ret);
return ret;
}
void log(int priority, const char *format, ...){
char buffer[1024];
va_list va;
va_start(va, format);
vsnprintf(buffer, sizeof(buffer), format, va);
va_end(va);
_ssh_log(priority, "libsshpp", "%s", buffer);
}
/** @brief copies options from a session to another
* @throws SshException on error
* @see ssh_options_copy
*/
void_throwable optionsCopy(const Session &source){
ssh_throw(ssh_options_copy(source.c_session,&c_session));
return_throwable;
}
/** @brief parses a configuration file for options
* @throws SshException on error
* @param[in] file configuration file name
* @see ssh_options_parse_config
*/
void_throwable optionsParseConfig(const char *file){
ssh_throw(ssh_options_parse_config(c_session,file));
return_throwable;
}
/** @brief silently disconnect from remote host
* @see ssh_silent_disconnect
*/
void silentDisconnect(){
ssh_silent_disconnect(c_session);
}
/** @brief Writes the known host file with current
* host key
* @throws SshException on error
* @see ssh_write_knownhost
*/
int writeKnownhost(){
int ret = ssh_write_knownhost(c_session);
ssh_throw(ret);
return ret;
}
/** @brief accept an incoming forward connection
* @param[in] timeout_ms timeout for waiting, in ms
* @returns new Channel pointer on the forward connection
* @returns NULL in case of error
* @warning you have to delete this pointer after use
* @see ssh_channel_forward_accept
* @see Session::listenForward
*/
inline Channel *acceptForward(int timeout_ms);
/* implemented outside the class due Channel references */
void_throwable cancelForward(const char *address, int port){
int err=ssh_channel_cancel_forward(c_session, address, port);
ssh_throw(err);
return_throwable;
}
void_throwable listenForward(const char *address, int port,
int &boundport){
int err=ssh_channel_listen_forward(c_session, address, port, &boundport);
ssh_throw(err);
return_throwable;
}
private:
ssh_session c_session;
ssh_session getCSession(){
return c_session;
}
/* No copy constructor, no = operator */
Session(const Session &);
Session& operator=(const Session &);
};
/** @brief the ssh::Channel class describes the state of an SSH
* channel.
* @see ssh_channel
*/
class Channel {
friend class Session;
public:
Channel(Session &session){
channel=ssh_channel_new(session.getCSession());
this->session=&session;
}
~Channel(){
ssh_channel_free(channel);
channel=NULL;
}
/** @brief accept an incoming X11 connection
* @param[in] timeout_ms timeout for waiting, in ms
* @returns new Channel pointer on the X11 connection
* @returns NULL in case of error
* @warning you have to delete this pointer after use
* @see ssh_channel_accept_x11
* @see Channel::requestX11
*/
Channel *acceptX11(int timeout_ms){
ssh_channel x11chan = ssh_channel_accept_x11(channel,timeout_ms);
ssh_throw_null(getCSession(),x11chan);
Channel *newchan = new Channel(getSession(),x11chan);
return newchan;
}
/** @brief change the size of a pseudoterminal
* @param[in] cols number of columns
* @param[in] rows number of rows
* @throws SshException on error
* @see ssh_channel_change_pty_size
*/
void_throwable changePtySize(int cols, int rows){
int err=ssh_channel_change_pty_size(channel,cols,rows);
ssh_throw(err);
return_throwable;
}
/** @brief closes a channel
* @throws SshException on error
* @see ssh_channel_close
*/
void_throwable close(){
ssh_throw(ssh_channel_close(channel));
return_throwable;
}
int getExitStatus(){
return ssh_channel_get_exit_status(channel);
}
Session &getSession(){
return *session;
}
/** @brief returns true if channel is in closed state
* @see ssh_channel_is_closed
*/
bool isClosed(){
return ssh_channel_is_closed(channel) != 0;
}
/** @brief returns true if channel is in EOF state
* @see ssh_channel_is_eof
*/
bool isEof(){
return ssh_channel_is_eof(channel) != 0;
}
/** @brief returns true if channel is in open state
* @see ssh_channel_is_open
*/
bool isOpen(){
return ssh_channel_is_open(channel) != 0;
}
int openForward(const char *remotehost, int remoteport,
const char *sourcehost=NULL, int localport=0){
int err=ssh_channel_open_forward(channel,remotehost,remoteport,
sourcehost, localport);
ssh_throw(err);
return err;
}
/* TODO: completely remove this ? */
void_throwable openSession(){
int err=ssh_channel_open_session(channel);
ssh_throw(err);
return_throwable;
}
int poll(bool is_stderr=false){
int err=ssh_channel_poll(channel,is_stderr);
ssh_throw(err);
return err;
}
int read(void *dest, size_t count, bool is_stderr){
int err;
/* handle int overflow */
if(count > 0x7fffffff)
count = 0x7fffffff;
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;
}
int readNonblocking(void *dest, size_t count, bool is_stderr=false){
int err;
/* handle int overflow */
if(count > 0x7fffffff)
count = 0x7fffffff;
err=ssh_channel_read_nonblocking(channel,dest,count,is_stderr);
ssh_throw(err);
return err;
}
void_throwable requestEnv(const char *name, const char *value){
int err=ssh_channel_request_env(channel,name,value);
ssh_throw(err);
return_throwable;
}
void_throwable requestExec(const char *cmd){
int err=ssh_channel_request_exec(channel,cmd);
ssh_throw(err);
return_throwable;
}
void_throwable requestPty(const char *term=NULL, int cols=0, int rows=0){
int err;
if(term != NULL && cols != 0 && rows != 0)
err=ssh_channel_request_pty_size(channel,term,cols,rows);
else
err=ssh_channel_request_pty(channel);
ssh_throw(err);
return_throwable;
}
void_throwable requestShell(){
int err=ssh_channel_request_shell(channel);
ssh_throw(err);
return_throwable;
}
void_throwable requestSendSignal(const char *signum){
int err=ssh_channel_request_send_signal(channel, signum);
ssh_throw(err);
return_throwable;
}
void_throwable requestSubsystem(const char *subsystem){
int err=ssh_channel_request_subsystem(channel,subsystem);
ssh_throw(err);
return_throwable;
}
int requestX11(bool single_connection,
const char *protocol, const char *cookie, int screen_number){
int err=ssh_channel_request_x11(channel,single_connection,
protocol, cookie, screen_number);
ssh_throw(err);
return err;
}
void_throwable sendEof(){
int err=ssh_channel_send_eof(channel);
ssh_throw(err);
return_throwable;
}
/** @brief Writes on a channel
* @param data data to write.
* @param len number of bytes to write.
* @param is_stderr write should be done on the stderr channel (server only)
* @returns number of bytes written
* @throws SshException in case of error
* @see channel_write
* @see channel_write_stderr
*/
int write(const void *data, size_t len, bool is_stderr=false){
int ret;
if(is_stderr){
ret=ssh_channel_write_stderr(channel,data,len);
} else {
ret=ssh_channel_write(channel,data,len);
}
ssh_throw(ret);
return ret;
}
private:
ssh_session getCSession(){
return session->getCSession();
}
Channel (Session &session, ssh_channel c_channel){
this->channel=c_channel;
this->session=&session;
}
Session *session;
ssh_channel channel;
/* No copy and no = operator */
Channel(const Channel &);
Channel &operator=(const Channel &);
};
inline Channel *Session::acceptForward(int timeout_ms){
ssh_channel forward =
ssh_channel_accept_forward(c_session, timeout_ms, NULL);
ssh_throw_null(c_session,forward);
Channel *newchan = new Channel(*this,forward);
return newchan;
}
} // namespace ssh
/** @} */
#endif /* LIBSSHPP_HPP_ */

108
include/libssh/messages.h Normal file
View File

@@ -0,0 +1,108 @@
/*
* 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 MESSAGES_H_
#define MESSAGES_H_
#include "config.h"
struct ssh_auth_request {
char *username;
int method;
char *password;
struct ssh_key_struct *pubkey;
char signature_state;
char kbdint_response;
};
struct ssh_channel_request_open {
int type;
uint32_t sender;
uint32_t window;
uint32_t packet_size;
char *originator;
uint16_t originator_port;
char *destination;
uint16_t destination_port;
};
struct ssh_service_request {
char *service;
};
struct ssh_global_request {
int type;
uint8_t want_reply;
char *bind_address;
uint16_t bind_port;
};
struct ssh_channel_request {
int type;
ssh_channel channel;
uint8_t want_reply;
/* pty-req type specifics */
char *TERM;
uint32_t width;
uint32_t height;
uint32_t pxwidth;
uint32_t pxheight;
ssh_string modes;
/* env type request */
char *var_name;
char *var_value;
/* exec type request */
char *command;
/* subsystem */
char *subsystem;
/* X11 */
uint8_t x11_single_connection;
char *x11_auth_protocol;
char *x11_auth_cookie;
uint32_t x11_screen_number;
};
struct ssh_message_struct {
ssh_session session;
int type;
struct ssh_auth_request auth_request;
struct ssh_channel_request_open channel_request_open;
struct ssh_channel_request channel_request;
struct ssh_service_request service_request;
struct ssh_global_request global_request;
};
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);
#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_ */

92
include/libssh/misc.h Normal file
View File

@@ -0,0 +1,92 @@
/*
* 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 MISC_H_
#define MISC_H_
/* in misc.c */
/* gets the user home dir. */
char *ssh_get_user_home_dir(void);
char *ssh_get_local_username(void);
int ssh_file_readaccess_ok(const char *file);
char *ssh_path_expand_tilde(const char *d);
char *ssh_path_expand_escape(ssh_session session, const char *s);
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);
#endif
#ifndef HAVE_HTONLL
#define htonll(x) ntohll((x))
#endif
/* list processing */
struct ssh_list {
struct ssh_iterator *root;
struct ssh_iterator *end;
};
struct ssh_iterator {
struct ssh_iterator *next;
const void *data;
};
struct ssh_timestamp {
long seconds;
long useconds;
};
struct ssh_list *ssh_list_new(void);
void ssh_list_free(struct ssh_list *list);
struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list);
struct ssh_iterator *ssh_list_find(const struct ssh_list *list, void *value);
int ssh_list_append(struct ssh_list *list, const void *data);
int ssh_list_prepend(struct ssh_list *list, const void *data);
void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator);
char *ssh_lowercase(const char* str);
char *ssh_hostport(const char *host, int port);
const void *_ssh_list_pop_head(struct ssh_list *list);
#define ssh_iterator_value(type, iterator)\
((type)((iterator)->data))
/** @brief fetch the head element of a list and remove it from list
* @param type type of the element to return
* @param list the ssh_list to use
* @return the first element of the list, or NULL if the list is empty
*/
#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 */

89
include/libssh/packet.h Normal file
View File

@@ -0,0 +1,89 @@
/*
* 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 PACKET_H_
#define PACKET_H_
#include "libssh/wrapper.h"
struct ssh_socket_struct;
/* this structure should go someday */
typedef struct packet_struct {
int valid;
uint32_t len;
uint8_t type;
} PACKET;
/** different state of packet reading. */
enum ssh_packet_state_e {
/** Packet not initialized, must read the size of packet */
PACKET_STATE_INIT,
/** Size was read, waiting for the rest of data */
PACKET_STATE_SIZEREAD,
/** Full packet was read and callbacks are being called. Future packets
* should wait for the end of the callback. */
PACKET_STATE_PROCESSING
};
int packet_send(ssh_session session);
#ifdef WITH_SSH1
int packet_send1(ssh_session session) ;
void ssh_packet_set_default_callbacks1(ssh_session session);
SSH_PACKET_CALLBACK(ssh_packet_disconnect1);
SSH_PACKET_CALLBACK(ssh_packet_smsg_success1);
SSH_PACKET_CALLBACK(ssh_packet_smsg_failure1);
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, enum ssh_hmac_e type);
#endif /* PACKET_H_ */

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