Collapse state flags into single bitmask attribute
Этот коммит содержится в:
родитель
2c5c54e999
Коммит
a05bf84ecf
2
README
2
README
@ -4,6 +4,8 @@ libssh2 - SSH2 library
|
||||
Version 0.6
|
||||
-----------
|
||||
|
||||
Collapsed exchanging_keys/newkeys/authenticated flags into single state attribute.
|
||||
|
||||
Fix zlib compression issue when internal buffer state misses partial sync.
|
||||
|
||||
Fix segfault when libssh2_session_methods() is called prior to session_startup().
|
||||
|
@ -180,9 +180,7 @@ struct _LIBSSH2_SESSION {
|
||||
char *kex_prefs;
|
||||
char *hostkey_prefs;
|
||||
|
||||
int exchanging_keys;
|
||||
int newkeys;
|
||||
int authenticated;
|
||||
int state;
|
||||
|
||||
/* Agreed Key Exchange Method */
|
||||
LIBSSH2_KEX_METHOD *kex;
|
||||
@ -233,6 +231,11 @@ struct _LIBSSH2_SESSION {
|
||||
int err_code;
|
||||
};
|
||||
|
||||
/* session.state bits */
|
||||
#define LIBSSH2_STATE_EXCHANGING_KEYS 0x00000001
|
||||
#define LIBSSH2_STATE_NEWKEYS 0x00000002
|
||||
#define LIBSSH2_STATE_AUTHENTICATED 0x00000004
|
||||
|
||||
/* libssh2 extensible ssh api, ultimately I'd like to allow loading additional methods via .so/.dll */
|
||||
|
||||
struct _LIBSSH2_KEX_METHOD {
|
||||
|
@ -263,7 +263,7 @@ static int libssh2_kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_S
|
||||
goto clean_exit;
|
||||
}
|
||||
/* The first key exchange has been performed, switch to active crypt/comp/mac mode */
|
||||
session->newkeys = 1;
|
||||
session->state |= LIBSSH2_STATE_NEWKEYS;
|
||||
|
||||
/* This will actually end up being just packet_type(1) for this packet type anyway */
|
||||
LIBSSH2_FREE(session, tmp);
|
||||
@ -1145,7 +1145,7 @@ int libssh2_kex_exchange(LIBSSH2_SESSION *session, int reexchange) /* session->f
|
||||
unsigned long data_len;
|
||||
|
||||
/* Prevent loop in packet_add() */
|
||||
session->exchanging_keys = 1;
|
||||
session->state |= LIBSSH2_STATE_EXCHANGING_KEYS;
|
||||
|
||||
if (reexchange) {
|
||||
session->kex = NULL;
|
||||
@ -1191,7 +1191,7 @@ int libssh2_kex_exchange(LIBSSH2_SESSION *session, int reexchange) /* session->f
|
||||
session->remote.kexinit = NULL;
|
||||
}
|
||||
|
||||
session->exchanging_keys = 0;
|
||||
session->state &= ~LIBSSH2_STATE_EXCHANGING_KEYS;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
10
src/packet.c
10
src/packet.c
@ -510,7 +510,7 @@ static int libssh2_packet_add(LIBSSH2_SESSION *session, unsigned char *data, siz
|
||||
packet->prev = NULL;
|
||||
}
|
||||
|
||||
if (data[0] == SSH_MSG_KEXINIT && !session->exchanging_keys) {
|
||||
if (data[0] == SSH_MSG_KEXINIT && !(session->state & LIBSSH2_STATE_EXCHANGING_KEYS)) {
|
||||
/* Remote wants new keys
|
||||
* Well, it's already in the brigade,
|
||||
* let's just call back into ourselves
|
||||
@ -591,7 +591,7 @@ int libssh2_packet_read(LIBSSH2_SESSION *session, int should_block)
|
||||
ioctlsocket(session->socket_fd, FIONBIO, &non_block);
|
||||
}
|
||||
#endif
|
||||
if (session->newkeys) {
|
||||
if (session->state & LIBSSH2_STATE_NEWKEYS) {
|
||||
/* Temporary Buffer
|
||||
* The largest blocksize (currently) is 32, the largest MAC (currently) is 20
|
||||
*/
|
||||
@ -854,14 +854,14 @@ int libssh2_packet_require_ex(LIBSSH2_SESSION *session, unsigned char packet_typ
|
||||
int libssh2_packet_write(LIBSSH2_SESSION *session, unsigned char *data, unsigned long data_len)
|
||||
{
|
||||
unsigned long packet_length = data_len + 1;
|
||||
unsigned long block_size = (session->newkeys) ? session->local.crypt->blocksize : 8;
|
||||
unsigned long block_size = (session->state & LIBSSH2_STATE_NEWKEYS) ? session->local.crypt->blocksize : 8;
|
||||
/* At this point packet_length doesn't include the packet_len field itself */
|
||||
unsigned long padding_length;
|
||||
int free_data = 0;
|
||||
unsigned char buf[246]; /* 6 byte header plus max padding size(240) */
|
||||
int i;
|
||||
|
||||
if (session->newkeys &&
|
||||
if ((session->state & LIBSSH2_STATE_NEWKEYS) &&
|
||||
strcmp(session->local.comp->name, "none")) {
|
||||
|
||||
if (session->local.comp->comp(session, 1, &data, &data_len, LIBSSH2_PACKET_MAXCOMP, &free_data, data, data_len, &session->local.comp_abstract)) {
|
||||
@ -894,7 +894,7 @@ int libssh2_packet_write(LIBSSH2_SESSION *session, unsigned char *data, unsigned
|
||||
buf[5 + i] = '\0';
|
||||
}
|
||||
|
||||
if (session->newkeys) {
|
||||
if (session->state & LIBSSH2_STATE_NEWKEYS) {
|
||||
/* Encryption is in effect */
|
||||
unsigned char *encbuf, *s;
|
||||
int ret;
|
||||
|
@ -325,7 +325,7 @@ LIBSSH2_API void libssh2_session_free(LIBSSH2_SESSION *session)
|
||||
libssh2_channel_forward_cancel(session->listeners);
|
||||
}
|
||||
|
||||
if (session->newkeys) {
|
||||
if (session->state & LIBSSH2_STATE_NEWKEYS) {
|
||||
/* hostkey */
|
||||
if (session->hostkey && session->hostkey->dtor) {
|
||||
session->hostkey->dtor(session, &session->server_hostkey_abstract);
|
||||
|
@ -80,7 +80,7 @@ LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session, char *username
|
||||
if (libssh2_packet_ask(session, SSH_MSG_USERAUTH_SUCCESS, &data, &data_len, 1) == 0) {
|
||||
/* Wow, who'dve thought... */
|
||||
LIBSSH2_FREE(session, data);
|
||||
session->authenticated = 1;
|
||||
session->state |= LIBSSH2_STATE_AUTHENTICATED;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ LIBSSH2_API char *libssh2_userauth_list(LIBSSH2_SESSION *session, char *username
|
||||
*/
|
||||
LIBSSH2_API int libssh2_userauth_authenticated(LIBSSH2_SESSION *session)
|
||||
{
|
||||
return session->authenticated;
|
||||
return session->state & LIBSSH2_STATE_AUTHENTICATED;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -151,7 +151,7 @@ LIBSSH2_API int libssh2_userauth_password_ex(LIBSSH2_SESSION *session, char *use
|
||||
while (1) {
|
||||
if (libssh2_packet_ask(session, SSH_MSG_USERAUTH_SUCCESS, &data, &data_len, 1) == 0) {
|
||||
LIBSSH2_FREE(session, data);
|
||||
session->authenticated = 1;
|
||||
session->state |= LIBSSH2_STATE_AUTHENTICATED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -389,7 +389,7 @@ LIBSSH2_API int libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session,
|
||||
LIBSSH2_FREE(session, packet);
|
||||
LIBSSH2_FREE(session, method);
|
||||
LIBSSH2_FREE(session, pubkeydata);
|
||||
session->authenticated = 1;
|
||||
session->state |= LIBSSH2_STATE_AUTHENTICATED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -485,7 +485,7 @@ LIBSSH2_API int libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION *session,
|
||||
if (libssh2_packet_ask(session, SSH_MSG_USERAUTH_SUCCESS, &data, &data_len, 1) == 0) {
|
||||
/* We are us and we've proved it. */
|
||||
LIBSSH2_FREE(session, data);
|
||||
session->authenticated = 1;
|
||||
session->state |= LIBSSH2_STATE_AUTHENTICATED;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user