Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/os-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ jobs:
'--enable-opensslextra=x509small',
'CPPFLAGS=''-DWOLFSSL_EXTRA'' ',
'--enable-lms=small,verify-only --enable-xmss=small,verify-only',
'--disable-sys-ca-certs'
'--disable-sys-ca-certs',
'--enable-all CPPFLAGS=-DWOLFSSL_DEBUG_CERTS ',
]
name: make check
if: github.repository_owner == 'wolfssl'
Expand Down
23 changes: 22 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,28 @@ add_option("WOLFSSL_DEBUG"
"no" "yes;no")

if(WOLFSSL_DEBUG)
set(CMAKE_C_FLAGS "-g ${CMAKE_C_FLAGS}")
# Optional variable inspection
if (0)
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
message(STATUS "")
message(STATUS "ALL VARIABLES BEGIN")
message(STATUS "")
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
message(STATUS "")
message(STATUS "ALL VARIABLES END")
message(STATUS "")
endif()

if (CMAKE_C_COMPILER_ID STREQUAL "Watcom" OR CMAKE_C_COMPILER_ID STREQUAL "OpenWatcom" OR CMAKE_GENERATOR STREQUAL "Watcom WMake")
# Open Watcom v2 does not support -g debugging
message(STATUS "Detected Watcom compiler, using CMAKE_C_FLAGS_DEBUG -d2")
set(CMAKE_C_FLAGS_DEBUG "-d2 ${CMAKE_C_FLAGS_DEBUG}")
else()
set(CMAKE_C_FLAGS "-g ${CMAKE_C_FLAGS}")
endif()
list(APPEND WOLFSSL_DEFINITIONS
"-DDEBUG_WOLFSSL"
"-DDEBUG")
Expand Down
9 changes: 6 additions & 3 deletions src/crl.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ CRL Options:

#include <wolfssl/internal.h>
#include <wolfssl/error-ssl.h>
#include <wolfssl/wolfcrypt/logging.h>

#ifndef WOLFSSL_LINUXKM
#include <string.h>
Expand Down Expand Up @@ -791,7 +792,7 @@ int BufferLoadCRL(WOLFSSL_CRL* crl, const byte* buff, long sz, int type,

crl->currentEntry = CRL_Entry_new(crl->heap);
if (crl->currentEntry == NULL) {
WOLFSSL_MSG("alloc CRL Entry failed");
WOLFSSL_MSG_CERT_LOG("alloc CRL Entry failed");
#ifdef WOLFSSL_SMALL_STACK
XFREE(dcrl, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
Expand All @@ -802,17 +803,19 @@ int BufferLoadCRL(WOLFSSL_CRL* crl, const byte* buff, long sz, int type,
InitDecodedCRL(dcrl, crl->heap);
ret = ParseCRL(crl->currentEntry->certs, dcrl, myBuffer, (word32)sz,
verify, crl->cm);

if (ret != 0 && !(ret == WC_NO_ERR_TRACE(ASN_CRL_NO_SIGNER_E)
&& verify == NO_VERIFY)) {
WOLFSSL_MSG("ParseCRL error");
WOLFSSL_MSG_CERT_LOG("ParseCRL error");
WOLFSSL_MSG_CERT_EX("ParseCRL verify = %d, ret = %d", verify, ret);
CRL_Entry_free(crl->currentEntry, crl->heap);
crl->currentEntry = NULL;
}
else {
ret = AddCRL(crl, dcrl, myBuffer,
ret != WC_NO_ERR_TRACE(ASN_CRL_NO_SIGNER_E));
if (ret != 0) {
WOLFSSL_MSG("AddCRL error");
WOLFSSL_MSG_CERT_LOG("AddCRL error");
crl->currentEntry = NULL;
}
}
Expand Down
24 changes: 21 additions & 3 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -8025,7 +8025,7 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
ssl->secLevel = ctx->secLevel;
#endif /* WOLFSSL_SYS_CRYPTO_POLICY */
/* Returns 0 on success, not WOLFSSL_SUCCESS (1) */
WOLFSSL_MSG_EX("InitSSL done. return 0 (success)");
WOLFSSL_MSG("InitSSL done. return 0 (success)");
return 0;
}

Expand Down Expand Up @@ -15776,7 +15776,8 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx,
if (ret == WC_NO_ERR_TRACE(ASN_NO_SIGNER_E) ||
ret == WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E)) {
if (!ssl->options.usingAltCertChain) {
WOLFSSL_MSG("Trying alternate cert chain");
WOLFSSL_MSG_CERT_LOG(
"Trying alternate cert chain");
ssl->options.usingAltCertChain = 1;
}

Expand All @@ -15788,8 +15789,25 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx,

/* do not add to certificate manager */
skipAddCA = 1;
} /* ASN_NO_SIGNER_E || ASN_SELF_SIGNED_E */
} /* ret != 0 && isCA */
#else
/* Not defined: WOLFSSL_ALT_CERT_CHAINS
* When WOLFSSL_DEBUG_CERTS enabled, suggest solution */
#ifdef WOLFSSL_DEBUG_CERTS
if (ret != 0 && args->dCert->isCA) {
if (ret == WC_NO_ERR_TRACE(ASN_NO_SIGNER_E)) {
WOLFSSL_MSG_CERT(
"Consider enabling WOLFSSL_ALT_CERT_CHAINS"
" to resolve ASN_NO_SIGNER_E");
}
}
if (ret == WC_NO_ERR_TRACE(ASN_SELF_SIGNED_E)) {
WOLFSSL_MSG_CERT(
"Consider enabling WOLFSSL_ALT_CERT_CHAINS"
" to resolve ASN_SELF_SIGNED_E");
}
} /* check alt-cert possible fixable error codes */
#endif
#endif /* WOLFSSL_ALT_CERT_CHAINS */

