MCPcopy Create free account
hub / github.com/secdev/scapy / _TLSIVField

Class _TLSIVField

scapy/layers/tls/basefields.py:109–151  ·  view source on GitHub ↗

As stated in Section 6.2.3.2. RFC 4346, TLS 1.1 implements an explicit IV mechanism. For that reason, the behavior of the field is dependent on the TLS version found in the packet if available or otherwise (on build, if not overloaded, it is provided by the session). The size of the

Source from the content-addressed store, hash-verified

107
108
109class _TLSIVField(StrField):
110 """
111 As stated in Section 6.2.3.2. RFC 4346, TLS 1.1 implements an explicit IV
112 mechanism. For that reason, the behavior of the field is dependent on the
113 TLS version found in the packet if available or otherwise (on build, if
114 not overloaded, it is provided by the session). The size of the IV and
115 its value are obviously provided by the session. As a side note, for the
116 first packets exchanged by peers, NULL being the default enc alg, it is
117 empty (except if forced to a specific value). Also note that the field is
118 kept empty (unless forced to a specific value) when the cipher is a stream
119 cipher (and NULL is considered a stream cipher).
120 """
121
122 def i2len(self, pkt, i):
123 if i is not None:
124 return len(i)
125 tmp_len = 0
126 cipher_type = pkt.tls_session.rcs.cipher.type
127 if cipher_type == "block":
128 if pkt.tls_session.tls_version >= 0x0302:
129 tmp_len = pkt.tls_session.rcs.cipher.block_size
130 elif cipher_type == "aead":
131 tmp_len = pkt.tls_session.rcs.cipher.nonce_explicit_len
132 return tmp_len
133
134 def i2m(self, pkt, x):
135 return x or b""
136
137 def addfield(self, pkt, s, val):
138 return s + self.i2m(pkt, val)
139
140 def getfield(self, pkt, s):
141 tmp_len = 0
142 cipher_type = pkt.tls_session.rcs.cipher.type
143 if cipher_type == "block":
144 if pkt.tls_session.tls_version >= 0x0302:
145 tmp_len = pkt.tls_session.rcs.cipher.block_size
146 elif cipher_type == "aead":
147 tmp_len = pkt.tls_session.rcs.cipher.nonce_explicit_len
148 return s[tmp_len:], self.m2i(pkt, s[:tmp_len])
149
150 def i2repr(self, pkt, x):
151 return repr(self.i2m(pkt, x))
152
153
154class _TLSMACField(StrField):

Callers 1

TLSClass · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…