Fix build error with NO_PKCS12

This commit is contained in:
Eric Blankenhorn
2021-04-07 13:19:22 -05:00
parent fd94d05b0a
commit ef69a9b458
2 changed files with 39 additions and 31 deletions

View File

@@ -25311,7 +25311,7 @@ WOLFSSL_X509* wolfSSL_d2i_X509_REQ_bio(WOLFSSL_BIO* bio, WOLFSSL_X509** x509)
#endif #endif
#if !defined(NO_ASN) && !defined(NO_PWDBASED) #if !defined(NO_ASN) && !defined(NO_PWDBASED)
#ifndef NO_BIO #if !defined(NO_BIO) && defined(HAVE_PKCS12)
WC_PKCS12* wolfSSL_d2i_PKCS12_bio(WOLFSSL_BIO* bio, WC_PKCS12** pkcs12) WC_PKCS12* wolfSSL_d2i_PKCS12_bio(WOLFSSL_BIO* bio, WC_PKCS12** pkcs12)
{ {
WC_PKCS12* localPkcs12 = NULL; WC_PKCS12* localPkcs12 = NULL;
@@ -25391,7 +25391,7 @@ int wolfSSL_i2d_PKCS12_bio(WOLFSSL_BIO *bio, WC_PKCS12 *pkcs12)
return ret; return ret;
} }
#endif /* !NO_BIO */ #endif /* !NO_BIO && HAVE_PKCS12 */
/* Copies unencrypted DER key buffer into "der". If "der" is null then the size /* Copies unencrypted DER key buffer into "der". If "der" is null then the size
* of buffer needed is returned. If *der == NULL then it allocates a buffer. * of buffer needed is returned. If *der == NULL then it allocates a buffer.
@@ -25404,6 +25404,7 @@ int wolfSSL_i2d_PrivateKey(const WOLFSSL_EVP_PKEY* key, unsigned char** der)
return wolfSSL_EVP_PKEY_get_der(key, der); return wolfSSL_EVP_PKEY_get_der(key, der);
} }
#ifdef HAVE_PKCS12
/* Creates a new WC_PKCS12 structure /* Creates a new WC_PKCS12 structure
* *
* pass password to use * pass password to use
@@ -25791,6 +25792,7 @@ int wolfSSL_PKCS12_verify_mac(WC_PKCS12 *pkcs12, const char *psw,
return wc_PKCS12_verify_ex(pkcs12, (const byte*)psw, pswLen) == 0 ? return wc_PKCS12_verify_ex(pkcs12, (const byte*)psw, pswLen) == 0 ?
WOLFSSL_SUCCESS : WOLFSSL_FAILURE; WOLFSSL_SUCCESS : WOLFSSL_FAILURE;
} }
#endif /* HAVE_PKCS12 */
#endif /* !NO_ASN && !NO_PWDBASED */ #endif /* !NO_ASN && !NO_PWDBASED */
@@ -26377,7 +26379,7 @@ static void *wolfSSL_d2i_X509_fp_ex(XFILE file, void **x509, int type)
newx509 = (void *)wolfSSL_d2i_X509_CRL(NULL, fileBuffer, (int)sz); newx509 = (void *)wolfSSL_d2i_X509_CRL(NULL, fileBuffer, (int)sz);
} }
#endif #endif
#if !defined(NO_ASN) && !defined(NO_PWDBASED) #if !defined(NO_ASN) && !defined(NO_PWDBASED) && defined(HAVE_PKCS12)
else if (type == PKCS12_TYPE) { else if (type == PKCS12_TYPE) {
if ((newx509 = wc_PKCS12_new()) == NULL) { if ((newx509 = wc_PKCS12_new()) == NULL) {
goto err_exit; goto err_exit;
@@ -26402,7 +26404,7 @@ static void *wolfSSL_d2i_X509_fp_ex(XFILE file, void **x509, int type)
goto _exit; goto _exit;
err_exit: err_exit:
#if !defined(NO_ASN) && !defined(NO_PWDBASED) #if !defined(NO_ASN) && !defined(NO_PWDBASED) && defined(HAVE_PKCS12)
if ((newx509 != NULL) && (type == PKCS12_TYPE)) { if ((newx509 != NULL) && (type == PKCS12_TYPE)) {
wc_PKCS12_free((WC_PKCS12*)newx509); wc_PKCS12_free((WC_PKCS12*)newx509);
newx509 = NULL; newx509 = NULL;

View File

@@ -5056,7 +5056,7 @@ static void test_wolfSSL_PKCS12(void)
*/ */
#if defined(OPENSSL_EXTRA) && !defined(NO_DES3) && !defined(NO_FILESYSTEM) && \ #if defined(OPENSSL_EXTRA) && !defined(NO_DES3) && !defined(NO_FILESYSTEM) && \
!defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_RSA) && \ !defined(NO_ASN) && !defined(NO_PWDBASED) && !defined(NO_RSA) && \
!defined(NO_SHA) !defined(NO_SHA) && defined(HAVE_PKCS12)
byte buffer[6000]; byte buffer[6000];
char file[] = "./certs/test-servercert.p12"; char file[] = "./certs/test-servercert.p12";
char order[] = "./certs/ecc-rsa-server.p12"; char order[] = "./certs/ecc-rsa-server.p12";
@@ -31743,15 +31743,6 @@ static void test_wolfSSL_OBJ(void)
ASN1_STRING *asn1 = NULL; ASN1_STRING *asn1 = NULL;
unsigned char *buf_dyn = NULL; unsigned char *buf_dyn = NULL;
PKCS12 *p12;
int boolRet;
EVP_PKEY *pkey = NULL;
const char *p12_f[] = {
#if !defined(NO_DES3) && !defined(NO_RSA)
"./certs/test-servercert.p12",
#endif
NULL};
printf(testingFmt, "wolfSSL_OBJ()"); printf(testingFmt, "wolfSSL_OBJ()");
AssertIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), SSL_FAILURE); AssertIntEQ(OBJ_obj2txt(buf, (int)sizeof(buf), obj, 1), SSL_FAILURE);
@@ -31809,12 +31800,24 @@ static void test_wolfSSL_OBJ(void)
} }
#ifdef HAVE_PKCS12
{
PKCS12 *p12;
int boolRet;
EVP_PKEY *pkey = NULL;
const char *p12_f[] = {
#if !defined(NO_DES3) && !defined(NO_RSA)
"./certs/test-servercert.p12",
#endif
NULL};
for (i = 0; p12_f[i] != NULL; i++) for (i = 0; p12_f[i] != NULL; i++)
{ {
AssertTrue((fp = XFOPEN(p12_f[i], "rb")) != XBADFILE); AssertTrue((fp = XFOPEN(p12_f[i], "rb")) != XBADFILE);
AssertNotNull(p12 = d2i_PKCS12_fp(fp, NULL)); AssertNotNull(p12 = d2i_PKCS12_fp(fp, NULL));
XFCLOSE(fp); XFCLOSE(fp);
AssertTrue((boolRet = PKCS12_parse(p12, "wolfSSL test", &pkey, &x509, NULL)) > 0); AssertTrue((boolRet = PKCS12_parse(p12, "wolfSSL test",
&pkey, &x509, NULL)) > 0);
wc_PKCS12_free(p12); wc_PKCS12_free(p12);
EVP_PKEY_free(pkey); EVP_PKEY_free(pkey);
x509Name = X509_get_issuer_name(x509); x509Name = X509_get_issuer_name(x509);
@@ -31824,12 +31827,15 @@ static void test_wolfSSL_OBJ(void)
for (j = 0; j < numNames; j++) for (j = 0; j < numNames; j++)
{ {
AssertNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, j)); AssertNotNull(x509NameEntry = X509_NAME_get_entry(x509Name, j));
AssertNotNull(asn1Name = X509_NAME_ENTRY_get_object(x509NameEntry)); AssertNotNull(asn1Name =
X509_NAME_ENTRY_get_object(x509NameEntry));
AssertTrue((nid = OBJ_obj2nid(asn1Name)) > 0); AssertTrue((nid = OBJ_obj2nid(asn1Name)) > 0);
} }
BIO_free(bio); BIO_free(bio);
X509_free(x509); X509_free(x509);
} }
}
#endif /* HAVE_PKCS12 */
printf(resultFmt, passed); printf(resultFmt, passed);
#endif #endif