Skip to content

Commit 15fdf6e

Browse files
Merge pull request #6910 from bigbrett/ios-ca-api
exercise --sys-ca-certs optionin external.test
2 parents c920337 + 89d445a commit 15fdf6e

4 files changed

Lines changed: 43 additions & 17 deletions

File tree

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,10 +1723,16 @@ if(WOLFSSL_SYS_CA_CERTS)
17231723
message("Can't enable system CA certs without a filesystem.")
17241724
override_cache(WOLFSSL_SYS_CA_CERTS "no")
17251725
elseif(APPLE)
1726+
# Headers used for MacOS default system CA certs behavior. Only MacOS SDK will have this header
17261727
check_include_file("Security/SecTrustSettings.h" HAVE_SECURITY_SECTRUSTSETTINGS_H)
1728+
# Headers used for Apple native cert validation. All device SDKs should have these headers
17271729
check_include_file("Security/SecCertificate.h" HAVE_SECURITY_SECCERTIFICATE_H)
17281730
check_include_file("Security/SecTrust.h" HAVE_SECURITY_SECTRUST_H)
17291731
check_include_file("Security/SecPolicy.h" HAVE_SECURITY_SECPOLICY_H)
1732+
# Either Security/SecTrustSettings (for MacOS cert loading), or the
1733+
# trio of Security/SecCertificate.h, Security/SecTrust.h, and
1734+
# Security/SecPolicy.h (for native trust APIs on other apple devices)
1735+
# must be present. Default to SecTrustSettings method on MacOS.
17301736
if(HAVE_SECURITY_SECTRUSTSETTINGS_H OR (HAVE_SECURITY_SECCERTIFICATE_H
17311737
AND HAVE_SECURITY_SECTRUST_H
17321738
AND HAVE_SECURITY_SECPOLICY_H))
@@ -1739,6 +1745,14 @@ if(WOLFSSL_SYS_CA_CERTS)
17391745
message(FATAL_ERROR "Can't enable system CA certs without Security framework.")
17401746
endif()
17411747
endif()
1748+
1749+
# MacOS should not use native cert validation by default, but other apple devices should.
1750+
if(NOT HAVE_SECURITY_SECTRUSTSETTINGS_H AND HAVE_SECURITY_SECCERTIFICATE_H
1751+
AND HAVE_SECURITY_SECTRUST_H
1752+
AND HAVE_SECURITY_SECPOLICY_H)
1753+
list(APPEND WOLFSSL_DEFINITIONS "-DWOLFSSL_APPLE_NATIVE_CERT_VALIDATION")
1754+
endif()
1755+
17421756
else()
17431757
message(FATAL_ERROR "Can't enable system CA certs without Apple Security.framework headers.")
17441758
endif()

configure.ac

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8351,26 +8351,30 @@ then
83518351

83528352
case $host_os in
83538353
*darwin*)
8354-
# Creates the HAVE_SECURITY_SECXXX_H macros in config.h
8354+
# Headers used for MacOS default system CA certs behavior. Only MacOS SDK will have this header
83558355
AC_CHECK_HEADERS([Security/SecTrustSettings.h])
8356+
# Headers used for Apple native cert validation. All device SDKs should have these headers
83568357
AC_CHECK_HEADERS([Security/SecCertificate.h])
83578358
AC_CHECK_HEADERS([Security/SecTrust.h])
83588359
AC_CHECK_HEADERS([Security/SecPolicy.h])
83598360
# Either Security/SecTrustSettings (for MacOS cert loading), or the
83608361
# trio of Security/SecCertificate.h, Security/SecTrust.h, and
8361-
# Security/SecPolicy.h (for native trust APIs other apple devices)
8362-
# must be present
8363-
AS_IF([test -n "$ac_cv_header_Security_SecTrustSettings_h" \
8364-
|| (test -n "$ac_cv_header_Security_SecCertificate_h" \
8365-
&& test -n "$ac_cv_header_Security_SecTrust_h" \
8366-
&& test -n "$ac_cv_header_Security_SecPolicy_h")],
8362+
# Security/SecPolicy.h (for native trust APIs on other apple devices)
8363+
# must be present. Default to SecTrustSettings method on MacOS.
8364+
AS_IF([test "$ac_cv_header_Security_SecTrustSettings_h" = "yes" \
8365+
|| (test "$ac_cv_header_Security_SecCertificate_h" = "yes" \
8366+
&& test "$ac_cv_header_Security_SecTrust_h" = "yes" \
8367+
&& test "$ac_cv_header_Security_SecPolicy_h" = "yes")],
8368+
[
8369+
LDFLAGS="$LDFLAGS -framework CoreFoundation -framework Security"
8370+
AS_IF([test "$ac_cv_header_Security_SecTrustSettings_h" != "yes"],
83678371
[
8368-
LDFLAGS="$LDFLAGS -framework CoreFoundation -framework Security"
8369-
],
8370-
[
8371-
AC_MSG_ERROR([Unable to find Apple Security.framework headers])
8372-
]
8373-
)
8372+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_APPLE_NATIVE_CERT_VALIDATION"
8373+
])
8374+
],
8375+
[
8376+
AC_MSG_ERROR([Unable to find Apple Security.framework headers])
8377+
])
83748378
;;
83758379
esac
83768380
fi

scripts/external.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,15 @@ RESULT=$?
4545
RESULT=$?
4646
[ $RESULT -ne 0 ] && echo -e "\n\nClient connection failed" && exit 1
4747

48+
# test again, but using system CA certs to verify the server if support is enabled.
49+
# We don't want to use --sys-ca-certs with static memory, as we don't know how
50+
# much memory will be required to store an unbounded number of certs
51+
BUILD_FLAGS="$(./examples/client/client '-#')"
52+
if echo "$BUILD_FLAGS" | grep -q "WOLFSSL_SYS_CA_CERTS" && ! echo "$BUILD_FLAGS" | grep -q "WOLFSSL_STATIC_MEMORY"; then
53+
echo -e "\nConnecting using WOLFSSL_SYS_CA_CERTS..."
54+
./examples/client/client -X -C -h $server -p 443 -g --sys-ca-certs
55+
RESULT=$?
56+
[ $RESULT -ne 0 ] && echo -e "\n\nClient connection failed when using WOLFSSL_SYS_CA_CERTS" && exit 1
57+
fi
58+
4859
exit 0

src/ssl.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8572,10 +8572,7 @@ int wolfSSL_CTX_load_system_CA_certs(WOLFSSL_CTX* ctx)
85728572
* load them manually into wolfSSL "the old way". Accessiblity of this API
85738573
* is indicated by the presence of the Security/SecTrustSettings.h header */
85748574
ret = LoadSystemCaCertsMac(ctx, &loaded);
8575-
#elif defined(WOLFSSL_APPLE_NATIVE_CERT_VALIDATION) \
8576-
|| (defined(HAVE_SECURITY_SECCERTIFICATE_H) \
8577-
&& defined(HAVE_SECURITY_SECTRUST_H) \
8578-
&& defined(HAVE_SECURITY_SECPOLICY_H))
8575+
#elif defined(WOLFSSL_APPLE_NATIVE_CERT_VALIDATION)
85798576
/* For other Apple devices, Apple has removed the ability to obtain
85808577
* certificates from the trust store, so we can't use wolfSSL's built-in
85818578
* certificate validation mechanisms anymore. We instead must call into the

0 commit comments

Comments
 (0)