Compare commits

..

159 Commits

Author SHA1 Message Date
Andreas Schneider
6da817aa47 Update ChangeLog. 2012-11-14 17:56:48 +01:00
Andreas Schneider
05ed61848f cmake: Bump version number. 2012-11-14 17:11:03 +01:00
Andreas Schneider
d63f19c300 CVE-2012-4561: Fix possible free's on invalid pointers. 2012-11-14 17:11:03 +01:00
Andreas Schneider
455da60846 CVE-2012-4561: Fix error handling of try_publickey_from_file(). 2012-11-14 17:11:03 +01:00
Andreas Schneider
46b2eb3c14 CVE-2012-4559: Make sure we don't free name and longname twice on error. 2012-11-14 17:11:03 +01:00
Andreas Schneider
6236001ff4 CVE-2012-4559: Ensure that we don't free req twice. 2012-11-14 17:11:03 +01:00
Andreas Schneider
1471f2c67a CVE-2012-4559: Ensure we don't free blob or request twice. 2012-11-14 17:11:03 +01:00
Andreas Schneider
b485463197 CVE-2012-4560: Fix a write one past the end of 'buf'. 2012-11-14 17:11:03 +01:00
Andreas Schneider
64fca8a7ed CVE-2012-4560: Fix a write one past the end of the 'u' buffer. 2012-11-14 17:11:03 +01:00
Xi Wang
e3d9501b31 CVE-2012-4562: Fix possible string related integer overflows. 2012-11-14 17:11:00 +01:00
Andreas Schneider
1699adfa03 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:10:57 +01:00
Xi Wang
db81310d71 CVE-2012-4562: Fix multiple integer overflows in buffer-related functions. 2012-11-14 17:10:53 +01:00
Xi Wang
8489521c0d 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:10:47 +01:00
Andreas Schneider
2ee6282fdd channels: Fix a possible infinite loop if the connection dropped.
This fixes bug #85.
2012-10-22 18:13:53 +02:00
Andreas Schneider
ae218d0d15 channels1: Add missing request_state and set it to accepted.
This fixes bug #88.
2012-10-22 18:06:12 +02:00
Andreas Schneider
26579b2231 auth1: Reset error state to no error.
This fixes bug #89.
2012-10-22 18:06:09 +02:00
Andreas Schneider
04f1d950b9 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:50 +02:00
Andreas Schneider
191c0ae2bb doc: Update copyright policy. 2012-10-14 19:58:26 +02:00
Andreas Schneider
5b32f31a31 channel: Fix a possible null pointer dereference.
(cherry picked from commit ceb8072b34)
2012-10-05 11:48:34 +02:00
Andreas Schneider
3eac8e1c18 channels: Fix a possible null pointer dereference.
(cherry picked from commit 656fd60110)
2012-10-05 11:47:35 +02:00
Andreas Schneider
dc8f0cddee getpass: Fix a memory leak in ssh_gets() on error.
(cherry picked from commit 6092596199)
2012-10-05 11:45:47 +02:00
Andreas Schneider
97b263aee9 sftp: Harden sftp_extension_supported() against null pointers.
(cherry picked from commit 22f607649d)
2012-10-05 11:45:28 +02:00
Andreas Schneider
cb53c4f0e1 sftp: Fix a memory on error in sftp_opendir().
(cherry picked from commit b5c4b090da)
2012-10-05 11:45:12 +02:00
Andreas Schneider
0d029e7038 misc: Don't leak memory on ssh_path_expand_escape() on error.
(cherry picked from commit 61d032fc03)
2012-10-05 11:44:50 +02:00
Andreas Schneider
aae725a44c session: Fix a memory leak in ssh_new() on error.
(cherry picked from commit 280ce3fe93)
2012-10-05 11:44:12 +02:00
Werner Koch
0e833d75e6 Fix regression in pre-connected socket setting.
* src/socket.c (ssh_socket_pollcallback): Factor some code out to ...
(ssh_socket_set_connecting): New.
* include/libssh/socket.h (ssh_socket_set_connecting): Add prototype.
* src/client.c (ssh_connect): Use new function for a socket set by
SSH_OPTIONS_FD.

Signed-off-by: Werner Koch <wk@gnupg.org>
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2012-09-21 09:41:47 +02:00
Andreas Schneider
ae83f77511 build: Fix missing struct in_addr warning.
(cherry picked from commit 782b2e37c6)
2012-07-17 18:17:05 +02:00
Andreas Schneider
4d8420f328 sftp: Fix bug in sftp_mkdir not returning on error.
resolves: #84
(cherry picked from commit a92c97b2e1)
2012-07-17 18:13:03 +02:00
Andreas Schneider
d8f2a793d3 connect: Fix a build warning.
(cherry picked from commit 8b8d9dc83a)
2012-07-17 17:34:50 +02:00
rofl0r
558b53a856 session: Cleanup timeout functions and fix packets termination.
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.
Also cleaned up ssh_blocking_flush, which was using the timeout in a
bogus manner (resetting the timeout after each check).
2012-01-02 12:42:47 +01:00
Andreas Schneider
0764adc82f message: Fix compiler warning.
(cherry picked from commit 2f861a858b)
2012-01-02 09:31:59 +01:00
rofl0r
87fd7d617e 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:54:09 +01:00
Andreas Schneider
3e83af5f5e keyfiles: Fix build errors with callbacks.
Introduced with the last commit.
2011-09-17 22:59:13 +02:00
Aris Adamantiadis
0dc57fdcf1 Fixes the ssh_log issue on ssh_bind handles.
(cherry picked from commit da954c2c5e)

Conflicts:

	src/keyfiles.c
2011-09-17 22:01:43 +02:00
Andreas Schneider
3799670d01 doc: Fix threading documentation.
(cherry picked from commit 2cc95e1e08)
2011-09-17 21:32:43 +02:00
Aris Adamantiadis
d6390d50bf Fix documentation bug about threading
(cherry picked from commit c84380bad5)
2011-09-17 21:22:20 +02:00
Andreas Schneider
e27b31c9c4 build: Increase version number. 2011-09-16 21:56:19 +02:00
Andreas Schneider
684b7f6a57 build: Updated changelog. 2011-09-16 21:54:39 +02:00
Aris Adamantiadis
b0b2fd768c SSH1: handle exit-status message (channels would not close) 2011-09-15 11:25:11 +02:00
Aris Adamantiadis
9180bfffcd channels: don't send SSH2 packets on SSH1 ! 2011-09-15 11:25:00 +02:00
Aris Adamantiadis
058bb0f4ea SSH1: fix build
(cherry picked from commit 3eece8ac0b)

Conflicts:

	src/channels.c
	src/channels1.c
2011-09-02 23:02:27 +02:00
Aris Adamantiadis
64b125700e channels: replaced bugged lists with ssh_list
(cherry picked from commit 6d8bb956c5)

Conflicts:

	src/channels.c
	src/session.c
2011-09-02 22:59:44 +02:00
Aris Adamantiadis
6f650a61ca 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.
(cherry picked from commit b5351f2809)
2011-09-02 22:49:22 +02:00
Aris Adamantiadis
d4e95f4653 Channels: increase window size x10
Provides me a 3x performance boost for async sftp, 5x for sync sftp
(on localhost)
(cherry picked from commit 17ae216340)
2011-09-02 22:45:54 +02:00
Andreas Schneider
26be91fb8e channels: Fix bug #52.
(cherry picked from commit a2c94abb92)

Conflicts:
    src/channels.c
2011-09-02 22:45:50 +02:00
Aris Adamantiadis
43a3becf08 unittests:make sftp_dir pass on my laptop
(cherry picked from commit 7363b29427)
2011-09-02 22:25:26 +02:00
Aris Adamantiadis
d127d68b9f scp: Fixed documentation bug #9
(cherry picked from commit 99e6fde751)
2011-09-02 22:24:47 +02:00
rofl0r
730da3e3c2 channels: Fix possible infinite loop in channel_read().
(cherry picked from commit 66188f1af8)
2011-08-29 21:48:09 +02:00
Jonas Jonsson
661722753b 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>
(cherry picked from commit d1df255df4)
2011-08-29 10:07:22 +02:00
Andreas Schneider
ac445a1e18 auth: Handle request service timeout in blocking mode.
(cherry picked from commit e5e673bafe)
2011-08-27 00:00:28 +02:00
Andreas Schneider
b7a3d41baf auth: Fix ssh_auth_list() documentation.
The server will not return SSH_AUTH_METHOD_NONE.
(cherry picked from commit 9c376dd913)
2011-08-22 15:04:09 +02:00
Andreas Schneider
096475b356 channels: Fix incorrect return values in ssh_channel_write().
(cherry picked from commit 13227714f2)
2011-08-10 18:37:58 +02:00
rofl0r
d08554dabd session: Fix an infinite loop in the termination callback.
This happened due to the use of the buggy and obsolete timeout
funtions.
(cherry picked from commit 7949f2cdc6)
2011-08-10 18:37:14 +02:00
Andreas Schneider
cbe8f8b760 channels: Handle SSH_AGAIN in channel_open().
(cherry picked from commit 2f87873642)
2011-08-09 23:08:39 +02:00
Mark Riordan
8987bc53e0 Fix "status -5 inflating zlib packet"
Signed-off-by: Mark Riordan <mriordan@ipswitch.com>
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 6c45d6dc01)
2011-08-09 20:13:41 +02:00
Andreas Schneider
39802b31fe build: Set libssh version to 0.5.1. 2011-08-09 14:47:33 +02:00
Andreas Schneider
e5a2aef1bf build: Updated ChangeLog. 2011-08-09 14:46:26 +02:00
Einar Floystad Dorum
edb03bd224 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>
(cherry picked from commit 01c4b713dc)
2011-08-08 15:28:08 +02:00
rofl0r
1204f43ea9 client: Fix another source of endless wait.
(cherry picked from commit 35686b4822)
2011-08-07 12:47:23 +02:00
rofl0r
b542bc9e4e channels: Fix an endless loop in case of a channel_open error.
(cherry picked from commit 7ccd9c31b3)
2011-08-07 12:47:17 +02:00
rofl0r
61a97ccede 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.
(cherry picked from commit af85337f5f)
2011-08-07 12:47:09 +02:00
rofl0r
a1ef27c0b8 channels: Fix checking for fatal errors.
We need this that we don't end up in and infinite poll loop.
(cherry picked from commit 563fbe4de8)

Conflicts:

	src/poll.c
