2 #include "keyconvert.h"
5 int main(int argc, char **argv)
8 char inbytes[16384], *inptr;
9 char decodedKey[16384];
15 fprintf(stderr, "syntax: keyconvert <infile> <outfile>\n");
19 fin = fopen(argv[1], "rt");
21 fprintf(stderr, "failed to open %s\n", argv[1]);
25 memset(inbytes, 0, sizeof(inbytes));
26 len = fread(inbytes, 1, sizeof(inbytes), fin);
29 // fprintf(stdout, "read %d bytes from openssh file\n", len);
34 while (isspace(*inptr)) inptr++;
36 // skip the ssh-rsa or ssh-dsa part
37 while (*inptr && !isspace(*inptr)) inptr++;
39 // skip spaces between ssh-rsa/ssh-dsa and key
40 while (isspace(*inptr)) inptr++;
42 // if there is any part after the key, terminate it
43 if (strchr(inptr, ' ') != NULL) {
44 *strchr(inptr, ' ') = '\0';
47 // at this point, inptr contains the b64 encoded openssh key
49 len = b64decode(inptr, decodedKey);
51 // fprintf(stdout, "decoded openssh file length is %d\n", len);
53 fout = fopen(argv[2], "wt");
55 fprintf(stderr, "failed to open output file %s\n", argv[2]);
59 openssh_binary_to_openssl(decodedKey, len, fout);
63 fprintf(stdout, "completed\n");