From 3d0e87cf570610856fc8f45798168ab722ecb99e Mon Sep 17 00:00:00 2001 From: Johan de Vries Date: Thu, 21 Jun 2018 09:25:19 +0200 Subject: [PATCH 1/2] src/Mayaqua/Encrypt.c: Add support for certificates with full year --- src/Mayaqua/Encrypt.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Mayaqua/Encrypt.c b/src/Mayaqua/Encrypt.c index 381d1c57..4928a482 100644 --- a/src/Mayaqua/Encrypt.c +++ b/src/Mayaqua/Encrypt.c @@ -2134,6 +2134,9 @@ bool Asn1TimeToSystem(SYSTEMTIME *s, void *asn1_time) // Convert the string to the system time bool StrToSystem(SYSTEMTIME *s, char *str) { + char century[3] = {0, 0, 0}; + bool fourdigityear = false; + // Validate arguments if (s == NULL || str == NULL) { @@ -2141,7 +2144,14 @@ bool StrToSystem(SYSTEMTIME *s, char *str) } if (StrLen(str) != 13) { - return false; + if (StrLen(str) != 15) return false; + + //Year has 4 digits - save first two and use the rest + //as if it had two digits + fourdigityear = true; + century[0] = str[0]; + century[1] = str[1]; + str += 2; } if (str[12] != 'Z') { @@ -2158,7 +2168,10 @@ bool StrToSystem(SYSTEMTIME *s, char *str) second[3] = {str[10], str[11], 0}; Zero(s, sizeof(SYSTEMTIME)); s->wYear = ToInt(year); - if (s->wYear >= 60) + if( fourdigityear ) { + s->wYear += ToInt(century) * 100; + } + else if (s->wYear >= 60) { s->wYear += 1900; } From 41f9cdadc422eecacf22f3dca4488a56fd3ff5b2 Mon Sep 17 00:00:00 2001 From: Johan de Vries Date: Thu, 21 Jun 2018 09:29:36 +0200 Subject: [PATCH 2/2] src/Mayaqua/Kernel.c: Fix for times before 1970 Before, it would end up far in the future. Now it gets clamped to 1970. This should be fine since dates before 1970 are not actively used. If they are, then the UINT64 should be replaced by the time64t in quite a few places. --- src/Mayaqua/Kernel.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Mayaqua/Kernel.c b/src/Mayaqua/Kernel.c index cb59c3fd..771a6e13 100644 --- a/src/Mayaqua/Kernel.c +++ b/src/Mayaqua/Kernel.c @@ -2137,6 +2137,15 @@ UINT64 SystemToUINT64(SYSTEMTIME *st) } time = SystemToTime(st); + + //For times before 1970-01-01, clamp to the minimum + //because we have to return an unsigned integer. + //This is less wrong than casting it to UINT64 + //and returning a time far in the future. + //For some reason we subtract 9 hours below, so + //account for that here. + if( time < 32400000LL ) return 0; + sec64 = (UINT64)time * (UINT64)1000; sec64 += st->wMilliseconds;