Jean-Paul Calderone | 897bc25 | 2008-02-18 20:50:23 -0500 | [diff] [blame^] | 1 | """ |
| 2 | Create certificates and private keys for the 'simple' example. |
| 3 | """ |
| 4 | |
| 5 | from OpenSSL import crypto |
| 6 | from certgen import * # yes yes, I know, I'm lazy |
| 7 | cakey = createKeyPair(TYPE_RSA, 1024) |
| 8 | careq = createCertRequest(cakey, CN='Certificate Authority') |
| 9 | cacert = createCertificate(careq, (careq, cakey), 0, (0, 60*60*24*365*5)) # five years |
| 10 | open('simple/CA.pkey', 'w').write(crypto.dump_privatekey(crypto.FILETYPE_PEM, cakey)) |
| 11 | open('simple/CA.cert', 'w').write(crypto.dump_certificate(crypto.FILETYPE_PEM, cacert)) |
| 12 | for (fname, cname) in [('client', 'Simple Client'), ('server', 'Simple Server')]: |
| 13 | pkey = createKeyPair(TYPE_RSA, 1024) |
| 14 | req = createCertRequest(pkey, CN=cname) |
| 15 | cert = createCertificate(req, (cacert, cakey), 1, (0, 60*60*24*365*5)) # five years |
| 16 | open('simple/%s.pkey' % (fname,), 'w').write(crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey)) |
| 17 | open('simple/%s.cert' % (fname,), 'w').write(crypto.dump_certificate(crypto.FILETYPE_PEM, cert)) |