echspec 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e07ddc58f010362c3d1cbf70aeaa0b89fb70c0ae6cad75f3c53dd4e64555986
4
- data.tar.gz: 91f26f14e3520cc7761eb20b2f640a42ae22c2302c1372e5a59fec2ff3230a09
3
+ metadata.gz: 34c5703f440baeb24faa415daaed6ab31d470c728105c6b1d397e06c07d7614a
4
+ data.tar.gz: dfaee0a011ac51ae4616b10f333118b1e5ea26e7bde42413452c118ea3171467
5
5
  SHA512:
6
- metadata.gz: 72bf8ce3e68f61c9a9ef325b004024453807a876cf2a4c654eb468041a3e44f07f555a9b9c04086451a9dc5ffa5b3021cf27dc43bc7279eb8b0fa6056623b8aa
7
- data.tar.gz: b09ca3150563ca2745009ffc1baf63783ae6faa9da2a906ef103d8c7025c98dec78932ed39c74d5d5d986cab7967d339ae60cd3de25d7e7bbc565c87493ce46d
6
+ metadata.gz: aaa74cb914f63edf02b478891701d65a2a27e101d57f4ba994ba0411d0f3d9d00888336316608dca1b2212f386b8f0d9cdc04b862daf8db41ebca52aa676ceb1
7
+ data.tar.gz: 3908ff4c175440f735b143a14ad981b799ef2fed208826a1130a8dbc7e16dda0b5e4906286c155fd22b14c22f59b0e18b99d3ea0074c2e11dda6cf80f1ac69f2
data/README.md CHANGED
@@ -64,8 +64,12 @@ TLS Encrypted Client Hello Server
64
64
  ✔ MUST abort with an "illegal_parameter" alert, if the extensions in ClientHelloOuter corresponding to those in OuterExtensions do not occur in the same order. [5.1-10]
65
65
  ✔ MUST abort with an "illegal_parameter" alert, if ECHClientHello.type is not a valid ECHClientHelloType in ClientHelloInner. [7-3]
66
66
  x MUST abort with an "illegal_parameter" alert, if ECHClientHello.type is not a valid ECHClientHelloType in ClientHelloOuter. [7-3]
67
+ x MUST abort with an "illegal_parameter" alert, if ClientHello is received with ECHClientHello.type of inner directly from the network. [7-5]
67
68
  ✔ MUST abort with an "illegal_parameter" alert, if ClientHelloInner offers TLS 1.2 or below. [7.1-11]
68
69
  ✔ MUST abort with an "illegal_parameter" alert, if ClientHelloInner does not contain the "encrypted_client_hello" extension. [7.1-11]
70
+ ✔ MUST abort with an "illegal_parameter" alert, if ClientHelloInner contains the "encrypted_client_hello" extension of type outer. [7.1-11]
71
+ ✔ MUST abort with an "illegal_parameter" alert, if ClientHelloInner contains the "encrypted_client_hello" extension of type inner that is not well-formed. [7.1-11]
72
+ ✔ MUST ignore the extension and proceed with the connection using ClientHelloOuter, if it receives a GREASE "encrypted_client_hello" extension. [7.1-13]
69
73
  ✔ MUST include the "encrypted_client_hello" extension in its EncryptedExtensions with the "retry_configs" field set to one or more ECHConfig. [7.1-14.2.1]
70
74
  ✔ MUST abort with a "missing_extension" alert, if 2nd ClientHelloOuter does not contains the "encrypted_client_hello" extension. [7.1.1-2]
71
75
  ✔ MUST abort with an "illegal_parameter" alert, if 2nd ClientHelloOuter "encrypted_client_hello" enc is not empty. [7.1.1-2]
@@ -73,6 +77,7 @@ TLS Encrypted Client Hello Server
73
77
  ✔ MUST abort with an "illegal_parameter" alert, if 2nd ClientHelloOuter "encrypted_client_hello" cipher_suite is changed. [7.1.1-2]
74
78
  ✔ MUST abort with a "decrypt_error" alert, if fails to decrypt 2nd ClientHelloOuter. [7.1.1-5]
75
79
  ✔ MUST include the "encrypted_client_hello" extension in its EncryptedExtensions with the "retry_configs" field set to one or more ECHConfig, if it rejected ECH with HelloRetryRequest. [7.1.1-7]
80
+ ✔ MUST confirm ECH acceptance in ServerHello. [7.2-1]
76
81
  ✔ MUST confirm ECH acceptance in ServerHello, if it confirmed ECH acceptance in HelloRetryRequest. [7.2-1]
77
82
 
78
83
  Failures:
@@ -81,7 +86,11 @@ Failures:
81
86
  https://datatracker.ietf.org/doc/html/rfc9849#section-7-3
82
87
  did not send expected alert: illegal_parameter
83
88
 
