summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2015-08-31 17:44:24 +0200
committerLinus Nordberg <linus@nordu.net>2015-08-31 17:44:24 +0200
commit24c8ad943a02132944677423e0c5d455d279620e (patch)
tree1b91f03522582912b4ef50335cc1bee80be1e1e4
parent6059a954b88317e4044ccada1a040a2c29863440 (diff)
Handle hsmhelper port crashes by restarting the signing gen_server.
Match on exit_status messages and return stop. Timeout on receive and return stop.
-rw-r--r--src/sign.erl11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/sign.erl b/src/sign.erl
index 07c5047..5949ad1 100644
--- a/src/sign.erl
+++ b/src/sign.erl
@@ -51,6 +51,7 @@ init([]) ->
Port = open_port({spawn_executable,
code:priv_dir(plop) ++ "/hsmhelper"},
[{args, Args},
+ exit_status,
{packet, 4}]),
{ok, #state{pubkey = Public_key,
hsmport = Port,
@@ -234,6 +235,14 @@ handle_call({sign, Data}, _From, State) ->
{Port, {data, RawSignature}} when is_port(Port) ->
Signature = encode_ec_signature(list_to_binary(RawSignature), 256),
lager:debug("received signing reply from HSM: ~p", [Signature]),
- {reply, Signature, State}
+ {reply, Signature, State};
+ {Port, {exit_status, ExitStatus}} ->
+ lager:error("hsmhelper port ~p exiting with status ~p",
+ [Port, ExitStatus]),
+ {stop, portexit, State}
+ after
+ 10000 ->
+ lager:error("HSM timeout"),
+ {stop, timeout, State}
end
end.