25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

Add acme certificates for all configured hosts in ejabberd_pkix

This commit is contained in:
Konstantinos Kallas 2017-08-19 12:50:40 +03:00
parent ddfe8742c7
commit 7cc7b74f1e
2 changed files with 39 additions and 9 deletions

View File

@ -10,6 +10,8 @@
is_valid_verbose_opt/1, is_valid_verbose_opt/1,
is_valid_domain_opt/1, is_valid_domain_opt/1,
is_valid_revoke_cert/1, is_valid_revoke_cert/1,
%% Called by ejabberd_pkix
certificate_exists/1,
%% Key Related %% Key Related
generate_key/0, generate_key/0,
to_public/1 to_public/1
@ -539,6 +541,25 @@ domain_certificate_exists(Domain) ->
lists:keyfind(Domain, 1, Certs). lists:keyfind(Domain, 1, Certs).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
%% Called by ejabberd_pkix to check
%% if a certificate exists for a
%% specific host
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec certificate_exists(bitstring()) -> {true, file:filename()} | false.
certificate_exists(Host) ->
Certificates = read_certificates_persistent(),
case lists:keyfind(Host, 1 , Certificates) of
false ->
false;
{Host, #data_cert{path=Path}} ->
{true, Path}
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%
%% Certificate Request Functions %% Certificate Request Functions

View File

@ -204,6 +204,7 @@ add_certfiles(State) ->
end, State, ejabberd_config:get_myhosts()). end, State, ejabberd_config:get_myhosts()).
add_certfiles(Host, State) -> add_certfiles(Host, State) ->
NewState =
lists:foldl( lists:foldl(
fun(Opt, AccState) -> fun(Opt, AccState) ->
case ejabberd_config:get_option({Opt, Host}) of case ejabberd_config:get_option({Opt, Host}) of
@ -212,7 +213,15 @@ add_certfiles(Host, State) ->
{_, NewAccState} = add_certfile(Path, AccState), {_, NewAccState} = add_certfile(Path, AccState),
NewAccState NewAccState
end end
end, State, [c2s_certfile, s2s_certfile, domain_certfile]). end, State, [c2s_certfile, s2s_certfile, domain_certfile]),
%% Add acme certificate if it exists
case ejabberd_acme:certificate_exists(Host) of
{true, Path} ->
{_, FinalState} = add_certfile(Path, NewState),
FinalState;
false ->
NewState
end.
add_certfile(Path, State) -> add_certfile(Path, State) ->
case maps:get(Path, State#state.certs, undefined) of case maps:get(Path, State#state.certs, undefined) of