summaryrefslogtreecommitdiff
path: root/src/sign.erl
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2015-03-27 03:06:19 +0100
committerMagnus Ahltorp <map@kth.se>2015-03-27 03:06:19 +0100
commitee01d8235ce09e08fd0378f2b04d10bdb7d85f78 (patch)
tree5d2de258d53c0d87223c6ba34d8ece4c499bd58f /src/sign.erl
parenta4d44679ddaafdc0ba205746e8eb8850e07f5216 (diff)
Handle multiple signing nodesmultisign
Diffstat (limited to 'src/sign.erl')
-rw-r--r--src/sign.erl27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/sign.erl b/src/sign.erl
index 167987d..f252001 100644
--- a/src/sign.erl
+++ b/src/sign.erl
@@ -109,25 +109,30 @@ public_key(#'RSAPrivateKey'{modulus = Mod, publicExponent = Exp}) ->
#'RSAPublicKey'{modulus = Mod, publicExponent = Exp}.
-remote_sign_request(URL, Request) ->
+remote_sign_request([], _Request) ->
+ none;
+remote_sign_request([URL|RestURLs], Request) ->
case plop_httputil:request("signing", URL, [{"Content-Type", "text/json"}], list_to_binary(mochijson2:encode(Request))) of
+ {error, Error} ->
+ lager:info("request error: ~p", [Error]),
+ remote_sign_request(RestURLs, Request);
{failure, _StatusLine, _RespHeaders, _Body} ->
lager:debug("auth check failed"),
- none;
+ remote_sign_request(RestURLs, Request);
{success, {_HttpVersion, StatusCode, _ReasonPhrase}, _RespHeaders, Body} when StatusCode == 200 ->
lager:debug("auth check succeeded"),
case (catch mochijson2:decode(Body)) of
{error, E} ->
lager:error("json parse error: ~p", [E]),
- none;
+ remote_sign_request(RestURLs, Request);
{struct, PropList} ->
base64:decode(proplists:get_value(<<"result">>, PropList))
end;
{noauth, _StatusLine, _RespHeaders, _Body} ->
lager:debug("no auth"),
- none;
+ remote_sign_request(RestURLs, Request);
_ ->
- none
+ remote_sign_request(RestURLs, Request)
end.
%%%%%%%%%%%%%%%%%%%%
@@ -136,12 +141,12 @@ remote_sign_request(URL, Request) ->
sign_sct(Data = <<_Version:8,
?CERTIFICATE_TIMESTAMP:8,
_/binary>>) ->
- case application:get_env(plop, signing_node) of
- {ok, URLBase} ->
+ case application:get_env(plop, signing_nodes) of
+ {ok, URLBases} ->
Request = {[{plop_version, 1},
{data, base64:encode(Data)}
]},
- remote_sign_request(URLBase ++ "sct", Request);
+ remote_sign_request([URLBase ++ "sct" || URLBase <- URLBases], Request);
undefined ->
call(?MODULE, {sign, Data})
end.
@@ -149,12 +154,12 @@ sign_sct(Data = <<_Version:8,
sign_sth(Data = <<_Version:8,
?TREE_HASH:8,
_/binary>>) ->
- case application:get_env(plop, signing_node) of
- {ok, URLBase} ->
+ case application:get_env(plop, signing_nodes) of
+ {ok, URLBases} ->
Request = {[{plop_version, 1},
{data, base64:encode(Data)}
]},
- remote_sign_request(URLBase ++ "sth", Request);
+ remote_sign_request([URLBase ++ "sth" || URLBase <- URLBases], Request);
undefined ->
call(?MODULE, {sign, Data})
end.