diff options
author | Ingela Anderton Andin <[email protected]> | 2013-12-02 09:52:58 +0100 |
---|---|---|
committer | Ingela Anderton Andin <[email protected]> | 2013-12-02 09:52:58 +0100 |
commit | 239ce1c4781fe4fc25c55795573654453887f507 (patch) | |
tree | 256c7436d2d1e24407422fb525e71258fe23334e /lib/ssl/src/dtls.erl | |
parent | d3e5761436cfbcb5b53edad9e1140e445ce94bfd (diff) | |
parent | 174b36ae2755b501e2b3152f6b00e9c59a90e848 (diff) | |
download | otp-239ce1c4781fe4fc25c55795573654453887f507.tar.gz otp-239ce1c4781fe4fc25c55795573654453887f507.tar.bz2 otp-239ce1c4781fe4fc25c55795573654453887f507.zip |
Merge branch 'ia/ssl/dtls-refactor-continue/OTP-11292' into maint
* ia/ssl/dtls-refactor-continue/OTP-11292:
ssl: Trap exits
ssl: Refactor connetion handling
ssl: API and supervisor
ssl: Dialyzer fixes
ssl: Test case enhancement
ssl: Refactor API
ssl, public_key: Dialyzer fixes
ssl: Refactor premaster secret handling
ssl: Refactor connection and handshake handling
ssl: Refactor handshake and record handling
Diffstat (limited to 'lib/ssl/src/dtls.erl')
-rw-r--r-- | lib/ssl/src/dtls.erl | 79 |
1 files changed, 78 insertions, 1 deletions
diff --git a/lib/ssl/src/dtls.erl b/lib/ssl/src/dtls.erl index 013286c9bd..1cad9560b5 100644 --- a/lib/ssl/src/dtls.erl +++ b/lib/ssl/src/dtls.erl @@ -19,7 +19,84 @@ %% -%%% Purpose : API for DTLS. +%%% Purpose : Reflect DTLS specific API options (fairly simple wrapper at the moment) +%% First implementation will support DTLS connections only in a "TLS/TCP like way" -module(dtls). +-include("ssl_api.hrl"). +-include("ssl_internal.hrl"). + +-export([connect/2, connect/3, listen/2, accept/1, accept/2, + handshake/1, handshake/2, handshake/3]). + +%%-------------------------------------------------------------------- +-spec connect(host() | port(), [connect_option()]) -> {ok, #sslsocket{}} | + {error, reason()}. +-spec connect(host() | port(), [connect_option()] | inet:port_number(), + timeout() | list()) -> + {ok, #sslsocket{}} | {error, reason()}. +-spec connect(host() | port(), inet:port_number(), list(), timeout()) -> + {ok, #sslsocket{}} | {error, reason()}. + +%% +%% Description: Connect to an DTLS server. +%%-------------------------------------------------------------------- + +connect(Socket, Options) when is_port(Socket) -> + connect(Socket, Options, infinity). +connect(Socket, SslOptions, Timeout) when is_port(Socket) -> + DTLSOpts = [{protocol, dtls} | SslOptions], + ssl:connect(Socket, DTLSOpts, Timeout); +connect(Host, Port, Options) -> + connect(Host, Port, Options, infinity). +connect(Host, Port, Options, Timeout) -> + DTLSOpts = [{protocol, dtls} | Options], + ssl:connect(Host, Port, DTLSOpts, Timeout). + +%%-------------------------------------------------------------------- +-spec listen(inet:port_number(), [listen_option()]) ->{ok, #sslsocket{}} | {error, reason()}. + +%% +%% Description: Creates an ssl listen socket. +%%-------------------------------------------------------------------- +listen(Port, Options) -> + DTLSOpts = [{protocol, dtls} | Options], + ssl:listen(Port, DTLSOpts). + +%%-------------------------------------------------------------------- +-spec accept(#sslsocket{}) -> {ok, #sslsocket{}} | + {error, reason()}. +-spec accept(#sslsocket{}, timeout()) -> {ok, #sslsocket{}} | + {error, reason()}. +%% +%% Description: Performs transport accept on an ssl listen socket +%%-------------------------------------------------------------------- +accept(ListenSocket) -> + accept(ListenSocket, infinity). +accept(Socket, Timeout) -> + ssl:transport_accept(Socket, Timeout). + +%%-------------------------------------------------------------------- +-spec handshake(#sslsocket{}) -> ok | {error, reason()}. +-spec handshake(#sslsocket{} | port(), timeout()| [ssl_option() + | transport_option()]) -> + ok | {ok, #sslsocket{}} | {error, reason()}. +-spec handshake(port(), [ssl_option()| transport_option()], timeout()) -> + {ok, #sslsocket{}} | {error, reason()}. +%% +%% Description: Performs accept on an ssl listen socket. e.i. performs +%% ssl handshake. +%%-------------------------------------------------------------------- + +handshake(ListenSocket) -> + handshake(ListenSocket, infinity). + +handshake(#sslsocket{} = Socket, Timeout) -> + ssl:ssl_accept(Socket, Timeout); + +handshake(ListenSocket, SslOptions) when is_port(ListenSocket) -> + handshake(ListenSocket, SslOptions, infinity). + +handshake(Socket, SslOptions, Timeout) when is_port(Socket) -> + ssl:ssl_accept(Socket, SslOptions, Timeout). |