|
1 #!/usr/bin/python |
|
2 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*- |
|
3 # vim: set filetype=python: |
|
4 # |
|
5 # This Source Code Form is subject to the terms of the Mozilla Public |
|
6 # License, v. 2.0. If a copy of the MPL was not distributed with this |
|
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
8 |
|
9 import tempfile, os, sys |
|
10 import random |
|
11 import pexpect |
|
12 import subprocess |
|
13 import shutil |
|
14 |
|
15 libpath = os.path.abspath('../psm_common_py') |
|
16 |
|
17 sys.path.append(libpath) |
|
18 |
|
19 import CertUtils |
|
20 |
|
21 srcdir = os.getcwd() |
|
22 db = tempfile.mkdtemp() |
|
23 |
|
24 CA_basic_constraints = "basicConstraints = critical, CA:TRUE\n" |
|
25 EE_basic_constraints = "basicConstraints = CA:FALSE\n" |
|
26 |
|
27 CA_full_ku = ("keyUsage = digitalSignature, nonRepudiation, keyEncipherment, " + |
|
28 "dataEncipherment, keyAgreement, keyCertSign, cRLSign\n") |
|
29 |
|
30 CA_eku = ("extendedKeyUsage = critical, serverAuth, clientAuth, " + |
|
31 "emailProtection, codeSigning\n") |
|
32 |
|
33 authority_key_ident = "authorityKeyIdentifier = keyid, issuer\n" |
|
34 subject_key_ident = "subjectKeyIdentifier = hash\n" |
|
35 |
|
36 |
|
37 |
|
38 def generate_certs(): |
|
39 key_type = 'rsa' |
|
40 ca_ext = CA_basic_constraints + CA_full_ku + subject_key_ident + CA_eku; |
|
41 ee_ext_text = (EE_basic_constraints + authority_key_ident) |
|
42 [ca_key, ca_cert] = CertUtils.generate_cert_generic(db, |
|
43 srcdir, |
|
44 1, |
|
45 key_type, |
|
46 'ca', |
|
47 ca_ext) |
|
48 |
|
49 [int_key, int_cert] = CertUtils.generate_cert_generic(db, |
|
50 srcdir, |
|
51 103, |
|
52 key_type, |
|
53 'int', |
|
54 ca_ext, |
|
55 ca_key, |
|
56 ca_cert) |
|
57 |
|
58 #now the ee |
|
59 CertUtils.generate_cert_generic(db, |
|
60 srcdir, |
|
61 100, |
|
62 key_type, |
|
63 'ee', |
|
64 ee_ext_text, |
|
65 int_key, |
|
66 int_cert) |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 generate_certs() |