| 794 | |
| 795 | |
| 796 | class _ExtensionsField(StrLenField): |
| 797 | islist = 1 |
| 798 | holds_packets = 1 |
| 799 | |
| 800 | def i2len(self, pkt, i): |
| 801 | if i is None: |
| 802 | return 0 |
| 803 | return len(self.i2m(pkt, i)) |
| 804 | |
| 805 | def getfield(self, pkt, s): |
| 806 | tmp_len = self.length_from(pkt) or 0 |
| 807 | if tmp_len <= 0: |
| 808 | return s, [] |
| 809 | return s[tmp_len:], self.m2i(pkt, s[:tmp_len]) |
| 810 | |
| 811 | def i2m(self, pkt, i): |
| 812 | if i is None: |
| 813 | return b"" |
| 814 | if isinstance(pkt, _GenericTLSSessionInheritance): |
| 815 | if not pkt.tls_session.frozen: |
| 816 | s = b"" |
| 817 | for ext in i: |
| 818 | if isinstance(ext, _GenericTLSSessionInheritance): |
| 819 | ext.tls_session = pkt.tls_session |
| 820 | s += ext.raw_stateful() |
| 821 | else: |
| 822 | s += raw(ext) |
| 823 | return s |
| 824 | return b"".join(map(raw, i)) |
| 825 | |
| 826 | def m2i(self, pkt, m): |
| 827 | res = [] |
| 828 | while len(m) >= 4: |
| 829 | t = struct.unpack("!H", m[:2])[0] |
| 830 | tmp_len = struct.unpack("!H", m[2:4])[0] |
| 831 | cls = _tls_ext_cls.get(t, TLS_Ext_Unknown) |
| 832 | if cls is TLS_Ext_KeyShare: |
| 833 | # TLS_Ext_KeyShare can be : |
| 834 | # - TLS_Ext_KeyShare_CH if the message is a ClientHello |
| 835 | # - TLS_Ext_KeyShare_SH if the message is a ServerHello |
| 836 | # and all parameters are accepted by the serveur |
| 837 | # - TLS_Ext_KeyShare_HRR if message is a ServerHello and |
| 838 | # the client has not provided a sufficient "key_share" |
| 839 | # extension |
| 840 | from scapy.layers.tls.keyexchange_tls13 import ( |
| 841 | _tls_ext_keyshare_cls, _tls_ext_keyshare_hrr_cls) |
| 842 | # If SHA-256("HelloRetryRequest") == server_random, |
| 843 | # this message is a HelloRetryRequest |
| 844 | if pkt.random_bytes and \ |
| 845 | pkt.random_bytes == _tls_hello_retry_magic: |
| 846 | cls = _tls_ext_keyshare_hrr_cls.get(pkt.msgtype, TLS_Ext_Unknown) # noqa: E501 |
| 847 | else: |
| 848 | cls = _tls_ext_keyshare_cls.get(pkt.msgtype, TLS_Ext_Unknown) # noqa: E501 |
| 849 | elif cls is TLS_Ext_PreSharedKey: |
| 850 | from scapy.layers.tls.keyexchange_tls13 import _tls_ext_presharedkey_cls # noqa: E501 |
| 851 | cls = _tls_ext_presharedkey_cls.get(pkt.msgtype, TLS_Ext_Unknown) # noqa: E501 |
| 852 | elif cls is TLS_Ext_SupportedVersions: |
| 853 | cls = _tls_ext_supported_version_cls.get(pkt.msgtype, TLS_Ext_Unknown) # noqa: E501 |
no outgoing calls
no test coverage detected
searching dependent graphs…