Skip to content

Commit

Permalink
Merge pull request #703 from tomato42/x509-cache
Browse files Browse the repository at this point in the history
Cache X509 certs
  • Loading branch information
tomato42 committed Sep 23, 2020
2 parents fa705db + b4411d4 commit 1ccc9de
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions tlsfuzzer/expect.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,22 +935,31 @@ def __init__(self, cert_type=CertificateType.x509):
super(ExpectCertificate, self).__init__(ContentType.handshake,
HandshakeType.certificate)
self.cert_type = cert_type
self._old_cert = None
self._old_cert_bytes = None

def process(self, state, msg):
"""
:type state: `~ConnectionState`
"""
assert msg.contentType == ContentType.handshake

parser = Parser(msg.write())
hs_type = parser.get(1)
assert hs_type == HandshakeType.certificate
msg_bytes = msg.write()
if self._old_cert_bytes is not None and \
msg_bytes == self._old_cert_bytes:
cert = self._old_cert
else:
parser = Parser(msg_bytes)
hs_type = parser.get(1)
assert hs_type == HandshakeType.certificate

cert = Certificate(self.cert_type, state.version)
cert.parse(parser)
cert = Certificate(self.cert_type, state.version)
cert.parse(parser)
self._old_cert_bytes = msg_bytes
self._old_cert = cert

state.handshake_messages.append(cert)
state.handshake_hashes.update(msg.write())
state.handshake_hashes.update(msg_bytes)


class ExpectCertificateVerify(ExpectHandshake):
Expand Down

0 comments on commit 1ccc9de

Please sign in to comment.