comparison signkey.c @ 165:0cfba3034be5

Fixed DEBUG_TRACE macro so that we don't get semicolons left about the place
author Matt Johnston <matt@ucc.asn.au>
date Sun, 02 Jan 2005 20:25:56 +0000
parents d3eb1fa8484e
children 5a75f8a21503
comparison
equal deleted inserted replaced
161:b9d3f725e00b 165:0cfba3034be5
92 unsigned char* ident; 92 unsigned char* ident;
93 unsigned int len; 93 unsigned int len;
94 int keytype; 94 int keytype;
95 int ret = DROPBEAR_FAILURE; 95 int ret = DROPBEAR_FAILURE;
96 96
97 TRACE(("enter buf_get_pub_key")); 97 TRACE(("enter buf_get_pub_key"))
98 98
99 ident = buf_getstring(buf, &len); 99 ident = buf_getstring(buf, &len);
100 keytype = signkey_type_from_name(ident, len); 100 keytype = signkey_type_from_name(ident, len);
101 m_free(ident); 101 m_free(ident);
102 102
128 m_free(key->rsakey); 128 m_free(key->rsakey);
129 } 129 }
130 } 130 }
131 #endif 131 #endif
132 132
133 TRACE(("leave buf_get_pub_key")); 133 TRACE(("leave buf_get_pub_key"))
134 134
135 return ret; 135 return ret;
136 136
137 } 137 }
138 138
144 unsigned char* ident; 144 unsigned char* ident;
145 unsigned int len; 145 unsigned int len;
146 int keytype; 146 int keytype;
147 int ret = DROPBEAR_FAILURE; 147 int ret = DROPBEAR_FAILURE;
148 148
149 TRACE(("enter buf_get_priv_key")); 149 TRACE(("enter buf_get_priv_key"))
150 150
151 ident = buf_getstring(buf, &len); 151 ident = buf_getstring(buf, &len);
152 keytype = signkey_type_from_name(ident, len); 152 keytype = signkey_type_from_name(ident, len);
153 m_free(ident); 153 m_free(ident);
154 154
155 if (*type != DROPBEAR_SIGNKEY_ANY && *type != keytype) { 155 if (*type != DROPBEAR_SIGNKEY_ANY && *type != keytype) {
156 TRACE(("wrong key type: %d %d", *type, keytype)); 156 TRACE(("wrong key type: %d %d", *type, keytype))
157 return DROPBEAR_FAILURE; 157 return DROPBEAR_FAILURE;
158 } 158 }
159 159
160 *type = keytype; 160 *type = keytype;
161 161
181 m_free(key->rsakey); 181 m_free(key->rsakey);
182 } 182 }
183 } 183 }
184 #endif 184 #endif
185 185
186 TRACE(("leave buf_get_priv_key")); 186 TRACE(("leave buf_get_priv_key"))
187 187
188 return ret; 188 return ret;
189 189
190 } 190 }
191 191
192 /* type is either DROPBEAR_SIGNKEY_DSS or DROPBEAR_SIGNKEY_RSA */ 192 /* type is either DROPBEAR_SIGNKEY_DSS or DROPBEAR_SIGNKEY_RSA */
193 void buf_put_pub_key(buffer* buf, sign_key *key, int type) { 193 void buf_put_pub_key(buffer* buf, sign_key *key, int type) {
194 194
195 buffer *pubkeys; 195 buffer *pubkeys;
196 196
197 TRACE(("enter buf_put_pub_key")); 197 TRACE(("enter buf_put_pub_key"))
198 pubkeys = buf_new(MAX_PUBKEY_SIZE); 198 pubkeys = buf_new(MAX_PUBKEY_SIZE);
199 199
200 #ifdef DROPBEAR_DSS 200 #ifdef DROPBEAR_DSS
201 if (type == DROPBEAR_SIGNKEY_DSS) { 201 if (type == DROPBEAR_SIGNKEY_DSS) {
202 buf_put_dss_pub_key(pubkeys, key->dsskey); 202 buf_put_dss_pub_key(pubkeys, key->dsskey);
214 buf_setpos(pubkeys, 0); 214 buf_setpos(pubkeys, 0);
215 buf_putstring(buf, buf_getptr(pubkeys, pubkeys->len), 215 buf_putstring(buf, buf_getptr(pubkeys, pubkeys->len),
216 pubkeys->len); 216 pubkeys->len);
217 217
218 buf_free(pubkeys); 218 buf_free(pubkeys);
219 TRACE(("leave buf_put_pub_key")); 219 TRACE(("leave buf_put_pub_key"))
220 } 220 }
221 221
222 /* type is either DROPBEAR_SIGNKEY_DSS or DROPBEAR_SIGNKEY_RSA */ 222 /* type is either DROPBEAR_SIGNKEY_DSS or DROPBEAR_SIGNKEY_RSA */
223 void buf_put_priv_key(buffer* buf, sign_key *key, int type) { 223 void buf_put_priv_key(buffer* buf, sign_key *key, int type) {
224 224
225 TRACE(("enter buf_put_priv_key")); 225 TRACE(("enter buf_put_priv_key"))
226 TRACE(("type is %d", type)); 226 TRACE(("type is %d", type))
227 227
228 #ifdef DROPBEAR_DSS 228 #ifdef DROPBEAR_DSS
229 if (type == DROPBEAR_SIGNKEY_DSS) { 229 if (type == DROPBEAR_SIGNKEY_DSS) {
230 buf_put_dss_priv_key(buf, key->dsskey); 230 buf_put_dss_priv_key(buf, key->dsskey);
231 TRACE(("leave buf_put_priv_key: dss done")); 231 TRACE(("leave buf_put_priv_key: dss done"))
232 return; 232 return;
233 } 233 }
234 #endif 234 #endif
235 #ifdef DROPBEAR_RSA 235 #ifdef DROPBEAR_RSA
236 if (type == DROPBEAR_SIGNKEY_RSA) { 236 if (type == DROPBEAR_SIGNKEY_RSA) {
237 buf_put_rsa_priv_key(buf, key->rsakey); 237 buf_put_rsa_priv_key(buf, key->rsakey);
238 TRACE(("leave buf_put_priv_key: rsa done")); 238 TRACE(("leave buf_put_priv_key: rsa done"))
239 return; 239 return;
240 } 240 }
241 #endif 241 #endif
242 dropbear_exit("bad key types in put pub key"); 242 dropbear_exit("bad key types in put pub key");
243 } 243 }
244 244
245 void sign_key_free(sign_key *key) { 245 void sign_key_free(sign_key *key) {
246 246
247 TRACE(("enter sign_key_free")); 247 TRACE(("enter sign_key_free"))
248 248
249 #ifdef DROPBEAR_DSS 249 #ifdef DROPBEAR_DSS
250 dss_key_free(key->dsskey); 250 dss_key_free(key->dsskey);
251 key->dsskey = NULL; 251 key->dsskey = NULL;
252 #endif 252 #endif
254 rsa_key_free(key->rsakey); 254 rsa_key_free(key->rsakey);
255 key->rsakey = NULL; 255 key->rsakey = NULL;
256 #endif 256 #endif
257 257
258 m_free(key); 258 m_free(key);
259 TRACE(("leave sign_key_free")); 259 TRACE(("leave sign_key_free"))
260 } 260 }
261 261
262 static char hexdig(unsigned char x) { 262 static char hexdig(unsigned char x) {
263 263
264 if (x > 0xf) 264 if (x > 0xf)
391 391
392 unsigned int bloblen; 392 unsigned int bloblen;
393 unsigned char * ident = NULL; 393 unsigned char * ident = NULL;
394 unsigned int identlen = 0; 394 unsigned int identlen = 0;
395 395
396 TRACE(("enter buf_verify")); 396 TRACE(("enter buf_verify"))
397 397
398 bloblen = buf_getint(buf); 398 bloblen = buf_getint(buf);
399 ident = buf_getstring(buf, &identlen); 399 ident = buf_getstring(buf, &identlen);
400 400
401 #ifdef DROPBEAR_DSS 401 #ifdef DROPBEAR_DSS
440 decodekey = buf_new(decodekeylen); 440 decodekey = buf_new(decodekeylen);
441 441
442 if (base64_decode(buf_getptr(line, len), len, 442 if (base64_decode(buf_getptr(line, len), len,
443 buf_getwriteptr(decodekey, decodekey->size), 443 buf_getwriteptr(decodekey, decodekey->size),
444 &decodekeylen) != CRYPT_OK) { 444 &decodekeylen) != CRYPT_OK) {
445 TRACE(("checkpubkey: base64 decode failed")); 445 TRACE(("checkpubkey: base64 decode failed"))
446 goto out; 446 goto out;
447 } 447 }
448 TRACE(("checkpubkey: base64_decode success")); 448 TRACE(("checkpubkey: base64_decode success"))
449 buf_incrlen(decodekey, decodekeylen); 449 buf_incrlen(decodekey, decodekeylen);
450 450
451 /* compare the keys */ 451 /* compare the keys */
452 if ( ( decodekeylen != keybloblen ) 452 if ( ( decodekeylen != keybloblen )
453 || memcmp( buf_getptr(decodekey, decodekey->len), 453 || memcmp( buf_getptr(decodekey, decodekey->len),
454 keyblob, decodekey->len) != 0) { 454 keyblob, decodekey->len) != 0) {
455 TRACE(("checkpubkey: compare failed")); 455 TRACE(("checkpubkey: compare failed"))
456 goto out; 456 goto out;
457 } 457 }
458 458
459 /* ... and also check that the algo specified and the algo in the key 459 /* ... and also check that the algo specified and the algo in the key
460 * itself match */ 460 * itself match */
461 filealgolen = buf_getint(decodekey); 461 filealgolen = buf_getint(decodekey);
462 filealgo = buf_getptr(decodekey, filealgolen); 462 filealgo = buf_getptr(decodekey, filealgolen);
463 if (filealgolen != algolen || memcmp(filealgo, algoname, algolen) != 0) { 463 if (filealgolen != algolen || memcmp(filealgo, algoname, algolen) != 0) {
464 TRACE(("checkpubkey: algo match failed")); 464 TRACE(("checkpubkey: algo match failed"))
465 goto out; 465 goto out;
466 } 466 }
467 467
468 /* All checks passed */ 468 /* All checks passed */
469 ret = DROPBEAR_SUCCESS; 469 ret = DROPBEAR_SUCCESS;