comparison svr-kex.c @ 1342:8747c2b19152

merge 2017.75
author Matt Johnston <matt@ucc.asn.au>
date Thu, 18 May 2017 22:59:38 +0800
parents efad433418c4 750ec4ec4cbe
children bbc0a0ee3843
comparison
equal deleted inserted replaced
1341:ab35a9ccc2eb 1342:8747c2b19152
52 if (!ses.kexstate.recvkexinit) { 52 if (!ses.kexstate.recvkexinit) {
53 dropbear_exit("Premature kexdh_init message received"); 53 dropbear_exit("Premature kexdh_init message received");
54 } 54 }
55 55
56 switch (ses.newkeys->algo_kex->mode) { 56 switch (ses.newkeys->algo_kex->mode) {
57 #if DROPBEAR_NORMAL_DH
57 case DROPBEAR_KEX_NORMAL_DH: 58 case DROPBEAR_KEX_NORMAL_DH:
58 m_mp_init(&dh_e); 59 m_mp_init(&dh_e);
59 if (buf_getmpint(ses.payload, &dh_e) != DROPBEAR_SUCCESS) { 60 if (buf_getmpint(ses.payload, &dh_e) != DROPBEAR_SUCCESS) {
60 dropbear_exit("Bad kex value"); 61 dropbear_exit("Bad kex value");
61 } 62 }
62 break; 63 break;
64 #endif
65 #if DROPBEAR_ECDH
63 case DROPBEAR_KEX_ECDH: 66 case DROPBEAR_KEX_ECDH:
67 #endif
68 #if DROPBEAR_CURVE25519
64 case DROPBEAR_KEX_CURVE25519: 69 case DROPBEAR_KEX_CURVE25519:
65 #if defined(DROPBEAR_ECDH) || defined(DROPBEAR_CURVE25519) 70 #endif
71 #if DROPBEAR_ECDH || DROPBEAR_CURVE25519
66 ecdh_qs = buf_getstringbuf(ses.payload); 72 ecdh_qs = buf_getstringbuf(ses.payload);
67 #endif 73 break;
68 break; 74 #endif
69 } 75 }
70 if (ses.payload->pos != ses.payload->len) { 76 if (ses.payload->pos != ses.payload->len) {
71 dropbear_exit("Bad kex value"); 77 dropbear_exit("Bad kex value");
72 } 78 }
73 79
83 ses.requirenext = SSH_MSG_NEWKEYS; 89 ses.requirenext = SSH_MSG_NEWKEYS;
84 TRACE(("leave recv_msg_kexdh_init")) 90 TRACE(("leave recv_msg_kexdh_init"))
85 } 91 }
86 92
87 93
88 #ifdef DROPBEAR_DELAY_HOSTKEY 94 #if DROPBEAR_DELAY_HOSTKEY
89 95
90 static void svr_ensure_hostkey() { 96 static void svr_ensure_hostkey() {
91 97
92 const char* fn = NULL; 98 const char* fn = NULL;
93 enum signkey_type type = ses.newkeys->algo_hostkey; 99 enum signkey_type type = ses.newkeys->algo_hostkey;
98 return; 104 return;
99 } 105 }
100 106
101 switch (type) 107 switch (type)
102 { 108 {
103 #ifdef DROPBEAR_RSA 109 #if DROPBEAR_RSA
104 case DROPBEAR_SIGNKEY_RSA: 110 case DROPBEAR_SIGNKEY_RSA:
105 fn = RSA_PRIV_FILENAME; 111 fn = RSA_PRIV_FILENAME;
106 break; 112 break;
107 #endif 113 #endif
108 #ifdef DROPBEAR_DSS 114 #if DROPBEAR_DSS
109 case DROPBEAR_SIGNKEY_DSS: 115 case DROPBEAR_SIGNKEY_DSS:
110 fn = DSS_PRIV_FILENAME; 116 fn = DSS_PRIV_FILENAME;
111 break; 117 break;
112 #endif 118 #endif
113 #ifdef DROPBEAR_ECDSA 119 #if DROPBEAR_ECDSA
114 case DROPBEAR_SIGNKEY_ECDSA_NISTP256: 120 case DROPBEAR_SIGNKEY_ECDSA_NISTP256:
115 case DROPBEAR_SIGNKEY_ECDSA_NISTP384: 121 case DROPBEAR_SIGNKEY_ECDSA_NISTP384:
116 case DROPBEAR_SIGNKEY_ECDSA_NISTP521: 122 case DROPBEAR_SIGNKEY_ECDSA_NISTP521:
117 fn = ECDSA_PRIV_FILENAME; 123 fn = ECDSA_PRIV_FILENAME;
118 break; 124 break;
164 TRACE(("enter send_msg_kexdh_reply")) 170 TRACE(("enter send_msg_kexdh_reply"))
165 171
166 /* we can start creating the kexdh_reply packet */ 172 /* we can start creating the kexdh_reply packet */
167 CHECKCLEARTOWRITE(); 173 CHECKCLEARTOWRITE();
168 174
169 #ifdef DROPBEAR_DELAY_HOSTKEY 175 #if DROPBEAR_DELAY_HOSTKEY
170 if (svr_opts.delay_hostkey) 176 if (svr_opts.delay_hostkey)
171 { 177 {
172 svr_ensure_hostkey(); 178 svr_ensure_hostkey();
173 } 179 }
174 #endif 180 #endif
176 buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_REPLY); 182 buf_putbyte(ses.writepayload, SSH_MSG_KEXDH_REPLY);
177 buf_put_pub_key(ses.writepayload, svr_opts.hostkey, 183 buf_put_pub_key(ses.writepayload, svr_opts.hostkey,
178 ses.newkeys->algo_hostkey); 184 ses.newkeys->algo_hostkey);
179 185
180 switch (ses.newkeys->algo_kex->mode) { 186 switch (ses.newkeys->algo_kex->mode) {
187 #if DROPBEAR_NORMAL_DH
181 case DROPBEAR_KEX_NORMAL_DH: 188 case DROPBEAR_KEX_NORMAL_DH:
182 { 189 {
183 struct kex_dh_param * dh_param = gen_kexdh_param(); 190 struct kex_dh_param * dh_param = gen_kexdh_param();
184 kexdh_comb_key(dh_param, dh_e, svr_opts.hostkey); 191 kexdh_comb_key(dh_param, dh_e, svr_opts.hostkey);
185 192
186 /* put f */ 193 /* put f */
187 buf_putmpint(ses.writepayload, &dh_param->pub); 194 buf_putmpint(ses.writepayload, &dh_param->pub);
188 free_kexdh_param(dh_param); 195 free_kexdh_param(dh_param);
189 } 196 }
190 break; 197 break;
198 #endif
199 #if DROPBEAR_ECDH
191 case DROPBEAR_KEX_ECDH: 200 case DROPBEAR_KEX_ECDH:
192 #ifdef DROPBEAR_ECDH
193 { 201 {
194 struct kex_ecdh_param *ecdh_param = gen_kexecdh_param(); 202 struct kex_ecdh_param *ecdh_param = gen_kexecdh_param();
195 kexecdh_comb_key(ecdh_param, ecdh_qs, svr_opts.hostkey); 203 kexecdh_comb_key(ecdh_param, ecdh_qs, svr_opts.hostkey);
196 204
197 buf_put_ecc_raw_pubkey_string(ses.writepayload, &ecdh_param->key); 205 buf_put_ecc_raw_pubkey_string(ses.writepayload, &ecdh_param->key);
198 free_kexecdh_param(ecdh_param); 206 free_kexecdh_param(ecdh_param);
199 } 207 }
200 #endif 208 break;
201 break; 209 #endif
210 #if DROPBEAR_CURVE25519
202 case DROPBEAR_KEX_CURVE25519: 211 case DROPBEAR_KEX_CURVE25519:
203 #ifdef DROPBEAR_CURVE25519
204 { 212 {
205 struct kex_curve25519_param *param = gen_kexcurve25519_param(); 213 struct kex_curve25519_param *param = gen_kexcurve25519_param();
206 kexcurve25519_comb_key(param, ecdh_qs, svr_opts.hostkey); 214 kexcurve25519_comb_key(param, ecdh_qs, svr_opts.hostkey);
207 buf_putstring(ses.writepayload, (const char*)param->pub, CURVE25519_LEN); 215 buf_putstring(ses.writepayload, (const char*)param->pub, CURVE25519_LEN);
208 free_kexcurve25519_param(param); 216 free_kexcurve25519_param(param);
209 } 217 }
210 #endif 218 break;
211 break; 219 #endif
212 } 220 }
213 221
214 /* calc the signature */ 222 /* calc the signature */
215 buf_put_sign(ses.writepayload, svr_opts.hostkey, 223 buf_put_sign(ses.writepayload, svr_opts.hostkey,
216 ses.newkeys->algo_hostkey, ses.hash); 224 ses.newkeys->algo_hostkey, ses.hash);