summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormischief <mischief@offblast.org>2013-10-27 18:50:14 -0700
committermischief <mischief@offblast.org>2013-10-27 18:50:14 -0700
commit8c9e7ded1758daabd43d35ea3e141cef4d914604 (patch)
treeab4314d8f67735ecf05baf33303daa61145071bf
parent420ed37c576ea9767e8704a7b84728b945b38368 (diff)
auth/rsa2ssh: add SSH2 RSA output format (from plan9port)
-rw-r--r--sys/man/8/rsa12
-rw-r--r--sys/src/cmd/auth/rsa2ssh.c28
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);
}