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

Class TLSServerHello

scapy/layers/tls/handshake.py:487–595  ·  view source on GitHub ↗

TLS ServerHello, with abilities to handle extensions. The Random structure follows the RFC 5246: while it is 32-byte long, many implementations use the first 4 bytes as a gmt_unix_time, and then the remaining 28 byts should be completely random. This was designed in order to (s

Source from the content-addressed store, hash-verified

485
486
487class TLSServerHello(_TLSHandshake):
488 """
489 TLS ServerHello, with abilities to handle extensions.
490
491 The Random structure follows the RFC 5246: while it is 32-byte long,
492 many implementations use the first 4 bytes as a gmt_unix_time, and then
493 the remaining 28 byts should be completely random. This was designed in
494 order to (sort of) mitigate broken RNGs. If you prefer to show the full
495 32 random bytes without any GMT time, just comment in/out the lines below.
496 """
497 name = "TLS Handshake - Server Hello"
498 fields_desc = [ByteEnumField("msgtype", 2, _tls_handshake_type),
499 ThreeBytesField("msglen", None),
500 _TLSVersionField("version", None, _tls_version),
501
502 # _TLSRandomBytesField("random_bytes", None, 32),
503 _GMTUnixTimeField("gmt_unix_time", None),
504 _TLSRandomBytesField("random_bytes", None, 28),
505
506 FieldLenField("sidlen", None, length_of="sid", fmt="B"),
507 _SessionIDField("sid", "",
508 length_from=lambda pkt: pkt.sidlen),
509
510 ShortEnumField("cipher", None, _tls_cipher_suites),
511 _CompressionMethodsField("comp", [0],
512 _tls_compression_algs,
513 itemfmt="B",
514 length_from=lambda pkt: 1),
515
516 _ExtensionsLenField("extlen", None, length_of="ext"),
517 _ExtensionsField("ext", None,
518 length_from=lambda pkt: (
519 pkt.msglen - (pkt.sidlen or 0) - 40
520 ))]
521
522 @classmethod
523 def dispatch_hook(cls, _pkt=None, *args, **kargs):
524 if _pkt and len(_pkt) >= 6:
525 version = struct.unpack("!H", _pkt[4:6])[0]
526 if version == 0x0304 or version > 0x7f00:
527 return TLS13ServerHello
528 return TLSServerHello
529
530 def build(self, *args, **kargs):
531 if self.getfieldval("sid") == b"" and self.tls_session:
532 self.sid = self.tls_session.sid
533 return super(TLSServerHello, self).build(*args, **kargs)
534
535 def post_build(self, p, pay):
536 if self.random_bytes is None:
537 p = p[:10] + randstring(28) + p[10 + 28:]
538 return super(TLSServerHello, self).post_build(p, pay)
539
540 def tls_session_update(self, msg_str):
541 """
542 Either for parsing or building, we store the server_random
543 along with the raw string representing this handshake message.
544 We also store the session_id, the cipher suite (if recognized),

Callers 1

Calls 11

ByteEnumFieldClass · 0.90
ThreeBytesFieldClass · 0.90
_TLSVersionFieldClass · 0.90
FieldLenFieldClass · 0.90
ShortEnumFieldClass · 0.90
_ExtensionsLenFieldClass · 0.90
_ExtensionsFieldClass · 0.90
_GMTUnixTimeFieldClass · 0.85
_SessionIDFieldClass · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…