Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. import sys,json
  2. from string import Template
  3.  
  4. print 'Number of arguments:', len(sys.argv), 'arguments.'
  5.  
  6. if (len(sys.argv) < 2) :
  7. print("To use the script you must run it in the following way:")
  8. print("python script.py <name_of_the_json_file_to_load>")
  9. sys.kill(1)
  10.  
  11. with open(str(sys.argv[1])) as data_file :
  12. data = json.load(data_file)
  13.  
  14. for person in data :
  15. print(person["mail"])
  16.  
  17. commonNameNoSpace = person["commonName"].encode("utf-8").replace(" ", "")
  18.  
  19. createCert = Template('openssl req -new -nodes -config openssl.cnf -keyout sample-ca/client_$commonNameNoSpace.key -out sample-ca/client_$commonNameNoSpace.csr -subj "/C=$country/ST=$state/O=$organization/CN=$commonName/emailAddress=$mail"')
  20. signCert = Template('openssl ca -batch -config openssl.cnf -out sample-ca/client_$commonNameNoSpace.crt -in sample-ca/client_$commonNameNoSpace.csr')
  21. createKey = Template('openssl rsa -aes256 -passout pass:M4tr1x2017 -in sample-ca/client_$commonNameNoSpace.key -out sample-ca/client-pass_$commonNameNoSpace.key')
  22. exportKeys = Template('openssl pkcs12 -export -nodes -password pass:M4tr1x2017 -out sample-ca/client_$commonNameNoSpace.p12 -inkey sample-ca/client_$commonNameNoSpace.key -in sample-ca/client_$commonNameNoSpace.crt -certfile sample-ca/ca.crt')
  23.  
  24. print createCert.substitute(country=person["country"].encode("utf-8"),state=person["state"].encode("utf-8"),organization=person["organization"].encode("utf-8"),commonName=person["commonName"].encode("utf-8"),commonNameNoSpace=commonNameNoSpace,mail=person["mail"].encode("utf-8"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement