[erlang-questions] Downgrade ssl connection

Caragea Silviu silviu.cpp@REDACTED
Thu Jan 5 11:39:39 CET 2017


Hello,

I'm trying to create an example where I send some data over ssl then I
downgrade the connection and send data over tcp . Unfortunately I'm doing
something wrong.

-export([test/0]).

get_certificate() ->
    "test/server.pem".

-define(SSL, ssl).

test() ->
    ?SSL:start(),
    Port = 12000,
    Opt = [
        binary,
        {exit_on_close, false},
        {active, false},
        {ciphers, ["AES128-GCM-SHA256"]},
        {verify, verify_none}
    ],

    {ok, LSocket} = ?SSL:listen(Port, [{certfile, get_certificate()} | Opt]),

    ClientProc = fun() ->
        {ok, CSocket} = ?SSL:connect("127.0.0.1", Port, Opt),
        ok = ?SSL:send(CSocket, <<"PING">>),
        {ok, <<"PONG">> } = ?SSL:recv(CSocket, 0),
        {ok, TcpSocket} = ?SSL:close(CSocket, {self(), 3000}),
        {ok, <<"PLAIN_DATA">>} = gen_tcp:recv(TcpSocket, 0),
        ok = gen_tcp:send(TcpSocket, <<"PLAIN_RESPONSE">>),
        ok = gen_tcp:close(CSocket)
    end,

    spawn(ClientProc),

    {ok, Socket} = ?SSL:transport_accept(LSocket, 5000),
    ok = ?SSL:ssl_accept(Socket),
    {ok, <<"PING">> } = ?SSL:recv(Socket, 0),
    ok = ?SSL:send(Socket, <<"PONG">>),
    {ok, TcpSocket} = ?SSL:close(Socket, {self(), 3000}),
    ok = gen_tcp:send(TcpSocket, <<"PLAIN_DATA">>),
    {ok, <<"PLAIN_RESPONSE">>} = gen_tcp:recv(TcpSocket, 0),
    ok = gen_tcp:close(Socket),

    ok = ?SSL:close(LSocket),
    true.

Any idea why it's not properly working ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20170105/7f581bd8/attachment.htm>


More information about the erlang-questions mailing list