1
1

fixed compiler warnings, and stripped off "libssh2_" from static functions

as that makes shorter function names and then making the code look fine within
80 columns is easier!
Этот коммит содержится в:
Daniel Stenberg 2009-01-01 22:47:06 +00:00
родитель 97fbb77da5
Коммит 369fcddb24
3 изменённых файлов: 172 добавлений и 178 удалений

223
src/kex.c
Просмотреть файл

@ -38,7 +38,7 @@
#include "libssh2_priv.h" #include "libssh2_priv.h"
/* TODO: Switch this to an inline and handle alloc() failures */ /* TODO: Switch this to an inline and handle alloc() failures */
/* Helper macro called from libssh2_kex_method_diffie_hellman_group1_sha1_key_exchange */ /* Helper macro called from kex_method_diffie_hellman_group1_sha1_key_exchange */
#define LIBSSH2_KEX_METHOD_DIFFIE_HELLMAN_SHA1_HASH(value, reqlen, version) \ #define LIBSSH2_KEX_METHOD_DIFFIE_HELLMAN_SHA1_HASH(value, reqlen, version) \
{ \ { \
libssh2_sha1_ctx hash; \ libssh2_sha1_ctx hash; \
@ -65,12 +65,11 @@
} \ } \
} }
/* {{{ libssh2_kex_method_diffie_hellman_groupGP_sha1_key_exchange /* {{{ kex_method_diffie_hellman_groupGP_sha1_key_exchange
* Diffie Hellman Key Exchange, Group Agnostic * Diffie Hellman Key Exchange, Group Agnostic
*/ */
static int static int
libssh2_kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION * kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
session,
_libssh2_bn * g, _libssh2_bn * g,
_libssh2_bn * p, _libssh2_bn * p,
int group_order, int group_order,
@ -78,10 +77,8 @@ libssh2_kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *
packet_type_init, packet_type_init,
unsigned char unsigned char
packet_type_reply, packet_type_reply,
unsigned char unsigned char *midhash,
*midhash, unsigned long midhash_len,
unsigned long
midhash_len,
kmdhgGPsha1kex_state_t kmdhgGPsha1kex_state_t
* exchange_state) * exchange_state)
{ {
@ -652,12 +649,11 @@ libssh2_kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *
/* }}} */ /* }}} */
/* {{{ libssh2_kex_method_diffie_hellman_group1_sha1_key_exchange /* {{{ kex_method_diffie_hellman_group1_sha1_key_exchange
* Diffie-Hellman Group1 (Actually Group2) Key Exchange using SHA1 * Diffie-Hellman Group1 (Actually Group2) Key Exchange using SHA1
*/ */
static int static int
libssh2_kex_method_diffie_hellman_group1_sha1_key_exchange(LIBSSH2_SESSION * kex_method_diffie_hellman_group1_sha1_key_exchange(LIBSSH2_SESSION *session,
session,
key_exchange_state_low_t key_exchange_state_low_t
* key_state) * key_state)
{ {
@ -698,11 +694,9 @@ libssh2_kex_method_diffie_hellman_group1_sha1_key_exchange(LIBSSH2_SESSION *
} }
ret = ret =
libssh2_kex_method_diffie_hellman_groupGP_sha1_key_exchange(session, kex_method_diffie_hellman_groupGP_sha1_key_exchange(session,
key_state-> key_state->g,
g, key_state->p, 128,
key_state->
p, 128,
SSH_MSG_KEXDH_INIT, SSH_MSG_KEXDH_INIT,
SSH_MSG_KEXDH_REPLY, SSH_MSG_KEXDH_REPLY,
NULL, 0, NULL, 0,
@ -723,12 +717,11 @@ libssh2_kex_method_diffie_hellman_group1_sha1_key_exchange(LIBSSH2_SESSION *
/* }}} */ /* }}} */
/* {{{ libssh2_kex_method_diffie_hellman_group14_sha1_key_exchange /* {{{ kex_method_diffie_hellman_group14_sha1_key_exchange
* Diffie-Hellman Group14 Key Exchange using SHA1 * Diffie-Hellman Group14 Key Exchange using SHA1
*/ */
static int static int
libssh2_kex_method_diffie_hellman_group14_sha1_key_exchange(LIBSSH2_SESSION * kex_method_diffie_hellman_group14_sha1_key_exchange(LIBSSH2_SESSION *session,
session,
key_exchange_state_low_t key_exchange_state_low_t
* key_state) * key_state)
{ {
@ -783,11 +776,10 @@ libssh2_kex_method_diffie_hellman_group14_sha1_key_exchange(LIBSSH2_SESSION *
key_state->state = libssh2_NB_state_created; key_state->state = libssh2_NB_state_created;
} }
ret = ret =
libssh2_kex_method_diffie_hellman_groupGP_sha1_key_exchange(session, kex_method_diffie_hellman_groupGP_sha1_key_exchange(session,
key_state-> key_state->g,
g, key_state->p,
key_state-> 256,
p, 256,
SSH_MSG_KEXDH_INIT, SSH_MSG_KEXDH_INIT,
SSH_MSG_KEXDH_REPLY, SSH_MSG_KEXDH_REPLY,
NULL, 0, NULL, 0,
@ -808,12 +800,12 @@ libssh2_kex_method_diffie_hellman_group14_sha1_key_exchange(LIBSSH2_SESSION *
/* }}} */ /* }}} */
/* {{{ libssh2_kex_method_diffie_hellman_group_exchange_sha1_key_exchange /* {{{ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
* Diffie-Hellman Group Exchange Key Exchange using SHA1 * Diffie-Hellman Group Exchange Key Exchange using SHA1
* Negotiates random(ish) group for secret derivation * Negotiates random(ish) group for secret derivation
*/ */
static int static int
libssh2_kex_method_diffie_hellman_group_exchange_sha1_key_exchange kex_method_diffie_hellman_group_exchange_sha1_key_exchange
(LIBSSH2_SESSION * session, key_exchange_state_low_t * key_state) (LIBSSH2_SESSION * session, key_exchange_state_low_t * key_state)
{ {
unsigned char *s; unsigned char *s;
@ -888,7 +880,7 @@ static int
s += g_len; s += g_len;
ret = ret =
libssh2_kex_method_diffie_hellman_groupGP_sha1_key_exchange kex_method_diffie_hellman_groupGP_sha1_key_exchange
(session, key_state->g, key_state->p, p_len, (session, key_state->g, key_state->p, p_len,
SSH_MSG_KEX_DH_GEX_INIT, SSH_MSG_KEX_DH_GEX_REPLY, SSH_MSG_KEX_DH_GEX_INIT, SSH_MSG_KEX_DH_GEX_REPLY,
key_state->data + 1, key_state->data_len - 1, key_state->data + 1, key_state->data_len - 1,
@ -915,29 +907,29 @@ static int
#define LIBSSH2_KEX_METHOD_FLAG_REQ_ENC_HOSTKEY 0x0001 #define LIBSSH2_KEX_METHOD_FLAG_REQ_ENC_HOSTKEY 0x0001
#define LIBSSH2_KEX_METHOD_FLAG_REQ_SIGN_HOSTKEY 0x0002 #define LIBSSH2_KEX_METHOD_FLAG_REQ_SIGN_HOSTKEY 0x0002
static const LIBSSH2_KEX_METHOD libssh2_kex_method_diffie_helman_group1_sha1 = { static const LIBSSH2_KEX_METHOD kex_method_diffie_helman_group1_sha1 = {
"diffie-hellman-group1-sha1", "diffie-hellman-group1-sha1",
libssh2_kex_method_diffie_hellman_group1_sha1_key_exchange, kex_method_diffie_hellman_group1_sha1_key_exchange,
LIBSSH2_KEX_METHOD_FLAG_REQ_SIGN_HOSTKEY, LIBSSH2_KEX_METHOD_FLAG_REQ_SIGN_HOSTKEY,
}; };
static const LIBSSH2_KEX_METHOD libssh2_kex_method_diffie_helman_group14_sha1 = { static const LIBSSH2_KEX_METHOD kex_method_diffie_helman_group14_sha1 = {
"diffie-hellman-group14-sha1", "diffie-hellman-group14-sha1",
libssh2_kex_method_diffie_hellman_group14_sha1_key_exchange, kex_method_diffie_hellman_group14_sha1_key_exchange,
LIBSSH2_KEX_METHOD_FLAG_REQ_SIGN_HOSTKEY, LIBSSH2_KEX_METHOD_FLAG_REQ_SIGN_HOSTKEY,
}; };
static const LIBSSH2_KEX_METHOD static const LIBSSH2_KEX_METHOD
libssh2_kex_method_diffie_helman_group_exchange_sha1 = { kex_method_diffie_helman_group_exchange_sha1 = {
"diffie-hellman-group-exchange-sha1", "diffie-hellman-group-exchange-sha1",
libssh2_kex_method_diffie_hellman_group_exchange_sha1_key_exchange, kex_method_diffie_hellman_group_exchange_sha1_key_exchange,
LIBSSH2_KEX_METHOD_FLAG_REQ_SIGN_HOSTKEY, LIBSSH2_KEX_METHOD_FLAG_REQ_SIGN_HOSTKEY,
}; };
static const LIBSSH2_KEX_METHOD *libssh2_kex_methods[] = { static const LIBSSH2_KEX_METHOD *libssh2_kex_methods[] = {
&libssh2_kex_method_diffie_helman_group14_sha1, &kex_method_diffie_helman_group14_sha1,
&libssh2_kex_method_diffie_helman_group_exchange_sha1, &kex_method_diffie_helman_group_exchange_sha1,
&libssh2_kex_method_diffie_helman_group1_sha1, &kex_method_diffie_helman_group1_sha1,
NULL NULL
}; };
@ -946,13 +938,13 @@ typedef struct _LIBSSH2_COMMON_METHOD
const char *name; const char *name;
} LIBSSH2_COMMON_METHOD; } LIBSSH2_COMMON_METHOD;
/* {{{ libssh2_kex_method_strlen /* {{{ kex_method_strlen
* Calculate the length of a particular method list's resulting string * Calculate the length of a particular method list's resulting string
* Includes SUM(strlen() of each individual method plus 1 (for coma)) - 1 (because the last coma isn't used) * Includes SUM(strlen() of each individual method plus 1 (for coma)) - 1 (because the last coma isn't used)
* Another sign of bad coding practices gone mad. Pretend you don't see this. * Another sign of bad coding practices gone mad. Pretend you don't see this.
*/ */
static size_t static size_t
libssh2_kex_method_strlen(LIBSSH2_COMMON_METHOD ** method) kex_method_strlen(LIBSSH2_COMMON_METHOD ** method)
{ {
size_t len = 0; size_t len = 0;
@ -970,11 +962,11 @@ libssh2_kex_method_strlen(LIBSSH2_COMMON_METHOD ** method)
/* }}} */ /* }}} */
/* {{{ libssh2_kex_method_list /* {{{ kex_method_list
* Generate formatted preference list in buf * Generate formatted preference list in buf
*/ */
static size_t static size_t
libssh2_kex_method_list(unsigned char *buf, size_t list_strlen, kex_method_list(unsigned char *buf, size_t list_strlen,
LIBSSH2_COMMON_METHOD ** method) LIBSSH2_COMMON_METHOD ** method)
{ {
libssh2_htonu32(buf, list_strlen); libssh2_htonu32(buf, list_strlen);
@ -997,7 +989,10 @@ libssh2_kex_method_list(unsigned char *buf, size_t list_strlen,
/* }}} */ /* }}} */
#define LIBSSH2_METHOD_PREFS_LEN(prefvar, defaultvar) ((prefvar) ? strlen(prefvar) : libssh2_kex_method_strlen((LIBSSH2_COMMON_METHOD**)(defaultvar))) #define LIBSSH2_METHOD_PREFS_LEN(prefvar, defaultvar) \
((prefvar) ? strlen(prefvar) : \
kex_method_strlen((LIBSSH2_COMMON_METHOD**)(defaultvar)))
#define LIBSSH2_METHOD_PREFS_STR(buf, prefvarlen, prefvar, defaultvar) \ #define LIBSSH2_METHOD_PREFS_STR(buf, prefvarlen, prefvar, defaultvar) \
if (prefvar) { \ if (prefvar) { \
libssh2_htonu32((buf), (prefvarlen)); \ libssh2_htonu32((buf), (prefvarlen)); \
@ -1005,14 +1000,14 @@ libssh2_kex_method_list(unsigned char *buf, size_t list_strlen,
memcpy((buf), (prefvar), (prefvarlen)); \ memcpy((buf), (prefvar), (prefvarlen)); \
buf += (prefvarlen); \ buf += (prefvarlen); \
} else { \ } else { \
buf += libssh2_kex_method_list((buf), (prefvarlen), (LIBSSH2_COMMON_METHOD**)(defaultvar)); \ buf += kex_method_list((buf), (prefvarlen), \
(LIBSSH2_COMMON_METHOD**)(defaultvar)); \
} }
/* {{{ libssh2_kexinit /* {{{ kexinit
* Send SSH_MSG_KEXINIT packet * Send SSH_MSG_KEXINIT packet
*/ */
static int static int kexinit(LIBSSH2_SESSION * session)
libssh2_kexinit(LIBSSH2_SESSION * session)
{ {
/* 62 = packet_type(1) + cookie(16) + first_packet_follows(1) + /* 62 = packet_type(1) + cookie(16) + first_packet_follows(1) +
reserved(4) + length longs(40) */ reserved(4) + length longs(40) */
@ -1167,12 +1162,12 @@ libssh2_kexinit(LIBSSH2_SESSION * session)
/* }}} */ /* }}} */
/* {{{ libssh2_kex_agree_instr /* {{{ kex_agree_instr
* Kex specific variant of strstr() * Kex specific variant of strstr()
* Needle must be preceed by BOL or ',', and followed by ',' or EOL * Needle must be preceed by BOL or ',', and followed by ',' or EOL
*/ */
static unsigned char * static unsigned char *
libssh2_kex_agree_instr(unsigned char *haystack, unsigned long haystack_len, kex_agree_instr(unsigned char *haystack, unsigned long haystack_len,
const unsigned char *needle, unsigned long needle_len) const unsigned char *needle, unsigned long needle_len)
{ {
unsigned char *s; unsigned char *s;
@ -1207,10 +1202,10 @@ libssh2_kex_agree_instr(unsigned char *haystack, unsigned long haystack_len,
/* }}} */ /* }}} */
/* {{{ libssh2_get_method_by_name /* {{{ kex_get_method_by_name
*/ */
static const LIBSSH2_COMMON_METHOD * static const LIBSSH2_COMMON_METHOD *
libssh2_get_method_by_name(const char *name, int name_len, kex_get_method_by_name(const char *name, size_t name_len,
const LIBSSH2_COMMON_METHOD ** methodlist) const LIBSSH2_COMMON_METHOD ** methodlist)
{ {
while (*methodlist) { while (*methodlist) {
@ -1225,11 +1220,11 @@ libssh2_get_method_by_name(const char *name, int name_len,
/* }}} */ /* }}} */
/* {{{ libssh2_kex_agree_hostkey /* {{{ kex_agree_hostkey
* Agree on a Hostkey which works with this kex * Agree on a Hostkey which works with this kex
*/ */
static int static int kex_agree_hostkey(LIBSSH2_SESSION * session,
libssh2_kex_agree_hostkey(LIBSSH2_SESSION * session, unsigned long kex_flags, unsigned long kex_flags,
unsigned char *hostkey, unsigned long hostkey_len) unsigned char *hostkey, unsigned long hostkey_len)
{ {
const LIBSSH2_HOSTKEY_METHOD **hostkeyp = libssh2_hostkey_methods(); const LIBSSH2_HOSTKEY_METHOD **hostkeyp = libssh2_hostkey_methods();
@ -1240,11 +1235,11 @@ libssh2_kex_agree_hostkey(LIBSSH2_SESSION * session, unsigned long kex_flags,
while (s && *s) { while (s && *s) {
unsigned char *p = (unsigned char *) strchr((char *) s, ','); unsigned char *p = (unsigned char *) strchr((char *) s, ',');
int method_len = (p ? (p - s) : strlen((char *) s)); size_t method_len = (p ? (size_t)(p - s) : strlen((char *) s));
if (libssh2_kex_agree_instr(hostkey, hostkey_len, s, method_len)) { if (kex_agree_instr(hostkey, hostkey_len, s, method_len)) {
const LIBSSH2_HOSTKEY_METHOD *method = const LIBSSH2_HOSTKEY_METHOD *method =
(const LIBSSH2_HOSTKEY_METHOD *) (const LIBSSH2_HOSTKEY_METHOD *)
libssh2_get_method_by_name((char *) s, method_len, kex_get_method_by_name((char *) s, method_len,
(const LIBSSH2_COMMON_METHOD **) (const LIBSSH2_COMMON_METHOD **)
hostkeyp); hostkeyp);
@ -1253,13 +1248,16 @@ libssh2_kex_agree_hostkey(LIBSSH2_SESSION * session, unsigned long kex_flags,
return -1; return -1;
} }
/* So far so good, but does it suit our purposes? (Encrypting vs Signing) */ /* So far so good, but does it suit our purposes? (Encrypting
vs Signing) */
if (((kex_flags & LIBSSH2_KEX_METHOD_FLAG_REQ_ENC_HOSTKEY) == if (((kex_flags & LIBSSH2_KEX_METHOD_FLAG_REQ_ENC_HOSTKEY) ==
0) || (method->encrypt)) { 0) || (method->encrypt)) {
/* Either this hostkey can do encryption or this kex just doesn't require it */ /* Either this hostkey can do encryption or this kex just
doesn't require it */
if (((kex_flags & LIBSSH2_KEX_METHOD_FLAG_REQ_SIGN_HOSTKEY) if (((kex_flags & LIBSSH2_KEX_METHOD_FLAG_REQ_SIGN_HOSTKEY)
== 0) || (method->sig_verify)) { == 0) || (method->sig_verify)) {
/* Either this hostkey can do signing or this kex just doesn't require it */ /* Either this hostkey can do signing or this kex just
doesn't require it */
session->hostkey = method; session->hostkey = method;
return 0; return 0;
} }
@ -1272,17 +1270,20 @@ libssh2_kex_agree_hostkey(LIBSSH2_SESSION * session, unsigned long kex_flags,
} }
while (hostkeyp && (*hostkeyp)->name) { while (hostkeyp && (*hostkeyp)->name) {
s = libssh2_kex_agree_instr(hostkey, hostkey_len, s = kex_agree_instr(hostkey, hostkey_len,
(unsigned char *) (*hostkeyp)->name, (unsigned char *) (*hostkeyp)->name,
strlen((*hostkeyp)->name)); strlen((*hostkeyp)->name));
if (s) { if (s) {
/* So far so good, but does it suit our purposes? (Encrypting vs Signing) */ /* So far so good, but does it suit our purposes? (Encrypting vs
Signing) */
if (((kex_flags & LIBSSH2_KEX_METHOD_FLAG_REQ_ENC_HOSTKEY) == 0) || if (((kex_flags & LIBSSH2_KEX_METHOD_FLAG_REQ_ENC_HOSTKEY) == 0) ||
((*hostkeyp)->encrypt)) { ((*hostkeyp)->encrypt)) {
/* Either this hostkey can do encryption or this kex just doesn't require it */ /* Either this hostkey can do encryption or this kex just
doesn't require it */
if (((kex_flags & LIBSSH2_KEX_METHOD_FLAG_REQ_SIGN_HOSTKEY) == if (((kex_flags & LIBSSH2_KEX_METHOD_FLAG_REQ_SIGN_HOSTKEY) ==
0) || ((*hostkeyp)->sig_verify)) { 0) || ((*hostkeyp)->sig_verify)) {
/* Either this hostkey can do signing or this kex just doesn't require it */ /* Either this hostkey can do signing or this kex just
doesn't require it */
session->hostkey = *hostkeyp; session->hostkey = *hostkeyp;
return 0; return 0;
} }
@ -1296,11 +1297,10 @@ libssh2_kex_agree_hostkey(LIBSSH2_SESSION * session, unsigned long kex_flags,
/* }}} */ /* }}} */
/* {{{ libssh2_kex_agree_kex_hostkey /* {{{ kex_agree_kex_hostkey
* Agree on a Key Exchange method and a hostkey encoding type * Agree on a Key Exchange method and a hostkey encoding type
*/ */
static int static int kex_agree_kex_hostkey(LIBSSH2_SESSION * session, unsigned char *kex,
libssh2_kex_agree_kex_hostkey(LIBSSH2_SESSION * session, unsigned char *kex,
unsigned long kex_len, unsigned char *hostkey, unsigned long kex_len, unsigned char *hostkey,
unsigned long hostkey_len) unsigned long hostkey_len)
{ {
@ -1312,10 +1312,10 @@ libssh2_kex_agree_kex_hostkey(LIBSSH2_SESSION * session, unsigned char *kex,
while (s && *s) { while (s && *s) {
unsigned char *q, *p = (unsigned char *) strchr((char *) s, ','); unsigned char *q, *p = (unsigned char *) strchr((char *) s, ',');
int method_len = (p ? (p - s) : strlen((char *) s)); size_t method_len = (p ? (size_t)(p - s) : strlen((char *) s));
if ((q = libssh2_kex_agree_instr(kex, kex_len, s, method_len))) { if ((q = kex_agree_instr(kex, kex_len, s, method_len))) {
const LIBSSH2_KEX_METHOD *method = (const LIBSSH2_KEX_METHOD *) const LIBSSH2_KEX_METHOD *method = (const LIBSSH2_KEX_METHOD *)
libssh2_get_method_by_name((char *) s, method_len, kex_get_method_by_name((char *) s, method_len,
(const LIBSSH2_COMMON_METHOD **) (const LIBSSH2_COMMON_METHOD **)
kexp); kexp);
@ -1327,8 +1327,8 @@ libssh2_kex_agree_kex_hostkey(LIBSSH2_SESSION * session, unsigned char *kex,
/* We've agreed on a key exchange method, /* We've agreed on a key exchange method,
* Can we agree on a hostkey that works with this kex? * Can we agree on a hostkey that works with this kex?
*/ */
if (libssh2_kex_agree_hostkey if (kex_agree_hostkey(session, method->flags, hostkey,
(session, method->flags, hostkey, hostkey_len) == 0) { hostkey_len) == 0) {
session->kex = method; session->kex = method;
if (session->burn_optimistic_kexinit && (kex == q)) { if (session->burn_optimistic_kexinit && (kex == q)) {
/* Server sent an optimistic packet, /* Server sent an optimistic packet,
@ -1346,15 +1346,15 @@ libssh2_kex_agree_kex_hostkey(LIBSSH2_SESSION * session, unsigned char *kex,
} }
while (*kexp && (*kexp)->name) { while (*kexp && (*kexp)->name) {
s = libssh2_kex_agree_instr(kex, kex_len, s = kex_agree_instr(kex, kex_len,
(unsigned char *) (*kexp)->name, (unsigned char *) (*kexp)->name,
strlen((*kexp)->name)); strlen((*kexp)->name));
if (s) { if (s) {
/* We've agreed on a key exchange method, /* We've agreed on a key exchange method,
* Can we agree on a hostkey that works with this kex? * Can we agree on a hostkey that works with this kex?
*/ */
if (libssh2_kex_agree_hostkey if (kex_agree_hostkey(session, (*kexp)->flags, hostkey,
(session, (*kexp)->flags, hostkey, hostkey_len) == 0) { hostkey_len) == 0) {
session->kex = *kexp; session->kex = *kexp;
if (session->burn_optimistic_kexinit && (kex == s)) { if (session->burn_optimistic_kexinit && (kex == s)) {
/* Server sent an optimistic packet, /* Server sent an optimistic packet,
@ -1372,12 +1372,12 @@ libssh2_kex_agree_kex_hostkey(LIBSSH2_SESSION * session, unsigned char *kex,
/* }}} */ /* }}} */
/* {{{ libssh2_kex_agree_crypt /* {{{ kex_agree_crypt
* Agree on a cipher algo * Agree on a cipher algo
*/ */
static int static int kex_agree_crypt(LIBSSH2_SESSION * session,
libssh2_kex_agree_crypt(LIBSSH2_SESSION * session, libssh2_endpoint_data *endpoint,
libssh2_endpoint_data * endpoint, unsigned char *crypt, unsigned char *crypt,
unsigned long crypt_len) unsigned long crypt_len)
{ {
const LIBSSH2_CRYPT_METHOD **cryptp = libssh2_crypt_methods(); const LIBSSH2_CRYPT_METHOD **cryptp = libssh2_crypt_methods();
@ -1390,12 +1390,12 @@ libssh2_kex_agree_crypt(LIBSSH2_SESSION * session,
while (s && *s) { while (s && *s) {
unsigned char *p = (unsigned char *) strchr((char *) s, ','); unsigned char *p = (unsigned char *) strchr((char *) s, ',');
int method_len = (p ? (p - s) : strlen((char *) s)); size_t method_len = (p ? (size_t)(p - s) : strlen((char *) s));
if (libssh2_kex_agree_instr(crypt, crypt_len, s, method_len)) { if (kex_agree_instr(crypt, crypt_len, s, method_len)) {
const LIBSSH2_CRYPT_METHOD *method = const LIBSSH2_CRYPT_METHOD *method =
(const LIBSSH2_CRYPT_METHOD *) (const LIBSSH2_CRYPT_METHOD *)
libssh2_get_method_by_name((char *) s, method_len, kex_get_method_by_name((char *) s, method_len,
(const LIBSSH2_COMMON_METHOD **) (const LIBSSH2_COMMON_METHOD **)
cryptp); cryptp);
@ -1414,7 +1414,7 @@ libssh2_kex_agree_crypt(LIBSSH2_SESSION * session,
} }
while (*cryptp && (*cryptp)->name) { while (*cryptp && (*cryptp)->name) {
s = libssh2_kex_agree_instr(crypt, crypt_len, s = kex_agree_instr(crypt, crypt_len,
(unsigned char *) (*cryptp)->name, (unsigned char *) (*cryptp)->name,
strlen((*cryptp)->name)); strlen((*cryptp)->name));
if (s) { if (s) {
@ -1429,11 +1429,10 @@ libssh2_kex_agree_crypt(LIBSSH2_SESSION * session,
/* }}} */ /* }}} */
/* {{{ libssh2_kex_agree_mac /* {{{ kex_agree_mac
* Agree on a message authentication hash * Agree on a message authentication hash
*/ */
static int static int kex_agree_mac(LIBSSH2_SESSION * session,
libssh2_kex_agree_mac(LIBSSH2_SESSION * session,
libssh2_endpoint_data * endpoint, unsigned char *mac, libssh2_endpoint_data * endpoint, unsigned char *mac,
unsigned long mac_len) unsigned long mac_len)
{ {
@ -1446,11 +1445,11 @@ libssh2_kex_agree_mac(LIBSSH2_SESSION * session,
while (s && *s) { while (s && *s) {
unsigned char *p = (unsigned char *) strchr((char *) s, ','); unsigned char *p = (unsigned char *) strchr((char *) s, ',');
int method_len = (p ? (p - s) : strlen((char *) s)); size_t method_len = (p ? (size_t)(p - s) : strlen((char *) s));
if (libssh2_kex_agree_instr(mac, mac_len, s, method_len)) { if (kex_agree_instr(mac, mac_len, s, method_len)) {
const LIBSSH2_MAC_METHOD *method = (const LIBSSH2_MAC_METHOD *) const LIBSSH2_MAC_METHOD *method = (const LIBSSH2_MAC_METHOD *)
libssh2_get_method_by_name((char *) s, method_len, kex_get_method_by_name((char *) s, method_len,
(const LIBSSH2_COMMON_METHOD **) (const LIBSSH2_COMMON_METHOD **)
macp); macp);
@ -1469,8 +1468,7 @@ libssh2_kex_agree_mac(LIBSSH2_SESSION * session,
} }
while (*macp && (*macp)->name) { while (*macp && (*macp)->name) {
s = libssh2_kex_agree_instr(mac, mac_len, s = kex_agree_instr(mac, mac_len, (unsigned char *) (*macp)->name,
(unsigned char *) (*macp)->name,
strlen((*macp)->name)); strlen((*macp)->name));
if (s) { if (s) {
endpoint->mac = *macp; endpoint->mac = *macp;
@ -1484,11 +1482,10 @@ libssh2_kex_agree_mac(LIBSSH2_SESSION * session,
/* }}} */ /* }}} */
/* {{{ libssh2_kex_agree_comp /* {{{ kex_agree_comp
* Agree on a compression scheme * Agree on a compression scheme
*/ */
static int static int kex_agree_comp(LIBSSH2_SESSION * session,
libssh2_kex_agree_comp(LIBSSH2_SESSION * session,
libssh2_endpoint_data * endpoint, unsigned char *comp, libssh2_endpoint_data * endpoint, unsigned char *comp,
unsigned long comp_len) unsigned long comp_len)
{ {
@ -1501,12 +1498,12 @@ libssh2_kex_agree_comp(LIBSSH2_SESSION * session,
while (s && *s) { while (s && *s) {
unsigned char *p = (unsigned char *) strchr((char *) s, ','); unsigned char *p = (unsigned char *) strchr((char *) s, ',');
int method_len = (p ? (p - s) : strlen((char *) s)); size_t method_len = (p ? (size_t)(p - s) : strlen((char *) s));
if (libssh2_kex_agree_instr(comp, comp_len, s, method_len)) { if (kex_agree_instr(comp, comp_len, s, method_len)) {
const LIBSSH2_COMP_METHOD *method = const LIBSSH2_COMP_METHOD *method =
(const LIBSSH2_COMP_METHOD *) (const LIBSSH2_COMP_METHOD *)
libssh2_get_method_by_name((char *) s, method_len, kex_get_method_by_name((char *) s, method_len,
(const LIBSSH2_COMMON_METHOD **) (const LIBSSH2_COMMON_METHOD **)
compp); compp);
@ -1525,8 +1522,7 @@ libssh2_kex_agree_comp(LIBSSH2_SESSION * session,
} }
while (*compp && (*compp)->name) { while (*compp && (*compp)->name) {
s = libssh2_kex_agree_instr(comp, comp_len, s = kex_agree_instr(comp, comp_len, (unsigned char *) (*compp)->name,
(unsigned char *) (*compp)->name,
strlen((*compp)->name)); strlen((*compp)->name));
if (s) { if (s) {
endpoint->comp = *compp; endpoint->comp = *compp;
@ -1544,11 +1540,10 @@ libssh2_kex_agree_comp(LIBSSH2_SESSION * session,
* The Client gets to make the final call on "agreed methods" * The Client gets to make the final call on "agreed methods"
*/ */
/* {{{ libssh2_kex_agree_methods /* {{{ kex_agree_methods
* Decide which specific method to use of the methods offered by each party * Decide which specific method to use of the methods offered by each party
*/ */
static int static int kex_agree_methods(LIBSSH2_SESSION * session, unsigned char *data,
libssh2_kex_agree_methods(LIBSSH2_SESSION * session, unsigned char *data,
unsigned data_len) unsigned data_len)
{ {
unsigned char *kex, *hostkey, *crypt_cs, *crypt_sc, *comp_cs, *comp_sc, unsigned char *kex, *hostkey, *crypt_cs, *crypt_sc, *comp_cs, *comp_sc,
@ -1596,7 +1591,7 @@ libssh2_kex_agree_methods(LIBSSH2_SESSION * session, unsigned char *data,
s += 4 + lang_sc_len; s += 4 + lang_sc_len;
/* If the server sent an optimistic packet, assume that it guessed wrong. /* If the server sent an optimistic packet, assume that it guessed wrong.
* If the guess is determined to be right (by libssh2_kex_agree_kex_hostkey) * If the guess is determined to be right (by kex_agree_kex_hostkey)
* This flag will be reset to zero so that it's not ignored */ * This flag will be reset to zero so that it's not ignored */
session->burn_optimistic_kexinit = *(s++); session->burn_optimistic_kexinit = *(s++);
/* Next uint32 in packet is all zeros (reserved) */ /* Next uint32 in packet is all zeros (reserved) */
@ -1604,26 +1599,22 @@ libssh2_kex_agree_methods(LIBSSH2_SESSION * session, unsigned char *data,
if (data_len < (unsigned) (s - data)) if (data_len < (unsigned) (s - data))
return -1; /* short packet */ return -1; /* short packet */
if (libssh2_kex_agree_kex_hostkey if (kex_agree_kex_hostkey(session, kex, kex_len, hostkey, hostkey_len)) {
(session, kex, kex_len, hostkey, hostkey_len)) {
return -1; return -1;
} }
if (libssh2_kex_agree_crypt if (kex_agree_crypt(session, &session->local, crypt_cs, crypt_cs_len)
(session, &session->local, crypt_cs, crypt_cs_len) || kex_agree_crypt(session, &session->remote, crypt_sc, crypt_sc_len)) {
|| libssh2_kex_agree_crypt(session, &session->remote, crypt_sc,
crypt_sc_len)) {
return -1; return -1;
} }
if (libssh2_kex_agree_mac(session, &session->local, mac_cs, mac_cs_len) || if (kex_agree_mac(session, &session->local, mac_cs, mac_cs_len) ||
libssh2_kex_agree_mac(session, &session->remote, mac_sc, mac_sc_len)) { kex_agree_mac(session, &session->remote, mac_sc, mac_sc_len)) {
return -1; return -1;
} }
if (libssh2_kex_agree_comp(session, &session->local, comp_cs, comp_cs_len) if (kex_agree_comp(session, &session->local, comp_cs, comp_cs_len) ||
|| libssh2_kex_agree_comp(session, &session->remote, comp_sc, kex_agree_comp(session, &session->remote, comp_sc, comp_sc_len)) {
comp_sc_len)) {
return -1; return -1;
} }
@ -1711,7 +1702,7 @@ libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
} }
if (key_state->state == libssh2_NB_state_sent) { if (key_state->state == libssh2_NB_state_sent) {
retcode = libssh2_kexinit(session); retcode = kexinit(session);
if (retcode == PACKET_EAGAIN) { if (retcode == PACKET_EAGAIN) {
session->state &= ~LIBSSH2_STATE_KEX_ACTIVE; session->state &= ~LIBSSH2_STATE_KEX_ACTIVE;
return PACKET_EAGAIN; return PACKET_EAGAIN;
@ -1754,8 +1745,8 @@ libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
session->remote.kexinit = key_state->data; session->remote.kexinit = key_state->data;
session->remote.kexinit_len = key_state->data_len; session->remote.kexinit_len = key_state->data_len;
if (libssh2_kex_agree_methods if (kex_agree_methods(session, key_state->data,
(session, key_state->data, key_state->data_len)) { key_state->data_len)) {
rc = -1; rc = -1;
} }
@ -1881,7 +1872,7 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type,
char *p = strchr(s, ','); char *p = strchr(s, ',');
int method_len = p ? (p - s) : (int) strlen(s); int method_len = p ? (p - s) : (int) strlen(s);
if (!libssh2_get_method_by_name(s, method_len, mlist)) { if (!kex_get_method_by_name(s, method_len, mlist)) {
/* Strip out unsupported method */ /* Strip out unsupported method */
if (p) { if (p) {
memcpy(s, p + 1, strlen(s) - method_len); memcpy(s, p + 1, strlen(s) - method_len);

Просмотреть файл

@ -679,7 +679,7 @@ libssh2_scp_send_ex(LIBSSH2_SESSION * session, const char *path, int mode,
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending time data for SCP file", 0); "Would block sending time data for SCP file", 0);
return NULL; return NULL;
} else if (rc != session->scpSend_response_len) { } else if (rc != (int)session->scpSend_response_len) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send time data for SCP file", 0); "Unable to send time data for SCP file", 0);
goto scp_send_error; goto scp_send_error;
@ -738,7 +738,7 @@ libssh2_scp_send_ex(LIBSSH2_SESSION * session, const char *path, int mode,
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block send core file data for SCP file", 0); "Would block send core file data for SCP file", 0);
return NULL; return NULL;
} else if (rc != session->scpSend_response_len) { } else if (rc != (int)session->scpSend_response_len) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND, libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send core file data for SCP file", 0); "Unable to send core file data for SCP file", 0);
goto scp_send_error; goto scp_send_error;

Просмотреть файл

@ -50,6 +50,9 @@ int main(int argc, char *argv[])
const char *password="password"; const char *password="password";
int ec = 1; int ec = 1;
(void)argc;
(void)argv;
if (getenv ("USER")) if (getenv ("USER"))
username = getenv ("USER"); username = getenv ("USER");