Skip to content

Commit

Permalink
Fixed stun packet creation (#4421)
Browse files Browse the repository at this point in the history
* Fixed stun packet creation

* Added unit tests for stun
  • Loading branch information
gkpln3 committed Jun 22, 2024
1 parent 039d10e commit 160e20d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scapy/contrib/stun.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def post_build(self, pkt, pay):
pkt += pay
if self.length is None:
pkt = pkt[:2] + struct.pack("!h", len(pkt) - 20) + pkt[4:]
for attr in self.tlvlist:
for attr in self.attributes:
if isinstance(attr, STUNMessageIntegrity):
pass # TODO Fill hmac-sha1 in MESSAGE-INTEGRITY attribute
return pkt
Expand Down
10 changes: 10 additions & 0 deletions test/contrib/stun.uts
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,13 @@ assert parsed.transaction_id == 0x1d9357a1e94a2051271996d9, parsed.transaction_i
assert parsed.attributes == [
STUNFingerprint(crc_32=0x53800d81)
]

= test STUN packet build
stun = STUN(
stun_message_type="Binding request",
transaction_id=0x7664047a24772b5748c0f173
)
built = stun.build()
parsed = STUN(built)

assert parsed.build() == built

0 comments on commit 160e20d

Please sign in to comment.