|
|
@@ -883,13 +883,17 @@ gen_point(Type, Name, Path) ->
|
|
|
%% TODO: cert manager for more generic utils functions
|
|
|
cert_expiry_at_from_path(Path0) ->
|
|
|
Path = emqx_schema:naive_env_interpolation(Path0),
|
|
|
- {ok, PemBin} = file:read_file(Path),
|
|
|
- [CertEntry | _] = public_key:pem_decode(PemBin),
|
|
|
- Cert = public_key:pem_entry_decode(CertEntry),
|
|
|
- %% TODO: Not fully tested for all certs type
|
|
|
- {'utcTime', NotAfterUtc} =
|
|
|
- Cert#'Certificate'.'tbsCertificate'#'TBSCertificate'.validity#'Validity'.'notAfter',
|
|
|
- utc_time_to_epoch(NotAfterUtc).
|
|
|
+ case file:read_file(Path) of
|
|
|
+ {ok, PemBin} ->
|
|
|
+ [CertEntry | _] = public_key:pem_decode(PemBin),
|
|
|
+ Cert = public_key:pem_entry_decode(CertEntry),
|
|
|
+ %% TODO: Not fully tested for all certs type
|
|
|
+ {'utcTime', NotAfterUtc} =
|
|
|
+ Cert#'Certificate'.'tbsCertificate'#'TBSCertificate'.validity#'Validity'.'notAfter',
|
|
|
+ utc_time_to_epoch(NotAfterUtc);
|
|
|
+ {error, _} ->
|
|
|
+ 0
|
|
|
+ end.
|
|
|
|
|
|
utc_time_to_epoch(UtcTime) ->
|
|
|
date_to_expiry_epoch(utc_time_to_datetime(UtcTime)).
|
|
|
@@ -898,7 +902,7 @@ utc_time_to_datetime(Str) ->
|
|
|
{ok, [Year, Month, Day, Hour, Minute, Second], _} = io_lib:fread(
|
|
|
"~2d~2d~2d~2d~2d~2dZ", Str
|
|
|
),
|
|
|
- %% Alwoys Assuming YY is in 2000
|
|
|
+ %% Always Assuming YY is in 2000
|
|
|
{{2000 + Year, Month, Day}, {Hour, Minute, Second}}.
|
|
|
|
|
|
%% 62167219200 =:= calendar:datetime_to_gregorian_seconds({{1970, 1, 1}, {0, 0, 0}}).
|