auth/asn12rsa: also convert ASN.1 encoded public key to plan9 format

This commit is contained in:
cinap_lenrek 2018-02-05 03:21:51 +01:00
parent 58914b4b0b
commit d06196ab87
2 changed files with 16 additions and 10 deletions

View file

@ -149,7 +149,7 @@ attributes if they are missing,
and prints a full key.
.PP
.I Asn12rsa
reads an RSA private key stored as ASN.1
reads an RSA private or public key stored as ASN.1
encoded in the binary Distinguished Encoding Rules (DER)
and prints a Plan 9 RSA key,
inserting

View file

@ -20,6 +20,7 @@ main(int argc, char **argv)
long n, tot;
char *tag, *file;
RSApriv *key;
RSApub *pub;
fmtinstall('B', mpfmt);
@ -54,16 +55,21 @@ main(int argc, char **argv)
break;
tot += n;
}
key = asn1toRSApriv(buf, tot);
if(key == nil)
sysfatal("couldn't parse asn1 key");
s = smprint("key proto=rsa %s%ssize=%d ek=%B !dk=%B n=%B !p=%B !q=%B !kp=%B !kq=%B !c2=%B\n",
tag ? tag : "", tag ? " " : "",
mpsignif(key->pub.n), key->pub.ek,
key->dk, key->pub.n, key->p, key->q,
key->kp, key->kq, key->c2);
if(key != nil){
s = smprint("key proto=rsa %s%ssize=%d ek=%B !dk=%B n=%B !p=%B !q=%B !kp=%B !kq=%B !c2=%B\n",
tag ? tag : "", tag ? " " : "",
mpsignif(key->pub.n), key->pub.ek,
key->dk, key->pub.n, key->p, key->q,
key->kp, key->kq, key->c2);
} else {
pub = asn1toRSApub(buf, tot);
if(pub == nil)
sysfatal("couldn't parse asn1 key");
s = smprint("key proto=rsa %s%ssize=%d ek=%B n=%B\n",
tag ? tag : "", tag ? " " : "",
mpsignif(pub->n), pub->ek, pub->n);
}
if(s == nil)
sysfatal("smprint: %r");
write(1, s, strlen(s));