4 #include "keyconvert.h"
7 int main(int argc, char **argv)
10 char inbytes[16384], *inptr;
11 char decodedKey[16384];
17 fprintf(stderr, "syntax: keyconvert <infile> <outfile>\n");
21 fin = fopen(argv[1], "rt");
23 fprintf(stderr, "failed to open %s\n", argv[1]);
27 memset(inbytes, 0, sizeof(inbytes));
28 len = fread(inbytes, 1, sizeof(inbytes), fin);
31 // fprintf(stdout, "read %d bytes from openssh file\n", len);
36 while (isspace(*inptr)) inptr++;
38 // skip the ssh-rsa or ssh-dsa part
39 while (*inptr && !isspace(*inptr)) inptr++;
41 // skip spaces between ssh-rsa/ssh-dsa and key
42 while (isspace(*inptr)) inptr++;
44 // if there is any part after the key, terminate it
45 if (strchr(inptr, ' ') != NULL) {
46 *strchr(inptr, ' ') = '\0';
49 // at this point, inptr contains the b64 encoded openssh key
51 len = b64decode(inptr, decodedKey);
53 // fprintf(stdout, "decoded openssh file length is %d\n", len);
55 fout = fopen(argv[2], "wt");
57 fprintf(stderr, "failed to open output file %s\n", argv[2]);
61 openssh_binary_to_openssl(decodedKey, len, fout);
65 fprintf(stdout, "completed\n");