Skip to content

Commit fd2b80e

Browse files
Merge pull request #7245 from julek-wolfssl/transient-certs
Implement transient certs
2 parents af2b2dd + 09de233 commit fd2b80e

7 files changed

Lines changed: 315 additions & 24 deletions

File tree

doc/dox_comments/header_files/ssl.h

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7599,18 +7599,49 @@ int wolfSSL_writev(WOLFSSL* ssl, const struct iovec* iov,
75997599
WOLFSSL_METHOD method = wolfTLSv1_2_client_method();
76007600
WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(method);
76017601
7602-
if(!wolfSSL_CTX_UnloadCAs(ctx)){
7602+
if(wolfSSL_CTX_UnloadCAs(ctx) != SSL_SUCCESS){
76037603
// The function did not unload CAs
76047604
}
76057605
\endcode
76067606
76077607
\sa wolfSSL_CertManagerUnloadCAs
76087608
\sa LockMutex
7609-
\sa FreeSignerTable
76107609
\sa UnlockMutex
76117610
*/
76127611
int wolfSSL_CTX_UnloadCAs(WOLFSSL_CTX*);
76137612

7613+
7614+
/*!
7615+
\ingroup Setup
7616+
7617+
\brief This function unloads intermediate certificates added to the CA
7618+
signer list and frees them.
7619+
7620+
\return SSL_SUCCESS returned on successful execution of the function.
7621+
\return BAD_FUNC_ARG returned if the WOLFSSL_CTX struct is NULL or there
7622+
are otherwise unpermitted argument values passed in a subroutine.
7623+
\return BAD_STATE_E returned if the WOLFSSL_CTX has a reference count > 1.
7624+
\return BAD_MUTEX_E returned if there was a mutex error. The LockMutex()
7625+
did not return 0.
7626+
7627+
\param ctx a pointer to a WOLFSSL_CTX structure, created using
7628+
wolfSSL_CTX_new().
7629+
7630+
_Example_
7631+
\code
7632+
WOLFSSL_METHOD method = wolfTLSv1_2_client_method();
7633+
WOLFSSL_CTX* ctx = WOLFSSL_CTX_new(method);
7634+
7635+
if(wolfSSL_CTX_UnloadIntermediateCerts(ctx) != NULL){
7636+
// The function did not unload CAs
7637+
}
7638+
\endcode
7639+
7640+
\sa wolfSSL_CTX_UnloadCAs
7641+
\sa wolfSSL_CertManagerUnloadIntermediateCerts
7642+
*/
7643+
int wolfSSL_CTX_UnloadIntermediateCerts(WOLFSSL_CTX* ctx);
7644+
76147645
/*!
76157646
\ingroup Setup
76167647
@@ -9551,18 +9582,45 @@ int wolfSSL_CertManagerLoadCABuffer(WOLFSSL_CERT_MANAGER* cm,
95519582
#include <wolfssl/ssl.h>
95529583
95539584
WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
9554-
WOLFSSL_CERT_MANAGER* cm = wolfSSL_CertManagerNew();
9585+
WOLFSSL_CERT_MANAGER* cm = wolfSSL_CTX_GetCertManager(ctx);
95559586
...
9556-
if(wolfSSL_CertManagerUnloadCAs(ctx->cm) != SSL_SUCCESS){
9557-
Failure case.
9587+
if(wolfSSL_CertManagerUnloadCAs(cm) != SSL_SUCCESS){
9588+
Failure case.
95589589
}
95599590
\endcode
95609591
9561-
\sa FreeSignerTable
95629592
\sa UnlockMutex
95639593
*/
95649594
int wolfSSL_CertManagerUnloadCAs(WOLFSSL_CERT_MANAGER* cm);
95659595

9596+
/*!
9597+
\ingroup CertManager
9598+
\brief This function unloads intermediate certificates add to the CA
9599+
signer list.
9600+
9601+
\return SSL_SUCCESS returned on successful execution of the function.
9602+
\return BAD_FUNC_ARG returned if the WOLFSSL_CERT_MANAGER is NULL.
9603+
\return BAD_MUTEX_E returned if there was a mutex error.
9604+
9605+
\param cm a pointer to a WOLFSSL_CERT_MANAGER structure,
9606+
created using wolfSSL_CertManagerNew().
9607+
9608+
_Example_
9609+
\code
9610+
#include <wolfssl/ssl.h>
9611+
9612+
WOLFSSL_CTX* ctx = wolfSSL_CTX_new(protocol method);
9613+
WOLFSSL_CERT_MANAGER* cm = wolfSSL_CTX_GetCertManager(ctx);
9614+
...
9615+
if(wolfSSL_CertManagerUnloadIntermediateCerts(cm) != SSL_SUCCESS){
9616+
Failure case.
9617+
}
9618+
\endcode
9619+
9620+
\sa UnlockMutex
9621+
*/
9622+
int wolfSSL_CertManagerUnloadIntermediateCerts(WOLFSSL_CERT_MANAGER* cm);
9623+
95669624
/*!
95679625
\ingroup CertManager
95689626
\brief The function will free the Trusted Peer linked list and unlocks

src/ssl.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5954,6 +5954,7 @@ int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify)
59545954
cert->permittedNames = NULL;
59555955
cert->excludedNames = NULL;
59565956
#endif
5957+
signer->type = (byte)type;
59575958

59585959
#ifndef NO_SKID
59595960
row = HashSigner(signer->subjectKeyIdHash);
@@ -16355,6 +16356,22 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
1635516356
return wolfSSL_CertManagerUnloadCAs(ctx->cm);
1635616357
}
1635716358

16359+
int wolfSSL_CTX_UnloadIntermediateCerts(WOLFSSL_CTX* ctx)
16360+
{
16361+
WOLFSSL_ENTER("wolfSSL_CTX_UnloadIntermediateCerts");
16362+
16363+
if (ctx == NULL)
16364+
return BAD_FUNC_ARG;
16365+
16366+
if (ctx->ref.count > 1) {
16367+
WOLFSSL_MSG("ctx object must have a ref count of 1 before "
16368+
"unloading intermediate certs");
16369+
return BAD_STATE_E;
16370+
}
16371+
16372+
return wolfSSL_CertManagerUnloadIntermediateCerts(ctx->cm);
16373+
}
16374+
1635816375

1635916376
#ifdef WOLFSSL_TRUST_PEER_CERT
1636016377
int wolfSSL_CTX_Unload_trust_peers(WOLFSSL_CTX* ctx)

src/ssl_certman.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,31 @@ int wolfSSL_CertManagerUnloadCAs(WOLFSSL_CERT_MANAGER* cm)
457457
return ret;
458458
}
459459

460+
int wolfSSL_CertManagerUnloadIntermediateCerts(WOLFSSL_CERT_MANAGER* cm)
461+
{
462+
int ret = WOLFSSL_SUCCESS;
463+
464+
WOLFSSL_ENTER("wolfSSL_CertManagerUnloadIntermediateCerts");
465+
466+
/* Validate parameter. */
467+
if (cm == NULL) {
468+
ret = BAD_FUNC_ARG;
469+
}
470+
/* Lock CA table. */
471+
if ((ret == WOLFSSL_SUCCESS) && (wc_LockMutex(&cm->caLock) != 0)) {
472+
ret = BAD_MUTEX_E;
473+
}
474+
if (ret == WOLFSSL_SUCCESS) {
475+
/* Dispose of CA table. */
476+
FreeSignerTableType(cm->caTable, CA_TABLE_SIZE, WOLFSSL_CHAIN_CA,
477+
cm->heap);
478+
479+
/* Unlock CA table. */
480+
wc_UnLockMutex(&cm->caLock);
481+
}
482+
483+
return ret;
484+
}
460485

461486
#ifdef WOLFSSL_TRUST_PEER_CERT
462487
/* Unload the trusted peers table.

0 commit comments

Comments
 (0)