| 1 |
%% Copyright (c) Loïc Hoguin <[email protected]> |
| 2 |
%% |
| 3 |
%% Permission to use, copy, modify, and/or distribute this software for any |
| 4 |
%% purpose with or without fee is hereby granted, provided that the above |
| 5 |
%% copyright notice and this permission notice appear in all copies. |
| 6 |
%% |
| 7 |
%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 |
%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 |
%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 10 |
%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 |
%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 12 |
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 13 |
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 14 |
|
| 15 |
-module(rfc9220_SUITE). |
| 16 |
-compile(export_all). |
| 17 |
-compile(nowarn_export_all). |
| 18 |
|
| 19 |
-import(ct_helper, [config/2]). |
| 20 |
-import(ct_helper, [doc/1]). |
| 21 |
|
| 22 |
-ifdef(COWBOY_QUICER). |
| 23 |
|
| 24 |
all() -> |
| 25 |
[{group, enabled}]. |
| 26 |
|
| 27 |
groups() -> |
| 28 |
Tests = ct_helper:all(?MODULE), |
| 29 |
[{enabled, [], Tests}]. %% @todo Enable parallel when all is better. |
| 30 |
|
| 31 |
init_per_group(Name = enabled, Config) -> |
| 32 |
cowboy_test:init_http3(Name, #{ |
| 33 |
enable_connect_protocol => true, |
| 34 |
env => #{dispatch => cowboy_router:compile(init_routes(Config))} |
| 35 |
}, Config). |
| 36 |
|
| 37 |
end_per_group(Name, _) -> |
| 38 |
cowboy_test:stop_group(Name). |
| 39 |
|
| 40 |
init_routes(_) -> [ |
| 41 |
{"localhost", [ |
| 42 |
{"/ws", ws_echo, []} |
| 43 |
]} |
| 44 |
]. |
| 45 |
|
| 46 |
% The SETTINGS_ENABLE_CONNECT_PROTOCOL SETTINGS Parameter. |
| 47 |
|
| 48 |
% The new parameter name is SETTINGS_ENABLE_CONNECT_PROTOCOL. The |
| 49 |
% value of the parameter MUST be 0 or 1. |
| 50 |
|
| 51 |
% Upon receipt of SETTINGS_ENABLE_CONNECT_PROTOCOL with a value of 1 a |
| 52 |
% client MAY use the Extended CONNECT definition of this document when |
| 53 |
% creating new streams. Receipt of this parameter by a server does not |
| 54 |
% have any impact. |
| 55 |
%% @todo ignore_client_enable_setting(Config) -> |
| 56 |
|
| 57 |
reject_handshake_when_disabled(Config0) -> |
| 58 |
doc("Extended CONNECT requests MUST be rejected with a " |
| 59 |
"H3_MESSAGE_ERROR stream error when enable_connect_protocol=false. " |
| 60 |
"(RFC9220, RFC8441 4)"), |
| 61 |
Config = cowboy_test:init_http3(disabled, #{ |
| 62 |
enable_connect_protocol => false, |
| 63 |
env => #{dispatch => cowboy_router:compile(init_routes(Config0))} |
| 64 |
}, Config0), |
| 65 |
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 0. |
| 66 |
#{ |
| 67 |
conn := Conn, |
| 68 |
settings := Settings |
| 69 |
} = rfc9114_SUITE:do_connect(Config), |
| 70 |
case Settings of |
| 71 |
#{enable_connect_protocol := false} -> ok; |
| 72 |
_ when map_size(Settings) =:= 0 -> ok |
| 73 |
end, |
| 74 |
%% Send a CONNECT :protocol request to upgrade the stream to Websocket. |
| 75 |
{ok, StreamRef} = quicer:start_stream(Conn, #{}), |
| 76 |
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([ |
| 77 |
{<<":method">>, <<"CONNECT">>}, |
| 78 |
{<<":protocol">>, <<"websocket">>}, |
| 79 |
{<<":scheme">>, <<"https">>}, |
| 80 |
{<<":path">>, <<"/ws">>}, |
| 81 |
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number. |
| 82 |
{<<"sec-websocket-version">>, <<"13">>}, |
| 83 |
{<<"origin">>, <<"http://localhost">>} |
| 84 |
], 0, cow_qpack:init(encoder)), |
| 85 |
{ok, _} = quicer:send(StreamRef, [ |
| 86 |
<<1>>, %% HEADERS frame. |
| 87 |
cow_http3:encode_int(iolist_size(EncodedRequest)), |
| 88 |
EncodedRequest |
| 89 |
]), |
| 90 |
%% The stream should have been aborted. |
| 91 |
#{reason := h3_message_error} = rfc9114_SUITE:do_wait_stream_aborted(StreamRef), |
| 92 |
ok. |
| 93 |
|
| 94 |
reject_handshake_disabled_by_default(Config0) -> |
| 95 |
doc("Extended CONNECT requests MUST be rejected with a " |
| 96 |
"H3_MESSAGE_ERROR stream error when enable_connect_protocol=false. " |
| 97 |
"(RFC9220, RFC8441 4)"), |
| 98 |
Config = cowboy_test:init_http3(disabled, #{ |
| 99 |
env => #{dispatch => cowboy_router:compile(init_routes(Config0))} |
| 100 |
}, Config0), |
| 101 |
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 0. |
| 102 |
#{ |
| 103 |
conn := Conn, |
| 104 |
settings := Settings |
| 105 |
} = rfc9114_SUITE:do_connect(Config), |
| 106 |
case Settings of |
| 107 |
#{enable_connect_protocol := false} -> ok; |
| 108 |
_ when map_size(Settings) =:= 0 -> ok |
| 109 |
end, |
| 110 |
%% Send a CONNECT :protocol request to upgrade the stream to Websocket. |
| 111 |
{ok, StreamRef} = quicer:start_stream(Conn, #{}), |
| 112 |
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([ |
| 113 |
{<<":method">>, <<"CONNECT">>}, |
| 114 |
{<<":protocol">>, <<"websocket">>}, |
| 115 |
{<<":scheme">>, <<"https">>}, |
| 116 |
{<<":path">>, <<"/ws">>}, |
| 117 |
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number. |
| 118 |
{<<"sec-websocket-version">>, <<"13">>}, |
| 119 |
{<<"origin">>, <<"http://localhost">>} |
| 120 |
], 0, cow_qpack:init(encoder)), |
| 121 |
{ok, _} = quicer:send(StreamRef, [ |
| 122 |
<<1>>, %% HEADERS frame. |
| 123 |
cow_http3:encode_int(iolist_size(EncodedRequest)), |
| 124 |
EncodedRequest |
| 125 |
]), |
| 126 |
%% The stream should have been aborted. |
| 127 |
#{reason := h3_message_error} = rfc9114_SUITE:do_wait_stream_aborted(StreamRef), |
| 128 |
ok. |
| 129 |
|
| 130 |
% The Extended CONNECT Method. |
| 131 |
|
| 132 |
accept_uppercase_pseudo_header_protocol(Config) -> |
| 133 |
doc("The :protocol pseudo header is case insensitive. (RFC9220, RFC8441 4, RFC9110 7.8)"), |
| 134 |
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 1. |
| 135 |
#{conn := Conn, settings := Settings} = rfc9114_SUITE:do_connect(Config), |
| 136 |
#{enable_connect_protocol := true} = Settings, |
| 137 |
%% Send a CONNECT :protocol request to upgrade the stream to Websocket. |
| 138 |
{ok, StreamRef} = quicer:start_stream(Conn, #{}), |
| 139 |
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([ |
| 140 |
{<<":method">>, <<"CONNECT">>}, |
| 141 |
{<<":protocol">>, <<"WEBSOCKET">>}, |
| 142 |
{<<":scheme">>, <<"https">>}, |
| 143 |
{<<":path">>, <<"/ws">>}, |
| 144 |
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number. |
| 145 |
{<<"sec-websocket-version">>, <<"13">>}, |
| 146 |
{<<"origin">>, <<"http://localhost">>} |
| 147 |
], 0, cow_qpack:init(encoder)), |
| 148 |
{ok, _} = quicer:send(StreamRef, [ |
| 149 |
<<1>>, %% HEADERS frame. |
| 150 |
cow_http3:encode_int(iolist_size(EncodedRequest)), |
| 151 |
EncodedRequest |
| 152 |
]), |
| 153 |
%% Receive a 200 response. |
| 154 |
{ok, Data} = rfc9114_SUITE:do_receive_data(StreamRef), |
| 155 |
{HLenEnc, HLenBits} = rfc9114_SUITE:do_guess_int_encoding(Data), |
| 156 |
<< |
| 157 |
1, %% HEADERS frame. |
| 158 |
HLenEnc:2, HLen:HLenBits, |
| 159 |
EncodedResponse:HLen/bytes |
| 160 |
>> = Data, |
| 161 |
{ok, DecodedResponse, _DecData, _DecSt} |
| 162 |
= cow_qpack:decode_field_section(EncodedResponse, 0, cow_qpack:init(decoder)), |
| 163 |
#{<<":status">> := <<"200">>} = maps:from_list(DecodedResponse), |
| 164 |
ok. |
| 165 |
|
| 166 |
reject_many_pseudo_header_protocol(Config) -> |
| 167 |
doc("An extended CONNECT request containing more than one " |
| 168 |
"protocol component must be rejected with a H3_MESSAGE_ERROR " |
| 169 |
"stream error. (RFC9220, RFC9114 4.3.1, RFC9114 4.1.2)"), |
| 170 |
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 1. |
| 171 |
#{conn := Conn, settings := Settings} = rfc9114_SUITE:do_connect(Config), |
| 172 |
#{enable_connect_protocol := true} = Settings, |
| 173 |
%% Send an extended CONNECT request with more than one :protocol pseudo-header. |
| 174 |
{ok, StreamRef} = quicer:start_stream(Conn, #{}), |
| 175 |
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([ |
| 176 |
{<<":method">>, <<"CONNECT">>}, |
| 177 |
{<<":protocol">>, <<"websocket">>}, |
| 178 |
{<<":protocol">>, <<"mqtt">>}, |
| 179 |
{<<":scheme">>, <<"https">>}, |
| 180 |
{<<":path">>, <<"/ws">>}, |
| 181 |
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number. |
| 182 |
{<<"sec-websocket-version">>, <<"13">>}, |
| 183 |
{<<"origin">>, <<"http://localhost">>} |
| 184 |
], 0, cow_qpack:init(encoder)), |
| 185 |
{ok, _} = quicer:send(StreamRef, [ |
| 186 |
<<1>>, %% HEADERS frame. |
| 187 |
cow_http3:encode_int(iolist_size(EncodedRequest)), |
| 188 |
EncodedRequest |
| 189 |
]), |
| 190 |
%% The stream should have been aborted. |
| 191 |
#{reason := h3_message_error} = rfc9114_SUITE:do_wait_stream_aborted(StreamRef), |
| 192 |
ok. |
| 193 |
|
| 194 |
reject_unknown_pseudo_header_protocol(Config) -> |
| 195 |
doc("An extended CONNECT request containing more than one " |
| 196 |
"protocol component must be rejected with a 501 Not Implemented " |
| 197 |
"response. (RFC9220, RFC8441 4)"), |
| 198 |
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 1. |
| 199 |
#{conn := Conn, settings := Settings} = rfc9114_SUITE:do_connect(Config), |
| 200 |
#{enable_connect_protocol := true} = Settings, |
| 201 |
%% Send an extended CONNECT request with an unknown protocol. |
| 202 |
{ok, StreamRef} = quicer:start_stream(Conn, #{}), |
| 203 |
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([ |
| 204 |
{<<":method">>, <<"CONNECT">>}, |
| 205 |
{<<":protocol">>, <<"mqtt">>}, |
| 206 |
{<<":scheme">>, <<"https">>}, |
| 207 |
{<<":path">>, <<"/ws">>}, |
| 208 |
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number. |
| 209 |
{<<"sec-websocket-version">>, <<"13">>}, |
| 210 |
{<<"origin">>, <<"http://localhost">>} |
| 211 |
], 0, cow_qpack:init(encoder)), |
| 212 |
{ok, _} = quicer:send(StreamRef, [ |
| 213 |
<<1>>, %% HEADERS frame. |
| 214 |
cow_http3:encode_int(iolist_size(EncodedRequest)), |
| 215 |
EncodedRequest |
| 216 |
]), |
| 217 |
%% The stream should have been rejected with a 501 Not Implemented. |
| 218 |
#{headers := #{<<":status">> := <<"501">>}} = rfc9114_SUITE:do_receive_response(StreamRef), |
| 219 |
ok. |
| 220 |
|
| 221 |
reject_invalid_pseudo_header_protocol(Config) -> |
| 222 |
doc("An extended CONNECT request with an invalid :protocol component " |
| 223 |
"must be rejected with a H3_MESSAGE_ERROR stream error. " |
| 224 |
"(RFC9220, RFC9114 4.3.1, RFC9114 4.1.2)"), |
| 225 |
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 1. |
| 226 |
#{conn := Conn, settings := Settings} = rfc9114_SUITE:do_connect(Config), |
| 227 |
#{enable_connect_protocol := true} = Settings, |
| 228 |
%% Send an extended CONNECT request with an invalid protocol. |
| 229 |
{ok, StreamRef} = quicer:start_stream(Conn, #{}), |
| 230 |
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([ |
| 231 |
{<<":method">>, <<"CONNECT">>}, |
| 232 |
{<<":protocol">>, <<"websocket mqtt">>}, |
| 233 |
{<<":scheme">>, <<"https">>}, |
| 234 |
{<<":path">>, <<"/ws">>}, |
| 235 |
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number. |
| 236 |
{<<"sec-websocket-version">>, <<"13">>}, |
| 237 |
{<<"origin">>, <<"http://localhost">>} |
| 238 |
], 0, cow_qpack:init(encoder)), |
| 239 |
{ok, _} = quicer:send(StreamRef, [ |
| 240 |
<<1>>, %% HEADERS frame. |
| 241 |
cow_http3:encode_int(iolist_size(EncodedRequest)), |
| 242 |
EncodedRequest |
| 243 |
]), |
| 244 |
%% The stream should have been aborted. |
| 245 |
#{reason := h3_message_error} = rfc9114_SUITE:do_wait_stream_aborted(StreamRef), |
| 246 |
ok. |
| 247 |
|
| 248 |
reject_invalid_pseudo_header_protocol_crlf(Config) -> |
| 249 |
doc("An extended CONNECT request with an invalid :protocol component " |
| 250 |
"must be rejected with a H3_MESSAGE_ERROR stream error. " |
| 251 |
"(RFC9220, RFC9114 4.3.1, RFC9114 4.1.2)"), |
| 252 |
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 1. |
| 253 |
#{conn := Conn, settings := Settings} = rfc9114_SUITE:do_connect(Config), |
| 254 |
#{enable_connect_protocol := true} = Settings, |
| 255 |
%% Send an extended CONNECT request with an invalid :protocol pseudo-header. |
| 256 |
{ok, StreamRef} = quicer:start_stream(Conn, #{}), |
| 257 |
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([ |
| 258 |
{<<":method">>, <<"CONNECT">>}, |
| 259 |
{<<":protocol">>, <<"websocket\r\n">>}, |
| 260 |
{<<":scheme">>, <<"https">>}, |
| 261 |
{<<":path">>, <<"/ws">>}, |
| 262 |
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number. |
| 263 |
{<<"sec-websocket-version">>, <<"13">>}, |
| 264 |
{<<"origin">>, <<"http://localhost">>} |
| 265 |
], 0, cow_qpack:init(encoder)), |
| 266 |
{ok, _} = quicer:send(StreamRef, [ |
| 267 |
<<1>>, %% HEADERS frame. |
| 268 |
cow_http3:encode_int(iolist_size(EncodedRequest)), |
| 269 |
EncodedRequest |
| 270 |
]), |
| 271 |
%% The stream should have been aborted. |
| 272 |
#{reason := h3_message_error} = rfc9114_SUITE:do_wait_stream_aborted(StreamRef), |
| 273 |
ok. |
| 274 |
|
| 275 |
reject_invalid_pseudo_header_protocol_nul(Config) -> |
| 276 |
doc("An extended CONNECT request with an invalid :protocol component " |
| 277 |
"must be rejected with a H3_MESSAGE_ERROR stream error. " |
| 278 |
"(RFC9220, RFC9114 4.3.1, RFC9114 4.1.2)"), |
| 279 |
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 1. |
| 280 |
#{conn := Conn, settings := Settings} = rfc9114_SUITE:do_connect(Config), |
| 281 |
#{enable_connect_protocol := true} = Settings, |
| 282 |
%% Send an extended CONNECT request with an invalid :protocol pseudo-header. |
| 283 |
{ok, StreamRef} = quicer:start_stream(Conn, #{}), |
| 284 |
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([ |
| 285 |
{<<":method">>, <<"CONNECT">>}, |
| 286 |
{<<":protocol">>, <<"websocket\0">>}, |
| 287 |
{<<":scheme">>, <<"https">>}, |
| 288 |
{<<":path">>, <<"/ws">>}, |
| 289 |
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number. |
| 290 |
{<<"sec-websocket-version">>, <<"13">>}, |
| 291 |
{<<"origin">>, <<"http://localhost">>} |
| 292 |
], 0, cow_qpack:init(encoder)), |
| 293 |
{ok, _} = quicer:send(StreamRef, [ |
| 294 |
<<1>>, %% HEADERS frame. |
| 295 |
cow_http3:encode_int(iolist_size(EncodedRequest)), |
| 296 |
EncodedRequest |
| 297 |
]), |
| 298 |
%% The stream should have been aborted. |
| 299 |
#{reason := h3_message_error} = rfc9114_SUITE:do_wait_stream_aborted(StreamRef), |
| 300 |
ok. |
| 301 |
|
| 302 |
reject_missing_pseudo_header_scheme(Config) -> |
| 303 |
doc("An extended CONNECT request whtout a scheme component " |
| 304 |
"must be rejected with a H3_MESSAGE_ERROR stream error. " |
| 305 |
"(RFC9220, RFC9114 4.3.1, RFC9114 4.1.2)"), |
| 306 |
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 1. |
| 307 |
#{conn := Conn, settings := Settings} = rfc9114_SUITE:do_connect(Config), |
| 308 |
#{enable_connect_protocol := true} = Settings, |
| 309 |
%% Send an extended CONNECT request without a :scheme pseudo-header. |
| 310 |
{ok, StreamRef} = quicer:start_stream(Conn, #{}), |
| 311 |
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([ |
| 312 |
{<<":method">>, <<"CONNECT">>}, |
| 313 |
{<<":protocol">>, <<"websocket">>}, |
| 314 |
{<<":path">>, <<"/ws">>}, |
| 315 |
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number. |
| 316 |
{<<"sec-websocket-version">>, <<"13">>}, |
| 317 |
{<<"origin">>, <<"http://localhost">>} |
| 318 |
], 0, cow_qpack:init(encoder)), |
| 319 |
{ok, _} = quicer:send(StreamRef, [ |
| 320 |
<<1>>, %% HEADERS frame. |
| 321 |
cow_http3:encode_int(iolist_size(EncodedRequest)), |
| 322 |
EncodedRequest |
| 323 |
]), |
| 324 |
%% The stream should have been aborted. |
| 325 |
#{reason := h3_message_error} = rfc9114_SUITE:do_wait_stream_aborted(StreamRef), |
| 326 |
ok. |
| 327 |
|
| 328 |
reject_missing_pseudo_header_path(Config) -> |
| 329 |
doc("An extended CONNECT request whtout a path component " |
| 330 |
"must be rejected with a H3_MESSAGE_ERROR stream error. " |
| 331 |
"(RFC9220, RFC9114 4.3.1, RFC9114 4.1.2)"), |
| 332 |
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 1. |
| 333 |
#{conn := Conn, settings := Settings} = rfc9114_SUITE:do_connect(Config), |
| 334 |
#{enable_connect_protocol := true} = Settings, |
| 335 |
%% Send an extended CONNECT request without a :path pseudo-header. |
| 336 |
{ok, StreamRef} = quicer:start_stream(Conn, #{}), |
| 337 |
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([ |
| 338 |
{<<":method">>, <<"CONNECT">>}, |
| 339 |
{<<":protocol">>, <<"websocket">>}, |
| 340 |
{<<":scheme">>, <<"https">>}, |
| 341 |
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number. |
| 342 |
{<<"sec-websocket-version">>, <<"13">>}, |
| 343 |
{<<"origin">>, <<"http://localhost">>} |
| 344 |
], 0, cow_qpack:init(encoder)), |
| 345 |
{ok, _} = quicer:send(StreamRef, [ |
| 346 |
<<1>>, %% HEADERS frame. |
| 347 |
cow_http3:encode_int(iolist_size(EncodedRequest)), |
| 348 |
EncodedRequest |
| 349 |
]), |
| 350 |
%% The stream should have been aborted. |
| 351 |
#{reason := h3_message_error} = rfc9114_SUITE:do_wait_stream_aborted(StreamRef), |
| 352 |
ok. |
| 353 |
|
| 354 |
% On requests bearing the :protocol pseudo-header, the :authority |
| 355 |
% pseudo-header field is interpreted according to Section 8.1.2.3 of |
| 356 |
% [RFC7540] instead of Section 8.3 of [RFC7540]. In particular the |
| 357 |
% server MUST not make a new TCP connection to the host and port |
| 358 |
% indicated by the :authority. |
| 359 |
|
| 360 |
reject_missing_pseudo_header_authority(Config) -> |
| 361 |
doc("An extended CONNECT request whtout an authority component " |
| 362 |
"must be rejected with a H3_MESSAGE_ERROR stream error. " |
| 363 |
"(RFC9220, RFC9114 4.3.1, RFC9114 4.1.2)"), |
| 364 |
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 1. |
| 365 |
#{conn := Conn, settings := Settings} = rfc9114_SUITE:do_connect(Config), |
| 366 |
#{enable_connect_protocol := true} = Settings, |
| 367 |
%% Send an extended CONNECT request without an :authority pseudo-header. |
| 368 |
{ok, StreamRef} = quicer:start_stream(Conn, #{}), |
| 369 |
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([ |
| 370 |
{<<":method">>, <<"CONNECT">>}, |
| 371 |
{<<":protocol">>, <<"websocket">>}, |
| 372 |
{<<":scheme">>, <<"https">>}, |
| 373 |
{<<":path">>, <<"/ws">>}, |
| 374 |
{<<"sec-websocket-version">>, <<"13">>}, |
| 375 |
{<<"origin">>, <<"http://localhost">>} |
| 376 |
], 0, cow_qpack:init(encoder)), |
| 377 |
{ok, _} = quicer:send(StreamRef, [ |
| 378 |
<<1>>, %% HEADERS frame. |
| 379 |
cow_http3:encode_int(iolist_size(EncodedRequest)), |
| 380 |
EncodedRequest |
| 381 |
]), |
| 382 |
%% The stream should have been aborted. |
| 383 |
#{reason := h3_message_error} = rfc9114_SUITE:do_wait_stream_aborted(StreamRef), |
| 384 |
ok. |
| 385 |
|
| 386 |
% Using Extended CONNECT To Bootstrap The WebSocket Protocol. |
| 387 |
|
| 388 |
reject_missing_pseudo_header_protocol(Config) -> |
| 389 |
doc("An extended CONNECT request whtout a protocol component " |
| 390 |
"must be rejected with a H3_MESSAGE_ERROR stream error. " |
| 391 |
"(RFC9220, RFC9114 4.3.1, RFC9114 4.1.2)"), |
| 392 |
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 1. |
| 393 |
#{conn := Conn, settings := Settings} = rfc9114_SUITE:do_connect(Config), |
| 394 |
#{enable_connect_protocol := true} = Settings, |
| 395 |
%% Send an extended CONNECT request without a :protocol pseudo-header. |
| 396 |
{ok, StreamRef} = quicer:start_stream(Conn, #{}), |
| 397 |
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([ |
| 398 |
{<<":method">>, <<"CONNECT">>}, |
| 399 |
{<<":scheme">>, <<"https">>}, |
| 400 |
{<<":path">>, <<"/ws">>}, |
| 401 |
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number. |
| 402 |
{<<"sec-websocket-version">>, <<"13">>}, |
| 403 |
{<<"origin">>, <<"http://localhost">>} |
| 404 |
], 0, cow_qpack:init(encoder)), |
| 405 |
{ok, _} = quicer:send(StreamRef, [ |
| 406 |
<<1>>, %% HEADERS frame. |
| 407 |
cow_http3:encode_int(iolist_size(EncodedRequest)), |
| 408 |
EncodedRequest |
| 409 |
]), |
| 410 |
%% The stream should have been aborted. |
| 411 |
#{reason := h3_message_error} = rfc9114_SUITE:do_wait_stream_aborted(StreamRef), |
| 412 |
ok. |
| 413 |
|
| 414 |
% The scheme of the Target URI [RFC7230] MUST be https for wss schemed |
| 415 |
% WebSockets. HTTP/3 does not provide support for ws schemed WebSockets. |
| 416 |
% The websocket URI is still used for proxy autoconfiguration. |
| 417 |
|
| 418 |
reject_connection_header(Config) -> |
| 419 |
doc("An extended CONNECT request with a connection header " |
| 420 |
"must be rejected with a H3_MESSAGE_ERROR stream error. " |
| 421 |
"(RFC9220, RFC8441 4, RFC9114 4.2, RFC9114 4.5, RFC9114 4.1.2)"), |
| 422 |
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 1. |
| 423 |
#{conn := Conn, settings := Settings} = rfc9114_SUITE:do_connect(Config), |
| 424 |
#{enable_connect_protocol := true} = Settings, |
| 425 |
%% Send an extended CONNECT request with a connection header. |
| 426 |
{ok, StreamRef} = quicer:start_stream(Conn, #{}), |
| 427 |
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([ |
| 428 |
{<<":method">>, <<"CONNECT">>}, |
| 429 |
{<<":protocol">>, <<"websocket">>}, |
| 430 |
{<<":scheme">>, <<"https">>}, |
| 431 |
{<<":path">>, <<"/ws">>}, |
| 432 |
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number. |
| 433 |
{<<"connection">>, <<"upgrade">>}, |
| 434 |
{<<"sec-websocket-version">>, <<"13">>}, |
| 435 |
{<<"origin">>, <<"http://localhost">>} |
| 436 |
], 0, cow_qpack:init(encoder)), |
| 437 |
{ok, _} = quicer:send(StreamRef, [ |
| 438 |
<<1>>, %% HEADERS frame. |
| 439 |
cow_http3:encode_int(iolist_size(EncodedRequest)), |
| 440 |
EncodedRequest |
| 441 |
]), |
| 442 |
%% The stream should have been aborted. |
| 443 |
#{reason := h3_message_error} = rfc9114_SUITE:do_wait_stream_aborted(StreamRef), |
| 444 |
ok. |
| 445 |
|
| 446 |
reject_upgrade_header(Config) -> |
| 447 |
doc("An extended CONNECT request with a upgrade header " |
| 448 |
"must be rejected with a H3_MESSAGE_ERROR stream error. " |
| 449 |
"(RFC9220, RFC8441 4, RFC9114 4.2, RFC9114 4.5, RFC9114 4.1.2)"), |
| 450 |
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 1. |
| 451 |
#{conn := Conn, settings := Settings} = rfc9114_SUITE:do_connect(Config), |
| 452 |
#{enable_connect_protocol := true} = Settings, |
| 453 |
%% Send an extended CONNECT request with a upgrade header. |
| 454 |
{ok, StreamRef} = quicer:start_stream(Conn, #{}), |
| 455 |
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([ |
| 456 |
{<<":method">>, <<"CONNECT">>}, |
| 457 |
{<<":protocol">>, <<"websocket">>}, |
| 458 |
{<<":scheme">>, <<"https">>}, |
| 459 |
{<<":path">>, <<"/ws">>}, |
| 460 |
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number. |
| 461 |
{<<"upgrade">>, <<"websocket">>}, |
| 462 |
{<<"sec-websocket-version">>, <<"13">>}, |
| 463 |
{<<"origin">>, <<"http://localhost">>} |
| 464 |
], 0, cow_qpack:init(encoder)), |
| 465 |
{ok, _} = quicer:send(StreamRef, [ |
| 466 |
<<1>>, %% HEADERS frame. |
| 467 |
cow_http3:encode_int(iolist_size(EncodedRequest)), |
| 468 |
EncodedRequest |
| 469 |
]), |
| 470 |
%% The stream should have been aborted. |
| 471 |
#{reason := h3_message_error} = rfc9114_SUITE:do_wait_stream_aborted(StreamRef), |
| 472 |
ok. |
| 473 |
|
| 474 |
% After successfully processing the opening handshake the peers should |
| 475 |
% proceed with The WebSocket Protocol [RFC6455] using the HTTP/2 stream |
| 476 |
% from the CONNECT transaction as if it were the TCP connection |
| 477 |
% referred to in [RFC6455]. The state of the WebSocket connection at |
| 478 |
% this point is OPEN as defined by [RFC6455], Section 4.1. |
| 479 |
%% @todo I'm guessing we should test for things like RST_STREAM, |
| 480 |
%% closing the connection and others? |
| 481 |
|
| 482 |
% Examples. |
| 483 |
|
| 484 |
accept_handshake_when_enabled(Config) -> |
| 485 |
doc("Confirm the example for Websocket over HTTP/3 works. (RFC9220, RFC8441 5.1)"), |
| 486 |
%% Connect to server and confirm that SETTINGS_ENABLE_CONNECT_PROTOCOL = 1. |
| 487 |
#{conn := Conn, settings := Settings} = rfc9114_SUITE:do_connect(Config), |
| 488 |
#{enable_connect_protocol := true} = Settings, |
| 489 |
%% Send a CONNECT :protocol request to upgrade the stream to Websocket. |
| 490 |
{ok, StreamRef} = quicer:start_stream(Conn, #{}), |
| 491 |
{ok, EncodedRequest, _EncData, _EncSt} = cow_qpack:encode_field_section([ |
| 492 |
{<<":method">>, <<"CONNECT">>}, |
| 493 |
{<<":protocol">>, <<"websocket">>}, |
| 494 |
{<<":scheme">>, <<"https">>}, |
| 495 |
{<<":path">>, <<"/ws">>}, |
| 496 |
{<<":authority">>, <<"localhost">>}, %% @todo Correct port number. |
| 497 |
{<<"sec-websocket-version">>, <<"13">>}, |
| 498 |
{<<"origin">>, <<"http://localhost">>} |
| 499 |
], 0, cow_qpack:init(encoder)), |
| 500 |
{ok, _} = quicer:send(StreamRef, [ |
| 501 |
<<1>>, %% HEADERS frame. |
| 502 |
cow_http3:encode_int(iolist_size(EncodedRequest)), |
| 503 |
EncodedRequest |
| 504 |
]), |
| 505 |
%% Receive a 200 response. |
| 506 |
{ok, Data} = rfc9114_SUITE:do_receive_data(StreamRef), |
| 507 |
{HLenEnc, HLenBits} = rfc9114_SUITE:do_guess_int_encoding(Data), |
| 508 |
<< |
| 509 |
1, %% HEADERS frame. |
| 510 |
HLenEnc:2, HLen:HLenBits, |
| 511 |
EncodedResponse:HLen/bytes |
| 512 |
>> = Data, |
| 513 |
{ok, DecodedResponse, _DecData, _DecSt} |
| 514 |
= cow_qpack:decode_field_section(EncodedResponse, 0, cow_qpack:init(decoder)), |
| 515 |
#{<<":status">> := <<"200">>} = maps:from_list(DecodedResponse), |
| 516 |
%% Masked text hello echoed back clear by the server. |
| 517 |
Mask = 16#37fa213d, |
| 518 |
MaskedHello = ws_SUITE:do_mask(<<"Hello">>, Mask, <<>>), |
| 519 |
{ok, _} = quicer:send(StreamRef, cow_http3:data( |
| 520 |
<<1:1, 0:3, 1:4, 1:1, 5:7, Mask:32, MaskedHello/binary>>)), |
| 521 |
{ok, WsData} = rfc9114_SUITE:do_receive_data(StreamRef), |
| 522 |
<< |
| 523 |
0, %% DATA frame. |
| 524 |
0:2, 7:6, %% Length (2 bytes header + "Hello"). |
| 525 |
1:1, 0:3, 1:4, 0:1, 5:7, "Hello" %% Websocket frame. |
| 526 |
>> = WsData, |
| 527 |
ok. |
| 528 |
|
| 529 |
%% Closing a Websocket stream. |
| 530 |
|
| 531 |
% The HTTP/3 stream closure is also analogous to the TCP connection |
| 532 |
% closure of [RFC6455]. Orderly TCP-level closures are represented |
| 533 |
% as a FIN bit on the stream (Section 4.4 of [HTTP/3]). RST exceptions |
| 534 |
% are represented with a stream error (Section 8 of [HTTP/3]) of type |
| 535 |
% H3_REQUEST_CANCELLED (Section 8.1 of [HTTP/3]). |
| 536 |
|
| 537 |
%% @todo client close frame with FIN |
| 538 |
%% @todo server close frame with FIN |
| 539 |
%% @todo client other frame with FIN |
| 540 |
%% @todo server other frame with FIN |
| 541 |
%% @todo client close connection |
| 542 |
|
| 543 |
-else. |
| 544 |
|
| 545 |
all() -> []. |
| 546 |
|
| 547 |
-endif. |