Skip to contentSkip to conversation

ima-evm-utils: rework openssl init

PATCH Superseded Vitaly Chikunov 2 participants 5 messages Feb 3, 2019 – Mar 23, 2019 Keys-trusted

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ima-evm-utils: rework openssl init

Remove deprecated call to OpenSSL_add_all_algorithms(). Allow to disable openssl config loading via configure `--disable-openssl-conf' option.
Finish engine initialization properly by calling ENGINE_set_default(), as suggested by James Bottomley.

---
- v1 is "ima-evm-utils: remove redundant call to OpenSSL_add_all_algorithms"
- everything is changed as suggested in mailing list, not just redundant OpenSSL_add_all_algorithms() call is removed.

 configure.ac    | 6 ++++++
 src/evmctl.c    | 1 +
 src/libimaevm.c | 8 ++++++--
 3 files changed, 13 insertions(+), 2 deletions(-)
configure.ac +6 -0
index 60f3684..ff8ac29 100644
@@ -39,6 +39,12 @@ AC_ARG_WITH(kernel_headers, [AS_HELP_STRING([--with-kernel-headers=PATH],
 	    [KERNEL_HEADERS="$withval"],
 	    [KERNEL_HEADERS=/lib/modules/$(uname -r)/source])
 
+AC_ARG_ENABLE([openssl_conf],
+	      [AS_HELP_STRING([--disable-openssl-conf], [disable loading of openssl config by libimaevm])],
+	      if test "$enable_openssl_conf" = "no"; then
+		AC_DEFINE(DISABLE_OPENSSL_CONF, 1, [Define to disable loading of openssl config by libimaevm.])
+	      fi)
+
 #debug support - yes for a while
 PKG_ARG_ENABLE(debug, "yes", DEBUG, [Enable Debug support])
 if test $pkg_cv_enable_debug = yes; then
src/evmctl.c +1 -0
index 2e4d551..fa074c4 100644
@@ -1904,6 +1904,7 @@ int main(int argc, char *argv[])
 				ENGINE_free(eng);
 				eng = NULL;
 			}
+			ENGINE_set_default(eng, ENGINE_METHOD_ALL);
 			break;
 		case 140: /* --xattr-user */
 			xattr_ima = "user.ima";
src/libimaevm.c +6 -2
index 799eeec..db27c6f 100644
@@ -976,7 +976,11 @@ int sign_hash(const char *hashalgo, const unsigned char *hash, int size, const c
 
 static void libinit()
 {
-	OpenSSL_add_all_algorithms();
-	OPENSSL_add_all_algorithms_conf();
+	OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS |
+			    OPENSSL_INIT_ADD_ALL_DIGESTS |
+#ifndef DISABLE_OPENSSL_CONF
+			    OPENSSL_INIT_LOAD_CONFIG |
+#endif
+			    OPENSSL_INIT_ENGINE_ALL_BUILTIN, NULL);
 	ERR_load_crypto_strings();
 }
Signature · 1 line
2.11.0
maintainer
#1 lore raw
Quoted 7 lines · Vitaly Chikunov

Remove deprecated call to OpenSSL_add_all_algorithms(). Allow to disable openssl config loading via configure `--disable-openssl-conf' option.
Finish engine initialization properly by calling ENGINE_set_default(), as suggested by James Bottomley.

Thanks!

Mimi

maintainer
#2 lore raw
In reply to Vitaly Chikunov

Hi Vitaly,

Quoted 6 lines · Vitaly Chikunov

