|
@@ -30,7 +30,6 @@
|
|
%% ssl.
|
|
%% ssl.
|
|
-export([ssl_accept_error/1]).
|
|
-export([ssl_accept_error/1]).
|
|
-export([ssl_accept_socket/1]).
|
|
-export([ssl_accept_socket/1]).
|
|
--export([ssl_accept_socket_nofile/1]).
|
|
|
|
-export([ssl_active_echo/1]).
|
|
-export([ssl_active_echo/1]).
|
|
-export([ssl_echo/1]).
|
|
-export([ssl_echo/1]).
|
|
|
|
|
|
@@ -71,7 +70,6 @@ groups() ->
|
|
]}, {ssl, [
|
|
]}, {ssl, [
|
|
ssl_accept_error,
|
|
ssl_accept_error,
|
|
ssl_accept_socket,
|
|
ssl_accept_socket,
|
|
- ssl_accept_socket_nofile,
|
|
|
|
ssl_active_echo,
|
|
ssl_active_echo,
|
|
ssl_echo
|
|
ssl_echo
|
|
]}, {misc, [
|
|
]}, {misc, [
|
|
@@ -118,11 +116,11 @@ misc_bad_transport(_) ->
|
|
|
|
|
|
%% ssl.
|
|
%% ssl.
|
|
|
|
|
|
-ssl_accept_error(Config) ->
|
|
|
|
|
|
+ssl_accept_error(_) ->
|
|
Name = ssl_accept_error,
|
|
Name = ssl_accept_error,
|
|
|
|
+ {_, Cert, Key} = ct_helper:make_certs(),
|
|
{ok, ListenerSup} = ranch:start_listener(Name, 1,
|
|
{ok, ListenerSup} = ranch:start_listener(Name, 1,
|
|
- ranch_ssl, [{port, 0},
|
|
|
|
- {certfile, ?config(data_dir, Config) ++ "cert.pem"}],
|
|
|
|
|
|
+ ranch_ssl, [{port, 0}, {cert, Cert}, {key, Key}],
|
|
echo_protocol, []),
|
|
echo_protocol, []),
|
|
Port = ranch:get_port(Name),
|
|
Port = ranch:get_port(Name),
|
|
ListenerSupChildren = supervisor:which_children(ListenerSup),
|
|
ListenerSupChildren = supervisor:which_children(ListenerSup),
|
|
@@ -138,23 +136,20 @@ ssl_accept_error(Config) ->
|
|
true = is_process_alive(AcceptorPid),
|
|
true = is_process_alive(AcceptorPid),
|
|
ranch:stop_listener(Name).
|
|
ranch:stop_listener(Name).
|
|
|
|
|
|
-ssl_accept_socket_nofile(Config) ->
|
|
|
|
|
|
+ssl_accept_socket(_) ->
|
|
%%% XXX we can't do the spawn to test the controlling process change
|
|
%%% XXX we can't do the spawn to test the controlling process change
|
|
%%% because of the bug in ssl
|
|
%%% because of the bug in ssl
|
|
- {ok, Pem} = file:read_file(filename:join(?config(data_dir, Config),
|
|
|
|
- "cert.pem")),
|
|
|
|
- [{KeyType, Key, not_encrypted},
|
|
|
|
- {_CertType, Cert, not_encrypted}] = public_key:pem_decode(Pem),
|
|
|
|
Name = ssl_accept_socket,
|
|
Name = ssl_accept_socket,
|
|
|
|
+ {_, Cert, Key} = ct_helper:make_certs(),
|
|
{ok, S} = ssl:listen(0,
|
|
{ok, S} = ssl:listen(0,
|
|
- [{cert, Cert}, {key, {KeyType, Key}}, binary,
|
|
|
|
|
|
+ [{cert, Cert}, {key, Key}, binary,
|
|
{active, false}, {packet, raw}, {reuseaddr, true}]),
|
|
{active, false}, {packet, raw}, {reuseaddr, true}]),
|
|
{ok, _} = ranch:start_listener(Name, 1,
|
|
{ok, _} = ranch:start_listener(Name, 1,
|
|
ranch_ssl, [{socket, S}], echo_protocol, []),
|
|
ranch_ssl, [{socket, S}], echo_protocol, []),
|
|
Port = ranch:get_port(Name),
|
|
Port = ranch:get_port(Name),
|
|
{ok, Socket} = ssl:connect("localhost", Port,
|
|
{ok, Socket} = ssl:connect("localhost", Port,
|
|
[binary, {active, false}, {packet, raw},
|
|
[binary, {active, false}, {packet, raw},
|
|
- {certfile, ?config(data_dir, Config) ++ "cert.pem"}]),
|
|
|
|
|
|
+ {cert, Cert}, {key, Key}]),
|
|
ok = ssl:send(Socket, <<"TCP Ranch is working!">>),
|
|
ok = ssl:send(Socket, <<"TCP Ranch is working!">>),
|
|
{ok, <<"TCP Ranch is working!">>} = ssl:recv(Socket, 21, 1000),
|
|
{ok, <<"TCP Ranch is working!">>} = ssl:recv(Socket, 21, 1000),
|
|
ok = ranch:stop_listener(Name),
|
|
ok = ranch:stop_listener(Name),
|
|
@@ -163,37 +158,16 @@ ssl_accept_socket_nofile(Config) ->
|
|
{'EXIT', _} = begin catch ranch:get_port(Name) end,
|
|
{'EXIT', _} = begin catch ranch:get_port(Name) end,
|
|
ok.
|
|
ok.
|
|
|
|
|
|
-ssl_accept_socket(Config) ->
|
|
|
|
- %%% XXX we can't do the spawn to test the controlling process change
|
|
|
|
- %%% because of the bug in ssl
|
|
|
|
- Name = ssl_accept_socket,
|
|
|
|
- {ok, S} = ssl:listen(0,
|
|
|
|
- [{certfile, ?config(data_dir, Config) ++ "cert.pem"}, binary,
|
|
|
|
- {active, false}, {packet, raw}, {reuseaddr, true}]),
|
|
|
|
- {ok, _} = ranch:start_listener(Name, 1,
|
|
|
|
- ranch_ssl, [{socket, S}], echo_protocol, []),
|
|
|
|
- Port = ranch:get_port(Name),
|
|
|
|
- {ok, Socket} = ssl:connect("localhost", Port,
|
|
|
|
- [binary, {active, false}, {packet, raw},
|
|
|
|
- {certfile, ?config(data_dir, Config) ++ "cert.pem"}]),
|
|
|
|
- ok = ssl:send(Socket, <<"TCP Ranch is working!">>),
|
|
|
|
- {ok, <<"TCP Ranch is working!">>} = ssl:recv(Socket, 21, 1000),
|
|
|
|
- ok = ranch:stop_listener(Name),
|
|
|
|
- {error, closed} = ssl:recv(Socket, 0, 1000),
|
|
|
|
- %% Make sure the listener stopped.
|
|
|
|
- {'EXIT', _} = begin catch ranch:get_port(Name) end,
|
|
|
|
- ok.
|
|
|
|
-
|
|
|
|
-ssl_active_echo(Config) ->
|
|
|
|
|
|
+ssl_active_echo(_) ->
|
|
Name = ssl_active_echo,
|
|
Name = ssl_active_echo,
|
|
|
|
+ {_, Cert, Key} = ct_helper:make_certs(),
|
|
{ok, _} = ranch:start_listener(Name, 1,
|
|
{ok, _} = ranch:start_listener(Name, 1,
|
|
- ranch_ssl, [{port, 0},
|
|
|
|
- {certfile, ?config(data_dir, Config) ++ "cert.pem"}],
|
|
|
|
|
|
+ ranch_ssl, [{port, 0}, {cert, Cert}, {key, Key}],
|
|
active_echo_protocol, []),
|
|
active_echo_protocol, []),
|
|
Port = ranch:get_port(Name),
|
|
Port = ranch:get_port(Name),
|
|
{ok, Socket} = ssl:connect("localhost", Port,
|
|
{ok, Socket} = ssl:connect("localhost", Port,
|
|
[binary, {active, false}, {packet, raw},
|
|
[binary, {active, false}, {packet, raw},
|
|
- {certfile, ?config(data_dir, Config) ++ "cert.pem"}]),
|
|
|
|
|
|
+ {cert, Cert}, {key, Key}]),
|
|
ok = ssl:send(Socket, <<"SSL Ranch is working!">>),
|
|
ok = ssl:send(Socket, <<"SSL Ranch is working!">>),
|
|
{ok, <<"SSL Ranch is working!">>} = ssl:recv(Socket, 21, 1000),
|
|
{ok, <<"SSL Ranch is working!">>} = ssl:recv(Socket, 21, 1000),
|
|
ok = ranch:stop_listener(Name),
|
|
ok = ranch:stop_listener(Name),
|
|
@@ -202,16 +176,16 @@ ssl_active_echo(Config) ->
|
|
{'EXIT', _} = begin catch ranch:get_port(Name) end,
|
|
{'EXIT', _} = begin catch ranch:get_port(Name) end,
|
|
ok.
|
|
ok.
|
|
|
|
|
|
-ssl_echo(Config) ->
|
|
|
|
|
|
+ssl_echo(_) ->
|
|
Name = ssl_echo,
|
|
Name = ssl_echo,
|
|
|
|
+ {_, Cert, Key} = ct_helper:make_certs(),
|
|
{ok, _} = ranch:start_listener(Name, 1,
|
|
{ok, _} = ranch:start_listener(Name, 1,
|
|
- ranch_ssl, [{port, 0},
|
|
|
|
- {certfile, ?config(data_dir, Config) ++ "cert.pem"}],
|
|
|
|
|
|
+ ranch_ssl, [{port, 0}, {cert, Cert}, {key, Key}],
|
|
echo_protocol, []),
|
|
echo_protocol, []),
|
|
Port = ranch:get_port(Name),
|
|
Port = ranch:get_port(Name),
|
|
{ok, Socket} = ssl:connect("localhost", Port,
|
|
{ok, Socket} = ssl:connect("localhost", Port,
|
|
[binary, {active, false}, {packet, raw},
|
|
[binary, {active, false}, {packet, raw},
|
|
- {certfile, ?config(data_dir, Config) ++ "cert.pem"}]),
|
|
|
|
|
|
+ {cert, Cert}, {key, Key}]),
|
|
ok = ssl:send(Socket, <<"SSL Ranch is working!">>),
|
|
ok = ssl:send(Socket, <<"SSL Ranch is working!">>),
|
|
{ok, <<"SSL Ranch is working!">>} = ssl:recv(Socket, 21, 1000),
|
|
{ok, <<"SSL Ranch is working!">>} = ssl:recv(Socket, 21, 1000),
|
|
ok = ranch:stop_listener(Name),
|
|
ok = ranch:stop_listener(Name),
|