/* returns success or failure, and the keytype in *type. If we want * to restrict the type, type can contain a type to return */ int readhostkey(const char * filename, sign_key * hostkey, int *type) { int ret = DROPBEAR_FAILURE; buffer *buf; buf = buf_new(MAX_PRIVKEY_SIZE); if (buf_readfile(buf, filename) == DROPBEAR_FAILURE) { goto out; } buf_setpos(buf, 0); addrandom(buf_getptr(buf, buf->len), buf->len); if (buf_get_priv_key(buf, hostkey, type) == DROPBEAR_FAILURE) { goto out; } ret = DROPBEAR_SUCCESS; out: buf_burn(buf); buf_free(buf); return ret; }
/* returns success or failure */ static int readhostkey(const char * filename, sign_key * hostkey, int type) { int ret = DROPBEAR_FAILURE; int i; buffer *buf; buf = buf_new(2000); if (buf_readfile(buf, filename) == DROPBEAR_FAILURE) { goto out; } buf_setpos(buf, 0); if (buf_get_priv_key(buf, hostkey, type) == DROPBEAR_FAILURE) { goto out; } ret = DROPBEAR_SUCCESS; out: if (ret == DROPBEAR_FAILURE) { for (i = 0; sshhostkey[i].name != NULL; i++) { if (sshhostkey[i].val == type) { sshhostkey[i].usable = 0; break; } } fprintf(stderr, "Failed reading '%s', disabling %s\n", filename, type == DROPBEAR_SIGNKEY_DSS ? "DSS" : "RSA"); } buf_burn(buf); buf_free(buf); return ret; }
static int printpubfile(const char* filename) { buffer *buf = NULL; sign_key *key = NULL; enum signkey_type keytype; int ret; int err = DROPBEAR_FAILURE; buf = buf_new(MAX_PRIVKEY_SIZE); ret = buf_readfile(buf, filename); if (ret != DROPBEAR_SUCCESS) { fprintf(stderr, "Failed reading '%s'\n", filename); goto out; } key = new_sign_key(); keytype = DROPBEAR_SIGNKEY_ANY; buf_setpos(buf, 0); ret = buf_get_priv_key(buf, key, &keytype); if (ret == DROPBEAR_FAILURE) { fprintf(stderr, "Bad key in '%s'\n", filename); goto out; } printpubkey(key, keytype); err = DROPBEAR_SUCCESS; out: buf_burn(buf); buf_free(buf); buf = NULL; if (key) { sign_key_free(key); key = NULL; } return err; }