Class: TTTLS13::Message::ServerHello
- Inherits:
-
Object
- Object
- TTTLS13::Message::ServerHello
- Defined in:
- lib/tttls1.3/message/server_hello.rb
Instance Attribute Summary collapse
-
#cipher_suite ⇒ Object
readonly
Returns the value of attribute cipher_suite.
-
#extensions ⇒ Object
readonly
Returns the value of attribute extensions.
-
#legacy_compression_method ⇒ Object
readonly
Returns the value of attribute legacy_compression_method.
-
#legacy_session_id_echo ⇒ Object
readonly
Returns the value of attribute legacy_session_id_echo.
-
#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::ServerHello
rubocop: disable Metrics/AbcSize rubocop: disable Metrics/MethodLength.
Instance Method Summary collapse
- #appearable_extensions? ⇒ Boolean
- #downgraded? ⇒ Boolean
-
#hrr? ⇒ Boolean
rubocop: enable Metrics/AbcSize rubocop: enable Metrics/MethodLength.
-
#initialize(legacy_session_id_echo:, cipher_suite:, legacy_version: ProtocolVersion::TLS_1_2, random: OpenSSL::Random.random_bytes(32), legacy_compression_method: "\x00", extensions: Extensions.new) ⇒ ServerHello
constructor
rubocop: disable Metrics/ParameterLists.
- #negotiated_tls_1_3? ⇒ Booelan
- #serialize ⇒ String
Constructor Details
#initialize(legacy_session_id_echo:, cipher_suite:, legacy_version: ProtocolVersion::TLS_1_2, random: OpenSSL::Random.random_bytes(32), legacy_compression_method: "\x00", extensions: Extensions.new) ⇒ ServerHello
rubocop: disable Metrics/ParameterLists
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/tttls1.3/message/server_hello.rb', line 47 def initialize(legacy_session_id_echo:, cipher_suite:, legacy_version: ProtocolVersion::TLS_1_2, random: OpenSSL::Random.random_bytes(32), legacy_compression_method: "\x00", extensions: Extensions.new) @msg_type = HandshakeType::SERVER_HELLO @legacy_version = legacy_version @random = random @legacy_session_id_echo = legacy_session_id_echo @cipher_suite = cipher_suite @legacy_compression_method = legacy_compression_method @extensions = extensions end |
Instance Attribute Details
#cipher_suite ⇒ Object (readonly)
Returns the value of attribute cipher_suite.
37 38 39 |
# File 'lib/tttls1.3/message/server_hello.rb', line 37 def cipher_suite @cipher_suite end |
#extensions ⇒ Object (readonly)
Returns the value of attribute extensions.
37 38 39 |
# File 'lib/tttls1.3/message/server_hello.rb', line 37 def extensions @extensions end |
#legacy_compression_method ⇒ Object (readonly)
Returns the value of attribute legacy_compression_method.
37 38 39 |
# File 'lib/tttls1.3/message/server_hello.rb', line 37 def legacy_compression_method @legacy_compression_method end |
#legacy_session_id_echo ⇒ Object (readonly)
Returns the value of attribute legacy_session_id_echo.
37 38 39 |
# File 'lib/tttls1.3/message/server_hello.rb', line 37 def legacy_session_id_echo @legacy_session_id_echo end |
#legacy_version ⇒ Object (readonly)
Returns the value of attribute legacy_version.
37 38 39 |
# File 'lib/tttls1.3/message/server_hello.rb', line 37 def legacy_version @legacy_version end |
#msg_type ⇒ Object (readonly)
Returns the value of attribute msg_type.
37 38 39 |
# File 'lib/tttls1.3/message/server_hello.rb', line 37 def msg_type @msg_type end |
#random ⇒ Object (readonly)
Returns the value of attribute random.
37 38 39 |
# File 'lib/tttls1.3/message/server_hello.rb', line 37 def random @random end |
Class Method Details
.deserialize(binary) ⇒ TTTLS13::Message::ServerHello
rubocop: disable Metrics/AbcSize rubocop: disable Metrics/MethodLength
81 82 83 84 85 86 87 88 89 90 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 |
# File 'lib/tttls1.3/message/server_hello.rb', line 81 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::SERVER_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_echo = binary.slice(39, lsid_len) i = 39 + lsid_len cipher_suite = binary.slice(i, 2) i += 2 legacy_compression_method = binary[i] i += 1 exs_len = Convert.bin2i(binary.slice(i, 2)) i += 2 exs_bin = binary.slice(i, exs_len) if random == HRR_RANDOM msg_type = HandshakeType::HELLO_RETRY_REQUEST else msg_type = HandshakeType::SERVER_HELLO end extensions = Extensions.deserialize(exs_bin, msg_type) i += exs_len raise Error::ErrorAlerts, :decode_error unless i == msg_len + 4 && i == binary.length ServerHello.new(legacy_version:, random:, legacy_session_id_echo:, cipher_suite:, legacy_compression_method:, extensions:) end |
Instance Method Details
#appearable_extensions? ⇒ Boolean
126 127 128 129 130 131 132 |
# File 'lib/tttls1.3/message/server_hello.rb', line 126 def appearable_extensions? exs = @extensions.keys - APPEARABLE_SH_EXTENSIONS exs = @extensions.keys - APPEARABLE_HRR_EXTENSIONS if hrr? return true if exs.empty? !(exs - DEFINED_EXTENSIONS).empty? end |
#downgraded? ⇒ Boolean
143 144 145 146 |
# File 'lib/tttls1.3/message/server_hello.rb', line 143 def downgraded? [DOWNGRADE_PROTECTION_TLS_1_2, DOWNGRADE_PROTECTION_TLS_1_1].include?(@random[-8..]) end |
#hrr? ⇒ Boolean
rubocop: enable Metrics/AbcSize rubocop: enable Metrics/MethodLength
121 122 123 |
# File 'lib/tttls1.3/message/server_hello.rb', line 121 def hrr? @random == HRR_RANDOM end |
#negotiated_tls_1_3? ⇒ Booelan
135 136 137 138 139 140 |
# File 'lib/tttls1.3/message/server_hello.rb', line 135 def negotiated_tls_1_3? sv = @extensions[Message::ExtensionType::SUPPORTED_VERSIONS] @legacy_version == Message::ProtocolVersion::TLS_1_2 && (sv&.versions || []).first == Message::ProtocolVersion::TLS_1_3 end |
#serialize ⇒ String
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/tttls1.3/message/server_hello.rb', line 62 def serialize binary = '' binary += @legacy_version binary += @random binary += @legacy_session_id_echo.prefix_uint8_length binary += @cipher_suite binary += @legacy_compression_method binary += @extensions.serialize @msg_type + binary.prefix_uint24_length end |