summaryrefslogtreecommitdiff
path: root/lib/public_key/src/public_key.erl
diff options
context:
space:
mode:
authorDan Gudmundsson <dgud@erlang.org>2022-04-01 16:06:44 +0200
committerDan Gudmundsson <dgud@erlang.org>2022-04-28 14:55:41 +0200
commit8f0270a35d56954987331d7c2833802cf3a7058a (patch)
tree98b8215fabdf3e7168b47a166002df5f0e1dc4c7 /lib/public_key/src/public_key.erl
parente384b222ccde9706965052fba7e785fab3f2d093 (diff)
downloaderlang-8f0270a35d56954987331d7c2833802cf3a7058a.tar.gz
Add API for fetching os cacerts
API: load/0 load/1 and get/0 clear/0 Writes to persistent_term to cache the results, user can re-load cache with load/0 and load/1 functions. load/1 is made for users with an unsupported OS, or if they want to load the cache with data from another file.
Diffstat (limited to 'lib/public_key/src/public_key.erl')
-rw-r--r--lib/public_key/src/public_key.erl39
1 files changed, 38 insertions, 1 deletions
diff --git a/lib/public_key/src/public_key.erl b/lib/public_key/src/public_key.erl
index 14b6043286..beef5ed416 100644
--- a/lib/public_key/src/public_key.erl
+++ b/lib/public_key/src/public_key.erl
@@ -63,7 +63,11 @@
pkix_test_root_cert/2,
pkix_ocsp_validate/5,
ocsp_responder_id/1,
- ocsp_extensions/1
+ ocsp_extensions/1,
+ cacerts_get/0,
+ cacerts_load/0,
+ cacerts_load/1,
+ cacerts_clear/0
]).
%%----------------
@@ -1399,6 +1403,39 @@ ocsp_responder_id(Cert) ->
pubkey_ocsp:get_ocsp_responder_id(Cert).
%%--------------------------------------------------------------------
+-spec cacerts_get() -> [combined_cert()].
+%%
+%% Description: Get loaded cacerts, if none are loaded it will try to
+%% load OS provided cacerts
+%%--------------------------------------------------------------------
+cacerts_get() ->
+ pubkey_os_cacerts:get().
+
+%%--------------------------------------------------------------------
+-spec cacerts_load() -> ok | {error, Reason::term()}.
+%%
+%% Description: (Re)Load OS provided cacerts
+%%--------------------------------------------------------------------
+cacerts_load() ->
+ pubkey_os_cacerts:load().
+
+%%--------------------------------------------------------------------
+-spec cacerts_load(File::file:filename_all()) -> ok | {error, Reason::term()}.
+%%
+%% Description: (Re)Load cacerts from a file
+%%--------------------------------------------------------------------
+cacerts_load(File) ->
+ pubkey_os_cacerts:load([File]).
+
+%%--------------------------------------------------------------------
+-spec cacerts_clear() -> boolean().
+%%
+%% Description: Clears loaded cacerts, returns true if any was loaded.
+%%--------------------------------------------------------------------
+cacerts_clear() ->
+ pubkey_os_cacerts:clear().
+
+%%--------------------------------------------------------------------
%%% Internal functions
%%--------------------------------------------------------------------
default_options([]) ->