openssl: make UCI config aware of built-in engines
authorEneas U de Queiroz <cotequeiroz@gmail.com>
Tue, 14 Mar 2023 21:51:45 +0000 (18:51 -0300)
committerEneas U de Queiroz <cotequeiroz@gmail.com>
Wed, 5 Apr 2023 11:24:49 +0000 (08:24 -0300)
Engines that are built into the main libcrypto OpenSSL library can't be
disabled through UCI.  Add a 'builtin' setting to signal that the engine
can't be disabled through UCI, and show a message explaining this in
case buitin=1 and enabled=0.

Signed-off-by: Eneas U de Queiroz <cotequeiroz@gmail.com>
package/libs/openssl/Makefile
package/libs/openssl/files/openssl.init

index b076a9c1fa1651a351d4f6e2401301023049254b..66872d54366944923bd015d65d0a8a6e951cdef1 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=openssl
 PKG_VERSION:=3.0.8
-PKG_RELEASE:=5
+PKG_RELEASE:=6
 PKG_BUILD_FLAGS:=no-mips16 gc-sections
 
 PKG_BUILD_PARALLEL:=1
@@ -138,6 +138,30 @@ $(call Package/openssl/Default/description)
 This package installs the OpenSSL configuration file /etc/ssl/openssl.cnf.
 endef
 
+ifneq ($(CONFIG_OPENSSL_ENGINE_BUILTIN_PADLOCK)$(CONFIG_OPENSSL_ENGINE_BUILTIN_DEVCRYPTO),)
+define Package/libopenssl-conf/postinst
+#!/bin/sh
+OPENSSL_UCI="$${IPKG_INSTROOT}/etc/config/openssl"
+
+add_engine_config() {
+       if [ -z "$${IPKG_INSTROOT}" ] && uci -q get "openssl.$$1" >/dev/null; then
+               [ "$$(uci -q get "openssl.$$1.builtin")" = 1 ] && return
+               uci set "openssl.$$1.builtin=1" && uci commit openssl
+               return
+       fi
+       {
+               echo "engine '$$1'"
+               echo "  option enabled '1'"
+               echo "  option builtin '1'"
+               echo
+       } >>"$${OPENSSL_UCI}"
+}
+
+$(if $(CONFIG_OPENSSL_ENGINE_BUILTIN_DEVCRYPTO),add_engine_config devcrypto)
+$(if $(CONFIG_OPENSSL_ENGINE_BUILTIN_PADLOCK),add_engine_config padlock)
+endef
+endif
+
 $(eval $(call Package/openssl/add-engine,afalg))
 define Package/libopenssl-afalg
   $(call Package/openssl/Default)
index 21e253e7a5616c86c773fd447152ba6d0f774ddb..f895b9878c822e8c9188cf814c4802e72dd28442 100755 (executable)
@@ -6,15 +6,26 @@ ENGINES_CNF="/var/etc/ssl/engines.cnf"
 ENGINES_DIR="%ENGINES_DIR%"
 
 config_engine() {
-       local enabled force
+       local builtin enabled force
+
+       config_get_bool builtin "$1" builtin 0
        config_get_bool enabled "$1" enabled 1
        config_get_bool force "$1" force 0
-       [ "$enabled" = 0 ] && return
-       if [ "$force" = 0 ] && \
-          [ ! -f "${ENGINES_CNF_D}/$1.cnf" ] && \
-          [ ! -f "${ENGINES_DIR}/$1.so" ]; then
-           echo Skipping engine "$1": not installed
-           return
+
+       if [ "$enabled" = 0 ]; then
+               [ "$builtin" != 1 ] && return 1
+               echo "Engine $1 is built into the libcrypto library and can't be disabled through UCI." && \
+               echo "If the engine was not built-in, remove 'config builtin' from /etc/config/openssl."
+       elif [ "$force" = 1 ]; then
+               printf "[Forced] "
+       elif ! grep -q "\\[ *$1 *]" "${ENGINES_CNF_D}"/*; then
+               echo "$1: Could not find section [$1] in config files."
+               return 1
+       elif [ "$builtin" = 1 ]; then
+               printf "[Builtin] "
+       elif [ ! -f "${ENGINES_DIR}/$1.so" ];then
+               echo "$1: ${ENGINES_DIR}/$1.so not found."
+               return 1
        fi
        echo Enabling engine "$1"
        echo "$1=$1" >> "${ENGINES_CNF}"