forked from lkiuyu/immortalwrt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adapts the engine build infrastructure to allow building providers, and packages the legacy provider. Providers are the successors of engines, which have been deprecated. The legacy provider supplies OpenSSL implementations of algorithms that have been deemed legacy, including DES, IDEA, MDC2, SEED, and Whirlpool. Even though these algorithms are implemented in a separate package, their removal makes the regular library smaller by 3%, so the build options will remain to allow lean custom builds. Their defaults will change to 'y' if not bulding for a small flash, so that the regular legacy package will contain a complete set of algorithms. The engine build and configuration structure was changed to accomodate providers, and adapt to the new style of openssl.cnf in version 3.0. There is not a clean upgrade path for the /etc/ssl/openssl.cnf file, installed by the openssl-conf package. It is recommended to rename or remove the old config file when flashing an image with the updated openssl-conf package, then apply the changes manually. An old openssl.cnf file will silently work, but new engine or provider packages will not be enabled. Any remaining engine config files under /etc/ssl/engines.cnf.d can be removed. On the build side, the include file used by engine packages was renamed to openssl-module.mk, so the engine packages in other feeds need to adapt. Signed-off-by: Eneas U de Queiroz <[email protected]>
- Loading branch information
1 parent
0b70d55
commit 0dc5fc8
Showing
10 changed files
with
202 additions
and
95 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# SPDX-License-Identifier: GPL-2.0-only | ||
# | ||
# Copyright (C) 2022-2023 Enéas Ulir de Queiroz | ||
|
||
ENGINES_DIR=engines-3 | ||
|
||
define Package/openssl/module/Default | ||
SECTION:=libs | ||
CATEGORY:=Libraries | ||
SUBMENU:=SSL | ||
DEPENDS:=libopenssl +libopenssl-conf | ||
endef | ||
|
||
define Package/openssl/engine/Default | ||
$(Package/openssl/module/Default) | ||
DEPENDS+=@OPENSSL_ENGINE | ||
endef | ||
|
||
|
||
# 1 = moudule type (engine|provider) | ||
# 2 = module name | ||
# 3 = directory to save .so file | ||
# 4 = [ package name, defaults to libopenssl-$(2) ] | ||
define Package/openssl/add-module | ||
$(eval MOD_TYPE:=$(1)) | ||
$(eval MOD_NAME:=$(2)) | ||
$(eval MOD_DIR:=$(3)) | ||
$(eval OSSL_PKG:=$(if $(4),$(4),libopenssl-$(MOD_NAME))) | ||
$(info Package/openssl/add-module 1='$(1)'; 2='$(2)'; 3='$(3)' 4='$(4)') | ||
$(info MOD_TYPE='$(MOD_TYPE)'; MOD_NAME='$(MOD_NAME)'; MOD_DIR='$(MOD_DIR)' OSSL_PKG='$(OSSL_PKG)') | ||
Package/$(OSSL_PKG)/conffiles:=/etc/ssl/modules.cnf.d/$(MOD_NAME).cnf | ||
|
||
define Package/$(OSSL_PKG)/install | ||
$$(INSTALL_DIR) $$(1)/$(MOD_DIR) | ||
$$(INSTALL_BIN) $$(PKG_INSTALL_DIR)/$(MOD_DIR)/$(MOD_NAME).so \ | ||
$$(1)/$(MOD_DIR) | ||
$$(INSTALL_DIR) $$(1)/etc/ssl/modules.cnf.d | ||
$$(INSTALL_DATA) ./files/$(MOD_NAME).cnf $$(1)/etc/ssl/modules.cnf.d/ | ||
endef | ||
|
||
define Package/$(OSSL_PKG)/postinst | ||
#!/bin/sh | ||
OPENSSL_UCI="$$$${IPKG_INSTROOT}/etc/config/openssl" | ||
|
||
[ -z "$$$${IPKG_INSTROOT}" ] \ | ||
&& uci -q get openssl.$(MOD_NAME) >/dev/null \ | ||
&& exit 0 | ||
|
||
cat << EOF >> "$$$${OPENSSL_UCI}" | ||
|
||
config $(MOD_TYPE) '$(MOD_NAME)' | ||
option enabled '1' | ||
EOF | ||
|
||
[ -n "$$$${IPKG_INSTROOT}" ] || /etc/init.d/openssl reload | ||
exit 0 | ||
endef | ||
|
||
define Package/$(OSSL_PKG)/postrm | ||
#!/bin/sh | ||
[ -n "$$$${IPKG_INSTROOT}" ] && exit 0 | ||
uci -q delete openssl.$(MOD_NAME) && uci commit openssl | ||
/etc/init.d/openssl reload | ||
exit 0 | ||
endef | ||
endef | ||
|
||
# 1 = engine name | ||
# 2 - package name, defaults to libopenssl-$(1) | ||
define Package/openssl/add-engine | ||
$(call Package/openssl/add-module,engine,$(1),/usr/lib/$(ENGINES_DIR),$(2)) | ||
endef | ||
|
||
# 1 = provider name | ||
# 2 = [ package name, defaults to libopenssl-$(1) ] | ||
define Package/openssl/add-provider | ||
$(call Package/openssl/add-module,provider,$(1),/usr/lib/ossl-modules,$(2)) | ||
endef | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[afalg] | ||
[afalg_sect] | ||
default_algorithms = ALL | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[legacy_sect] | ||
activate = 1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,72 @@ | ||
#!/bin/sh /etc/rc.common | ||
|
||
START=13 | ||
ENGINES_CNF_D="/etc/ssl/engines.cnf.d" | ||
ENGINES_CNF="/var/etc/ssl/engines.cnf" | ||
ENGINES_DIR="%ENGINES_DIR%" | ||
ENGINES_CNF=/var/etc/ssl/engines.cnf | ||
ENGINES_DIR=%ENGINES_DIR% | ||
MODULES_DIR=/usr/lib/ossl-modules | ||
PROVIDERS_CNF=/var/etc/ssl/providers.cnf | ||
|
||
config_engine() { | ||
#1: cnf file | ||
write_cnf_header() { | ||
mkdir -p "$(dirname "$1")" && \ | ||
echo "# This file is automatically generated from /etc/config/openssl." >"$1" || { | ||
echo "Error writing to $1." | ||
return 1 | ||
} | ||
} | ||
|
||
|
||
#1: module name | ||
#2: output cnf file | ||
#3: module.so | ||
enable_module() { | ||
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 | ||
|
||
if [ "$enabled" = 0 ]; then | ||
[ "$builtin" != 1 ] && return 1 | ||
echo "Engine $1 is built into the libcrypto library and can't be disabled through UCI." && \ | ||
[ "$builtin" = 0 ] && 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 | ||
elif ! grep -q "\\[ *$1_sect *]" /etc/ssl/modules.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." | ||
elif [ ! -f "$3" ];then | ||
echo "Skipping $1: $3 not found." | ||
return 1 | ||
fi | ||
echo Enabling engine "$1" | ||
echo "$1=$1" >> "${ENGINES_CNF}" | ||
echo "Enabling $1" | ||
echo "$1=$1_sect" >>"$2" | ||
} | ||
|
||
config_engine() { | ||
enable_module "$1" "$ENGINES_CNF" \ | ||
"${ENGINES_DIR}/${1}.so" | ||
} | ||
|
||
config_provider() { | ||
enable_module "$1" "$PROVIDERS_CNF" \ | ||
"${MODULES_DIR}/${1}.so" | ||
} | ||
|
||
start() { | ||
mkdir -p "$(dirname "${ENGINES_CNF}")" || exit 1 | ||
echo Generating engines.cnf | ||
echo "# This file is automatically generated from /etc/config/openssl." \ | ||
> "${ENGINES_CNF}" || \ | ||
{ echo Error writing ${ENGINES_CNF} >&2; exit 1; } | ||
local ret=0 | ||
|
||
config_load openssl | ||
config_foreach config_engine engine | ||
|
||
echo Generating engines.cnf | ||
write_cnf_header "${ENGINES_CNF}" && \ | ||
config_foreach config_engine engine || ret=$? | ||
|
||
echo Generating providers.cnf | ||
write_cnf_header "${PROVIDERS_CNF}" && \ | ||
config_foreach config_provider provider || ret=$? | ||
|
||
return $ret | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[padlock] | ||
[padlock_sect] | ||
default_algorithms = ALL | ||
|
Oops, something went wrong.