mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-29 01:03:57 +03:00
packet: Move packet callbacks to packet_cb.c.
This commit is contained in:
154
src/client.c
154
src/client.c
@@ -180,143 +180,6 @@ end:
|
||||
return err;
|
||||
}
|
||||
|
||||
SSH_PACKET_CALLBACK(ssh_packet_dh_reply){
|
||||
int rc;
|
||||
(void)type;
|
||||
(void)user;
|
||||
ssh_log(session,SSH_LOG_PROTOCOL,"Received SSH_KEXDH_REPLY");
|
||||
if(session->session_state!= SSH_SESSION_STATE_DH &&
|
||||
session->dh_handshake_state != DH_STATE_INIT_SENT){
|
||||
ssh_set_error(session,SSH_FATAL,"ssh_packet_dh_reply called in wrong state : %d:%d",
|
||||
session->session_state,session->dh_handshake_state);
|
||||
goto error;
|
||||
}
|
||||
switch(session->next_crypto->kex_type){
|
||||
case SSH_KEX_DH_GROUP1_SHA1:
|
||||
rc=ssh_client_dh_reply(session, packet);
|
||||
break;
|
||||
#ifdef HAVE_ECDH
|
||||
case SSH_KEX_ECDH_SHA2_NISTP256:
|
||||
rc = ssh_client_ecdh_reply(session, packet);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ssh_set_error(session,SSH_FATAL,"Wrong kex type in ssh_packet_dh_reply");
|
||||
goto error;
|
||||
}
|
||||
if(rc==SSH_OK) {
|
||||
session->dh_handshake_state = DH_STATE_NEWKEYS_SENT;
|
||||
return SSH_PACKET_USED;
|
||||
}
|
||||
error:
|
||||
session->session_state=SSH_SESSION_STATE_ERROR;
|
||||
return SSH_PACKET_USED;
|
||||
}
|
||||
|
||||
SSH_PACKET_CALLBACK(ssh_packet_newkeys){
|
||||
ssh_string sig_blob = NULL;
|
||||
int rc;
|
||||
(void)packet;
|
||||
(void)user;
|
||||
(void)type;
|
||||
ssh_log(session, SSH_LOG_PROTOCOL, "Received SSH_MSG_NEWKEYS");
|
||||
if(session->session_state!= SSH_SESSION_STATE_DH &&
|
||||
session->dh_handshake_state != DH_STATE_NEWKEYS_SENT){
|
||||
ssh_set_error(session,SSH_FATAL,"ssh_packet_newkeys called in wrong state : %d:%d",
|
||||
session->session_state,session->dh_handshake_state);
|
||||
goto error;
|
||||
}
|
||||
if(session->server){
|
||||
/* server things are done in server.c */
|
||||
session->dh_handshake_state=DH_STATE_FINISHED;
|
||||
} else {
|
||||
ssh_key key;
|
||||
/* client */
|
||||
rc = make_sessionid(session);
|
||||
if (rc != SSH_OK) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the cryptographic functions for the next crypto
|
||||
* (it is needed for generate_session_keys for key lengths)
|
||||
*/
|
||||
if (crypt_set_algorithms(session)) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (generate_session_keys(session) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Verify the host's signature. FIXME do it sooner */
|
||||
sig_blob = session->next_crypto->dh_server_signature;
|
||||
session->next_crypto->dh_server_signature = NULL;
|
||||
|
||||
/* get the server public key */
|
||||
rc = ssh_pki_import_pubkey_blob(session->next_crypto->server_pubkey, &key);
|
||||
if (rc < 0) {
|
||||
return SSH_ERROR;
|
||||
}
|
||||
|
||||
/* check if public key from server matches user preferences */
|
||||
if (session->wanted_methods[SSH_HOSTKEYS]) {
|
||||
if(!ssh_match_group(session->wanted_methods[SSH_HOSTKEYS],
|
||||
key->type_c)) {
|
||||
ssh_set_error(session,
|
||||
SSH_FATAL,
|
||||
"Public key from server (%s) doesn't match user "
|
||||
"preference (%s)",
|
||||
key->type_c,
|
||||
session->wanted_methods[SSH_HOSTKEYS]);
|
||||
ssh_key_free(key);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
rc = ssh_pki_signature_verify_blob(session,
|
||||
sig_blob,
|
||||
key,
|
||||
session->next_crypto->session_id,
|
||||
session->next_crypto->digest_len);
|
||||
/* Set the server public key type for known host checking */
|
||||
session->next_crypto->server_pubkey_type = key->type_c;
|
||||
|
||||
ssh_key_free(key);
|
||||
ssh_string_burn(sig_blob);
|
||||
ssh_string_free(sig_blob);
|
||||
sig_blob = NULL;
|
||||
if (rc == SSH_ERROR) {
|
||||
goto error;
|
||||
}
|
||||
ssh_log(session,SSH_LOG_PROTOCOL,"Signature verified and valid");
|
||||
|
||||
/*
|
||||
* Once we got SSH2_MSG_NEWKEYS we can switch next_crypto and
|
||||
* current_crypto
|
||||
*/
|
||||
if (session->current_crypto) {
|
||||
crypto_free(session->current_crypto);
|
||||
session->current_crypto=NULL;
|
||||
}
|
||||
|
||||
/* FIXME later, include a function to change keys */
|
||||
session->current_crypto = session->next_crypto;
|
||||
|
||||
session->next_crypto = crypto_new();
|
||||
if (session->next_crypto == NULL) {
|
||||
ssh_set_error_oom(session);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
session->dh_handshake_state = DH_STATE_FINISHED;
|
||||
session->ssh_connection_callback(session);
|
||||
return SSH_PACKET_USED;
|
||||
error:
|
||||
session->session_state=SSH_SESSION_STATE_ERROR;
|
||||
return SSH_PACKET_USED;
|
||||
}
|
||||
|
||||
/** @internal
|
||||
* @brief launches the DH handshake state machine
|
||||
* @param session session handle
|
||||
@@ -371,23 +234,6 @@ error:
|
||||
return rc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @brief handles a SSH_SERVICE_ACCEPT packet
|
||||
*
|
||||
*/
|
||||
SSH_PACKET_CALLBACK(ssh_packet_service_accept){
|
||||
(void)packet;
|
||||
(void)type;
|
||||
(void)user;
|
||||
enter_function();
|
||||
session->auth_service_state=SSH_AUTH_SERVICE_ACCEPTED;
|
||||
ssh_log(session, SSH_LOG_PACKET,
|
||||
"Received SSH_MSG_SERVICE_ACCEPT");
|
||||
leave_function();
|
||||
return SSH_PACKET_USED;
|
||||
}
|
||||
|
||||
static int ssh_service_request_termination(void *s){
|
||||
ssh_session session = (ssh_session)s;
|
||||
if(session->session_state == SSH_SESSION_STATE_ERROR ||
|
||||
|
||||
Reference in New Issue
Block a user