Repository navigation
Conversation
|
I target just 8.5+ as I can't be bothered to deal with conflict for this sort of "not real" issue (who would be using certs valid longer than year 3000...? :) ) |
|
|
||
| if (ASN1_STRING_type(timestr) == V_ASN1_GENERALIZEDTIME && timestr_len < 15) { | ||
| /* Validates the string and fills in the broken-down time in UTC. */ | ||
| if (!ASN1_TIME_to_tm(timestr, &thetime)) { |
There was a problem hiding this comment.
While at it, why not use ASN1_TIME_diff for the whole algo?
https://manpages.opensuse.org/Leap-15.6/openssl-3-doc/ASN1_TIME_diff.33ssl.en.html
So you don't need to maintain the date algo yourself. But at the cost that there might be one more allocation/free for ASN1_TIME in each call.
There was a problem hiding this comment.
ASN1_TIME_diff is much cleaner i think, without Howard Hinnant
epoch = ASN1_TIME_set(NULL, 0);
if (epoch == NULL || !ASN1_TIME_diff(&days, &secs, epoch, timestr)) {
php_openssl_store_errors();
ASN1_TIME_free(epoch);
php_error_docref(NULL, E_WARNING, "Unable to parse time string %s correctly", ASN1_STRING_get0_data(timestr));
return (time_t)-1;
}
ASN1_TIME_free(epoch);
ret = (int64_t)days * 86400 + secs;
There was a problem hiding this comment.
Yeah ASN1_TIME_diff is better indeed. Changed.
There was a problem hiding this comment.
I checked the supported version availability and it should be fine even on LibreSSL so should be fine to use it always.
|
Besides GH-21545 this also fixes two things:
|
The ASN.1 time was converted to a timestamp with mktime() and a manual time zone correction. MSVC's 64-bit mktime() cannot represent dates after 23:59:59 on 31 December 3000 UTC and returns -1, which then had the local time zone adjustment added to it, producing values like 7199 or 32399. Use ASN1_TIME_diff() against the epoch to validate the string and compute the timestamp in UTC, so the result no longer depends on the C library's mktime() range or on the local time zone. Closes phpGH-21545
e2ebce0 to
d377171
Compare
The ASN.1 time was converted to a timestamp with mktime() and a manual time zone correction. MSVC's 64-bit mktime() cannot represent dates after 23:59:59 on 31 December 3000 UTC and returns -1, which then had the local time zone adjustment added to it, producing values like 7199 or 32399.
Decode the string with ASN1_TIME_to_tm() and compute the timestamp directly from the UTC civil date, so the result no longer depends on the C library's mktime() range or on the local time zone.
Closes GH-21545