Fix unicode formatting in ACME module

This commit is contained in:
Evgeny Khramtsov 2019-09-22 20:11:54 +03:00
parent faefad746e
commit 2e1e128833
2 changed files with 33 additions and 33 deletions

View File

@ -34,7 +34,7 @@
{jose, ".*", {git, "https://github.com/potatosalad/erlang-jose", {tag, "1.8.4"}}}, {jose, ".*", {git, "https://github.com/potatosalad/erlang-jose", {tag, "1.8.4"}}},
{eimp, ".*", {git, "https://github.com/processone/eimp", {tag, "1.0.12"}}}, {eimp, ".*", {git, "https://github.com/processone/eimp", {tag, "1.0.12"}}},
{mqtree, ".*", {git, "https://github.com/processone/mqtree", {tag, "1.0.4"}}}, {mqtree, ".*", {git, "https://github.com/processone/mqtree", {tag, "1.0.4"}}},
{acme, ".*", {git, "https://github.com/processone/acme.git", "be6405c"}}, {acme, ".*", {git, "https://github.com/processone/acme.git", "84c9534"}},
{if_var_true, stun, {stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.0.29"}}}}, {if_var_true, stun, {stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.0.29"}}}},
{if_var_true, sip, {esip, ".*", {git, "https://github.com/processone/esip", {tag, "1.0.30"}}}}, {if_var_true, sip, {esip, ".*", {git, "https://github.com/processone/esip", {tag, "1.0.30"}}}},
{if_var_true, mysql, {p1_mysql, ".*", {git, "https://github.com/processone/p1_mysql", {if_var_true, mysql, {p1_mysql, ".*", {git, "https://github.com/processone/p1_mysql",

View File

@ -112,12 +112,12 @@ init([]) ->
{ok, #state{}}. {ok, #state{}}.
handle_call({request, [_|_] = Domains}, _From, State) -> handle_call({request, [_|_] = Domains}, _From, State) ->
?INFO_MSG("Requesting new certificate for ~s from ~s", ?INFO_MSG("Requesting new certificate for ~ts from ~s",
[misc:format_hosts_list(Domains), directory_url()]), [misc:format_hosts_list(Domains), directory_url()]),
{Ret, State1} = issue_request(State, Domains), {Ret, State1} = issue_request(State, Domains),
{reply, Ret, State1}; {reply, Ret, State1};
handle_call({revoke, Cert, Key, Path}, _From, State) -> handle_call({revoke, Cert, Key, Path}, _From, State) ->
?INFO_MSG("Revoking certificate from file ~s", [Path]), ?INFO_MSG("Revoking certificate from file ~ts", [Path]),
{Ret, State1} = revoke_request(State, Cert, Key, Path), {Ret, State1} = revoke_request(State, Cert, Key, Path),
{reply, Ret, State1}; {reply, Ret, State1};
handle_call(Request, From, State) -> handle_call(Request, From, State) ->
@ -127,7 +127,7 @@ handle_call(Request, From, State) ->
handle_cast(ejabberd_started, State) -> handle_cast(ejabberd_started, State) ->
case request_on_start() of case request_on_start() of
{true, Domains} -> {true, Domains} ->
?INFO_MSG("Requesting new certificate for ~s from ~s", ?INFO_MSG("Requesting new certificate for ~ts from ~s",
[misc:format_hosts_list(Domains), directory_url()]), [misc:format_hosts_list(Domains), directory_url()]),
{_, State1} = issue_request(State, Domains), {_, State1} = issue_request(State, Domains),
{noreply, State1}; {noreply, State1};
@ -135,7 +135,7 @@ handle_cast(ejabberd_started, State) ->
{noreply, State} {noreply, State}
end; end;
handle_cast({request, [_|_] = Domains}, State) -> handle_cast({request, [_|_] = Domains}, State) ->
?INFO_MSG("Requesting renewal of certificate for ~s from ~s", ?INFO_MSG("Requesting renewal of certificate for ~ts from ~s",
[misc:format_hosts_list(Domains), directory_url()]), [misc:format_hosts_list(Domains), directory_url()]),
{_, State1} = issue_request(State, Domains), {_, State1} = issue_request(State, Domains),
{noreply, State1}; {noreply, State1};
@ -203,13 +203,13 @@ issue_request(State, Domains) ->
CertType = maps:get(cert_type, Config, rsa), CertType = maps:get(cert_type, Config, rsa),
issue_request(State, DirURL, Domains, AsciiDomains, AccKey, CertType, Contact); issue_request(State, DirURL, Domains, AsciiDomains, AccKey, CertType, Contact);
{error, Reason} = Err -> {error, Reason} = Err ->
?ERROR_MSG("Failed to request certificate for ~s: ~s", ?ERROR_MSG("Failed to request certificate for ~ts: ~ts",
[misc:format_hosts_list(Domains), [misc:format_hosts_list(Domains),
format_error(Reason)]), format_error(Reason)]),
{Err, State} {Err, State}
end; end;
{error, Reason} = Err -> {error, Reason} = Err ->
?ERROR_MSG("Failed to request certificate for ~s: ~s", ?ERROR_MSG("Failed to request certificate for ~ts: ~ts",
[misc:format_hosts_list(Domains), [misc:format_hosts_list(Domains),
format_error(Reason)]), format_error(Reason)]),
{Err, State} {Err, State}
@ -231,18 +231,18 @@ issue_request(State, DirURL, Domains, AsciiDomains, AccKey, CertType, Contact) -
{ok, Path} -> {ok, Path} ->
ejabberd_pkix:add_certfile(Path), ejabberd_pkix:add_certfile(Path),
ejabberd_pkix:commit(), ejabberd_pkix:commit(),
?INFO_MSG("Certificate for ~s has been received, " ?INFO_MSG("Certificate for ~ts has been received, "
"stored and loaded successfully", "stored and loaded successfully",
[misc:format_hosts_list(Domains)]), [misc:format_hosts_list(Domains)]),
{ok, State}; {ok, State};
{error, Reason} = Err -> {error, Reason} = Err ->
?ERROR_MSG("Failed to store certificate for ~s: ~s", ?ERROR_MSG("Failed to store certificate for ~ts: ~ts",
[misc:format_hosts_list(Domains), [misc:format_hosts_list(Domains),
format_error(Reason)]), format_error(Reason)]),
{Err, State} {Err, State}
end; end;
{error, Reason} = Err -> {error, Reason} = Err ->
?ERROR_MSG("Failed to request certificate for ~s: ~s", ?ERROR_MSG("Failed to request certificate for ~ts: ~ts",
[misc:format_hosts_list(Domains), [misc:format_hosts_list(Domains),
format_error(Reason)]), format_error(Reason)]),
{Err, State} {Err, State}
@ -257,7 +257,7 @@ revoke_request(State, Cert, Key, Path) ->
case acme:revoke(directory_url(), Cert, Key, case acme:revoke(directory_url(), Cert, Key,
[{debug_fun, debug_fun()}]) of [{debug_fun, debug_fun()}]) of
ok -> ok ->
?INFO_MSG("Certificate from file ~s has been " ?INFO_MSG("Certificate from file ~ts has been "
"revoked successfully", [Path]), "revoked successfully", [Path]),
case delete_file(Path) of case delete_file(Path) of
ok -> ok ->
@ -268,7 +268,7 @@ revoke_request(State, Cert, Key, Path) ->
{Err, State} {Err, State}
end; end;
{error, Reason} = Err -> {error, Reason} = Err ->
?ERROR_MSG("Failed to revoke certificate from file ~s: ~s", ?ERROR_MSG("Failed to revoke certificate from file ~ts: ~ts",
[Path, format_error(Reason)]), [Path, format_error(Reason)]),
{Err, State} {Err, State}
end. end.
@ -313,36 +313,36 @@ read_account_key() ->
case maps:keys(KeyMap) of case maps:keys(KeyMap) of
[#'ECPrivateKey'{} = Key|_] -> {ok, Key}; [#'ECPrivateKey'{} = Key|_] -> {ok, Key};
_ -> _ ->
?WARNING_MSG("File ~s doesn't contain ACME account key. " ?WARNING_MSG("File ~ts doesn't contain ACME account key. "
"Trying to create a new one...", "Trying to create a new one...",
[prep_path(Path)]), [Path]),
create_account_key() create_account_key()
end; end;
{error, enoent} -> {error, enoent} ->
create_account_key(); create_account_key();
{error, {bad_cert, _, _} = Reason} -> {error, {bad_cert, _, _} = Reason} ->
?WARNING_MSG("ACME account key from '~s' is corrupted: ~s. " ?WARNING_MSG("ACME account key from '~ts' is corrupted: ~s. "
"Trying to create a new one...", "Trying to create a new one...",
[prep_path(Path), pkix:format_error(Reason)]), [Path, pkix:format_error(Reason)]),
create_account_key(); create_account_key();
{error, Reason} -> {error, Reason} ->
?ERROR_MSG("Failed to read ACME account from ~s: ~s. " ?ERROR_MSG("Failed to read ACME account from ~ts: ~s. "
"Try to fix permissions or delete the file completely", "Try to fix permissions or delete the file completely",
[prep_path(Path), pkix:format_error(Reason)]), [Path, pkix:format_error(Reason)]),
{error, {file, Reason}} {error, {file, Reason}}
end. end.
-spec create_account_key() -> {ok, #'ECPrivateKey'{}} | {error, {file, io_error()}}. -spec create_account_key() -> {ok, #'ECPrivateKey'{}} | {error, {file, io_error()}}.
create_account_key() -> create_account_key() ->
Path = account_file(), Path = account_file(),
?DEBUG("Creating ACME account key in ~s", [prep_path(Path)]), ?DEBUG("Creating ACME account key in ~ts", [Path]),
Key = acme:generate_key(ec), Key = acme:generate_key(ec),
DER = public_key:der_encode(element(1, Key), Key), DER = public_key:der_encode(element(1, Key), Key),
PEM = public_key:pem_encode([{element(1, Key), DER, not_encrypted}]), PEM = public_key:pem_encode([{element(1, Key), DER, not_encrypted}]),
case write_file(Path, PEM) of case write_file(Path, PEM) of
ok -> ok ->
?DEBUG("ACME account key has been created successfully in ~s", ?DEBUG("ACME account key has been created successfully in ~ts",
[prep_path(Path)]), [Path]),
{ok, Key}; {ok, Key};
{error, Reason} -> {error, Reason} ->
{error, {file, Reason}} {error, {file, Reason}}
@ -361,8 +361,8 @@ store_cert(Key, Chain, CertType, Domains) ->
end, Chain), end, Chain),
PEM = public_key:pem_encode(PemChain ++ PemKey), PEM = public_key:pem_encode(PemChain ++ PemKey),
Path = cert_file(CertType, Domains), Path = cert_file(CertType, Domains),
?DEBUG("Storing certificate for ~s in ~s", ?DEBUG("Storing certificate for ~ts in ~ts",
[misc:format_hosts_list(Domains), prep_path(Path)]), [misc:format_hosts_list(Domains), Path]),
case write_file(Path, PEM) of case write_file(Path, PEM) of
ok -> ok ->
{ok, Path}; {ok, Path};
@ -375,7 +375,7 @@ store_cert(Key, Chain, CertType, Domains) ->
{bad_cert, _, _} | {bad_cert, _, _} |
unexpected_certfile}. unexpected_certfile}.
read_cert(Path) -> read_cert(Path) ->
?DEBUG("Reading certificate from ~s", [prep_path(Path)]), ?DEBUG("Reading certificate from ~ts", [Path]),
case pkix:read_file(Path) of case pkix:read_file(Path) of
{ok, CertsMap, KeysMap} -> {ok, CertsMap, KeysMap} ->
case {maps:to_list(CertsMap), maps:keys(KeysMap)} of case {maps:to_list(CertsMap), maps:keys(KeysMap)} of
@ -399,12 +399,12 @@ write_file(Path, Data) ->
case file:change_mode(Path, 8#600) of case file:change_mode(Path, 8#600) of
ok -> ok; ok -> ok;
{error, Why} -> {error, Why} ->
?WARNING_MSG("Failed to change permissions of ~s: ~s", ?WARNING_MSG("Failed to change permissions of ~ts: ~s",
[prep_path(Path), file:format_error(Why)]) [Path, file:format_error(Why)])
end; end;
{error, Why} = Err -> {error, Why} = Err ->
?ERROR_MSG("Failed to write file ~s: ~s", ?ERROR_MSG("Failed to write file ~ts: ~s",
[prep_path(Path), file:format_error(Why)]), [Path, file:format_error(Why)]),
Err Err
end; end;
Err -> Err ->
@ -416,8 +416,8 @@ delete_file(Path) ->
case file:delete(Path) of case file:delete(Path) of
ok -> ok; ok -> ok;
{error, Why} = Err -> {error, Why} = Err ->
?WARNING_MSG("Failed to delete file ~s: ~s", ?WARNING_MSG("Failed to delete file ~ts: ~s",
[prep_path(Path), file:format_error(Why)]), [Path, file:format_error(Why)]),
Err Err
end. end.
@ -426,8 +426,8 @@ ensure_dir(Path) ->
case filelib:ensure_dir(Path) of case filelib:ensure_dir(Path) of
ok -> ok; ok -> ok;
{error, Why} = Err -> {error, Why} = Err ->
?ERROR_MSG("Failed to create directory ~s: ~s", ?ERROR_MSG("Failed to create directory ~ts: ~s",
[prep_path(filename:dirname(Path)), [filename:dirname(Path),
file:format_error(Why)]), file:format_error(Why)]),
Err Err
end. end.
@ -437,7 +437,7 @@ delete_obsolete_data() ->
Path = filename:join(ejabberd_pkix:certs_dir(), "acme"), Path = filename:join(ejabberd_pkix:certs_dir(), "acme"),
case filelib:is_dir(Path) of case filelib:is_dir(Path) of
true -> true ->
?INFO_MSG("Deleting obsolete directory ~s", [prep_path(Path)]), ?INFO_MSG("Deleting obsolete directory ~ts", [Path]),
_ = misc:delete_dir(Path), _ = misc:delete_dir(Path),
ok; ok;
false -> false ->