mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-24 17:29:28 +01:00
Print validity in list-certificates
This commit is contained in:
parent
8fe551cc68
commit
2e18122cd9
@ -54,11 +54,40 @@ list_certificates(Verbose) ->
|
|||||||
{ok, Certs} = read_certificates_persistent(),
|
{ok, Certs} = read_certificates_persistent(),
|
||||||
case Verbose of
|
case Verbose of
|
||||||
"plain" ->
|
"plain" ->
|
||||||
[{Domain, certificate} || {Domain, _Cert} <- Certs];
|
[{Domain, certificate_metadata(PemCert)} || {Domain, PemCert} <- Certs];
|
||||||
"verbose" ->
|
"verbose" ->
|
||||||
Certs
|
Certs
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%% TODO: Make this cleaner and more secure
|
||||||
|
certificate_metadata(PemCert) ->
|
||||||
|
PemList = public_key:pem_decode(PemCert),
|
||||||
|
PemEntryCert = lists:keyfind('Certificate', 1, PemList),
|
||||||
|
#'Certificate'{tbsCertificate = #'TBSCertificate'{
|
||||||
|
subject = {rdnSequence, SubjectList},
|
||||||
|
validity = Validity}}
|
||||||
|
= public_key:pem_entry_decode(PemEntryCert),
|
||||||
|
|
||||||
|
%% Find the commonName
|
||||||
|
%% TODO: Not the best way to find the commonName
|
||||||
|
?INFO_MSG("Subject List: ~p", [SubjectList]),
|
||||||
|
ShallowSubjectList = [Attribute || [Attribute] <- SubjectList],
|
||||||
|
{_, _, CommonName} = lists:keyfind(attribute_oid(commonName), 2, ShallowSubjectList),
|
||||||
|
|
||||||
|
%% Find the notAfter date
|
||||||
|
%% TODO: Find a library function to decode utc time
|
||||||
|
#'Validity'{notAfter = {utcTime, UtcTime}} = Validity,
|
||||||
|
[Y1,Y2,MO1,MO2,D1,D2,H1,H2,MI1,MI2,S1,S2,$Z] = UtcTime,
|
||||||
|
YEAR = case list_to_integer([Y1,Y2]) >= 50 of
|
||||||
|
true -> "19" ++ [Y1,Y2];
|
||||||
|
_ -> "20" ++ [Y1,Y2]
|
||||||
|
end,
|
||||||
|
NotAfter = lists:flatten(io_lib:format("Valid until: ~s-~s-~s ~s:~s:~s",
|
||||||
|
[YEAR, [MO1,MO2], [D1,D2],
|
||||||
|
[H1,H2], [MI1,MI2], [S1,S2]])),
|
||||||
|
|
||||||
|
NotAfter.
|
||||||
|
|
||||||
%%
|
%%
|
||||||
%% Get Certificate
|
%% Get Certificate
|
||||||
%%
|
%%
|
||||||
@ -704,8 +733,7 @@ new_user_scenario(CAUrl, HttpDir) ->
|
|||||||
{ok, Authz3, Nonce7} = ejabberd_acme_comm:get_authz_until_valid({CAUrl, AuthzId}),
|
{ok, Authz3, Nonce7} = ejabberd_acme_comm:get_authz_until_valid({CAUrl, AuthzId}),
|
||||||
|
|
||||||
#{"new-cert" := NewCert} = Dirs,
|
#{"new-cert" := NewCert} = Dirs,
|
||||||
CSRSubject = [{commonName, bitstring_to_list(DomainName)},
|
CSRSubject = [{commonName, bitstring_to_list(DomainName)}],
|
||||||
{organizationName, "Example Corp"}],
|
|
||||||
{CSR, CSRKey} = make_csr(CSRSubject),
|
{CSR, CSRKey} = make_csr(CSRSubject),
|
||||||
{MegS, Sec, MicS} = erlang:timestamp(),
|
{MegS, Sec, MicS} = erlang:timestamp(),
|
||||||
NotBefore = xmpp_util:encode_timestamp({MegS-1, Sec, MicS}),
|
NotBefore = xmpp_util:encode_timestamp({MegS-1, Sec, MicS}),
|
||||||
|
Loading…
Reference in New Issue
Block a user