2011-08-07 12:46:47 +02:00
rofl0r
fb8f2cd11b channels: Fix ssh_channel_from_local()
It only worked if the first channel in the list was equivalent to we
were looking for.
(cherry picked from commit 39f962c91e)
2011-08-07 12:46:06 +02:00
rofl0r
1d8a9ddf84 misc: Fix ssh_timeout_update().
(cherry picked from commit c31cac93f3)
2011-08-07 12:45:54 +02:00
Andreas Schneider
bea66b6476 examples: Fix permissions of the file we copy.
Thanks to Baptiste Marchand.
(cherry picked from commit 15ebbad146)
2011-08-03 22:23:51 +02:00
Andreas Schneider
a8111934d5 channels: Set the max packet size to 32768.
(cherry picked from commit 790b62bca5)
2011-08-03 22:20:52 +02:00
Aris Adamantiadis
f201e983b0 Workaround ssh_get_user_home_dir on LDAP users 2011-07-13 12:04:04 +02:00
Andreas Schneider
81332e1e27 build: Fix libssh_threads pkg-config.
(cherry picked from commit 269c9fed354f3a8adbc54fccba6287d5b1f166e3)
2011-06-15 18:26:33 +02:00
Andreas Schneider
ea84f50603 cmake: Added pkg-config support for libssh_treads.
(cherry picked from commit 583a7f933a)
2011-06-14 13:47:51 +02:00
Andreas Schneider
ccc94e7ab6 packet: Don't (de)compress empty buffers.
This fixes bug #50.
(cherry picked from commit fb0f125351)
2011-06-11 13:16:21 +02:00
Aris Adamantiadis
4c05be0c1b Fix compilation without server and sftp modes
(cherry picked from commit 809b3adeba)
2011-06-09 12:16:07 +02:00
Andreas Schneider
a493a90c59 build: Check for ntohll().
This function is available on AIX.
(cherry picked from commit 640e3830f2)
2011-06-06 18:57:50 +02:00
Andreas Schneider
4a18df8574 string: Added missing include.
(cherry picked from commit 3fa801a929)
2011-06-06 18:57:11 +02:00
Andreas Schneider
cfa74c1dc6 string: Added missing errno.
(cherry picked from commit d536cc4f39)
2011-06-06 18:51:12 +02:00
milo
de706de8c3 Check for NULL pointers in string.c
(cherry picked from commit 4230509e80)
2011-06-06 18:50:11 +02:00
Andreas Schneider
71fa0dc6bb cmake: Fix static .lib overwriting on Windows.
(cherry picked from commit 1880ef54d2)
2011-06-01 14:53:29 +02:00
Andreas Schneider
914a2d8e41 cmake: Prepare for release. 2011-05-30 12:36:54 +02:00
Andreas Schneider
956b64d348 session: Fix return code of ssh_blocking_flush().
(cherry picked from commit 3c21281bf0)
2011-05-28 18:35:21 +02:00
Aris Adamantiadis
91489cd378 remove "0.5.0 is dev" in the doc
(cherry picked from commit 3bc46c3bf0)
2011-05-27 14:20:02 +02:00
Aris Adamantiadis
615bc3b8f7 Forgot a cast to remove warnings
(cherry picked from commit ac167c9077)
2011-05-27 14:19:54 +02:00
Aris Adamantiadis
5b645419fd Fix bug #5, channel_read_nonblocking that blocks 2011-05-27 14:19:42 +02:00
Mark Riordan
c436e07022 Fix memory leak when compression is used
Signed-off-by: Mark Riordan <mriordan@ipswitch.com>
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit dcea8db6b2)
2011-05-27 11:47:26 +02:00
Andreas Schneider
188fb37801 sftp: Reset eof on seek operations.
This fixes bug #48.
(cherry picked from commit c483418b82)
2011-05-26 11:27:35 +02:00
Andreas Schneider
44fed3eb9b misc: Fix compilation on Windows.
(cherry picked from commit ba03388031)
2011-05-26 11:20:25 +02:00
Andreas Schneider
36abd82a7e cmake: Fix detection of clock_gettime. 2011-05-25 22:13:28 +02:00
Aris Adamantiadis
fd6d0b6897 Replace clock_gettime with gettimeofday when missing
(cherry picked from commit 65282841e2)
2011-05-25 22:00:00 +02:00
Aris Adamantiadis
09b0018b93 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.
(cherry picked from commit 59f7647cd9)
2011-05-25 21:59:51 +02:00
Andreas Schneider
2624e603d4 Revert "Use BIO* in _privatekey_from_file [Oliver Stöneberg]"
This reverts commit da8356b477.
2011-05-19 19:47:29 +02:00
Oliver Stöneberg
fd61eda16d keyfiles: Move FILE* into HAVE_LIBGCRYPT code.
(cherry picked from commit c7c563eb8ad01ab5750b5ea4e72031ebd298651c)
2011-05-17 21:00:02 +02:00
Oliver Stöneberg
a6dda5fefd keyfiles: Use BIO* in _privatekey_from_file().
(cherry picked from commit 82df5dc2083a6f7234d1545bd671ee1b5b4680b6)
2011-05-17 20:59:55 +02:00
Oliver Stöneberg
da8356b477 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]
2011-05-17 20:57:58 +02:00
Oliver Stöneberg
e5fb20c17b socket: Fixed use-after-free.
When s->callbacks->exception() was called in ssh_socket_pollcallback()
we had a use after free bug.
(cherry picked from commit 9866763789)
2011-05-17 20:57:38 +02:00
Oliver Stöneberg
c472bd7437 keyfiles: Fixed compilation without defines.
This fixes cppcheck issues.
(cherry picked from commit 7f0761885c)
2011-05-17 20:57:38 +02:00
Oliver Stöneberg
8796756ae5 tests: Fixed some cppcheck warnings.
(cherry picked from commit e3311d03db)
2011-05-17 20:57:38 +02:00
Oliver Stöneberg
9c8f285a98 examples: Use the right cleanup functions.
(cherry picked from commit 525324b2f9)
2011-05-17 20:57:38 +02:00
Oliver Stöneberg
8154e24027 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.
(cherry picked from commit 4e153aed8a)
2011-05-17 20:57:38 +02:00
Oliver Stöneberg
629cfbccc4 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.
(cherry picked from commit 671a982739)
2011-05-17 20:57:38 +02:00
Oliver Stöneberg
c5990791db poll: Removed WSAPoll() support.
It was causing too many issues and the poll emulation is quite stable.
(cherry picked from commit f4f4ce37f0)
2011-05-17 20:57:38 +02:00
Oliver Stöneberg
16241938af doc: Small update to auth.c documentation.
(cherry picked from commit 12b61a6266)
2011-05-17 20:57:38 +02:00
Andreas Schneider
6a8cb38dd3 channel: Improve the request signal documentation.
(cherry picked from commit 32cd45612b)
2011-05-15 13:44:11 +02:00
Oliver Stöneberg
bac2227ee2 Updated privatekey_from_file() to use BIO* as well [Oliver Stöneberg] 2011-05-02 19:46:54 +02:00
Oliver Stöneberg
dcb50cc0c8 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]
2011-05-02 19:17:38 +02:00
milo
f503c4a3e1 Delay the check for kbdint->answers in kbdint_send()
(cherry picked from commit 32ba5204b7)
2011-05-02 18:04:56 +02:00
milo
a56c925da9 Fix segfault when ssh_userauth_kbdint_setanswer() has not been called
(cherry picked from commit b6e712e934)
2011-05-02 17:47:00 +02:00
milo
833cc00014 [socket] fix a segfault at disconnect
(cherry picked from commit 7d2064c289)
2011-05-02 17:41:51 +02:00
milo
09e8cf33d7 [messages] don't queue messages if callback present
(cherry picked from commit 1979c14aac)
2011-05-02 17:40:05 +02:00
milo
a03bb2fbf7 [poll] avoid infinite loop in ssh_poll_ctx_free()
(cherry picked from commit 8092541603)
2011-05-02 17:39:28 +02:00
milo
bb784ec6be [channels] Added ssh_channel_window_size() and avoided reentrancy in channel_write_common()
(cherry picked from commit 7ba0938846)
2011-05-02 17:35:34 +02:00
Andreas Schneider
996c00c81c keyfiles: Fixed the build. 2011-05-01 21:04:55 +02:00
Oliver Stöneberg
30bdca07e9 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:43:57 +02:00
Oliver Stöneberg
b4b49cf3f6 socket: Fixed poll input event.
(cherry picked from commit 040a543f57)
2011-05-01 19:43:01 +02:00
Oliver Stöneberg
189796e94f examples: Removed unnecessary \n from ssh_log() calls in samplessh.
(cherry picked from commit a73459171b)
2011-05-01 19:42:13 +02:00
Oliver Stöneberg
2431c7d925 examples: Fixed memory leak in samplessh when using commands.
(cherry picked from commit c3849a3cfd)
2011-05-01 19:42:01 +02:00
Andreas Schneider
fc9c61714f poll: Fix poll input events.
bug#38
2011-04-15 19:17:40 +02:00
Andreas Schneider
e096658df3 examples: Fix some memory leaks.
(cherry picked from commit 644145a88c)
2011-04-15 19:06:24 +02:00
Andreas Schneider
b1d58c5454 Fix assertion with Visual Studio because of %zu.
(cherry picked from commit ef658b4bef)
2011-04-15 19:03:02 +02:00
Mark Riordan
ced66eb11f 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>
(cherry picked from commit 5939cfe78a)
2011-04-14 14:19:15 +02:00
Andreas Schneider
1b44daddf6 examples: Call correct functions on exit.
(cherry picked from commit 3e7d4534ce)
2011-04-14 14:19:08 +02:00
Aris Adamantiadis
a309c1b38e Fixed missing CRYPTO_cleanup_all_ex_data() in ssh_finalize
(cherry picked from commit 934252d6ca)
2011-04-14 13:40:42 +02:00
Andreas Schneider
e56aaf5f44 wrapper: Fixed a possible NULL pointer dereference.
(cherry picked from commit 94e7d345a7)
2011-04-14 10:18:37 +02:00
Andreas Schneider
632cee4426 server: Fixed a possible NULL pointer dereference.
(cherry picked from commit 7e4916cefc)
2011-04-14 10:18:34 +02:00
Oliver Stöneberg
af25fc35d1 build: Fixed some VS2010 problems.
(cherry picked from commit 166ee451c5)
2011-04-11 11:19:26 +02:00
Oliver Stöneberg
db49b84a44 keys: Fixed issues reported by cppcheck.
(cherry picked from commit 46475dfa2f)
2011-04-11 11:19:18 +02:00
Andreas Schneider
c5f4b8c1c7 cmake: Fixed a typo.
(cherry picked from commit 7150cabafa)
2011-04-08 11:06:16 +02:00
Mark Riordan
6a0daddd8f sftp: Fixed double-free in sftp_unlink().
(cherry picked from commit 29bb718a93)
2011-04-08 11:00:04 +02:00
Aris Adamantiadis
af997b221d Fixed doc of ssh_userauth_list()
(cherry picked from commit 1c062b22bf)
2011-03-28 13:36:51 +02:00
Aris Adamantiadis
9d6855702e Change session state after receiving a Disconnect
(cherry picked from commit 4bc9c96e4e)
2011-03-28 13:36:44 +02:00
Andreas Schneider
daf256e15f cpack: Raise version number. 2011-03-23 08:51:06 +01:00
Aris Adamantiadis
0eddcb4424 Fix the ssh_message_retrieve problem by anihilation 2011-03-23 08:49:34 +01:00
Aris Adamantiadis
b7f6794e03 Implement ssh_blocking_flush()
Based on code from Jan Willamowius
(cherry picked from commit dff4e4e6d3)
2011-03-23 08:49:26 +01:00
Andreas Schneider
cd9fc88151 doc: Improve the doc of ssh_bind_set_callbacks.
(cherry picked from commit 7daa81f3aa)
2011-03-09 18:33:49 +01:00
Andreas Schneider
fbe0f37e1b doc: Improved documentation for server options.
(cherry picked from commit 6754c34711)
2011-03-09 18:33:42 +01:00
Andreas Schneider
c496194614 messages: Added missing config.h include. 2011-03-01 14:08:01 +01:00
Andreas Schneider
ca639ceb63 legacy: Added missing channel_write_stderr. 2011-02-23 12:39:25 +01:00
Andreas Schneider
e85537aac4 legacy: Fixed the symbol export. 2011-02-23 12:32:02 +01:00
milo
e839c9cae6 Reverse commit 076dfb82 for the server side
(cherry picked from commit 32e23a25da)
2011-02-19 10:38:15 +01:00
Andreas Schneider
100e94c18e channel: Fixed uninitialized use of session. 2011-02-19 10:24:57 +01:00
Andreas Schneider
e7f7b4e499 server: Fixed logging function name.
(cherry picked from commit ac8276c70e)
2011-02-18 20:57:37 +01:00
Bernhard R. Link
eca8b53868 channel: Improve ssh_channel_open_reverse_forward documentation.
(cherry picked from commit 23b3c46fd6)
2011-02-18 18:01:45 +01:00
Andreas Schneider
b8767be373 channels: set error for new NULL pointer checks
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 8a83990c16)
2011-02-18 18:01:45 +01:00
Bernhard R. Link
9658eade0b socket: Set errors on return.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 071b0034db)
2011-02-18 17:54:43 +01:00
Bernhard R. Link
689536ec92 channels: Set errors on return.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 7ae59c571a)
2011-02-18 17:54:34 +01:00
Bernhard R. Link
3ff2999228 bind: Set errors on return.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit b1db0e54ad)
2011-02-18 17:54:28 +01:00
Andreas Schneider
4f65104ecc misc: Fixed ssh_is_ipaddr_v4() on Windows.
(cherry picked from commit eea1df3574)
2011-02-13 17:39:18 +01:00
Andreas Schneider
242e1c342c build: Try to fix the build on Solaris.
(cherry picked from commit 9baa491b0b)
2011-02-13 17:39:11 +01:00
Andreas Schneider
935e3b70ae misc: Added working ssh_is_ipaddr for Windows.
(cherry picked from commit cd30a1d4b1)
2011-02-13 12:30:52 +01:00
Andreas Schneider
8d1bfb5a85 tests: Fixed misc and isipaddr test on Windows.
(cherry picked from commit ca941d6985)
2011-02-13 12:30:46 +01:00
Andreas Schneider
2ac664968d torture: Fixed torture on Windows.
(cherry picked from commit cbcd5668f5)
2011-02-13 12:30:33 +01:00
Andreas Schneider
1199ad8f47 misc: Fixed ssh_is_ipaddr on FreeBSD.
(cherry picked from commit d1ddec00d9)
2011-02-13 12:30:17 +01:00
Bernhard R. Link
c12559f8f6 always set error when returning error in auth.c
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 637fc7ea59)
2011-02-12 20:15:07 +01:00
Andreas Schneider
840e1abcdc tests: Added ipv6 tests.
(cherry picked from commit 5d4bd5a21d)
2011-02-12 19:22:02 +01:00
Andreas Schneider
e3594ba0ec tests: Fixed torture_isipaddr.
(cherry picked from commit e8c3f55751)
2011-02-12 19:22:02 +01:00
Andreas Schneider
0d07dc5355 srv_sftp: Set error messages in sftp_get_client_message().
(cherry picked from commit 4d38b4c848)
2011-02-12 19:22:01 +01:00
Andreas Schneider
4170258595 connect: Use ssh_is_ipaddr instead of regex.
(cherry picked from commit 768fbdd92e)
2011-02-12 19:22:01 +01:00
Andreas Schneider
dacfc41d21 misc: Added ssh_is_ipaddr() function.
(cherry picked from commit b313fa944a)
2011-02-12 19:22:01 +01:00
Aris Adamantiadis
5158877b72 Connect: Test the new isipaddr() function
(cherry picked from commit 7acc2fa607)
2011-02-12 19:21:42 +01:00
Bernhard R. Link
a785ba3c4d 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>
(cherry picked from commit 8d9d46ca66)
2011-02-12 19:21:17 +01:00
Bernhard R. Link
92dbd4eca2 ssh_connect_host_nonblocking returns SSH_EINTR, not E_INTR, so update documentation
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 8e0e4d8fb3)
2011-02-12 19:21:16 +01:00
Bernhard R. Link
a7144c5b6b proper prototypes
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 8b51d29363)
2011-02-12 19:21:16 +01:00
189 changed files with 10079 additions and 26047 deletions

