diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2019-08-30 07:34:35 +0200 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2019-08-30 07:34:35 +0200 |
commit | 85216d3d95505c19a57d3bbe74e8a7eca109a8e6 (patch) | |
tree | 11be5cfbb3a1ab2854013be14f0728ea2d2a346a /sys/src/cmd/auth/rsa2asn1.c | |
parent | 7bb1a9a18566ea9c8ae7f6c2fa99e448026521d2 (diff) |
auth/rsa2asn1: implement private key export with -a flag (thanks kvik)
kvik writes:
I needed to convert the RSA private key that was laying around in
secstore into a format understood by UNIX® tools like SSH.
With asn12rsa(8) we can go from the ASN.1/DER to Plan 9 format, but not
back - so I wrote the libsec function asn1encodeRSApriv(2) and used it in
rsa2asn1(8) by adding the -a flag which causes the full private key to be
encoded and output.
Diffstat (limited to 'sys/src/cmd/auth/rsa2asn1.c')
-rw-r--r-- | sys/src/cmd/auth/rsa2asn1.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/sys/src/cmd/auth/rsa2asn1.c b/sys/src/cmd/auth/rsa2asn1.c index 51f82282e..cf7bfc77d 100644 --- a/sys/src/cmd/auth/rsa2asn1.c +++ b/sys/src/cmd/auth/rsa2asn1.c @@ -5,10 +5,12 @@ #include <libsec.h> #include "rsa2any.h" +int privatekey = 0; + void usage(void) { - fprint(2, "usage: auth/rsa2asn1 [file]\n"); + fprint(2, "usage: auth/rsa2asn1 [-a] [file]\n"); exits("usage"); } @@ -20,6 +22,9 @@ main(int argc, char **argv) int n; ARGBEGIN{ + case 'a': + privatekey = 1; + break; default: usage(); }ARGEND @@ -27,10 +32,15 @@ main(int argc, char **argv) if(argc > 1) usage(); - if((k = getrsakey(argc, argv, 0, nil)) == nil) + if((k = getrsakey(argc, argv, privatekey, nil)) == nil) sysfatal("%r"); - if((n = asn1encodeRSApub(&k->pub, buf, sizeof(buf))) < 0) - sysfatal("asn1encodeRSApub: %r"); + if(privatekey){ + if((n = asn1encodeRSApriv(k, buf, sizeof(buf))) < 0) + sysfatal("asn1encodeRSApriv: %r"); + }else{ + if((n = asn1encodeRSApub(&k->pub, buf, sizeof(buf))) < 0) + sysfatal("asn1encodeRSApub: %r"); + } if(write(1, buf, n) != n) sysfatal("write: %r"); exits(nil); |