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

This commit is contained in:
mischief 2013-10-27 18:50:14 -07:00
parent 420ed37c57
commit 8c9e7ded17
2 changed files with 38 additions and 2 deletions

View file

@ -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

View file

@ -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);
}