Skip to content

Commit

Permalink
Fix for the time parsing related issue (#1969)
Browse files Browse the repository at this point in the history
Allow for GeneralizedTime (> year 2049) in certificates.
Fix also a bug in renormalizing the Year from UTCTime parsing.

Fixes #1969.
  • Loading branch information
gganis committed Mar 22, 2023
1 parent 54cecf7 commit 6e703cb
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/XrdCrypto/XrdCryptosslAux.cc
Expand Up @@ -730,16 +730,27 @@ time_t XrdCryptosslASN1toUTC(const ASN1_TIME *tsn1)
&(ltm.tm_year), &(ltm.tm_mon), &(ltm.tm_mday),
&(ltm.tm_hour), &(ltm.tm_min), &(ltm.tm_sec),
&zz) != 7) || (zz != 'Z')) {
return -1;
// Try GeneralizedTime
if ((sscanf((const char *)(tsn1->data),
"%04d%02d%02d%02d%02d%02d%c",
&(ltm.tm_year), &(ltm.tm_mon), &(ltm.tm_mday),
&(ltm.tm_hour), &(ltm.tm_min), &(ltm.tm_sec),
&zz) != 7) || (zz != 'Z')) {
return -1;
}
}
// Init also the ones not used by mktime
ltm.tm_wday = 0; // day of the week
ltm.tm_yday = 0; // day in the year
ltm.tm_isdst = 0; // we will correct with an offset without dst
//
// Renormalize some values: year should be modulo 1900
if (ltm.tm_year < 90)
ltm.tm_year += 100;
// Renormalize some values (year should be modulo 1900), honouring all cases
if (ltm.tm_year < 50) {
ltm.tm_year += 2000;
} else if (ltm.tm_year < 100) {
ltm.tm_year += 1900;
}
ltm.tm_year -= 1900;
//
// month should in [0, 11]
(ltm.tm_mon)--;
Expand Down

0 comments on commit 6e703cb

Please sign in to comment.