|
16 | 16 | from hypothesis import given, example
|
17 | 17 | import hypothesis.strategies as st
|
18 | 18 | from tlslite.utils.compat import compatHMAC
|
| 19 | +from tlslite.utils.cryptomath import getRandomBytes |
19 | 20 | from tlslite.recordlayer import RecordLayer
|
20 | 21 | import tlslite.utils.tlshashlib as hashlib
|
21 | 22 | import hmac
|
@@ -266,6 +267,26 @@ def test_with_invalid_hash(self):
|
266 | 267 | self.assertFalse(ct_check_cbc_mac_and_pad(data, h, seqnum_bytes,
|
267 | 268 | content_type, version))
|
268 | 269 |
|
| 270 | + @given(i=st.integers(1, 20)) |
| 271 | + def test_with_invalid_random_hash(self, i): |
| 272 | + key = compatHMAC(getRandomBytes(20)) |
| 273 | + seqnum_bytes = bytearray(16) |
| 274 | + content_type = 0x15 |
| 275 | + version = (3, 3) |
| 276 | + application_data = getRandomBytes(63) |
| 277 | + mac = hashlib.sha1 |
| 278 | + |
| 279 | + data = self.data_prepare(application_data, seqnum_bytes, content_type, |
| 280 | + version, mac, key) |
| 281 | + data[-i] ^= 0xff |
| 282 | + padding = bytearray(b'\x00') |
| 283 | + data += padding |
| 284 | + |
| 285 | + h = hmac.new(key, digestmod=mac) |
| 286 | + h.block_size = mac().block_size |
| 287 | + self.assertFalse(ct_check_cbc_mac_and_pad(data, h, seqnum_bytes, |
| 288 | + content_type, version)) |
| 289 | + |
269 | 290 | def test_with_invalid_pad(self):
|
270 | 291 | key = compatHMAC(bytearray(20))
|
271 | 292 | seqnum_bytes = bytearray(16)
|
|
0 commit comments