static void ask_to_confirm(unsigned char* keyblob, unsigned int keybloblen) { char* fp = NULL; FILE *tty = NULL; char response = 'z'; fp = sign_key_fingerprint(keyblob, keybloblen); if (cli_opts.always_accept_key) { fprintf(stderr, "\nHost '%s' key accepted unconditionally.\n(fingerprint %s)\n", cli_opts.remotehost, fp); m_free(fp); return; } fprintf(stderr, "\nHost '%s' is not in the trusted hosts file.\n(fingerprint %s)\nDo you want to continue connecting? (y/n) ", cli_opts.remotehost, fp); m_free(fp); tty = fopen(_PATH_TTY, "r"); if (tty) { response = getc(tty); fclose(tty); } else { response = getc(stdin); } if (response == 'y') { return; } dropbear_exit("Didn't validate host key"); }
static void printpubkey(sign_key * key, int keytype) { buffer * buf = NULL; unsigned char base64key[MAX_PUBKEY_SIZE*2]; unsigned long base64len; int err; const char * typestring = NULL; char *fp = NULL; int len; struct passwd * pw = NULL; char * username = NULL; char hostname[100]; buf = buf_new(MAX_PUBKEY_SIZE); buf_put_pub_key(buf, key, keytype); buf_setpos(buf, 4); len = buf->len - buf->pos; base64len = sizeof(base64key); err = base64_encode(buf_getptr(buf, len), len, base64key, &base64len); if (err != CRYPT_OK) { fprintf(stderr, "base64 failed"); } typestring = signkey_name_from_type(keytype, NULL); fp = sign_key_fingerprint(buf_getptr(buf, len), len); /* a user@host comment is informative */ username = ""; pw = getpwuid(getuid()); if (pw) { username = pw->pw_name; } gethostname(hostname, sizeof(hostname)); hostname[sizeof(hostname)-1] = '\0'; printf("Public key portion is:\n%s %s %s@%s\nFingerprint: %s\n", typestring, base64key, username, hostname, fp); m_free(fp); buf_free(buf); }