mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-12 21:52:07 +02:00
Implement verbose list_certificates option
This commit is contained in:
parent
3abe3aeeec
commit
ac7105d39e
|
@ -248,16 +248,11 @@ list_certificates(Verbose) ->
|
||||||
-spec list_certificates0(verbose_opt()) -> [string()] | [any()].
|
-spec list_certificates0(verbose_opt()) -> [string()] | [any()].
|
||||||
list_certificates0(Verbose) ->
|
list_certificates0(Verbose) ->
|
||||||
Certs = read_certificates_persistent(),
|
Certs = read_certificates_persistent(),
|
||||||
case Verbose of
|
[format_certificate(DataCert, Verbose) || {_Key, DataCert} <- Certs].
|
||||||
"plain" ->
|
|
||||||
[format_certificate(DataCert) || {_Key, DataCert} <- Certs];
|
|
||||||
"verbose" ->
|
|
||||||
Certs
|
|
||||||
end.
|
|
||||||
|
|
||||||
%% TODO: Make this cleaner and more robust
|
%% TODO: Make this cleaner and more robust
|
||||||
-spec format_certificate(data_cert()) -> string().
|
-spec format_certificate(data_cert(), verbose_opt()) -> string().
|
||||||
format_certificate(DataCert) ->
|
format_certificate(DataCert, Verbose) ->
|
||||||
#data_cert{
|
#data_cert{
|
||||||
domain = DomainName,
|
domain = DomainName,
|
||||||
pem = PemCert,
|
pem = PemCert,
|
||||||
|
@ -274,10 +269,15 @@ format_certificate(DataCert) ->
|
||||||
%% Find the notAfter date
|
%% Find the notAfter date
|
||||||
NotAfter = get_notAfter(Certificate),
|
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().
|
-spec format_certificate_plain(bitstring(), string(), string()) -> string().
|
||||||
format_certificate1(DomainName, NotAfter, Path) ->
|
format_certificate_plain(DomainName, NotAfter, Path) ->
|
||||||
Result = lists:flatten(io_lib:format(
|
Result = lists:flatten(io_lib:format(
|
||||||
" Domain: ~s~n"
|
" Domain: ~s~n"
|
||||||
" Valid until: ~s UTC~n"
|
" Valid until: ~s UTC~n"
|
||||||
|
@ -285,6 +285,15 @@ format_certificate1(DomainName, NotAfter, Path) ->
|
||||||
[DomainName, NotAfter, Path])),
|
[DomainName, NotAfter, Path])),
|
||||||
Result.
|
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().
|
-spec get_commonName(#'Certificate'{}) -> string().
|
||||||
get_commonName(#'Certificate'{tbsCertificate = TbsCertificate}) ->
|
get_commonName(#'Certificate'{tbsCertificate = TbsCertificate}) ->
|
||||||
#'TBSCertificate'{
|
#'TBSCertificate'{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user