2

I have an SSL server, and I want to downgrade this after receiving the first ssl:recv to a raw gen_tcp. Assuming this can be used to do that I can not find an example on how to use this. And I am not so good at using the Erlang/OTP documentation yet http://erlang.org/doc/man/ssl.html#close-2

I am a bit confused with NewController::pid() from the documentation:

How = timeout() | {NewController::pid(), timeout()}
David Buck
  • 3,752
  • 35
  • 31
  • 35
Mike5050
  • 625
  • 1
  • 7
  • 22

1 Answers1

1

NewController::pid() here refers to the process you want to set as the "controlling process" for the downgraded TCP socket. gen_tcp functions on the socket will only work if called from that process. You'll want to send self() here unless you want to use the downgraded TCP socket from another process.

The only example I could find of ssl:close/2 being used with a tuple as the second argument is this test. Here's a simplified version of that code to get you started:

% Assuming `SSLSocket` is the SSL socket.
{ok, TCPSocket} = ssl:close(SSLSocket, {self(), 10000}),
% You can use `TCPSocket` with `gen_tcp` now.
gen_tcp:send(TCPSocket, "foo"),
Dogbert
  • 212,659
  • 41
  • 396
  • 397
  • I get an error, timeout when I do this. "In the latter case the transport connection will be handed over to the NewController process after receiving the TLS close alert from the peer." -- Does the peer(client) need to send something special? – Mike5050 Aug 10 '17 at 18:38