Skip to content

Commit 6ed9d3b

Browse files
authored
Merge pull request #497 from tlsfuzzer/session_id_length
reject too long session_id field
2 parents 4263b0b + 37264b3 commit 6ed9d3b

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

tlslite/messages.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@ def parse(self, p):
622622
self.client_version = (p.get(1), p.get(1))
623623
self.random = p.getFixBytes(32)
624624
self.session_id = p.getVarBytes(1)
625+
if len(self.session_id) > 32:
626+
raise DecodeError("session_id too long")
625627
self.cipher_suites = p.getVarList(2, 2)
626628
self.compression_methods = p.getVarList(1, 1)
627629
if not p.atLengthCheck():

unit_tests/test_tlslite_messages.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
ApplicationData, EncryptedExtensions, CertificateEntry, \
2424
NewSessionTicket, SessionTicketPayload, Heartbeat, HelloRequest, \
2525
KeyUpdate
26-
from tlslite.utils.codec import Parser
26+
from tlslite.utils.codec import Parser, DecodeError
2727
from tlslite.constants import CipherSuite, CertificateType, ContentType, \
2828
AlertLevel, AlertDescription, ExtensionType, ClientCertificateType, \
2929
HashAlgorithm, SignatureAlgorithm, ECCurveType, GroupName, \
@@ -207,6 +207,26 @@ def test_parse_with_empty_extensions(self):
207207
self.assertEqual([], client_hello.compression_methods)
208208
self.assertEqual([], client_hello.extensions)
209209

210+
def test_parse_with_too_long_session_id(self):
211+
p = Parser(bytearray(
212+
# we don't include the type of message as it is handled by the
213+
# hello protocol parser
214+
#b'x01' + # type of message - client_hello
215+
b'\x00'*2 + b'\x48' + # length - 38 bytes
216+
b'\x01\x01' + # protocol version - arbitrary (invalid)
217+
b'\x00'*32 + # client random
218+
b'\x21' + # session ID length
219+
b'\x00' * 33 + # session ID
220+
b'\x00'*2 + # cipher suites length
221+
b'\x00' + # compression methods length
222+
b'\x00\x00' # extensions length
223+
))
224+
client_hello = ClientHello()
225+
with self.assertRaises(DecodeError) as e:
226+
client_hello = client_hello.parse(p)
227+
228+
self.assertIn("session_id", str(e.exception))
229+
210230
def test_parse_with_SNI_extension(self):
211231
p = Parser(bytearray(
212232
# we don't include the type of message as it is handled by the

0 commit comments

Comments
 (0)