|
|
bf760f |
diff -up openssl-3.0.0-alpha13/crypto/context.c.kernel-fips openssl-3.0.0-alpha13/crypto/context.c
|
|
|
bf760f |
--- openssl-3.0.0-alpha13/crypto/context.c.kernel-fips 2021-03-16 00:09:55.814826432 +0100
|
|
|
bf760f |
+++ openssl-3.0.0-alpha13/crypto/context.c 2021-03-16 00:15:55.129043811 +0100
|
|
|
bf760f |
@@ -12,11 +12,46 @@
|
|
|
bf760f |
#include "internal/bio.h"
|
|
|
bf760f |
#include "internal/provider.h"
|
|
|
bf760f |
|
|
|
bf760f |
+# include <sys/types.h>
|
|
|
bf760f |
+# include <sys/stat.h>
|
|
|
bf760f |
+# include <fcntl.h>
|
|
|
bf760f |
+# include <unistd.h>
|
|
|
bf760f |
+# include <openssl/evp.h>
|
|
|
bf760f |
+
|
|
|
bf760f |
struct ossl_lib_ctx_onfree_list_st {
|
|
|
bf760f |
ossl_lib_ctx_onfree_fn *fn;
|
|
|
bf760f |
struct ossl_lib_ctx_onfree_list_st *next;
|
|
|
bf760f |
};
|
|
|
bf760f |
|
|
|
bf760f |
+# define FIPS_MODE_SWITCH_FILE "/proc/sys/crypto/fips_enabled"
|
|
|
bf760f |
+
|
|
|
bf760f |
+static int kernel_fips_flag;
|
|
|
bf760f |
+
|
|
|
bf760f |
+static void read_kernel_fips_flag(void)
|
|
|
bf760f |
+{
|
|
|
bf760f |
+ char buf[2] = "0";
|
|
|
bf760f |
+ int fd;
|
|
|
bf760f |
+
|
|
|
bf760f |
+ if (ossl_safe_getenv("OPENSSL_FORCE_FIPS_MODE") != NULL) {
|
|
|
bf760f |
+ buf[0] = '1';
|
|
|
bf760f |
+ } else if ((fd = open(FIPS_MODE_SWITCH_FILE, O_RDONLY)) >= 0) {
|
|
|
bf760f |
+ while (read(fd, buf, sizeof(buf)) < 0 && errno == EINTR) ;
|
|
|
bf760f |
+ close(fd);
|
|
|
bf760f |
+ }
|
|
|
bf760f |
+
|
|
|
bf760f |
+ if (buf[0] == '1') {
|
|
|
bf760f |
+ kernel_fips_flag = 1;
|
|
|
bf760f |
+ }
|
|
|
bf760f |
+
|
|
|
bf760f |
+ return;
|
|
|
bf760f |
+}
|
|
|
bf760f |
+
|
|
|
bf760f |
+int ossl_get_kernel_fips_flag()
|
|
|
bf760f |
+{
|
|
|
bf760f |
+ return kernel_fips_flag;
|
|
|
bf760f |
+}
|
|
|
bf760f |
+
|
|
|
bf760f |
+
|
|
|
bf760f |
struct ossl_lib_ctx_st {
|
|
|
bf760f |
CRYPTO_RWLOCK *lock;
|
|
|
bf760f |
CRYPTO_EX_DATA data;
|
|
|
bf760f |
@@ -121,6 +170,7 @@ static CRYPTO_THREAD_LOCAL default_conte
|
|
|
bf760f |
|
|
|
bf760f |
DEFINE_RUN_ONCE_STATIC(default_context_do_init)
|
|
|
bf760f |
{
|
|
|
bf760f |
+ read_kernel_fips_flag();
|
|
|
bf760f |
return CRYPTO_THREAD_init_local(&default_context_thread_local, NULL)
|
|
|
bf760f |
&& context_init(&default_context_int);
|
|
|
bf760f |
}
|
|
|
bf760f |
diff -up openssl-3.0.1/include/internal/provider.h.embed-fips openssl-3.0.1/include/internal/provider.h
|
|
|
bf760f |
--- openssl-3.0.1/include/internal/provider.h.embed-fips 2022-01-11 13:13:08.323238760 +0100
|
|
|
bf760f |
+++ openssl-3.0.1/include/internal/provider.h 2022-01-11 13:13:43.522558909 +0100
|
|
|
bf760f |
@@ -110,6 +110,9 @@ int ossl_provider_init_as_child(OSSL_LIB
|
|
|
bf760f |
const OSSL_DISPATCH *in);
|
|
|
bf760f |
void ossl_provider_deinit_child(OSSL_LIB_CTX *ctx);
|
|
|
bf760f |
|
|
|
bf760f |
+/* FIPS flag access */
|
|
|
bf760f |
+int ossl_get_kernel_fips_flag(void);
|
|
|
bf760f |
+
|
|
|
bf760f |
# ifdef __cplusplus
|
|
|
bf760f |
}
|
|
|
bf760f |
# endif
|