84
test_server:format("Msg: ~p ~n", [Msg]),
85
test_server:format("Server Msg: ~p ~n", [Msg]),
85
86
Pid ! {self(), Msg}
89
90
run_server(ListenSocket, Opts);
92
run_server(ListenSocket, [MFA | proplists:delete(mfa, Opts)]);
91
ok = rpc:call(Node, ssl, close, [AcceptSocket])
94
test_server:format("Server closing ~p ~n", [self()]),
95
Result = rpc:call(Node, ssl, close, [AcceptSocket], 500),
96
test_server:format("Result ~p ~n", [Result]);
94
101
%%% To enable to test with s_client -reconnect
139
148
test_server:format("ssl:connect(~p, ~p, ~p)~n", [Host, Port, Options]),
140
149
case rpc:call(Node, ssl, connect, [Host, Port, Options]) of
151
Pid ! { connected, Socket },
143
152
test_server:format("Client: connected~n", []),
144
153
%% In specail cases we want to know the client port, it will
145
154
%% be indicated by sending {port, 0} in options list!
163
test_server:format("Client Msg: ~p ~n", [Msg]),
154
164
Pid ! {self(), Msg}
158
ok = rpc:call(Node, ssl, close, [Socket])
168
test_server:format("Client closing~n", []),
169
rpc:call(Node, ssl, close, [Socket]);
170
{ssl_closed, Socket} ->
160
173
{error, Reason} ->
161
test_server:format("Client: connection failed: ~p ~n", [Reason]),
174
test_server:format("Client: connection failed: ~p ~n", [Reason]),
162
175
Pid ! {self(), {error, Reason}}
179
test_server:format("Close ~p ~n", [Pid]),
180
Monitor = erlang:monitor(process, Pid),
183
{'DOWN', Monitor, process, Pid, Reason} ->
184
erlang:demonitor(Monitor),
185
test_server:format("Pid: ~p down due to:~p ~n", [Pid, Reason])
168
188
check_result(Server, ServerMsg, Client, ClientMsg) ->
208
228
test_server:fail(Reason)
211
check_result_ignore_renegotiation_reject(Pid, Msg) ->
213
{Pid, fail_session_fatal_alert_during_renegotiation} ->
214
test_server:comment("Server rejected old renegotiation"),
216
{ssl_error, _, esslconnect} ->
217
test_server:comment("Server rejected old renegotiation"),
221
{Port, {data,Debug}} when is_port(Port) ->
222
io:format("openssl ~s~n",[Debug]),
223
check_result(Pid,Msg);
225
Reason = {{expected, {Pid, Msg}},
227
test_server:fail(Reason)
231
231
wait_for_result(Server, ServerMsg, Client, ClientMsg) ->
233
233
{Server, ServerMsg} ->
235
235
{Client, ClientMsg} ->
240
240
{Client, ClientMsg} ->
242
242
{Server, ServerMsg} ->
247
247
{Port, {data,Debug}} when is_port(Port) ->
248
248
io:format("openssl ~s~n",[Debug]),
249
wait_for_result(Server, ServerMsg, Client, ClientMsg);
249
wait_for_result(Server, ServerMsg, Client, ClientMsg)
328
328
make_dsa_cert(Config) ->
330
{ServerCaCertFile, ServerCertFile, ServerKeyFile} = make_dsa_cert_files("server", Config),
331
{ClientCaCertFile, ClientCertFile, ClientKeyFile} = make_dsa_cert_files("client", Config),
330
{ServerCaCertFile, ServerCertFile, ServerKeyFile} = make_cert_files("server", Config, dsa, dsa, ""),
331
{ClientCaCertFile, ClientCertFile, ClientKeyFile} = make_cert_files("client", Config, dsa, dsa, ""),
332
332
[{server_dsa_opts, [{ssl_imp, new},{reuseaddr, true},
333
333
{cacertfile, ServerCaCertFile},
334
334
{certfile, ServerCertFile}, {keyfile, ServerKeyFile}]},
346
make_dsa_cert_files(RoleStr, Config) ->
347
CaInfo = {CaCert, _} = erl_make_certs:make_cert([{key, dsa}]),
348
{Cert, CertKey} = erl_make_certs:make_cert([{key, dsa}, {issuer, CaInfo}]),
345
make_mix_cert(Config) ->
346
{ServerCaCertFile, ServerCertFile, ServerKeyFile} = make_cert_files("server", Config, dsa,
348
{ClientCaCertFile, ClientCertFile, ClientKeyFile} = make_cert_files("client", Config, dsa,
350
[{server_mix_opts, [{ssl_imp, new},{reuseaddr, true},
351
{cacertfile, ServerCaCertFile},
352
{certfile, ServerCertFile}, {keyfile, ServerKeyFile}]},
353
{server_mix_verify_opts, [{ssl_imp, new},{reuseaddr, true},
354
{cacertfile, ClientCaCertFile},
355
{certfile, ServerCertFile}, {keyfile, ServerKeyFile},
356
{verify, verify_peer}]},
357
{client_mix_opts, [{ssl_imp, new},{reuseaddr, true},
358
{cacertfile, ClientCaCertFile},
359
{certfile, ClientCertFile}, {keyfile, ClientKeyFile}]}
362
make_cert_files(RoleStr, Config, Alg1, Alg2, Prefix) ->
363
Alg1Str = atom_to_list(Alg1),
364
Alg2Str = atom_to_list(Alg2),
365
CaInfo = {CaCert, _} = erl_make_certs:make_cert([{key, Alg1}]),
366
{Cert, CertKey} = erl_make_certs:make_cert([{key, Alg2}, {issuer, CaInfo}]),
349
367
CaCertFile = filename:join([?config(priv_dir, Config),
350
RoleStr, "dsa_cacerts.pem"]),
368
RoleStr, Prefix ++ Alg1Str ++ "_cacerts.pem"]),
351
369
CertFile = filename:join([?config(priv_dir, Config),
352
RoleStr, "dsa_cert.pem"]),
370
RoleStr, Prefix ++ Alg2Str ++ "_cert.pem"]),
353
371
KeyFile = filename:join([?config(priv_dir, Config),
354
RoleStr, "dsa_key.pem"]),
372
RoleStr, Prefix ++ Alg2Str ++ "_key.pem"]),
356
374
der_to_pem(CaCertFile, [{'Certificate', CaCert, not_encrypted}]),
357
375
der_to_pem(CertFile, [{'Certificate', Cert, not_encrypted}]),
358
376
der_to_pem(KeyFile, [CertKey]),
359
377
{CaCertFile, CertFile, KeyFile}.
361
380
start_upgrade_server(Args) ->
362
381
Result = spawn_link(?MODULE, run_upgrade_server, [Args]),
396
415
{Module, Function, Args} = proplists:get_value(mfa, Opts),
397
416
Msg = rpc:call(Node, Module, Function, [SslAcceptSocket | Args]),
417
test_server:format("Upgrade Server Msg: ~p ~n", [Msg]),
398
418
Pid ! {self(), Msg},
401
ok = rpc:call(Node, ssl, close, [SslAcceptSocket])
421
test_server:format("Upgrade Server closing~n", []),
422
rpc:call(Node, ssl, close, [SslAcceptSocket])
403
424
catch error:{badmatch, Error} ->
404
425
Pid ! {self(), Error}
428
449
test_server:format("apply(~p, ~p, ~p)~n",
429
450
[Module, Function, [SslSocket | Args]]),
430
451
Msg = rpc:call(Node, Module, Function, [SslSocket | Args]),
452
test_server:format("Upgrade Client Msg: ~p ~n", [Msg]),
431
453
Pid ! {self(), Msg},
434
ok = rpc:call(Node, ssl, close, [SslSocket])
456
test_server:format("Upgrade Client closing~n", []),
457
rpc:call(Node, ssl, close, [SslSocket])
437
460
start_upgrade_server_error(Args) ->
649
675
{unexpected, Other}
678
session_info_result(Socket) ->
679
ssl:session_info(Socket).
682
public_key(#'PrivateKeyInfo'{privateKeyAlgorithm =
683
#'PrivateKeyInfo_privateKeyAlgorithm'{algorithm = ?rsaEncryption},
684
privateKey = Key}) ->
685
public_key:der_decode('RSAPrivateKey', iolist_to_binary(Key));
687
public_key(#'PrivateKeyInfo'{privateKeyAlgorithm =
688
#'PrivateKeyInfo_privateKeyAlgorithm'{algorithm = ?'id-dsa'},
689
privateKey = Key}) ->
690
public_key:der_decode('DSAPrivateKey', iolist_to_binary(Key));
693
receive_rizzo_duong_beast() ->
695
{ssl, _, "ello\n"} ->
699
{ssl, _, "world\n"} ->
705
state([{data,[{"State", State}]} | _]) ->
707
state([{data,[{"StateData", State}]} | _]) ->