mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 16:37:47 +00:00
LibCrypto: Store ASN1 certificate timestamps as UnixDateTime
We are currently using Core::DateTime, which is meant to represent local time. However, we are doing no conversion between the parsed time in UTC and local time, so we end up comparing time stamps from different time zones. Instead, store the parsed times as UnixDateTime, which is UTC. Then we can always compare the parsed times against the current UTC time. This also lets us store parsed milliseconds.
This commit is contained in:
parent
da118f2adf
commit
928287b782
7 changed files with 64 additions and 65 deletions
|
@ -119,7 +119,7 @@ ByteString type_name(Type type)
|
|||
return "InvalidType";
|
||||
}
|
||||
|
||||
Optional<Core::DateTime> parse_utc_time(StringView time)
|
||||
Optional<UnixDateTime> parse_utc_time(StringView time)
|
||||
{
|
||||
// YYMMDDhhmm[ss]Z or YYMMDDhhmm[ss](+|-)hhmm
|
||||
GenericLexer lexer(time);
|
||||
|
@ -164,10 +164,10 @@ Optional<Core::DateTime> parse_utc_time(StringView time)
|
|||
if (offset_hours.has_value() || offset_minutes.has_value())
|
||||
dbgln("FIXME: Implement UTCTime with offset!");
|
||||
|
||||
return Core::DateTime::create(full_year, month.value(), day.value(), hour.value(), minute.value(), full_seconds);
|
||||
return UnixDateTime::from_unix_time_parts(full_year, month.value(), day.value(), hour.value(), minute.value(), full_seconds, 0);
|
||||
}
|
||||
|
||||
Optional<Core::DateTime> parse_generalized_time(StringView time)
|
||||
Optional<UnixDateTime> parse_generalized_time(StringView time)
|
||||
{
|
||||
// YYYYMMDDhh[mm[ss[.fff]]] or YYYYMMDDhh[mm[ss[.fff]]]Z or YYYYMMDDhh[mm[ss[.fff]]](+|-)hhmm
|
||||
GenericLexer lexer(time);
|
||||
|
@ -177,6 +177,7 @@ Optional<Core::DateTime> parse_generalized_time(StringView time)
|
|||
auto hour = lexer.consume(2).to_number<unsigned>();
|
||||
Optional<unsigned> minute, seconds, milliseconds, offset_hours, offset_minutes;
|
||||
[[maybe_unused]] bool negative_offset = false;
|
||||
|
||||
if (!lexer.is_eof()) {
|
||||
if (lexer.consume_specific('Z'))
|
||||
goto done_parsing;
|
||||
|
@ -233,7 +234,6 @@ done_parsing:;
|
|||
if (offset_hours.has_value() || offset_minutes.has_value())
|
||||
dbgln("FIXME: Implement GeneralizedTime with offset!");
|
||||
|
||||
// Unceremoniously drop the milliseconds on the floor.
|
||||
return Core::DateTime::create(year.value(), month.value(), day.value(), hour.value(), minute.value_or(0), seconds.value_or(0));
|
||||
return UnixDateTime::from_unix_time_parts(year.value(), month.value(), day.value(), hour.value(), minute.value_or(0), seconds.value_or(0), milliseconds.value_or(0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Time.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibCore/DateTime.h>
|
||||
#include <LibCrypto/BigInt/UnsignedBigInteger.h>
|
||||
|
||||
namespace Crypto::ASN1 {
|
||||
|
@ -75,7 +75,7 @@ ByteString kind_name(Kind);
|
|||
ByteString class_name(Class);
|
||||
ByteString type_name(Type);
|
||||
|
||||
Optional<Core::DateTime> parse_utc_time(StringView);
|
||||
Optional<Core::DateTime> parse_generalized_time(StringView);
|
||||
Optional<UnixDateTime> parse_utc_time(StringView);
|
||||
Optional<UnixDateTime> parse_generalized_time(StringView);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue