3
########################################################################
5
# (c) by Michael Stroeder, michael@stroeder.com
6
########################################################################
10
########################################################################
11
# This short script creates a pickled object file of the
12
# OpenSSL configuration file.
13
########################################################################
15
import sys, string, os, pickle, getopt
17
def findoption(options,paramname):
23
def PrintUsage(ErrorMsg='',ErrorCode=1):
24
script_name = string.split(sys.argv[0],os.sep)[-1]
25
sys.stderr.write("""*** %s *** (C) by Michael Stroeder, 1999
32
Print out this message
35
Pathname of OpenSSL configuration file.
36
You may also use env variable OPENSSL_CONF.
37
Default: /etc/openssl/openssl.cnf
40
Specify directory containing the pyCA modules
41
You may also use env variable PYCALIB.
42
Default: /usr/local/pyca/pylib
44
""" % (script_name,script_name))
46
sys.stderr.write('Error: %s\n' % ErrorMsg)
49
########################################################################
51
########################################################################
53
script_name=sys.argv[0]
56
options,args=getopt.getopt(sys.argv[1:],'h',['help','config=','pycalib='])
57
except getopt.error,e:
60
if findoption(options,'-h')!=() or findoption(options,'--help')!=():
63
if findoption(options,'--config')!=():
64
opensslcnfname = findoption(options,'--config')[1]
66
opensslcnfname = os.environ.get('OPENSSL_CONF','/etc/openssl/openssl.cnf')
68
if not os.path.isfile(opensslcnfname):
69
PrintUsage('Config file %s not found.' % (opensslcnfname))
71
if findoption(options,'--pycalib')!=():
72
pycalib = findoption(options,'--pycalib')[1]
74
pycalib = os.environ.get('PYCALIB','/usr/local/pyca/pylib')
76
if not os.path.exists(pycalib) or not os.path.isdir(pycalib):
77
PrintUsage('Module directory %s not exists or not a directory.' % (pycalib))
79
sys.path.append(pycalib)
84
PrintUsage('Module openssl not found in directory %s!' % (pycalib))
86
print 'Reading source file %s...' % (opensslcnfname)
87
opensslcnf = openssl.cnf.OpenSSLConfigClass(opensslcnfname)
89
pickle_opensslcnfname = '%s.pickle' % (opensslcnfname)
91
#if os.path.isfile(pickle_opensslcnfname):
92
# print 'Removing old pickle file %s' % (pickle_opensslcnfname)
93
# os.remove(pickle_opensslcnfname)
95
print 'Write new pickled file %s...' % (pickle_opensslcnfname)
96
f=open(pickle_opensslcnfname,'wb')
97
pickle.dump(opensslcnf, f,1)