comparison signkey.c @ 551:c3f2ec71e3d4 agent-client

New standard linked list to use, rather than adhoc SignKeyList or TCPFwdList
author Matt Johnston <matt@ucc.asn.au>
date Mon, 06 Jul 2009 12:59:13 +0000
parents 7282370416a0
children 52d7301e46bd
comparison
equal deleted inserted replaced
550:61c3513825b0 551:c3f2ec71e3d4
38 ret->dsskey = NULL; 38 ret->dsskey = NULL;
39 #endif 39 #endif
40 #ifdef DROPBEAR_RSA 40 #ifdef DROPBEAR_RSA
41 ret->rsakey = NULL; 41 ret->rsakey = NULL;
42 #endif 42 #endif
43 return ret; 43 ret->filename = NULL;
44 44 ret->type = DROPBEAR_SIGNKEY_NONE;
45 ret->source = SIGNKEY_SOURCE_INVALID;
46 return ret;
45 } 47 }
46 48
47 /* Returns "ssh-dss" or "ssh-rsa" corresponding to the type. Exits fatally 49 /* Returns "ssh-dss" or "ssh-rsa" corresponding to the type. Exits fatally
48 * if the type is invalid */ 50 * if the type is invalid */
49 const char* signkey_name_from_type(int type, int *namelen) { 51 const char* signkey_name_from_type(int type, int *namelen) {
78 if (namelen == SSH_SIGNKEY_DSS_LEN 80 if (namelen == SSH_SIGNKEY_DSS_LEN
79 && memcmp(name, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN) == 0) { 81 && memcmp(name, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN) == 0) {
80 return DROPBEAR_SIGNKEY_DSS; 82 return DROPBEAR_SIGNKEY_DSS;
81 } 83 }
82 #endif 84 #endif
85
86 TRACE(("signkey_type_from_name unexpected key type."))
87 printhex("Key type", name, namelen);
83 88
84 return DROPBEAR_SIGNKEY_NONE; 89 return DROPBEAR_SIGNKEY_NONE;
85 } 90 }
86 91
87 /* returns DROPBEAR_SUCCESS on success, DROPBEAR_FAILURE on fail. 92 /* returns DROPBEAR_SUCCESS on success, DROPBEAR_FAILURE on fail.
99 ident = buf_getstring(buf, &len); 104 ident = buf_getstring(buf, &len);
100 keytype = signkey_type_from_name(ident, len); 105 keytype = signkey_type_from_name(ident, len);
101 m_free(ident); 106 m_free(ident);
102 107
103 if (*type != DROPBEAR_SIGNKEY_ANY && *type != keytype) { 108 if (*type != DROPBEAR_SIGNKEY_ANY && *type != keytype) {
109 TRACE(("buf_get_pub_key bad type - got %d, expected %d", keytype, type))
104 return DROPBEAR_FAILURE; 110 return DROPBEAR_FAILURE;
105 } 111 }
112
113 TRACE(("buf_get_pub_key keytype is %d"))
106 114
107 *type = keytype; 115 *type = keytype;
108 116
109 /* Rewind the buffer back before "ssh-rsa" etc */ 117 /* Rewind the buffer back before "ssh-rsa" etc */
110 buf_incrpos(buf, -len - 4); 118 buf_incrpos(buf, -len - 4);
253 #ifdef DROPBEAR_RSA 261 #ifdef DROPBEAR_RSA
254 rsa_key_free(key->rsakey); 262 rsa_key_free(key->rsakey);
255 key->rsakey = NULL; 263 key->rsakey = NULL;
256 #endif 264 #endif
257 265
266 m_free(key->filename);
267
258 m_free(key); 268 m_free(key);
259 TRACE(("leave sign_key_free")) 269 TRACE(("leave sign_key_free"))
260 } 270 }
261 271
262 static char hexdig(unsigned char x) { 272 static char hexdig(unsigned char x) {
356 366
357 void buf_put_sign(buffer* buf, sign_key *key, int type, 367 void buf_put_sign(buffer* buf, sign_key *key, int type,
358 const unsigned char *data, unsigned int len) { 368 const unsigned char *data, unsigned int len) {
359 369
360 buffer *sigblob; 370 buffer *sigblob;
361
362 sigblob = buf_new(MAX_PUBKEY_SIZE); 371 sigblob = buf_new(MAX_PUBKEY_SIZE);
363 372
364 #ifdef DROPBEAR_DSS 373 #ifdef DROPBEAR_DSS
365 if (type == DROPBEAR_SIGNKEY_DSS) { 374 if (type == DROPBEAR_SIGNKEY_DSS) {
366 buf_put_dss_sign(sigblob, key->dsskey, data, len); 375 buf_put_dss_sign(sigblob, key->dsskey, data, len);
372 } 381 }
373 #endif 382 #endif
374 if (sigblob->len == 0) { 383 if (sigblob->len == 0) {
375 dropbear_exit("non-matching signing type"); 384 dropbear_exit("non-matching signing type");
376 } 385 }
377
378 buf_setpos(sigblob, 0); 386 buf_setpos(sigblob, 0);
379 buf_putstring(buf, buf_getptr(sigblob, sigblob->len), 387 buf_putstring(buf, buf_getptr(sigblob, sigblob->len),
380 sigblob->len); 388 sigblob->len);
381 389
382 buf_free(sigblob); 390 buf_free(sigblob);