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

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

Overview

NOTE:

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:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tttls1.3/message/extension/ech.rb', line 41

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

Returns the value of attribute cipher_suite.



31
32
33
# File 'lib/tttls1.3/message/extension/ech.rb', line 31

def cipher_suite
  @cipher_suite
end

#config_idObject

Returns the value of attribute config_id.



32
33
34
# File 'lib/tttls1.3/message/extension/ech.rb', line 32

def config_id
  @config_id
end

#encObject

Returns the value of attribute enc.



33
34
35
# File 'lib/tttls1.3/message/extension/ech.rb', line 33

def enc
  @enc
end

#extension_typeObject

Returns the value of attribute extension_type.



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

def extension_type
  @extension_type
end

#payloadObject

Returns the value of attribute payload.



34
35
36
# File 'lib/tttls1.3/message/extension/ech.rb', line 34

def payload
  @payload
end

#typeObject

Returns the value of attribute type.



30
31
32
# File 'lib/tttls1.3/message/extension/ech.rb', line 30

def type
  @type
end

Class Method Details

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

Parameters:

  • binary (String)

Returns:

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

Raises:



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/tttls1.3/message/extension/ech.rb', line 80

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)


149
150
151
# File 'lib/tttls1.3/message/extension/ech.rb', line 149

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)


159
160
161
162
163
164
165
166
167
# File 'lib/tttls1.3/message/extension/ech.rb', line 159

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

Instance Method Details

#serializeString

Returns:

  • (String)

Raises:



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/tttls1.3/message/extension/ech.rb', line 61

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