#!/usr/bin/env python from certs import gencerts import os,sys,getopt ## def gencerts(c,st,l,o,ou,cn,crldp,passphrase): def main(argv): c=u'UK' st=u'England' l=u'Manchester' o=u'Jisc' ou=u'Govroam' cn=u'something.somewhere.com' crldp=u'http://something.somewhere.com/crldp' passphrase=b'something' try: opts, args = getopt.getopt(argv,"c:s:l:o:u:n:r:p:d:") except getopt.GetoptError: print "cli.py -c -s -l -o -ou -n -r -p -d " sys.exit(2) for opt, arg in opts: if opt == '-c': c=unicode(arg, "utf-8") if opt == '-s': st=unicode(arg, "utf-8") if opt == '-l': l=unicode(arg, "utf-8") if opt == '-o': o=unicode(arg, "utf-8") if opt == '-u': ou=unicode(arg, "utf-8") if opt == '-n': cn=unicode(arg, "utf-8") if opt == '-r': crldp=unicode(arg, "utf-8") if opt == '-p': password=unicode(arg, "utf-8") if opt == '-d': directory=unicode(arg, "utf-8") if not os.path.exists(directory): os.makedirs(directory) ## return csrsubject,output_cert(cacert),output_key_encrypted(cakey,passphrase),output_key_ ## encrypted(csrkey,passphrase),output_cert(servercert),output_cert(csrcert),output_cert(crlc ## ert) csrsubject, cacert, cakey_enc, csrkey_enc, servercert, csrcert, crlcert = gencerts(c,st,l,o,ou,cn,crldp,passphrase) with open (directory + '/rootca.pem','w') as f: f.write(cacert) f.close with open (directory + '/root-key.pem','w') as f: f.write(cakey_enc) f.close with open (directory + '/csrkey.pem','w') as f: f.write(csrkey_enc) f.close with open (directory + '/server-cert.pem','w') as f: f.write(servercert) f.close with open (directory + '/server-key.pem','w') as f: f.write(csrcert) f.close with open (directory + '/list.crl','w') as f: f.write(crlcert) f.close if __name__ == "__main__": main(sys.argv[1:])