123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- #include "includes.h"
- #include "signkey.h"
- #include "buffer.h"
- #include "dbutil.h"
- #include "keyimport.h"
- #include "crypto_desc.h"
- #include "dbrandom.h"
- static int do_convert(int intype, const char* infile, int outtype,
- const char* outfile);
- static void printhelp(char * progname);
- static void printhelp(char * progname) {
- fprintf(stderr, "Usage: %s <inputtype> <outputtype> <inputfile> <outputfile>\n\n"
- "CAUTION: This program is for convenience only, and is not secure if used on\n"
- "untrusted input files, ie it could allow arbitrary code execution.\n"
- "All parameters must be specified in order.\n"
- "\n"
- "The input and output types are one of:\n"
- "openssh\n"
- "dropbear\n"
- "\n"
- "Example:\n"
- "dropbearconvert openssh dropbear /etc/ssh/ssh_host_rsa_key /etc/dropbear_rsa_host_key\n",
- progname);
- }
- #if defined(DBMULTI_dropbearconvert) || !DROPBEAR_MULTI
- #if defined(DBMULTI_dropbearconvert) && DROPBEAR_MULTI
- int dropbearconvert_main(int argc, char ** argv) {
- #else
- int main(int argc, char ** argv) {
- #endif
- int intype, outtype;
- const char* infile;
- const char* outfile;
- crypto_init();
- seedrandom();
- #if DEBUG_TRACE
-
- debug_trace = DROPBEAR_VERBOSE_LEVEL;
- #endif
-
- if (argc != 5) {
- fprintf(stderr, "All arguments must be specified\n");
- goto usage;
- }
-
- if (argv[1][0] == 'd') {
- intype = KEYFILE_DROPBEAR;
- } else if (argv[1][0] == 'o') {
- intype = KEYFILE_OPENSSH;
- } else {
- fprintf(stderr, "Invalid input key type\n");
- goto usage;
- }
-
- if (argv[2][0] == 'd') {
- outtype = KEYFILE_DROPBEAR;
- } else if (argv[2][0] == 'o') {
- outtype = KEYFILE_OPENSSH;
- } else {
- fprintf(stderr, "Invalid output key type\n");
- goto usage;
- }
-
- umask(077);
- infile = argv[3];
- outfile = argv[4];
- return do_convert(intype, infile, outtype, outfile);
- usage:
- printhelp(argv[0]);
- return 1;
- }
- #endif
- static int do_convert(int intype, const char* infile, int outtype,
- const char* outfile) {
- sign_key * key = NULL;
- const char * keytype = NULL;
- int ret = 1;
- key = import_read(infile, NULL, intype);
- if (!key) {
- fprintf(stderr, "Error reading key from '%s'\n",
- infile);
- goto out;
- }
- keytype = signkey_name_from_type(key->type, NULL);
- fprintf(stderr, "Key is a %s key\n", keytype);
- if (import_write(outfile, key, NULL, outtype) != 1) {
- fprintf(stderr, "Error writing key to '%s'\n", outfile);
- } else {
- fprintf(stderr, "Wrote key to '%s'\n", outfile);
- ret = 0;
- }
- out:
- if (key) {
- sign_key_free(key);
- }
- return ret;
- }
|