Blob


1 #include <u.h>
2 #include <libc.h>
3 #include <auth.h>
4 #include <mp.h>
5 #include <libsec.h>
6 #include "rsa2any.h"
8 int ssh2;
10 void
11 usage(void)
12 {
13 fprint(2, "usage: auth/rsa2ssh [-2] [-c comment] [file]\n");
14 exits("usage");
15 }
17 void
18 main(int argc, char **argv)
19 {
20 RSApriv *k;
21 char *comment;
23 fmtinstall('B', mpfmt);
24 fmtinstall('[', encodefmt);
25 comment = "";
26 ARGBEGIN{
27 case '2':
28 ssh2 = 1;
29 break;
30 case 'c':
31 comment = EARGF(usage());
32 break;
33 default:
34 usage();
35 }ARGEND
37 if(argc > 1)
38 usage();
40 if((k = getkey(argc, argv, 0, nil)) == nil)
41 sysfatal("%r");
43 if(ssh2){
44 uchar buf[8192], *p;
46 p = buf;
47 p = put4(p, 7);
48 p = putn(p, "ssh-rsa", 7);
49 p = putmp2(p, k->pub.ek);
50 p = putmp2(p, k->pub.n);
51 print("ssh-rsa %.*[ %s\n", p-buf, buf, comment);
52 }else
53 print("%d %.10B %.10B %s\n", mpsignif(k->pub.n), k->pub.ek,
54 k->pub.n, comment);
55 exits(nil);
56 }