include/libssh/priv.h

00001 /*
00002 Copyright (c) 2003-2008 Aris Adamantiadis
00003 
00004 This file is part of the SSH Library
00005 
00006 The SSH Library is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU Lesser General Public License as published by
00008 the Free Software Foundation; either version 2.1 of the License, or (at your
00009 option) any later version.
00010 
00011 The SSH Library is distributed in the hope that it will be useful, but
00012 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00013 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00014 License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License
00017 along with the SSH Library; see the file COPYING.  If not, write to
00018 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00019 MA 02111-1307, USA. */
00020 
00021 /* priv.h file */
00022 /* This include file contains everything you shouldn't deal with in user programs. */
00023 /* Consider that anything in this file might change without notice; libssh.h file will keep */
00024 /* backward compatibility on binary & source */
00025 
00026 #ifndef _LIBSSH_PRIV_H
00027 #define _LIBSSH_PRIV_H
00028 #include "config.h"
00029 #include "libssh/libssh.h"
00030 
00031 /* Debugging constants */
00032 
00033 /* Define this if you want to debug crypto systems */
00034 /* it's usefull when you are debugging the lib */
00035 /*#define DEBUG_CRYPTO */
00036 
00037 /* some constants */
00038 #define MAX_PACKET_LEN 262144
00039 #define ERROR_BUFFERLEN 1024
00040 #define CLIENTBANNER1 "SSH-1.5-" LIBSSH_VERSION
00041 #define CLIENTBANNER2 "SSH-2.0-" LIBSSH_VERSION
00042 #define KBDINT_MAX_PROMPT 256 /* more than openssh's :) */
00043 /* some types for public keys */
00044 #define TYPE_DSS 1
00045 #define TYPE_RSA 2
00046 #define TYPE_RSA1 3
00047 
00048 /* profiling constants. Don't touch them unless you know what you do */
00049 #ifdef HAVE_LIBCRYPTO
00050 #define OPENSSL_BIGNUMS
00051 #endif
00052 
00053 #ifdef __cplusplus
00054 extern "C" {
00055 #endif
00056 
00057 /* wrapper things */
00058 #ifdef HAVE_LIBGCRYPT
00059 #include <gcrypt.h>
00060 typedef gcry_md_hd_t SHACTX;
00061 typedef gcry_md_hd_t MD5CTX;
00062 typedef gcry_md_hd_t HMACCTX;
00063 #ifdef MD5_DIGEST_LEN
00064     #undef MD5_DIGEST_LEN
00065 #endif
00066 #define SHA_DIGEST_LEN 20
00067 #define MD5_DIGEST_LEN 16
00068 #define EVP_MAX_MD_SIZE 36
00069 
00070 typedef gcry_mpi_t bignum;
00071 
00072 #define bignum_new() gcry_mpi_new(0)
00073 #define bignum_free(num) gcry_mpi_release(num)
00074 #define bignum_set_word(bn,n) gcry_mpi_set_ui(bn,n)
00075 #define bignum_bin2bn(bn,datalen,data) gcry_mpi_scan(data,GCRYMPI_FMT_USG,bn,datalen,NULL)
00076 #define bignum_bn2dec(num) my_gcry_bn2dec(num)
00077 #define bignum_dec2bn(num, data) my_gcry_dec2bn(data, num)
00078 #define bignum_bn2hex(num,data) gcry_mpi_aprint(GCRYMPI_FMT_HEX,data,NULL,num)
00079 #define bignum_hex2bn(num,datalen,data) gcry_mpi_scan(num,GCRYMPI_FMT_HEX,data,datalen,NULL)
00080 #define bignum_rand(num,bits) gcry_mpi_randomize(num,bits,GCRY_STRONG_RANDOM),gcry_mpi_set_bit(num,bits-1),gcry_mpi_set_bit(num,0)
00081 #define bignum_mod_exp(dest,generator,exp,modulo) gcry_mpi_powm(dest,generator,exp,modulo)
00082 #define bignum_num_bits(num) gcry_mpi_get_nbits(num)
00083 #define bignum_num_bytes(num) ((gcry_mpi_get_nbits(num)+7)/8)
00084 #define bignum_is_bit_set(num,bit) gcry_mpi_test_bit(num,bit)
00085 #define bignum_bn2bin(num,datalen,data) gcry_mpi_print(GCRYMPI_FMT_USG,data,datalen,NULL,num)
00086 #define bignum_cmp(num1,num2) gcry_mpi_cmp(num1,num2)
00087 
00088 #elif defined HAVE_LIBCRYPTO
00089 #include <openssl/dsa.h>
00090 #include <openssl/rsa.h>
00091 #include <openssl/sha.h>
00092 #include <openssl/md5.h>
00093 #include <openssl/hmac.h>
00094 typedef SHA_CTX* SHACTX;
00095 typedef MD5_CTX*  MD5CTX;
00096 typedef HMAC_CTX* HMACCTX;
00097 #ifdef MD5_DIGEST_LEN
00098     #undef MD5_DIGEST_LEN
00099 #endif
00100 #define SHA_DIGEST_LEN SHA_DIGEST_LENGTH
00101 #define MD5_DIGEST_LEN MD5_DIGEST_LENGTH
00102 
00103 #endif /* OPENSSL_CRYPTO */
00104 #ifdef OPENSSL_BIGNUMS
00105 #include <openssl/bn.h>
00106 typedef BIGNUM*  bignum;
00107 typedef BN_CTX* bignum_CTX;
00108 
00109 #define bignum_new() BN_new()
00110 #define bignum_free(num) BN_clear_free(num)
00111 #define bignum_set_word(bn,n) BN_set_word(bn,n)
00112 #define bignum_bin2bn(bn,datalen,data) BN_bin2bn(bn,datalen,data)
00113 #define bignum_bn2dec(num) BN_bn2dec(num)
00114 #define bignum_dec2bn(bn,data) BN_dec2bn(data,bn)
00115 #define bignum_bn2hex(num) BN_bn2hex(num)
00116 #define bignum_rand(rnd, bits, top, bottom) BN_rand(rnd,bits,top,bottom)
00117 #define bignum_ctx_new() BN_CTX_new()
00118 #define bignum_ctx_free(num) BN_CTX_free(num)
00119 #define bignum_mod_exp(dest,generator,exp,modulo,ctx) BN_mod_exp(dest,generator,exp,modulo,ctx)
00120 #define bignum_num_bytes(num) BN_num_bytes(num)
00121 #define bignum_num_bits(num) BN_num_bits(num)
00122 #define bignum_is_bit_set(num,bit) BN_is_bit_set(num,bit)
00123 #define bignum_bn2bin(num,ptr) BN_bn2bin(num,ptr)
00124 #define bignum_cmp(num1,num2) BN_cmp(num1,num2)
00125 
00126 #endif /* OPENSSL_BIGNUMS */
00127 
00128 #ifdef HAVE_SYS_TIME_H
00129 #include <sys/time.h>
00130 #endif
00131 
00132 /* wrapper.c */
00133 MD5CTX md5_init(void);
00134 void md5_update(MD5CTX c, const void *data, unsigned long len);
00135 void md5_final(unsigned char *md,MD5CTX c);
00136 SHACTX sha1_init(void);
00137 void sha1_update(SHACTX c, const void *data, unsigned long len);
00138 void sha1_final(unsigned char *md,SHACTX c);
00139 void sha1(unsigned char *digest,int len,unsigned char *hash);
00140 #define HMAC_SHA1 1
00141 #define HMAC_MD5 2
00142 HMACCTX hmac_init(const void *key,int len,int type);
00143 void hmac_update(HMACCTX c, const void *data, unsigned long len);
00144 void hmac_final(HMACCTX ctx,unsigned char *hashmacbuf,unsigned int *len);
00145 
00146 /* strings and buffers */
00147 /* must be 32 bits number + immediatly our data */
00148 struct string_struct {
00149         u32 size;
00150         unsigned char string[MAX_PACKET_LEN];
00151 } __attribute__ ((packed));
00152 
00155 struct buffer_struct {
00156     char *data;
00157     int used;
00158     int allocated;
00159     int pos;
00160 };
00161 
00162 /* i should remove it one day */
00163 typedef struct packet_struct {
00164         int valid;
00165         u32 len;
00166         u8 type;
00167 } PACKET;
00168 
00169 typedef struct kex_struct {
00170         unsigned char cookie[16];
00171         char **methods;
00172 } KEX;
00173 
00174 struct public_key_struct {
00175     int type;
00176     char *type_c; /* Don't free it ! it is static */
00177 #ifdef HAVE_LIBGCRYPT
00178     gcry_sexp_t dsa_pub;
00179     gcry_sexp_t rsa_pub;
00180 #elif HAVE_LIBCRYPTO
00181     DSA *dsa_pub;
00182     RSA *rsa_pub;
00183 #endif
00184 };
00185 
00186 struct private_key_struct {
00187     int type;
00188 #ifdef HAVE_LIBGCRYPT
00189     gcry_sexp_t dsa_priv;
00190     gcry_sexp_t rsa_priv;
00191 #elif defined HAVE_LIBCRYPTO
00192     DSA *dsa_priv;
00193     RSA *rsa_priv;
00194 #endif
00195 };
00196 
00197 typedef struct signature_struct {
00198     int type;
00199 #ifdef HAVE_LIBGCRYPT
00200     gcry_sexp_t dsa_sign;
00201     gcry_sexp_t rsa_sign;
00202 #elif defined HAVE_LIBCRYPTO
00203     DSA_SIG *dsa_sign;
00204     STRING *rsa_sign;
00205 #endif
00206 } SIGNATURE;
00207 
00208 
00209 struct error_struct {
00210 /* error handling */
00211     int error_code;
00212     char error_buffer[ERROR_BUFFERLEN];
00213 };
00214 
00215 struct ssh_options_struct {
00216     struct error_struct error;
00217     char *banner; /* explicit banner to send */
00218     char *username;
00219     char *host;
00220     char *bindaddr;
00221     int bindport;
00222     char *identity;
00223     char *ssh_dir;
00224     char *known_hosts_file;
00225     socket_t fd; /* specificaly wanted file descriptor, don't connect host */
00226     int port;
00227     int dont_verify_hostkey; /* Don't spare time, don't check host key ! unneeded to say it's dangerous and not safe */
00228     int use_nonexisting_algo; /* if user sets a not supported algorithm for kex, don't complain */
00229     char *wanted_methods[10]; /* the kex methods can be choosed. better use the kex fonctions to do that */
00230     void *wanted_cookie; /* wants a specific cookie to be sent ? if null, generate a new one */
00231     void *passphrase_function; /* this functions will be called if a keyphrase is needed. look keyfiles.c for more info */
00232     void (*connect_status_function)(void *arg, float status); /* status callback function */
00233     void *connect_status_arg; /* arbitrary argument */
00234     long timeout; /* seconds */
00235     long timeout_usec;
00236     int ssh2allowed;
00237     int ssh1allowed;
00238     char *dsakey;
00239     char *rsakey; /* host key for server implementation */
00240     int log_verbosity;
00241     void (*log_function)(const char *message, SSH_SESSION *session, int verbosity); //log callback
00242 };
00243 
00244 typedef struct ssh_crypto_struct {
00245     bignum e,f,x,k,y;
00246     unsigned char session_id[SHA_DIGEST_LEN];
00247     
00248     unsigned char encryptIV[SHA_DIGEST_LEN*2];
00249     unsigned char decryptIV[SHA_DIGEST_LEN*2];
00250 
00251     unsigned char decryptkey[SHA_DIGEST_LEN*2];
00252     unsigned char encryptkey[SHA_DIGEST_LEN*2];
00253 
00254     unsigned char encryptMAC[SHA_DIGEST_LEN];
00255     unsigned char decryptMAC[SHA_DIGEST_LEN];
00256     unsigned char hmacbuf[EVP_MAX_MD_SIZE];
00257     struct crypto_struct *in_cipher, *out_cipher; /* the cipher structures/objects */
00258     STRING *server_pubkey;
00259     char *server_pubkey_type;
00260     int do_compress_out; /* idem */
00261     int do_compress_in; /* don't set them, set the option instead */
00262     void *compress_out_ctx; /* don't touch it */
00263     void *compress_in_ctx; /* really, don't */
00264 } CRYPTO;
00265 
00266 struct channel_struct {
00267     struct channel_struct *prev;
00268     struct channel_struct *next;
00269     SSH_SESSION *session; /* SSH_SESSION pointer */
00270     u32 local_channel;
00271     u32 local_window;
00272     int local_eof;
00273     u32 local_maxpacket;
00274 
00275     u32 remote_channel;
00276     u32 remote_window;
00277     int remote_eof; /* end of file received */
00278     u32 remote_maxpacket;
00279     int open; /* shows if the channel is still opened */
00280     int delayed_close;
00281     BUFFER *stdout_buffer;
00282     BUFFER *stderr_buffer;
00283     void *userarg;
00284     int version;
00285     int blocking;
00286 };
00287 
00288 struct ssh_session {
00289     struct error_struct error;
00290     struct socket *socket;
00291     SSH_OPTIONS *options;
00292     char *serverbanner;
00293     char *clientbanner;
00294     int protoversion;
00295     int server;
00296     int client;
00297     u32 send_seq;
00298     u32 recv_seq;
00299 /* status flags */
00300     int closed;
00301     int closed_by_except;
00302     
00303     int connected; 
00304     /* !=0 when the user got a session handle */
00305     int alive;
00306     /* two previous are deprecated */
00307     int auth_service_asked;
00308     
00309 /* socket status */
00310     int blocking; // functions should block
00311     
00312     STRING *banner; /* that's the issue banner from 
00313                        the server */
00314     char *remotebanner; /* that's the SSH- banner from
00315                            remote host. */
00316     char *discon_msg; /* disconnect message from 
00317                          the remote host */
00318     BUFFER *in_buffer;
00319     PACKET in_packet;
00320     BUFFER *out_buffer;
00321        
00322     /* the states are used by the nonblocking stuff to remember */
00323     /* where it was before being interrupted */
00324     int packet_state;
00325     int dh_handshake_state;
00326     STRING *dh_server_signature; //information used by dh_handshake.
00327     
00328     KEX server_kex;
00329     KEX client_kex;
00330     BUFFER *in_hashbuf;
00331     BUFFER *out_hashbuf;
00332     CRYPTO *current_crypto;
00333     CRYPTO *next_crypto;  /* next_crypto is going to be used after a SSH2_MSG_NEWKEYS */
00334 
00335     CHANNEL *channels; /* linked list of channels */
00336     int maxchannel;
00337     int exec_channel_opened; /* version 1 only. more 
00338                                 info in channels1.c */
00339 
00340 /* keyb interactive data */
00341     struct ssh_kbdint *kbdint;
00342     int version; /* 1 or 2 */
00343     /* server host keys */
00344     PRIVATE_KEY *rsa_key;
00345     PRIVATE_KEY *dsa_key;
00346     /* auths accepted by server */
00347     int auth_methods; 
00348     int hostkeys; /* contains type of host key wanted by client, in server impl */
00349     struct ssh_message *ssh_message; /* ssh message */
00350     int log_verbosity; /*cached copy of the option structure */
00351     int log_indent; /* indentation level in enter_function logs */
00352 };
00353 
00354 struct ssh_kbdint {
00355     u32 nprompts;
00356     char *name;
00357     char *instruction;
00358     char **prompts;
00359     unsigned char *echo; /* bool array */
00360     char **answers;
00361 };
00362 
00363 /* server data */
00364 
00365 struct ssh_bind_struct {
00366     struct error_struct error;
00367     socket_t bindfd;
00368     SSH_OPTIONS *options;
00369     int blocking;
00370     int toaccept;
00371 };
00372 
00373 struct ssh_auth_request {
00374     char *username;
00375     int method;
00376     char *password;
00377 };
00378 
00379 struct ssh_channel_request_open {
00380     int type;
00381     u32 sender;
00382     u32 window;
00383     u32 packet_size;
00384     char *originator;
00385     u16 orignator_port;
00386     char *destination;
00387     u16 destination_port;
00388 };
00389 
00390 struct ssh_channel_request {
00391     int type;
00392     CHANNEL *channel;
00393     u8 want_reply;
00394     /* pty-req type specifics */
00395     char *TERM;
00396     u32 width;
00397     u32 height;
00398     u32 pxwidth;
00399     u32 pxheight;
00400     STRING *modes;
00401     
00402     /* env type request */
00403     char *var_name;
00404     char *var_value;
00405     /* exec type request */
00406     char *command;
00407     /* subsystem */
00408     char *subsystem;
00409 };
00410 
00411 struct ssh_message {
00412     SSH_SESSION *session;
00413     int type;
00414     struct ssh_auth_request auth_request;
00415     struct ssh_channel_request_open channel_request_open;
00416     struct ssh_channel_request channel_request;
00417 };
00418 
00419 /* socket.c */
00420 
00421 struct socket;
00422 void ssh_socket_init();
00423 struct socket *ssh_socket_new(SSH_SESSION *session);
00424 void ssh_socket_free(struct socket *s);
00425 void ssh_socket_set_fd(struct socket *s, socket_t fd);
00426 socket_t ssh_socket_get_fd(struct socket *s);
00427 void ssh_socket_close(struct socket *s);
00428 int ssh_socket_read(struct socket *s, void *buffer, int len);
00429 int ssh_socket_write(struct socket *s,const void *buffer, int len);
00430 int ssh_socket_is_open(struct socket *s);
00431 int ssh_socket_fd_isset(struct socket *s, fd_set *set);
00432 void ssh_socket_fd_set(struct socket *s, fd_set *set, int *fd_max);
00433 int ssh_socket_completeread(struct socket *s, void *buffer, int len);
00434 int ssh_socket_wait_for_data(struct socket *s, SSH_SESSION *session,int len);
00435 int ssh_socket_nonblocking_flush(struct socket *s);
00436 int ssh_socket_blocking_flush(struct socket *s);
00437 int ssh_socket_poll(struct socket *s, int *write, int *except);
00438 void ssh_socket_set_towrite(struct socket *s);
00439 void ssh_socket_set_toread(struct socket *s);
00440 void ssh_socket_set_except(struct socket *s);
00441 int ssh_socket_get_status(struct socket *s);
00442 int ssh_socket_data_available(struct socket *s);
00443 int ssh_socket_data_writable(struct socket *s);
00444 /* session.c */
00445 
00446 void ssh_cleanup(SSH_SESSION *session);
00447 
00448 /* client.c */
00449 
00450 int ssh_send_banner(SSH_SESSION *session, int is_server);
00451 char *ssh_get_banner(SSH_SESSION *session);
00452 
00453 /* errors.c */
00454 void ssh_set_error(void *error,int code,char *descr,...);
00455 
00456 /* in dh.c */
00457 /* DH key generation */
00458 void dh_generate_e(SSH_SESSION *session);
00459 void ssh_print_bignum(char *which,bignum num);
00460 void dh_generate_x(SSH_SESSION *session);
00461 void dh_generate_y(SSH_SESSION *session);
00462 void dh_generate_f(SSH_SESSION *session);
00463 void ssh_crypto_finalize();
00464 STRING *dh_get_e(SSH_SESSION *session);
00465 STRING *dh_get_f(SSH_SESSION *session);
00466 void dh_import_f(SSH_SESSION *session,STRING *f_string);
00467 void dh_import_e(SSH_SESSION *session, STRING *e_string);
00468 void dh_import_pubkey(SSH_SESSION *session,STRING *pubkey_string);
00469 void dh_build_k(SSH_SESSION *session);
00470 void make_sessionid(SSH_SESSION *session);
00471 /* add data for the final cookie */
00472 void hashbufin_add_cookie(SSH_SESSION *session,unsigned char *cookie);
00473 void hashbufout_add_cookie(SSH_SESSION *session);
00474 void generate_session_keys(SSH_SESSION *session);
00475 /* returns 1 if server signature ok, 0 otherwise. The NEXT crypto is checked, not the current one */
00476 int signature_verify(SSH_SESSION *session,STRING *signature);
00477 bignum make_string_bn(STRING *string);
00478 STRING *make_bignum_string(bignum num);
00479 
00480 /* in crypt.c */
00481 u32 packet_decrypt_len(SSH_SESSION *session,char *crypted);
00482 int packet_decrypt(SSH_SESSION *session, void *packet,unsigned int len);
00483 unsigned char *packet_encrypt(SSH_SESSION *session,void *packet,unsigned int len);
00484  /* it returns the hmac buffer if exists*/
00485 int packet_hmac_verify(SSH_SESSION *session,BUFFER *buffer,unsigned char *mac);
00486 
00487 /* in packet.c */
00488 
00489 void packet_parse(SSH_SESSION *session);
00490 int packet_send(SSH_SESSION *session);
00491 
00492 int packet_read(SSH_SESSION *session);
00493 int packet_translate(SSH_SESSION *session);
00494 int packet_wait(SSH_SESSION *session,int type,int blocking);
00495 int packet_flush(SSH_SESSION *session, int enforce_blocking);
00496 /* connect.c */
00497 SSH_SESSION *ssh_session_new();
00498 socket_t ssh_connect_host(SSH_SESSION *session, const char *host,const char 
00499         *bind_addr, int port, long timeout, long usec);
00500 
00501 /* in kex.c */
00502 extern char *ssh_kex_nums[];
00503 void ssh_send_kex(SSH_SESSION *session,int server_kex);
00504 void ssh_list_kex(KEX *kex);
00505 int set_kex(SSH_SESSION *session);
00506 int ssh_get_kex(SSH_SESSION *session, int server_kex);
00507 int verify_existing_algo(int algo, const char *name);
00508 char **space_tokenize(const char *chain);
00509 int ssh_get_kex1(SSH_SESSION *session);
00510 char *ssh_find_matching(const char *in_d, const char *what_d);
00511 
00512 /* in keyfiles.c */
00513 
00514 PRIVATE_KEY  *_privatekey_from_file(void *session,char *filename,int type);
00515 
00516 /* in keys.c */
00517 char *ssh_type_to_char(int type);
00518 PUBLIC_KEY *publickey_make_dss(SSH_SESSION *session, BUFFER *buffer);
00519 PUBLIC_KEY *publickey_make_rsa(SSH_SESSION *session, BUFFER *buffer,char *type);
00520 PUBLIC_KEY *publickey_from_string(SSH_SESSION *session, STRING *pubkey_s);
00521 SIGNATURE *signature_from_string(SSH_SESSION *session, STRING *signature,PUBLIC_KEY *pubkey,int needed_type);
00522 void signature_free(SIGNATURE *sign);
00523 STRING *ssh_do_sign(SSH_SESSION *session,BUFFER *sigbuf, 
00524         PRIVATE_KEY *privatekey);
00525 STRING *ssh_sign_session_id(SSH_SESSION *session, PRIVATE_KEY *privatekey);
00526 STRING *ssh_encrypt_rsa1(SSH_SESSION *session, STRING *data, PUBLIC_KEY *key);
00527 /* channel.c */
00528 void channel_handle(SSH_SESSION *session, int type);
00529 CHANNEL *channel_new(SSH_SESSION *session);
00530 void channel_default_bufferize(CHANNEL *channel, void *data, int len,
00531         int is_stderr);
00532 u32 ssh_channel_new_id(SSH_SESSION *session);
00533 CHANNEL *ssh_channel_from_local(SSH_SESSION *session,u32 num);
00534 
00535 /* options.c */
00536 
00537 void ssh_options_free(SSH_OPTIONS *opt);
00538 /* this function must be called when no specific username has been asked. it has to guess it */
00539 int ssh_options_default_username(SSH_OPTIONS *opt);
00540 int ssh_options_default_ssh_dir(SSH_OPTIONS *opt);
00541 int ssh_options_default_known_hosts_file(SSH_OPTIONS *opt);
00542 
00543 /* buffer.c */
00544 void buffer_add_ssh_string(BUFFER *buffer,STRING *string);
00545 void buffer_add_u8(BUFFER *buffer, u8 data);
00546 void buffer_add_u32(BUFFER *buffer, u32 data);
00547 void buffer_add_u64(BUFFER *buffer,u64 data);
00548 void buffer_add_data(BUFFER *buffer,const void *data, int len);
00549 void buffer_add_data_begin(BUFFER *buffer,const void *data,int len);
00550 void buffer_add_buffer(BUFFER *buffer, BUFFER *source);
00551 void buffer_reinit(BUFFER *buffer);
00552 
00553 /* buffer_get_rest returns a pointer to the current position into the buffer */
00554 void *buffer_get_rest(BUFFER *buffer);
00555 /* buffer_get_rest_len returns the number of bytes which can be read */
00556 int buffer_get_rest_len(BUFFER *buffer);
00557 
00558 /* buffer_read_*() returns the number of bytes read, except for ssh strings */
00559 int buffer_get_u8(BUFFER *buffer,u8 *data);
00560 int buffer_get_u32(BUFFER *buffer,u32 *data);
00561 int buffer_get_u64(BUFFER *buffer, u64 *data);
00562 
00563 int buffer_get_data(BUFFER *buffer,void *data,int requestedlen);
00564 /* buffer_get_ssh_string() is an exception. if the String read is too large or invalid, it will answer NULL. */
00565 STRING *buffer_get_ssh_string(BUFFER *buffer);
00566 /* gets a string out of a SSH-1 mpint */
00567 STRING *buffer_get_mpint(BUFFER *buffer);
00568 /* buffer_pass_bytes acts as if len bytes have been read (used for padding) */
00569 int buffer_pass_bytes_end(BUFFER *buffer,int len);
00570 int buffer_pass_bytes(BUFFER *buffer, int len);
00571 
00572 /* in base64.c */
00573 BUFFER *base64_to_bin(char *source);
00574 unsigned char *bin_to_base64(unsigned char *source, int len);
00575 
00576 /* gzip.c */
00577 int compress_buffer(SSH_SESSION *session,BUFFER *buf);
00578 int decompress_buffer(SSH_SESSION *session,BUFFER *buf);
00579 
00580 /* wrapper.c */
00581 int crypt_set_algorithms(SSH_SESSION *);
00582 int crypt_set_algorithms_server(SSH_SESSION *session);
00583 CRYPTO *crypto_new();
00584 void crypto_free(CRYPTO *crypto);
00585 
00586 /* crc32.c */
00587 u32 ssh_crc32(char *buffer, int len);
00588 
00589 /* auth1.c */
00590 int ssh_userauth1_none(SSH_SESSION *session, char *username);
00591 int ssh_userauth1_offer_pubkey(SSH_SESSION *session, char *username,
00592         int type, STRING *pubkey);
00593 int ssh_userauth1_password(SSH_SESSION *session, char *username, 
00594         char *password);
00595 /* in misc.c */
00596 /* gets the user home dir. */
00597 char *ssh_get_user_home_dir();
00598 int ssh_file_readaccess_ok(char *file);
00599 
00600 /* macro for byte ordering */
00601 u64 ntohll(u64);
00602 #define htonll(x) ntohll(x)
00603 
00604 /* channels1.c */
00605 int channel_open_session1(CHANNEL *channel);
00606 int channel_request_pty_size1(CHANNEL *channel, char *terminal,int cols, 
00607         int rows);
00608 int channel_change_pty_size1(CHANNEL *channel, int cols, int rows);
00609 int channel_request_shell1(CHANNEL *channel);
00610 int channel_request_exec1(CHANNEL *channel, char *cmd);
00611 void channel_handle1(SSH_SESSION *session,int type);
00612 int channel_write1(CHANNEL *channel, void *data, int len);
00613 
00614 /* session.c */
00615 
00616 int ssh_handle_packets(SSH_SESSION *session);
00617 
00618 /* log.c */
00619 
00620 #define _enter_function(sess) \
00621         do {\
00622                 if((sess)->log_verbosity >= SSH_LOG_FUNCTIONS){ \
00623                         ssh_log((sess),SSH_LOG_FUNCTIONS,"entering function %s line %d in " __FILE__ , __FUNCTION__,__LINE__);\
00624                         (sess)->log_indent++; \
00625                 } \
00626         } while(0)
00627 
00628 #define _leave_function(sess) \
00629         do { \
00630                 if((sess)->log_verbosity >= SSH_LOG_FUNCTIONS){ \
00631                         (sess)->log_indent--; \
00632                         ssh_log((sess),SSH_LOG_FUNCTIONS,"leaving function %s line %d in " __FILE__ , __FUNCTION__,__LINE__);\
00633                 }\
00634         } while(0)
00635 
00636 #define enter_function() _enter_function(session)
00637 #define leave_function() _leave_function(session)
00638 
00639 #ifdef HAVE_LIBGCRYPT
00640 /* gcrypt_missing.c */
00641 int my_gcry_dec2bn(bignum *bn, const char *data);
00642 char *my_gcry_bn2dec(bignum bn);
00643 #endif /* !HAVE_LIBGCRYPT */
00644 
00645 #ifdef __cplusplus
00646 } 
00647 #endif
00648 
00649 #endif /* _LIBSSH_PRIV_H */

Generated on Sun Aug 23 08:55:35 2009 for libssh by  doxygen 1.4.7