1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2008-2020. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20 21%% 22-module(ssl_packet_SUITE). 23 24%% Note: This directive should only be used in test suites. 25-compile(export_all). 26 27-include_lib("common_test/include/ct.hrl"). 28 29-define(BYTE(X), X:8/unsigned-big-integer). 30-define(UINT16(X), X:16/unsigned-big-integer). 31-define(UINT24(X), X:24/unsigned-big-integer). 32-define(UINT32(X), X:32/unsigned-big-integer). 33-define(UINT64(X), X:64/unsigned-big-integer). 34-define(STRING(X), ?UINT32((size(X))), (X)/binary). 35 36-define(byte(X), << ?BYTE(X) >> ). 37-define(uint16(X), << ?UINT16(X) >> ). 38-define(uint24(X), << ?UINT24(X) >> ). 39-define(uint32(X), << ?UINT32(X) >> ). 40-define(uint64(X), << ?UINT64(X) >> ). 41 42-define(MANY, 1000). 43-define(SOME, 50). 44-define(BASE_TIMEOUT_SECONDS, 5). 45-define(SOME_SCALE, 2). 46-define(MANY_SCALE, 3). 47 48%%-------------------------------------------------------------------- 49%% Common Test interface functions ----------------------------------- 50%%-------------------------------------------------------------------- 51all() -> 52 [ 53 {group, 'tlsv1.3'}, 54 {group, 'tlsv1.2'}, 55 {group, 'tlsv1.1'}, 56 {group, 'tlsv1'}, 57 {group, 'sslv3'}, 58 {group, 'dtlsv1.2'}, 59 {group, 'dtlsv1'} 60 ]. 61 62groups() -> 63 [{'tlsv1.3', [], socket_packet_tests() ++ protocol_packet_tests()}, 64 {'tlsv1.2', [], socket_packet_tests() ++ protocol_packet_tests()}, 65 {'tlsv1.1', [], socket_packet_tests() ++ protocol_packet_tests()}, 66 {'tlsv1', [], socket_packet_tests() ++ protocol_packet_tests()}, 67 {'sslv3', [], socket_packet_tests() ++ protocol_packet_tests()}, 68 %% We will not support any packet types if the transport is 69 %% not reliable. We might support it for DTLS over SCTP in the future 70 {'dtlsv1.2', [], [reject_packet_opt]}, 71 {'dtlsv1', [], [reject_packet_opt]} 72 ]. 73 74socket_packet_tests() -> 75 socket_active_packet_tests() ++ socket_active_once_packet_tests() ++ 76 socket_passive_packet_tests() ++ [packet_send_to_large, packet_tpkt_decode, packet_tpkt_decode_list]. 77 78protocol_packet_tests() -> 79 protocol_active_packet_tests() ++ protocol_active_once_packet_tests() ++ protocol_passive_packet_tests() ++ 80 [packet_cdr_decode, packet_cdr_decode_list, 81 packet_http_decode, packet_http_decode_list, 82 packet_http_bin_decode_multi, 83 packet_line_decode, packet_line_decode_list, 84 packet_asn1_decode, packet_asn1_decode_list, 85 packet_sunrm_decode, packet_sunrm_decode_list]. 86 87socket_passive_packet_tests() -> 88 [packet_raw_passive_many_small, 89 packet_0_passive_many_small, 90 packet_1_passive_many_small, 91 packet_2_passive_many_small, 92 packet_4_passive_many_small, 93 packet_raw_passive_some_big, 94 packet_0_passive_some_big, 95 packet_1_passive_some_big, 96 packet_2_passive_some_big, 97 packet_4_passive_some_big, 98 packet_wait_passive, 99 packet_size_passive, 100 %% inet header option should be deprecated! 101 header_decode_one_byte_passive, 102 header_decode_two_bytes_passive, 103 header_decode_two_bytes_two_sent_passive, 104 header_decode_two_bytes_one_sent_passive 105 ]. 106 107protocol_passive_packet_tests() -> 108 [packet_httph_passive, 109 packet_httph_bin_passive, 110 packet_http_error_passive, 111 packet_baddata_passive 112 ]. 113 114socket_active_once_packet_tests() -> 115 [packet_raw_active_once_many_small, 116 packet_0_active_once_many_small, 117 packet_1_active_once_many_small, 118 packet_2_active_once_many_small, 119 packet_4_active_once_many_small, 120 packet_raw_active_once_some_big, 121 packet_0_active_once_some_big, 122 packet_1_active_once_some_big, 123 packet_2_active_once_some_big, 124 packet_4_active_once_some_big 125 ]. 126 127protocol_active_once_packet_tests() -> 128 [ 129 packet_httph_active_once, 130 packet_httph_bin_active_once 131 ]. 132 133socket_active_packet_tests() -> 134 [packet_raw_active_many_small, 135 packet_0_active_many_small, 136 packet_1_active_many_small, 137 packet_2_active_many_small, 138 packet_4_active_many_small, 139 packet_raw_active_some_big, 140 packet_0_active_some_big, 141 packet_1_active_some_big, 142 packet_2_active_some_big, 143 packet_4_active_some_big, 144 packet_wait_active, 145 packet_size_active, 146 packet_switch, 147 %% inet header option should be deprecated! 148 header_decode_one_byte_active, 149 header_decode_two_bytes_active, 150 header_decode_two_bytes_two_sent_active, 151 header_decode_two_bytes_one_sent_active 152 ]. 153 154 155protocol_active_packet_tests() -> 156 [packet_httph_active, 157 packet_httph_bin_active, 158 packet_baddata_active 159 ]. 160 161init_per_suite(Config) -> 162 catch crypto:stop(), 163 try crypto:start() of 164 ok -> 165 ssl_test_lib:clean_start(), 166 {ok, _} = make_certs:all(proplists:get_value(data_dir, Config), 167 proplists:get_value(priv_dir, Config)), 168 ssl_test_lib:cert_options(Config) 169 catch _:_ -> 170 {skip, "Crypto did not start"} 171 end. 172 173end_per_suite(_Config) -> 174 ssl:stop(), 175 application:stop(crypto). 176 177init_per_group(GroupName, Config) -> 178 case ssl_test_lib:is_tls_version(GroupName) of 179 true -> 180 case ssl_test_lib:sufficient_crypto_support(GroupName) of 181 true -> 182 ssl_test_lib:init_tls_version(GroupName, Config); 183 false -> 184 {skip, "Missing crypto support"} 185 end; 186 _ -> 187 ssl:stop(), 188 ssl:start(), 189 Config 190 end. 191 192 193end_per_group(GroupName, Config) -> 194 case ssl_test_lib:is_tls_version(GroupName) of 195 true -> 196 ssl_test_lib:clean_tls_version(Config); 197 false -> 198 Config 199 end. 200 201init_per_testcase(_TestCase, Config) -> 202 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS}), 203 Config. 204 205 206end_per_testcase(_TestCase, Config) -> 207 Config. 208 209%%-------------------------------------------------------------------- 210%% Test Cases -------------------------------------------------------- 211%%-------------------------------------------------------------------- 212 213packet_raw_passive_many_small() -> 214 [{doc,"Test packet option {packet, raw} in passive mode."}]. 215 216packet_raw_passive_many_small(Config) when is_list(Config) -> 217 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?MANY_SCALE}), 218 Data = "Packet option is {packet, raw}", 219 packet(Config, Data, send, passive_raw, ?MANY, raw, false). 220 221%%-------------------------------------------------------------------- 222 223packet_raw_passive_some_big() -> 224 [{doc,"Test packet option {packet, raw} in passive mode."}]. 225 226packet_raw_passive_some_big(Config) when is_list(Config) -> 227 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?SOME_SCALE}), 228 Data = lists:append(lists:duplicate(100, "1234567890")), 229 packet(Config, Data, send, passive_raw, ?SOME, raw, false). 230%%-------------------------------------------------------------------- 231packet_0_passive_many_small() -> 232 [{doc,"Test packet option {packet, 0} in passive mode."}]. 233 234packet_0_passive_many_small(Config) when is_list(Config) -> 235 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?MANY_SCALE}), 236 Data = "Packet option is {packet, 0}, equivalent to packet raw.", 237 packet(Config, Data, send, passive_raw, ?MANY, 0, false). 238 239%%-------------------------------------------------------------------- 240packet_0_passive_some_big() -> 241 [{doc,"Test packet option {packet, 0} in passive mode."}]. 242 243packet_0_passive_some_big(Config) when is_list(Config) -> 244 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?SOME_SCALE}), 245 Data = lists:append(lists:duplicate(100, "1234567890")), 246 packet(Config, Data, send, passive_raw, ?SOME, 0, false). 247 248%%-------------------------------------------------------------------- 249packet_1_passive_many_small() -> 250 [{doc,"Test packet option {packet, 1} in passive mode."}]. 251 252packet_1_passive_many_small(Config) when is_list(Config) -> 253 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?MANY_SCALE}), 254 Data = "Packet option is {packet, 1}", 255 packet(Config, Data, send, passive_recv_packet, ?MANY, 1, false). 256 257%%-------------------------------------------------------------------- 258packet_1_passive_some_big() -> 259 [{doc,"Test packet option {packet, 1} in passive mode."}]. 260 261packet_1_passive_some_big(Config) when is_list(Config) -> 262 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?SOME_SCALE}), 263 Data = lists:append(lists:duplicate(255, "1")), 264 packet(Config, Data, send, passive_recv_packet, ?SOME, 1, false). 265 266%%-------------------------------------------------------------------- 267packet_2_passive_many_small() -> 268 [{doc,"Test packet option {packet, 2} in passive mode"}]. 269 270packet_2_passive_many_small(Config) when is_list(Config) -> 271 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?MANY_SCALE}), 272 Data = "Packet option is {packet, 2}", 273 packet(Config, Data, send, passive_recv_packet, ?MANY, 2, false). 274 275%%-------------------------------------------------------------------- 276packet_2_passive_some_big() -> 277 [{doc,"Test packet option {packet, 2} in passive mode"}]. 278 279packet_2_passive_some_big(Config) when is_list(Config) -> 280 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?SOME_SCALE}), 281 Data = lists:append(lists:duplicate(100, "1234567890")), 282 packet(Config, Data, send, passive_recv_packet, ?SOME, 2, false). 283 284%%-------------------------------------------------------------------- 285packet_4_passive_many_small() -> 286 [{doc,"Test packet option {packet, 4} in passive mode"}]. 287 288packet_4_passive_many_small(Config) when is_list(Config) -> 289 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?MANY_SCALE}), 290 Data = "Packet option is {packet, 4}", 291 packet(Config, Data, send, passive_recv_packet, ?MANY, 4, false). 292 293%%-------------------------------------------------------------------- 294packet_4_passive_some_big() -> 295 [{doc,"Test packet option {packet, 4} in passive mode"}]. 296 297packet_4_passive_some_big(Config) when is_list(Config) -> 298 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?SOME_SCALE}), 299 Data = lists:append(lists:duplicate(100, "1234567890")), 300 packet(Config, Data, send, passive_recv_packet, ?SOME, 4, false). 301 302%%-------------------------------------------------------------------- 303packet_raw_active_once_many_small() -> 304 [{doc,"Test packet option {packet, raw} in active once mode."}]. 305 306packet_raw_active_once_many_small(Config) when is_list(Config) -> 307 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?MANY_SCALE}), 308 Data = "Packet option is {packet, raw}", 309 packet(Config, Data, send_raw, active_once_raw, ?MANY, raw, once). 310 311%%-------------------------------------------------------------------- 312packet_raw_active_once_some_big() -> 313 [{doc,"Test packet option {packet, raw} in active once mode."}]. 314 315packet_raw_active_once_some_big(Config) when is_list(Config) -> 316 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?SOME_SCALE}), 317 Data = lists:append(lists:duplicate(100, "1234567890")), 318 packet(Config, Data, send_raw, active_once_raw, ?SOME, raw, once). 319 320%%-------------------------------------------------------------------- 321packet_0_active_once_many_small() -> 322 [{doc,"Test packet option {packet, 0} in active once mode."}]. 323 324packet_0_active_once_many_small(Config) when is_list(Config) -> 325 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?MANY_SCALE}), 326 Data = "Packet option is {packet, 0}", 327 packet(Config, Data, send_raw, active_once_raw, ?MANY, 0, once). 328 329%%-------------------------------------------------------------------- 330packet_0_active_once_some_big() -> 331 [{doc,"Test packet option {packet, 0} in active once mode."}]. 332 333packet_0_active_once_some_big(Config) when is_list(Config) -> 334 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?SOME_SCALE}), 335 Data = lists:append(lists:duplicate(100, "1234567890")), 336 packet(Config, Data, send_raw, active_once_raw, ?SOME, 0, once). 337 338%%-------------------------------------------------------------------- 339packet_1_active_once_many_small() -> 340 [{doc,"Test packet option {packet, 1} in active once mode."}]. 341 342packet_1_active_once_many_small(Config) when is_list(Config) -> 343 Data = "Packet option is {packet, 1}", 344 packet(Config, Data, send, active_once_packet, ?MANY, 1, once). 345 346%%-------------------------------------------------------------------- 347packet_1_active_once_some_big() -> 348 [{doc,"Test packet option {packet, 1} in active once mode."}]. 349 350packet_1_active_once_some_big(Config) when is_list(Config) -> 351 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?SOME_SCALE}), 352 Data = lists:append(lists:duplicate(255, "1")), 353 packet(Config, Data, send, active_once_packet, ?SOME, 1, once). 354 355 356%%-------------------------------------------------------------------- 357packet_2_active_once_many_small() -> 358 [{doc,"Test packet option {packet, 2} in active once mode"}]. 359 360packet_2_active_once_many_small(Config) when is_list(Config) -> 361 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?MANY_SCALE}), 362 Data = "Packet option is {packet, 2}", 363 packet(Config, Data, send, active_once_packet, ?MANY, 2, once). 364 365%%-------------------------------------------------------------------- 366packet_2_active_once_some_big() -> 367 [{doc,"Test packet option {packet, 2} in active once mode"}]. 368 369packet_2_active_once_some_big(Config) when is_list(Config) -> 370 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?SOME_SCALE}), 371 Data = lists:append(lists:duplicate(100, "1234567890")), 372 packet(Config, Data, send, active_once_raw, ?SOME, 2, once). 373 374%%-------------------------------------------------------------------- 375packet_4_active_once_many_small() -> 376 [{doc,"Test packet option {packet, 4} in active once mode"}]. 377 378packet_4_active_once_many_small(Config) when is_list(Config) -> 379 Data = "Packet option is {packet, 4}", 380 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?MANY_SCALE}), 381 packet(Config, Data, send, active_once_packet, ?MANY, 4, once). 382 383%%-------------------------------------------------------------------- 384packet_4_active_once_some_big() -> 385 [{doc,"Test packet option {packet, 4} in active once mode"}]. 386 387packet_4_active_once_some_big(Config) when is_list(Config) -> 388 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?SOME_SCALE}), 389 Data = lists:append(lists:duplicate(100, "1234567890")), 390 packet(Config, Data, send, active_once_packet, ?SOME, 4, once). 391 392%%-------------------------------------------------------------------- 393packet_raw_active_many_small() -> 394 [{doc,"Test packet option {packet, raw} in active mode."}]. 395 396packet_raw_active_many_small(Config) when is_list(Config) -> 397 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?MANY_SCALE}), 398 Data = "Packet option is {packet, raw}", 399 packet(Config, Data, send_raw, active_raw, ?MANY, raw, true). 400 401%%-------------------------------------------------------------------- 402packet_raw_active_some_big() -> 403 [{doc,"Test packet option {packet, raw} in active mode."}]. 404 405packet_raw_active_some_big(Config) when is_list(Config) -> 406 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?SOME_SCALE}), 407 Data = lists:append(lists:duplicate(100, "1234567890")), 408 packet(Config, Data, send_raw, active_raw, ?SOME, raw, true). 409 410%%-------------------------------------------------------------------- 411packet_0_active_many_small() -> 412 [{doc,"Test packet option {packet, 0} in active mode."}]. 413 414packet_0_active_many_small(Config) when is_list(Config) -> 415 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?MANY_SCALE}), 416 Data = "Packet option is {packet, 0}", 417 packet(Config, Data, send_raw, active_raw, ?MANY, 0, true). 418 419%%-------------------------------------------------------------------- 420packet_0_active_some_big() -> 421 [{doc,"Test packet option {packet, 0} in active mode."}]. 422 423packet_0_active_some_big(Config) when is_list(Config) -> 424 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?SOME_SCALE}), 425 Data = lists:append(lists:duplicate(100, "1234567890")), 426 packet(Config, Data, send, active_raw, ?SOME, 0, true). 427 428%%-------------------------------------------------------------------- 429packet_1_active_many_small() -> 430 [{doc,"Test packet option {packet, 1} in active mode."}]. 431 432packet_1_active_many_small(Config) when is_list(Config) -> 433 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?MANY_SCALE}), 434 Data = "Packet option is {packet, 1}", 435 packet(Config, Data, send, active_packet, ?MANY, 1, true). 436 437%%-------------------------------------------------------------------- 438packet_1_active_some_big() -> 439 [{doc,"Test packet option {packet, 1} in active mode."}]. 440 441packet_1_active_some_big(Config) when is_list(Config) -> 442 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?SOME_SCALE}), 443 Data = lists:append(lists:duplicate(255, "1")), 444 packet(Config, Data, send, active_packet, ?SOME, 1, true). 445 446%%-------------------------------------------------------------------- 447packet_2_active_many_small() -> 448 [{doc,"Test packet option {packet, 2} in active mode"}]. 449 450packet_2_active_many_small(Config) when is_list(Config) -> 451 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?MANY_SCALE}), 452 Data = "Packet option is {packet, 2}", 453 packet(Config, Data, send, active_packet, ?MANY, 2, true). 454 455%%-------------------------------------------------------------------- 456packet_2_active_some_big() -> 457 [{doc,"Test packet option {packet, 2} in active mode"}]. 458 459packet_2_active_some_big(Config) when is_list(Config) -> 460 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?SOME_SCALE}), 461 Data = lists:append(lists:duplicate(100, "1234567890")), 462 packet(Config, Data, send, active_packet, ?SOME, 2, true). 463 464%%-------------------------------------------------------------------- 465packet_4_active_many_small() -> 466 [{doc,"Test packet option {packet, 4} in active mode"}]. 467 468packet_4_active_many_small(Config) when is_list(Config) -> 469 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?MANY_SCALE}), 470 Data = "Packet option is {packet, 4}", 471 packet(Config, Data, send, active_packet, ?MANY, 4, true). 472 473%%-------------------------------------------------------------------- 474packet_4_active_some_big() -> 475 [{doc,"Test packet option {packet, 4} in active mode"}]. 476 477packet_4_active_some_big(Config) when is_list(Config) -> 478 ct:timetrap({seconds, ?BASE_TIMEOUT_SECONDS * ?SOME_SCALE}), 479 Data = lists:append(lists:duplicate(100, "1234567890")), 480 packet(Config, Data, send, active_packet, ?SOME, 4, true). 481 482%%-------------------------------------------------------------------- 483packet_send_to_large() -> 484 [{doc,"Test setting the packet option {packet, 2} on the send side"}]. 485 486packet_send_to_large(Config) when is_list(Config) -> 487 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 488 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 489 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 490 491 Data = lists:append(lists:duplicate(30, "1234567890")), 492 493 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 494 {from, self()}, 495 {mfa, {?MODULE, send, [Data, 1]}}, 496 {options, [{packet, 1}| ServerOpts]}]), 497 Port = ssl_test_lib:inet_port(Server), 498 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 499 {host, Hostname}, 500 {from, self()}, 501 {mfa, {?MODULE, active_packet, [Data, 1]}}, 502 {options, [{active, true} | ClientOpts]}]), 503 504 ssl_test_lib:check_result(Server, {error, {badarg, 505 {packet_to_large, 300, 255}}}), 506 507 ssl_test_lib:close(Server), 508 ssl_test_lib:close(Client). 509 510%%-------------------------------------------------------------------- 511packet_wait_active() -> 512 [{doc,"Test waiting when complete packages have not arrived"}]. 513 514packet_wait_active(Config) when is_list(Config) -> 515 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 516 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 517 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 518 519 Data = list_to_binary(lists:duplicate(100, "1234567890")), 520 521 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 522 {from, self()}, 523 {mfa, {?MODULE, send_incomplete, 524 [Data, ?SOME]}}, 525 {options, ServerOpts}]), 526 Port = ssl_test_lib:inet_port(Server), 527 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 528 {host, Hostname}, 529 {from, self()}, 530 {mfa, 531 {?MODULE, active_packet, 532 [binary_to_list(Data), ?SOME]}}, 533 {options, [{active, true}, 534 {packet, 4} | 535 ClientOpts]}]), 536 537 ssl_test_lib:check_result(Client, ok), 538 539 ssl_test_lib:close(Server), 540 ssl_test_lib:close(Client). 541 542 543%%-------------------------------------------------------------------- 544packet_wait_passive() -> 545 [{doc,"Test waiting when complete packages have not arrived"}]. 546 547packet_wait_passive(Config) when is_list(Config) -> 548 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 549 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 550 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 551 552 Data = list_to_binary(lists:duplicate(100, "1234567890")), 553 554 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 555 {from, self()}, 556 {mfa, {?MODULE, send_incomplete, 557 [Data, ?SOME]}}, 558 {options, ServerOpts}]), 559 Port = ssl_test_lib:inet_port(Server), 560 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 561 {host, Hostname}, 562 {from, self()}, 563 {mfa, {?MODULE, passive_recv_packet, 564 [binary_to_list(Data), ?SOME]}}, 565 {options, [{active, false}, 566 {packet, 4} | 567 ClientOpts]}]), 568 569 ssl_test_lib:check_result(Client, ok), 570 571 ssl_test_lib:close(Server), 572 ssl_test_lib:close(Client). 573%%-------------------------------------------------------------------- 574packet_baddata_active() -> 575 [{doc,"Test that if a bad packet arrives error msg is sent and socket is closed"}]. 576 577packet_baddata_active(Config) when is_list(Config) -> 578 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 579 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 580 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 581 582 Data = list_to_binary(lists:duplicate(100, "1234567890")), 583 584 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 585 {from, self()}, 586 {mfa, {?MODULE, send_incomplete ,[Data, 1]}}, 587 {options, ServerOpts}]), 588 Port = ssl_test_lib:inet_port(Server), 589 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 590 {host, Hostname}, 591 {from, self()}, 592 {mfa, {?MODULE, active_packet, [Data, 1]}}, 593 {options, [{active, true}, 594 {packet, cdr} | 595 ClientOpts]}]), 596 receive 597 {Client, {ssl_error, _, {invalid_packet, _}}} -> 598 ok; 599 Unexpected -> 600 ct:fail({unexpected, Unexpected}) 601 end, 602 603 604 ssl_test_lib:close(Server), 605 ssl_test_lib:close(Client). 606%%-------------------------------------------------------------------- 607packet_baddata_passive() -> 608 [{doc,"Test that if a bad packet arrives error msg is sent and socket is closed"}]. 609 610packet_baddata_passive(Config) when is_list(Config) -> 611 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 612 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 613 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 614 615 Data = list_to_binary(lists:duplicate(100, "1234567890")), 616 617 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 618 {from, self()}, 619 {mfa, {?MODULE, send_incomplete ,[Data, 1]}}, 620 {options, ServerOpts}]), 621 Port = ssl_test_lib:inet_port(Server), 622 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 623 {host, Hostname}, 624 {from, self()}, 625 {mfa, {?MODULE, passive_recv_packet, 626 [Data, 1]}}, 627 {options, [{active, false}, 628 {packet, cdr} | 629 ClientOpts]}]), 630 631 receive 632 {Client, {error, {invalid_packet, _}}} -> 633 ok; 634 Unexpected -> 635 ct:fail({unexpected, Unexpected}) 636 end, 637 638 ssl_test_lib:close(Server), 639 ssl_test_lib:close(Client). 640%%-------------------------------------------------------------------- 641 642packet_size_active() -> 643 [{doc,"Test that if a packet of size larger than 644 packet_size arrives error msg is sent and socket is closed"}]. 645 646packet_size_active(Config) when is_list(Config) -> 647 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 648 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 649 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 650 651 Data = list_to_binary(lists:duplicate(100, "1234567890")), 652 653 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 654 {from, self()}, 655 {mfa, {?MODULE, send_incomplete ,[Data, 1]}}, 656 {options, ServerOpts}]), 657 Port = ssl_test_lib:inet_port(Server), 658 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 659 {host, Hostname}, 660 {from, self()}, 661 {mfa, {?MODULE, active_packet, [Data, 1]}}, 662 {options, [{active, true}, 663 {packet, 4}, {packet_size, 10} | 664 ClientOpts]}]), 665 receive 666 {Client, {ssl_error, _, {invalid_packet, _}}}-> 667 ok; 668 Unexpected -> 669 ct:fail({unexpected, Unexpected}) 670 end, 671 672 ssl_test_lib:close(Server), 673 ssl_test_lib:close(Client). 674%%-------------------------------------------------------------------- 675 676packet_size_passive() -> 677 [{doc, "Test that if a packet of size larger 678 than packet_size arrives error msg is sent and socket is closed"}]. 679 680packet_size_passive(Config) when is_list(Config) -> 681 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 682 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 683 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 684 685 Data = list_to_binary(lists:duplicate(100, "1234567890")), 686 687 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 688 {from, self()}, 689 {mfa, {?MODULE, send_incomplete ,[Data, 1]}}, 690 {options, ServerOpts}]), 691 Port = ssl_test_lib:inet_port(Server), 692 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 693 {host, Hostname}, 694 {from, self()}, 695 {mfa, {?MODULE, passive_recv_packet, 696 [Data, 1]}}, 697 {options, [{active, false}, 698 {packet, 4}, {packet_size, 30} | 699 ClientOpts]}]), 700 receive 701 {Client, {error, {invalid_packet, _}}} -> 702 ok; 703 Unexpected -> 704 ct:fail({unexpected, Unexpected}) 705 end, 706 707 ssl_test_lib:close(Server), 708 ssl_test_lib:close(Client). 709 710 711%%-------------------------------------------------------------------- 712packet_switch() -> 713 [{doc,"Test packet option {packet, 2} followd by {packet, 4}"}]. 714 715packet_switch(Config) when is_list(Config) -> 716 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 717 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 718 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 719 720 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 721 {from, self()}, 722 {mfa, {?MODULE, send_switch_packet ,["Hello World", 4]}}, 723 {options, [{nodelay, true},{packet, 2} | ServerOpts]}]), 724 Port = ssl_test_lib:inet_port(Server), 725 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 726 {host, Hostname}, 727 {from, self()}, 728 {mfa, {?MODULE, recv_switch_packet, ["Hello World", 4]}}, 729 {options, [{nodelay, true}, {packet, 2} | 730 ClientOpts]}]), 731 732 ssl_test_lib:check_result(Client, ok, Server, ok), 733 734 ssl_test_lib:close(Server), 735 ssl_test_lib:close(Client). 736 737 738%%-------------------------------------------------------------------- 739packet_cdr_decode() -> 740 [{doc,"Test setting the packet option {packet, cdr}, {mode, binary}"}]. 741packet_cdr_decode(Config) when is_list(Config) -> 742 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 743 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 744 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 745 746 %% A valid cdr packet 747 Data = <<71,73,79,80,1,2,2,1,0,0,0,41,0,0,0,0,0,0,0,0,0,0,0,1,78, 748 69,79,0,0,0,0,2,0,10,0,0,0,0,0,0,0,0,0,18,0,0,0,0,0,0,0,4,49>>, 749 750 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 751 {from, self()}, 752 {mfa, {?MODULE, server_packet_decode, 753 [Data]}}, 754 {options, [{active, true}, binary, 755 {packet, cdr}|ServerOpts]}]), 756 757 Port = ssl_test_lib:inet_port(Server), 758 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 759 {host, Hostname}, 760 {from, self()}, 761 {mfa, {?MODULE, client_packet_decode, 762 [Data]}}, 763 {options, [{active, true}, {packet, cdr}, 764 binary | ClientOpts]}]), 765 766 ssl_test_lib:check_result(Server, ok, Client, ok), 767 768 ssl_test_lib:close(Server), 769 ssl_test_lib:close(Client). 770 771%%-------------------------------------------------------------------- 772packet_cdr_decode_list() -> 773 [{doc,"Test setting the packet option {packet, cdr} {mode, list}"}]. 774packet_cdr_decode_list(Config) when is_list(Config) -> 775 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 776 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 777 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 778 779 %% A valid cdr packet 780 Data = [71,73,79,80,1,2,2,1,0,0,0,41,0,0,0,0,0,0,0,0,0,0,0,1,78, 781 69,79,0,0,0,0,2,0,10,0,0,0,0,0,0,0,0,0,18,0,0,0,0,0,0,0,4,49], 782 783 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 784 {from, self()}, 785 {mfa, {?MODULE, server_packet_decode, 786 [Data]}}, 787 {options, [{active, true}, list, 788 {packet, cdr}|ServerOpts]}]), 789 790 Port = ssl_test_lib:inet_port(Server), 791 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 792 {host, Hostname}, 793 {from, self()}, 794 {mfa, {?MODULE, client_packet_decode, 795 [Data]}}, 796 {options, [{active, true}, {packet, cdr}, 797 list | ClientOpts]}]), 798 799 ssl_test_lib:check_result(Server, ok, Client, ok), 800 801 ssl_test_lib:close(Server), 802 ssl_test_lib:close(Client). 803 804%%-------------------------------------------------------------------- 805packet_http_decode() -> 806 [{doc, "Test setting the packet option {packet, http} {mode, binary} " 807 "(Body will be binary http strings are lists)"}]. 808 809packet_http_decode(Config) when is_list(Config) -> 810 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 811 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 812 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 813 814 Request = "GET / HTTP/1.1\r\n" 815 "host: www.example.com\r\n" 816 "user-agent: HttpTester\r\n" 817 "\r\n", 818 Response = "HTTP/1.1 200 OK\r\n" 819 "\r\n" 820 "Hello!", 821 822 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 823 {from, self()}, 824 {mfa, {?MODULE, server_http_decode, 825 [Response]}}, 826 {options, [{active, true},binary, 827 {packet, http} | ServerOpts]}]), 828 829 Port = ssl_test_lib:inet_port(Server), 830 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 831 {host, Hostname}, 832 {from, self()}, 833 {mfa, {?MODULE, client_http_decode, 834 [Request]}}, 835 {options, [{active, true}, binary, 836 {packet, http} | 837 ClientOpts]}]), 838 839 ssl_test_lib:check_result(Server, ok, Client, ok), 840 841 ssl_test_lib:close(Server), 842 ssl_test_lib:close(Client). 843 844 845server_http_decode(Socket, HttpResponse) -> 846 assert_packet_opt(Socket, http), 847 receive 848 {ssl, Socket, {http_request, 'GET', _, {1,1}}} -> ok; 849 Other1 -> exit({?LINE, Other1}) 850 end, 851 assert_packet_opt(Socket, http), 852 receive 853 {ssl, Socket, {http_header, _, 'Host', _, "www.example.com"}} -> ok; 854 Other2 -> exit({?LINE, Other2}) 855 end, 856 assert_packet_opt(Socket, http), 857 receive 858 {ssl, Socket, {http_header, _, 'User-Agent', _, "HttpTester"}} -> ok; 859 Other3 -> exit({?LINE, Other3}) 860 end, 861 assert_packet_opt(Socket, http), 862 receive 863 {ssl, Socket, http_eoh} -> ok; 864 Other4 -> exit({?LINE, Other4}) 865 end, 866 assert_packet_opt(Socket, http), 867 spawn(fun() -> ssl:send(Socket, HttpResponse) end), 868 ok. 869 870client_http_decode(Socket, HttpRequest) -> 871 spawn(fun() -> ssl:send(Socket, HttpRequest) end), 872 receive 873 {ssl, Socket, {http_response, {1,1}, 200, "OK"}} -> ok; 874 Other1 -> exit({?LINE, Other1}) 875 end, 876 receive 877 {ssl, Socket, http_eoh} -> ok; 878 Other2 -> exit({?LINE, Other2}) 879 end, 880 ok = ssl:setopts(Socket, [{packet, 0}]), 881 receive 882 {ssl, Socket, <<"Hello!">>} -> ok; 883 Other3 -> exit({?LINE, Other3}) 884 end, 885 ok. 886 887%%-------------------------------------------------------------------- 888packet_http_decode_list() -> 889 [{doc, "Test setting the packet option {packet, http}, {mode, list}" 890 "(Body will be list too)"}]. 891packet_http_decode_list(Config) when is_list(Config) -> 892 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 893 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 894 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 895 896 Request = "GET / HTTP/1.1\r\n" 897 "host: www.example.com\r\n" 898 "user-agent: HttpTester\r\n" 899 "\r\n", 900 Response = "HTTP/1.1 200 OK\r\n" 901 "\r\n" 902 "Hello!", 903 904 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 905 {from, self()}, 906 {mfa, {?MODULE, server_http_decode, 907 [Response]}}, 908 {options, [{active, true}, binary, 909 {packet, http} | 910 ServerOpts]}]), 911 912 Port = ssl_test_lib:inet_port(Server), 913 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 914 {host, Hostname}, 915 {from, self()}, 916 {mfa, {?MODULE, client_http_decode_list, 917 [Request]}}, 918 {options, [{active, true}, list, 919 {packet, http} | 920 ClientOpts]}]), 921 922 ssl_test_lib:check_result(Server, ok, Client, ok), 923 924 ssl_test_lib:close(Server), 925 ssl_test_lib:close(Client). 926 927 928client_http_decode_list(Socket, HttpRequest) -> 929 spawn(fun() -> ssl:send(Socket, HttpRequest) end), 930 receive 931 {ssl, Socket, {http_response, {1,1}, 200, "OK"}} -> ok; 932 Other1 -> exit({?LINE, Other1}) 933 end, 934 receive 935 {ssl, Socket, http_eoh} -> ok; 936 Other2 -> exit({?LINE, Other2}) 937 end, 938 ok = ssl:setopts(Socket, [{packet, 0}]), 939 receive 940 {ssl, Socket, "Hello!"} -> ok; 941 Other3 -> exit({?LINE, Other3}) 942 end, 943 ok. 944 945%%-------------------------------------------------------------------- 946packet_http_bin_decode_multi() -> 947 [{doc,"Test setting the packet option {packet, http_bin} with multiple requests"}]. 948packet_http_bin_decode_multi(Config) when is_list(Config) -> 949 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 950 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 951 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 952 953 Request = <<"GET / HTTP/1.1\r\n" 954 "host: www.example.com\r\n" 955 "user-agent: HttpTester\r\n" 956 "\r\n">>, 957 Response = <<"HTTP/1.1 200 OK\r\n" 958 "\r\n" 959 "Hello!">>, 960 NumMsgs = 3, 961 962 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 963 {from, self()}, 964 {mfa, {?MODULE, server_http_bin_decode, 965 [Response, NumMsgs]}}, 966 {options, [{active, true}, binary, 967 {packet, http_bin} | 968 ServerOpts]}]), 969 970 Port = ssl_test_lib:inet_port(Server), 971 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 972 {host, Hostname}, 973 {from, self()}, 974 {mfa, {?MODULE, client_http_bin_decode, 975 [Request, NumMsgs]}}, 976 {options, [{active, true}, binary, 977 {packet, http_bin} | 978 ClientOpts]}]), 979 980 ssl_test_lib:check_result(Server, ok, Client, ok), 981 982 ssl_test_lib:close(Server), 983 ssl_test_lib:close(Client). 984 985 986server_http_bin_decode(Socket, HttpResponse, Count) when Count > 0 -> 987 assert_packet_opt(Socket, http_bin), 988 receive 989 {ssl, Socket, {http_request, 'GET', _, {1,1}}} -> ok; 990 Other1 -> exit({?LINE, Other1}) 991 end, 992 assert_packet_opt(Socket, http_bin), 993 receive 994 {ssl, Socket, {http_header, _, 'Host', _, <<"www.example.com">>}} -> ok; 995 Other2 -> exit({?LINE, Other2}) 996 end, 997 assert_packet_opt(Socket, http_bin), 998 receive 999 {ssl, Socket, {http_header, _, 'User-Agent', _, <<"HttpTester">>}} -> ok; 1000 Other3 -> exit({?LINE, Other3}) 1001 end, 1002 assert_packet_opt(Socket, http_bin), 1003 receive 1004 {ssl, Socket, http_eoh} -> ok; 1005 Other4 -> exit({?LINE, Other4}) 1006 end, 1007 assert_packet_opt(Socket, http_bin), 1008 spawn(fun() -> ssl:send(Socket, HttpResponse) end), 1009 server_http_bin_decode(Socket, HttpResponse, Count - 1); 1010server_http_bin_decode(_, _, _) -> 1011 ok. 1012 1013client_http_bin_decode(Socket, HttpRequest, Count) when Count > 0 -> 1014 spawn(fun() -> ssl:send(Socket, HttpRequest) end), 1015 receive 1016 {ssl, Socket, {http_response, {1,1}, 200, <<"OK">>}} -> ok; 1017 Other1 -> exit({?LINE, Other1}) 1018 end, 1019 receive 1020 {ssl, Socket, http_eoh} -> ok; 1021 Other2 -> exit({?LINE, Other2}) 1022 end, 1023 ok = ssl:setopts(Socket, [{packet, 0}]), 1024 receive 1025 {ssl, Socket, <<"Hello!">>} -> ok; 1026 Other3 -> exit({?LINE, Other3}) 1027 end, 1028 ok = ssl:setopts(Socket, [{packet, http_bin}]), 1029 client_http_bin_decode(Socket, HttpRequest, Count - 1); 1030client_http_bin_decode(_, _, _) -> 1031 ok. 1032 1033%%-------------------------------------------------------------------- 1034packet_http_error_passive() -> 1035 [{doc,"Test setting the packet option {packet, http}, {active, false}" 1036 " with a incorrect http header."}]. 1037 1038packet_http_error_passive(Config) when is_list(Config) -> 1039 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1040 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1041 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1042 1043 Request = "GET / HTTP/1.1\r\n" 1044 "host: www.example.com\r\n" 1045 "user-agent HttpTester\r\n" 1046 "\r\n", 1047 Response = "HTTP/1.1 200 OK\r\n" 1048 "\r\n" 1049 "Hello!", 1050 1051 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1052 {from, self()}, 1053 {mfa, {?MODULE, server_http_decode_error, 1054 [Response]}}, 1055 {options, [{active, false}, binary, 1056 {packet, http} | 1057 ServerOpts]}]), 1058 1059 Port = ssl_test_lib:inet_port(Server), 1060 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1061 {host, Hostname}, 1062 {from, self()}, 1063 {mfa, {?MODULE, client_http_decode_list, 1064 [Request]}}, 1065 {options, [{active, true}, list, 1066 {packet, http} | 1067 ClientOpts]}]), 1068 1069 ssl_test_lib:check_result(Server, ok, Client, ok), 1070 1071 ssl_test_lib:close(Server), 1072 ssl_test_lib:close(Client). 1073 1074 1075server_http_decode_error(Socket, HttpResponse) -> 1076 assert_packet_opt(Socket, http), 1077 1078 {ok, {http_request, 'GET', _, {1,1}}} = ssl:recv(Socket, 0), 1079 1080 assert_packet_opt(Socket, http), 1081 1082 {ok, {http_header, _, 'Host', _, "www.example.com"}} = ssl:recv(Socket, 0), 1083 assert_packet_opt(Socket, http), 1084 1085 {ok, {http_error, _}} = ssl:recv(Socket, 0), 1086 1087 assert_packet_opt(Socket, http), 1088 1089 {ok, http_eoh} = ssl:recv(Socket, 0), 1090 1091 assert_packet_opt(Socket, http), 1092 spawn(fun() -> ssl:send(Socket, HttpResponse) end), 1093 ok. 1094%%-------------------------------------------------------------------- 1095packet_httph_active() -> 1096 [{doc,"Test setting the packet option {packet, httph}"}]. 1097 1098packet_httph_active(Config) when is_list(Config) -> 1099 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1100 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1101 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1102 1103 Trailer = "Content-Encoding: gzip\r\n" 1104 "\r\n", 1105 1106 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1107 {from, self()}, 1108 {mfa, {?MODULE, server_send_trailer, 1109 [Trailer]}}, 1110 {options, [{active, true}, binary | 1111 ServerOpts]}]), 1112 1113 Port = ssl_test_lib:inet_port(Server), 1114 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1115 {host, Hostname}, 1116 {from, self()}, 1117 {mfa, {?MODULE, client_http_decode_trailer_active, 1118 []}}, 1119 {options, [{active, true}, 1120 {packet, httph}, 1121 list | 1122 ClientOpts]}]), 1123 1124 ssl_test_lib:check_result(Server, ok, Client, ok), 1125 1126 ssl_test_lib:close(Server), 1127 ssl_test_lib:close(Client). 1128 1129 1130server_send_trailer(Socket, Trailer)-> 1131 ssl:send(Socket, Trailer), 1132 ok. 1133 1134client_http_decode_trailer_active(Socket) -> 1135 receive 1136 {ssl, Socket, 1137 {http_header,36,'Content-Encoding',undefined,"gzip"}} -> 1138 ok; 1139 Other1 -> 1140 exit({?LINE, Other1}) 1141 end, 1142 receive 1143 {ssl, Socket, http_eoh} -> 1144 ok; 1145 Other2 -> 1146 exit({?LINE, Other2}) 1147 end, 1148 ok. 1149 1150%%-------------------------------------------------------------------- 1151packet_httph_bin_active() -> 1152 [{doc,"Test setting the packet option {packet, httph_bin}"}]. 1153packet_httph_bin_active(Config) when is_list(Config) -> 1154 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1155 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1156 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1157 1158 Trailer = "Content-Encoding: gzip\r\n" 1159 "\r\n", 1160 1161 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1162 {from, self()}, 1163 {mfa, {?MODULE, server_send_trailer, 1164 [Trailer]}}, 1165 {options, [{active, true}, binary | 1166 ServerOpts]}]), 1167 1168 Port = ssl_test_lib:inet_port(Server), 1169 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1170 {host, Hostname}, 1171 {from, self()}, 1172 {mfa, {?MODULE, client_http_decode_trailer_bin_active, 1173 []}}, 1174 {options, [{active, true}, 1175 {packet, httph_bin}, 1176 list | 1177 ClientOpts]}]), 1178 1179 ssl_test_lib:check_result(Server, ok, Client, ok), 1180 1181 ssl_test_lib:close(Server), 1182 ssl_test_lib:close(Client). 1183 1184client_http_decode_trailer_bin_active(Socket) -> 1185 receive 1186 {ssl, Socket, 1187 {http_header,36,'Content-Encoding',undefined, <<"gzip">>}} -> 1188 ok; 1189 Other1 -> 1190 exit({?LINE, Other1}) 1191 end, 1192 receive 1193 {ssl, Socket, http_eoh} -> 1194 ok; 1195 Other2 -> 1196 exit({?LINE, Other2}) 1197 end, 1198 ok. 1199%%-------------------------------------------------------------------- 1200packet_httph_active_once() -> 1201 [{doc,"Test setting the packet option {packet, httph}"}]. 1202 1203packet_httph_active_once(Config) when is_list(Config) -> 1204 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1205 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1206 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1207 1208 Trailer = "Content-Encoding: gzip\r\n" 1209 "\r\n", 1210 1211 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1212 {from, self()}, 1213 {mfa, {?MODULE, server_send_trailer, 1214 [Trailer]}}, 1215 {options, [{active, true}, binary | 1216 ServerOpts]}]), 1217 1218 Port = ssl_test_lib:inet_port(Server), 1219 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1220 {host, Hostname}, 1221 {from, self()}, 1222 {mfa, {?MODULE, client_http_decode_trailer_active_once, 1223 []}}, 1224 {options, [{active, false}, 1225 {packet, httph}, 1226 list | 1227 ClientOpts]}]), 1228 1229 ssl_test_lib:check_result(Server, ok, Client, ok), 1230 1231 ssl_test_lib:close(Server), 1232 ssl_test_lib:close(Client). 1233 1234 1235client_http_decode_trailer_active_once(Socket) -> 1236 ssl:setopts(Socket, [{active, once}]), 1237 receive 1238 {ssl, Socket, 1239 {http_header,36,'Content-Encoding',undefined,"gzip"}} -> 1240 ok; 1241 Other1 -> 1242 exit({?LINE, Other1}) 1243 end, 1244 ssl:setopts(Socket, [{active, once}]), 1245 receive 1246 {ssl, Socket, http_eoh} -> 1247 ok; 1248 Other2 -> 1249 exit({?LINE, Other2}) 1250 end, 1251 ok. 1252%%-------------------------------------------------------------------- 1253packet_httph_bin_active_once() -> 1254 [{doc,"Test setting the packet option {packet, httph_bin}"}]. 1255 1256packet_httph_bin_active_once(Config) when is_list(Config) -> 1257 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1258 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1259 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1260 1261 Trailer = "Content-Encoding: gzip\r\n" 1262 "\r\n", 1263 1264 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1265 {from, self()}, 1266 {mfa, {?MODULE, server_send_trailer, 1267 [Trailer]}}, 1268 {options, [{active, true}, binary | 1269 ServerOpts]}]), 1270 1271 Port = ssl_test_lib:inet_port(Server), 1272 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1273 {host, Hostname}, 1274 {from, self()}, 1275 {mfa, {?MODULE, client_http_decode_trailer_bin_active_once, 1276 []}}, 1277 {options, [{active, false}, 1278 {packet, httph_bin}, 1279 list | 1280 ClientOpts]}]), 1281 1282 ssl_test_lib:check_result(Server, ok, Client, ok), 1283 1284 ssl_test_lib:close(Server), 1285 ssl_test_lib:close(Client). 1286 1287client_http_decode_trailer_bin_active_once(Socket) -> 1288 ssl:setopts(Socket, [{active, once}]), 1289 receive 1290 {ssl, Socket, 1291 {http_header,36,'Content-Encoding',undefined, <<"gzip">>}} -> 1292 ok; 1293 Other1 -> 1294 exit({?LINE, Other1}) 1295 end, 1296 ssl:setopts(Socket, [{active, once}]), 1297 receive 1298 {ssl, Socket, http_eoh} -> 1299 ok; 1300 Other2 -> 1301 exit({?LINE, Other2}) 1302 end, 1303 ok. 1304 1305%%-------------------------------------------------------------------- 1306 1307packet_httph_passive() -> 1308 [{doc,"Test setting the packet option {packet, httph}"}]. 1309 1310packet_httph_passive(Config) when is_list(Config) -> 1311 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1312 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1313 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1314 1315 Trailer = "Content-Encoding: gzip\r\n" 1316 "\r\n", 1317 1318 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1319 {from, self()}, 1320 {mfa, {?MODULE, server_send_trailer, 1321 [Trailer]}}, 1322 {options, [{active, true}, binary | 1323 ServerOpts]}]), 1324 1325 Port = ssl_test_lib:inet_port(Server), 1326 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1327 {host, Hostname}, 1328 {from, self()}, 1329 {mfa, {?MODULE, client_http_decode_trailer_passive, 1330 []}}, 1331 {options, [{active, false}, 1332 {packet, httph}, 1333 list | 1334 ClientOpts]}]), 1335 1336 ssl_test_lib:check_result(Server, ok, Client, ok), 1337 1338 ssl_test_lib:close(Server), 1339 ssl_test_lib:close(Client). 1340 1341client_http_decode_trailer_passive(Socket) -> 1342 {ok,{http_header,36,'Content-Encoding',undefined,"gzip"}} = ssl:recv(Socket, 0), 1343 {ok, http_eoh} = ssl:recv(Socket, 0), 1344 ok. 1345 1346%%-------------------------------------------------------------------- 1347packet_httph_bin_passive() -> 1348 [{doc,"Test setting the packet option {packet, httph_bin}"}]. 1349 1350packet_httph_bin_passive(Config) when is_list(Config) -> 1351 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1352 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1353 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1354 1355 Trailer = "Content-Encoding: gzip\r\n" 1356 "\r\n", 1357 1358 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1359 {from, self()}, 1360 {mfa, {?MODULE, server_send_trailer, 1361 [Trailer]}}, 1362 {options, [{active, true}, binary | 1363 ServerOpts]}]), 1364 1365 Port = ssl_test_lib:inet_port(Server), 1366 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1367 {host, Hostname}, 1368 {from, self()}, 1369 {mfa, {?MODULE, client_http_decode_trailer_bin_passive, 1370 []}}, 1371 {options, [{active, false}, 1372 {packet, httph_bin}, 1373 list | 1374 ClientOpts]}]), 1375 1376 ssl_test_lib:check_result(Server, ok, Client, ok), 1377 1378 ssl_test_lib:close(Server), 1379 ssl_test_lib:close(Client). 1380 1381client_http_decode_trailer_bin_passive(Socket) -> 1382 {ok,{http_header,36,'Content-Encoding',undefined,<<"gzip">>}} = ssl:recv(Socket, 0), 1383 {ok, http_eoh} = ssl:recv(Socket, 0), 1384 ok. 1385 1386%%-------------------------------------------------------------------- 1387packet_line_decode() -> 1388 [{doc,"Test setting the packet option {packet, line}, {mode, binary}"}]. 1389 1390packet_line_decode(Config) when is_list(Config) -> 1391 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1392 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1393 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1394 1395 Data = list_to_binary(lists:flatten(io_lib:format("Line ends here.~n" 1396 "Now it is a new line.~n", 1397 []))), 1398 1399 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1400 {from, self()}, 1401 {mfa, {?MODULE, server_line_packet_decode, 1402 [Data]}}, 1403 {options, [{active, true}, binary, 1404 {packet, line}|ServerOpts]}]), 1405 1406 Port = ssl_test_lib:inet_port(Server), 1407 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1408 {host, Hostname}, 1409 {from, self()}, 1410 {mfa, {?MODULE, client_line_packet_decode, 1411 [Data]}}, 1412 {options, [{active, true}, 1413 {packet, line}, 1414 binary | ClientOpts]}]), 1415 1416 ssl_test_lib:check_result(Server, ok, Client, ok), 1417 1418 ssl_test_lib:close(Server), 1419 ssl_test_lib:close(Client). 1420 1421%%-------------------------------------------------------------------- 1422 1423packet_line_decode_list() -> 1424 [{doc,"Test setting the packet option {packet, line}, {mode, list}"}]. 1425 1426packet_line_decode_list(Config) when is_list(Config) -> 1427 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1428 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1429 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1430 1431 Data = lists:flatten(io_lib:format("Line ends here.~n" 1432 "Now it is a new line.~n", [])), 1433 1434 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1435 {from, self()}, 1436 {mfa, {?MODULE, 1437 server_line_packet_decode, 1438 [Data]}}, 1439 {options, [{active, true}, list, 1440 {packet, line}|ServerOpts]}]), 1441 1442 Port = ssl_test_lib:inet_port(Server), 1443 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1444 {host, Hostname}, 1445 {from, self()}, 1446 {mfa, {?MODULE, 1447 client_line_packet_decode, 1448 [Data]}}, 1449 {options, [{active, true}, 1450 {packet, line}, 1451 list | ClientOpts]}]), 1452 1453 ssl_test_lib:check_result(Server, ok, Client, ok), 1454 1455 ssl_test_lib:close(Server), 1456 ssl_test_lib:close(Client). 1457 1458 1459%%-------------------------------------------------------------------- 1460 1461packet_asn1_decode() -> 1462 [{doc,"Test setting the packet option {packet, asn1}"}]. 1463 1464packet_asn1_decode(Config) when is_list(Config) -> 1465 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1466 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1467 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1468 1469 File = proplists:get_value(certfile, ServerOpts), 1470 1471 %% A valid asn1 BER packet (DER is stricter BER) 1472 [{'Certificate', Data, _}] = ssl_test_lib:pem_to_der(File), 1473 1474 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1475 {from, self()}, 1476 {mfa, {?MODULE, server_packet_decode, 1477 [Data]}}, 1478 {options, [{active, true}, binary, 1479 {packet, asn1}|ServerOpts]}]), 1480 1481 Port = ssl_test_lib:inet_port(Server), 1482 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1483 {host, Hostname}, 1484 {from, self()}, 1485 {mfa, {?MODULE, client_packet_decode, 1486 [Data]}}, 1487 {options, [{active, true}, {packet, asn1}, 1488 binary | ClientOpts]}]), 1489 1490 ssl_test_lib:check_result(Server, ok, Client, ok), 1491 1492 ssl_test_lib:close(Server), 1493 ssl_test_lib:close(Client). 1494 1495%%-------------------------------------------------------------------- 1496packet_asn1_decode_list() -> 1497 [{doc,"Test setting the packet option {packet, asn1}"}]. 1498 1499packet_asn1_decode_list(Config) when is_list(Config) -> 1500 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1501 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1502 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1503 1504 File = proplists:get_value(certfile, ServerOpts), 1505 1506 %% A valid asn1 BER packet (DER is stricter BER) 1507 [{'Certificate', BinData, _}] = ssl_test_lib:pem_to_der(File), 1508 1509 Data = binary_to_list(BinData), 1510 1511 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1512 {from, self()}, 1513 {mfa, {?MODULE, server_packet_decode, 1514 [Data]}}, 1515 {options, [{active, true}, list, 1516 {packet, asn1}|ServerOpts]}]), 1517 1518 Port = ssl_test_lib:inet_port(Server), 1519 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1520 {host, Hostname}, 1521 {from, self()}, 1522 {mfa, {?MODULE, client_packet_decode, 1523 [Data]}}, 1524 {options, [{active, true}, {packet, asn1}, 1525 list | ClientOpts]}]), 1526 1527 ssl_test_lib:check_result(Server, ok, Client, ok), 1528 1529 ssl_test_lib:close(Server), 1530 ssl_test_lib:close(Client). 1531 1532%%-------------------------------------------------------------------- 1533packet_tpkt_decode() -> 1534 [{doc,"Test setting the packet option {packet, tpkt}"}]. 1535 1536packet_tpkt_decode(Config) when is_list(Config) -> 1537 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1538 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1539 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1540 1541 Data = list_to_binary(add_tpkt_header("TPKT data")), 1542 1543 1544 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1545 {from, self()}, 1546 {mfa, {?MODULE, server_packet_decode, 1547 [Data]}}, 1548 {options, [{active, true}, binary, 1549 {packet, tpkt}|ServerOpts]}]), 1550 1551 Port = ssl_test_lib:inet_port(Server), 1552 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1553 {host, Hostname}, 1554 {from, self()}, 1555 {mfa, {?MODULE, client_packet_decode, 1556 [Data]}}, 1557 {options, [{active, true}, {packet, tpkt}, 1558 binary | ClientOpts]}]), 1559 1560 ssl_test_lib:check_result(Server, ok, Client, ok), 1561 1562 ssl_test_lib:close(Server), 1563 ssl_test_lib:close(Client). 1564%%-------------------------------------------------------------------- 1565packet_tpkt_decode_list() -> 1566 [{doc,"Test setting the packet option {packet, tpkt}"}]. 1567 1568packet_tpkt_decode_list(Config) when is_list(Config) -> 1569 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1570 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1571 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1572 1573 Data = binary_to_list(list_to_binary(add_tpkt_header("TPKT data"))), 1574 1575 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1576 {from, self()}, 1577 {mfa, {?MODULE, server_packet_decode, 1578 [Data]}}, 1579 {options, [{active, true}, list, 1580 {packet, tpkt}|ServerOpts]}]), 1581 1582 Port = ssl_test_lib:inet_port(Server), 1583 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1584 {host, Hostname}, 1585 {from, self()}, 1586 {mfa, {?MODULE, client_packet_decode, 1587 [Data]}}, 1588 {options, [{active, true}, {packet, tpkt}, 1589 list | ClientOpts]}]), 1590 1591 ssl_test_lib:check_result(Server, ok, Client, ok), 1592 1593 ssl_test_lib:close(Server), 1594 ssl_test_lib:close(Client). 1595 1596%%-------------------------------------------------------------------- 1597 1598%% packet_fcgi_decode() -> 1599%% [{doc,"Test setting the packet option {packet, fcgi}"}]. 1600 1601%% packet_fcgi_decode(Config) when is_list(Config) -> 1602%% ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1603%% ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1604%% {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1605 1606%% Data = ... 1607 1608%% Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1609%% {from, self()}, 1610%% {mfa, {?MODULE, server_packet_decode, 1611%% [Data0, Data1]}}, 1612%% {options, [{active, true}, binary, 1613%% {packet, fcgi}|ServerOpts]}]), 1614 1615%% Port = ssl_test_lib:inet_port(Server), 1616%% Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1617%% {host, Hostname}, 1618%% {from, self()}, 1619%% {mfa, {?MODULE, client_packet_decode, 1620%% [Data0, Data1]}}, 1621%% {options, [{active, true}, {packet, fcgi}, 1622%% binary | ClientOpts]}]), 1623 1624%% ssl_test_lib:check_result(Server, ok, Client, ok), 1625 1626%% ssl_test_lib:close(Server), 1627%% ssl_test_lib:close(Client). 1628 1629 1630%%-------------------------------------------------------------------- 1631 1632packet_sunrm_decode() -> 1633 [{doc,"Test setting the packet option {packet, sunrm}"}]. 1634packet_sunrm_decode(Config) when is_list(Config) -> 1635 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1636 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1637 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1638 1639 Data = <<11:32, "Hello world">>, 1640 1641 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1642 {from, self()}, 1643 {mfa, {?MODULE, server_packet_decode, 1644 [Data]}}, 1645 {options, [{active, true}, binary, 1646 {packet, sunrm}|ServerOpts]}]), 1647 1648 Port = ssl_test_lib:inet_port(Server), 1649 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1650 {host, Hostname}, 1651 {from, self()}, 1652 {mfa, {?MODULE, client_packet_decode, 1653 [Data]}}, 1654 {options, [{active, true}, {packet, sunrm}, 1655 binary | ClientOpts]}]), 1656 1657 ssl_test_lib:check_result(Server, ok, Client, ok), 1658 1659 ssl_test_lib:close(Server), 1660 ssl_test_lib:close(Client). 1661 1662%%-------------------------------------------------------------------- 1663packet_sunrm_decode_list() -> 1664 [{doc,"Test setting the packet option {packet, sunrm}"}]. 1665 1666packet_sunrm_decode_list(Config) when is_list(Config) -> 1667 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1668 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1669 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1670 1671 Data = binary_to_list(list_to_binary([<<11:32>>, "Hello world"])), 1672 1673 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1674 {from, self()}, 1675 {mfa, {?MODULE, server_packet_decode, 1676 [Data]}}, 1677 {options, [{active, true}, list, 1678 {packet, sunrm}|ServerOpts]}]), 1679 1680 Port = ssl_test_lib:inet_port(Server), 1681 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1682 {host, Hostname}, 1683 {from, self()}, 1684 {mfa, {?MODULE, client_packet_decode, 1685 [Data]}}, 1686 {options, [{active, true}, {packet, sunrm}, 1687 list | ClientOpts]}]), 1688 1689 ssl_test_lib:check_result(Server, ok, Client, ok), 1690 1691 ssl_test_lib:close(Server), 1692 ssl_test_lib:close(Client). 1693%%-------------------------------------------------------------------- 1694 1695header_decode_one_byte_active() -> 1696 [{doc,"Test setting the packet option {header, 1}"}]. 1697 1698header_decode_one_byte_active(Config) when is_list(Config) -> 1699 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1700 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1701 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1702 1703 Data = <<11:8, "Hello world">>, 1704 1705 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1706 {from, self()}, 1707 {mfa, {?MODULE, server_header_decode_active, 1708 [Data, [11 | <<"Hello world">>]]}}, 1709 {options, [{active, true}, binary, 1710 {header,1}|ServerOpts]}]), 1711 1712 Port = ssl_test_lib:inet_port(Server), 1713 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1714 {host, Hostname}, 1715 {from, self()}, 1716 {mfa, {?MODULE, client_header_decode_active, 1717 [Data, [11 | <<"Hello world">> ]]}}, 1718 {options, [{active, true}, binary, {header, 1} 1719 | ClientOpts]}]), 1720 1721 ssl_test_lib:check_result(Server, ok, Client, ok), 1722 1723 ssl_test_lib:close(Server), 1724 ssl_test_lib:close(Client). 1725 1726%%-------------------------------------------------------------------- 1727 1728header_decode_two_bytes_active() -> 1729 [{doc,"Test setting the packet option {header, 2}"}]. 1730 1731header_decode_two_bytes_active(Config) when is_list(Config) -> 1732 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1733 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1734 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1735 1736 Data = <<11:8, "Hello world">>, 1737 1738 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1739 {from, self()}, 1740 {mfa, {?MODULE, server_header_decode_active, 1741 [Data, [11, $H | <<"ello world">> ]]}}, 1742 {options, [{active, true}, binary, 1743 {header,2}|ServerOpts]}]), 1744 1745 Port = ssl_test_lib:inet_port(Server), 1746 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1747 {host, Hostname}, 1748 {from, self()}, 1749 {mfa, {?MODULE, client_header_decode_active, 1750 [Data, [11, $H | <<"ello world">> ]]}}, 1751 {options, [{active, true}, {header, 2}, 1752 binary | ClientOpts]}]), 1753 1754 ssl_test_lib:check_result(Server, ok, Client, ok), 1755 1756 ssl_test_lib:close(Server), 1757 ssl_test_lib:close(Client). 1758 1759 1760%%-------------------------------------------------------------------- 1761 1762header_decode_two_bytes_two_sent_active() -> 1763 [{doc,"Test setting the packet option {header, 2} and sending two byte"}]. 1764 1765header_decode_two_bytes_two_sent_active(Config) when is_list(Config) -> 1766 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1767 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1768 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1769 1770 Data = <<"He">>, 1771 1772 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1773 {from, self()}, 1774 {mfa, {?MODULE, server_header_decode_active, 1775 [Data, [$H, $e | <<>>]]}}, 1776 {options, [{active, true}, binary, 1777 {header,2}|ServerOpts]}]), 1778 1779 Port = ssl_test_lib:inet_port(Server), 1780 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1781 {host, Hostname}, 1782 {from, self()}, 1783 {mfa, {?MODULE, client_header_decode_active, 1784 [Data, [$H, $e | <<>>]]}}, 1785 {options, [{active, true}, {header, 2}, 1786 binary | ClientOpts]}]), 1787 1788 ssl_test_lib:check_result(Server, ok, Client, ok), 1789 1790 ssl_test_lib:close(Server), 1791 ssl_test_lib:close(Client). 1792 1793 1794%%-------------------------------------------------------------------- 1795 1796header_decode_two_bytes_one_sent_active() -> 1797 [{doc,"Test setting the packet option {header, 2} and sending one byte"}]. 1798 1799header_decode_two_bytes_one_sent_active(Config) when is_list(Config) -> 1800 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1801 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1802 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1803 1804 Data = <<"H">>, 1805 1806 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1807 {from, self()}, 1808 {mfa, {?MODULE, server_header_decode_active, 1809 [Data, "H"]}}, 1810 {options, [{active, true}, binary, 1811 {header,2}|ServerOpts]}]), 1812 1813 Port = ssl_test_lib:inet_port(Server), 1814 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1815 {host, Hostname}, 1816 {from, self()}, 1817 {mfa, {?MODULE, client_header_decode_active, 1818 [Data, "H"]}}, 1819 {options, [{active, true}, {header, 2}, 1820 binary | ClientOpts]}]), 1821 1822 ssl_test_lib:check_result(Server, ok, Client, ok), 1823 1824 ssl_test_lib:close(Server), 1825 ssl_test_lib:close(Client). 1826 1827%%-------------------------------------------------------------------- 1828 1829header_decode_one_byte_passive() -> 1830 [{doc,"Test setting the packet option {header, 1}"}]. 1831 1832header_decode_one_byte_passive(Config) when is_list(Config) -> 1833 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1834 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1835 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1836 1837 Data = <<11:8, "Hello world">>, 1838 1839 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1840 {from, self()}, 1841 {mfa, {?MODULE, server_header_decode_passive, 1842 [Data, [11 | <<"Hello world">>]]}}, 1843 {options, [{active, false}, binary, 1844 {header,1}|ServerOpts]}]), 1845 1846 Port = ssl_test_lib:inet_port(Server), 1847 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1848 {host, Hostname}, 1849 {from, self()}, 1850 {mfa, {?MODULE, client_header_decode_passive, 1851 [Data, [11 | <<"Hello world">> ]]}}, 1852 {options, [{active, false}, binary, {header, 1} 1853 | ClientOpts]}]), 1854 1855 ssl_test_lib:check_result(Server, ok, Client, ok), 1856 1857 ssl_test_lib:close(Server), 1858 ssl_test_lib:close(Client). 1859 1860%%-------------------------------------------------------------------- 1861 1862header_decode_two_bytes_passive() -> 1863 [{doc,"Test setting the packet option {header, 2}"}]. 1864 1865header_decode_two_bytes_passive(Config) when is_list(Config) -> 1866 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1867 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1868 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1869 1870 Data = <<11:8, "Hello world">>, 1871 1872 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1873 {from, self()}, 1874 {mfa, {?MODULE, server_header_decode_passive, 1875 [Data, [11, $H | <<"ello world">> ]]}}, 1876 {options, [{active, false}, binary, 1877 {header,2}|ServerOpts]}]), 1878 1879 Port = ssl_test_lib:inet_port(Server), 1880 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1881 {host, Hostname}, 1882 {from, self()}, 1883 {mfa, {?MODULE, client_header_decode_passive, 1884 [Data, [11, $H | <<"ello world">> ]]}}, 1885 {options, [{active, false}, {header, 2}, 1886 binary | ClientOpts]}]), 1887 1888 ssl_test_lib:check_result(Server, ok, Client, ok), 1889 1890 ssl_test_lib:close(Server), 1891 ssl_test_lib:close(Client). 1892 1893 1894%%-------------------------------------------------------------------- 1895 1896header_decode_two_bytes_two_sent_passive() -> 1897 [{doc,"Test setting the packet option {header, 2} and sending two byte"}]. 1898 1899header_decode_two_bytes_two_sent_passive(Config) when is_list(Config) -> 1900 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1901 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1902 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1903 1904 Data = <<"He">>, 1905 1906 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1907 {from, self()}, 1908 {mfa, {?MODULE, server_header_decode_passive, 1909 [Data, [$H, $e | <<>>]]}}, 1910 {options, [{active, false}, binary, 1911 {header,2}|ServerOpts]}]), 1912 1913 Port = ssl_test_lib:inet_port(Server), 1914 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1915 {host, Hostname}, 1916 {from, self()}, 1917 {mfa, {?MODULE, client_header_decode_passive, 1918 [Data, [$H, $e | <<>>]]}}, 1919 {options, [{active, false}, {header, 2}, 1920 binary | ClientOpts]}]), 1921 1922 ssl_test_lib:check_result(Server, ok, Client, ok), 1923 1924 ssl_test_lib:close(Server), 1925 ssl_test_lib:close(Client). 1926 1927 1928%%-------------------------------------------------------------------- 1929 1930header_decode_two_bytes_one_sent_passive() -> 1931 [{doc,"Test setting the packet option {header, 2} and sending one byte"}]. 1932 1933header_decode_two_bytes_one_sent_passive(Config) when is_list(Config) -> 1934 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1935 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1936 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1937 1938 Data = <<"H">>, 1939 1940 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1941 {from, self()}, 1942 {mfa, {?MODULE, server_header_decode_passive, 1943 [Data, "H"]}}, 1944 {options, [{active, false}, binary, 1945 {header,2}|ServerOpts]}]), 1946 1947 Port = ssl_test_lib:inet_port(Server), 1948 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1949 {host, Hostname}, 1950 {from, self()}, 1951 {mfa, {?MODULE, client_header_decode_passive, 1952 [Data, "H"]}}, 1953 {options, [{active, false}, {header, 2}, 1954 binary | ClientOpts]}]), 1955 1956 ssl_test_lib:check_result(Server, ok, Client, ok), 1957 1958 ssl_test_lib:close(Server), 1959 ssl_test_lib:close(Client). 1960 1961%%-------------------------------------------------------------------- 1962reject_packet_opt() -> 1963 [{doc,"Test packet option is rejected for DTLS over udp"}]. 1964 1965reject_packet_opt(Config) when is_list(Config) -> 1966 1967 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1968 1969 {error,{options,{not_supported,{packet,4}}}} = 1970 ssl:listen(9999, [{packet, 4} | ServerOpts]), 1971 {error,{options,{not_supported,{packet_size,1}}}} = 1972 ssl:listen(9999, [{packet_size, 1} | ServerOpts]), 1973 {error,{options,{not_supported,{header,1}}}} = 1974 ssl:listen(9999, [{header, 1} | ServerOpts]), 1975 1976 client_reject_packet_opt(Config, {packet,4}), 1977 client_reject_packet_opt(Config, {packet_size, 1}), 1978 client_reject_packet_opt(Config, {header, 1}). 1979 1980%%-------------------------------------------------------------------- 1981%% Internal functions ------------------------------------------------ 1982%%-------------------------------------------------------------------- 1983 1984packet(Config, Data, Send, Recv, Quantity, Packet, Active) when Packet == 0; 1985 Packet == raw -> 1986 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 1987 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 1988 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 1989 1990 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 1991 {from, self()}, 1992 {mfa, {?MODULE, Send ,[Data, Quantity]}}, 1993 {options, [{nodelay, true},{packet, Packet} | ServerOpts]}]), 1994 Port = ssl_test_lib:inet_port(Server), 1995 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 1996 {host, Hostname}, 1997 {from, self()}, 1998 {mfa, {?MODULE, Recv, [Data, Quantity]}}, 1999 {options, [{active, Active}, {nodelay, true}, 2000 {packet, Packet} | 2001 ClientOpts]}]), 2002 2003 ssl_test_lib:check_result(Client, ok), 2004 2005 ssl_test_lib:close(Server), 2006 ssl_test_lib:close(Client); 2007 2008packet(Config, Data, Send, Recv, Quantity, Packet, Active) -> 2009 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 2010 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 2011 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 2012 2013 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 2014 {from, self()}, 2015 {mfa, {?MODULE, Send ,[Data, Quantity]}}, 2016 {options, [{packet, Packet}, {nodelay, true}| ServerOpts] 2017 ++ ssl_test_lib:bigger_buffers()}]), 2018 Port = ssl_test_lib:inet_port(Server), 2019 Client = ssl_test_lib:start_client([{node, ServerNode}, {port, Port}, 2020 {host, Hostname}, 2021 {from, self()}, 2022 {mfa, {?MODULE, Recv, [Data, Quantity]}}, 2023 {options, [{active, Active}, 2024 {nodelay, true}, 2025 {packet, Packet} | 2026 ClientOpts] ++ ssl_test_lib:bigger_buffers()}]), 2027 2028 ssl_test_lib:check_result(Client, ok), 2029 2030 ssl_test_lib:close(Server), 2031 ssl_test_lib:close(Client). 2032 2033send_raw(Socket,_, 0) -> 2034 ssl:send(Socket, <<>>), 2035 no_result_msg; 2036send_raw(Socket, Data, N) -> 2037 ssl:send(Socket, Data), 2038 send_raw(Socket, Data, N-1). 2039 2040passive_raw(Socket, _, 0) -> 2041 {error, timeout} = ssl:recv(Socket, 0, 500), 2042 ok; 2043passive_raw(Socket, Data, N) -> 2044 Length = length(Data), 2045 {ok, Data} = ssl:recv(Socket, Length), 2046 passive_raw(Socket, Data, N-1). 2047 2048passive_recv_packet(Socket, _, 0) -> 2049 case ssl:recv(Socket, 0) of 2050 {ok, []} -> 2051 {error, timeout} = ssl:recv(Socket, 0, 500), 2052 ok; 2053 Other -> 2054 {other, Other, ssl:connection_information(Socket, [session_id, cipher_suite]), 0} 2055 end; 2056passive_recv_packet(Socket, Data, N) -> 2057 case ssl:recv(Socket, 0, 10000) of 2058 {ok, Data} -> 2059 passive_recv_packet(Socket, Data, N-1); 2060 {error, _} = Other -> 2061 Other 2062 end. 2063 2064send(Socket,_, 0) -> 2065 ssl:send(Socket, <<>>), 2066 no_result_msg; 2067send(Socket, Data, N) -> 2068 case ssl:send(Socket, [Data]) of 2069 ok -> 2070 send(Socket, Data, N-1); 2071 Other -> 2072 Other 2073 end. 2074 2075send_incomplete(Socket, Data, N) -> 2076 send_incomplete(Socket, Data, N, <<>>). 2077send_incomplete(Socket, _Data, 0, Prev) -> 2078 ssl:send(Socket, Prev), 2079 ssl:send(Socket, [?uint32(0)]), 2080 no_result_msg; 2081send_incomplete(Socket, Data, N, Prev) -> 2082 Length = size(Data), 2083 <<Part1:42/binary, Rest/binary>> = Data, 2084 ssl:send(Socket, [Prev, ?uint32(Length), Part1]), 2085 send_incomplete(Socket, Data, N-1, Rest). 2086 2087active_once_raw(Socket, Data, N) -> 2088 active_once_raw(Socket, Data, N, []). 2089 2090active_once_raw(_, _, 0, _) -> 2091 ok; 2092active_once_raw(Socket, Data, N, Acc0) -> 2093 case lists:prefix(Data, Acc0) of 2094 true -> 2095 DLen = length(Data), 2096 Start = DLen + 1, 2097 Len = length(Acc0) - DLen, 2098 Acc = string:substr(Acc0, Start, Len), 2099 active_once_raw(Socket, Data, N-1, Acc); 2100 false -> 2101 receive 2102 {ssl, Socket, Info} -> 2103 ssl:setopts(Socket, [{active, once}]), 2104 active_once_raw(Socket, Data, N, Acc0 ++ Info) 2105 end 2106 end. 2107 2108active_once_packet(Socket,_, 0) -> 2109 receive 2110 {ssl, Socket, []} -> 2111 ok; 2112 {ssl, Socket, Other} -> 2113 {other, Other, ssl:connection_information(Socket, [session_id, cipher_suite]), 0} 2114 end; 2115active_once_packet(Socket, Data, N) -> 2116 receive 2117 {ssl, Socket, Data} -> 2118 ssl:setopts(Socket, [{active, once}]), 2119 active_once_packet(Socket, Data, N-1) 2120 end. 2121 2122active_raw(Socket, Data, N) -> 2123 active_raw(Socket, (length(Data) * N)). 2124active_raw(_Socket, 0) -> 2125 ok; 2126active_raw(Socket, N) -> 2127 receive 2128 {ssl, Socket, Bytes} -> 2129 active_raw(Socket, N-length(Bytes)) 2130 end. 2131 2132active_packet(Socket, _, 0) -> 2133 receive 2134 {ssl, Socket, []} -> 2135 ok; 2136 Other -> 2137 {other, Other, ssl:connection_information(Socket, [session_id, cipher_suite]), 0} 2138 end; 2139active_packet(Socket, Data, N) -> 2140 receive 2141 {ssl, Socket, Data} -> 2142 active_packet(Socket, Data, N-1); 2143 Other -> 2144 Other 2145 end. 2146 2147assert_packet_opt(Socket, Type) -> 2148 {ok, [{packet, Type}]} = ssl:getopts(Socket, [packet]). 2149 2150server_packet_decode(Socket, Packet) -> 2151 receive 2152 {ssl, Socket, Packet} -> ok; 2153 Other1 -> exit({?LINE, Other1}) 2154 end, 2155 ok = ssl:send(Socket, Packet), 2156 receive 2157 {ssl, Socket, Packet} -> ok; 2158 Other2 -> exit({?LINE, Other2}) 2159 end, 2160 spawn(fun() -> ssl:send(Socket, Packet) end), 2161 ok. 2162 2163client_packet_decode(Socket, Packet) when is_binary(Packet)-> 2164 <<P1:10/binary, P2/binary>> = Packet, 2165 client_packet_decode(Socket, P1, P2, Packet); 2166client_packet_decode(Socket, [Head | Tail] = Packet) -> 2167 client_packet_decode(Socket, [Head], Tail, Packet). 2168 2169client_packet_decode(Socket, P1, P2, Packet) -> 2170 spawn(fun() -> ssl:send(Socket, P1), ssl:send(Socket, P2) end), 2171 receive 2172 {ssl, Socket, Packet} -> ok; 2173 Other1 -> exit({?LINE, Other1}) 2174 end, 2175 spawn(fun() -> ssl:send(Socket, Packet) end), 2176 receive 2177 {ssl, Socket, Packet} -> ok; 2178 Other2 -> exit({?LINE, Other2}) 2179 end. 2180 2181server_header_decode_active(Socket, Packet, Result) -> 2182 receive 2183 {ssl, Socket, Result} -> 2184 ok; 2185 {ssl, Socket, Other1} -> 2186 check_header_result(Result, Other1) 2187 end, 2188 spawn(fun() -> ssl:send(Socket, Packet) end), 2189 ok. 2190 2191client_header_decode_active(Socket, Packet, Result) -> 2192 spawn(fun() -> ssl:send(Socket, Packet) end), 2193 receive 2194 {ssl, Socket, Result} -> 2195 ok; 2196 {ssl, Socket, Other1} -> 2197 check_header_result(Result, Other1) 2198 end. 2199 2200server_header_decode_passive(Socket, Packet, Result) -> 2201 case ssl:recv(Socket, 0) of 2202 {ok, Result} -> 2203 ok; 2204 {ok, Other} -> 2205 check_header_result(Result, Other) 2206 end, 2207 spawn(fun() -> ssl:send(Socket, Packet) end), 2208 ok. 2209 2210client_header_decode_passive(Socket, Packet, Result) -> 2211 spawn(fun() -> ssl:send(Socket, Packet) end), 2212 case ssl:recv(Socket, 0) of 2213 {ok, Result} -> 2214 ok; 2215 {ok, Other} -> 2216 check_header_result(Result, Other) 2217 end. 2218 2219%% The inet header option is a broken option as it does not buffer until it gets enough data. 2220%% This check only checks that it has the same behavior as inet, but it is a quite useless 2221%% option and the bitsynax makes it obsolete! 2222check_header_result([Byte1 | _], [Byte1]) -> 2223 ok; 2224check_header_result([Byte1 | _], [Byte1| <<>>]) -> 2225 ok; 2226check_header_result([Byte1, Byte2 | _], [Byte1, Byte2]) -> 2227 ok; 2228check_header_result([Byte1, Byte2 | _], [Byte1, Byte2 | <<>>]) -> 2229 ok; 2230check_header_result(Expected,Got) -> 2231 exit({?LINE, {Expected, Got}}). 2232 2233server_line_packet_decode(Socket, Packet) when is_binary(Packet) -> 2234 [L1, L2] = string:tokens(binary_to_list(Packet), "\n"), 2235 server_line_packet_decode(Socket, list_to_binary(L1 ++ "\n"), list_to_binary(L2 ++ "\n"), Packet); 2236server_line_packet_decode(Socket, Packet) -> 2237 [L1, L2] = string:tokens(Packet, "\n"), 2238 server_line_packet_decode(Socket, L1 ++ "\n", L2 ++ "\n", Packet). 2239 2240server_line_packet_decode(Socket, L1, L2, Packet) -> 2241 receive 2242 {ssl, Socket, L1} -> ok; 2243 Other1 -> exit({?LINE, Other1}) 2244 end, 2245 receive 2246 {ssl, Socket, L2} -> ok; 2247 Other2 -> exit({?LINE, Other2}) 2248 end, 2249 spawn(fun() -> ssl:send(Socket, Packet) end), 2250 ok. 2251 2252client_line_packet_decode(Socket, Packet) when is_binary(Packet)-> 2253 <<P1:10/binary, P2/binary>> = Packet, 2254 [L1, L2] = string:tokens(binary_to_list(Packet), "\n"), 2255 client_line_packet_decode(Socket, P1, P2, list_to_binary(L1 ++ "\n"), list_to_binary(L2 ++ "\n")); 2256client_line_packet_decode(Socket, [Head | Tail] = Packet) -> 2257 [L1, L2] = string:tokens(Packet, "\n"), 2258 client_line_packet_decode(Socket, [Head], Tail, L1 ++ "\n", L2 ++ "\n"). 2259 2260client_line_packet_decode(Socket, P1, P2, L1, L2) -> 2261 spawn(fun() -> ssl:send(Socket, P1), ssl:send(Socket, P2) end), 2262 receive 2263 {ssl, Socket, L1} -> ok; 2264 Other1 -> exit({?LINE, Other1}) 2265 end, 2266 receive 2267 {ssl, Socket, L2} -> ok; 2268 Other2 -> exit({?LINE, Other2}) 2269 end. 2270 2271add_tpkt_header(Data) when is_binary(Data) -> 2272 L = size(Data) + 4, 2273 [3, 0, ((L) bsr 8) band 16#ff, (L) band 16#ff ,Data]; 2274add_tpkt_header(IOList) when is_list(IOList) -> 2275 Binary = list_to_binary(IOList), 2276 L = size(Binary) + 4, 2277 [3, 0, ((L) bsr 8) band 16#ff, (L) band 16#ff , Binary]. 2278 2279 2280client_reject_packet_opt(Config, PacketOpt) -> 2281 ServerOpts = ssl_test_lib:ssl_options(server_opts, Config), 2282 ClientOpts = ssl_test_lib:ssl_options(client_opts, Config), 2283 {ClientNode, ServerNode, Hostname} = ssl_test_lib:run_where(Config), 2284 2285 Server = ssl_test_lib:start_server([{node, ClientNode}, {port, 0}, 2286 {from, self()}, 2287 {mfa, {ssl_test_lib, no_result_msg ,[]}}, 2288 {options, ServerOpts}]), 2289 Port = ssl_test_lib:inet_port(Server), 2290 Client = ssl_test_lib:start_client_error([{node, ServerNode}, {port, Port}, 2291 {host, Hostname}, 2292 {from, self()}, 2293 {mfa, {ssl_test_lib, no_result_msg, []}}, 2294 {options, [PacketOpt | 2295 ClientOpts]}]), 2296 2297 ssl_test_lib:check_result(Client, {error, {options, {not_supported, PacketOpt}}}). 2298 2299 2300send_switch_packet(SslSocket, Data, NextPacket) -> 2301 spawn(fun() -> ssl:send(SslSocket, Data) end), 2302 receive 2303 {ssl, SslSocket, "Hello World"} -> 2304 ssl:setopts(SslSocket, [{packet, NextPacket}]), 2305 spawn(fun() -> ssl:send(SslSocket, Data) end), 2306 receive 2307 {ssl, SslSocket, "Hello World"} -> 2308 ok 2309 end 2310 end. 2311recv_switch_packet(SslSocket, Data, NextPacket) -> 2312 receive 2313 {ssl, SslSocket, "Hello World"} -> 2314 spawn(fun() -> ssl:send(SslSocket, Data) end), 2315 ssl:setopts(SslSocket, [{packet, NextPacket}]), 2316 receive 2317 {ssl, SslSocket, "Hello World"} -> 2318 spawn(fun() -> ssl:send(SslSocket, Data) end), 2319 ok 2320 end 2321 end. 2322