aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/certutils.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2016-10-05 11:32:05 +1100
committerGitHub <noreply@github.com>2016-10-05 11:32:05 +1100
commit8e7ec6117afe528f521fb8d691f27b87141d878b (patch)
treee99ca35a61cd95ddf78c51cc675ef1d5cebed7e0 /netlib/certutils.py
parentff388f2e6298c880d26a5a5e3e41a6bb6bffb167 (diff)
parent89d36713e360ff5797f67e9b89d14db81da3bc25 (diff)
downloadmitmproxy-8e7ec6117afe528f521fb8d691f27b87141d878b.tar.gz
mitmproxy-8e7ec6117afe528f521fb8d691f27b87141d878b.tar.bz2
mitmproxy-8e7ec6117afe528f521fb8d691f27b87141d878b.zip
Merge pull request #1601 from cortesi/certcap
certutils: cap the cert store size at 100 by default
Diffstat (limited to 'netlib/certutils.py')
-rw-r--r--netlib/certutils.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/netlib/certutils.py b/netlib/certutils.py
index 9eb41d03..bdc2b77e 100644
--- a/netlib/certutils.py
+++ b/netlib/certutils.py
@@ -169,6 +169,7 @@ class CertStore(object):
"""
Implements an in-memory certificate store.
"""
+ STORE_CAP = 100
def __init__(
self,
@@ -181,6 +182,15 @@ class CertStore(object):
self.default_chain_file = default_chain_file
self.dhparams = dhparams
self.certs = dict()
+ self.expire_queue = []
+
+ def expire(self, entry):
+ self.expire_queue.append(entry)
+ if len(self.expire_queue) > self.STORE_CAP:
+ d = self.expire_queue.pop(0)
+ for k, v in list(self.certs.items()):
+ if v == d:
+ del self.certs[k]
@staticmethod
def load_dhparam(path):
@@ -342,6 +352,7 @@ class CertStore(object):
privatekey=self.default_privatekey,
chain_file=self.default_chain_file)
self.certs[(commonname, tuple(sans))] = entry
+ self.expire(entry)
return entry.cert, entry.privatekey, entry.chain_file