#if defined(__APPLE__) && defined(WOLFSSL_SYS_CA_CERTS)
Expand Down
40 changes: 36 additions & 4 deletions src/ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -5869,7 +5869,7 @@ int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify)
#endif
DerBuffer* der = *pDer;

WOLFSSL_MSG("Adding a CA");
WOLFSSL_MSG_CERT_LOG("Adding a CA");

if (cm == NULL) {
FreeDer(pDer);
Expand All @@ -5893,8 +5893,34 @@ int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify)
}
#endif

WOLFSSL_MSG_CERT("\tParsing new CA");
ret = ParseCert(cert, CA_TYPE, verify, cm);

WOLFSSL_MSG("\tParsed new CA");
#ifdef WOLFSSL_DEBUG_CERTS
#ifdef WOLFSSL_SMALL_STACK
if (cert == NULL) {
WOLFSSL_MSG_CERT(WOLFSSL_MSG_CERT_INDENT "Failed; cert is NULL");
}
else
#endif
{
const char* err_msg;
if (ret == 0) {
WOLFSSL_MSG_CERT_EX(WOLFSSL_MSG_CERT_INDENT "issuer: '%s'",
cert->issuer);
WOLFSSL_MSG_CERT_EX(WOLFSSL_MSG_CERT_INDENT "subject: '%s'",
cert->subject);
}
else {
WOLFSSL_MSG_CERT(
WOLFSSL_MSG_CERT_INDENT "Failed during parse of new CA");
err_msg = wc_GetErrorString(ret);
WOLFSSL_MSG_CERT_EX(WOLFSSL_MSG_CERT_INDENT "error ret: %d; %s",
ret, err_msg);
}
}
#endif /* WOLFSSL_DEBUG_CERTS */

#ifndef NO_SKID
subjectHash = cert->extSubjKeyId;
Expand All @@ -5903,7 +5929,7 @@ int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify)
#endif

