|
23 | 23 | ApplicationData, EncryptedExtensions, CertificateEntry, \ |
24 | 24 | NewSessionTicket, SessionTicketPayload, Heartbeat, HelloRequest, \ |
25 | 25 | KeyUpdate |
26 | | -from tlslite.utils.codec import Parser |
| 26 | +from tlslite.utils.codec import Parser, DecodeError |
27 | 27 | from tlslite.constants import CipherSuite, CertificateType, ContentType, \ |
28 | 28 | AlertLevel, AlertDescription, ExtensionType, ClientCertificateType, \ |
29 | 29 | HashAlgorithm, SignatureAlgorithm, ECCurveType, GroupName, \ |
@@ -207,6 +207,26 @@ def test_parse_with_empty_extensions(self): |
207 | 207 | self.assertEqual([], client_hello.compression_methods) |
208 | 208 | self.assertEqual([], client_hello.extensions) |
209 | 209 |
|
| 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 | + |
210 | 230 | def test_parse_with_SNI_extension(self): |
211 | 231 | p = Parser(bytearray( |
212 | 232 | # we don't include the type of message as it is handled by the |
|
0 commit comments