Class: TTTLS13::Message::Record
- Inherits:
-
Object
- Object
- TTTLS13::Message::Record
- Defined in:
- lib/tttls1.3/message/record.rb
Overview
rubocop: disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#cipher ⇒ Object
readonly
Returns the value of attribute cipher.
-
#legacy_record_version ⇒ Object
readonly
Returns the value of attribute legacy_record_version.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.deserialize(binary, cipher, buffered = '', record_size_limit = DEFAULT_RECORD_SIZE_LIMIT) ⇒ TTTLS13::Message::Record, ...
If previous Record has surplus_binary, surplus_binary should is given to Record.deserialize as buffered.
Instance Method Summary collapse
-
#initialize(type:, messages:, cipher:, legacy_record_version: ProtocolVersion::TLS_1_2) ⇒ Record
constructor
A new instance of Record.
-
#serialize(record_size_limit = DEFAULT_RECORD_SIZE_LIMIT) ⇒ String
serialize joins messages.
Constructor Details
#initialize(type:, messages:, cipher:, legacy_record_version: ProtocolVersion::TLS_1_2) ⇒ Record
Returns a new instance of Record.
17 18 19 20 21 22 23 |
# File 'lib/tttls1.3/message/record.rb', line 17 def initialize(type:, messages:, cipher:, legacy_record_version: ProtocolVersion::TLS_1_2) @type = type @legacy_record_version = legacy_record_version @messages = @cipher = cipher end |
Instance Attribute Details
#cipher ⇒ Object (readonly)
Returns the value of attribute cipher.
11 12 13 |
# File 'lib/tttls1.3/message/record.rb', line 11 def cipher @cipher end |
#legacy_record_version ⇒ Object (readonly)
Returns the value of attribute legacy_record_version.
11 12 13 |
# File 'lib/tttls1.3/message/record.rb', line 11 def legacy_record_version @legacy_record_version end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
11 12 13 |
# File 'lib/tttls1.3/message/record.rb', line 11 def @messages end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
11 12 13 |
# File 'lib/tttls1.3/message/record.rb', line 11 def type @type end |
Class Method Details
.deserialize(binary, cipher, buffered = '', record_size_limit = DEFAULT_RECORD_SIZE_LIMIT) ⇒ TTTLS13::Message::Record, ...
If previous Record has surplus_binary, surplus_binary should is given to Record.deserialize as buffered.
rubocop: disable Metrics/AbcSize
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/tttls1.3/message/record.rb', line 61 def self.deserialize(binary, cipher, buffered = '', record_size_limit = DEFAULT_RECORD_SIZE_LIMIT) raise Error::ErrorAlerts, :internal_error if binary.nil? raise Error::ErrorAlerts, :decode_error if binary.length < 5 type = binary[0] legacy_record_version = binary.slice(1, 2) fragment_len = Convert.bin2i(binary.slice(3, 2)) raise Error::ErrorAlerts, :record_overflow \ if (cipher.is_a?(Cryptograph::Passer) && fragment_len > 2**14) || (cipher.is_a?(Cryptograph::Aead) && fragment_len > 2**14 + 256) fragment = binary.slice(5, fragment_len) raise Error::ErrorAlerts, :decode_error \ unless binary.length == 5 + fragment_len if type == ContentType::APPLICATION_DATA raise Error::ErrorAlerts, :record_overflow if fragment.length - cipher.auth_tag_len > record_size_limit fragment, inner_type = cipher.decrypt(fragment, binary.slice(0, 5)) end , orig_msgs, surplus_binary = deserialize_fragment( buffered + fragment, inner_type || type ) record = Record.new( type:, legacy_record_version:, messages:, cipher: ) [record, orig_msgs, surplus_binary] end |
Instance Method Details
#serialize(record_size_limit = DEFAULT_RECORD_SIZE_LIMIT) ⇒ String
serialize joins messages. If serialize is received Server Parameters(EE, CT, CV), it returns one binary.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tttls1.3/message/record.rb', line 32 def serialize(record_size_limit = DEFAULT_RECORD_SIZE_LIMIT) tlsplaintext = @messages.map(&:serialize).join if @cipher.is_a?(Cryptograph::Aead) max = @cipher.tlsplaintext_length_limit(record_size_limit) fragments = tlsplaintext.scan(/.{1,#{max}}/m) else fragments = [tlsplaintext] end fragments.map do |s| @type + @legacy_record_version \ + @cipher.encrypt(s, ).prefix_uint16_length end.join end |