Remove deprecated call to OpenSSL_add_all_algorithms(). Allow to disable openssl config loading via configure `--disable-openssl-conf' option.
Finish engine initialization properly by calling ENGINE_set_default(), as suggested by James Bottomley.

Thanks, could you also display the status under "Give some feedback".

Mimi

Quoted 58 lines

---
- v1 is "ima-evm-utils: remove redundant call to OpenSSL_add_all_algorithms"
- everything is changed as suggested in mailing list, not just redundant OpenSSL_add_all_algorithms() call is removed.

 configure.ac    | 6 ++++++
 src/evmctl.c    | 1 +
 src/libimaevm.c | 8 ++++++--
 3 files changed, 13 insertions(+), 2 deletions(-)
configure.ac +6 -0
index 60f3684..ff8ac29 100644
@@ -39,6 +39,12 @@ AC_ARG_WITH(kernel_headers, [AS_HELP_STRING([--with-kernel-headers=PATH],
 	    [KERNEL_HEADERS="$withval"],
 	    [KERNEL_HEADERS=/lib/modules/$(uname -r)/source])
 
+AC_ARG_ENABLE([openssl_conf],
+	      [AS_HELP_STRING([--disable-openssl-conf], [disable loading of openssl config by libimaevm])],
+	      if test "$enable_openssl_conf" = "no"; then
+		AC_DEFINE(DISABLE_OPENSSL_CONF, 1, [Define to disable loading of openssl config by libimaevm.])
+	      fi)
+
 #debug support - yes for a while
 PKG_ARG_ENABLE(debug, "yes", DEBUG, [Enable Debug support])
 if test $pkg_cv_enable_debug = yes; then
src/evmctl.c +1 -0
index 2e4d551..fa074c4 100644
@@ -1904,6 +1904,7 @@ int main(int argc, char *argv[])
 				ENGINE_free(eng);
 				eng = NULL;
 			}
+			ENGINE_set_default(eng, ENGINE_METHOD_ALL);
 			break;
 		case 140: /* --xattr-user */
 			xattr_ima = "user.ima";
src/libimaevm.c +6 -2
index 799eeec..db27c6f 100644
@@ -976,7 +976,11 @@ int sign_hash(const char *hashalgo, const unsigned char *hash, int size, const c
 
 static void libinit()
 {
-	OpenSSL_add_all_algorithms();
-	OPENSSL_add_all_algorithms_conf();
+	OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS |
+			    OPENSSL_INIT_ADD_ALL_DIGESTS |
+#ifndef DISABLE_OPENSSL_CONF
+			    OPENSSL_INIT_LOAD_CONFIG |
+#endif
+			    OPENSSL_INIT_ENGINE_ALL_BUILTIN, NULL);
 	ERR_load_crypto_strings();
 }
#3 lore raw

Mimi,

Quoted 10 lines · Mimi Zohar
Quoted 6 lines · Vitaly Chikunov

Remove deprecated call to OpenSSL_add_all_algorithms(). Allow to disable openssl config loading via configure `--disable-openssl-conf' option.
Finish engine initialization properly by calling ENGINE_set_default(), as suggested by James Bottomley.

Thanks, could you also display the status under "Give some feedback".

OK.

Quoted 62 lines

Mimi

Quoted 58 lines

---
- v1 is "ima-evm-utils: remove redundant call to OpenSSL_add_all_algorithms"
- everything is changed as suggested in mailing list, not just redundant OpenSSL_add_all_algorithms() call is removed.

 configure.ac    | 6 ++++++
 src/evmctl.c    | 1 +
 src/libimaevm.c | 8 ++++++--
 3 files changed, 13 insertions(+), 2 deletions(-)