View File

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

2
.gitignore vendored
View File

@@ -1,5 +1,3 @@
*.a
*.o
.* .*
*.swp *.swp
*~$ *~$

View File

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

View File

@@ -7,8 +7,8 @@ cmake_minimum_required(VERSION 2.6.0)
set(APPLICATION_NAME ${PROJECT_NAME}) set(APPLICATION_NAME ${PROJECT_NAME})
set(APPLICATION_VERSION_MAJOR "0") set(APPLICATION_VERSION_MAJOR "0")
set(APPLICATION_VERSION_MINOR "6") set(APPLICATION_VERSION_MINOR "5")
set(APPLICATION_VERSION_PATCH "1") set(APPLICATION_VERSION_PATCH "3")
set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}") set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")
@@ -19,7 +19,7 @@ set(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINO
# Increment AGE. Set REVISION to 0 # Increment AGE. Set REVISION to 0
# If the source code was changed, but there were no interface changes: # If the source code was changed, but there were no interface changes:
# Increment REVISION. # Increment REVISION.
set(LIBRARY_VERSION "4.4.0") set(LIBRARY_VERSION "4.2.3")
set(LIBRARY_SOVERSION "4") set(LIBRARY_SOVERSION "4")
# where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked # where to look first for cmake modules, before ${CMAKE_ROOT}/Modules/ is checked
@@ -39,13 +39,17 @@ include(CPackConfig.cmake)
include(MacroEnsureOutOfSourceBuild) 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.") 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 # search for libraries
if (WITH_ZLIB) if (WITH_LIBZ)
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)
endif (WITH_ZLIB) endif (WITH_LIBZ)
if (WITH_GCRYPT) if (WITH_GCRYPT)
find_package(GCrypt 1.5.0 REQUIRED) find_package(GCrypt REQUIRED)
if (NOT GCRYPT_FOUND) if (NOT GCRYPT_FOUND)
message(FATAL_ERROR "Could not find GCrypt") message(FATAL_ERROR "Could not find GCrypt")
endif (NOT GCRYPT_FOUND) endif (NOT GCRYPT_FOUND)
@@ -63,17 +67,6 @@ endif(WITH_GCRYPT)
set(CMAKE_THREAD_PREFER_PTHREADS ON) set(CMAKE_THREAD_PREFER_PTHREADS ON)
find_package(Threads) 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 # config.h checks
include(ConfigureChecks.cmake) include(ConfigureChecks.cmake)
configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
@@ -96,29 +89,11 @@ install(
pkgconfig pkgconfig
) )
# cmake config files add_subdirectory(examples)
configure_file(libssh-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libssh-config.cmake @ONLY)
configure_file(libssh-config-version.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/libssh-config-version.cmake @ONLY)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/libssh-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/libssh-config-version.cmake
DESTINATION
${CMAKE_INSTALL_DIR}
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) if (WITH_TESTING)
find_package(CMocka REQUIRED) find_package(CMockery REQUIRED)
include(AddCMockaTest) include(AddCMockeryTest)
add_subdirectory(tests) add_subdirectory(tests)
endif (WITH_TESTING) endif (WITH_TESTING)
@@ -126,15 +101,12 @@ endif (WITH_TESTING)
message(STATUS "********************************************") message(STATUS "********************************************")
message(STATUS "********** ${PROJECT_NAME} build options : **********") message(STATUS "********** ${PROJECT_NAME} build options : **********")
message(STATUS "zlib support: ${WITH_ZLIB}") message(STATUS "zlib support: ${WITH_LIBZ}")
message(STATUS "libgcrypt support: ${WITH_GCRYPT}") message(STATUS "libgcrypt support: ${WITH_GCRYPT}")
message(STATUS "libnacl support: ${WITH_NACL}")
message(STATUS "SSH-1 support: ${WITH_SSH1}") message(STATUS "SSH-1 support: ${WITH_SSH1}")
message(STATUS "SFTP support: ${WITH_SFTP}") message(STATUS "SFTP support: ${WITH_SFTP}")
message(STATUS "Server support : ${WITH_SERVER}") message(STATUS "Server support : ${WITH_SERVER}")
message(STATUS "GSSAPI support : ${WITH_GSSAPI}")
message(STATUS "Pcap debugging support : ${WITH_PCAP}") message(STATUS "Pcap debugging support : ${WITH_PCAP}")
message(STATUS "With static library: ${WITH_STATIC_LIB}")
message(STATUS "Unit testing: ${WITH_TESTING}") message(STATUS "Unit testing: ${WITH_TESTING}")
message(STATUS "Client code Unit testing: ${WITH_CLIENT_TESTING}") message(STATUS "Client code Unit testing: ${WITH_CLIENT_TESTING}")
if (WITH_INTERNAL_DOC) if (WITH_INTERNAL_DOC)

