Browse Source

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.
Michiel Visser 3 years ago
parent
commit
f8ce0eb648
1 changed files with 3 additions and 1 deletions
  1. 3 1
      Userland/Libraries/LibCrypto/ASN1/ASN1.cpp

+ 3 - 1
Userland/Libraries/LibCrypto/ASN1/ASN1.cpp

@@ -110,7 +110,9 @@ Optional<Core::DateTime> parse_utc_time(StringView time)
         return {};
         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);
     auto full_seconds = seconds.value_or(0);
 
 
     // FIXME: Handle offsets!
     // FIXME: Handle offsets!