~divmod-dev/divmod.org/trunk

« back to all changes in this revision

Viewing changes to Epsilon/epsilon/scripts/certcreate.py

  • Committer: Jean-Paul Calderone
  • Date: 2014-06-29 20:33:04 UTC
  • mfrom: (2749.1.1 remove-epsilon-1325289)
  • Revision ID: exarkun@twistedmatrix.com-20140629203304-gdkmbwl1suei4m97
mergeĀ lp:~exarkun/divmod.org/remove-epsilon-1325289

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2005-2008 Divmod, Inc.  See LICENSE file for details
2
 
 
3
 
import sys
4
 
 
5
 
from twisted.python import usage
6
 
from twisted.internet.ssl import KeyPair
7
 
 
8
 
 
9
 
class Options(usage.Options):
10
 
    optParameters = [
11
 
        ["country", "C", "US", None],
12
 
        ["state", "s", "New York", None],
13
 
        ["city", "c", "New York", None],
14
 
        ["organization", "o", "Divmod LLC", None],
15
 
        ["unit", "u", "Security", None],
16
 
        ["hostname", "h", "divmod.com", None],
17
 
        ["email", "e", "support@divmod.org", None],
18
 
 
19
 
        ["filename", "f", "server.pem", "Name of the file to which to write the PEM."],
20
 
        ["serial-number", "S", 1, None],
21
 
    ]
22
 
 
23
 
    optFlags = [
24
 
        ['quiet', 'q']
25
 
    ]
26
 
 
27
 
 
28
 
 
29
 
def createSSLCertificate(opts):
30
 
    sslopt = {}
31
 
    for x, y in (('country','C'),
32
 
                 ('state', 'ST'),
33
 
                 ('city', 'L'),
34
 
                 ('organization', 'O'),
35
 
                 ('unit', 'OU'),
36
 
                 ('hostname', 'CN'),
37
 
                 ('email','emailAddress')):
38
 
        sslopt[y] = opts[x]
39
 
    serialNumber = int(opts['serial-number'])
40
 
    ssc = KeyPair.generate().selfSignedCert(serialNumber, **sslopt)
41
 
    file(opts['filename'], 'w').write(ssc.dumpPEM())
42
 
    if not opts['quiet']:
43
 
        print 'Wrote SSL certificate:'
44
 
        print ssc.inspect()
45
 
    return ssc
46
 
 
47
 
 
48
 
 
49
 
def main(args=None):
50
 
    """
51
 
    Create a private key and a certificate and write them to a file.
52
 
    """
53
 
    if args is None:
54
 
        args = sys.argv[1:]
55
 
 
56
 
    o = Options()
57
 
    try:
58
 
        o.parseOptions(args)
59
 
    except usage.UsageError, e:
60
 
        raise SystemExit(str(e))
61
 
    else:
62
 
        return createSSLCertificate(o)