SSL client reuse_sessions not working?

Roger Lipscombe roger@REDACTED
Thu Apr 2 11:07:27 CEST 2020


I'm investigating SSL session reuse, and I can't get my client to
actually reuse sessions. I'm using the escript below.

It reports 'false' for 'session_resumption' for every connection; the
session cache always has zero entries, and the server reports a
different session ID each time. The server (using ranch) is happily
reusing sessions when used with 'openssl s_time'.

What am I doing wrong?

#!/usr/bin/env escript

main(_Args) ->
    Host = "localhost",
    Port = 15350,

    {ok, _} = application:ensure_all_started(ssl),

    Count = 100,
    loop(Host, Port, Count),
    ok.

loop(_H, _P, 0) -> ok;
loop(Host, Port, Count) ->
    % Loop, connecting and disconnecting. Reuse sessions if possible.
    Options = [
               {reuse_sessions, true}  % automatic session reuse
              ],

    {ok, S} = ssl:connect(Host, Port, Options, infinity),
    {ok, [{session_id, SessionId}]} = ssl:connection_information(S,
[session_id]),
    {ok, [{session_resumption, SessionResumption}]} =
ssl:connection_information(S, [session_resumption]),
    io:format("~p ~p\n", [SessionId, SessionResumption]),
    ssl:close(S),

    io:format("client_ssl_otp_session_cache: ~p\n",
[get_ets_size(client_ssl_otp_session_cache)]),

    loop(Host, Port, Count - 1).

get_ets_size(Name) ->
    get_ets_size(Name, ets:all()).

get_ets_size(Name, []) -> undefined;
get_ets_size(Name, [Tid | Rest]) ->
    case ets:info(Tid, name) of
        Name ->
            ets:info(Tid, size);
        _ ->
            get_ets_size(Name, Rest)
    end.


More information about the erlang-questions mailing list