1 # The software in this package is distributed under the GNU General
2 # Public License version 2 (with a special exception described below).
4 # A copy of GNU General Public License (GPL) is included in this distribution,
5 # in the file COPYING.GPL.
7 # As a special exception, if other files instantiate templates or use macros
8 # or inline functions from this file, or you compile this file and link it
9 # with other works to produce a work based on this file, this file
10 # does not by itself cause the resulting work to be covered
11 # by the GNU General Public License.
13 # However the source code for this file must still be made available
14 # in accordance with section (3) of the GNU General Public License.
16 # This exception does not invalidate any other reasons why a work based
17 # on this file might be covered by the GNU General Public License.
19 # Copyright (c) 2016-2018 Intra2net AG <info@intra2net.com>
21 from .build_cnfvar import BuildCnfVar
22 """Class to create own keys cnfvar on the fly """
25 class BuildKey(BuildCnfVar):
26 def __init__(self, data='sample key', instance=0, line_no=1):
27 BuildCnfVar.__init__(self, 'KEY_OWN', instance, data, line_no)
29 # set some dummy data for cnf_check
31 'KEY_OWN_FINGERPRINT_MD5': '76:3B:CF:8E:CB:BF:A5:7D:CC:87:39:FA:CE:99:2E:96',
32 'KEY_OWN_FINGERPRINT_SHA1': 'ED:5A:C6:D9:5B:BE:47:1F:B9:4F:CF:A3:80:3B:42:08:F4:00:16:96',
33 'KEY_OWN_ID_X509': 'CN=some.net.lan',
34 'KEY_OWN_ISSUER': 'CN=ab, C=fd, L=ab, ST=ab, O=ab, OU=ab/emailAddress=ab@ab.com',
35 'KEY_OWN_KEYSIZE': '2048',
36 'KEY_OWN_HASH_ALGO': 'SHA2_256',
37 'KEY_OWN_PRIVATE_KEY': '-----BEGIN PRIVATE KEY-----\\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKk' +
38 'ZTzqHXg41RZMiY+ywRZ037pBq8J3BkH\\n-----END PRIVATE KEY-----\\n',
39 'KEY_OWN_PUBLIC_KEY': '-----BEGIN CERTIFICATE-----\\nMIIFCTCCAvGgAwIBAgIEVBGDuTANBgkqhkiG' +
40 '9w0BAQsFADCBgTEPMA0GA1UEAwwG\\n-----END CERTIFICATE-----\\n',
41 'KEY_OWN_REQUEST': '-----BEGIN CERTIFICATE REQUEST-----\\nMIIDCzCCAfMCAQAwIjEgMB4GA1UEAww' +
42 'XaW50cmFkZXYtYWllc\\n-----END CERTIFICATE REQUEST-----\\n',
43 'KEY_OWN_SUBJECT': 'CN=some.net.lan',
44 'KEY_OWN_VALIDFROM': '20140911T111257',
45 'KEY_OWN_VALIDTILL': '20160731T134608',
46 'KEY_OWN_TYPE': 'SELF',
48 # the ones bellow should be set when using 'generate' to create the key
49 'KEY_OWN_CREATE_CN': 'somehost',
50 'KEY_OWN_CREATE_EMAIL': 'default@intra2net.com'
53 self.add_defaults(defaults)
55 def country(self, country):
56 self.update_cnf('KEY_OWN_CREATE_C', 0, country)
59 def state(self, state):
60 self.update_cnf('KEY_OWN_CREATE_ST', 0, state)
64 self.update_cnf('KEY_OWN_CREATE_L', 0, city)
67 def company(self, company):
68 self.update_cnf('KEY_OWN_CREATE_O', 0, company)
71 def department(self, department):
72 self.update_cnf('KEY_OWN_CREATE_OU', 0, department)
75 def computer_name(self, computer_name):
76 self.update_cnf('KEY_OWN_CREATE_CN', 0, computer_name)
79 def email(self, email):
80 self.update_cnf('KEY_OWN_CREATE_EMAIL', 0, email)
84 self.update_cnf('KEY_OWN_CREATE_DAYS', 0, days)
87 def keysize(self, keysize):
88 self.update_cnf('KEY_OWN_KEYSIZE', 0, keysize)
91 def hash_algo(self, hash_algo):
92 self.update_cnf('KEY_OWN_HASH_ALGO', 0, hash_algo)
95 def certchain(self, certchain):
96 self.update_cnf('KEY_OWN_CERTCHAIN', 0, certchain)
99 def cerchain_count(self, cerchain_count):
100 self.update_cnf('KEY_OWN_CERTCHAIN_CERTCOUNT', 0, cerchain_count)
103 def create_subjalt(self, create_subjalt):
104 self.update_cnf('KEY_OWN_CREATE_SUBJALT', 0, create_subjalt)
107 def create_subjalt_type(self, create_subjalt_type):
108 self.update_cnf('KEY_OWN_CREATE_SUBJALT_TYPE', 0, create_subjalt_type)
111 def fingerprint_md5(self, fingerprint_md5):
112 self.update_cnf('KEY_OWN_FINGERPRINT_MD5', 0, fingerprint_md5)
115 def fingerprint_sha1(self, fingerprint_sha1):
116 self.update_cnf('KEY_OWN_FINGERPRINT_SHA1', 0, fingerprint_sha1)
119 def id_x509(self, id_x509):
120 self.update_cnf('KEY_OWN_ID_X509', 0, id_x509)
123 def issuer(self, issuer):
124 self.update_cnf('KEY_OWN_ISSUER', 0, issuer)
127 def private_key(self, private_key):
128 self.update_cnf('KEY_OWN_PRIVATE_KEY', 0, private_key)
131 def public_key(self, public_key):
132 self.update_cnf('KEY_OWN_PUBLIC_KEY', 0, public_key)
135 def request(self, request):
136 self.update_cnf('KEY_OWN_REQUEST', 0, request)
139 def subject(self, subject):
140 self.update_cnf('KEY_OWN_SUBJECT', 0, subject)
143 def subject_alt(self, subject_alt):
144 self.update_cnf('KEY_OWN_SUBJECT_ALT', 0, subject_alt)
147 def key_type(self, key_type):
148 self.update_cnf('KEY_OWN_TYPE', 0, key_type)
151 def valid_from(self, valid_from):
152 self.update_cnf('KEY_OWN_VALIDFROM', 0, valid_from)
155 def valid_till(self, valid_till):
156 self.update_cnf('KEY_OWN_VALIDTILL', 0, valid_till)