View File

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

View File

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

View File

@@ -1,50 +1,6 @@
ChangeLog ChangeLog
========== ==========
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) version 0.5.3 (released 2012-11-20)
* CVE-2012-4559 Fixed multiple double free() flaws. * CVE-2012-4559 Fixed multiple double free() flaws.
* CVE-2012-4560 Fixed multiple buffer overflow flaws. * CVE-2012-4560 Fixed multiple buffer overflow flaws.

View File

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

View File

@@ -36,12 +36,7 @@ endfunction()
if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2) if(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
compiler_dumpversion(GNUCC_VERSION) compiler_dumpversion(GNUCC_VERSION)
if (NOT GNUCC_VERSION EQUAL 34) if (NOT GNUCC_VERSION EQUAL 34)
set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden") check_c_compiler_flag("-fvisibility=hidden" WITH_VISIBILITY_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 (NOT GNUCC_VERSION EQUAL 34)
endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2) endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
@@ -49,15 +44,19 @@ endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2)
check_include_file(argp.h HAVE_ARGP_H) check_include_file(argp.h HAVE_ARGP_H)
check_include_file(pty.h HAVE_PTY_H) check_include_file(pty.h HAVE_PTY_H)
check_include_file(termios.h HAVE_TERMIOS_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)
if (WIN32) if (WIN32)
check_include_files("winsock2.h;ws2tcpip.h;wspiapi.h" HAVE_WSPIAPI_H) check_include_file(wspiapi.h HAVE_WSPIAPI_H)
if (NOT 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") message(STATUS "WARNING: Without wspiapi.h, this build will only work on Windows XP and newer versions")
endif (NOT HAVE_WSPIAPI_H) endif (NOT HAVE_WSPIAPI_H)
check_include_files("winsock2.h;ws2tcpip.h" HAVE_WS2TCPIP_H) check_include_file(ws2tcpip.h HAVE_WS2TCPIP_H)
if (HAVE_WSPIAPI_H OR HAVE_WS2TCPIP_H)
set(HAVE_GETADDRINFO TRUE)
set(HAVE_GETHOSTBYNAME TRUE)
endif (HAVE_WSPIAPI_H OR HAVE_WS2TCPIP_H)
set(HAVE_SELECT TRUE)
endif (WIN32) endif (WIN32)
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS}) set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
@@ -69,59 +68,21 @@ check_include_file(openssl/blowfish.h HAVE_OPENSSL_BLOWFISH_H)
set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS}) set(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIRS})
check_include_file(openssl/des.h HAVE_OPENSSL_DES_H) 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) if (CMAKE_HAVE_PTHREAD_H)
set(HAVE_PTHREAD_H 1) set(HAVE_PTHREAD_H 1)
endif (CMAKE_HAVE_PTHREAD_H) 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 # FUNCTIONS
check_function_exists(isblank HAVE_ISBLANK)
check_function_exists(strncpy HAVE_STRNCPY) check_function_exists(strncpy HAVE_STRNCPY)
check_function_exists(vsnprintf HAVE_VSNPRINTF) check_function_exists(vsnprintf HAVE_VSNPRINTF)
check_function_exists(snprintf HAVE_SNPRINTF) check_function_exists(snprintf HAVE_SNPRINTF)
check_function_exists(poll HAVE_POLL)
check_function_exists(select HAVE_SELECT)
check_function_exists(getaddrinfo HAVE_GETADDRINFO)
check_function_exists(ntohll HAVE_NTOHLL)
check_function_exists(htonll HAVE_HTONLL)
if (WIN32) if (WIN32)
check_function_exists(_strtoui64 HAVE__STRTOUI64)
check_function_exists(_vsnprintf_s HAVE__VSNPRINTF_S) check_function_exists(_vsnprintf_s HAVE__VSNPRINTF_S)
check_function_exists(_vsnprintf HAVE__VSNPRINTF) check_function_exists(_vsnprintf HAVE__VSNPRINTF)
check_function_exists(_snprintf HAVE__SNPRINTF) check_function_exists(_snprintf HAVE__SNPRINTF)
check_function_exists(_snprintf_s HAVE__SNPRINTF_S) check_function_exists(_snprintf_s HAVE__SNPRINTF_S)
if (HAVE_WSPIAPI_H OR HAVE_WS2TCPIP_H)
set(HAVE_GETADDRINFO TRUE)
set(HAVE_GETHOSTBYNAME TRUE)
if (MSVC)
set(HAVE_NTOHLL TRUE)
set(HAVE_HTONLL TRUE)
endif (MSVC)
endif (HAVE_WSPIAPI_H OR HAVE_WS2TCPIP_H)
set(HAVE_SELECT TRUE)
endif (WIN32) endif (WIN32)
if (UNIX) if (UNIX)
@@ -129,10 +90,15 @@ if (UNIX)
# libsocket (Solaris) # libsocket (Solaris)
check_library_exists(socket getaddrinfo "" HAVE_LIBSOCKET) check_library_exists(socket getaddrinfo "" HAVE_LIBSOCKET)
if (HAVE_LIBSOCKET) if (HAVE_LIBSOCKET)
set(HAVE_GETADDRINFO TRUE) set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} socket)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} socket)
endif (HAVE_LIBSOCKET) endif (HAVE_LIBSOCKET)
# libresolv
check_library_exists(resolv hstrerror "" HAVE_LIBRESOLV)
if (HAVE_LIBRESOLV)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} resolv)
endif (HAVE_LIBRESOLV)
# libnsl/inet_pton (Solaris) # libnsl/inet_pton (Solaris)
check_library_exists(nsl inet_pton "" HAVE_LIBNSL) check_library_exists(nsl inet_pton "" HAVE_LIBNSL)
if (HAVE_LIBNSL) if (HAVE_LIBNSL)
@@ -148,10 +114,12 @@ if (UNIX)
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt) set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} rt)
endif (HAVE_LIBRT OR HAVE_CLOCK_GETTIME) endif (HAVE_LIBRT OR HAVE_CLOCK_GETTIME)
check_library_exists(util forkpty "" HAVE_LIBUTIL) check_function_exists(getaddrinfo HAVE_GETADDRINFO)
check_function_exists(poll HAVE_POLL)
check_function_exists(select HAVE_SELECT)
check_function_exists(cfmakeraw HAVE_CFMAKERAW) check_function_exists(cfmakeraw HAVE_CFMAKERAW)
check_function_exists(strtoull HAVE_STRTOULL) check_function_exists(regcomp HAVE_REGCOMP)
check_function_exists(__strtoull HAVE___STRTOULL) check_function_exists(ntohll HAVE_NTOHLL)
endif (UNIX) endif (UNIX)
set(LIBSSH_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "libssh required system libraries") set(LIBSSH_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} CACHE INTERNAL "libssh required system libraries")
@@ -162,44 +130,20 @@ if (OPENSSL_FOUND)
endif (OPENSSL_FOUND) endif (OPENSSL_FOUND)
if (GCRYPT_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) endif (GCRYPT_FOUND)
if (CMAKE_USE_PTHREADS_INIT) if (ZLIB_LIBRARY)
set(HAVE_PTHREAD 1) set(HAVE_LIBZ 1)
endif (CMAKE_USE_PTHREADS_INIT) endif (ZLIB_LIBRARY)
if (CMAKE_HAVE_THREADS_LIBRARY)
if (CMAKE_USE_PTHREADS_INIT)
set(HAVE_PTHREAD 1)
endif (CMAKE_USE_PTHREADS_INIT)
endif (CMAKE_HAVE_THREADS_LIBRARY)
# OPTIONS # 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)
if (WITH_DEBUG_CRYPTO) if (WITH_DEBUG_CRYPTO)
set(DEBUG_CRYPTO 1) set(DEBUG_CRYPTO 1)
endif (WITH_DEBUG_CRYPTO) endif (WITH_DEBUG_CRYPTO)
@@ -208,10 +152,6 @@ if (WITH_DEBUG_CALLTRACE)
set(DEBUG_CALLTRACE 1) set(DEBUG_CALLTRACE 1)
endif (WITH_DEBUG_CALLTRACE) endif (WITH_DEBUG_CALLTRACE)
if (WITH_GSSAPI AND NOT GSSAPI_FOUND)
set(WITH_GSSAPI 0)
endif (WITH_GSSAPI AND NOT GSSAPI_FOUND)
# ENDIAN # ENDIAN
if (NOT WIN32) if (NOT WIN32)
test_big_endian(WORDS_BIGENDIAN) test_big_endian(WORDS_BIGENDIAN)

View File

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

27
INSTALL
View File

@@ -18,26 +18,16 @@ optional:
Note that these version numbers are version we know works correctly. If you 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. 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 ## Building
First, you need to configure the compilation, using CMake. Go inside the First, you need to configure the compilation, using CMake. Go inside the
`build` dir. Create it if it doesn't exist. `build` dir. Create it if it doesn't exist.
GNU/Linux, MacOS X, MSYS/MinGW: GNU/Linux and MacOS X:
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug .. cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug ..
make make
On Windows you should choose a makefile gernerator with -G or use
cmake-gui.exe ..
### CMake standard options ### CMake standard options
Here is a list of the most interesting options provided out of the box by Here is a list of the most interesting options provided out of the box by
CMake. CMake.
@@ -57,7 +47,7 @@ Options are defined in the following files:
They can be changed with the -D option: They can be changed with the -D option:
`cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug -DWITH_ZLIB=OFF ..` `cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug -DWITH_LIBZ=OFF ..`
### Browsing/editing CMake options ### Browsing/editing CMake options
@@ -69,17 +59,6 @@ and MacOS X).
- On Windows: run `cmakesetup` - On Windows: run `cmakesetup`
- On GNU/Linux and MacOS X: run `ccmake ..` - 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 ## Installing
If you want to install libssh after compilation run: If you want to install libssh after compilation run:
@@ -88,7 +67,7 @@ If you want to install libssh after compilation run:
## Running ## Running
The libssh binary can be found in the `build/src` directory. The libssh binary can be found in the `build/libssh` directory.
You can use `build/examples/samplessh` which is a sample client to You can use `build/examples/samplessh` which is a sample client to
test libssh on UNIX. test libssh on UNIX.

11
README
View File

