blob: 1c1e8745ffeb406834c5fd14c14f106f6ecf201c [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/bin/sh /etc/rc.common
2
3START=13
4ENGINES_CNF=/var/etc/ssl/engines.cnf
5ENGINES_DIR=%ENGINES_DIR%
6MODULES_DIR=/usr/lib/ossl-modules
7PROVIDERS_CNF=/var/etc/ssl/providers.cnf
8
9#1: cnf file
10write_cnf_header() {
11 mkdir -p "$(dirname "$1")" && \
12 echo "# This file is automatically generated from /etc/config/openssl." >"$1" || {
13 echo "Error writing to $1."
14 return 1
15 }
16}
17
18
19#1: module name
20#2: output cnf file
21#3: module.so
22enable_module() {
23 local builtin enabled force
24
25 config_get_bool builtin "$1" builtin 0
26 config_get_bool enabled "$1" enabled 1
27 config_get_bool force "$1" force 0
28
29 if [ "$enabled" = 0 ]; then
30 [ "$builtin" = 0 ] && return 1
31 echo "Engine $1 is built into the libcrypto library and can't be disabled through UCI."
32 echo "If the engine was not built-in, remove 'config builtin' from /etc/config/openssl."
33 elif [ "$force" = 1 ]; then
34 printf "[Forced] "
35 elif ! grep -q "\\[ *$1_sect *]" /etc/ssl/modules.cnf.d/*; then
36 echo "$1: Could not find section [$1] in config files."
37 return 1
38 elif [ "$builtin" = 1 ]; then
39 printf "[Builtin] "
40 elif [ ! -f "$3" ];then
41 echo "Skipping $1: $3 not found."
42 return 1
43 fi
44 echo "Enabling $1"
45 echo "$1=$1_sect" >>"$2"
46}
47
48config_engine() {
49 enable_module "$1" "$ENGINES_CNF" \
50 "${ENGINES_DIR}/${1}.so"
51}
52
53config_provider() {
54 enable_module "$1" "$PROVIDERS_CNF" \
55 "${MODULES_DIR}/${1}.so"
56}
57
58start() {
59 local ret=0
60
61 config_load openssl
62
63 echo Generating engines.cnf
64 write_cnf_header "${ENGINES_CNF}" && \
65 config_foreach config_engine engine || ret=$?
66
67 echo Generating providers.cnf
68 write_cnf_header "${PROVIDERS_CNF}" && \
69 config_foreach config_provider provider || ret=$?
70
71 return $ret
72}