Mercurial > dropbear
comparison cli-kex.c @ 747:077bbe1eb220
merge kexguess branch
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 03 Apr 2013 00:49:24 +0800 |
parents | 15999b098cc9 |
children | d63ef1e211ea |
comparison
equal
deleted
inserted
replaced
736:0b854ab00333 | 747:077bbe1eb220 |
---|---|
40 | 40 |
41 static void checkhostkey(unsigned char* keyblob, unsigned int keybloblen); | 41 static void checkhostkey(unsigned char* keyblob, unsigned int keybloblen); |
42 #define MAX_KNOWNHOSTS_LINE 4500 | 42 #define MAX_KNOWNHOSTS_LINE 4500 |
43 | 43 |
44 void send_msg_kexdh_init() { | 44 void send_msg_kexdh_init() { |
45 | 45 TRACE(("send_msg_kexdh_init()")) |
46 cli_ses.dh_e = (mp_int*)m_malloc(sizeof(mp_int)); | 46 if ((cli_ses.dh_e && cli_ses.dh_x |
47 cli_ses.dh_x = (mp_int*)m_malloc(sizeof(mp_int)); | 47 && cli_ses.dh_val_algo == ses.newkeys->algo_kex)) { |
48 m_mp_init_multi(cli_ses.dh_e, cli_ses.dh_x, NULL); | 48 TRACE(("reusing existing dh_e from first_kex_packet_follows")) |
49 | 49 } else { |
50 gen_kexdh_vals(cli_ses.dh_e, cli_ses.dh_x); | 50 if (!cli_ses.dh_e || !cli_ses.dh_e) { |
51 cli_ses.dh_e = (mp_int*)m_malloc(sizeof(mp_int)); | |
52 cli_ses.dh_x = (mp_int*)m_malloc(sizeof(mp_int)); | |
53 m_mp_init_multi(cli_ses.dh_e, cli_ses.dh_x, NULL); | |
54 } | |
55 | |
56 gen_kexdh_vals(cli_ses.dh_e, cli_ses.dh_x); | |
57 cli_ses.dh_val_algo = ses.newkeys->algo_kex; | |
58 } | |
51 | 59 |
52 CHECKCLEARTOWRITE(); | 60 CHECKCLEARTOWRITE(); |
53 buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_INIT); | 61 buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_INIT); |
54 buf_putmpint(ses.writepayload, cli_ses.dh_e); | 62 buf_putmpint(ses.writepayload, cli_ses.dh_e); |
55 encrypt_packet(); | 63 encrypt_packet(); |
56 ses.requirenext = SSH_MSG_KEXDH_REPLY; | 64 // XXX fixme |
65 //ses.requirenext = SSH_MSG_KEXDH_REPLY; | |
57 } | 66 } |
58 | 67 |
59 /* Handle a diffie-hellman key exchange reply. */ | 68 /* Handle a diffie-hellman key exchange reply. */ |
60 void recv_msg_kexdh_reply() { | 69 void recv_msg_kexdh_reply() { |
61 | 70 |
96 kexdh_comb_key(cli_ses.dh_e, cli_ses.dh_x, &dh_f, hostkey); | 105 kexdh_comb_key(cli_ses.dh_e, cli_ses.dh_x, &dh_f, hostkey); |
97 mp_clear(&dh_f); | 106 mp_clear(&dh_f); |
98 mp_clear_multi(cli_ses.dh_e, cli_ses.dh_x, NULL); | 107 mp_clear_multi(cli_ses.dh_e, cli_ses.dh_x, NULL); |
99 m_free(cli_ses.dh_e); | 108 m_free(cli_ses.dh_e); |
100 m_free(cli_ses.dh_x); | 109 m_free(cli_ses.dh_x); |
110 cli_ses.dh_val_algo = DROPBEAR_KEX_NONE; | |
101 | 111 |
102 if (buf_verify(ses.payload, hostkey, ses.hash, SHA1_HASH_SIZE) | 112 if (buf_verify(ses.payload, hostkey, ses.hash, SHA1_HASH_SIZE) |
103 != DROPBEAR_SUCCESS) { | 113 != DROPBEAR_SUCCESS) { |
104 dropbear_exit("Bad hostkey signature"); | 114 dropbear_exit("Bad hostkey signature"); |
105 } | 115 } |