|
1 | 1 | -module(uaa_jwks).
|
2 |
| --export([get/2]). |
| 2 | +-export([get/2, ssl_options/1]). |
3 | 3 |
|
4 | 4 | -spec get(string() | binary(), term()) -> {ok, term()} | {error, term()}.
|
5 |
| -get(JwksUrl, KeyConfig) -> |
6 |
| - httpc:request(get, {JwksUrl, []}, [{ssl, ssl_options(KeyConfig)}, {timeout, 60000}], []). |
| 5 | +get(JwksUrl, SslOptions) -> |
| 6 | + Options = [{timeout, 60000}] ++ [{ssl, SslOptions}], |
| 7 | + rabbit_log:debug("get signing keys using options ~p", Options), |
| 8 | + httpc:request(get, {JwksUrl, []}, Options, []). |
| 9 | + |
| 10 | +-spec ssl_options(term()) -> list(). |
| 11 | +ssl_options(KeyConfig) -> |
| 12 | + PeerVerification = proplists:get_value(peer_verification, KeyConfig, verify_none), |
| 13 | + Depth = proplists:get_value(depth, KeyConfig, 10), |
| 14 | + FailIfNoPeerCert = proplists:get_value(fail_if_no_peer_cert, KeyConfig, false), |
| 15 | + CrlCheck = proplists:get_value(crl_check, KeyConfig, false), |
| 16 | + SslOpts0 = [{verify, PeerVerification}, |
| 17 | + {depth, Depth}, |
| 18 | + {fail_if_no_peer_cert, FailIfNoPeerCert}, |
| 19 | + {crl_check, CrlCheck}, |
| 20 | + {crl_cache, {ssl_crl_cache, {internal, [{http, 10000}]}}} | cacertfile(KeyConfig)], |
| 21 | + |
| 22 | + case proplists:get_value(hostname_verification, KeyConfig, none) of |
| 23 | + wildcard -> |
| 24 | + [{customize_hostname_check, [{match_fun, public_key:pkix_verify_hostname_match_fun(https)}]} | SslOpts0]; |
| 25 | + none -> |
| 26 | + SslOpts0 |
| 27 | + end. |
| 28 | + |
| 29 | +cacertfile(KeyConfig) -> |
| 30 | + case proplists:get_value(cacertfile, KeyConfig) of |
| 31 | + undefined -> []; |
| 32 | + CaCertFile -> [{cacertfile, CaCertFile}] |
| 33 | + end. |
0 commit comments