cli.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python
  2. from certs import gencerts
  3. import os,sys,getopt
  4. def main(argv):
  5. c=u'GB'
  6. st=u'England'
  7. l=u'Manchester'
  8. o=u'WorkPlace'
  9. ou=u'WorkUnit'
  10. cn=u'Placeholder'
  11. crldp=u'http://placeholder/crldp'
  12. passphrase=b'something'
  13. directory=u'/tmp'
  14. try:
  15. opts, args = getopt.getopt(argv,"c:s:l:o:u:n:r:p:d:")
  16. except getopt.GetoptError:
  17. print "cli.py -c <County> -s <State> -l <Location> -o <Organisation> -ou <Organisation Unit> -n <CN> -r <CRLDP> -p <password> -d <Output Directory>"
  18. sys.exit(2)
  19. for opt, arg in opts:
  20. if opt == '-c':
  21. c=unicode(arg, "utf-8")
  22. if opt == '-s':
  23. st=unicode(arg, "utf-8")
  24. if opt == '-l':
  25. l=unicode(arg, "utf-8")
  26. if opt == '-o':
  27. o=unicode(arg, "utf-8")
  28. if opt == '-u':
  29. ou=unicode(arg, "utf-8")
  30. if opt == '-n':
  31. cn=unicode(arg, "utf-8")
  32. if opt == '-r':
  33. crldp=unicode(arg, "utf-8")
  34. if opt == '-p':
  35. passphrase=arg
  36. if opt == '-d':
  37. directory=unicode(arg, "utf-8")
  38. if not os.path.exists(directory):
  39. os.makedirs(directory)
  40. csrsubject, cacert, cakey_enc, csrkey_enc, servercert, csrcert, crlcert = gencerts(c,st,l,o,ou,cn,crldp,passphrase)
  41. with open (directory + '/rootca.pem','w') as f:
  42. f.write(cacert)
  43. f.close
  44. with open (directory + '/root-key.pem','w') as f:
  45. f.write(cakey_enc)
  46. f.close
  47. with open (directory + '/server-cert.pem','w') as f:
  48. f.write(servercert)
  49. f.close
  50. with open (directory + '/server-key.pem','w') as f:
  51. f.write(csrkey_enc)
  52. f.close
  53. with open (directory + '/list.crl','w') as f:
  54. f.write(crlcert)
  55. f.close
  56. if __name__ == "__main__":
  57. main(sys.argv[1:])