2023-05-31 13:21:45 +00:00
|
|
|
diff -rupN --no-dereference openssl-3.0.9/crypto/context.c openssl-3.0.9-new/crypto/context.c
|
|
|
|
--- openssl-3.0.9/crypto/context.c 2023-05-30 14:31:57.000000000 +0200
|
|
|
|
+++ openssl-3.0.9-new/crypto/context.c 2023-05-31 14:33:10.856115545 +0200
|
|
|
|
@@ -17,11 +17,46 @@
|
|
|
|
#include "crypto/ctype.h"
|
|
|
|
#include "crypto/rand.h"
|
2022-02-17 15:28:36 +00:00
|
|
|
|
|
|
|
+# include <sys/types.h>
|
|
|
|
+# include <sys/stat.h>
|
|
|
|
+# include <fcntl.h>
|
|
|
|
+# include <unistd.h>
|
|
|
|
+# include <openssl/evp.h>
|
|
|
|
+
|
|
|
|
struct ossl_lib_ctx_onfree_list_st {
|
|
|
|
ossl_lib_ctx_onfree_fn *fn;
|
|
|
|
struct ossl_lib_ctx_onfree_list_st *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
+# define FIPS_MODE_SWITCH_FILE "/proc/sys/crypto/fips_enabled"
|
|
|
|
+
|
|
|
|
+static int kernel_fips_flag;
|
|
|
|
+
|
|
|
|
+static void read_kernel_fips_flag(void)
|
|
|
|
+{
|
|
|
|
+ char buf[2] = "0";
|
|
|
|
+ int fd;
|
|
|
|
+
|
|
|
|
+ if (ossl_safe_getenv("OPENSSL_FORCE_FIPS_MODE") != NULL) {
|
|
|
|
+ buf[0] = '1';
|
|
|
|
+ } else if ((fd = open(FIPS_MODE_SWITCH_FILE, O_RDONLY)) >= 0) {
|
|
|
|
+ while (read(fd, buf, sizeof(buf)) < 0 && errno == EINTR) ;
|
|
|
|
+ close(fd);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (buf[0] == '1') {
|
|
|
|
+ kernel_fips_flag = 1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return;
|
|
|
|
+}
|
|
|
|
+
|
2023-05-31 13:21:45 +00:00
|
|
|
+int ossl_get_kernel_fips_flag()
|
2022-02-17 15:28:36 +00:00
|
|
|
+{
|
2023-05-31 13:21:45 +00:00
|
|
|
+ return kernel_fips_flag;
|
2022-02-17 15:28:36 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
struct ossl_lib_ctx_st {
|
|
|
|
CRYPTO_RWLOCK *lock;
|
|
|
|
CRYPTO_EX_DATA data;
|
2023-05-31 13:21:45 +00:00
|
|
|
@@ -151,6 +186,7 @@ static CRYPTO_THREAD_LOCAL default_conte
|
2022-02-17 15:28:36 +00:00
|
|
|
|
|
|
|
DEFINE_RUN_ONCE_STATIC(default_context_do_init)
|
|
|
|
{
|
|
|
|
+ read_kernel_fips_flag();
|
|
|
|
return CRYPTO_THREAD_init_local(&default_context_thread_local, NULL)
|
|
|
|
&& context_init(&default_context_int);
|
|
|
|
}
|
2023-05-31 13:21:45 +00:00
|
|
|
diff -rupN --no-dereference openssl-3.0.9/include/internal/provider.h openssl-3.0.9-new/include/internal/provider.h
|
|
|
|
--- openssl-3.0.9/include/internal/provider.h 2023-05-30 14:31:57.000000000 +0200
|
|
|
|
+++ openssl-3.0.9-new/include/internal/provider.h 2023-05-31 14:33:10.856115545 +0200
|
|
|
|
@@ -113,6 +113,9 @@ int ossl_provider_init_as_child(OSSL_LIB
|
|
|
|
const OSSL_DISPATCH *in);
|
|
|
|
void ossl_provider_deinit_child(OSSL_LIB_CTX *ctx);
|
|
|
|
|
|
|
|
+/* FIPS flag access */
|
|
|
|
+int ossl_get_kernel_fips_flag(void);
|
|
|
|
+
|
|
|
|
# ifdef __cplusplus
|
|
|
|
}
|
|
|
|
# endif
|