84
- 1 failure
89
+ 2) MUST abort with an "illegal_parameter" alert, if ClientHello is received with ECHClientHello.type of inner directly from the network. [7-5]
90
+ https://datatracker.ietf.org/doc/html/rfc9849#section-7-5
91
+ did not send expected alert: illegal_parameter
92
+
93
+ 2 failure
85
94
  ```
86
95
 
87
96
  By default, `echspec` retrieves ECHConfigs via DNS HTTPS resource records. You can specify a local PEM file using the `-f, --file FILE` option. To test a server on localhost:
@@ -99,13 +99,7 @@ module EchSpec
99
99
  exs, = TLS13Client.gen_ch_extensions(hostname)
100
100
  exs = super_extensions.new(exs.values)
101
101
  inner = TTTLS13::Message::ClientHello.new(
102
- cipher_suites: TTTLS13::CipherSuites.new(
103
- [
104
- TTTLS13::CipherSuite::TLS_AES_256_GCM_SHA384,
105
- TTTLS13::CipherSuite::TLS_CHACHA20_POLY1305_SHA256,
106
- TTTLS13::CipherSuite::TLS_AES_128_GCM_SHA256
107
- ]
108
- ),
102
+ cipher_suites: TTTLS13::CipherSuites.new(TLS13Client::DEFAULT_CH_CIPHER_SUITES),
109
103
  extensions: exs.merge(
110
104
  TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO => inner_ech
111
105
  )
@@ -51,13 +51,7 @@ module EchSpec
51
51
  inner_ech = TTTLS13::Message::Extension::ECHClientHello.new_inner
52
52
  exs, = TLS13Client.gen_ch_extensions(hostname)
53
53
  inner = TTTLS13::Message::ClientHello.new(
54
- cipher_suites: TTTLS13::CipherSuites.new(
55
- [
56
- TTTLS13::CipherSuite::TLS_AES_256_GCM_SHA384,
57
- TTTLS13::CipherSuite::TLS_CHACHA20_POLY1305_SHA256,
58
- TTTLS13::CipherSuite::TLS_AES_128_GCM_SHA256
59
- ]
60
- ),
54
+ cipher_suites: TTTLS13::CipherSuites.new(TLS13Client::DEFAULT_CH_CIPHER_SUITES),
61
55
  extensions: exs.merge(
62
56
  TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO => inner_ech
63
57
  )
@@ -77,13 +77,7 @@ module EchSpec
77
77
  inner_ech = IllegalEchClientHello.new_inner
78
78
  exs, = TLS13Client.gen_ch_extensions(hostname)
79
79
  inner = TTTLS13::Message::ClientHello.new(
80
- cipher_suites: TTTLS13::CipherSuites.new(
81
- [
82
- TTTLS13::CipherSuite::TLS_AES_256_GCM_SHA384,
83
- TTTLS13::CipherSuite::TLS_CHACHA20_POLY1305_SHA256,
84
- TTTLS13::CipherSuite::TLS_AES_128_GCM_SHA256
85
- ]
86
- ),
80
+ cipher_suites: TTTLS13::CipherSuites.new(TLS13Client::DEFAULT_CH_CIPHER_SUITES),
87
81
  extensions: exs.merge(
88
82
  TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO => inner_ech
89
83
  )
@@ -119,13 +113,7 @@ module EchSpec
119
113
  inner_ech = TTTLS13::Message::Extension::ECHClientHello.new_inner
120
114
  exs, = TLS13Client.gen_ch_extensions(hostname)
121
115
  inner = TTTLS13::Message::ClientHello.new(
122
- cipher_suites: TTTLS13::CipherSuites.new(
123
- [
124
- TTTLS13::CipherSuite::TLS_AES_256_GCM_SHA384,
125
- TTTLS13::CipherSuite::TLS_CHACHA20_POLY1305_SHA256,
126
- TTTLS13::CipherSuite::TLS_AES_128_GCM_SHA256
127
- ]
128
- ),
116
+ cipher_suites: TTTLS13::CipherSuites.new(TLS13Client::DEFAULT_CH_CIPHER_SUITES),
129
117
  extensions: exs.merge(
130
118
  TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO => inner_ech
131
119
  )
@@ -154,7 +142,7 @@ module EchSpec
154
142
  cipher_suite: ech_state.cipher_suite,
155
143
  config_id: ech_state.config_id,
156
144
  enc:,
157
- payload: '0' * (encoded.length + overhead_len)
145
+ payload: "\x00" * (encoded.length + overhead_len)
158
146
  )
159
147
  aad = TTTLS13::Message::ClientHello.new(
160
148
  legacy_version: inner.legacy_version,
@@ -0,0 +1,80 @@
1
+ module EchSpec
2
+ module Spec
3
+ class Spec7_5 < WithSocket
4
+ # In shared mode, a server plays both roles, first decrypting the
5
+ # ClientHelloOuter and then using the contents of the
6
+ # ClientHelloInner. A shared mode server which receives a ClientHello
7
+ # with ECHClientHello.type of inner MUST abort with an
8
+ # "illegal_parameter" alert, because such a ClientHello should never be
9
+ # received directly from the network.
10
+ #
11
+ # https://datatracker.ietf.org/doc/html/rfc9849#section-7-5
12
+
13
+ # @return [EchSpec::SpecGroup]
14
+ def self.spec_group
15
+ SpecGroup.new(
16
+ '7-5',
17
+ [
18
+ SpecCase.new(
19
+ 'MUST abort with an "illegal_parameter" alert, if ClientHello is received with ECHClientHello.type of inner directly from the network.',
20
+ method(:validate_ch_with_inner_ech_type)
21
+ )
22
+ ]
23
+ )
24
+ end
25
+
26
+ # @param hostname [String]
27
+ # @param port [Integer]
28
+ # @param _ [ECHConfig]
29
+ #
30
+ # @return [EchSpec::Ok | Err]
31
+ def self.validate_ch_with_inner_ech_type(hostname, port, _)
32
+ Spec7_5.new.do_validate_ch_with_inner_ech_type(hostname, port)
33
+ end
34
+
35
+ # @param hostname [String]
36
+ # @param port [Integer]
37
+ #
38
+ # @return [EchSpec::Ok | Err]
39
+ def do_validate_ch_with_inner_ech_type(hostname, port)
40
+ with_socket(hostname, port) do |socket|
41
+ recv = send_ch_with_inner_ech_type(socket, hostname)
42
+ return Err.new('did not send expected alert: illegal_parameter', message_stack) \
43
+ unless Spec.expect_alert(recv, :illegal_parameter)
44
+
45
+ Ok.new(nil)
46
+ end
47
+ end
48
+
49
+ # @param socket [TCPSocket]
50
+ # @param hostname [String]
51
+ #
52
+ # @return [TTTLS13::Message::Record]
53
+ def send_ch_with_inner_ech_type(socket, hostname)
54
+ conn = TLS13Client::Connection.new(socket, :client)
55
+ inner_ech = TTTLS13::Message::Extension::ECHClientHello.new_inner
56
+ exs, = TLS13Client.gen_ch_extensions(hostname)
57
+ # ClientHello with ECHClientHello.type of inner, without encryption
58
+ ch = TTTLS13::Message::ClientHello.new(
59
+ cipher_suites: TTTLS13::CipherSuites.new(TLS13Client::DEFAULT_CH_CIPHER_SUITES),
60
+ extensions: exs.merge(
61
+ TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO => inner_ech
62
+ )
63
+ )
64
+ conn.send_record(
65
+ TTTLS13::Message::Record.new(
66
+ type: TTTLS13::Message::ContentType::HANDSHAKE,
67
+ messages: [ch],
68
+ cipher: TTTLS13::Cryptograph::Passer.new
69
+ )
70
+ )
71
+ @stack << ch
72
+
73
+ recv, = conn.recv_message(TTTLS13::Cryptograph::Passer.new)
74
+ @stack << recv
75
+
76
+ recv
77
+ end
78
+ end
79
+ end
80
+ end
@@ -21,6 +21,14 @@ module EchSpec
21
21
  SpecCase.new(
22
22
  'MUST abort with an "illegal_parameter" alert, if ClientHelloInner does not contain the "encrypted_client_hello" extension.',
23
23
  method(:validate_ch_inner_without_ech)
24
+ ),
25
+ SpecCase.new(
26
+ 'MUST abort with an "illegal_parameter" alert, if ClientHelloInner contains the "encrypted_client_hello" extension of type outer.',
27
+ method(:validate_ch_inner_with_outer_ech)
28
+ ),
29
+ SpecCase.new(
30
+ 'MUST abort with an "illegal_parameter" alert, if ClientHelloInner contains the "encrypted_client_hello" extension of type inner that is not well-formed.',
31
+ method(:validate_ch_inner_with_malformed_ech)
24
32
  )
25
33
  ]
26
34
  )
@@ -74,7 +82,54 @@ module EchSpec
74
82
  end
75
83
  end
76
84
 
77
- # rubocop: disable Metrics/MethodLength
85
+ # @param hostname [String]
86
+ # @param port [Integer]
87
+ # @param ech_config [ECHConfig]
88
+ #
89
+ # @return [EchSpec::Ok | Err]
90
+ def self.validate_ch_inner_with_outer_ech(hostname, port, ech_config)
91
+ Spec7_1_11.new.do_validate_ch_inner_with_outer_ech(hostname, port, ech_config)
92
+ end
93
+
94
+ # @param hostname [String]
95
+ # @param port [Integer]
96
+ # @param ech_config [ECHConfig]
97
+ #
98
+ # @return [EchSpec::Ok | Err]
99
+ def do_validate_ch_inner_with_outer_ech(hostname, port, ech_config)
100
+ with_socket(hostname, port) do |socket|
101
+ recv = send_ch_inner_with_outer_ech(socket, hostname, ech_config)
102
+ return Err.new('did not send expected alert: illegal_parameter', message_stack) \
103
+ unless Spec.expect_alert(recv, :illegal_parameter)
104
+
105
+ Ok.new(nil)
106
+ end
107
+ end
108
+
109
+ # @param hostname [String]
110
+ # @param port [Integer]
111
+ # @param ech_config [ECHConfig]
112
+ #
113
+ # @return [EchSpec::Ok | Err]
114
+ def self.validate_ch_inner_with_malformed_ech(hostname, port, ech_config)
115
+ Spec7_1_11.new.do_validate_ch_inner_with_malformed_ech(hostname, port, ech_config)
116
+ end
117
+
118
+ # @param hostname [String]
119
+ # @param port [Integer]
120
+ # @param ech_config [ECHConfig]
121
+ #
122
+ # @return [EchSpec::Ok | Err]
123
+ def do_validate_ch_inner_with_malformed_ech(hostname, port, ech_config)
124
+ with_socket(hostname, port) do |socket|
125
+ recv = send_ch_inner_with_malformed_ech(socket, hostname, ech_config)
126
+ return Err.new('did not send expected alert: illegal_parameter', message_stack) \
127
+ unless Spec.expect_alert(recv, :illegal_parameter)
128
+
129
+ Ok.new(nil)
130
+ end
131
+ end
132
+
78
133
  def send_ch_ech_with_tls12(socket, hostname, ech_config)
79
134
  conn = TLS13Client::Connection.new(socket, :client)
80
135
  inner_ech = TTTLS13::Message::Extension::ECHClientHello.new_inner
@@ -86,13 +141,7 @@ module EchSpec
86
141
  )
87
142
  exs[TTTLS13::Message::ExtensionType::SUPPORTED_VERSIONS] = versions
88
143
  inner = TTTLS13::Message::ClientHello.new(
89
- cipher_suites: TTTLS13::CipherSuites.new(
90
- [
91
- TTTLS13::CipherSuite::TLS_AES_256_GCM_SHA384,
92
- TTTLS13::CipherSuite::TLS_CHACHA20_POLY1305_SHA256,
93
- TTTLS13::CipherSuite::TLS_AES_128_GCM_SHA256
94
- ]
95
- ),
144
+ cipher_suites: TTTLS13::CipherSuites.new(TLS13Client::DEFAULT_CH_CIPHER_SUITES),
96
145
  extensions: exs.merge(
97
146
  TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO => inner_ech
98
147
  )
@@ -115,20 +164,13 @@ module EchSpec
115
164
 
116
165
  recv
117
166
  end
118
- # rubocop: enable Metrics/MethodLength
119
167
 
120
168
  def send_ch_inner_without_ech(socket, hostname, ech_config)
121
169
  conn = TLS13Client::Connection.new(socket, :client)
122
170
  exs, = TLS13Client.gen_ch_extensions(hostname)
123
171
  # ClientHelloInner without "encrypted_client_hello"
124
172
  inner = TTTLS13::Message::ClientHello.new(
125
- cipher_suites: TTTLS13::CipherSuites.new(
126
- [
127
- TTTLS13::CipherSuite::TLS_AES_256_GCM_SHA384,
128
- TTTLS13::CipherSuite::TLS_CHACHA20_POLY1305_SHA256,
129
- TTTLS13::CipherSuite::TLS_AES_128_GCM_SHA256
130
- ]
131
- ),
173
+ cipher_suites: TTTLS13::CipherSuites.new(TLS13Client::DEFAULT_CH_CIPHER_SUITES),
132
174
  extensions: exs
133
175
  )
134
176
 
@@ -149,6 +191,103 @@ module EchSpec
149
191
 
150
192
  recv
151
193
  end
194
+
195
+ def send_ch_inner_with_outer_ech(socket, hostname, ech_config)
196
+ conn = TLS13Client::Connection.new(socket, :client)
197
+ # ClientHelloInner with "encrypted_client_hello" of type outer
198
+ outer_ech = TTTLS13::Ech.new_grease_ech
199
+ exs, = TLS13Client.gen_ch_extensions(hostname)
200
+ inner = TTTLS13::Message::ClientHello.new(
201
+ cipher_suites: TTTLS13::CipherSuites.new(TLS13Client::DEFAULT_CH_CIPHER_SUITES),
202
+ extensions: exs.merge(
203
+ TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO => outer_ech
204
+ )
205
+ )
206
+
207
+ selector = proc { |x| TLS13Client.select_ech_hpke_cipher_suite(x) }
208
+ ch, inner, = TTTLS13::Ech.offer_ech(inner, ech_config, selector)
209
+ conn.send_record(
210
+ TTTLS13::Message::Record.new(
211
+ type: TTTLS13::Message::ContentType::HANDSHAKE,
212
+ messages: [ch],
213
+ cipher: TTTLS13::Cryptograph::Passer.new
214
+ )
215
+ )
216
+ @stack << inner
217
+ @stack << ch
218
+
219
+ recv, = conn.recv_message(TTTLS13::Cryptograph::Passer.new)
220
+ @stack << recv
221
+
222
+ recv
223
+ end
224
+
225
+ def send_ch_inner_with_malformed_ech(socket, hostname, ech_config)
226
+ conn = TLS13Client::Connection.new(socket, :client)
227
+ inner_ech = MalformedInnerEch.new(TTTLS13::Ech.new_grease_ech)
228
+ exs, = TLS13Client.gen_ch_extensions(hostname)
229
+ inner = TTTLS13::Message::ClientHello.new(
230
+ cipher_suites: TTTLS13::CipherSuites.new(TLS13Client::DEFAULT_CH_CIPHER_SUITES),
231
+ extensions: exs.merge(
232
+ TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO => inner_ech
233
+ )
234
+ )
235
+
236
+ selector = proc { |x| TLS13Client.select_ech_hpke_cipher_suite(x) }
237
+ ch, inner, = TTTLS13::Ech.offer_ech(inner, ech_config, selector)
238
+ conn.send_record(
239
+ TTTLS13::Message::Record.new(
240
+ type: TTTLS13::Message::ContentType::HANDSHAKE,
241
+ messages: [ch],
242
+ cipher: TTTLS13::Cryptograph::Passer.new
243
+ )
244
+ )
245
+ @stack << inner
246
+ @stack << ch
247
+
248
+ recv, = conn.recv_message(TTTLS13::Cryptograph::Passer.new)
249
+ @stack << recv
250
+
251
+ recv
252
+ end
253
+
254
+ # The well-formed ECHClientHello has no fields after type inner:
255
+ #
256
+ # struct {
257
+ # ECHClientHelloType type;
258
+ # select (ECHClientHello.type) {
259
+ # case outer:
260
+ # HpkeSymmetricCipherSuite cipher_suite;
261
+ # uint8 config_id;
262
+ # opaque enc<0..2^16-1>;
263
+ # opaque payload<1..2^16-1>;
264
+ # case inner:
265
+ # Empty;
266
+ # };
267
+ # } ECHClientHello;
268
+ #
269
+ # https://datatracker.ietf.org/doc/html/rfc9849#section-5
270
+ class MalformedInnerEch < TTTLS13::Message::Extension::ECHClientHello
271
+ using TTTLS13::Refinements
272
+
273
+ # @param ech [TTTLS13::Message::Extension::ECHClientHello] of type outer; its fields follow type inner
274
+ def initialize(ech)
275
+ super(
276
+ type: TTTLS13::Message::Extension::ECHClientHelloType::INNER,
277
+ cipher_suite: ech.cipher_suite,
278
+ config_id: ech.config_id,
279
+ enc: ech.enc,
280
+ payload: ech.payload
281
+ )
282
+ end
283
+
284
+ def serialize
285
+ binary = @type + @cipher_suite.encode + @config_id.to_uint8 \
286
+ + @enc.prefix_uint16_length + @payload.prefix_uint16_length
287
+
288
+ @extension_type + binary.prefix_uint16_length
289
+ end
290
+ end
152
291
  end
153
292
  end
154
293
  end
@@ -0,0 +1,107 @@
1
+ module EchSpec
2
+ module Spec
3
+ class Spec7_1_13 < WithSocket
4
+ # Otherwise, if all candidate ECHConfig values fail to decrypt the
5
+ # extension, the client-facing server MUST ignore the extension and
6
+ # proceed with the connection using ClientHelloOuter with the following
7
+ # modifications:
8
+ #
9
+ # https://datatracker.ietf.org/doc/html/rfc9849#section-7.1-13
10
+
11
+ # @return [EchSpec::SpecGroup]
12
+ def self.spec_group
13
+ SpecGroup.new(
14
+ '7.1-13',
15
+ [
16
+ SpecCase.new(
17
+ 'MUST ignore the extension and proceed with the connection using ClientHelloOuter, if it receives a GREASE "encrypted_client_hello" extension.',
18
+ method(:validate_proceed_with_ch_outer)
19
+ )
20
+ ]
21
+ )
22
+ end
23
+
24
+ # @param hostname [String]
25
+ # @param port [Integer]
26
+ # @param _ [ECHConfig]
27
+ #
28
+ # @return [EchSpec::Ok | Err]
29
+ def self.validate_proceed_with_ch_outer(hostname, port, _)
30
+ Spec7_1_13.new.do_validate_proceed_with_ch_outer(hostname, port)
31
+ end
32
+
33
+ # @param hostname [String]
34
+ # @param port [Integer]
35
+ #
36
+ # @return [EchSpec::Ok | Err]
37
+ def do_validate_proceed_with_ch_outer(hostname, port)
38
+ with_socket(hostname, port) do |socket|
39
+ recv = send_ch_with_greased_ech(socket, hostname)
40
+ return Err.new('did not proceed with the connection using ClientHelloOuter', message_stack) \
41
+ unless recv.is_a?(TTTLS13::Message::EncryptedExtensions)
42
+
43
+ Ok.new(nil)
44
+ end
45
+ end
46
+
47
+ # @param socket [TCPSocket]
48
+ # @param hostname [String]
49
+ #
50
+ # @raise [EchSpec::Error::BeforeTargetSituationError]
51
+ #
52
+ # @return [TTTLS13::Message::$Object]
53
+ # rubocop: disable Metrics/AbcSize
54
+ # rubocop: disable Metrics/MethodLength
55
+ def send_ch_with_greased_ech(socket, hostname)
56
+ conn = TLS13Client::Connection.new(socket, :client)
57
+ inner_ech = TTTLS13::Message::Extension::ECHClientHello.new_inner
58
+ exs, shared_secret = TLS13Client.gen_ch_extensions(hostname)
59
+ inner = TTTLS13::Message::ClientHello.new(
60
+ cipher_suites: TTTLS13::CipherSuites.new(TLS13Client::DEFAULT_CH_CIPHER_SUITES),
61
+ extensions: exs.merge(
62
+ TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO => inner_ech
63
+ )
64
+ )
65
+ @stack << inner
66
+
67
+ ch = TTTLS13::Ech.new_greased_ch(inner, TTTLS13::Ech.new_grease_ech)
68
+ conn.send_record(
69
+ TTTLS13::Message::Record.new(
70
+ type: TTTLS13::Message::ContentType::HANDSHAKE,
71
+ messages: [ch],
72
+ cipher: TTTLS13::Cryptograph::Passer.new
73
+ )
74
+ )
75
+ @stack << ch
76
+
77
+ recv, = conn.recv_message(TTTLS13::Cryptograph::Passer.new)
78
+ @stack << recv
79
+ raise Error::BeforeTargetSituationError, 'not received ServerHello' \
80
+ if recv.is_a?(TTTLS13::Message::ServerHello) && recv.hrr?
81
+ return recv unless recv.is_a?(TTTLS13::Message::ServerHello)
82
+
83
+ # derive the handshake keys from ClientHelloOuter
84
+ transcript = TTTLS13::Transcript.new
85
+ transcript[TTTLS13::CH] = [ch, ch.serialize]
86
+ sh = recv
87
+ transcript[TTTLS13::SH] = [sh, sh.serialize]
88
+ kse = sh.extensions[TTTLS13::Message::ExtensionType::KEY_SHARE]
89
+ .key_share_entry.first
90
+ key_schedule = TTTLS13::KeySchedule.new(
91
+ psk: nil,
92
+ shared_secret: shared_secret.build(kse.group, kse.key_exchange),
93
+ cipher_suite: sh.cipher_suite,
94
+ transcript:
95
+ )
96
+ hs_rcipher = TTTLS13::Endpoint.gen_cipher(
97
+ sh.cipher_suite,
98
+ key_schedule.server_handshake_write_key,
99
+ key_schedule.server_handshake_write_iv
100
+ )
101
+ conn.recv_message_skipping_ccs(hs_rcipher, @stack)
102
+ end
103
+ # rubocop: enable Metrics/AbcSize
104
+ # rubocop: enable Metrics/MethodLength
105
+ end
106
+ end
107
+ end
@@ -135,7 +135,7 @@ module EchSpec
135
135
  def send_2nd_ch_missing_ech(socket, hostname, ech_config)
136
136
  conn, _inner1, ch1, hrr, = TLS13Client.recv_hrr(socket, hostname, ech_config, @stack)
137
137
  # send 2nd ClientHello without ech
138
- new_exs = TLS13Client.gen_newch_extensions(ch1, hrr)
138
+ new_exs, = TLS13Client.gen_newch_extensions(ch1, hrr)
139
139
  new_exs.delete(TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO)
140
140
  ch = TTTLS13::Message::ClientHello.new(
141
141
  legacy_version: ch1.legacy_version,
@@ -160,7 +160,7 @@ module EchSpec
160
160
  def send_2nd_ch_unchanged_ech(socket, hostname, ech_config)
161
161
  conn, inner1, ch1, hrr, = TLS13Client.recv_hrr(socket, hostname, ech_config, @stack)
162
162
  # send 2nd ClientHello with unchanged ech
163
- new_exs = TLS13Client.gen_newch_extensions(ch1, hrr)
163
+ new_exs, = TLS13Client.gen_newch_extensions(ch1, hrr)
164
164
  new_exs[TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO] =
165
165
  ch1.extensions[TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO]
166
166
  ch = TTTLS13::Message::ClientHello.new(
@@ -188,7 +188,7 @@ module EchSpec
188
188
  conn, inner1, ch1, hrr, = TLS13Client.recv_hrr(socket, hostname, ech_config, @stack)
189
189
  # send 2nd ClientHello with changed config_id
190
190
  ech1 = ch1.extensions[TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO]
191
- new_exs = TLS13Client.gen_newch_extensions(ch1, hrr)
191
+ new_exs, = TLS13Client.gen_newch_extensions(ch1, hrr)
192
192
  new_exs[TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO] =
193
193
  TTTLS13::Message::Extension::ECHClientHello.new_outer(
194
194
  cipher_suite: ech1.cipher_suite,
@@ -223,7 +223,7 @@ module EchSpec
223
223
  # send 2nd ClientHello with changed cipher_suite
224
224
  ech1 = ch1.extensions[TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO]
225
225
  aead_id = ech1.cipher_suite.aead_id.uint16 == HPKE::AES_128_GCM ? HPKE::AES_256_GCM : HPKE::AES_128_GCM
226
- new_exs = TLS13Client.gen_newch_extensions(ch1, hrr)
226
+ new_exs, = TLS13Client.gen_newch_extensions(ch1, hrr)
227
227
  new_exs[TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO] =
228
228
  TTTLS13::Message::Extension::ECHClientHello.new_outer(
229
229
  cipher_suite: ECHConfig::ECHConfigContents::HpkeKeyConfig::HpkeSymmetricCipherSuite.new(
@@ -50,13 +50,14 @@ module EchSpec
50
50
  def send_2nd_ch_with_undecryptable_ech(socket, hostname, ech_config)
51
51
  conn, inner1, _ch1, hrr, ech_state = TLS13Client.recv_hrr(socket, hostname, ech_config, @stack)
52
52
  # send 2nd ClientHello with undecryptable ech
53
+ new_exs, = TLS13Client.gen_newch_extensions(inner1, hrr)
53
54
  inner = TTTLS13::Message::ClientHello.new(
54
55
  legacy_version: inner1.legacy_version,
55
56
  random: inner1.random,
56
57
  legacy_session_id: inner1.legacy_session_id,
57
58
  cipher_suites: inner1.cipher_suites,
58
59
  legacy_compression_methods: inner1.legacy_compression_methods,
59
- extensions: TLS13Client.gen_newch_extensions(inner1, hrr)
60
+ extensions: new_exs
60
61
  )
61
62
  ech_state.ctx.increment_seq # invalidly increment of the sequence number
62
63
  ch, inner = TTTLS13::Ech.offer_new_ech(inner, ech_state)
@@ -62,13 +62,7 @@ module EchSpec
62
62
  )
63
63
  exs[TTTLS13::Message::ExtensionType::KEY_SHARE] = key_share
64
64
  inner = TTTLS13::Message::ClientHello.new(
65
- cipher_suites: TTTLS13::CipherSuites.new(
66
- [
67
- TTTLS13::CipherSuite::TLS_AES_256_GCM_SHA384,
68
- TTTLS13::CipherSuite::TLS_CHACHA20_POLY1305_SHA256,
69
- TTTLS13::CipherSuite::TLS_AES_128_GCM_SHA256
70
- ]
71
- ),
65
+ cipher_suites: TTTLS13::CipherSuites.new(TLS13Client::DEFAULT_CH_CIPHER_SUITES),
72
66
  extensions: exs.merge(
73
67
  TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO => inner_ech
74
68
  )
@@ -94,10 +88,7 @@ module EchSpec
94
88
  unless hrr.extensions.include?(TTTLS13::Message::ExtensionType::KEY_SHARE)
95
89
 
96
90
  # send 2nd ClientHello; the greased ech is copied from 1st ClientHello
97
- new_exs = TLS13Client.gen_newch_extensions(ch1, hrr)
98
- group = hrr.extensions[TTTLS13::Message::ExtensionType::KEY_SHARE].key_share_entry.first.group
99
- key_share, shared_secret = TTTLS13::Message::Extension::KeyShare.gen_ch_key_share([group])
100
- new_exs[TTTLS13::Message::ExtensionType::KEY_SHARE] = key_share
91
+ new_exs, shared_secret = TLS13Client.gen_newch_extensions(ch1, hrr)
101
92
  ch = TTTLS13::Message::ClientHello.new(
102
93
  legacy_version: ch1.legacy_version,
103
94
  random: ch1.random,
@@ -13,6 +13,10 @@ module EchSpec
13
13
  SpecGroup.new(
14
14
  '7.2-1',
15
15
  [
16
+ SpecCase.new(
17
+ 'MUST confirm ECH acceptance in ServerHello.',
18
+ method(:validate_sh_confirmation)
19
+ ),
16
20
  SpecCase.new(
17
21
  'MUST confirm ECH acceptance in ServerHello, if it confirmed ECH acceptance in HelloRetryRequest.',
18
22
  method(:validate_sh_confirmation_after_hrr)
@@ -21,6 +25,30 @@ module EchSpec
21
25
  )
22
26
  end
23
27
 
28
+ # @param hostname [String]
29
+ # @param port [Integer]
30
+ # @param ech_config [ECHConfig]
31
+ #
32
+ # @return [EchSpec::Ok | Err]
33
+ def self.validate_sh_confirmation(hostname, port, ech_config)
34
+ Spec7_2_1.new.do_validate_sh_confirmation(hostname, port, ech_config)
35
+ end
36
+
37
+ # @param hostname [String]
38
+ # @param port [Integer]
39
+ # @param ech_config [ECHConfig]
40
+ #
41
+ # @return [EchSpec::Ok | Err]
42
+ def do_validate_sh_confirmation(hostname, port, ech_config)
43
+ with_socket(hostname, port) do |socket|
44
+ recv, confirmation = send_ch(socket, hostname, ech_config)
45
+ return Err.new('did not send expected handshake message: ServerHello', message_stack) \
46
+ unless recv.is_a?(TTTLS13::Message::ServerHello)
47
+
48
+ validate_sh_random(confirmation, recv)
49
+ end
50
+ end
51
+
24
52
  # @param hostname [String]
25
53
  # @param port [Integer]
26
54
  # @param ech_config [ECHConfig]
@@ -41,7 +69,7 @@ module EchSpec
41
69
  return Err.new('did not send expected handshake message: ServerHello', message_stack) \
42
70
  unless recv.is_a?(TTTLS13::Message::ServerHello) && !recv.hrr?
43
71
 
44
- validate_sh_confirmation(confirmation, recv)
72
+ validate_sh_random(confirmation, recv)
45
73
  end
46
74
  end
47
75
 
@@ -49,11 +77,57 @@ module EchSpec
49
77
  # @param sh [TTTLS13::Message::ServerHello]
50
78
  #
51
79
  # @return [EchSpec::Ok | Err]
52
- def validate_sh_confirmation(expected, sh)
80
+ def validate_sh_random(expected, sh)
53
81
  return Ok.new(nil) if sh.random[-8..] == expected
54
82
 
55
- Err.new('the last 8 bytes of ServerHello.random did not match accept_confirmation, although HelloRetryRequest confirmed ECH acceptance', message_stack)
83
+ Err.new('the last 8 bytes of ServerHello.random did not match accept_confirmation', message_stack)
84
+ end
85
+
86
+ # rubocop: disable Metrics/AbcSize
87
+ # rubocop: disable Metrics/MethodLength
88
+ def send_ch(socket, hostname, ech_config)
89
+ conn = TLS13Client::Connection.new(socket, :client)
90
+ inner_ech = TTTLS13::Message::Extension::ECHClientHello.new_inner
91
+ exs, = TLS13Client.gen_ch_extensions(hostname)
92
+ inner = TTTLS13::Message::ClientHello.new(
93
+ cipher_suites: TTTLS13::CipherSuites.new(TLS13Client::DEFAULT_CH_CIPHER_SUITES),
94
+ extensions: exs.merge(
95
+ TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO => inner_ech
96
+ )
97
+ )
98
+
99
+ selector = proc { |x| TLS13Client.select_ech_hpke_cipher_suite(x) }
100
+ ch, inner, = TTTLS13::Ech.offer_ech(inner, ech_config, selector)
101
+ conn.send_record(
102
+ TTTLS13::Message::Record.new(
103
+ type: TTTLS13::Message::ContentType::HANDSHAKE,
104
+ messages: [ch],
105
+ cipher: TTTLS13::Cryptograph::Passer.new
106
+ )
107
+ )
108
+ @stack << inner
109
+ @stack << ch
110
+
111
+ recv, = conn.recv_message(TTTLS13::Cryptograph::Passer.new)
112
+ @stack << recv
113
+ raise Error::BeforeTargetSituationError, 'not received ServerHello' \
114
+ if recv.is_a?(TTTLS13::Message::ServerHello) && recv.hrr?
115
+ return [recv, nil] unless recv.is_a?(TTTLS13::Message::ServerHello)
116
+
117
+ transcript = TTTLS13::Transcript.new
118
+ transcript[TTTLS13::CH] = [inner, inner.serialize]
119
+ sh = recv
120
+ transcript[TTTLS13::SH] = [sh, sh.serialize]
121
+ # shared_secret is not used to compute accept_confirmation
122
+ key_schedule = TTTLS13::KeySchedule.new(
123
+ shared_secret: nil,
124
+ cipher_suite: sh.cipher_suite,
125
+ transcript:
126
+ )
127
+ [recv, key_schedule.accept_confirmation]
56
128
  end
129
+ # rubocop: enable Metrics/AbcSize
130
+ # rubocop: enable Metrics/MethodLength
57
131
 
58
132
  # rubocop: disable Metrics/AbcSize
59
133
  # rubocop: disable Metrics/MethodLength
@@ -75,13 +149,14 @@ module EchSpec
75
149
  # send 2nd ClientHello; ClientHelloInner2 is based on ClientHelloInner1,
76
150
  # and its "encrypted_client_hello" extension of type inner is left
77
151
  # unmodified.
152
+ new_exs, = TLS13Client.gen_newch_extensions(inner1, hrr)
78
153
  inner2 = TTTLS13::Message::ClientHello.new(
79
154
  legacy_version: inner1.legacy_version,
80
155
  random: inner1.random,
81
156
  legacy_session_id: inner1.legacy_session_id,
82
157
  cipher_suites: inner1.cipher_suites,
83
158
  legacy_compression_methods: inner1.legacy_compression_methods,
84
- extensions: TLS13Client.gen_newch_extensions(inner1, hrr)
159
+ extensions: new_exs
85
160
  )
86
161
  ch, inner2 = TTTLS13::Ech.offer_new_ech(inner2, ech_state)
87
162
  conn.send_record(
data/lib/echspec/spec.rb CHANGED
@@ -199,7 +199,7 @@ module EchSpec
199
199
  groups = [Spec5_11, Spec5_1_9, Spec5_1_10]
200
200
 
201
201
  # https://datatracker.ietf.org/doc/html/rfc9849#section-7
202
- groups += [Spec7_3, Spec7_1_11, Spec7_1_14_2_1, Spec7_1_1_2, Spec7_1_1_5, Spec7_1_1_7, Spec7_2_1]
202
+ groups += [Spec7_3, Spec7_5, Spec7_1_11, Spec7_1_13, Spec7_1_14_2_1, Spec7_1_1_2, Spec7_1_1_5, Spec7_1_1_7, Spec7_2_1]
203
203
 
204
204
  groups.map(&:spec_group)
205
205
  end
@@ -1,6 +1,12 @@
1
1
  module EchSpec
2
2
  # rubocop: disable Metrics/ModuleLength
3
3
  module TLS13Client
4
+ DEFAULT_CH_CIPHER_SUITES = [
5
+ TTTLS13::CipherSuite::TLS_AES_256_GCM_SHA384,
6
+ TTTLS13::CipherSuite::TLS_CHACHA20_POLY1305_SHA256,
7
+ TTTLS13::CipherSuite::TLS_AES_128_GCM_SHA256
8
+ ].freeze
9
+
4
10
  class Connection < TTTLS13::Connection
5
11
  # @param socket [Socket]
6
12
  # @param side [:client or :server]
@@ -93,13 +99,14 @@ module EchSpec
93
99
  # @param hrr [TTTLS13::Message::ServerHello]
94
100
  #
95
101
  # @return [TTTLS13::Message::Extensions]
102
+ # @return [Hash of NamedGroup => OpenSSL::PKey::EC.$Object or nil]
96
103
  def gen_newch_extensions(ch1, hrr)
97
104
  exs = TTTLS13::Message::Extensions.new
98
105
  # key_share
99
106
  if hrr.extensions.include?(TTTLS13::Message::ExtensionType::KEY_SHARE)
100
107
  group = hrr.extensions[TTTLS13::Message::ExtensionType::KEY_SHARE]
101
108
  .key_share_entry.first.group
102
- key_share, = TTTLS13::Message::Extension::KeyShare.gen_ch_key_share([group])
109
+ key_share, shared_secret = TTTLS13::Message::Extension::KeyShare.gen_ch_key_share([group])
103
110
  exs << key_share
104
111
  end
105
112
 
@@ -107,7 +114,7 @@ module EchSpec
107
114
  exs << hrr.extensions[TTTLS13::Message::ExtensionType::COOKIE] \
108
115
  if hrr.extensions.include?(TTTLS13::Message::ExtensionType::COOKIE)
109
116
 
110
- ch1.extensions.merge(exs)
117
+ [ch1.extensions.merge(exs), shared_secret]
111
118
  end
112
119
 
113
120
  # @param socket [TCPSocket]
@@ -124,13 +131,7 @@ module EchSpec
124
131
  inner_ech = TTTLS13::Message::Extension::ECHClientHello.new_inner
125
132
  exs, shared_secret = TLS13Client.gen_ch_extensions(hostname)
126
133
  inner = TTTLS13::Message::ClientHello.new(
127
- cipher_suites: TTTLS13::CipherSuites.new(
128
- [
129
- TTTLS13::CipherSuite::TLS_AES_256_GCM_SHA384,
130
- TTTLS13::CipherSuite::TLS_CHACHA20_POLY1305_SHA256,
131
- TTTLS13::CipherSuite::TLS_AES_128_GCM_SHA256
132
- ]
133
- ),
134
+ cipher_suites: TTTLS13::CipherSuites.new(TLS13Client::DEFAULT_CH_CIPHER_SUITES),
134
135
  extensions: exs.merge(
135
136
  TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO => inner_ech
136
137
  )
@@ -199,7 +200,6 @@ module EchSpec
199
200
  # @return [TTTLS13::Message::ClientHello]
200
201
  # @return [TTTLS13::Message::ServerHello] HelloRetryRequest
201
202
  # @return [TTTLS13::EchState]
202
- # rubocop: disable Metrics/MethodLength
203
203
  def recv_hrr(socket, hostname, ech_config, stack)
204
204
  # send 1st ClientHello
205
205
  conn = TLS13Client::Connection.new(socket, :client)
@@ -212,13 +212,7 @@ module EchSpec
212
212
  )
213
213
  exs[TTTLS13::Message::ExtensionType::KEY_SHARE] = key_share
214
214
  inner = TTTLS13::Message::ClientHello.new(
215
- cipher_suites: TTTLS13::CipherSuites.new(
216
- [
217
- TTTLS13::CipherSuite::TLS_AES_256_GCM_SHA384,
218
- TTTLS13::CipherSuite::TLS_CHACHA20_POLY1305_SHA256,
219
- TTTLS13::CipherSuite::TLS_AES_128_GCM_SHA256
220
- ]
221
- ),
215
+ cipher_suites: TTTLS13::CipherSuites.new(TLS13Client::DEFAULT_CH_CIPHER_SUITES),
222
216
  extensions: exs.merge(
223
217
  TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO => inner_ech
224
218
  )
@@ -244,7 +238,6 @@ module EchSpec
244
238
 
245
239
  [conn, inner, ch, recv, ech_state]
246
240
  end
247
- # rubocop: enable Metrics/MethodLength
248
241
  end
249
242
  end
250
243
  # rubocop: enable Metrics/ModuleLength
@@ -1,3 +1,3 @@
1
1
  module EchSpec
2
- VERSION = '0.0.9'.freeze
2
+ VERSION = '0.0.10'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: echspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - thekuwayama
@@ -115,7 +115,9 @@ files:
115
115
  - lib/echspec/spec/5.1-10.rb
116
116
  - lib/echspec/spec/5.1-9.rb
117
117
  - lib/echspec/spec/7-3.rb
118
+ - lib/echspec/spec/7-5.rb
118
119
  - lib/echspec/spec/7.1-11.rb
120
+ - lib/echspec/spec/7.1-13.rb
119
121
  - lib/echspec/spec/7.1-14.2.1.rb
120
122
  - lib/echspec/spec/7.1.1-2.rb
121
123
  - lib/echspec/spec/7.1.1-5.rb