viff

changeset 848:be0907a7a885

Move program body to its own block.
author Martin Geisler <mg@daimi.au.dk>
date Thu, 24 Jul 2008 22:45:06 +0200
parents 1a1f4941633b
children b42cf723fa4c
files apps/generate-certificates.py
diffstat 1 files changed, 25 insertions(+), 25 deletions(-) [+]
line diff
     1.1 --- a/apps/generate-certificates.py	Thu Jul 24 22:38:14 2008 +0200
     1.2 +++ b/apps/generate-certificates.py	Thu Jul 24 22:45:06 2008 +0200
     1.3 @@ -26,20 +26,6 @@
     1.4  # CA certificate (ca.cert).
     1.5  
     1.6  from OpenSSL import crypto
     1.7 -from optparse import OptionParser
     1.8 -
     1.9 -parser = OptionParser()
    1.10 -parser.add_option("-p", "--prefix",
    1.11 -                  help="output filename prefix")
    1.12 -parser.add_option("-k", "--key-size", type="int",
    1.13 -                  help="key size")
    1.14 -parser.add_option("-n", "--players", dest="n", type="int",
    1.15 -                  help="number of players")
    1.16 -
    1.17 -parser.set_defaults(n=3, key_size=1024, prefix='player')
    1.18 -
    1.19 -(options, args) = parser.parse_args()
    1.20 -
    1.21  
    1.22  def create_key(bits, type=crypto.TYPE_RSA):
    1.23      """Create a public/private key pair."""
    1.24 @@ -81,17 +67,31 @@
    1.25      fp.write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert))
    1.26      fp.close()
    1.27  
    1.28 -ca_key = create_key(options.key_size)
    1.29 -ca_req = create_request(ca_key, "VIFF Certificate Authority")
    1.30 -ca_cert = create_cert(ca_req, ca_req, ca_key, 0)
    1.31 +if __name__ == "__main__":
    1.32 +    from optparse import OptionParser
    1.33  
    1.34 -save_key(ca_key, "ca.key")
    1.35 -save_cert(ca_cert, "ca.cert")
    1.36 +    parser = OptionParser()
    1.37 +    parser.add_option("-p", "--prefix",
    1.38 +                      help="output filename prefix")
    1.39 +    parser.add_option("-k", "--key-size", type="int",
    1.40 +                      help="key size")
    1.41 +    parser.add_option("-n", "--players", dest="n", type="int",
    1.42 +                      help="number of players")
    1.43 +    parser.set_defaults(n=3, key_size=1024, prefix='player')
    1.44  
    1.45 -for i in range(1, options.n + 1):
    1.46 -    key = create_key(options.key_size)
    1.47 -    req = create_request(key, "VIFF Player %d" % i)
    1.48 -    cert = create_cert(req, ca_cert, ca_key, i)
    1.49 +    (options, args) = parser.parse_args()
    1.50  
    1.51 -    save_key(key, "%s-%d.key" % (options.prefix, i))
    1.52 -    save_cert(cert, "%s-%d.cert" % (options.prefix, i))
    1.53 +    ca_key = create_key(options.key_size)
    1.54 +    ca_req = create_request(ca_key, "VIFF Certificate Authority")
    1.55 +    ca_cert = create_cert(ca_req, ca_req, ca_key, 0)
    1.56 +
    1.57 +    save_key(ca_key, "ca.key")
    1.58 +    save_cert(ca_cert, "ca.cert")
    1.59 +
    1.60 +    for i in range(1, options.n + 1):
    1.61 +        key = create_key(options.key_size)
    1.62 +        req = create_request(key, "VIFF Player %d" % i)
    1.63 +        cert = create_cert(req, ca_cert, ca_key, i)
    1.64 +
    1.65 +        save_key(key, "%s-%d.key" % (options.prefix, i))
    1.66 +        save_cert(cert, "%s-%d.cert" % (options.prefix, i))