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

Implement verbose list_certificates option

This commit is contained in:
Konstantinos Kallas 2017-08-02 19:36:11 +03:00
parent 3abe3aeeec
commit ac7105d39e

View File

@ -248,16 +248,11 @@ list_certificates(Verbose) ->
-spec list_certificates0(verbose_opt()) -> [string()] | [any()].
list_certificates0(Verbose) ->
Certs = read_certificates_persistent(),
case Verbose of
"plain" ->
[format_certificate(DataCert) || {_Key, DataCert} <- Certs];
"verbose" ->
Certs
end.
[format_certificate(DataCert, Verbose) || {_Key, DataCert} <- Certs].
%% TODO: Make this cleaner and more robust
-spec format_certificate(data_cert()) -> string().
format_certificate(DataCert) ->
-spec format_certificate(data_cert(), verbose_opt()) -> string().
format_certificate(DataCert, Verbose) ->
#data_cert{
domain = DomainName,
pem = PemCert,
@ -274,10 +269,15 @@ format_certificate(DataCert) ->
%% Find the notAfter date
NotAfter = get_notAfter(Certificate),
format_certificate1(DomainName, NotAfter, Path).
case Verbose of
"plain" ->
format_certificate_plain(DomainName, NotAfter, Path);
"verbose" ->
format_certificate_verbose(DomainName, NotAfter, PemCert)
end.
-spec format_certificate1(bitstring(), string(), string()) -> string().
format_certificate1(DomainName, NotAfter, Path) ->
-spec format_certificate_plain(bitstring(), string(), string()) -> string().
format_certificate_plain(DomainName, NotAfter, Path) ->
Result = lists:flatten(io_lib:format(
" Domain: ~s~n"
" Valid until: ~s UTC~n"
@ -285,6 +285,15 @@ format_certificate1(DomainName, NotAfter, Path) ->
[DomainName, NotAfter, Path])),
Result.
-spec format_certificate_verbose(bitstring(), string(), bitstring()) -> string().
format_certificate_verbose(DomainName, NotAfter, PemCert) ->
Result = lists:flatten(io_lib:format(
" Domain: ~s~n"
" Valid until: ~s UTC~n"
" Certificate In PEM format: ~n~s",
[DomainName, NotAfter, PemCert])),
Result.
-spec get_commonName(#'Certificate'{}) -> string().
get_commonName(#'Certificate'{tbsCertificate = TbsCertificate}) ->
#'TBSCertificate'{