rsc | 57fcfc2 | 2005-02-13 18:04:20 +0000 | [diff] [blame] | 1 | #include <u.h> |
| 2 | #include <libc.h> |
| 3 | #include <bio.h> |
| 4 | #include <auth.h> |
| 5 | #include <mp.h> |
| 6 | #include <libsec.h> |
| 7 | #include "rsa2any.h" |
| 8 | |
| 9 | void |
| 10 | usage(void) |
| 11 | { |
| 12 | fprint(2, "usage: aux/rsa2csr 'C=US ...CN=xxx' [key]"); |
| 13 | exits("usage"); |
| 14 | } |
| 15 | |
| 16 | void |
| 17 | main(int argc, char **argv) |
| 18 | { |
| 19 | int len; |
| 20 | uchar *cert; |
| 21 | RSApriv *key; |
| 22 | |
| 23 | fmtinstall('B', mpfmt); |
| 24 | fmtinstall('H', encodefmt); |
| 25 | |
| 26 | ARGBEGIN{ |
| 27 | default: |
| 28 | usage(); |
| 29 | }ARGEND |
| 30 | |
| 31 | if(argc != 1 && argc != 2) |
| 32 | usage(); |
| 33 | |
| 34 | if((key = getkey(argc-1, argv+1, 1, nil)) == nil) |
| 35 | sysfatal("%r"); |
| 36 | |
| 37 | cert = X509req(key, argv[0], &len); |
| 38 | if(cert == nil) |
| 39 | sysfatal("X509req: %r"); |
| 40 | |
| 41 | write(1, cert, len); |
| 42 | exits(0); |
| 43 | } |