]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Stop using X509_cmp_timeframe in ossl_X509_check
authorBob Beck <beck@openssl.org>
Sat, 20 Sep 2025 01:35:36 +0000 (19:35 -0600)
committerNeil Horman <nhorman@openssl.org>
Thu, 16 Oct 2025 13:16:06 +0000 (09:16 -0400)
To no longer accept invalid certificate times as valid forver.

Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28623)

crypto/cmp/cmp_genm.c
crypto/x509/x509_vfy.c

index 40731cc4d09a5552d5c0c92c5951b1044e78120a..963d1e4bce16dc781fda9424b2702d0c040d076c 100644 (file)
@@ -36,15 +36,33 @@ static int ossl_X509_check(OSSL_CMP_CTX *ctx, const char *source, X509 *cert,
                            int type_CA, const X509_VERIFY_PARAM *vpm)
 {
     uint32_t ex_flags = X509_get_extension_flags(cert);
-    int res = X509_cmp_timeframe(vpm, X509_get0_notBefore(cert),
-                                 X509_get0_notAfter(cert));
-    int ret = res == 0;
+    int ret, err;
     OSSL_CMP_severity level =
         vpm == NULL ? OSSL_CMP_LOG_WARNING : OSSL_CMP_LOG_ERR;
 
-    if (!ret)
+    ret = ossl_x509_check_certificate_times(vpm, cert, &err);
+    if (!ret) {
+        const char * msg;
+        switch (err) {
+        case X509_V_ERR_CERT_NOT_YET_VALID:
+            msg = "not yet valid";
+            break;
+        case X509_V_ERR_CERT_HAS_EXPIRED:
+            msg = "has expired";
+            break;
+        case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
+            msg = "has an invalid not before field";
+            break;
+        case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
+            msg = "has an invalid not after field";
+            break;
+        default:
+            msg = "is invalid for an unspecfied reason";
+            break;
+        }
         cert_msg(OPENSSL_FUNC, OPENSSL_FILE, OPENSSL_LINE, level, ctx,
-                 source, cert, res > 0 ? "has expired" : "not yet valid");
+                 source, cert, msg);
+    }
     if (type_CA >= 0 && (ex_flags & EXFLAG_V1) == 0) {
         int is_CA = (ex_flags & EXFLAG_CA) != 0;
 
index 5df13c6fe717927882014ec4840e91e2618e5ffe..c7b4189d8eb96e36813e82ad59a5a191204dbaec 100644 (file)
@@ -2130,7 +2130,7 @@ static int check_policy(X509_STORE_CTX *ctx)
  *
  * Return 1 on success, 0 otherwise.
  */
-static int ossl_x509_compare_asn1_time(const X509_VERIFY_PARAM *vpm,
+int ossl_x509_compare_asn1_time(const X509_VERIFY_PARAM *vpm,
                                        const ASN1_TIME *time, int *comparison)
 {
     const time_t *check_time = NULL;