/* check CA key size */
if (verify) {
if (verify && (ret == 0 )) {
switch (cert->keyOID) {
#ifndef NO_RSA
#ifdef WC_RSA_PSS
Expand All @@ -5913,7 +5939,10 @@ int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify)
if (cm->minRsaKeySz < 0 ||
cert->pubKeySize < (word16)cm->minRsaKeySz) {
ret = RSA_KEY_SIZE_E;
WOLFSSL_MSG("\tCA RSA key size error");
WOLFSSL_MSG_CERT_LOG("\tCA RSA key size error");
WOLFSSL_MSG_CERT_EX("\tCA RSA pubKeySize = %d; "
"minRsaKeySz = %d",
cert->pubKeySize, cm->minRsaKeySz);
}
break;
#endif /* !NO_RSA */
Expand All @@ -5922,7 +5951,10 @@ int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify)
if (cm->minEccKeySz < 0 ||
cert->pubKeySize < (word16)cm->minEccKeySz) {
ret = ECC_KEY_SIZE_E;
WOLFSSL_MSG("\tCA ECC key size error");
WOLFSSL_MSG_CERT_LOG("\tCA ECC key size error");
WOLFSSL_MSG_CERT_EX("\tCA ECC pubKeySize = %d; "
"minEccKeySz = %d",
cert->pubKeySize, cm->minEccKeySz);
}
break;
#endif /* HAVE_ECC */
Expand Down
23 changes: 18 additions & 5 deletions src/ssl_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/

#ifdef WOLFSSL_SYS_CA_CERTS
/* Will be turned off automatically when NO_FILESYSTEM is defined */

#ifdef _WIN32
#define _WINSOCKAPI_ /* block inclusion of winsock.h header file */
Expand Down Expand Up @@ -59,6 +60,8 @@
#endif
#else

#include <wolfssl/wolfcrypt/logging.h>

#if defined(HAVE_SESSION_TICKET) || !defined(NO_PSK)
/* PSK field of context when it exists. */
#define CTX_HAVE_PSK(ctx) (ctx)->havePSK
Expand Down Expand Up @@ -2721,38 +2724,46 @@ int ProcessFile(WOLFSSL_CTX* ctx, const char* fname, int format, int type,
&sz);
if ((ret == 0) && (type == DETECT_CERT_TYPE) &&
(format != WOLFSSL_FILETYPE_PEM)) {
WOLFSSL_MSG("Cannot detect certificate type when not PEM");
WOLFSSL_MSG_CERT_LOG("Cannot detect certificate type when not PEM");
ret = WOLFSSL_BAD_CERTTYPE;
}
/* Try to detect type by parsing cert header and footer. */
if ((ret == 0) && (type == DETECT_CERT_TYPE)) {
#if !defined(NO_CODING) && !defined(WOLFSSL_NO_PEM)
const char* header = NULL;
const char* footer = NULL;
#ifdef HAVE_CRL
WOLFSSL_MSG_CERT("Detecting cert type... (including CRL_TYPE)");
#else
WOLFSSL_MSG_CERT("Detecting cert type... (HAVE_CRL not defined)");
#endif

/* Look for CA header and footer - same as CERT_TYPE. */
if (wc_PemGetHeaderFooter(CA_TYPE, &header, &footer) == 0 &&
(XSTRNSTR((char*)content.buffer, header, (word32)sz) != NULL)) {
type = CA_TYPE;
WOLFSSL_DEBUG_PRINTF("Detected cert type CA_TYPE = %d:", type);
}
#ifdef HAVE_CRL
/* Look for CRL header and footer. */
else if (wc_PemGetHeaderFooter(CRL_TYPE, &header, &footer) == 0 &&
(XSTRNSTR((char*)content.buffer, header, (word32)sz) != NULL)) {
type = CRL_TYPE;
WOLFSSL_DEBUG_PRINTF("Detected cert type CRL_TYPE = %d:", type);
}
#endif
/* Look for cert header and footer - same as CA_TYPE. */
else if (wc_PemGetHeaderFooter(CERT_TYPE, &header, &footer) == 0 &&
(XSTRNSTR((char*)content.buffer, header, (word32)sz) !=
NULL)) {
type = CERT_TYPE;
WOLFSSL_DEBUG_PRINTF("Detected cert type CERT_TYPE = %d:", type);
}
else
#endif
#endif /* !NO_CODING && !WOLFSSL_NO_PEM */
{
/* Not a header that we support. */
WOLFSSL_MSG("Failed to detect certificate type");
WOLFSSL_MSG_CERT_LOG("Failed to detect certificate type");
#ifdef WOLFSSL_DEBUG_CERTIFICATE_LOADS
WOLFSSL_DEBUG_PRINTF(
"ERROR: ProcessFile: Failed to detect certificate type"
Expand All @@ -2761,17 +2772,19 @@ int ProcessFile(WOLFSSL_CTX* ctx, const char* fname, int format, int type,
#endif
ret = WOLFSSL_BAD_CERTTYPE;
}
}
} /* (ret == 0) && (type == DETECT_CERT_TYPE) */

if (ret == 0) {
/* When CA or trusted peer and PEM - process as a chain buffer. */
if (((type == CA_TYPE) || (type == TRUSTED_PEER_TYPE)) &&
(format == WOLFSSL_FILETYPE_PEM)) {
WOLFSSL_MSG_CERT("Processing cert chain buffer...");
ret = ProcessChainBuffer(ctx, ssl, content.buffer, sz, type,
verify, fname);
}
#ifdef HAVE_CRL
else if (type == CRL_TYPE) {
/* Load the CRL. */
WOLFSSL_MSG_CERT("Loading CRL...");
ret = BufferLoadCRL(crl, content.buffer, sz, format, verify);
}
#endif
Expand Down
1 change: 1 addition & 0 deletions src/wolfio.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <wolfssl/internal.h>
#include <wolfssl/error-ssl.h>
#include <wolfssl/wolfio.h>
#include <wolfssl/wolfcrypt/logging.h>

#ifdef NUCLEUS_PLUS_2_3
/* Holds last Nucleus networking error number */
Expand Down
9 changes: 5 additions & 4 deletions wolfcrypt/src/asn.c
Original file line number Diff line number Diff line change
Expand Up @@ -25749,7 +25749,7 @@ int ParseCertRelative(DecodedCert* cert, int type, int verify, void* cm,
}
}
#endif /* IGNORE_NAME_CONSTRAINTS */
}
} /* cert->ca */
#ifdef WOLFSSL_CERT_REQ
else if (type == CERTREQ_TYPE) {
/* try to confirm/verify signature */
Expand Down Expand Up @@ -25813,7 +25813,7 @@ int ParseCertRelative(DecodedCert* cert, int type, int verify, void* cm,
#endif
else {
/* no signer */
WOLFSSL_MSG("No CA signer to verify with");
WOLFSSL_MSG_CERT_LOG("No CA signer to verify with");
/* If you end up here with error -188,
* consider using WOLFSSL_ALT_CERT_CHAINS. */
#if defined(OPENSSL_ALL) || defined(WOLFSSL_QT)
Expand All @@ -25826,10 +25826,11 @@ int ParseCertRelative(DecodedCert* cert, int type, int verify, void* cm,
#endif
{
WOLFSSL_ERROR_VERBOSE(ASN_NO_SIGNER_E);
WOLFSSL_MSG_CERT("Consider using WOLFSSL_ALT_CERT_CHAINS.");
return ASN_NO_SIGNER_E;
}
}
}
} /* verify != NO_VERIFY && type != CA_TYPE && type != TRUSTED_PEER_TYPE */

#if defined(WOLFSSL_NO_TRUSTED_CERTS_VERIFY) && !defined(NO_SKID)
exit_pcr:
Expand All @@ -25839,7 +25840,7 @@ int ParseCertRelative(DecodedCert* cert, int type, int verify, void* cm,
if (verify != VERIFY_SKIP_DATE) {
return cert->badDate;
}
WOLFSSL_MSG("Date error: Verify option is skipping");
WOLFSSL_MSG_CERT_LOG("Date error: Verify option is skipping");
}

if (cert->criticalExt != 0)
Expand Down
Loading
Loading