Class: TTTLS13::Message::Extension::ECHClientHello

Inherits:
Object
  • Object
show all
Defined in:
lib/tttls1.3/message/extension/ech.rb

Overview

struct {

    ECHClientHelloType type;
    select (ECHClientHello.type) {
        case outer:
            HpkeSymmetricCipherSuite cipher_suite;
            uint8 config_id;
            opaque enc<0..2^16-1>;
            opaque payload<1..2^16-1>;
        case inner:
            Empty;
    };
} ECHClientHello;

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, cipher_suite: nil, config_id: nil, enc: nil, payload: nil) ⇒ ECHClientHello

Returns a new instance of ECHClientHello.

Parameters:

Raises:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/tttls1.3/message/extension/ech.rb', line 35

def initialize(type:,
               cipher_suite: nil,
               config_id: nil,
               enc: nil,
               payload: nil)
  @extension_type = ExtensionType::ENCRYPTED_CLIENT_HELLO
  @type = type
  @cipher_suite = cipher_suite
  raise Error::ErrorAlerts, :internal_error \
    if @type == ECHClientHelloType::OUTER && \
       !@cipher_suite.is_a?(HpkeSymmetricCipherSuite)

  @config_id = config_id
  @enc = enc
  @payload = payload
end

Instance Attribute Details

#cipher_suiteObject (readonly)

Returns the value of attribute cipher_suite.



28
29
30
# File 'lib/tttls1.3/message/extension/ech.rb', line 28

def cipher_suite
  @cipher_suite
end

#config_idObject (readonly)

Returns the value of attribute config_id.



28
29
30
# File 'lib/tttls1.3/message/extension/ech.rb', line 28

def config_id
  @config_id
end

#encObject (readonly)

Returns the value of attribute enc.



28
29
30
# File 'lib/tttls1.3/message/extension/ech.rb', line 28

def enc
  @enc
end

#extension_typeObject (readonly)

Returns the value of attribute extension_type.



28
29
30
# File 'lib/tttls1.3/message/extension/ech.rb', line 28

def extension_type
  @extension_type
end

#payloadObject (readonly)

Returns the value of attribute payload.



28
29
30
# File 'lib/tttls1.3/message/extension/ech.rb', line 28

def payload
  @payload
end

#typeObject (readonly)

Returns the value of attribute type.



28
29
30
# File 'lib/tttls1.3/message/extension/ech.rb', line 28

def type
  @type
end

Class Method Details

.deserialize(binary) ⇒ TTTLS13::Message::Extensions::ECHClientHello

Parameters:

  • binary (String)

Returns:

  • (TTTLS13::Message::Extensions::ECHClientHello)

Raises:



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/tttls1.3/message/extension/ech.rb', line 74

def self.deserialize(binary)
  raise Error::ErrorAlerts, :internal_error \
    if binary.nil? || binary.empty?

  case binary[0]
  when ECHClientHelloType::OUTER
    return deserialize_outer_ech(binary[1..])
  when ECHClientHelloType::INNER
    return deserialize_inner_ech(binary[1..])
  end

  raise Error::ErrorAlerts, :internal_error
end

.new_innerTTTLS13::Message::Extensions::ECHClientHello

Returns:

  • (TTTLS13::Message::Extensions::ECHClientHello)


141
142
143
# File 'lib/tttls1.3/message/extension/ech.rb', line 141

def self.new_inner
  ECHClientHello.new(type: ECHClientHelloType::INNER)
end

.new_outer(cipher_suite:, config_id:, enc:, payload:) ⇒ TTTLS13::Message::Extensions::ECHClientHello

Parameters:

Returns:

  • (TTTLS13::Message::Extensions::ECHClientHello)


151
152
153
154
155
156
157
158
159
# File 'lib/tttls1.3/message/extension/ech.rb', line 151

def self.new_outer(cipher_suite:, config_id:, enc:, payload:)
  ECHClientHello.new(
    type: ECHClientHelloType::OUTER,
    cipher_suite:,
    config_id:,
    enc:,
    payload:
  )
end

Instance Method Details

#serializeString

Returns:

  • (String)

Raises:



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/tttls1.3/message/extension/ech.rb', line 55

def serialize
  case @type
  when ECHClientHelloType::OUTER
    binary = @type + @cipher_suite.encode + @config_id.to_uint8 \
             + @enc.prefix_uint16_length + @payload.prefix_uint16_length
  when ECHClientHelloType::INNER
    binary = @type
  else
    raise Error::ErrorAlerts, :internal_error
  end

  @extension_type + binary.prefix_uint16_length
end