Skip to content

Commit 1c3ab92

Browse files
committed
wolfSSL_get_certificate: return ctx pointer if possible
1 parent 48002a6 commit 1c3ab92

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/ssl.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14921,6 +14921,23 @@ WOLFSSL_X509* wolfSSL_get_certificate(WOLFSSL* ssl)
1492114921

1492214922
if (ssl->buffers.weOwnCert) {
1492314923
if (ssl->ourCert == NULL) {
14924+
/* Check if ctx has ourCert set - if so, use it instead of creating
14925+
* a new X509. This maintains pointer compatibility with
14926+
* applications (like nginx OCSP stapling) that use the X509 pointer
14927+
* from SSL_CTX_use_certificate as a lookup key. */
14928+
if (ssl->ctx != NULL && ssl->ctx->ourCert != NULL) {
14929+
/* Compare cert buffers to make sure they are the same */
14930+
if (ssl->buffers.certificate == NULL ||
14931+
ssl->buffers.certificate->buffer == NULL ||
14932+
(ssl->buffers.certificate->length ==
14933+
ssl->ctx->certificate->length &&
14934+
XMEMCMP(ssl->buffers.certificate->buffer,
14935+
ssl->ctx->certificate->buffer,
14936+
ssl->buffers.certificate->length) == 0)) {
14937+
ssl->ourCert = ssl->ctx->ourCert;
14938+
return ssl->ctx->ourCert;
14939+
}
14940+
}
1492414941
if (ssl->buffers.certificate == NULL) {
1492514942
WOLFSSL_MSG("Certificate buffer not set!");
1492614943
return NULL;

0 commit comments

Comments
 (0)