Skip to content

Commit 337cddf

Browse files
committed
Rework implementation to use existing weOwnCert logic
1 parent f4decf8 commit 337cddf

3 files changed

Lines changed: 4 additions & 21 deletions

File tree

src/internal.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6816,6 +6816,7 @@ int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
68166816
return ret;
68176817
}
68186818

6819+
ssl->buffers.weOwnCert = TRUE;
68196820
ret = WOLFSSL_SUCCESS;
68206821
}
68216822
if (ctx->certChain != NULL) {
@@ -6829,6 +6830,7 @@ int SetSSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx, int writeDup)
68296830
return ret;
68306831
}
68316832

6833+
ssl->buffers.weOwnCertChain = TRUE;
68326834
ret = WOLFSSL_SUCCESS;
68336835
}
68346836
#else

src/ssl.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10806,11 +10806,6 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
1080610806
return BAD_FUNC_ARG;
1080710807
}
1080810808

10809-
#ifdef WOLFSSL_COPY_CERT
10810-
/* If WOLFSSL_COPY_CERT defined, always free cert buffers in SSL obj */
10811-
FreeDer(&ssl->buffers.certificate);
10812-
FreeDer(&ssl->buffers.certChain);
10813-
#endif
1081410809
if (ssl->buffers.weOwnCert && !ssl->keepCert) {
1081510810
WOLFSSL_MSG("Unloading cert");
1081610811
FreeDer(&ssl->buffers.certificate);
@@ -19554,11 +19549,6 @@ void wolfSSL_certs_clear(WOLFSSL* ssl)
1955419549
/* ctx still owns certificate, certChain, key, dh, and cm */
1955519550
if (ssl->buffers.weOwnCert)
1955619551
FreeDer(&ssl->buffers.certificate);
19557-
#ifdef WOLFSSL_COPY_CERT
19558-
/* If WOLFSSL_COPY_CERT defined, always free cert buffers in SSL obj */
19559-
FreeDer(&ssl->buffers.certificate);
19560-
FreeDer(&ssl->buffers.certChain);
19561-
#endif
1956219552
ssl->buffers.certificate = NULL;
1956319553
if (ssl->buffers.weOwnCertChain)
1956419554
FreeDer(&ssl->buffers.certChain);
@@ -20174,6 +20164,7 @@ WOLFSSL_CTX* wolfSSL_set_SSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
2017420164
return NULL;
2017520165
}
2017620166

20167+
ssl->buffers.weOwnCert = TRUE;
2017720168
ret = WOLFSSL_SUCCESS;
2017820169
}
2017920170
if (ctx->certChain != NULL) {
@@ -20187,6 +20178,7 @@ WOLFSSL_CTX* wolfSSL_set_SSL_CTX(WOLFSSL* ssl, WOLFSSL_CTX* ctx)
2018720178
return NULL;
2018820179
}
2018920180

20181+
ssl->buffers.weOwnCertChain = TRUE;
2019020182
ret = WOLFSSL_SUCCESS;
2019120183
}
2019220184
#else

src/ssl_load.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,6 @@ static int ProcessUserChainRetain(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
236236
/* Store in SSL object if available. */
237237
if (ssl != NULL) {
238238
/* Dispose of old chain if not reference to context's. */
239-
#ifdef WOLFSSL_COPY_CERT
240-
FreeDer(&ssl->buffers.certChain);
241-
#endif
242239
if (ssl->buffers.weOwnCertChain) {
243240
FreeDer(&ssl->buffers.certChain);
244241
}
@@ -2082,10 +2079,6 @@ static int ProcessBufferCertHandleDer(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
20822079
/* Leaf certificate - our certificate. */
20832080
else if (type == CERT_TYPE) {
20842081
if (ssl != NULL) {
2085-
#ifdef WOLFSSL_COPY_CERT
2086-
/* Always Free previously set if WOLFSSL_COPY_CERT defined */
2087-
FreeDer(&ssl->buffers.certificate);
2088-
#endif
20892082
/* Free previous certificate if we own it. */
20902083
if (ssl->buffers.weOwnCert) {
20912084
FreeDer(&ssl->buffers.certificate);
@@ -4567,10 +4560,6 @@ static int wolfssl_add_to_chain(DerBuffer** chain, int weOwn, const byte* cert,
45674560
c32to24(certSz, newChain->buffer + len);
45684561
XMEMCPY(newChain->buffer + len + CERT_HEADER_SZ, cert, certSz);
45694562

4570-
#ifdef WOLFSSL_COPY_CERT
4571-
FreeDer(chain);
4572-
#endif
4573-
45744563
/* Dispose of old chain if we own it. */
45754564
if (weOwn) {
45764565
FreeDer(chain);

0 commit comments

Comments
 (0)