From f8ce0eb64849ac729eb07a6ec8a36ad4f55bfa3a Mon Sep 17 00:00:00 2001 From: Michiel Visser Date: Mon, 21 Feb 2022 22:15:41 +0100 Subject: [PATCH] LibTLS: ASN1 parse_utc_time handle pre 2000 years In this format the year is specified using two digits. In the case that these digits are 50 or more, we should assume that the year is in 1950-1999. If it is 49 or less, the year is 2000-2049. This is specified in RFC5280 section 4.1.2.5.1. --- Userland/Libraries/LibCrypto/ASN1/ASN1.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibCrypto/ASN1/ASN1.cpp b/Userland/Libraries/LibCrypto/ASN1/ASN1.cpp index 7fc07b1ca9..a87e5b4f54 100644 --- a/Userland/Libraries/LibCrypto/ASN1/ASN1.cpp +++ b/Userland/Libraries/LibCrypto/ASN1/ASN1.cpp @@ -110,7 +110,9 @@ Optional parse_utc_time(StringView time) return {}; } - auto full_year = (Core::DateTime::now().year() / 100) * 100 + year_in_century.value(); + // RFC5280 section 4.1.2.5.1. + auto full_year = year_in_century.value(); + full_year += (full_year < 50) ? 2000 : 1900; auto full_seconds = seconds.value_or(0); // FIXME: Handle offsets!