Ditch enacl, support DH448 and Blake2s, and fix types (#14)
* Remove get_stacktrace (deprecated since OTP-24) * Add DH448 support and switch to crypto:generate_key for DH25519 * Switch to crypto:hash/2 for Blake2b and support Blake2s * Switch last enacl calls to crypto - no more enacl * Eqwalizer fixes Ewqalizer fix Eqwalizer fix Eqwalizer fix Eqwalizer fix Eqwalizer support Eqwalizer fix Fix tests to follow types (remote keys) * More error handling on setup * Dialyzer fix * Write CHANGELOG * Note about type-checking in README
This commit is contained in:
@@ -43,7 +43,8 @@ noise_test(_Name, Protocol, Init, Resp, Messages, HSHash) ->
|
||||
SecK = fun(undefined) -> undefined; (Sec) -> enoise_keypair:new(DH, Sec, undefined) end,
|
||||
PubK = fun(undefined) -> undefined; (Pub) -> enoise_keypair:new(DH, Pub) end,
|
||||
HSInit = fun(P, R, #{ e := E, s := S, rs := RS, prologue := PL }) ->
|
||||
enoise_hs_state:init(P, R, PL, {SecK(S), SecK(E), PubK(RS), undefined})
|
||||
{ok, HS} = enoise_hs_state:init(P, R, PL, {SecK(S), SecK(E), PubK(RS), undefined}),
|
||||
HS
|
||||
end,
|
||||
|
||||
InitHS = HSInit(Protocol, initiator, Init),
|
||||
|
||||
@@ -7,5 +7,18 @@
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
name_test() ->
|
||||
?assertMatch(<<"Noise_XK_25519_ChaChaPoly_SHA512">>,
|
||||
enoise_protocol:to_name(enoise_protocol:from_name("Noise_XK_25519_ChaChaPoly_SHA512"))).
|
||||
roundtrip("Noise_XK_25519_ChaChaPoly_SHA512"),
|
||||
roundtrip("Noise_NN_25519_AESGCM_BLAKE2b").
|
||||
|
||||
name2_test() ->
|
||||
Name = "Noise_NXpsk2_25519_AESGCM_SHA512",
|
||||
?assertError({name_not_recognized, Name}, enoise_protocol:from_name(Name)).
|
||||
|
||||
name_pattern_test() ->
|
||||
Pat = "XKfallback+psk0",
|
||||
RoundPat = enoise_protocol:to_name_pattern(enoise_protocol:from_name_pattern(Pat)),
|
||||
?assertEqual(Pat, RoundPat).
|
||||
|
||||
roundtrip(Name) ->
|
||||
ExpectedName = iolist_to_binary(Name),
|
||||
?assertMatch(ExpectedName, enoise_protocol:to_name(enoise_protocol:from_name(Name))).
|
||||
|
||||
@@ -41,10 +41,9 @@ noise_interactive(V = #{ protocol_name := Name }) ->
|
||||
noise_interactive(_Name, Protocol, Init, Resp, Messages, HSHash) ->
|
||||
DH = enoise_protocol:dh(Protocol),
|
||||
SecK = fun(undefined) -> undefined; (Sec) -> enoise_keypair:new(DH, Sec, undefined) end,
|
||||
PubK = fun(undefined) -> undefined; (Pub) -> enoise_keypair:new(DH, Pub) end,
|
||||
|
||||
HSInit = fun(#{ e := E, s := S, rs := RS, prologue := PL }, R) ->
|
||||
Opts = [{noise, Protocol}, {s, SecK(S)}, {e, SecK(E)}, {rs, PubK(RS)}, {prologue, PL}],
|
||||
Opts = [{noise, Protocol}, {s, SecK(S)}, {e, SecK(E)}, {rs, RS}, {prologue, PL}],
|
||||
enoise:handshake(Opts, R)
|
||||
end,
|
||||
{ok, InitHS} = HSInit(Init, initiator),
|
||||
@@ -149,12 +148,12 @@ noise_test_run_(Conf, SKP, CKP) ->
|
||||
Protocol = enoise_protocol:from_name(Conf),
|
||||
Port = 4556,
|
||||
|
||||
SrvOpts = [{echos, 2}, {cpub, CKP}],
|
||||
SrvOpts = [{echos, 2}, {cpub, enoise_keypair:pubkey(CKP)}],
|
||||
EchoSrv = enoise_utils:echo_srv_start(Port, Protocol, SKP, SrvOpts),
|
||||
|
||||
{ok, TcpSock} = gen_tcp:connect("localhost", Port, [{active, once}, binary, {reuseaddr, true}], 100),
|
||||
|
||||
Opts = [{noise, Protocol}, {s, CKP}] ++ [{rs, SKP} || enoise_utils:need_rs(initiator, Conf) ],
|
||||
Opts = [{noise, Protocol}, {s, CKP}] ++ [{rs, enoise_keypair:pubkey(SKP)} || enoise_utils:need_rs(initiator, Conf) ],
|
||||
{ok, EConn, _} = enoise:connect(TcpSock, Opts),
|
||||
|
||||
ok = enoise:send(EConn, <<"Hello World!">>),
|
||||
|
||||
@@ -26,7 +26,7 @@ echo_srv(Port, Protocol, SKP, SrvOpts) ->
|
||||
AcceptRes =
|
||||
try
|
||||
enoise:accept(TcpSock, Opts)
|
||||
catch _:R -> gen_tcp:close(TcpSock), {error, {R, erlang:get_stacktrace()}} end,
|
||||
catch _:R:S -> gen_tcp:close(TcpSock), {error, {R, S}} end,
|
||||
|
||||
gen_tcp:close(LSock),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user