Skip to content

Commit

Permalink
Merge 59b549f into d82944f
Browse files Browse the repository at this point in the history
  • Loading branch information
tomato42 committed Sep 16, 2019
2 parents d82944f + 59b549f commit 510864a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions tlslite/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2279,6 +2279,7 @@ def parse(self, p):
"""
self.message_type = p.get(1)
self.payload = p.getVarBytes(2)
self.padding = p.getFixBytes(p.getRemainingLength())
return self

def write(self):
Expand Down
14 changes: 9 additions & 5 deletions tlslite/tlsrecordlayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,20 +845,24 @@ def _getMsg(self, expectedType, secondaryType=None, constructorType=None):
"Received heartbeat_request to "
"peer_not_allowed_to_send mode"):
yield result
else:
heartbeat_response = heartbeat_message.\
create_response()
if len(heartbeat_message.padding) < 16:
# per RFC, silently ignore if the message
# is malformed
continue
heartbeat_response = heartbeat_message.\
create_response()
for result in self._sendMsg(
heartbeat_response):
yield result
# If we received heartbeat response, then we
# check, if its payload is same as payload of
# request we sent
elif heartbeat_message.message_type == \
HeartbeatMessageType.heartbeat_response:
HeartbeatMessageType.heartbeat_response \
and self.heartbeat_response_callback:
self.heartbeat_response_callback(
heartbeat_message)
except socket.error:
except (socket.error, SyntaxError):
pass
continue

Expand Down
3 changes: 2 additions & 1 deletion unit_tests/test_tlslite_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3615,13 +3615,14 @@ def test_parse(self):
b'\x01' + # request
b'\x00\x01' + # payload length
b'\x00' + # payload
b'\x00' # padding
b'\xff' # padding
))

heartbeat_msg = heartbeat_msg.parse(parser)

self.assertEqual(heartbeat_msg.message_type, 1)
self.assertEqual(heartbeat_msg.payload, b'\x00')
self.assertEqual(heartbeat_msg.padding, b'\xff')

def test_parse_with_missing_data(self):
heartbeat_msg = Heartbeat()
Expand Down

0 comments on commit 510864a

Please sign in to comment.