Skip to content

Commit bdea725

Browse files
committed
* modules/ssl/ssl_engine_vars.c (ssl_var_lookup_ssl_cert): Use
ASN1_TIME_diff() if available to avoid parsing the ASN1_TIME. Temporarily disable the new ASN1_TIME_diff() code for the feature/ech branch build since that branch has a regression, once openssl/openssl@9fb44b5 is merged this workaround should be reverted. Github: closes #596 git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1931421 13f79535-47bb-0310-9956-ffa450edef68
1 parent b8236d1 commit bdea725

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

modules/ssl/ssl_engine_vars.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -827,23 +827,36 @@ static const char *ssl_var_lookup_ssl_cert_valid(apr_pool_t *p, ASN1_TIME *tm)
827827
return modssl_bio_free_read(p, bio);
828828
}
829829

830-
#define DIGIT2NUM(x) (((x)[0] - '0') * 10 + (x)[1] - '0')
830+
/* Evaluates to true if asn1 isn't a valid ASN.1 TIME; RFC3280
831+
* mandates that the seconds digits are present even though ASN.1
832+
* doesn't. */
833+
#define INVALID_ASN1_TIME(asn1) ( \
834+
((asn1)->type == V_ASN1_UTCTIME && (asn1)->length < 11) \
835+
|| ((asn1)->type == V_ASN1_GENERALIZEDTIME && (asn1)->length < 13) \
836+
|| ASN1_TIME_check(asn1) != 1)
831837

832838
/* Return a string giving the number of days remaining until 'tm', or
833839
* "0" if this can't be determined. */
834840
static const char *ssl_var_lookup_ssl_cert_remain(apr_pool_t *p, ASN1_TIME *tm)
835841
{
842+
/* NOTE: temporary workaround to disable this for HAVE_OPENSSL_ECH since the
843+
* feature/ech branch is missing 9fb44b527ee3717795609fb876a7a81f8898c623 */
844+
#if OPENSSL_VERSION_NUMBER >= 0x10101000L && !defined(LIBRESSL_VERSION_NUMBER) \
845+
&& !defined(HAVE_OPENSSL_ECH)
846+
int diff;
847+
848+
if (INVALID_ASN1_TIME(tm) || ASN1_TIME_diff(&diff, NULL, NULL, tm) != 1) {
849+
return "0";
850+
}
851+
#else
836852
apr_time_t then, now = apr_time_now();
837853
apr_time_exp_t exp = {0};
838854
long diff;
839855
unsigned char *dp;
840856

841-
/* Fail if the time isn't a valid ASN.1 TIME; RFC3280 mandates
842-
* that the seconds digits are present even though ASN.1
843-
* doesn't. */
844-
if ((tm->type == V_ASN1_UTCTIME && tm->length < 11) ||
845-
(tm->type == V_ASN1_GENERALIZEDTIME && tm->length < 13) ||
846-
!ASN1_TIME_check(tm)) {
857+
#define DIGIT2NUM(x) (((x)[0] - '0') * 10 + (x)[1] - '0')
858+
859+
if (INVALID_ASN1_TIME(tm)) {
847860
return "0";
848861
}
849862

@@ -867,6 +880,7 @@ static const char *ssl_var_lookup_ssl_cert_remain(apr_pool_t *p, ASN1_TIME *tm)
867880
}
868881

869882
diff = (long)((apr_time_sec(then) - apr_time_sec(now)) / (60*60*24));
883+
#endif
870884

871885
return diff > 0 ? apr_ltoa(p, diff) : "0";
872886
}

0 commit comments

Comments
 (0)