|
1 | 1 | #!/bin/sh |
2 | 2 | set -e |
3 | 3 |
|
4 | | -# We currently only support "replace default" mode. |
5 | | -# In this mode, we don't need to modify the system openssl.cnf file |
6 | | -# since our modified openssl references libwolfprov.so explicitly. |
7 | | -# In the future, we should add scripting here to find the system openssl.cnf file |
8 | | -# and add the include line to it. Note that the code below |
9 | | -# references a hardcoded path which may not be correct for all systems. |
| 4 | +# Define the include line to add to the openssl.cnf file |
| 5 | +INCLUDE_LINE=".include /usr/lib/ssl/openssl.cnf.d/wolfprovider.conf" |
10 | 6 |
|
11 | | -# INCLUDE_LINE=".include /usr/lib/ssl/openssl.cnf.d/wolfprovider.conf" |
12 | | -# CONF_FILE="/usr/lib/ssl/openssl.cnf" |
13 | | -# CONF_DEFAULT="/usr/share/openssl-defaults/openssl.cnf" |
| 7 | +# Search for the openssl.cnf file in /usr, /lib and /etc |
| 8 | +CONF_FILES=$(find /usr /lib /etc -name openssl.cnf 2>/dev/null) |
14 | 9 |
|
15 | | -# # Copy from our template if it doesn't exist |
16 | | -# if [ ! -f "$CONF_FILE" ]; then |
17 | | -# echo "Config file does not exist: $CONF_FILE" |
18 | | -# if [ -f "$CONF_DEFAULT" ]; then |
19 | | -# install -Dm644 "$CONF_DEFAULT" "$CONF_FILE" |
20 | | -# else |
21 | | -# echo "Default config file does not exist: $CONF_DEFAULT" |
22 | | -# exit 1 |
23 | | -# fi |
24 | | -# fi |
| 10 | +# Check if we are in replace-default mode by reading the openssl version |
| 11 | +REPLACE_DEFAULT=0 |
| 12 | +if command -v openssl >/dev/null 2>&1; then |
| 13 | + OPENSSL_VERSION=$(openssl version) |
| 14 | + if echo "$OPENSSL_VERSION" | grep -q "wolfProvider"; then |
| 15 | + REPLACE_DEFAULT=1 |
| 16 | + fi |
| 17 | +fi |
25 | 18 |
|
26 | | -# # Add include for wolfprovider config file if not already present |
27 | | -# if grep -qF "$INCLUDE_LINE" "$CONF_FILE"; then |
28 | | -# echo "Include line already exists in $CONF_FILE" |
29 | | -# else |
30 | | -# echo "Adding include for wolfprovider to $CONF_FILE..." |
31 | | -# sed -i "/^openssl_conf/ a $INCLUDE_LINE" "$CONF_FILE" |
32 | | -# fi |
| 19 | +if [ $REPLACE_DEFAULT -eq 1 ]; then |
| 20 | + # Remove INCLUDE_LINE from each CONF_FILE |
| 21 | + # Replace default mode should automatically find wolfProvider. |
| 22 | + # Using the config file or OPENSSL_CONF will cause: |
| 23 | + # 1. the provider name to be 'libwolfprov' instead of 'default' |
| 24 | + # 2. the provider init call to happen twice |
| 25 | + # Neither of these is harmful, but it's not ideal. |
| 26 | + for CONF_FILE in $CONF_FILES; do |
| 27 | + # Remove any line containing both ".include" and "wolfprovider.conf" |
| 28 | + sed -i '/\.include/ { /wolfprovider\.conf/ d; }' "$CONF_FILE" |
| 29 | + printf "Removed wolfprovider include line(s) from %s\n" "$CONF_FILE" |
| 30 | + done |
| 31 | +else |
| 32 | + # For each CONF_FILE, apply the include line to the openssl.cnf file, if not already applied |
| 33 | + for CONF_FILE in $CONF_FILES; do |
| 34 | + if grep -qF "$INCLUDE_LINE" "$CONF_FILE"; then |
| 35 | + echo "Include line already exists in $CONF_FILE" |
| 36 | + else |
| 37 | + echo "Adding include for wolfprovider to $CONF_FILE..." |
| 38 | + echo "$INCLUDE_LINE" >> "$CONF_FILE" |
| 39 | + fi |
| 40 | + done |
| 41 | +fi |
33 | 42 |
|
34 | 43 | #DEBHELPER# |
35 | 44 | exit 0 |
0 commit comments