plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

rsa2ssh.c (873B)


      1 #include <u.h>
      2 #include <libc.h>
      3 #include <auth.h>
      4 #include <mp.h>
      5 #include <libsec.h>
      6 #include "rsa2any.h"
      7 
      8 int ssh2;
      9 
     10 void
     11 usage(void)
     12 {
     13 	fprint(2, "usage: auth/rsa2ssh [-2] [-c comment] [file]\n");
     14 	exits("usage");
     15 }
     16 
     17 void
     18 main(int argc, char **argv)
     19 {
     20 	RSApriv *k;
     21 	char *comment;
     22 
     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
     36 
     37 	if(argc > 1)
     38 		usage();
     39 
     40 	if((k = getkey(argc, argv, 0, nil)) == nil)
     41 		sysfatal("%r");
     42 
     43 	if(ssh2){
     44 		uchar buf[8192], *p;
     45 
     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 }