Mercurial > dropbear
comparison svr-authpubkey.c @ 1881:d39cfedaf015
extract pubkey_info when seuccesfully auth with a key and free it in the cleanup function
author | HansH111 <hans@atbas.org> |
---|---|
date | Sun, 13 Mar 2022 17:38:13 +0000 |
parents | 064f5be2fc45 |
children | f54451afc046 |
comparison
equal
deleted
inserted
replaced
1880:4c1560627693 | 1881:d39cfedaf015 |
---|---|
259 | 259 |
260 static int checkpubkey_line(buffer* line, int line_num, const char* filename, | 260 static int checkpubkey_line(buffer* line, int line_num, const char* filename, |
261 const char* algo, unsigned int algolen, | 261 const char* algo, unsigned int algolen, |
262 const unsigned char* keyblob, unsigned int keybloblen) { | 262 const unsigned char* keyblob, unsigned int keybloblen) { |
263 buffer *options_buf = NULL; | 263 buffer *options_buf = NULL; |
264 unsigned int pos, len; | 264 unsigned int pos, len, infopos, infolen; |
265 int ret = DROPBEAR_FAILURE; | 265 int ret = DROPBEAR_FAILURE; |
266 | 266 |
267 if (line->len < MIN_AUTHKEYS_LINE || line->len > MAX_AUTHKEYS_LINE) { | 267 if (line->len < MIN_AUTHKEYS_LINE || line->len > MAX_AUTHKEYS_LINE) { |
268 TRACE(("checkpubkey_line: bad line length %d", line->len)) | 268 TRACE(("checkpubkey_line: bad line length %d", line->len)) |
269 goto out; | 269 goto out; |
342 /* truncate the line at the space after the base64 data */ | 342 /* truncate the line at the space after the base64 data */ |
343 pos = line->pos; | 343 pos = line->pos; |
344 for (len = 0; line->pos < line->len; len++) { | 344 for (len = 0; line->pos < line->len; len++) { |
345 if (buf_getbyte(line) == ' ') break; | 345 if (buf_getbyte(line) == ' ') break; |
346 } | 346 } |
347 /* findout the length of the public key info */ | |
348 infopos = line->pos; | |
349 for (infolen = 0; line->pos < line->len; infolen++) { | |
350 if (buf_getbyte(line) == ' ') break; | |
351 } | |
347 buf_setpos(line, pos); | 352 buf_setpos(line, pos); |
348 buf_setlen(line, line->pos + len); | 353 buf_setlen(line, line->pos + len); |
349 | 354 |
350 TRACE(("checkpubkey_line: line pos = %d len = %d", line->pos, line->len)) | 355 TRACE(("checkpubkey_line: line pos = %d len = %d", line->pos, line->len)) |
351 | 356 |
352 ret = cmp_base64_key(keyblob, keybloblen, (const unsigned char *) algo, algolen, line, NULL); | 357 ret = cmp_base64_key(keyblob, keybloblen, (const unsigned char *) algo, algolen, line, NULL); |
353 | 358 |
354 if (ret == DROPBEAR_SUCCESS && options_buf) { | 359 if (ret == DROPBEAR_SUCCESS) { |
355 ret = svr_add_pubkey_options(options_buf, line_num, filename); | 360 if (options_buf) { |
361 ret = svr_add_pubkey_options(options_buf, line_num, filename); | |
362 } | |
363 /* save the (optional) public key information */ | |
364 if (infolen) { | |
365 ses.authstate.pubkey_info = m_malloc(infolen + 1); | |
366 if (ses.authstate.pubkey_info) { | |
367 strncpy(ses.authstate.pubkey_info, &line->data[infopos], infolen); | |
368 ses.authstate.pubkey_info[infolen]='\0'; | |
369 } | |
370 } else { | |
371 ses.authstate.pubkey_info = NULL; | |
372 } | |
356 } | 373 } |
357 | 374 |
358 out: | 375 out: |
359 if (options_buf) { | 376 if (options_buf) { |
360 buf_free(options_buf); | 377 buf_free(options_buf); |