shithub: riscv

Download patch

ref: 8c9e7ded1758daabd43d35ea3e141cef4d914604
parent: 420ed37c576ea9767e8704a7b84728b945b38368
author: mischief <[email protected]>
date: Sun Oct 27 14:50:14 EDT 2013

auth/rsa2ssh: add SSH2 RSA output format (from plan9port)

--- a/sys/man/8/rsa
+++ b/sys/man/8/rsa
@@ -33,6 +33,13 @@
 .PP
 .B rsa2ssh
 [
+.B -2
+]
+[
+.B -c
+.I comment
+]
+[
 .I file
 ]
 .PP
@@ -170,6 +177,11 @@
 .BR ek ,
 and
 .BR n .
+The
+.B -2
+option will change the output to SSH2 RSA public key format. The
+.B -c
+option will set the comment.
 For compatibility with external SSH implementations, the public keys in
 .B /sys/lib/ssh/keyring
 and
--- a/sys/src/cmd/auth/rsa2ssh.c
+++ b/sys/src/cmd/auth/rsa2ssh.c
@@ -8,7 +8,7 @@
 void
 usage(void)
 {
-	fprint(2, "usage: auth/rsa2ssh [file]\n");
+	fprint(2, "usage: auth/rsa2ssh [-2] [-c comment] [file]\n");
 	exits("usage");
 }
 
@@ -16,10 +16,21 @@
 main(int argc, char **argv)
 {
 	RSApriv *k;
+	int ssh2;
+	char *comment;
 
 	fmtinstall('B', mpfmt);
+	fmtinstall('[', encodefmt);
 
+	comment = "";
+
 	ARGBEGIN{
+	case 'c':
+		comment = EARGF(usage());
+		break;
+	case '2':
+		ssh2 = 1;
+		break;
 	default:
 		usage();
 	}ARGEND
@@ -30,6 +41,19 @@
 	if((k = getkey(argc, argv, 0, nil)) == nil)
 		sysfatal("%r");
 
-	print("%d %.10B %.10B\n", mpsignif(k->pub.n), k->pub.ek, k->pub.n);
+	if(ssh2) {
+		uchar buf[8192], *p;
+
+		p = buf;
+		p = put4(p, 7);
+		p = putn(p, "ssh-rsa", 7);
+		p = putmp2(p, k->pub.ek);
+		p = putmp2(p, k->pub.n);
+
+		print("ssh-rsa %.*[ %s\n", p-buf, buf, comment);
+	} else {
+		print("%d %.10B %.10B %s\n", mpsignif(k->pub.n), k->pub.ek, k->pub.n, comment);
+	}
+
 	exits(nil);
 }