replace xrouter_clientd with xrouter_procd

This commit is contained in:
Irina Guberman 2017-08-16 18:42:30 -05:00
parent 207ec85f8c
commit fd796440db
2 changed files with 63 additions and 52 deletions

View File

@ -7,6 +7,9 @@ compile:
eqc_compile: compile eqc_compile: compile
erlc -o _build/default/lib/enacl/ebin eqc_test/enacl_eqc.erl erlc -o _build/default/lib/enacl/ebin eqc_test/enacl_eqc.erl
eqc_mini_compile: compile
erlc -Dmini -o _build/default/lib/enacl/ebin eqc_test/enacl_eqc.erl
.PHONE: console .PHONE: console
console: compile console: compile
$(REBAR) shell $(REBAR) shell

View File

@ -2,11 +2,19 @@
-include_lib("eqc/include/eqc.hrl"). -include_lib("eqc/include/eqc.hrl").
-compile(export_all). -compile(export_all).
%% -compile({parse_transform, eqc_parallelize}). -ifndef(mini).
-compile({parse_transform, eqc_parallelize}).
-define(FAULT(Arg1, Arg2), eqc:fault(Arg1, Arg2)).
-define(FAULT_RATE(Arg1, Arg2, Arg3), eqc:fault_rate(Arg1, Arg2, Arg3)).
-else.
-define(FAULT(Arg1, Arg2), noop_fault(Arg1, Arg2)).
-define(FAULT_RATE(Arg1, Arg2, Arg3), noop_fault_rate(Arg1, Arg2, Arg3)).
-endif.
z_fault(_Bad, Good) -> Good.
z_fault_rate(_1, _2, Gen) -> Gen. noop_fault(_Bad, Good) -> Good.
noop_fault_rate(_1, _2, Gen) -> Gen.
non_byte_int() -> non_byte_int() ->
oneof([ oneof([
@ -18,7 +26,7 @@ g_iolist() ->
?SIZED(Sz, g_iolist(Sz)). ?SIZED(Sz, g_iolist(Sz)).
g_iolist(0) -> g_iolist(0) ->
z_fault( ?FAULT(
oneof([ oneof([
elements([a,b,c]), elements([a,b,c]),
real(), real(),
@ -26,7 +34,7 @@ g_iolist(0) ->
]), ]),
return([])); return([]));
g_iolist(N) -> g_iolist(N) ->
z_fault( ?FAULT(
oneof([ oneof([
elements([a,b,c]), elements([a,b,c]),
real(), real(),
@ -38,7 +46,7 @@ g_iolist(N) ->
])). ])).
g_iodata() -> g_iodata() ->
z_fault( ?FAULT(
oneof([elements([a,b,c]), real()]), oneof([elements([a,b,c]), real()]),
oneof([binary(), g_iolist(), eqc_gen:largebinary(64*1024)])). oneof([binary(), g_iolist(), eqc_gen:largebinary(64*1024)])).
@ -54,7 +62,7 @@ v_iodata(Structure) -> v_iolist(Structure).
%% Generator for binaries of a given size with different properties and fault injection: %% Generator for binaries of a given size with different properties and fault injection:
g_binary(Sz) -> g_binary(Sz) ->
z_fault(g_binary_bad(Sz), g_binary_good(Sz)). ?FAULT(g_binary_bad(Sz), g_binary_good(Sz)).
g_binary_good(Sz) when Sz =< 32 -> binary(Sz); g_binary_good(Sz) when Sz =< 32 -> binary(Sz);
g_binary_good(Sz) -> eqc_gen:largebinary(Sz). g_binary_good(Sz) -> eqc_gen:largebinary(Sz).
@ -78,7 +86,7 @@ nonce_valid(N) -> v_binary(enacl:box_nonce_size(), N).
%% Generator of natural numbers %% Generator of natural numbers
g_nat() -> g_nat() ->
z_fault(g_nat_bad(), nat()). ?FAULT(g_nat_bad(), nat()).
g_nat_bad() -> g_nat_bad() ->
oneof([ oneof([
@ -110,7 +118,7 @@ keypair_bad() ->
end). end).
keypair() -> keypair() ->
z_fault(keypair_bad(), keypair_good()). ?FAULT(keypair_bad(), keypair_good()).
%% CRYPTO BOX %% CRYPTO BOX
%% --------------------------- %% ---------------------------
@ -162,10 +170,10 @@ failure(X) -> {failure, X}.
prop_box_correct() -> prop_box_correct() ->
?FORALL({Msg, Nonce, {PK1, SK1}, {PK2, SK2}}, ?FORALL({Msg, Nonce, {PK1, SK1}, {PK2, SK2}},
{z_fault_rate(1, 40, g_iodata()), {?FAULT_RATE(1, 40, g_iodata()),
z_fault_rate(1, 40, nonce()), ?FAULT_RATE(1, 40, nonce()),
z_fault_rate(1, 40, keypair()), ?FAULT_RATE(1, 40, keypair()),
z_fault_rate(1, 40, keypair())}, ?FAULT_RATE(1, 40, keypair())},
begin begin
case v_iodata(Msg) andalso nonce_valid(Nonce) andalso keypair_valid(PK1, SK1) andalso keypair_valid(PK2, SK2) of case v_iodata(Msg) andalso nonce_valid(Nonce) andalso keypair_valid(PK1, SK1) andalso keypair_valid(PK2, SK2) of
true -> true ->
@ -186,10 +194,10 @@ prop_box_correct() ->
prop_box_failure_integrity() -> prop_box_failure_integrity() ->
?FORALL({Msg, Nonce, {PK1, SK1}, {PK2, SK2}}, ?FORALL({Msg, Nonce, {PK1, SK1}, {PK2, SK2}},
{z_fault_rate(1, 40, g_iodata()), {?FAULT_RATE(1, 40, g_iodata()),
z_fault_rate(1, 40, nonce()), ?FAULT_RATE(1, 40, nonce()),
z_fault_rate(1, 40, keypair()), ?FAULT_RATE(1, 40, keypair()),
z_fault_rate(1, 40, keypair())}, ?FAULT_RATE(1, 40, keypair())},
begin begin
case v_iodata(Msg) case v_iodata(Msg)
andalso nonce_valid(Nonce) andalso nonce_valid(Nonce)
@ -211,7 +219,7 @@ prop_box_failure_integrity() ->
end). end).
prop_seal_box_failure_integrity() -> prop_seal_box_failure_integrity() ->
?FORALL({Msg, {PK1, SK1}}, {z_fault_rate(1,40,g_iodata()), z_fault_rate(1,40,keypair())}, ?FORALL({Msg, {PK1, SK1}}, {?FAULT_RATE(1,40,g_iodata()), ?FAULT_RATE(1,40,keypair())},
begin begin
case v_iodata(Msg) andalso keypair_valid(PK1, SK1) of case v_iodata(Msg) andalso keypair_valid(PK1, SK1) of
true -> true ->
@ -229,8 +237,8 @@ prop_seal_box_failure_integrity() ->
prop_seal_box_correct() -> prop_seal_box_correct() ->
?FORALL({Msg, {PK1, SK1}}, ?FORALL({Msg, {PK1, SK1}},
{z_fault_rate(1, 40, g_iodata()), {?FAULT_RATE(1, 40, g_iodata()),
z_fault_rate(1, 40, keypair())}, ?FAULT_RATE(1, 40, keypair())},
begin begin
case v_iodata(Msg) andalso keypair_valid(PK1, SK1) of case v_iodata(Msg) andalso keypair_valid(PK1, SK1) of
true -> true ->
@ -247,7 +255,7 @@ prop_seal_box_correct() ->
%% PRECOMPUTATIONS %% PRECOMPUTATIONS
beforenm_key() -> beforenm_key() ->
?LET([{PK1, SK1}, {PK2, SK2}], [z_fault_rate(1, 40, keypair()), z_fault_rate(1, 40, keypair())], ?LET([{PK1, SK1}, {PK2, SK2}], [?FAULT_RATE(1, 40, keypair()), ?FAULT_RATE(1, 40, keypair())],
case keypair_valid(PK1, SK1) andalso keypair_valid(PK2, SK2) of case keypair_valid(PK1, SK1) andalso keypair_valid(PK2, SK2) of
true -> true ->
enacl:box_beforenm(PK1, SK2); enacl:box_beforenm(PK1, SK2);
@ -263,7 +271,7 @@ v_key(K) when is_binary(K) -> byte_size(K) == enacl:box_beforenm_bytes();
v_key(_) -> false. v_key(_) -> false.
prop_beforenm_correct() -> prop_beforenm_correct() ->
?FORALL([{PK1, SK1}, {PK2, SK2}], [z_fault_rate(1, 40, keypair()), z_fault_rate(1, 40, keypair())], ?FORALL([{PK1, SK1}, {PK2, SK2}], [?FAULT_RATE(1, 40, keypair()), ?FAULT_RATE(1, 40, keypair())],
case keypair_valid(PK1, SK1) andalso keypair_valid(PK2, SK2) of case keypair_valid(PK1, SK1) andalso keypair_valid(PK2, SK2) of
true -> true ->
equals(enacl:box_beforenm(PK1, SK2), enacl:box_beforenm(PK2, SK1)); equals(enacl:box_beforenm(PK1, SK2), enacl:box_beforenm(PK2, SK1));
@ -276,9 +284,9 @@ prop_beforenm_correct() ->
prop_afternm_correct() -> prop_afternm_correct() ->
?FORALL([Msg, Nonce, Key], ?FORALL([Msg, Nonce, Key],
[z_fault_rate(1, 40, g_iodata()), [?FAULT_RATE(1, 40, g_iodata()),
z_fault_rate(1, 40, nonce()), ?FAULT_RATE(1, 40, nonce()),
z_fault_rate(1, 40, beforenm_key())], ?FAULT_RATE(1, 40, beforenm_key())],
begin begin
case v_iodata(Msg) andalso nonce_valid(Nonce) andalso v_key(Key) of case v_iodata(Msg) andalso nonce_valid(Nonce) andalso v_key(Key) of
true -> true ->
@ -329,7 +337,7 @@ sign_keypair_good() ->
return(enacl:sign_keypair()). return(enacl:sign_keypair()).
sign_keypair() -> sign_keypair() ->
z_fault(sign_keypair_bad(), sign_keypair_good()). ?FAULT(sign_keypair_bad(), sign_keypair_good()).
sign_keypair_public_valid(#{ public := Public }) sign_keypair_public_valid(#{ public := Public })
when is_binary(Public) -> when is_binary(Public) ->
@ -346,8 +354,8 @@ sign_keypair_valid(KP) ->
prop_sign_detached() -> prop_sign_detached() ->
?FORALL({Msg, KeyPair}, ?FORALL({Msg, KeyPair},
{z_fault_rate(1, 40, g_iodata()), {?FAULT_RATE(1, 40, g_iodata()),
z_fault_rate(1, 40, sign_keypair())}, ?FAULT_RATE(1, 40, sign_keypair())},
begin begin
case v_iodata(Msg) andalso sign_keypair_secret_valid(KeyPair) of case v_iodata(Msg) andalso sign_keypair_secret_valid(KeyPair) of
true -> true ->
@ -362,8 +370,8 @@ prop_sign_detached() ->
prop_sign() -> prop_sign() ->
?FORALL({Msg, KeyPair}, ?FORALL({Msg, KeyPair},
{z_fault_rate(1, 40, g_iodata()), {?FAULT_RATE(1, 40, g_iodata()),
z_fault_rate(1, 40, sign_keypair())}, ?FAULT_RATE(1, 40, sign_keypair())},
begin begin
case v_iodata(Msg) andalso sign_keypair_secret_valid(KeyPair) of case v_iodata(Msg) andalso sign_keypair_secret_valid(KeyPair) of
true -> true ->
@ -407,10 +415,10 @@ signed_message_bad_d() ->
{binary(), oneof([a, int(), ?SUCHTHAT(B, binary(Sz), byte_size(B) /= Sz)])}. {binary(), oneof([a, int(), ?SUCHTHAT(B, binary(Sz), byte_size(B) /= Sz)])}.
signed_message(M) -> signed_message(M) ->
z_fault(signed_message_bad(), signed_message_good(M)). ?FAULT(signed_message_bad(), signed_message_good(M)).
signed_message_d(M) -> signed_message_d(M) ->
z_fault(signed_message_bad(), signed_message_good(M)). ?FAULT(signed_message_bad(), signed_message_good(M)).
signed_message_valid({valid, _}, _) -> true; signed_message_valid({valid, _}, _) -> true;
signed_message_valid({invalid, _}, _) -> true; signed_message_valid({invalid, _}, _) -> true;
@ -478,7 +486,7 @@ secret_key_bad() ->
?SUCHTHAT(B, binary(), byte_size(B) /= enacl:secretbox_key_size())]). ?SUCHTHAT(B, binary(), byte_size(B) /= enacl:secretbox_key_size())]).
secret_key() -> secret_key() ->
z_fault(secret_key_bad(), secret_key_good()). ?FAULT(secret_key_bad(), secret_key_good()).
secret_key_valid(SK) when is_binary(SK) -> secret_key_valid(SK) when is_binary(SK) ->
Sz = enacl:secretbox_key_size(), Sz = enacl:secretbox_key_size(),
@ -501,9 +509,9 @@ secretbox_open(Msg, Nonce, Key) ->
prop_secretbox_correct() -> prop_secretbox_correct() ->
?FORALL({Msg, Nonce, Key}, ?FORALL({Msg, Nonce, Key},
{z_fault_rate(1, 40, g_iodata()), {?FAULT_RATE(1, 40, g_iodata()),
z_fault_rate(1, 40, nonce()), ?FAULT_RATE(1, 40, nonce()),
z_fault_rate(1, 40, secret_key())}, ?FAULT_RATE(1, 40, secret_key())},
begin begin
case v_iodata(Msg) andalso nonce_valid(Nonce) andalso secret_key_valid(Key) of case v_iodata(Msg) andalso nonce_valid(Nonce) andalso secret_key_valid(Key) of
true -> true ->
@ -531,8 +539,8 @@ prop_secretbox_failure_integrity() ->
prop_stream_correct() -> prop_stream_correct() ->
?FORALL({Len, Nonce, Key}, ?FORALL({Len, Nonce, Key},
{int(), {int(),
z_fault_rate(1, 40, nonce()), ?FAULT_RATE(1, 40, nonce()),
z_fault_rate(1, 40, secret_key())}, ?FAULT_RATE(1, 40, secret_key())},
case Len >= 0 andalso nonce_valid(Nonce) andalso secret_key_valid(Key) of case Len >= 0 andalso nonce_valid(Nonce) andalso secret_key_valid(Key) of
true -> true ->
CipherStream = enacl:stream(Len, Nonce, Key), CipherStream = enacl:stream(Len, Nonce, Key),
@ -547,9 +555,9 @@ xor_bytes(<<>>, <<>>) -> [].
%% prop_stream_xor_correct() -> %% prop_stream_xor_correct() ->
%% ?FORALL({Msg, Nonce, Key}, %% ?FORALL({Msg, Nonce, Key},
%% {z_fault_rate(1, 40, g_iodata()), %% {?FAULT_RATE(1, 40, g_iodata()),
%% z_fault_rate(1, 40, nonce()), %% ?FAULT_RATE(1, 40, nonce()),
%% z_fault_rate(1, 40, secret_key())}, %% ?FAULT_RATE(1, 40, secret_key())},
%% case v_iodata(Msg) andalso nonce_valid(Nonce) andalso secret_key_valid(Key) of %% case v_iodata(Msg) andalso nonce_valid(Nonce) andalso secret_key_valid(Key) of
%% true -> %% true ->
%% Stream = enacl:stream(iolist_size(Msg), Nonce, Key), %% Stream = enacl:stream(iolist_size(Msg), Nonce, Key),
@ -566,8 +574,8 @@ xor_bytes(<<>>, <<>>) -> [].
%% CRYPTO AUTH %% CRYPTO AUTH
prop_auth_correct() -> prop_auth_correct() ->
?FORALL({Msg, Key}, ?FORALL({Msg, Key},
{z_fault_rate(1, 40, g_iodata()), {?FAULT_RATE(1, 40, g_iodata()),
z_fault_rate(1, 40, secret_key())}, ?FAULT_RATE(1, 40, secret_key())},
case v_iodata(Msg) andalso secret_key_valid(Key) of case v_iodata(Msg) andalso secret_key_valid(Key) of
true -> true ->
Authenticator = enacl:auth(Msg, Key), Authenticator = enacl:auth(Msg, Key),
@ -592,7 +600,7 @@ authenticator_good(_Msg, _Key) ->
binary(enacl:auth_size()). binary(enacl:auth_size()).
authenticator(Msg, Key) -> authenticator(Msg, Key) ->
z_fault(authenticator_bad(), authenticator_good(Msg, Key)). ?FAULT(authenticator_bad(), authenticator_good(Msg, Key)).
authenticator_valid({valid, _}) -> true; authenticator_valid({valid, _}) -> true;
authenticator_valid({invalid, _}) -> true; authenticator_valid({invalid, _}) -> true;
@ -600,8 +608,8 @@ authenticator_valid(_) -> false.
prop_auth_verify_correct() -> prop_auth_verify_correct() ->
?FORALL({Msg, Key}, ?FORALL({Msg, Key},
{z_fault_rate(1, 40, g_iodata()), {?FAULT_RATE(1, 40, g_iodata()),
z_fault_rate(1, 40, secret_key())}, ?FAULT_RATE(1, 40, secret_key())},
?FORALL(Authenticator, authenticator(Msg, Key), ?FORALL(Authenticator, authenticator(Msg, Key),
case v_iodata(Msg) andalso secret_key_valid(Key) andalso authenticator_valid(Authenticator) of case v_iodata(Msg) andalso secret_key_valid(Key) andalso authenticator_valid(Authenticator) of
true -> true ->
@ -618,8 +626,8 @@ prop_auth_verify_correct() ->
%% CRYPTO ONETIME AUTH %% CRYPTO ONETIME AUTH
prop_onetimeauth_correct() -> prop_onetimeauth_correct() ->
?FORALL({Msg, Key}, ?FORALL({Msg, Key},
{z_fault_rate(1, 40, g_iodata()), {?FAULT_RATE(1, 40, g_iodata()),
z_fault_rate(1, 40, secret_key())}, ?FAULT_RATE(1, 40, secret_key())},
case v_iodata(Msg) andalso secret_key_valid(Key) of case v_iodata(Msg) andalso secret_key_valid(Key) of
true -> true ->
Authenticator = enacl:onetime_auth(Msg, Key), Authenticator = enacl:onetime_auth(Msg, Key),
@ -644,7 +652,7 @@ ot_authenticator_good(_Msg, _Key) ->
binary(enacl:auth_size()). binary(enacl:auth_size()).
ot_authenticator(Msg, Key) -> ot_authenticator(Msg, Key) ->
z_fault(ot_authenticator_bad(), ot_authenticator_good(Msg, Key)). ?FAULT(ot_authenticator_bad(), ot_authenticator_good(Msg, Key)).
ot_authenticator_valid({valid, _}) -> true; ot_authenticator_valid({valid, _}) -> true;
ot_authenticator_valid({invalid, _}) -> true; ot_authenticator_valid({invalid, _}) -> true;
@ -652,8 +660,8 @@ ot_authenticator_valid(_) -> false.
prop_onetime_auth_verify_correct() -> prop_onetime_auth_verify_correct() ->
?FORALL({Msg, Key}, ?FORALL({Msg, Key},
{z_fault_rate(1, 40, g_iodata()), {?FAULT_RATE(1, 40, g_iodata()),
z_fault_rate(1, 40, secret_key())}, ?FAULT_RATE(1, 40, secret_key())},
?FORALL(Authenticator, ot_authenticator(Msg, Key), ?FORALL(Authenticator, ot_authenticator(Msg, Key),
case v_iodata(Msg) andalso secret_key_valid(Key) andalso ot_authenticator_valid(Authenticator) of case v_iodata(Msg) andalso secret_key_valid(Key) andalso ot_authenticator_valid(Authenticator) of
true -> true ->
@ -710,7 +718,7 @@ verify_pair_good(Sz) ->
?SUCHTHAT({X, Y}, {binary(Sz), binary(Sz)}, X /= Y)]). ?SUCHTHAT({X, Y}, {binary(Sz), binary(Sz)}, X /= Y)]).
verify_pair(Sz) -> verify_pair(Sz) ->
z_fault(verify_pair_bad(Sz), verify_pair_good(Sz)). ?FAULT(verify_pair_bad(Sz), verify_pair_good(Sz)).
verify_pair_valid(Sz, X, Y) -> verify_pair_valid(Sz, X, Y) ->
byte_size(X) == Sz andalso byte_size(Y) == Sz. byte_size(X) == Sz andalso byte_size(Y) == Sz.