| 4 | |
| 5 | |
| 6 | class HttpdConf(object): |
| 7 | |
| 8 | def __init__(self, env: HttpdTestEnv, extras: Dict[str, Any] = None): |
| 9 | """ Create a new httpd configuration. |
| 10 | :param env: then environment this operates in |
| 11 | :param extras: extra configuration directive with ServerName as key and |
| 12 | 'base' as special key for global configuration additions. |
| 13 | """ |
| 14 | self.env = env |
| 15 | self._indents = 0 |
| 16 | self._lines = [] |
| 17 | self._extras = extras.copy() if extras else {} |
| 18 | if 'base' in self._extras: |
| 19 | self.add(self._extras['base']) |
| 20 | self._tls_engine_ports = set() |
| 21 | |
| 22 | def __repr__(self): |
| 23 | s = '\n'.join(self._lines) |
| 24 | return f"HttpdConf[{s}]" |
| 25 | |
| 26 | def install(self): |
| 27 | self.env.install_test_conf(self._lines) |
| 28 | |
| 29 | def replacetlsstr(self, line): |
| 30 | l = line.replace("TLS_", "") |
| 31 | l = l.replace("\n", " ") |
| 32 | l = l.replace("\\", " ") |
| 33 | l = " ".join(l.split()) |
| 34 | l = l.replace(" ", ":") |
| 35 | l = l.replace("_", "-") |
| 36 | l = l.replace("-WITH", "") |
| 37 | l = l.replace("AES-", "AES") |
| 38 | l = l.replace("POLY1305-SHA256", "POLY1305") |
| 39 | return l |
| 40 | |
| 41 | def replaceinstr(self, line): |
| 42 | if line.startswith("TLSCiphersPrefer"): |
| 43 | # the "TLS_" are changed into "". |
| 44 | l = self.replacetlsstr(line) |
| 45 | l = l.replace("TLSCiphersPrefer:", "SSLCipherSuite ") |
| 46 | elif line.startswith("TLSCiphersSuppress"): |
| 47 | # like SSLCipherSuite but with :! |
| 48 | l = self.replacetlsstr(line) |
| 49 | l = l.replace("TLSCiphersSuppress:", "SSLCipherSuite !") |
| 50 | l = l.replace(":", ":!") |
| 51 | elif line.startswith("TLSCertificate"): |
| 52 | l = line.replace("TLSCertificate", "SSLCertificateFile") |
| 53 | elif line.startswith("TLSProtocol"): |
| 54 | # mod_ssl is different (+ no supported and 0x code have to be translated) |
| 55 | l = line.replace("TLSProtocol", "SSLProtocol") |
| 56 | l = l.replace("+", "") |
| 57 | l = l.replace("default", "all") |
| 58 | l = l.replace("0x0303", "1.2") # need to check 1.3 and 1.1 |
| 59 | elif line.startswith("SSLProtocol"): |
| 60 | l = line # we have that in test/modules/tls/test_05_proto.py |
| 61 | elif line.startswith("TLSHonorClientOrder"): |
| 62 | # mod_ssl has SSLHonorCipherOrder on = use server off = use client. |
| 63 | l = line.lower() |
no outgoing calls