|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
diff -up openssl-3.0.0-alpha13/crypto/context.c.kernel-fips openssl-3.0.0-alpha13/crypto/context.c
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
--- openssl-3.0.0-alpha13/crypto/context.c.kernel-fips 2021-03-16 00:09:55.814826432 +0100
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+++ openssl-3.0.0-alpha13/crypto/context.c 2021-03-16 00:15:55.129043811 +0100
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
@@ -12,11 +12,54 @@
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
#include "internal/bio.h"
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
#include "internal/provider.h"
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+#ifndef FIPS_MODULE
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+# include <sys/types.h>
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+# include <sys/stat.h>
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+# include <fcntl.h>
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+# include <unistd.h>
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+# include <openssl/evp.h>
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+#endif
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
struct ossl_lib_ctx_onfree_list_st {
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
ossl_lib_ctx_onfree_fn *fn;
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
struct ossl_lib_ctx_onfree_list_st *next;
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
};
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+# ifndef FIPS_MODULE
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+# define FIPS_MODE_SWITCH_FILE "/proc/sys/crypto/fips_enabled"
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+static int kernel_fips_flag;
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+static void read_kernel_fips_flag(void)
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+{
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ char buf[2] = "0";
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ int fd;
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ if (ossl_safe_getenv("OPENSSL_FORCE_FIPS_MODE") != NULL) {
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ buf[0] = '1';
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ } else if ((fd = open(FIPS_MODE_SWITCH_FILE, O_RDONLY)) >= 0) {
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ while (read(fd, buf, sizeof(buf)) < 0 && errno == EINTR) ;
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ close(fd);
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ }
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ if (buf[0] == '1') {
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ kernel_fips_flag = 1;
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ }
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ return;
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+}
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+static int apply_kernel_fips_flag(OSSL_LIB_CTX *ctx)
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+{
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ if (kernel_fips_flag) {
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ return EVP_default_properties_enable_fips(ctx, 1);
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ }
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ return 1;
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+}
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+# endif
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
struct ossl_lib_ctx_st {
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
CRYPTO_RWLOCK *lock;
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
CRYPTO_EX_DATA data;
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
@@ -74,6 +117,12 @@ static int context_init(OSSL_LIB_CTX *ct
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
if (!ossl_property_parse_init(ctx))
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
goto err;
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+# ifndef FIPS_MODULE
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ /* Preset the fips=yes default property with kernel FIPS mode */
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ if (!apply_kernel_fips_flag(ctx))
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ goto err;
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+# endif
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
return 1;
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
err:
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
if (exdata_done)
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
@@ -121,6 +170,7 @@ static CRYPTO_THREAD_LOCAL default_conte
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
DEFINE_RUN_ONCE_STATIC(default_context_do_init)
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
{
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
+ read_kernel_fips_flag();
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
return CRYPTO_THREAD_init_local(&default_context_thread_local, NULL)
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
&& context_init(&default_context_int);
|
|
![](https://seccdn.libravatar.org/avatar/51e79f1c8f0708302b10d192df7f68f65a35a40baf326e94c95366eb1dfd12fc?s=16&d=retro) |
347681c |
}
|