2 * Dropbear - a SSH2 server
4 * Copyright (c) 2002,2003 Matt Johnston
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 /* This program converts to/from Dropbear and OpenSSH private-key formats */
30 #include "keyimport.h"
31 #include "crypto_desc.h"
35 static int do_convert(int intype
, const char* infile
, int outtype
,
38 static void printhelp(char * progname
);
40 static void printhelp(char * progname
) {
42 fprintf(stderr
, "Usage: %s <inputtype> <outputtype> <inputfile> <outputfile>\n\n"
43 "CAUTION: This program is for convenience only, and is not secure if used on\n"
44 "untrusted input files, ie it could allow arbitrary code execution.\n"
45 "All parameters must be specified in order.\n"
47 "The input and output types are one of:\n"
52 "dropbearconvert openssh dropbear /etc/ssh/ssh_host_rsa_key /etc/dropbear_rsa_host_key\n",
56 #if defined(DBMULTI_dropbearconvert) || !defined(DROPBEAR_MULTI)
57 #if defined(DBMULTI_dropbearconvert) && defined(DROPBEAR_MULTI)
58 int dropbearconvert_main(int argc
, char ** argv
) {
60 int main(int argc
, char ** argv
) {
71 /* It's hard for it to get in the way _too_ much */
75 /* get the commandline options */
77 fprintf(stderr
, "All arguments must be specified\n");
82 if (argv
[1][0] == 'd') {
83 intype
= KEYFILE_DROPBEAR
;
84 } else if (argv
[1][0] == 'o') {
85 intype
= KEYFILE_OPENSSH
;
87 fprintf(stderr
, "Invalid input key type\n");
92 if (argv
[2][0] == 'd') {
93 outtype
= KEYFILE_DROPBEAR
;
94 } else if (argv
[2][0] == 'o') {
95 outtype
= KEYFILE_OPENSSH
;
97 fprintf(stderr
, "Invalid output key type\n");
101 /* we don't want output readable by others */
107 return do_convert(intype
, infile
, outtype
, outfile
);
115 static int do_convert(int intype
, const char* infile
, int outtype
,
116 const char* outfile
) {
118 sign_key
* key
= NULL
;
119 const char * keytype
= NULL
;
122 key
= import_read(infile
, NULL
, intype
);
124 fprintf(stderr
, "Error reading key from '%s'\n",
129 keytype
= signkey_name_from_type(key
->type
, NULL
);
131 fprintf(stderr
, "Key is a %s key\n", keytype
);
133 if (import_write(outfile
, key
, NULL
, outtype
) != 1) {
134 fprintf(stderr
, "Error writing key to '%s'\n", outfile
);
136 fprintf(stderr
, "Wrote key to '%s'\n", outfile
);