1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-26 19:39:53 +03:00

Merge pull request #560 from jbwdevries/certificate_date_fixes

Certificate date fixes
This commit is contained in:
Ilya Shipitsin 2018-07-21 10:45:09 +05:00 committed by GitHub
commit 1b4cc1fb8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View File

@ -2135,6 +2135,9 @@ bool Asn1TimeToSystem(SYSTEMTIME *s, void *asn1_time)
// Convert the string to the system time // Convert the string to the system time
bool StrToSystem(SYSTEMTIME *s, char *str) bool StrToSystem(SYSTEMTIME *s, char *str)
{ {
char century[3] = {0, 0, 0};
bool fourdigityear = false;
// Validate arguments // Validate arguments
if (s == NULL || str == NULL) if (s == NULL || str == NULL)
{ {
@ -2142,7 +2145,14 @@ bool StrToSystem(SYSTEMTIME *s, char *str)
} }
if (StrLen(str) != 13) 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') if (str[12] != 'Z')
{ {
@ -2159,7 +2169,10 @@ bool StrToSystem(SYSTEMTIME *s, char *str)
second[3] = {str[10], str[11], 0}; second[3] = {str[10], str[11], 0};
Zero(s, sizeof(SYSTEMTIME)); Zero(s, sizeof(SYSTEMTIME));
s->wYear = ToInt(year); s->wYear = ToInt(year);
if (s->wYear >= 60) if( fourdigityear ) {
s->wYear += ToInt(century) * 100;
}
else if (s->wYear >= 60)
{ {
s->wYear += 1900; s->wYear += 1900;
} }

View File

@ -2137,6 +2137,15 @@ UINT64 SystemToUINT64(SYSTEMTIME *st)
} }
time = SystemToTime(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 = (UINT64)time * (UINT64)1000;
sec64 += st->wMilliseconds; sec64 += st->wMilliseconds;