From 8c9e7ded1758daabd43d35ea3e141cef4d914604 Mon Sep 17 00:00:00 2001 From: mischief Date: Sun, 27 Oct 2013 18:50:14 -0700 Subject: [PATCH] auth/rsa2ssh: add SSH2 RSA output format (from plan9port) --- sys/man/8/rsa | 12 ++++++++++++ sys/src/cmd/auth/rsa2ssh.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/sys/man/8/rsa b/sys/man/8/rsa index cc0ca8af0..c78d7d741 100644 --- a/sys/man/8/rsa +++ b/sys/man/8/rsa @@ -33,6 +33,13 @@ rsagen, rsafill, asn12rsa, rsa2pub, rsa2ssh, rsa2x509 \- generate and format rsa .PP .B rsa2ssh [ +.B -2 +] +[ +.B -c +.I comment +] +[ .I file ] .PP @@ -170,6 +177,11 @@ in the format used by SSH: three space-separated decimal numbers .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 diff --git a/sys/src/cmd/auth/rsa2ssh.c b/sys/src/cmd/auth/rsa2ssh.c index 96f1b1ed0..9dc3afc1b 100644 --- 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 @@ void 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 @@ main(int argc, char **argv) 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); }