@@ -1,12 +1,5 @@
_ _ _ _ libssh: the SSH library
(_) (_) (_) (_) ~~~~~~~~~~~~~~~~~~~~~~~
(_) _ (_) _ _ _ _ _ (_) _
(_) (_) (_)(_) _ (_)(_) (_)(_) (_)(_) _
(_) (_) (_) (_) _ (_) _ (_) (_) (_)
(_) (_) (_)(_)(_) (_)(_) (_)(_) (_) (_).org
The SSH library
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1* Why ? 1* Why ?
-_-_-_-_-_ -_-_-_-_-_

View File

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

View File

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

View File

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

View File

@@ -1,14 +1,13 @@
# define system dependent compiler flags # define system dependent compiler flags
include(CheckCCompilerFlag) include(CheckCCompilerFlag)
include(CheckCCompilerFlagSSP) include(MacroCheckCCompilerFlagSSP)
if (UNIX AND NOT WIN32) if (UNIX AND NOT WIN32)
# #
# Define GNUCC compiler flags # Define GNUCC compiler flags
# #
if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)") if (${CMAKE_C_COMPILER_ID} MATCHES GNU)
# add -Wconversion ? # add -Wconversion ?
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -pedantic -pedantic-errors") 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} -Wall -Wextra -Wshadow -Wmissing-prototypes -Wdeclaration-after-statement")
@@ -26,16 +25,11 @@ if (UNIX AND NOT WIN32)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstack-protector")
endif (WITH_STACK_PROTECTOR) endif (WITH_STACK_PROTECTOR)
if (CMAKE_BUILD_TYPE) check_c_compiler_flag("-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE)
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) if (WITH_FORTIFY_SOURCE)
if (CMAKE_BUILD_TYPE_LOWER MATCHES (release|relwithdebinfo|minsizerel)) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FORTIFY_SOURCE=2")
check_c_compiler_flag("-Wp,-D_FORTIFY_SOURCE=2" WITH_FORTIFY_SOURCE) endif (WITH_FORTIFY_SOURCE)
if (WITH_FORTIFY_SOURCE) endif (${CMAKE_C_COMPILER_ID} MATCHES GNU)
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 # Check for large filesystem support
@@ -75,10 +69,3 @@ if (MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT=1") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_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") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D _CRT_NONSTDC_NO_WARNINGS=1 /D _CRT_SECURE_NO_WARNINGS=1")
endif (MSVC) 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,15 @@
if (UNIX OR OS2) if (WIN32)
# Same same
set(BIN_INSTALL_DIR "bin" CACHE PATH "-")
set(SBIN_INSTALL_DIR "." CACHE PATH "-")
set(LIB_INSTALL_DIR "lib" CACHE PATH "-")
set(INCLUDE_INSTALL_DIR "include" CACHE PATH "-")
set(PLUGIN_INSTALL_DIR "plugins" CACHE PATH "-")
set(HTML_INSTALL_DIR "doc/HTML" CACHE PATH "-")
set(ICON_INSTALL_DIR "." CACHE PATH "-")
set(SOUND_INSTALL_DIR "." CACHE PATH "-")
set(LOCALE_INSTALL_DIR "lang" CACHE PATH "-")
elseif (UNIX OR OS2)
IF (NOT APPLICATION_NAME) IF (NOT APPLICATION_NAME)
MESSAGE(STATUS "${PROJECT_NAME} is used as APPLICATION_NAME") MESSAGE(STATUS "${PROJECT_NAME} is used as APPLICATION_NAME")
SET(APPLICATION_NAME ${PROJECT_NAME}) SET(APPLICATION_NAME ${PROJECT_NAME})
@@ -47,10 +58,6 @@ if (UNIX OR OS2)
CACHE PATH "The subdirectory to the header prefix (default prefix/include)" 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 SET(DATA_INSTALL_DIR
"${DATA_INSTALL_PREFIX}" "${DATA_INSTALL_PREFIX}"
CACHE PATH "The parent directory where applications can install their data (default prefix/share/${APPLICATION_NAME})" CACHE PATH "The parent directory where applications can install their data (default prefix/share/${APPLICATION_NAME})"
@@ -94,16 +101,4 @@ if (UNIX OR OS2)
"${SHARE_INSTALL_PREFIX}/info" "${SHARE_INSTALL_PREFIX}/info"
CACHE PATH "The ${APPLICATION_NAME} info install dir (default prefix/info)" CACHE PATH "The ${APPLICATION_NAME} info install dir (default prefix/info)"
) )
else()
# Same same
set(BIN_INSTALL_DIR "bin" CACHE PATH "-")
set(SBIN_INSTALL_DIR "sbin" CACHE PATH "-")
set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "-")
set(INCLUDE_INSTALL_DIR "include" CACHE PATH "-")
set(CMAKE_INSTALL_DIR "CMake" CACHE PATH "-")
set(PLUGIN_INSTALL_DIR "plugins" CACHE PATH "-")
set(HTML_INSTALL_DIR "doc/HTML" CACHE PATH "-")
set(ICON_INSTALL_DIR "icons" CACHE PATH "-")
set(SOUND_INSTALL_DIR "soudns" CACHE PATH "-")
set(LOCALE_INSTALL_DIR "lang" CACHE PATH "-")
endif () endif ()

View File

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

View File

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

View File

@@ -1,66 +0,0 @@
# - 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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,21 @@
# - 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

@@ -0,0 +1,20 @@
# - 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

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

@@ -0,0 +1,33 @@
# - 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

@@ -23,7 +23,7 @@
# #
# Copyright (c) 2009-2010 Tobias Rautenkranz <tobias@rautenkranz.ch> # Copyright (c) 2009-2010 Tobias Rautenkranz <tobias@rautenkranz.ch>
# Copyright (c) 2010 Andreas Schneider <asn@cryptomilk.org> # Copyright (c) 2010 Andreas Schneider <mail@cynapses.org>
# #
# Redistribution and use is allowed according to the terms of the New # Redistribution and use is allowed according to the terms of the New
# BSD license. # BSD license.
@@ -63,27 +63,27 @@ if(DOXYGEN_FOUND AND DOXYFILE_IN_FOUND)
set(DOXYFILE_PDFLATEX FALSE) set(DOXYFILE_PDFLATEX FALSE)
set(DOXYFILE_DOT FALSE) set(DOXYFILE_DOT FALSE)
#find_package(LATEX) find_package(LATEX)
#if(LATEX_COMPILER AND MAKEINDEX_COMPILER) if(LATEX_COMPILER AND MAKEINDEX_COMPILER)
# set(DOXYFILE_LATEX TRUE) set(DOXYFILE_LATEX TRUE)
# usedoxygen_set_default(DOXYFILE_LATEX_DIR "latex") usedoxygen_set_default(DOXYFILE_LATEX_DIR "latex")
#
# set_property(DIRECTORY APPEND PROPERTY set_property(DIRECTORY APPEND PROPERTY
# ADDITIONAL_MAKE_CLEAN_FILES ADDITIONAL_MAKE_CLEAN_FILES
# "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}") "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}")
#
# if(PDFLATEX_COMPILER) if(PDFLATEX_COMPILER)
# set(DOXYFILE_PDFLATEX TRUE) set(DOXYFILE_PDFLATEX TRUE)
# endif() endif()
# if(DOXYGEN_DOT_EXECUTABLE) if(DOXYGEN_DOT_EXECUTABLE)
# set(DOXYFILE_DOT TRUE) set(DOXYFILE_DOT TRUE)
# endif() endif()
#
# add_custom_command(TARGET doxygen add_custom_command(TARGET doxygen
# POST_BUILD POST_BUILD
# COMMAND ${CMAKE_MAKE_PROGRAM} COMMAND ${CMAKE_MAKE_PROGRAM}
# WORKING_DIRECTORY "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}") WORKING_DIRECTORY "${DOXYFILE_OUTPUT_DIR}/${DOXYFILE_LATEX_DIR}")
#endif() endif()
configure_file(${DOXYFILE_IN} ${CMAKE_CURRENT_BINARY_DIR}/doxy.config ESCAPE_QUOTES IMMEDIATE @ONLY) configure_file(${DOXYFILE_IN} ${CMAKE_CURRENT_BINARY_DIR}/doxy.config ESCAPE_QUOTES IMMEDIATE @ONLY)
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/doxy.trac.in) if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/doxy.trac.in)

View File

@@ -20,15 +20,9 @@
/* Define to 1 if you have the <pty.h> header file. */ /* Define to 1 if you have the <pty.h> header file. */
#cmakedefine HAVE_PTY_H 1 #cmakedefine HAVE_PTY_H 1
/* Define to 1 if you have the <util.h> header file. */
#cmakedefine HAVE_UTIL_H 1
/* Define to 1 if you have the <termios.h> header file. */ /* Define to 1 if you have the <termios.h> header file. */
#cmakedefine HAVE_TERMIOS_H 1 #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. */ /* Define to 1 if you have the <openssl/aes.h> header file. */
#cmakedefine HAVE_OPENSSL_AES_H 1 #cmakedefine HAVE_OPENSSL_AES_H 1
@@ -41,26 +35,9 @@
/* Define to 1 if you have the <openssl/des.h> header file. */ /* Define to 1 if you have the <openssl/des.h> header file. */
#cmakedefine HAVE_OPENSSL_DES_H 1 #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. */ /* Define to 1 if you have the <pthread.h> header file. */
#cmakedefine HAVE_PTHREAD_H 1 #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 ***************************/ /*************************** FUNCTIONS ***************************/
@@ -82,9 +59,6 @@
/* Define to 1 if you have the `_vsnprintf_s' function. */ /* Define to 1 if you have the `_vsnprintf_s' function. */
#cmakedefine HAVE__VSNPRINTF_S 1 #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. */ /* Define to 1 if you have the `strncpy' function. */
#cmakedefine HAVE_STRNCPY 1 #cmakedefine HAVE_STRNCPY 1
@@ -100,24 +74,15 @@
/* Define to 1 if you have the `select' function. */ /* Define to 1 if you have the `select' function. */
#cmakedefine HAVE_SELECT 1 #cmakedefine HAVE_SELECT 1
/* Define to 1 if you have the `regcomp' function. */
#cmakedefine HAVE_REGCOMP 1
/* Define to 1 if you have the `clock_gettime' function. */ /* Define to 1 if you have the `clock_gettime' function. */
#cmakedefine HAVE_CLOCK_GETTIME 1 #cmakedefine HAVE_CLOCK_GETTIME 1
/* Define to 1 if you have the `ntohll' function. */ /* Define to 1 if you have the `ntohll' function. */
#cmakedefine HAVE_NTOHLL 1 #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 ***************************/ /*************************** LIBRARIES ***************************/
/* Define to 1 if you have the `crypto' library (-lcrypto). */ /* Define to 1 if you have the `crypto' library (-lcrypto). */
@@ -126,21 +91,17 @@
/* Define to 1 if you have the `gcrypt' library (-lgcrypt). */ /* Define to 1 if you have the `gcrypt' library (-lgcrypt). */
#cmakedefine HAVE_LIBGCRYPT 1 #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). */ /* Define to 1 if you have the `pthread' library (-lpthread). */
#cmakedefine HAVE_PTHREAD 1 #cmakedefine HAVE_PTHREAD 1
/**************************** OPTIONS ****************************/ /**************************** OPTIONS ****************************/
#cmakedefine HAVE_GCC_THREAD_LOCAL_STORAGE 1
#cmakedefine HAVE_MSC_THREAD_LOCAL_STORAGE 1
#cmakedefine HAVE_GCC_VOLATILE_MEMORY_PROTECTION 1
/* Define to 1 if you want to enable GSSAPI */
#cmakedefine WITH_GSSAPI 1
/* Define to 1 if you want to enable ZLIB */ /* Define to 1 if you want to enable ZLIB */
#cmakedefine WITH_ZLIB 1 #cmakedefine WITH_LIBZ 1
/* Define to 1 if you want to enable SFTP */ /* Define to 1 if you want to enable SFTP */
#cmakedefine WITH_SFTP 1 #cmakedefine WITH_SFTP 1
@@ -160,9 +121,6 @@
/* Define to 1 if you want to enable calltrace debug output */ /* Define to 1 if you want to enable calltrace debug output */
#cmakedefine DEBUG_CALLTRACE 1 #cmakedefine DEBUG_CALLTRACE 1
/* Define to 1 if you want to enable NaCl support */
#cmakedefine WITH_NACL 1
/*************************** ENDIAN *****************************/ /*************************** ENDIAN *****************************/
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most

