rsa2x509.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. #include <auth.h>
  13. #include <mp.h>
  14. #include <libsec.h>
  15. #include "rsa2any.h"
  16. void
  17. usage(void)
  18. {
  19. fprint(2, "usage: auth/rsa2x509 [-e expireseconds] 'C=US ...CN=xxx' [key]");
  20. exits("usage");
  21. }
  22. void
  23. main(int argc, char **argv)
  24. {
  25. int len;
  26. unsigned char *cert;
  27. uint32_t valid[2];
  28. RSApriv *key;
  29. fmtinstall('B', mpfmt);
  30. fmtinstall('H', encodefmt);
  31. valid[0] = time(0);
  32. valid[1] = valid[0] + 3*366*24*60*60;
  33. ARGBEGIN{
  34. default:
  35. usage();
  36. case 'e':
  37. valid[1] = valid[0] + strtoul(ARGF(), 0, 10);
  38. break;
  39. }ARGEND
  40. if(argc != 1 && argc != 2)
  41. usage();
  42. if((key = getkey(argc-1, argv+1, 1, nil)) == nil)
  43. sysfatal("%r");
  44. cert = X509gen(key, argv[0], valid, &len);
  45. if(cert == nil)
  46. sysfatal("X509gen: %r");
  47. write(1, cert, len);
  48. exits(0);
  49. }