diff options
author | Magnus Ahltorp <map@kth.se> | 2017-01-20 00:30:36 +0100 |
---|---|---|
committer | Magnus Ahltorp <map@kth.se> | 2017-01-20 00:30:36 +0100 |
commit | 784f116ba3fad8e28ef2fefd86d5df71801dbe6f (patch) | |
tree | 409e53de64335664b2944baa1e1880b9f5565ece /src/plop_httputil.erl | |
parent | 109fc863b5ebec2d502c55df1f763c8f0ecb4722 (diff) |
API keys are now provided in config file
Also added CA cert verification for internal TLS connections.
Diffstat (limited to 'src/plop_httputil.erl')
-rw-r--r-- | src/plop_httputil.erl | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/plop_httputil.erl b/src/plop_httputil.erl index 37e25c1..af4a5d1 100644 --- a/src/plop_httputil.erl +++ b/src/plop_httputil.erl @@ -59,15 +59,25 @@ verify_fun(Cert, valid_peer, UserState) -> {valid, UserState} end. +read_and_verify_cacertfile(Filename) -> + {ok, PemBin} = file:read_file(Filename), + [KeyPem] = public_key:pem_decode(PemBin), + {'Certificate', Der, _} = KeyPem, + CalculatedHash = crypto:hash(sha256, Der), + CorrectHash = application:get_env(catlfish, https_cacert_fingerprint, none), + CorrectHash = CalculatedHash, + Der. + request(DebugTag, URL, Headers, RequestBody) -> Starttime = os:timestamp(), ParsedURL = hackney_url:parse_url(URL), CACertFile = application:get_env(catlfish, https_cacertfile, none), + CACert = read_and_verify_cacertfile(CACertFile), #hackney_url{path = Path, host = Host} = ParsedURL, lager:debug("~s: sending http request to ~p", [DebugTag, URL]), case hackney:connect(ParsedURL, - [{ssl_options, [{cacertfile, CACertFile}, + [{ssl_options, [{cacerts, [CACert]}, {verify, verify_peer}, {verify_fun, {fun verify_fun/3, [{check_hostname, Host}]}} |