From 4fe38c4b8b2c8024afb60990e598ff823743fd54 Mon Sep 17 00:00:00 2001 From: Qijiang Fan Date: Tue, 30 Dec 2014 22:40:28 +0800 Subject: ssl: add SNI server support --- lib/ssl/src/ssl_connection.erl | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'lib/ssl/src/ssl_connection.erl') diff --git a/lib/ssl/src/ssl_connection.erl b/lib/ssl/src/ssl_connection.erl index 4a839872a6..2c0b1b6257 100644 --- a/lib/ssl/src/ssl_connection.erl +++ b/lib/ssl/src/ssl_connection.erl @@ -42,7 +42,8 @@ %% User Events -export([send/2, recv/3, close/1, shutdown/2, new_user/2, get_opts/2, set_opts/2, info/1, session_info/1, - peer_certificate/1, renegotiation/1, negotiated_protocol/1, prf/5 + peer_certificate/1, renegotiation/1, negotiated_protocol/1, prf/5, + sni_hostname/1 ]). -export([handle_session/7]). @@ -160,6 +161,14 @@ send(Pid, Data) -> recv(Pid, Length, Timeout) -> sync_send_all_state_event(Pid, {recv, Length, Timeout}). +%%-------------------------------------------------------------------- +-spec sni_hostname(pid()) -> undefined | string(). +%% +%% Description: Get the SNI hostname +%%-------------------------------------------------------------------- +sni_hostname(Pid) when is_pid(Pid) -> + sync_send_all_state_event(Pid, sni_hostname). + %%-------------------------------------------------------------------- -spec close(pid()) -> ok | {error, reason()}. %% @@ -845,7 +854,10 @@ handle_sync_event(session_info, _, StateName, handle_sync_event(peer_certificate, _, StateName, #state{session = #session{peer_certificate = Cert}} = State) -> - {reply, {ok, Cert}, StateName, State, get_timeout(State)}. + {reply, {ok, Cert}, StateName, State, get_timeout(State)}; +handle_sync_event(sni_hostname, _, StateName, #state{sni_hostname = SNIHostname} = State) -> + {reply, SNIHostname, StateName, State}. + handle_info({ErrorTag, Socket, econnaborted}, StateName, #state{socket = Socket, transport_cb = Transport, -- cgit v1.2.3