tls.py (1099:090bf53b3100) tls.py (1100:32ee6a91138d)
1import os
1import ssl
2import subprocess
3from unit.applications.proto import TestApplicationProto
4
5
6class TestApplicationTLS(TestApplicationProto):
7 def __init__(self, test):
8 super().__init__(test)
9
10 self.context = ssl.create_default_context()
11 self.context.check_hostname = False
12 self.context.verify_mode = ssl.CERT_NONE
13
14 def certificate(self, name='default', load=True):
2import ssl
3import subprocess
4from unit.applications.proto import TestApplicationProto
5
6
7class TestApplicationTLS(TestApplicationProto):
8 def __init__(self, test):
9 super().__init__(test)
10
11 self.context = ssl.create_default_context()
12 self.context.check_hostname = False
13 self.context.verify_mode = ssl.CERT_NONE
14
15 def certificate(self, name='default', load=True):
16 self.openssl_conf()
17
15 subprocess.call(
16 [
17 'openssl',
18 'req',
19 '-x509',
20 '-new',
21 '-subj', '/CN=' + name + '/',
22 '-config', self.testdir + '/openssl.conf',

--- 31 unchanged lines hidden (view full) ---

54 elif 'PROTOCOL_TLSv1_2' in ssl_list:
55 ssl_version = ssl.PROTOCOL_TLSv1_2
56
57 else:
58 ssl_version = ssl.PROTOCOL_TLSv1_1
59
60 return ssl.get_server_certificate(addr, ssl_version=ssl_version)
61
18 subprocess.call(
19 [
20 'openssl',
21 'req',
22 '-x509',
23 '-new',
24 '-subj', '/CN=' + name + '/',
25 '-config', self.testdir + '/openssl.conf',

--- 31 unchanged lines hidden (view full) ---

57 elif 'PROTOCOL_TLSv1_2' in ssl_list:
58 ssl_version = ssl.PROTOCOL_TLSv1_2
59
60 else:
61 ssl_version = ssl.PROTOCOL_TLSv1_1
62
63 return ssl.get_server_certificate(addr, ssl_version=ssl_version)
64
62 def load(self, script, name=None):
63 if name is None:
64 name = script
65 def openssl_conf(self):
66 conf_path = self.testdir + '/openssl.conf'
65
67
66 # create default openssl configuration
68 if os.path.exists(conf_path):
69 return
67
70
68 with open(self.testdir + '/openssl.conf', 'w') as f:
71 with open(conf_path, 'w') as f:
69 f.write(
70 """[ req ]
71default_bits = 2048
72encrypt_key = no
73distinguished_name = req_distinguished_name
74[ req_distinguished_name ]"""
75 )
76
72 f.write(
73 """[ req ]
74default_bits = 2048
75encrypt_key = no
76distinguished_name = req_distinguished_name
77[ req_distinguished_name ]"""
78 )
79
80 def load(self, script, name=None):
81 if name is None:
82 name = script
83
77 script_path = self.current_dir + '/python/' + script
78
79 self._load_conf(
80 {
81 "listeners": {"*:7080": {"pass": "applications/" + name}},
82 "applications": {
83 name: {
84 "type": "python",
85 "processes": {"spare": 0},
86 "path": script_path,
87 "working_directory": script_path,
88 "module": "wsgi",
89 }
90 },
91 }
92 )
84 script_path = self.current_dir + '/python/' + script
85
86 self._load_conf(
87 {
88 "listeners": {"*:7080": {"pass": "applications/" + name}},
89 "applications": {
90 name: {
91 "type": "python",
92 "processes": {"spare": 0},
93 "path": script_path,
94 "working_directory": script_path,
95 "module": "wsgi",
96 }
97 },
98 }
99 )