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
19 changes: 19 additions & 0 deletions src/native/libs/System.Security.Cryptography.Native/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,13 @@ int32_t CryptoNative_BioSeek(BIO* bio, int32_t ofs)
return BIO_seek(bio, ofs);
}

#ifdef FEATURE_DISTRO_AGNOSTIC_SSL
static void local_sk_X509_freefunc_thunk(OPENSSL_sk_freefunc freefunc_arg, void* ptr)
{
freefunc_arg(ptr);
}
#endif

/*
Function:
NewX509Stack
Expand All @@ -1054,7 +1061,19 @@ A STACK_OF(X509*) with no comparator.
STACK_OF(X509) * CryptoNative_NewX509Stack(void)
{
ERR_clear_error();

#ifdef FEATURE_DISTRO_AGNOSTIC_SSL
OPENSSL_STACK* sk = OPENSSL_sk_new_null();

if (API_EXISTS(OPENSSL_sk_set_thunks))
{
OPENSSL_sk_set_thunks(sk, local_sk_X509_freefunc_thunk);
}

return (STACK_OF(X509)*)sk;
#else
return sk_X509_new_null();
#endif
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ static void OpenLibraryOnce(void)
{
DlOpen(MAKELIB("1.1"));
}

// While it's still in alpha, OpenSSL 4 is probed, but not preferred.
if (libssl == NULL)
{
DlOpen(MAKELIB("4"));
}
}

static pthread_once_t g_openLibrary = PTHREAD_ONCE_INIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1423,9 +1423,6 @@ extern TYPEOF(OPENSSL_gmtime)* OPENSSL_gmtime_ptr;
#define sk_X509_NAME_num(stack) OPENSSL_sk_num((const OPENSSL_STACK*)(1 ? stack : (const STACK_OF(X509_NAME)*)0))
#define sk_X509_num(stack) OPENSSL_sk_num((const OPENSSL_STACK*)(1 ? stack : (const STACK_OF(X509)*)0))

// type-safe OPENSSL_sk_new_null
#define sk_X509_new_null() (STACK_OF(X509)*)OPENSSL_sk_new_null()

// type-safe OPENSSL_sk_push
#define sk_X509_push(stack,value) OPENSSL_sk_push((OPENSSL_STACK*)(1 ? stack : (STACK_OF(X509)*)0), (const void*)(1 ? value : (X509*)0))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <string.h>
#include <unistd.h>

#include "openssl.h"

#ifndef NAME_MAX
#error "NAME_MAX is not defined"
#endif
Expand Down Expand Up @@ -625,7 +627,7 @@ int32_t CryptoNative_X509StackAddDirectoryStore(X509Stack* stack, char* storePat
if (storeDir != NULL)
{
X509* cert;
X509Stack* tmpStack = sk_X509_new_null();
X509Stack* tmpStack = CryptoNative_NewX509Stack();

if (tmpStack == NULL)
{
Expand Down Expand Up @@ -1348,7 +1350,7 @@ int32_t CryptoNative_X509DecodeOcspToExpiration(const uint8_t* buf, int32_t len,

if (store != NULL)
{
bag = sk_X509_new_null();
bag = CryptoNative_NewX509Stack();
}

if (bag != NULL)
Expand Down
Loading