forked from wolfSSL/wolfProvider
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils-openssl.sh
More file actions
executable file
·151 lines (132 loc) · 4.79 KB
/
utils-openssl.sh
File metadata and controls
executable file
·151 lines (132 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
#
# Copyright (C) 2006-2024 wolfSSL Inc.
#
# This file is part of wolfProvider.
#
# wolfProvider is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# wolfProvider is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with wolfProvider. If not, see <http://www.gnu.org/licenses/>.
#
#
# OpenSSL 3.5.0
#
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source ${SCRIPT_DIR}/utils-general.sh
OPENSSL_GIT_URL="https://github.com/openssl/openssl.git"
OPENSSL_TAG=${OPENSSL_TAG:-"openssl-3.5.0"}
OPENSSL_SOURCE_DIR=${SCRIPT_DIR}/../openssl-source
OPENSSL_INSTALL_DIR=${SCRIPT_DIR}/../openssl-install
OPENSSL_BIN=${OPENSSL_INSTALL_DIR}/bin/openssl
OPENSSL_TEST=${OPENSSL_SOURCE_DIR}/test
OPENSSL_LIB_DIRS="${OPENSSL_INSTALL_DIR}/lib:${OPENSSL_INSTALL_DIR}/lib64"
NUMCPU=${NUMCPU:-8}
WOLFPROV_DEBUG=${WOLFPROV_DEBUG:-0}
USE_CUR_TAG=${USE_CUR_TAG:-0}
clone_openssl() {
if [ -d ${OPENSSL_SOURCE_DIR} ] && [ "$USE_CUR_TAG" != "1" ]; then
OPENSSL_TAG_CUR=$(cd ${OPENSSL_SOURCE_DIR} && (git describe --tags 2>/dev/null || git branch --show-current))
if [ "${OPENSSL_TAG_CUR}" != "${OPENSSL_TAG}" ]; then # force a rebuild
printf "Version inconsistency. Please fix ${OPENSSL_SOURCE_DIR} (expected: ${OPENSSL_TAG}, got: ${OPENSSL_TAG_CUR})\n"
do_cleanup
exit 1
fi
fi
if [ ! -d ${OPENSSL_SOURCE_DIR} ]; then
printf "\tOpenSSL source directory not found: ${OPENSSL_SOURCE_DIR}\n"
printf "\tParent directory:\n"
tree -L 2 $(dirname ${OPENSSL_SOURCE_DIR}/..) || true
CLONE_TAG=${USE_CUR_TAG:+${OPENSSL_TAG_CUR}}
CLONE_TAG=${CLONE_TAG:-${OPENSSL_TAG}}
DEPTH_ARG=${WOLFPROV_DEBUG:+""}
DEPTH_ARG=${DEPTH_ARG:---depth=1}
printf "\tClone OpenSSL ${CLONE_TAG} from ${OPENSSL_GIT_URL} ... "
git clone ${DEPTH_ARG} -b ${CLONE_TAG} ${OPENSSL_GIT_URL} ${OPENSSL_SOURCE_DIR}
RET=$?
if [ $RET != 0 ]; then
printf "ERROR.\n"
do_cleanup
exit 1
fi
printf "Done.\n"
printf "\tOpenSSL source cloned to: ${OPENSSL_SOURCE_DIR}\n"
if [ ! -d ${OPENSSL_SOURCE_DIR} ]; then
printf "ERROR: OpenSSL source directory not found after clone: ${OPENSSL_SOURCE_DIR}\n"
fi
else
printf "\tOpenSSL source directory exists: ${OPENSSL_SOURCE_DIR}\n"
if [ ! -d ${OPENSSL_SOURCE_DIR}/.git ]; then
printf "ERROR: OpenSSL source directory is not a git repository: ${OPENSSL_SOURCE_DIR}\n"
do_cleanup
exit 1
fi
fi
}
install_openssl() {
printf "\nInstalling OpenSSL ${OPENSSL_TAG} ..."
clone_openssl
cd ${OPENSSL_SOURCE_DIR}
if [ ! -d ${OPENSSL_INSTALL_DIR} ]; then
printf "\tConfigure OpenSSL ${OPENSSL_TAG} ... "
if [ "$WOLFPROV_DEBUG" = "1" ]; then
./config shared enable-trace --prefix=${OPENSSL_INSTALL_DIR} --debug >>$LOG_FILE 2>&1
RET=$?
else
./config shared --prefix=${OPENSSL_INSTALL_DIR} >>$LOG_FILE 2>&1
RET=$?
fi
if [ $RET != 0 ]; then
printf "ERROR.\n"
rm -rf ${OPENSSL_INSTALL_DIR}
do_cleanup
exit 1
fi
printf "Done.\n"
printf "\tBuild OpenSSL ${OPENSSL_TAG} ... "
make -j$NUMCPU >>$LOG_FILE 2>&1
if [ $? != 0 ]; then
printf "ERROR.\n"
rm -rf ${OPENSSL_INSTALL_DIR}
do_cleanup
exit 1
fi
printf "Done.\n"
printf "\tInstalling OpenSSL ${OPENSSL_TAG} ... "
make -j$NUMCPU install >>$LOG_FILE 2>&1
if [ $? != 0 ]; then
printf "ERROR.\n"
rm -rf ${OPENSSL_INSTALL_DIR}
do_cleanup
exit 1
fi
printf "Done.\n"
fi
cd ..
}
init_openssl() {
install_openssl
printf "\tOpenSSL ${OPENSSL_TAG} installed in: ${OPENSSL_INSTALL_DIR}\n"
OSSL_VER=`LD_LIBRARY_PATH=${OPENSSL_LIB_DIRS} $OPENSSL_BIN version | tail -n1`
case $OSSL_VER in
OpenSSL\ 3.*) ;;
*)
echo "OpenSSL ($OPENSSL_BIN) has wrong version: $OSSL_VER"
echo "Set: OPENSSL_DIR"
exit 1
;;
esac
if [ -z $LD_LIBRARY_PATH ]; then
export LD_LIBRARY_PATH=${OPENSSL_LIB_DIRS}
else
export LD_LIBRARY_PATH=${OPENSSL_LIB_DIRS}:$LD_LIBRARY_PATH
fi
}