1
doc/TracFooter.html Normal file
View File

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

4
doc/TracHeader.html Normal file
View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@@ -17,14 +17,8 @@ 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 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. 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 On Windows you need to define LIBSSH_STATIC in the compiler command
LIBSSH_STATIC as a define in the compiler command line or define it before you line. This is required cause the dynamic library needs to specify the
include libssh.h. This is required cause the dynamic library needs to specify dllimport attribute.
the dllimport attribute.
@code
#define LIBSSH_STATIC 1
#include <libssh/libssh.h>
@endcode
*/ */

View File

@@ -19,29 +19,24 @@ the interesting functions as you go.
The libssh library provides: The libssh library provides:
- <strong>Key Exchange Methods</strong>: <i>ecdh-sha2-nistp256</i>, diffie-hellman-group1-sha1, diffie-hellman-group14-sha1 - Full C library functions for manipulating a client-side SSH connection
- <strong>Hostkey Types</strong>: <i>ecdsa-sha2-nistp256</i>, ssh-dss, ssh-rsa - SSH2 and SSH1 protocol compliant
- <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 - Fully configurable sessions
- <strong>Compression Schemes</strong>: zlib, <i>zlib@openssh.com</i>, none - Server support
- <strong>MAC hashes</strong>: hmac-sha1, none - SSH agent authentication support
- <strong>Authentication</strong>: none, password, public-key, hostbased, keyboard-interactive, <i>gssapi-with-mic</i> - Support for AES-128, AES-192, AES-256, Blowfish, 3DES in CBC mode, and AES in CTR mode
- <strong>Channels</strong>: shell, exec (incl. SCP wrapper), direct-tcpip, subsystem, <i>auth-agent-req@openssh.com</i> - Supports OpenSSL and GCrypt
- <strong>Global Requests</strong>: tcpip-forward, forwarded-tcpip - Use multiple SSH connections in a same process, at same time
- <strong>Channel Requests</strong>: x11, pty, <i>exit-status, signal, exit-signal, keepalive@openssh.com, auth-agent-req@openssh.com</i> - Use multiple channels in the same connection
- <strong>Subsystems</strong>: sftp(version 3), publickey(version 2), <i>OpenSSH Extensions</i> - Thread safety when using different sessions at same time
- <strong>SFTP</strong>: <i>statvfs@openssh.com, fstatvfs@openssh.com</i> - POSIX-like SFTP (Secure File Transfer) implementation with openssh extension support
- <strong>Thread-safe</strong>: Just don't share sessions - SCP implementation
- <strong>Non-blocking</strong>: it can be used both blocking and non-blocking - Large file system support (files bigger than 4GB)
- <strong>Your sockets</strong>: the app hands over the socket, or uses libssh sockets - RSA and DSS server public key supported
- <b>OpenSSL</b> or <b>gcrypt</b>: builds with either - Compression support (with zlib)
- Public key (RSA and DSS), password and keyboard-interactive authentication
@section main-additional-features Additional Features - Full poll()/WSAPoll() support and a poll-emulation for Win32.
- Runs and tested under x86_64, x86, ARM, Sparc32, PPC under Linux, BSD, MacOSX, Solaris and Windows
- 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 @section main-copyright Copyright Policy
@@ -210,7 +205,5 @@ them like the statvfs calls in SFTP or the ssh-agent.
OpenSSH's deviations and extensions</a> OpenSSH's deviations and extensions</a>
- <a href="http://api.libssh.org/rfc/PROTOCOL.agent" target="_blank"> - <a href="http://api.libssh.org/rfc/PROTOCOL.agent" target="_blank">
OpenSSH's ssh-agent</a> OpenSSH's ssh-agent</a>
- <a href="http://api.libssh.org/rfc/PROTOCOL.certkeys" target="_blank">
OpenSSH's pubkey certificate authentication</a>
*/ */

View File

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

View File

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

View File

@@ -61,6 +61,5 @@ implement the following methods :
- mutex_destroy - mutex_destroy
- thread_id - 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 ! Good luck !
*/ */

View File

@@ -11,52 +11,29 @@ include_directories(
${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}
) )
if (BSD OR SOLARIS OR OSX) if (LINUX)
find_package(Argp)
endif (BSD OR SOLARIS OR OSX)
if (UNIX AND NOT WIN32)
add_executable(libssh_scp libssh_scp.c ${examples_SRCS}) add_executable(libssh_scp libssh_scp.c ${examples_SRCS})
target_link_libraries(libssh_scp ${LIBSSH_SHARED_LIBRARY}) target_link_libraries(libssh_scp ${LIBSSH_SHARED_LIBRARY})
add_executable(scp_download scp_download.c ${examples_SRCS}) add_executable(scp_download scp_download.c ${examples_SRCS})
target_link_libraries(scp_download ${LIBSSH_SHARED_LIBRARY}) target_link_libraries(scp_download ${LIBSSH_SHARED_LIBRARY})
add_executable(samplessh sample.c ${examples_SRCS})
target_link_libraries(samplessh ${LIBSSH_SHARED_LIBRARY})
add_executable(sshnetcat sshnetcat.c ${examples_SRCS}) add_executable(sshnetcat sshnetcat.c ${examples_SRCS})
target_link_libraries(sshnetcat ${LIBSSH_SHARED_LIBRARY}) target_link_libraries(sshnetcat ${LIBSSH_SHARED_LIBRARY})
if (WITH_SERVER)
if (HAVE_LIBUTIL)
add_executable(samplesshd-tty samplesshd-tty.c)
target_link_libraries(samplesshd-tty ${LIBSSH_SHARED_LIBRARY} ${ARGP_LIBRARIES} util)
endif (HAVE_LIBUTIL)
endif (WITH_SERVER)
if (WITH_SFTP) if (WITH_SFTP)
add_executable(samplesftp samplesftp.c ${examples_SRCS}) add_executable(samplesftp samplesftp.c ${examples_SRCS})
target_link_libraries(samplesftp ${LIBSSH_SHARED_LIBRARY}) target_link_libraries(samplesftp ${LIBSSH_SHARED_LIBRARY})
endif (WITH_SFTP) endif (WITH_SFTP)
add_executable(samplessh sample.c ${examples_SRCS})
target_link_libraries(samplessh ${LIBSSH_SHARED_LIBRARY})
if (WITH_SERVER) if (WITH_SERVER)
add_executable(samplesshd samplesshd.c) add_executable(samplesshd samplesshd.c)
target_link_libraries(samplesshd ${LIBSSH_SHARED_LIBRARY} ${ARGP_LIBRARIES}) target_link_libraries(samplesshd ${LIBSSH_SHARED_LIBRARY})
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 (WITH_SERVER)
endif (UNIX AND NOT WIN32) endif (LINUX)
add_executable(exec exec.c ${examples_SRCS}) add_executable(exec exec.c ${examples_SRCS})
target_link_libraries(exec ${LIBSSH_SHARED_LIBRARY}) target_link_libraries(exec ${LIBSSH_SHARED_LIBRARY})

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,306 +0,0 @@
/* 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

@@ -1,413 +0,0 @@
/* 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;
}

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,23 +1,3 @@
/*
* 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 #ifndef __AGENT_H
#define __AGENT_H #define __AGENT_H
@@ -71,7 +51,6 @@ struct ssh_agent_struct {
struct ssh_socket_struct *sock; struct ssh_socket_struct *sock;
ssh_buffer ident; ssh_buffer ident;
unsigned int count; unsigned int count;
ssh_channel channel;
}; };
#ifndef _WIN32 #ifndef _WIN32
@@ -101,17 +80,17 @@ void agent_free(struct ssh_agent_struct *agent);
*/ */
int agent_is_running(struct ssh_session_struct *session); int agent_is_running(struct ssh_session_struct *session);
int ssh_agent_get_ident_count(struct ssh_session_struct *session); int agent_get_ident_count(struct ssh_session_struct *session);
ssh_key ssh_agent_get_next_ident(struct ssh_session_struct *session, struct ssh_public_key_struct *agent_get_next_ident(struct ssh_session_struct *session,
char **comment); char **comment);
ssh_key ssh_agent_get_first_ident(struct ssh_session_struct *session, struct ssh_public_key_struct *agent_get_first_ident(struct ssh_session_struct *session,
char **comment); char **comment);
ssh_string ssh_agent_sign_data(ssh_session session, ssh_string agent_sign_data(struct ssh_session_struct *session,
const ssh_key pubkey, struct ssh_buffer_struct *data,
struct ssh_buffer_struct *data); struct ssh_public_key_struct *pubkey);
#endif #endif
#endif /* __AGENT_H */ #endif /* __AGENT_H */

View File

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

View File

