From 71a95b89f9e7c51fd97d79ab73a2c1213ab1c641 Mon Sep 17 00:00:00 2001 From: Magnus Ahltorp Date: Tue, 7 Apr 2015 14:17:51 +0200 Subject: Only spawn one verifycert process --- verifycert.erl | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) (limited to 'verifycert.erl') diff --git a/verifycert.erl b/verifycert.erl index 2fafca9..e501d6d 100755 --- a/verifycert.erl +++ b/verifycert.erl @@ -1,15 +1,41 @@ #!/usr/bin/env escript %% -*- erlang -*- -%%! -pa ebin -pa lib/catlfish-0.2.0-dev.ez/catlfish-0.2.0-dev/ebin -pa lib/lager-2.0.3.ez/lager-2.0.3/ebin +%%! -pa ebin -pa lib/catlfish-0.2.0-dev.ez/catlfish-0.2.0-dev/ebin -pa lib/lager-2.1.1.ez/lager-2.1.1/ebin + +write_reply(Bin) -> + Length = size(Bin), + file:write(standard_io, <>). + +verify(Certs, DBEntry) -> + try + Chain = catlfish:chain_from_entry(DBEntry), + %% XXX: doesn't verify that MTL is derived from Chain + case x509:normalise_chain(Certs, Chain) of + {ok, _} -> + write_reply(<<0:8>>); + {error, Reason} -> + ReasonBin = list_to_binary(io_lib:format("~p", [Reason])), + write_reply(<<1:8, ReasonBin/binary>>) + end + catch + Type:What -> + [CrashFunction | Stack] = erlang:get_stacktrace(), + ErrorBin = list_to_binary(io_lib:format("Crash: ~p ~p~n~p~n~p~n", [Type, What, CrashFunction, Stack])), + write_reply(<<2:8, ErrorBin/binary>>) + end. + +loop(Certs) -> + {ok, LengthBin} = file:read(standard_io, 4), + <> = list_to_binary(LengthBin), + case Length of + 0 -> + none; + _ -> + {ok, DBEntry} = file:read(standard_io, Length), + verify(Certs, list_to_binary(DBEntry)), + loop(Certs) + end. main(_) -> - {ok, DBEntry} = file:read(standard_io, 100000), - %io:format("~p~n", [DBEntry]), Certs = x509:read_pemfiles_from_dir("tests/known_roots/"), - Chain = catlfish:chain_from_entry(list_to_binary(DBEntry)), - case x509:normalise_chain(Certs, Chain) of - {ok, _} -> - io:format("ok~n", []); - {error, Reason} -> - io:format("error: ~p~n", [Reason]) - end. + loop(Certs). -- cgit v1.1