Skip to content
Open
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
43 changes: 43 additions & 0 deletions doc/dox_comments/header_files/asn.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,53 @@ int wc_SetUnknownExtCallback32Ex(DecodedCert* cert,

\sa wolfSSL_CertManagerNew
\sa wolfSSL_CertManagerLoadCA
\sa wc_CheckCertSignature_ex
*/
int wc_CheckCertSignature(const byte* cert, word32 certSz, void* heap,
WOLFSSL_CERT_MANAGER* cm);

/*!
\ingroup ASN
\brief This function verifies the signature on a certificate using a
certificate manager, as wc_CheckCertSignature() does, and reports the
public key of the CA that verified it.

\return 0 On successful signature verification.
\return BAD_FUNC_ARG If cert is NULL, or caKey is not NULL and caKeySz
is NULL.
\return ASN_NO_SIGNER_E If cm holds no CA for the certificate.
\return ASN_SIG_CONFIRM_E If signature verification fails.
\return Other negative values on error.

\param cert pointer to the DER encoded certificate
\param certSz size of the certificate in bytes
\param heap pointer to heap hint for memory allocation (can be NULL)
\param cm pointer to certificate manager containing trusted CAs
\param caKey set to the public key of the CA that verified the
signature, in the form the certificate manager stores it, or to NULL
when verification fails. The key belongs to cm and is valid while the CA
stays loaded. Can be NULL.
\param caKeySz set to the size of caKey in bytes, or to 0. Must not be
NULL when caKey is not NULL.

_Example_
\code
const byte* caKey = NULL;
word32 caKeySz = 0;

int ret = wc_CheckCertSignature_ex(cert, certSz, NULL, cm, &caKey,
&caKeySz);
if (ret == 0) {
// caKey and caKeySz give the key of the CA that verified cert
}
\endcode

\sa wc_CheckCertSignature
*/
int wc_CheckCertSignature_ex(const byte* cert, word32 certSz, void* heap,
WOLFSSL_CERT_MANAGER* cm, const byte** caKey,
word32* caKeySz);

/*!
\ingroup ASN
\brief This function encodes an array of word16 values into an ASN.1
Expand Down
16 changes: 14 additions & 2 deletions src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -17405,6 +17405,8 @@ static int ProcessPeerCertParse(WOLFSSL* ssl, ProcPeerCertArgs* args,
#endif
#ifdef WOLFSSL_SMALL_CERT_VERIFY
int sigRet = 0;
const byte* sigCaKey = NULL;
word32 sigCaKeySz = 0;
#endif

if (ssl == NULL || args == NULL
Expand Down Expand Up @@ -17477,8 +17479,9 @@ PRAGMA_GCC_DIAG_POP
}

/* perform cert parsing and signature check */
sigRet = wc_CheckCertSignature(cert->buffer, cert->length,
ssl->heap, SSL_CM(ssl));
sigRet = wc_CheckCertSignature_ex(cert->buffer, cert->length,
ssl->heap, SSL_CM(ssl), &sigCaKey,
&sigCaKeySz);
/* fail on errors here after the ParseCertRelative call, so dCert is populated */

/* verify name only in ParseCertRelative below, signature check done */
Expand Down Expand Up @@ -17525,6 +17528,15 @@ PRAGMA_GCC_DIAG_POP
#endif
/* Parse Certificate */
ret = ParseCertRelative(args->dCert, certType, verify, SSL_CM(ssl), extraSigners);
#ifdef WOLFSSL_SMALL_CERT_VERIFY
/* Self signed: the key that verified the signature is its own */
if (verify == VERIFY_NAME && sigRet == 0 && sigCaKey != NULL &&
args->dCert->publicKey != NULL) {
args->dCert->selfSigned = args->dCert->selfIssued &&
sigCaKeySz == args->dCert->pubKeySize &&
XMEMCMP(sigCaKey, args->dCert->publicKey, sigCaKeySz) == 0;
}
#endif

#if defined(HAVE_RPK)
/* Confirm the received certificate's form (X.509 vs raw public key) matches
Expand Down
Loading
Loading