Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

messages.py: handle empty compressed certificate message #531

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tlslite/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2554,6 +2554,10 @@ def parse(self, p):
self.compression_algo = p.get(2)
expected_length = p.get(3)
compressed_msg = p.getVarBytes(3)

if len(compressed_msg) == 0:
raise DecodeError("Empty compress certificate message")

p.stopLengthCheck()
certificate_msg = self._decompress(compressed_msg, expected_length)

Expand Down
19 changes: 18 additions & 1 deletion unit_tests/test_tlslite_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4062,7 +4062,7 @@ def test_write_none(self):

@unittest.skipIf(PY_VER < (3, ),
"In Python2 zlib fails to decompress an empty message")
def test_parse_empty(self):
def test_parse_empty_certificate(self):
cc = CompressedCertificate(CertificateType.x509)

algos = [CertificateCompressionAlgorithm.zlib]
Expand Down Expand Up @@ -4097,6 +4097,23 @@ def test_parse_empty(self):
self.assertEqual(cc.compression_algo, algo)
cc.compression_algo = None

def test_parse_empty_message(self):
cc = CompressedCertificate(CertificateType.x509)

writer = Writer()
writer.add(8, 3)
writer.add(CertificateCompressionAlgorithm.zlib, 2)
writer.bytes += b'\x00\x00\xff' # length of uncompressed message
writer.add(0, 3)

parser = Parser(writer.bytes)

with self.assertRaises(DecodeError) as e:
cc = cc.parse(parser)

self.assertIn("Empty compress certificate message",
str(e.exception))

@unittest.skipIf(PY_VER < (3, ),
"In Python2 zlib fails to decompress an empty message")
def test_parse_empty_with_wrong_expected_size(self):
Expand Down
Loading