@@ -3,19 +3,20 @@
* *
* Copyright (c) 2010 by Aris Adamantiadis * Copyright (c) 2010 by Aris Adamantiadis
* *
* This library is free software; you can redistribute it and/or * The SSH Library is free software; you can redistribute it and/or modify
* modify it under the terms of the GNU Lesser General Public * it under the terms of the GNU Lesser General Public License as published by
* License as published by the Free Software Foundation; either * the Free Software Foundation; either version 2.1 of the License, or (at your
* version 2.1 of the License, or (at your option) any later version. * option) any later version.
* *
* This library is distributed in the hope that it will be useful, * The SSH Library is distributed in the hope that it will be useful, but
* but WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* Lesser General Public License for more details. * License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public License
* License along with this library; if not, write to the Free Software * along with the SSH Library; see the file COPYING. If not, write to
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/ */
#ifndef BIND_H_ #ifndef BIND_H_
@@ -33,12 +34,8 @@ struct ssh_bind_struct {
/* options */ /* options */
char *wanted_methods[10]; char *wanted_methods[10];
char *banner; char *banner;
char *ecdsakey;
char *dsakey; char *dsakey;
char *rsakey; char *rsakey;
ssh_key ecdsa;
ssh_key dsa;
ssh_key rsa;
char *bindaddr; char *bindaddr;
socket_t bindfd; socket_t bindfd;
unsigned int bindport; unsigned int bindport;

View File

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

View File

@@ -3,19 +3,20 @@
* *
* Copyright (c) 2009 Aris Adamantiadis <aris@0xbadc0de.be> * Copyright (c) 2009 Aris Adamantiadis <aris@0xbadc0de.be>
* *
* This library is free software; you can redistribute it and/or * The SSH Library is free software; you can redistribute it and/or modify
* modify it under the terms of the GNU Lesser General Public * it under the terms of the GNU Lesser General Public License as published by
* License as published by the Free Software Foundation; either * the Free Software Foundation; either version 2.1 of the License, or (at your
* version 2.1 of the License, or (at your option) any later version. * option) any later version.
* *
* This library is distributed in the hope that it will be useful, * The SSH Library is distributed in the hope that it will be useful, but
* but WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* Lesser General Public License for more details. * License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public License
* License along with this library; if not, write to the Free Software * along with the SSH Library; see the file COPYING. If not, write to
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/ */
/* callback.h /* callback.h
@@ -63,7 +64,22 @@ 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_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_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); typedef int (*ssh_channel_callback_data) (ssh_channel channel, int code, void *data, size_t len, void *user);
/**
* @brief SSH authentication callback.
*
* @param prompt Prompt to be displayed.
* @param buf Buffer to save the password. You should null-terminate it.
* @param len Length of the buffer.
* @param echo Enable or disable the echo of what you type.
* @param verify Should the password be verified?
* @param userdata Userdata to be passed to the callback function. Useful
* for GUI applications.
*
* @return 0 on success, < 0 on error.
*/
typedef int (*ssh_auth_callback) (const char *prompt, char *buf, size_t len,
int echo, int verify, void *userdata);
/** /**
* @brief SSH log callback. All logging messages will go through this callback * @brief SSH log callback. All logging messages will go through this callback
* @param session Current session handler * @param session Current session handler
@@ -74,24 +90,6 @@ typedef int (*ssh_channel_callback_data) (ssh_channel channel, int code, void *d
typedef void (*ssh_log_callback) (ssh_session session, int priority, typedef void (*ssh_log_callback) (ssh_session session, int priority,
const char *message, void *userdata); 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. * @brief SSH Connection status callback.
* @param session Current session handler * @param session Current session handler
@@ -112,18 +110,6 @@ typedef void (*ssh_status_callback) (ssh_session session, float status,
typedef void (*ssh_global_request_callback) (ssh_session session, typedef void (*ssh_global_request_callback) (ssh_session session,
ssh_message message, void *userdata); 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. * The structure to replace libssh functions with appropriate callbacks.
*/ */
@@ -151,211 +137,9 @@ struct ssh_callbacks_struct {
* This function will be called each time a global request is received. * This function will be called each time a global request is received.
*/ */
ssh_global_request_callback global_request_function; 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; 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 * These are the callbacks exported by the socket structure
* They are called by the socket module when a socket event appears * They are called by the socket module when a socket event appears
@@ -495,8 +279,6 @@ LIBSSH_API int ssh_set_callbacks(ssh_session session, ssh_callbacks cb);
* @param len the length of the data * @param len the length of the data
* @param is_stderr is 0 for stdout or 1 for stderr * @param is_stderr is 0 for stdout or 1 for stderr
* @param userdata Userdata to be passed to the callback function. * @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, typedef int (*ssh_channel_data_callback) (ssh_session session,
ssh_channel channel, ssh_channel channel,
@@ -566,120 +348,6 @@ typedef void (*ssh_channel_exit_signal_callback) (ssh_session session,
const char *lang, const char *lang,
void *userdata); 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 { struct ssh_channel_callbacks_struct {
/** DON'T SET THIS use ssh_callbacks_init() instead. */ /** DON'T SET THIS use ssh_callbacks_init() instead. */
size_t size; size_t size;
@@ -711,40 +379,7 @@ struct ssh_channel_callbacks_struct {
* This functions will be called when an exit signal has been received * This functions will be called when an exit signal has been received
*/ */
ssh_channel_exit_signal_callback channel_exit_signal_function; 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; typedef struct ssh_channel_callbacks_struct *ssh_channel_callbacks;
/** /**
@@ -790,21 +425,14 @@ struct ssh_threads_callbacks_struct {
}; };
/** /**
* @brief Set the thread callbacks structure. * @brief sets the thread callbacks necessary if your program is using
* * libssh in a multithreaded fashion. This function must be called first,
* This is necessary if your program is using libssh in a multithreaded fashion. * outside of any threading context (in your main() for instance), before
* This function must be called first, outside of any threading context (in your * ssh_init().
* main() function for instance), before you call ssh_init(). * @param cb pointer to a ssh_threads_callbacks_struct structure, which contains
* * the different callbacks to be set.
* @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_callbacks_struct
* @see SSH_THREADS_PTHREAD * @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 LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct
*cb); *cb);
@@ -818,33 +446,13 @@ LIBSSH_API int ssh_threads_set_callbacks(struct ssh_threads_callbacks_struct
LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_pthread(void); LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_pthread(void);
/** /**
* @brief Get the noop threads callbacks structure * @brief returns a pointer on the noop threads callbacks, to be used with
* * ssh_threads_set_callbacks. These callbacks do nothing and are being used by
* This can be used with ssh_threads_set_callbacks. These callbacks do nothing * default.
* and are being used by default.
*
* @return Always returns a valid pointer to the noop callbacks structure.
*
* @see ssh_threads_set_callbacks * @see ssh_threads_set_callbacks
*/ */
LIBSSH_API struct ssh_threads_callbacks_struct *ssh_threads_get_noop(void); 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 #ifdef __cplusplus
} }

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,43 +0,0 @@
/*
* 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_ */

View File

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

View File

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

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -4,19 +4,20 @@
* *
* Copyright (c) 2003-2008 by Aris Adamantiadis * Copyright (c) 2003-2008 by Aris Adamantiadis
* *
* This library is free software; you can redistribute it and/or * The SSH Library is free software; you can redistribute it and/or modify
* modify it under the terms of the GNU Lesser General Public * it under the terms of the GNU Lesser General Public License as published by
* License as published by the Free Software Foundation; either * the Free Software Foundation; either version 2.1 of the License, or (at your
* version 2.1 of the License, or (at your option) any later version. * option) any later version.
* *
* This library is distributed in the hope that it will be useful, * The SSH Library is distributed in the hope that it will be useful, but
* but WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* Lesser General Public License for more details. * License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public License
* License along with this library; if not, write to the Free Software * along with the SSH Library; see the file COPYING. If not, write to
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/ */
/** /**
@@ -55,6 +56,7 @@ typedef struct ssh_bind_struct* ssh_bind;
* @brief Incoming connection callback. This callback is called when a ssh_bind * @brief Incoming connection callback. This callback is called when a ssh_bind
* has a new incoming connection. * has a new incoming connection.
* @param sshbind Current sshbind session handler * @param sshbind Current sshbind session handler
* @param message the actual message
* @param userdata Userdata to be passed to the callback function. * @param userdata Userdata to be passed to the callback function.
*/ */
typedef void (*ssh_bind_incoming_connection_callback) (ssh_bind sshbind, typedef void (*ssh_bind_incoming_connection_callback) (ssh_bind sshbind,
@@ -222,23 +224,6 @@ LIBSSH_API void ssh_bind_fd_toaccept(ssh_bind ssh_bind_o);
*/ */
LIBSSH_API int ssh_bind_accept(ssh_bind ssh_bind_o, ssh_session session); LIBSSH_API int ssh_bind_accept(ssh_bind ssh_bind_o, ssh_session session);
/**
* @brief Accept an incoming ssh connection on the given file descriptor
* and initialize the session.
*
* @param ssh_bind_o The ssh server bind to accept a connection.
* @param session A preallocated ssh session
* @param fd A file descriptor of an already established TCP
* inbound connection
* @see ssh_new
* @see ssh_bind_accept
* @return SSH_OK when a connection is established
*/
LIBSSH_API int ssh_bind_accept_fd(ssh_bind ssh_bind_o, ssh_session session,
socket_t fd);
LIBSSH_API ssh_gssapi_creds ssh_gssapi_get_creds(ssh_session session);
/** /**
* @brief Handles the key exchange and set up encryption * @brief Handles the key exchange and set up encryption
* *
@@ -255,67 +240,12 @@ LIBSSH_API int ssh_handle_key_exchange(ssh_session session);
*/ */
LIBSSH_API void ssh_bind_free(ssh_bind ssh_bind_o); LIBSSH_API void ssh_bind_free(ssh_bind ssh_bind_o);
LIBSSH_API void ssh_set_auth_methods(ssh_session session, int auth_methods); /* messages.c */
/**********************************************************
* SERVER MESSAGING
**********************************************************/
/**
* @brief Reply with a standard reject message.
*
* Use this function if you don't know what to respond or if you want to reject
* a request.
*
* @param[in] msg The message to use for the reply.
*
* @return 0 on success, -1 on error.
*
* @see ssh_message_get()
*/
LIBSSH_API int ssh_message_reply_default(ssh_message msg); LIBSSH_API int ssh_message_reply_default(ssh_message msg);
/** LIBSSH_API char *ssh_message_auth_user(ssh_message msg);
* @brief Get the name of the authenticated user. LIBSSH_API char *ssh_message_auth_password(ssh_message msg);
* LIBSSH_API ssh_public_key ssh_message_auth_publickey(ssh_message msg);
* @param[in] msg The message to get the username from.
*
* @return The username or NULL if an error occured.
*
* @see ssh_message_get()
* @see ssh_message_type()
*/
LIBSSH_API const char *ssh_message_auth_user(ssh_message msg);
/**
* @brief Get the password of the authenticated user.
*
* @param[in] msg The message to get the password from.
*
* @return The username or NULL if an error occured.
*
* @see ssh_message_get()
* @see ssh_message_type()
*/
LIBSSH_API const char *ssh_message_auth_password(ssh_message msg);
/**
* @brief Get the publickey of the authenticated user.
*
* If you need the key for later user you should duplicate it.
*
* @param[in] msg The message to get the public key from.
*
* @return The public key or NULL.
*
* @see ssh_key_dup()
* @see ssh_key_cmp()
* @see ssh_message_get()
* @see ssh_message_type()
*/
LIBSSH_API ssh_key ssh_message_auth_pubkey(ssh_message msg);
LIBSSH_API int ssh_message_auth_kbdint_is_response(ssh_message msg);
LIBSSH_API enum ssh_publickey_state_e ssh_message_auth_publickey_state(ssh_message msg); LIBSSH_API enum ssh_publickey_state_e ssh_message_auth_publickey_state(ssh_message msg);
LIBSSH_API int ssh_message_auth_reply_success(ssh_message msg,int partial); LIBSSH_API int ssh_message_auth_reply_success(ssh_message msg,int partial);
LIBSSH_API int ssh_message_auth_reply_pk_ok(ssh_message msg, ssh_string algo, ssh_string pubkey); LIBSSH_API int ssh_message_auth_reply_pk_ok(ssh_message msg, ssh_string algo, ssh_string pubkey);
@@ -323,12 +253,8 @@ LIBSSH_API int ssh_message_auth_reply_pk_ok_simple(ssh_message msg);
LIBSSH_API int ssh_message_auth_set_methods(ssh_message msg, int methods); LIBSSH_API int ssh_message_auth_set_methods(ssh_message msg, int methods);
LIBSSH_API int ssh_message_auth_interactive_request(ssh_message msg,
const char *name, const char *instruction,
unsigned int num_prompts, const char **prompts, char *echo);
LIBSSH_API int ssh_message_service_reply_success(ssh_message msg); LIBSSH_API int ssh_message_service_reply_success(ssh_message msg);
LIBSSH_API const char *ssh_message_service_service(ssh_message msg); LIBSSH_API char *ssh_message_service_service(ssh_message msg);
LIBSSH_API int ssh_message_global_request_reply_success(ssh_message msg, LIBSSH_API int ssh_message_global_request_reply_success(ssh_message msg,
uint16_t bound_port); uint16_t bound_port);
@@ -338,38 +264,31 @@ LIBSSH_API void ssh_set_message_callback(ssh_session session,
void *data); void *data);
LIBSSH_API int ssh_execute_message_callbacks(ssh_session session); LIBSSH_API int ssh_execute_message_callbacks(ssh_session session);
LIBSSH_API const char *ssh_message_channel_request_open_originator(ssh_message msg); LIBSSH_API char *ssh_message_channel_request_open_originator(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_open_originator_port(ssh_message msg); LIBSSH_API int ssh_message_channel_request_open_originator_port(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_open_destination(ssh_message msg); LIBSSH_API char *ssh_message_channel_request_open_destination(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_open_destination_port(ssh_message msg); LIBSSH_API int ssh_message_channel_request_open_destination_port(ssh_message msg);
LIBSSH_API ssh_channel ssh_message_channel_request_channel(ssh_message msg); LIBSSH_API ssh_channel ssh_message_channel_request_channel(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_pty_term(ssh_message msg); LIBSSH_API char *ssh_message_channel_request_pty_term(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_pty_width(ssh_message msg); LIBSSH_API int ssh_message_channel_request_pty_width(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_pty_height(ssh_message msg); LIBSSH_API int ssh_message_channel_request_pty_height(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_pty_pxwidth(ssh_message msg); LIBSSH_API int ssh_message_channel_request_pty_pxwidth(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_pty_pxheight(ssh_message msg); LIBSSH_API int ssh_message_channel_request_pty_pxheight(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_env_name(ssh_message msg); LIBSSH_API char *ssh_message_channel_request_env_name(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_env_value(ssh_message msg); LIBSSH_API char *ssh_message_channel_request_env_value(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_command(ssh_message msg); LIBSSH_API char *ssh_message_channel_request_command(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_subsystem(ssh_message msg); LIBSSH_API char *ssh_message_channel_request_subsystem(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_x11_single_connection(ssh_message msg); LIBSSH_API char *ssh_message_global_request_address(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_x11_auth_protocol(ssh_message msg);
LIBSSH_API const char *ssh_message_channel_request_x11_auth_cookie(ssh_message msg);
LIBSSH_API int ssh_message_channel_request_x11_screen_number(ssh_message msg);
LIBSSH_API const char *ssh_message_global_request_address(ssh_message msg);
LIBSSH_API int ssh_message_global_request_port(ssh_message msg); LIBSSH_API int ssh_message_global_request_port(ssh_message msg);
LIBSSH_API int ssh_channel_open_reverse_forward(ssh_channel channel, const char *remotehost, LIBSSH_API int ssh_channel_open_reverse_forward(ssh_channel channel, const char *remotehost,
int remoteport, const char *sourcehost, int localport); int remoteport, const char *sourcehost, int localport);
LIBSSH_API int ssh_channel_open_x11(ssh_channel channel,
const char *orig_addr, int orig_port);
LIBSSH_API int ssh_channel_request_send_exit_status(ssh_channel channel, LIBSSH_API int ssh_channel_request_send_exit_status(ssh_channel channel,
int exit_status); int exit_status);
@@ -382,8 +301,6 @@ LIBSSH_API int ssh_channel_write_stderr(ssh_channel channel,
const void *data, const void *data,
uint32_t len); uint32_t len);
LIBSSH_API int ssh_send_keepalive(ssh_session session);
/* deprecated functions */ /* deprecated functions */
SSH_DEPRECATED LIBSSH_API int ssh_accept(ssh_session session); SSH_DEPRECATED LIBSSH_API int ssh_accept(ssh_session session);
SSH_DEPRECATED LIBSSH_API int channel_write_stderr(ssh_channel channel, SSH_DEPRECATED LIBSSH_API int channel_write_stderr(ssh_channel channel,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -3,19 +3,20 @@
* *
* Copyright (c) 2009 by Aris Adamantiadis * Copyright (c) 2009 by Aris Adamantiadis
* *
* This library is free software; you can redistribute it and/or * The SSH Library is free software; you can redistribute it and/or modify
* modify it under the terms of the GNU Lesser General Public * it under the terms of the GNU Lesser General Public License as published by
* License as published by the Free Software Foundation; either * the Free Software Foundation; either version 2.1 of the License, or (at your
* version 2.1 of the License, or (at your option) any later version. * option) any later version.
* *
* This library is distributed in the hope that it will be useful, * The SSH Library is distributed in the hope that it will be useful, but
* but WITHOUT ANY WARRANTY; without even the implied warranty of * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* Lesser General Public License for more details. * License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public License
* License along with this library; if not, write to the Free Software * along with the SSH Library; see the file COPYING. If not, write to
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/ */
#ifndef WRAPPER_H_ #ifndef WRAPPER_H_
@@ -25,24 +26,6 @@
#include "libssh/libcrypto.h" #include "libssh/libcrypto.h"
#include "libssh/libgcrypt.h" #include "libssh/libgcrypt.h"
enum ssh_mac_e {
SSH_MAC_SHA1=1,
SSH_MAC_SHA256,
SSH_MAC_SHA384,
SSH_MAC_SHA512
};
enum ssh_hmac_e {
SSH_HMAC_SHA1 = 1,
SSH_HMAC_MD5
};
enum ssh_des_e {
SSH_3DES,
SSH_DES
};
typedef struct ssh_mac_ctx_struct *ssh_mac_ctx;
MD5CTX md5_init(void); MD5CTX md5_init(void);
void md5_update(MD5CTX c, const void *data, unsigned long len); void md5_update(MD5CTX c, const void *data, unsigned long len);
void md5_final(unsigned char *md,MD5CTX c); void md5_final(unsigned char *md,MD5CTX c);
@@ -50,22 +33,13 @@ SHACTX sha1_init(void);
void sha1_update(SHACTX c, const void *data, unsigned long len); void sha1_update(SHACTX c, const void *data, unsigned long len);
void sha1_final(unsigned char *md,SHACTX c); void sha1_final(unsigned char *md,SHACTX c);
void sha1(unsigned char *digest,int len,unsigned char *hash); void sha1(unsigned char *digest,int len,unsigned char *hash);
void sha256(unsigned char *digest, int len, unsigned char *hash); #define HMAC_SHA1 1
#define HMAC_MD5 2
void evp(int nid, unsigned char *digest, int len, unsigned char *hash, unsigned int *hlen); HMACCTX hmac_init(const void *key,int len,int type);
EVPCTX evp_init(int nid);
void evp_update(EVPCTX ctx, const void *data, unsigned long len);
void evp_final(EVPCTX ctx, unsigned char *md, unsigned int *mdlen);
ssh_mac_ctx ssh_mac_ctx_init(enum ssh_mac_e type);
void ssh_mac_update(ssh_mac_ctx ctx, const void *data, unsigned long len);
void ssh_mac_final(unsigned char *md, ssh_mac_ctx ctx);
HMACCTX hmac_init(const void *key,int len, enum ssh_hmac_e type);
void hmac_update(HMACCTX c, const void *data, unsigned long len); void hmac_update(HMACCTX c, const void *data, unsigned long len);
void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len); void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len);
int crypt_set_algorithms(ssh_session session, enum ssh_des_e des_type); int crypt_set_algorithms(ssh_session );
int crypt_set_algorithms_server(ssh_session session); int crypt_set_algorithms_server(ssh_session session);
struct ssh_crypto_struct *crypto_new(void); struct ssh_crypto_struct *crypto_new(void);
void crypto_free(struct ssh_crypto_struct *crypto); void crypto_free(struct ssh_crypto_struct *crypto);

View File

@@ -1 +0,0 @@
set(LIBSSH_INLUDE_DIR @PROJECT_SOURCE_DIR@/include)

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