]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add --fips-provider to feature-test
authorMark Andrews <marka@isc.org>
Fri, 26 Aug 2022 01:52:57 +0000 (11:52 +1000)
committerMark Andrews <marka@isc.org>
Mon, 3 Apr 2023 02:06:04 +0000 (12:06 +1000)
Check that an FIPS provider is available.  This only works with
OpenSSL 3

bin/tests/system/feature-test.c

index c27b5af23c0893204750249c956ff8c31725cc42..00d78f8f207a901f80fdcd54ee75a2efda1b7363 100644 (file)
 #include <string.h>
 #include <unistd.h>
 
+#include <openssl/crypto.h>
 #include <openssl/opensslv.h>
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L && OPENSSL_API_LEVEL >= 30000
+#include <openssl/provider.h>
+#endif
 
 #include <isc/fips.h>
 #include <isc/md.h>
@@ -37,6 +41,7 @@ usage(void) {
        fprintf(stderr, "\t--enable-dnsrps\n");
        fprintf(stderr, "\t--enable-dnstap\n");
        fprintf(stderr, "\t--enable-querytrace\n");
+       fprintf(stderr, "\t--fips-provider\n");
        fprintf(stderr, "\t--gethostname\n");
        fprintf(stderr, "\t--gssapi\n");
        fprintf(stderr, "\t--have-fips-dh\n");
@@ -95,6 +100,18 @@ main(int argc, char **argv) {
 #endif /* ifdef WANT_QUERYTRACE */
        }
 
+       if (strcasecmp(argv[1], "--fips-provider") == 0) {
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L && OPENSSL_API_LEVEL >= 30000
+               OSSL_PROVIDER *fips = OSSL_PROVIDER_load(NULL, "fips");
+               if (fips != NULL) {
+                       OSSL_PROVIDER_unload(fips);
+               }
+               return (fips != NULL ? 0 : 1);
+#else
+               return (1);
+#endif
+       }
+
        if (strcmp(argv[1], "--gethostname") == 0) {
                char hostname[_POSIX_HOST_NAME_MAX + 1];
                int n;
@@ -118,14 +135,14 @@ main(int argc, char **argv) {
 
        if (strcmp(argv[1], "--have-fips-dh") == 0) {
 #if defined(ENABLE_FIPS_MODE)
-#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L && OPENSSL_API_LEVEL >= 30000
                return (0);
 #else
                return (1);
 #endif
 #else
                if (isc_fips_mode()) {
-#if OPENSSL_VERSION_NUMBER >= 0x30000000L
+#if OPENSSL_VERSION_NUMBER >= 0x30000000L && OPENSSL_API_LEVEL >= 30000
                        return (0);
 #else
                        return (1);