configure.ac +6 -0
index 60f3684..ff8ac29 100644
@@ -39,6 +39,12 @@ AC_ARG_WITH(kernel_headers, [AS_HELP_STRING([--with-kernel-headers=PATH],
 	    [KERNEL_HEADERS="$withval"],
 	    [KERNEL_HEADERS=/lib/modules/$(uname -r)/source])
 
+AC_ARG_ENABLE([openssl_conf],
+	      [AS_HELP_STRING([--disable-openssl-conf], [disable loading of openssl config by libimaevm])],
+	      if test "$enable_openssl_conf" = "no"; then
+		AC_DEFINE(DISABLE_OPENSSL_CONF, 1, [Define to disable loading of openssl config by libimaevm.])
+	      fi)
+
 #debug support - yes for a while
 PKG_ARG_ENABLE(debug, "yes", DEBUG, [Enable Debug support])
 if test $pkg_cv_enable_debug = yes; then
src/evmctl.c +1 -0
index 2e4d551..fa074c4 100644
@@ -1904,6 +1904,7 @@ int main(int argc, char *argv[])
 				ENGINE_free(eng);
 				eng = NULL;
 			}
+			ENGINE_set_default(eng, ENGINE_METHOD_ALL);
 			break;
 		case 140: /* --xattr-user */
 			xattr_ima = "user.ima";
src/libimaevm.c +6 -2
index 799eeec..db27c6f 100644
@@ -976,7 +976,11 @@ int sign_hash(const char *hashalgo, const unsigned char *hash, int size, const c
 
 static void libinit()
 {
-	OpenSSL_add_all_algorithms();
-	OPENSSL_add_all_algorithms_conf();
+	OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS |
+			    OPENSSL_INIT_ADD_ALL_DIGESTS |
+#ifndef DISABLE_OPENSSL_CONF
+			    OPENSSL_INIT_LOAD_CONFIG |
+#endif
+			    OPENSSL_INIT_ENGINE_ALL_BUILTIN, NULL);
 	ERR_load_crypto_strings();
 }
#4 lore raw

Mimi,

Quoted 64 lines · Vitaly Chikunov
Quoted 10 lines · Mimi Zohar
Quoted 6 lines · Vitaly Chikunov

Remove deprecated call to OpenSSL_add_all_algorithms(). Allow to disable openssl config loading via configure `--disable-openssl-conf' option.
Finish engine initialization properly by calling ENGINE_set_default(), as suggested by James Bottomley.

Thanks, could you also display the status under "Give some feedback".

OK.

Quoted 50 lines

Mimi

Quoted 46 lines

---
- v1 is "ima-evm-utils: remove redundant call to OpenSSL_add_all_algorithms"
- everything is changed as suggested in mailing list, not just redundant OpenSSL_add_all_algorithms() call is removed.

 configure.ac    | 6 ++++++
 src/evmctl.c    | 1 +
 src/libimaevm.c | 8 ++++++--
 3 files changed, 13 insertions(+), 2 deletions(-)
configure.ac +6 -0
index 60f3684..ff8ac29 100644
@@ -39,6 +39,12 @@ AC_ARG_WITH(kernel_headers, [AS_HELP_STRING([--with-kernel-headers=PATH],
 	    [KERNEL_HEADERS="$withval"],
 	    [KERNEL_HEADERS=/lib/modules/$(uname -r)/source])
 
+AC_ARG_ENABLE([openssl_conf],
+	      [AS_HELP_STRING([--disable-openssl-conf], [disable loading of openssl config by libimaevm])],
+	      if test "$enable_openssl_conf" = "no"; then
+		AC_DEFINE(DISABLE_OPENSSL_CONF, 1, [Define to disable loading of openssl config by libimaevm.])
+	      fi)
+
 #debug support - yes for a while
 PKG_ARG_ENABLE(debug, "yes", DEBUG, [Enable Debug support])
 if test $pkg_cv_enable_debug = yes; then
src/evmctl.c +1 -0
index 2e4d551..fa074c4 100644
@@ -1904,6 +1904,7 @@ int main(int argc, char *argv[])
 				ENGINE_free(eng);
 				eng = NULL;
 			}
+			ENGINE_set_default(eng, ENGINE_METHOD_ALL);
 			break;
 		case 140: /* --xattr-user */
 			xattr_ima = "user.ima";
src/libimaevm.c +0 -0
index 799eeec..db27c6f 100644
@@ -976,7 +976,11 @@ int sign_hash(const char *hashalgo, const unsigned char *hash, int size, const c
 
Quoted 10 lines
Quoted 10 lines

src/libimaevm.c int sign_hash(const char *hashalgo, const unsigned char *hash, int size, const c · line 984

Quoted 10 lines
src/libimaevm.c +6 -2
 static void libinit()
 {
-	OpenSSL_add_all_algorithms();
-	OPENSSL_add_all_algorithms_conf();
+	OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS |
+			    OPENSSL_INIT_ADD_ALL_DIGESTS |
+#ifndef DISABLE_OPENSSL_CONF
+			    OPENSSL_INIT_LOAD_CONFIG |
+#endif
+			    OPENSSL_INIT_ENGINE_ALL_BUILTIN, NULL);

I think now, that libimaevm should not load config, because it is library and that decision should be of the program that uses it.

Thus, src/libimaevm.c:libinit should only call

      OPENSSL_init_crypto(OPENSSL_INIT_ADD_ALL_CIPHERS |
			  OPENSSL_INIT_ADD_ALL_DIGESTS, NULL);

(like OpenSSL_add_all_algorithms*() was doing) and option --disable-openssl-conf should be removed.

But, evmctl should always call OPENSSL_init_crypto() again, with OPENSSL_INIT_LOAD_CONFIG | OPENSSL_INIT_ENGINE_ALL_BUILTIN.

What do you think?

If you wish we can repurpose --disable-openssl-conf to affect evmctl instead of libimaevm.

Thanks,