aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-07-19 00:02:31 +0200
committerMaximilian Hils <git@maximilianhils.com>2014-07-19 00:02:31 +0200
commitd382bb27bf4732def621cddb46fc4cc1d2143ab4 (patch)
tree528d8a0eed88a37c6d6712718ea8fc00986e5318 /netlib
parentcba927885e8c683752f3042ce9f1746336f90168 (diff)
downloadmitmproxy-d382bb27bf4732def621cddb46fc4cc1d2143ab4.tar.gz
mitmproxy-d382bb27bf4732def621cddb46fc4cc1d2143ab4.tar.bz2
mitmproxy-d382bb27bf4732def621cddb46fc4cc1d2143ab4.zip
certstore: add support for asterisk form to DNTree replacement
Diffstat (limited to 'netlib')
-rw-r--r--netlib/certutils.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/netlib/certutils.py b/netlib/certutils.py
index 87fb99c3..308d6cf8 100644
--- a/netlib/certutils.py
+++ b/netlib/certutils.py
@@ -215,6 +215,19 @@ class CertStore:
for i in names:
self.certs[i] = (cert, privkey)
+ @staticmethod
+ def asterisk_forms(dn):
+ parts = dn.split(".")
+ parts.reverse()
+ curr_dn = ""
+ dn_forms = ["*"]
+ for part in parts[:-1]:
+ curr_dn = "." + part + curr_dn # .example.com
+ dn_forms.append("*" + curr_dn) # *.example.com
+ if parts[-1] != "*":
+ dn_forms.append(parts[-1] + curr_dn)
+ return dn_forms
+
def get_cert(self, commonname, sans):
"""
Returns an (cert, privkey) tuple.
@@ -227,7 +240,11 @@ class CertStore:
Return None if the certificate could not be found or generated.
"""
- potential_keys = [commonname] + sans + [(commonname, tuple(sans))]
+ potential_keys = self.asterisk_forms(commonname)
+ for s in sans:
+ potential_keys.extend(self.asterisk_forms(s))
+ potential_keys.append((commonname, tuple(sans)))
+
name = next(itertools.ifilter(lambda key: key in self.certs, potential_keys), None)
if name:
c = self.certs[name]