1/*
2 * This file is part of the SSH Library
3 *
4 * Copyright (c) 2003-2009 by Aris Adamantiadis
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef _LIBSSH_H
22#define _LIBSSH_H
23
24#if defined _WIN32 || defined __CYGWIN__
25 #ifdef LIBSSH_STATIC
26 #define LIBSSH_API
27 #else
28 #ifdef LIBSSH_EXPORTS
29 #ifdef __GNUC__
30 #define LIBSSH_API __attribute__((dllexport))
31 #else
32 #define LIBSSH_API __declspec(dllexport)
33 #endif
34 #else
35 #ifdef __GNUC__
36 #define LIBSSH_API __attribute__((dllimport))
37 #else
38 #define LIBSSH_API __declspec(dllimport)
39 #endif
40 #endif
41 #endif
42#else
43 #if __GNUC__ >= 4 && !defined(__OS2__)
44 #define LIBSSH_API __attribute__((visibility("default")))
45 #else
46 #define LIBSSH_API
47 #endif
48#endif
49
50#ifdef _MSC_VER
51 /* Visual Studio hasn't inttypes.h so it doesn't know uint32_t */
52 typedef int int32_t;
53 typedef unsigned int uint32_t;
54 typedef unsigned short uint16_t;
55 typedef unsigned char uint8_t;
56 typedef unsigned long long uint64_t;
57 typedef int mode_t;
58#else /* _MSC_VER */
59 #include <unistd.h>
60 #include <inttypes.h>
61 #include <sys/types.h>
62#endif /* _MSC_VER */
63
64#ifdef _WIN32
65 #include <winsock2.h>
66#else /* _WIN32 */
67 #include <sys/select.h> /* for fd_set * */
68 #include <netdb.h>
69#endif /* _WIN32 */
70
71#define SSH_STRINGIFY(s) SSH_TOSTRING(s)
72#define SSH_TOSTRING(s) #s
73
74/* libssh version macros */
75#define SSH_VERSION_INT(a, b, c) ((a) << 16 | (b) << 8 | (c))
76#define SSH_VERSION_DOT(a, b, c) a ##.## b ##.## c
77#define SSH_VERSION(a, b, c) SSH_VERSION_DOT(a, b, c)
78
79/* libssh version */
80#define LIBSSH_VERSION_MAJOR 0
81#define LIBSSH_VERSION_MINOR 7
82#define LIBSSH_VERSION_MICRO 6
83
84#define LIBSSH_VERSION_INT SSH_VERSION_INT(LIBSSH_VERSION_MAJOR, \
85 LIBSSH_VERSION_MINOR, \
86 LIBSSH_VERSION_MICRO)
87#define LIBSSH_VERSION SSH_VERSION(LIBSSH_VERSION_MAJOR, \
88 LIBSSH_VERSION_MINOR, \
89 LIBSSH_VERSION_MICRO)
90
91/* GCC have printf type attribute check. */
92#ifdef __GNUC__
93#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
94#else
95#define PRINTF_ATTRIBUTE(a,b)
96#endif /* __GNUC__ */
97
98#ifdef __GNUC__
99#define SSH_DEPRECATED __attribute__ ((deprecated))
100#else
101#define SSH_DEPRECATED
102#endif
103
104#ifdef __cplusplus
105extern "C" {
106#endif
107
108struct ssh_counter_struct {
109 uint64_t in_bytes;
110 uint64_t out_bytes;
111 uint64_t in_packets;
112 uint64_t out_packets;
113};
114typedef struct ssh_counter_struct *ssh_counter;
115
116typedef struct ssh_agent_struct* ssh_agent;
117typedef struct ssh_buffer_struct* ssh_buffer;
118typedef struct ssh_channel_struct* ssh_channel;
119typedef struct ssh_message_struct* ssh_message;
120typedef struct ssh_pcap_file_struct* ssh_pcap_file;
121typedef struct ssh_key_struct* ssh_key;
122typedef struct ssh_scp_struct* ssh_scp;
123typedef struct ssh_session_struct* ssh_session;
124typedef struct ssh_string_struct* ssh_string;
125typedef struct ssh_event_struct* ssh_event;
126typedef void* ssh_gssapi_creds;
127
128/* Socket type */
129#ifdef _WIN32
130#ifndef socket_t
131typedef SOCKET socket_t;
132#endif /* socket_t */
133#else /* _WIN32 */
134#ifndef socket_t
135typedef int socket_t;
136#endif
137#endif /* _WIN32 */
138
139#define SSH_INVALID_SOCKET ((socket_t) -1)
140
141/* the offsets of methods */
142enum ssh_kex_types_e {
143 SSH_KEX=0,
144 SSH_HOSTKEYS,
145 SSH_CRYPT_C_S,
146 SSH_CRYPT_S_C,
147 SSH_MAC_C_S,
148 SSH_MAC_S_C,
149 SSH_COMP_C_S,
150 SSH_COMP_S_C,
151 SSH_LANG_C_S,
152 SSH_LANG_S_C
153};
154
155#define SSH_CRYPT 2
156#define SSH_MAC 3
157#define SSH_COMP 4
158#define SSH_LANG 5
159
160enum ssh_auth_e {
161 SSH_AUTH_SUCCESS=0,
162 SSH_AUTH_DENIED,
163 SSH_AUTH_PARTIAL,
164 SSH_AUTH_INFO,
165 SSH_AUTH_AGAIN,
166 SSH_AUTH_ERROR=-1
167};
168
169/* auth flags */
170#define SSH_AUTH_METHOD_UNKNOWN 0
171#define SSH_AUTH_METHOD_NONE 0x0001
172#define SSH_AUTH_METHOD_PASSWORD 0x0002
173#define SSH_AUTH_METHOD_PUBLICKEY 0x0004
174#define SSH_AUTH_METHOD_HOSTBASED 0x0008
175#define SSH_AUTH_METHOD_INTERACTIVE 0x0010
176#define SSH_AUTH_METHOD_GSSAPI_MIC 0x0020
177
178/* messages */
179enum ssh_requests_e {
180 SSH_REQUEST_AUTH=1,
181 SSH_REQUEST_CHANNEL_OPEN,
182 SSH_REQUEST_CHANNEL,
183 SSH_REQUEST_SERVICE,
184 SSH_REQUEST_GLOBAL
185};
186
187enum ssh_channel_type_e {
188 SSH_CHANNEL_UNKNOWN=0,
189 SSH_CHANNEL_SESSION,
190 SSH_CHANNEL_DIRECT_TCPIP,
191 SSH_CHANNEL_FORWARDED_TCPIP,
192 SSH_CHANNEL_X11
193};
194
195enum ssh_channel_requests_e {
196 SSH_CHANNEL_REQUEST_UNKNOWN=0,
197 SSH_CHANNEL_REQUEST_PTY,
198 SSH_CHANNEL_REQUEST_EXEC,
199 SSH_CHANNEL_REQUEST_SHELL,
200 SSH_CHANNEL_REQUEST_ENV,
201 SSH_CHANNEL_REQUEST_SUBSYSTEM,
202 SSH_CHANNEL_REQUEST_WINDOW_CHANGE,
203 SSH_CHANNEL_REQUEST_X11
204};
205
206enum ssh_global_requests_e {
207 SSH_GLOBAL_REQUEST_UNKNOWN=0,
208 SSH_GLOBAL_REQUEST_TCPIP_FORWARD,
209 SSH_GLOBAL_REQUEST_CANCEL_TCPIP_FORWARD,
210};
211
212enum ssh_publickey_state_e {
213 SSH_PUBLICKEY_STATE_ERROR=-1,
214 SSH_PUBLICKEY_STATE_NONE=0,
215 SSH_PUBLICKEY_STATE_VALID=1,
216 SSH_PUBLICKEY_STATE_WRONG=2
217};
218
219/* Status flags */
220/** Socket is closed */
221#define SSH_CLOSED 0x01
222/** Reading to socket won't block */
223#define SSH_READ_PENDING 0x02
224/** Session was closed due to an error */
225#define SSH_CLOSED_ERROR 0x04
226/** Output buffer not empty */
227#define SSH_WRITE_PENDING 0x08
228
229enum ssh_server_known_e {
230 SSH_SERVER_ERROR=-1,
231 SSH_SERVER_NOT_KNOWN=0,
232 SSH_SERVER_KNOWN_OK,
233 SSH_SERVER_KNOWN_CHANGED,
234 SSH_SERVER_FOUND_OTHER,
235 SSH_SERVER_FILE_NOT_FOUND
236};
237
238#ifndef MD5_DIGEST_LEN
239 #define MD5_DIGEST_LEN 16
240#endif
241/* errors */
242
243enum ssh_error_types_e {
244 SSH_NO_ERROR=0,
245 SSH_REQUEST_DENIED,
246 SSH_FATAL,
247 SSH_EINTR
248};
249
250/* some types for keys */
251enum ssh_keytypes_e{
252 SSH_KEYTYPE_UNKNOWN=0,
253 SSH_KEYTYPE_DSS=1,
254 SSH_KEYTYPE_RSA,
255 SSH_KEYTYPE_RSA1,
256 SSH_KEYTYPE_ECDSA,
257 SSH_KEYTYPE_ED25519
258};
259
260enum ssh_keycmp_e {
261 SSH_KEY_CMP_PUBLIC = 0,
262 SSH_KEY_CMP_PRIVATE
263};
264
265/* Error return codes */
266#define SSH_OK 0 /* No error */
267#define SSH_ERROR -1 /* Error of some kind */
268#define SSH_AGAIN -2 /* The nonblocking call must be repeated */
269#define SSH_EOF -127 /* We have already a eof */
270
271/**
272 * @addtogroup libssh_log
273 *
274 * @{
275 */
276
277enum {
278 /** No logging at all
279 */
280 SSH_LOG_NOLOG=0,
281 /** Only warnings
282 */
283 SSH_LOG_WARNING,
284 /** High level protocol information
285 */
286 SSH_LOG_PROTOCOL,
287 /** Lower level protocol infomations, packet level
288 */
289 SSH_LOG_PACKET,
290 /** Every function path
291 */
292 SSH_LOG_FUNCTIONS
293};
294/** @} */
295#define SSH_LOG_RARE SSH_LOG_WARNING
296
297/**
298 * @name Logging levels
299 *
300 * @brief Debug levels for logging.
301 * @{
302 */
303
304/** No logging at all */
305#define SSH_LOG_NONE 0
306/** Show only warnings */
307#define SSH_LOG_WARN 1
308/** Get some information what's going on */
309#define SSH_LOG_INFO 2
310/** Get detailed debuging information **/
311#define SSH_LOG_DEBUG 3
312/** Get trace output, packet information, ... */
313#define SSH_LOG_TRACE 4
314
315/** @} */
316
317enum ssh_options_e {
318 SSH_OPTIONS_HOST,
319 SSH_OPTIONS_PORT,
320 SSH_OPTIONS_PORT_STR,
321 SSH_OPTIONS_FD,
322 SSH_OPTIONS_USER,
323 SSH_OPTIONS_SSH_DIR,
324 SSH_OPTIONS_IDENTITY,
325 SSH_OPTIONS_ADD_IDENTITY,
326 SSH_OPTIONS_KNOWNHOSTS,
327 SSH_OPTIONS_TIMEOUT,
328 SSH_OPTIONS_TIMEOUT_USEC,
329 SSH_OPTIONS_SSH1,
330 SSH_OPTIONS_SSH2,
331 SSH_OPTIONS_LOG_VERBOSITY,
332 SSH_OPTIONS_LOG_VERBOSITY_STR,
333 SSH_OPTIONS_CIPHERS_C_S,
334 SSH_OPTIONS_CIPHERS_S_C,
335 SSH_OPTIONS_COMPRESSION_C_S,
336 SSH_OPTIONS_COMPRESSION_S_C,
337 SSH_OPTIONS_PROXYCOMMAND,
338 SSH_OPTIONS_BINDADDR,
339 SSH_OPTIONS_STRICTHOSTKEYCHECK,
340 SSH_OPTIONS_COMPRESSION,
341 SSH_OPTIONS_COMPRESSION_LEVEL,
342 SSH_OPTIONS_KEY_EXCHANGE,
343 SSH_OPTIONS_HOSTKEYS,
344 SSH_OPTIONS_GSSAPI_SERVER_IDENTITY,
345 SSH_OPTIONS_GSSAPI_CLIENT_IDENTITY,
346 SSH_OPTIONS_GSSAPI_DELEGATE_CREDENTIALS,
347 SSH_OPTIONS_HMAC_C_S,
348 SSH_OPTIONS_HMAC_S_C,
349};
350
351enum {
352 /** Code is going to write/create remote files */
353 SSH_SCP_WRITE,
354 /** Code is going to read remote files */
355 SSH_SCP_READ,
356 SSH_SCP_RECURSIVE=0x10
357};
358
359enum ssh_scp_request_types {
360 /** A new directory is going to be pulled */
361 SSH_SCP_REQUEST_NEWDIR=1,
362 /** A new file is going to be pulled */
363 SSH_SCP_REQUEST_NEWFILE,
364 /** End of requests */
365 SSH_SCP_REQUEST_EOF,
366 /** End of directory */
367 SSH_SCP_REQUEST_ENDDIR,
368 /** Warning received */
369 SSH_SCP_REQUEST_WARNING
370};
371
372LIBSSH_API int ssh_blocking_flush(ssh_session session, int timeout);
373LIBSSH_API ssh_channel ssh_channel_accept_x11(ssh_channel channel, int timeout_ms);
374LIBSSH_API int ssh_channel_change_pty_size(ssh_channel channel,int cols,int rows);
375LIBSSH_API int ssh_channel_close(ssh_channel channel);
376LIBSSH_API void ssh_channel_free(ssh_channel channel);
377LIBSSH_API int ssh_channel_get_exit_status(ssh_channel channel);
378LIBSSH_API ssh_session ssh_channel_get_session(ssh_channel channel);
379LIBSSH_API int ssh_channel_is_closed(ssh_channel channel);
380LIBSSH_API int ssh_channel_is_eof(ssh_channel channel);
381LIBSSH_API int ssh_channel_is_open(ssh_channel channel);
382LIBSSH_API ssh_channel ssh_channel_new(ssh_session session);
383LIBSSH_API int ssh_channel_open_auth_agent(ssh_channel channel);
384LIBSSH_API int ssh_channel_open_forward(ssh_channel channel, const char *remotehost,
385 int remoteport, const char *sourcehost, int localport);
386LIBSSH_API int ssh_channel_open_session(ssh_channel channel);
387LIBSSH_API int ssh_channel_open_x11(ssh_channel channel, const char *orig_addr, int orig_port);
388LIBSSH_API int ssh_channel_poll(ssh_channel channel, int is_stderr);
389LIBSSH_API int ssh_channel_poll_timeout(ssh_channel channel, int timeout, int is_stderr);
390LIBSSH_API int ssh_channel_read(ssh_channel channel, void *dest, uint32_t count, int is_stderr);
391LIBSSH_API int ssh_channel_read_timeout(ssh_channel channel, void *dest, uint32_t count, int is_stderr, int timeout_ms);
392LIBSSH_API int ssh_channel_read_nonblocking(ssh_channel channel, void *dest, uint32_t count,
393 int is_stderr);
394LIBSSH_API int ssh_channel_request_env(ssh_channel channel, const char *name, const char *value);
395LIBSSH_API int ssh_channel_request_exec(ssh_channel channel, const char *cmd);
396LIBSSH_API int ssh_channel_request_pty(ssh_channel channel);
397LIBSSH_API int ssh_channel_request_pty_size(ssh_channel channel, const char *term,
398 int cols, int rows);
399LIBSSH_API int ssh_channel_request_shell(ssh_channel channel);
400LIBSSH_API int ssh_channel_request_send_signal(ssh_channel channel, const char *signum);
401LIBSSH_API int ssh_channel_request_sftp(ssh_channel channel);
402LIBSSH_API int ssh_channel_request_subsystem(ssh_channel channel, const char *subsystem);
403LIBSSH_API int ssh_channel_request_x11(ssh_channel channel, int single_connection, const char *protocol,
404 const char *cookie, int screen_number);
405LIBSSH_API int ssh_channel_send_eof(ssh_channel channel);
406LIBSSH_API int ssh_channel_select(ssh_channel *readchans, ssh_channel *writechans, ssh_channel *exceptchans, struct
407 timeval * timeout);
408LIBSSH_API void ssh_channel_set_blocking(ssh_channel channel, int blocking);
409LIBSSH_API void ssh_channel_set_counter(ssh_channel channel,
410 ssh_counter counter);
411LIBSSH_API int ssh_channel_write(ssh_channel channel, const void *data, uint32_t len);
412LIBSSH_API uint32_t ssh_channel_window_size(ssh_channel channel);
413
414LIBSSH_API char *ssh_basename (const char *path);
415LIBSSH_API void ssh_clean_pubkey_hash(unsigned char **hash);
416LIBSSH_API int ssh_connect(ssh_session session);
417LIBSSH_API const char *ssh_copyright(void);
418LIBSSH_API void ssh_disconnect(ssh_session session);
419LIBSSH_API char *ssh_dirname (const char *path);
420LIBSSH_API int ssh_finalize(void);
421
422/* REVERSE PORT FORWARDING */
423LIBSSH_API ssh_channel ssh_channel_accept_forward(ssh_session session,
424 int timeout_ms,
425 int *destination_port);
426LIBSSH_API int ssh_channel_cancel_forward(ssh_session session,
427 const char *address,
428 int port);
429LIBSSH_API int ssh_channel_listen_forward(ssh_session session,
430 const char *address,
431 int port,
432 int *bound_port);
433
434LIBSSH_API void ssh_free(ssh_session session);
435LIBSSH_API const char *ssh_get_disconnect_message(ssh_session session);
436LIBSSH_API const char *ssh_get_error(void *error);
437LIBSSH_API int ssh_get_error_code(void *error);
438LIBSSH_API socket_t ssh_get_fd(ssh_session session);
439LIBSSH_API char *ssh_get_hexa(const unsigned char *what, size_t len);
440LIBSSH_API char *ssh_get_issue_banner(ssh_session session);
441LIBSSH_API int ssh_get_openssh_version(ssh_session session);
442
443LIBSSH_API int ssh_get_publickey(ssh_session session, ssh_key *key);
444
445enum ssh_publickey_hash_type {
446 SSH_PUBLICKEY_HASH_SHA1,
447 SSH_PUBLICKEY_HASH_MD5,
448 SSH_PUBLICKEY_HASH_SHA256
449};
450LIBSSH_API int ssh_get_publickey_hash(const ssh_key key,
451 enum ssh_publickey_hash_type type,
452 unsigned char **hash,
453 size_t *hlen);
454
455/* DEPRECATED FUNCTIONS */
456SSH_DEPRECATED LIBSSH_API int ssh_get_pubkey_hash(ssh_session session, unsigned char **hash);
457SSH_DEPRECATED LIBSSH_API ssh_channel ssh_forward_accept(ssh_session session, int timeout_ms);
458SSH_DEPRECATED LIBSSH_API int ssh_forward_cancel(ssh_session session, const char *address, int port);
459SSH_DEPRECATED LIBSSH_API int ssh_forward_listen(ssh_session session, const char *address, int port, int *bound_port);
460
461
462LIBSSH_API int ssh_get_random(void *where,int len,int strong);
463LIBSSH_API int ssh_get_version(ssh_session session);
464LIBSSH_API int ssh_get_status(ssh_session session);
465LIBSSH_API int ssh_get_poll_flags(ssh_session session);
466LIBSSH_API int ssh_init(void);
467LIBSSH_API int ssh_is_blocking(ssh_session session);
468LIBSSH_API int ssh_is_connected(ssh_session session);
469LIBSSH_API int ssh_is_server_known(ssh_session session);
470
471/* LOGGING */
472LIBSSH_API int ssh_set_log_level(int level);
473LIBSSH_API int ssh_get_log_level(void);
474LIBSSH_API void *ssh_get_log_userdata(void);
475LIBSSH_API int ssh_set_log_userdata(void *data);
476LIBSSH_API void _ssh_log(int verbosity,
477 const char *function,
478 const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
479
480/* legacy */
481SSH_DEPRECATED LIBSSH_API void ssh_log(ssh_session session,
482 int prioriry,
483 const char *format, ...) PRINTF_ATTRIBUTE(3, 4);
484
485LIBSSH_API ssh_channel ssh_message_channel_request_open_reply_accept(ssh_message msg);
486LIBSSH_API int ssh_message_channel_request_reply_success(ssh_message msg);
487LIBSSH_API void ssh_message_free(ssh_message msg);
488LIBSSH_API ssh_message ssh_message_get(ssh_session session);
489LIBSSH_API int ssh_message_subtype(ssh_message msg);
490LIBSSH_API int ssh_message_type(ssh_message msg);
491LIBSSH_API int ssh_mkdir (const char *pathname, mode_t mode);
492LIBSSH_API ssh_session ssh_new(void);
493
494LIBSSH_API int ssh_options_copy(ssh_session src, ssh_session *dest);
495LIBSSH_API int ssh_options_getopt(ssh_session session, int *argcptr, char **argv);
496LIBSSH_API int ssh_options_parse_config(ssh_session session, const char *filename);
497LIBSSH_API int ssh_options_set(ssh_session session, enum ssh_options_e type,
498 const void *value);
499LIBSSH_API int ssh_options_get(ssh_session session, enum ssh_options_e type,
500 char **value);
501LIBSSH_API int ssh_options_get_port(ssh_session session, unsigned int * port_target);
502LIBSSH_API int ssh_pcap_file_close(ssh_pcap_file pcap);
503LIBSSH_API void ssh_pcap_file_free(ssh_pcap_file pcap);
504LIBSSH_API ssh_pcap_file ssh_pcap_file_new(void);
505LIBSSH_API int ssh_pcap_file_open(ssh_pcap_file pcap, const char *filename);
506
507/**
508 * @brief SSH authentication callback.
509 *
510 * @param prompt Prompt to be displayed.
511 * @param buf Buffer to save the password. You should null-terminate it.
512 * @param len Length of the buffer.
513 * @param echo Enable or disable the echo of what you type.
514 * @param verify Should the password be verified?
515 * @param userdata Userdata to be passed to the callback function. Useful
516 * for GUI applications.
517 *
518 * @return 0 on success, < 0 on error.
519 */
520typedef int (*ssh_auth_callback) (const char *prompt, char *buf, size_t len,
521 int echo, int verify, void *userdata);
522
523LIBSSH_API ssh_key ssh_key_new(void);
524LIBSSH_API void ssh_key_free (ssh_key key);
525LIBSSH_API enum ssh_keytypes_e ssh_key_type(const ssh_key key);
526LIBSSH_API const char *ssh_key_type_to_char(enum ssh_keytypes_e type);
527LIBSSH_API enum ssh_keytypes_e ssh_key_type_from_name(const char *name);
528LIBSSH_API int ssh_key_is_public(const ssh_key k);
529LIBSSH_API int ssh_key_is_private(const ssh_key k);
530LIBSSH_API int ssh_key_cmp(const ssh_key k1,
531 const ssh_key k2,
532 enum ssh_keycmp_e what);
533
534LIBSSH_API int ssh_pki_generate(enum ssh_keytypes_e type, int parameter,
535 ssh_key *pkey);
536LIBSSH_API int ssh_pki_import_privkey_base64(const char *b64_key,
537 const char *passphrase,
538 ssh_auth_callback auth_fn,
539 void *auth_data,
540 ssh_key *pkey);
541LIBSSH_API int ssh_pki_import_privkey_file(const char *filename,
542 const char *passphrase,
543 ssh_auth_callback auth_fn,
544 void *auth_data,
545 ssh_key *pkey);
546LIBSSH_API int ssh_pki_export_privkey_file(const ssh_key privkey,
547 const char *passphrase,
548 ssh_auth_callback auth_fn,
549 void *auth_data,
550 const char *filename);
551
552LIBSSH_API int ssh_pki_import_pubkey_base64(const char *b64_key,
553 enum ssh_keytypes_e type,
554 ssh_key *pkey);
555LIBSSH_API int ssh_pki_import_pubkey_file(const char *filename,
556 ssh_key *pkey);
557
558LIBSSH_API int ssh_pki_export_privkey_to_pubkey(const ssh_key privkey,
559 ssh_key *pkey);
560LIBSSH_API int ssh_pki_export_pubkey_base64(const ssh_key key,
561 char **b64_key);
562LIBSSH_API int ssh_pki_export_pubkey_file(const ssh_key key,
563 const char *filename);
564
565LIBSSH_API const char *ssh_pki_key_ecdsa_name(const ssh_key key);
566
567LIBSSH_API char *ssh_get_fingerprint_hash(enum ssh_publickey_hash_type type,
568 unsigned char *hash,
569 size_t len);
570LIBSSH_API void ssh_print_hash(enum ssh_publickey_hash_type type, unsigned char *hash, size_t len);
571LIBSSH_API void ssh_print_hexa(const char *descr, const unsigned char *what, size_t len);
572LIBSSH_API int ssh_send_ignore (ssh_session session, const char *data);
573LIBSSH_API int ssh_send_debug (ssh_session session, const char *message, int always_display);
574LIBSSH_API void ssh_gssapi_set_creds(ssh_session session, const ssh_gssapi_creds creds);
575LIBSSH_API int ssh_scp_accept_request(ssh_scp scp);
576LIBSSH_API int ssh_scp_close(ssh_scp scp);
577LIBSSH_API int ssh_scp_deny_request(ssh_scp scp, const char *reason);
578LIBSSH_API void ssh_scp_free(ssh_scp scp);
579LIBSSH_API int ssh_scp_init(ssh_scp scp);
580LIBSSH_API int ssh_scp_leave_directory(ssh_scp scp);
581LIBSSH_API ssh_scp ssh_scp_new(ssh_session session, int mode, const char *location);
582LIBSSH_API int ssh_scp_pull_request(ssh_scp scp);
583LIBSSH_API int ssh_scp_push_directory(ssh_scp scp, const char *dirname, int mode);
584LIBSSH_API int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, int perms);
585LIBSSH_API int ssh_scp_push_file64(ssh_scp scp, const char *filename, uint64_t size, int perms);
586LIBSSH_API int ssh_scp_read(ssh_scp scp, void *buffer, size_t size);
587LIBSSH_API const char *ssh_scp_request_get_filename(ssh_scp scp);
588LIBSSH_API int ssh_scp_request_get_permissions(ssh_scp scp);
589LIBSSH_API size_t ssh_scp_request_get_size(ssh_scp scp);
590LIBSSH_API uint64_t ssh_scp_request_get_size64(ssh_scp scp);
591LIBSSH_API const char *ssh_scp_request_get_warning(ssh_scp scp);
592LIBSSH_API int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len);
593LIBSSH_API int ssh_select(ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd,
594 fd_set *readfds, struct timeval *timeout);
595LIBSSH_API int ssh_service_request(ssh_session session, const char *service);
596LIBSSH_API int ssh_set_agent_channel(ssh_session session, ssh_channel channel);
597LIBSSH_API int ssh_set_agent_socket(ssh_session session, socket_t fd);
598LIBSSH_API void ssh_set_blocking(ssh_session session, int blocking);
599LIBSSH_API void ssh_set_counters(ssh_session session, ssh_counter scounter,
600 ssh_counter rcounter);
601LIBSSH_API void ssh_set_fd_except(ssh_session session);
602LIBSSH_API void ssh_set_fd_toread(ssh_session session);
603LIBSSH_API void ssh_set_fd_towrite(ssh_session session);
604LIBSSH_API void ssh_silent_disconnect(ssh_session session);
605LIBSSH_API int ssh_set_pcap_file(ssh_session session, ssh_pcap_file pcapfile);
606
607/* USERAUTH */
608LIBSSH_API int ssh_userauth_none(ssh_session session, const char *username);
609LIBSSH_API int ssh_userauth_list(ssh_session session, const char *username);
610LIBSSH_API int ssh_userauth_try_publickey(ssh_session session,
611 const char *username,
612 const ssh_key pubkey);
613LIBSSH_API int ssh_userauth_publickey(ssh_session session,
614 const char *username,
615 const ssh_key privkey);
616#ifndef _WIN32
617LIBSSH_API int ssh_userauth_agent(ssh_session session,
618 const char *username);
619#endif
620LIBSSH_API int ssh_userauth_publickey_auto(ssh_session session,
621 const char *username,
622 const char *passphrase);
623LIBSSH_API int ssh_userauth_password(ssh_session session,
624 const char *username,
625 const char *password);
626
627LIBSSH_API int ssh_userauth_kbdint(ssh_session session, const char *user, const char *submethods);
628LIBSSH_API const char *ssh_userauth_kbdint_getinstruction(ssh_session session);
629LIBSSH_API const char *ssh_userauth_kbdint_getname(ssh_session session);
630LIBSSH_API int ssh_userauth_kbdint_getnprompts(ssh_session session);
631LIBSSH_API const char *ssh_userauth_kbdint_getprompt(ssh_session session, unsigned int i, char *echo);
632LIBSSH_API int ssh_userauth_kbdint_getnanswers(ssh_session session);
633LIBSSH_API const char *ssh_userauth_kbdint_getanswer(ssh_session session, unsigned int i);
634LIBSSH_API int ssh_userauth_kbdint_setanswer(ssh_session session, unsigned int i,
635 const char *answer);
636LIBSSH_API int ssh_userauth_gssapi(ssh_session session);
637LIBSSH_API const char *ssh_version(int req_version);
638LIBSSH_API int ssh_write_knownhost(ssh_session session);
639
640LIBSSH_API void ssh_string_burn(ssh_string str);
641LIBSSH_API ssh_string ssh_string_copy(ssh_string str);
642LIBSSH_API void *ssh_string_data(ssh_string str);
643LIBSSH_API int ssh_string_fill(ssh_string str, const void *data, size_t len);
644LIBSSH_API void ssh_string_free(ssh_string str);
645LIBSSH_API ssh_string ssh_string_from_char(const char *what);
646LIBSSH_API size_t ssh_string_len(ssh_string str);
647LIBSSH_API ssh_string ssh_string_new(size_t size);
648LIBSSH_API const char *ssh_string_get_char(ssh_string str);
649LIBSSH_API char *ssh_string_to_char(ssh_string str);
650LIBSSH_API void ssh_string_free_char(char *s);
651
652LIBSSH_API int ssh_getpass(const char *prompt, char *buf, size_t len, int echo,
653 int verify);
654
655
656typedef int (*ssh_event_callback)(socket_t fd, int revents, void *userdata);
657
658LIBSSH_API ssh_event ssh_event_new(void);
659LIBSSH_API int ssh_event_add_fd(ssh_event event, socket_t fd, short events,
660 ssh_event_callback cb, void *userdata);
661LIBSSH_API int ssh_event_add_session(ssh_event event, ssh_session session);
662LIBSSH_API int ssh_event_dopoll(ssh_event event, int timeout);
663LIBSSH_API int ssh_event_remove_fd(ssh_event event, socket_t fd);
664LIBSSH_API int ssh_event_remove_session(ssh_event event, ssh_session session);
665LIBSSH_API void ssh_event_free(ssh_event event);
666LIBSSH_API const char* ssh_get_clientbanner(ssh_session session);
667LIBSSH_API const char* ssh_get_serverbanner(ssh_session session);
668LIBSSH_API const char* ssh_get_kex_algo(ssh_session session);
669LIBSSH_API const char* ssh_get_cipher_in(ssh_session session);
670LIBSSH_API const char* ssh_get_cipher_out(ssh_session session);
671LIBSSH_API const char* ssh_get_hmac_in(ssh_session session);
672LIBSSH_API const char* ssh_get_hmac_out(ssh_session session);
673
674#ifndef LIBSSH_LEGACY_0_4
675#include "libssh/legacy.h"
676#endif
677
678#ifdef __cplusplus
679}
680#endif
681#endif /* _LIBSSH_H */
682/* vim: set ts=2 sw=2 et cindent: */
683