forked from wolfSSL/wolfssl
Add test for CRL with invalid GeneralizedTime length
Co-Authored-By: Anthony H <anthony@wolfssl.com>
This commit is contained in:
13
certs/crl/invalid/gentime13.pem
Normal file
13
certs/crl/invalid/gentime13.pem
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
-----BEGIN X509 CRL-----
|
||||||
|
MIIB7DCB1QIBATANBgkqhkiG9w0BAQsFADBOMQswCQYDVQQGEwJVUzELMAkGA1UE
|
||||||
|
CAwCVVMxCzAJBgNVBAcMAlVTMQswCQYDVQQKDAJVUzELMAkGA1UEAwwCVVMxCzAJ
|
||||||
|
BgNVBAsMAlVTGA0yNDAxMjMwMDAwMDBaGA0zNDAxMjAwMDAwMDBaMDUwMwIUHIAC
|
||||||
|
LvgfJAXulqYS3LYf4KxwHl4XDTI1MDMxMzAyNDQ0MFowDDAKBgNVHRUEAwoBBqAc
|
||||||
|
MBowGAYDVR0UBBECDxnP/97adO3y9qRGDM7hQDANBgkqhkiG9w0BAQsFAAOCAQEA
|
||||||
|
aDY9jBdAJiAujUkaLYLVtzNWF/0SxD5CB4dYIcZMqtPKLn5ykcxkXvnRbVihJ+Kn
|
||||||
|
AAv9Fkn5iwj77EGwxNjyZktQ4gAmcMhCTBEcAHbmi92tHttot9Sr44+CN+0NaaQD
|
||||||
|
OflIeVw7Zir90TWufjScy8/e7FkVm+aD5CicrbJWqoe21pB1Q1jS49iNrZzqZ2vw
|
||||||
|
HLiqNAzpecxwUih/YPe5+CBk5Nq4vICeieGVC/JO9r5SkdDwWQTl0I3kSK6n4Jh7
|
||||||
|
53FmIen80F2ZZuZu4/fhJ7C4rlr6W9i6FrK06s5mk1PeYFHKhCkwI8wp8cIudJQD
|
||||||
|
lLsK2u4CTcuTKdbDLsszYA==
|
||||||
|
-----END X509 CRL-----
|
34
tests/api.c
34
tests/api.c
@@ -51394,6 +51394,39 @@ static int test_wolfSSL_X509_print(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int test_wolfSSL_X509_CRL_print(void)
|
static int test_wolfSSL_X509_CRL_print(void)
|
||||||
|
|
||||||
|
static int test_wolfSSL_X509_CRL_invalid_gentime(void)
|
||||||
|
{
|
||||||
|
EXPECT_DECLS;
|
||||||
|
#if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && defined(HAVE_CRL) && \
|
||||||
|
!defined(NO_RSA) && !defined(NO_FILESYSTEM)
|
||||||
|
X509_CRL* crl = NULL;
|
||||||
|
XFILE fp = XBADFILE;
|
||||||
|
const char* crlFile = "./certs/crl/invalid/gentime13.pem";
|
||||||
|
|
||||||
|
WOLFSSL_MSG("Testing CRL with invalid GeneralizedTime length (13 characters)");
|
||||||
|
|
||||||
|
/* Try to load CRL with invalid GeneralizedTime length */
|
||||||
|
ExpectTrue((fp = XFOPEN(crlFile, "rb")) != XBADFILE);
|
||||||
|
if (fp == XBADFILE) {
|
||||||
|
WOLFSSL_MSG("Failed to open CRL file");
|
||||||
|
EXPECT_FAIL();
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This should fail due to invalid GeneralizedTime length */
|
||||||
|
crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL**)NULL, NULL, NULL);
|
||||||
|
|
||||||
|
/* Expect crl to be NULL due to invalid date format */
|
||||||
|
ExpectNull(crl);
|
||||||
|
|
||||||
|
done:
|
||||||
|
if (fp != XBADFILE) {
|
||||||
|
XFCLOSE(fp);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return EXPECT_RESULT();
|
||||||
|
}
|
||||||
{
|
{
|
||||||
EXPECT_DECLS;
|
EXPECT_DECLS;
|
||||||
#if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && defined(HAVE_CRL) && \
|
#if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && defined(HAVE_CRL) && \
|
||||||
@@ -67094,6 +67127,7 @@ TEST_CASE testCases[] = {
|
|||||||
TEST_DECL(test_wolfSSL_X509_check_ca),
|
TEST_DECL(test_wolfSSL_X509_check_ca),
|
||||||
TEST_DECL(test_wolfSSL_X509_check_ip_asc),
|
TEST_DECL(test_wolfSSL_X509_check_ip_asc),
|
||||||
TEST_DECL(test_wolfSSL_X509_bad_altname),
|
TEST_DECL(test_wolfSSL_X509_bad_altname),
|
||||||
|
TEST_DECL(test_wolfSSL_X509_CRL_invalid_gentime),
|
||||||
TEST_DECL(test_wolfSSL_X509_name_match),
|
TEST_DECL(test_wolfSSL_X509_name_match),
|
||||||
TEST_DECL(test_wolfSSL_X509_name_match2),
|
TEST_DECL(test_wolfSSL_X509_name_match2),
|
||||||
TEST_DECL(test_wolfSSL_X509_name_match3),
|
TEST_DECL(test_wolfSSL_X509_name_match3),
|
||||||
|
101
tests/test_invalid_gentime_crl.c
Normal file
101
tests/test_invalid_gentime_crl.c
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
/* test_invalid_gentime_crl.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006-2024 wolfSSL Inc.
|
||||||
|
*
|
||||||
|
* This file is part of wolfSSL.
|
||||||
|
*
|
||||||
|
* wolfSSL is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* wolfSSL is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <wolfssl/wolfcrypt/settings.h>
|
||||||
|
#include <wolfssl/wolfcrypt/asn.h>
|
||||||
|
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||||
|
|
||||||
|
#if defined(OPENSSL_EXTRA) && defined(HAVE_CRL)
|
||||||
|
|
||||||
|
#include <wolfssl/openssl/x509.h>
|
||||||
|
#include <wolfssl/openssl/bio.h>
|
||||||
|
#include <wolfssl/openssl/pem.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int test_invalid_gentime_crl(void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
XFILE fp = XBADFILE;
|
||||||
|
X509_CRL *crl = NULL;
|
||||||
|
const char* crlFile = "./certs/crl/invalid/gentime13.pem";
|
||||||
|
|
||||||
|
printf("Testing CRL with invalid GeneralizedTime length (13 characters)...\n");
|
||||||
|
|
||||||
|
/* Try to load CRL with invalid GeneralizedTime length */
|
||||||
|
fp = XFOPEN(crlFile, "rb");
|
||||||
|
if (fp == XBADFILE) {
|
||||||
|
printf("Failed to open CRL file: %s\n", crlFile);
|
||||||
|
ret = -1;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This should fail due to invalid GeneralizedTime length */
|
||||||
|
crl = (X509_CRL*)PEM_read_X509_CRL(fp, (X509_CRL**)NULL, NULL, NULL);
|
||||||
|
|
||||||
|
/* Expect crl to be NULL due to invalid date format */
|
||||||
|
if (crl != NULL) {
|
||||||
|
printf("ERROR: Successfully parsed CRL with invalid GeneralizedTime length\n");
|
||||||
|
ret = -1;
|
||||||
|
} else {
|
||||||
|
printf("SUCCESS: CRL with invalid GeneralizedTime length was rejected\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fp != XBADFILE) {
|
||||||
|
XFCLOSE(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
if (crl != NULL) {
|
||||||
|
X509_CRL_free(crl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
ret = test_invalid_gentime_crl();
|
||||||
|
|
||||||
|
if (ret != 0) {
|
||||||
|
printf("Test failed with error: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("All tests passed!\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
printf("Test skipped: OPENSSL_EXTRA and HAVE_CRL required\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* OPENSSL_EXTRA && HAVE_CRL */
|
Reference in New Issue
Block a user