Class: TTTLS13::Message::ClientHello
- Inherits:
-
Object
- Object
- TTTLS13::Message::ClientHello
- Defined in:
- lib/tttls1.3/message/client_hello.rb
Instance Attribute Summary collapse
-
#cipher_suites ⇒ Object
readonly
Returns the value of attribute cipher_suites.
-
#extensions ⇒ Object
readonly
Returns the value of attribute extensions.
-
#legacy_compression_methods ⇒ Object
readonly
Returns the value of attribute legacy_compression_methods.
-
#legacy_session_id ⇒ Object
readonly
Returns the value of attribute legacy_session_id.
-
#legacy_version ⇒ Object
readonly
Returns the value of attribute legacy_version.
-
#msg_type ⇒ Object
readonly
Returns the value of attribute msg_type.
-
#random ⇒ Object
readonly
Returns the value of attribute random.
Class Method Summary collapse
-
.deserialize(binary) ⇒ TTTLS13::Message::ClientHello
rubocop: disable Metrics/AbcSize rubocop: disable Metrics/MethodLength.
Instance Method Summary collapse
- #appearable_extensions? ⇒ Boolean
-
#initialize(legacy_version: ProtocolVersion::TLS_1_2, random: OpenSSL::Random.random_bytes(32), legacy_session_id: OpenSSL::Random.random_bytes(32), cipher_suites:, legacy_compression_methods: ["\x00"], extensions: Extensions.new) ⇒ ClientHello
constructor
rubocop: disable Metrics/ParameterLists.
- #negotiated_tls_1_3? ⇒ Boolean
- #serialize ⇒ String
- #valid_key_share? ⇒ Boolean
Constructor Details
#initialize(legacy_version: ProtocolVersion::TLS_1_2, random: OpenSSL::Random.random_bytes(32), legacy_session_id: OpenSSL::Random.random_bytes(32), cipher_suites:, legacy_compression_methods: ["\x00"], extensions: Extensions.new) ⇒ ClientHello
rubocop: disable Metrics/ParameterLists
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/tttls1.3/message/client_hello.rb', line 55 def initialize(legacy_version: ProtocolVersion::TLS_1_2, random: OpenSSL::Random.random_bytes(32), legacy_session_id: OpenSSL::Random.random_bytes(32), cipher_suites:, legacy_compression_methods: ["\x00"], extensions: Extensions.new) @msg_type = HandshakeType::CLIENT_HELLO @legacy_version = legacy_version @random = random @legacy_session_id = legacy_session_id @cipher_suites = cipher_suites @legacy_compression_methods = legacy_compression_methods @extensions = extensions end |
Instance Attribute Details
#cipher_suites ⇒ Object (readonly)
Returns the value of attribute cipher_suites.
44 45 46 |
# File 'lib/tttls1.3/message/client_hello.rb', line 44 def cipher_suites @cipher_suites end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
46 47 48 |
# File 'lib/tttls1.3/message/client_hello.rb', line 46 def extensions @extensions end |
#legacy_compression_methods ⇒ Object (readonly)
Returns the value of attribute legacy_compression_methods.
45 46 47 |
# File 'lib/tttls1.3/message/client_hello.rb', line 45 def legacy_compression_methods @legacy_compression_methods end |
#legacy_session_id ⇒ Object (readonly)
Returns the value of attribute legacy_session_id.
43 44 45 |
# File 'lib/tttls1.3/message/client_hello.rb', line 43 def legacy_session_id @legacy_session_id end |
#legacy_version ⇒ Object (readonly)
Returns the value of attribute legacy_version.
41 42 43 |
# File 'lib/tttls1.3/message/client_hello.rb', line 41 def legacy_version @legacy_version end |
#msg_type ⇒ Object (readonly)
Returns the value of attribute msg_type.
40 41 42 |
# File 'lib/tttls1.3/message/client_hello.rb', line 40 def msg_type @msg_type end |
#random ⇒ Object (readonly)
Returns the value of attribute random.
42 43 44 |
# File 'lib/tttls1.3/message/client_hello.rb', line 42 def random @random end |
Class Method Details
.deserialize(binary) ⇒ TTTLS13::Message::ClientHello
rubocop: disable Metrics/AbcSize rubocop: disable Metrics/MethodLength
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/tttls1.3/message/client_hello.rb', line 91 def self.deserialize(binary) raise Error::ErrorAlerts, :internal_error if binary.nil? raise Error::ErrorAlerts, :decode_error if binary.length < 39 raise Error::ErrorAlerts, :internal_error \ unless binary[0] == HandshakeType::CLIENT_HELLO msg_len = Convert.bin2i(binary.slice(1, 3)) legacy_version = binary.slice(4, 2) random = binary.slice(6, 32) lsid_len = Convert.bin2i(binary[38]) legacy_session_id = binary.slice(39, lsid_len) i = 39 + lsid_len cs_len = Convert.bin2i(binary.slice(i, 2)) i += 2 cs_bin = binary.slice(i, cs_len) cipher_suites = CipherSuites.deserialize(cs_bin) i += cs_len cm_len = Convert.bin2i(binary[i]) i += 1 legacy_compression_methods = binary.slice(i, cm_len).split('') i += cm_len exs_len = Convert.bin2i(binary.slice(i, 2)) i += 2 exs_bin = binary.slice(i, exs_len) extensions = Extensions.deserialize(exs_bin, HandshakeType::CLIENT_HELLO) i += exs_len raise Error::ErrorAlerts, :decode_error unless i == msg_len + 4 && i == binary.length ClientHello.new(legacy_version: legacy_version, random: random, legacy_session_id: legacy_session_id, cipher_suites: cipher_suites, legacy_compression_methods: legacy_compression_methods, extensions: extensions) end |
Instance Method Details
#appearable_extensions? ⇒ Boolean
132 133 134 135 136 137 |
# File 'lib/tttls1.3/message/client_hello.rb', line 132 def appearable_extensions? exs = @extensions.keys - APPEARABLE_CH_EXTENSIONS return true if exs.empty? !(exs - DEFINED_EXTENSIONS).empty? end |
#negotiated_tls_1_3? ⇒ Boolean
140 141 142 143 144 145 |
# File 'lib/tttls1.3/message/client_hello.rb', line 140 def negotiated_tls_1_3? sv = @extensions[ExtensionType::SUPPORTED_VERSIONS] @legacy_version == ProtocolVersion::TLS_1_2 && (sv&.versions || []).include?(ProtocolVersion::TLS_1_3) end |
#serialize ⇒ String
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/tttls1.3/message/client_hello.rb', line 72 def serialize binary = '' binary += @legacy_version binary += @random binary += @legacy_session_id.prefix_uint8_length binary += @cipher_suites.serialize binary += @legacy_compression_methods.join.prefix_uint8_length binary += @extensions.serialize @msg_type + binary.prefix_uint24_length end |
#valid_key_share? ⇒ Boolean
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/tttls1.3/message/client_hello.rb', line 148 def valid_key_share? ks = @extensions[Message::ExtensionType::KEY_SHARE] ks_groups = ks&.key_share_entry&.map(&:group) || [] sg = @extensions[Message::ExtensionType::SUPPORTED_GROUPS] sg_groups = sg&.named_group_list || [] # Each KeyShareEntry value MUST correspond to a group offered in the # "supported_groups" extension and MUST appear in the same order. # # Clients MUST NOT offer multiple KeyShareEntry values for the same # group. (ks_groups - sg_groups).empty? && sg_groups.filter { |g| ks_groups.include?(g) } == ks_groups && ks_groups.uniq == ks_groups end |