Created
February 8, 2016 07:50
-
-
Save RoadRunnr/27179905a341a51a0f53 to your computer and use it in GitHub Desktop.
Erlang DTLS sample client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(dtls_client). | |
-export([connect/1]). | |
psk_verify(Username, UserState) -> | |
io:format("Server Hint: ~p~n", [Username]), | |
{ok, UserState}. | |
connect(Port) -> | |
[application:start(X) || X <- [crypto, asn1, public_key, ssl]], | |
%% Opts = [{ciphers,[{dhe_dss,aes_256_cbc,sha256}]}, | |
Opts = [ | |
{ssl_imp,new}, | |
{active, false}, | |
{verify, 0}, | |
{protocol, dtls}, | |
{versions, ['dtlsv1.2']}, | |
%% {ciphers,[{ecdhe_rsa, aes_128_cbc, sha256}]}, | |
{cb_info, {dtls_udp, dtls_udp, udp_close, udp_error}} | |
%% {versions, ['tlsv1.2']}, | |
%% {ciphers,[{ecdhe_rsa,chacha20_poly1305,null}]} | |
%% {srp_identity, {"Test-User", "secret"}}, | |
%% {ciphers, [{srp_anon, aes_256_cbc, sha}]}, | |
%% {psk_identity, "Client_identity"}, | |
%% {psk_lookup_fun, {fun psk_verify/2, <<16#11>>}}, | |
%% {versions, [tlsv1]}, | |
%% {ciphers,[{rsa_psk, aes_256_cbc, sha}]}, | |
%% {reuseaddr,true} | |
], | |
%%{ok, Host} = inet:gethostname(), | |
Host = {127,0,0,1}, | |
{ok, CSock} = ssl:connect(Host, Port, Opts), | |
io:fwrite("Connect: connected.~n"), | |
{ok, Data} = ssl:recv(CSock, 0), | |
io:fwrite("Connect: got data: ~p~n", [Data]), | |
io:fwrite("Connect: closing and terminating.~n"), | |
ssl:close(CSock). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment