Skip to content

Commit d29832b

Browse files
authored
Merge pull request #158 from haydenroche5/openssh
Make various improvements, mostly around supporting OpenSSH.
2 parents 09c2dd5 + 9f16452 commit d29832b

File tree

15 files changed

+464
-157
lines changed

15 files changed

+464
-157
lines changed

configure.ac

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ then
115115
AM_CFLAGS="$AM_CFLAGS -DWE_ALIGNMENT_SAFETY"
116116
fi
117117

118+
# Adds the necessary flags to support using wolfEngine with OpenSSH.
119+
AC_ARG_ENABLE([openssh],
120+
[AS_HELP_STRING([--enable-openssh],[Support using wolfEngine with OpenSSH. (default: disabled).])],
121+
[ ENABLED_OPENSSH=$enableval ],
122+
[ ENABLED_OPENSSH=no ]
123+
)
124+
125+
if test "$ENABLED_OPENSSH" = "yes"
126+
then
127+
AM_CFLAGS="$AM_CFLAGS -DWE_RSA_USE_GLOBAL_RNG -DWE_ECC_USE_GLOBAL_RNG -DWE_DH_USE_GLOBAL_RNG"
128+
fi
129+
118130
# Single threaded
119131
AC_ARG_ENABLE([singlethreaded],
120132
[AS_HELP_STRING([--enable-singlethreaded],[Enable wolfEngine single threaded (default: disabled).])],
@@ -707,6 +719,7 @@ echo " Features "
707719
echo " * User settings: $ENABLED_USERSETTINGS"
708720
echo " * Dynamic engine: $ENABLED_DYNAMIC_ENGINE"
709721
echo " * Alignment safety: $ENABLED_ALIGNMENT_SAFETY"
722+
echo " * OpenSSH support: $ENABLED_OPENSSH"
710723
echo " * Digest:"
711724
echo " * - SHA-1: $ENABLED_SHA1"
712725
echo " * - SHA-224: $ENABLED_SHA224"

include/wolfengine/we_openssl_bc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ void EVP_MD_meth_free(EVP_MD *md);
8080
const unsigned char *EVP_CIPHER_CTX_iv(const EVP_CIPHER_CTX *ctx);
8181
void *EVP_CIPHER_CTX_get_cipher_data(const EVP_CIPHER_CTX *ctx);
8282
unsigned char *EVP_CIPHER_CTX_iv_noconst(EVP_CIPHER_CTX *ctx);
83+
int EVP_CIPHER_CTX_num(const EVP_CIPHER_CTX *ctx);
84+
void EVP_CIPHER_CTX_set_num(EVP_CIPHER_CTX *ctx, int num);
8385

8486
int EVP_CIPHER_meth_set_iv_length(EVP_CIPHER *cipher, int iv_len);
8587
int EVP_CIPHER_meth_set_flags(EVP_CIPHER *cipher, unsigned long flags);

scripts/build-openssl-wolfengine.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,16 +326,17 @@ build_wolfengine() {
326326
if [ -n "${OPENSSL_INSTALL}" ]; then
327327
./configure $OPENSSL_CPPFLAGS $OPENSSL_LDFLAGS \
328328
--with-openssl=$OPENSSL_INSTALL \
329-
--enable-debug >> $LOGFILE 2>&1
329+
--enable-debug \
330+
$WOLFENGINE_EXTRA_OPTS >> $LOGFILE 2>&1
330331
else
331332
# Tests have been patched to use debug logging - must enable debug.
332333
# User can set WOLFENGINE_EXTRA_LDFLAGS to provide extra LDFLAGS and
333334
# WOLFENGINE_EXTRA_CPPFLAGS to provide extra CPPFLAGS.
334335
./configure LDFLAGS="-L$OPENSSL_SOURCE $WOLFENGINE_EXTRA_LDFLAGS" \
335336
CPPFLAGS="$WOLFENGINE_EXTRA_CPPFLAGS" \
336337
--with-openssl=$OPENSSL_SOURCE \
337-
$WOLFENGINE_EXTRA_OPTS \
338-
--enable-debug >> $LOGFILE 2>&1
338+
--enable-debug \
339+
$WOLFENGINE_EXTRA_OPTS >> $LOGFILE 2>&1
339340
fi
340341
if [ "$?" != 0 ]; then
341342
printf "failed\n"

scripts/openssh-tests.sh

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
#!/bin/bash
2+
3+
#
4+
# Tests that using OpenSSH with wolfEngine works.
5+
#
6+
7+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
8+
WOLFENGINE_ROOT="${SCRIPT_DIR}/.."
9+
10+
if [ -z "${OPENSSL_INSTALL_DIR}" ]; then
11+
OPENSSL_INSTALL_DIR=${SCRIPT_DIR}/openssl
12+
fi
13+
OPENSSH_DIR=${SCRIPT_DIR}/openssh
14+
15+
source ${SCRIPT_DIR}/build-openssl-wolfengine.sh
16+
17+
do_cleanup() {
18+
printf "Cleaning up.\n"
19+
20+
# Use the environment variable KEEP_OPENSSH to prevent OpenSSH and OpenSSL
21+
# directories from being deleted at the end of the run.
22+
if [ -z "${KEEP_OPENSSH}" ]; then
23+
printf "\tDeleting OpenSSH directory.\n"
24+
rm -rf ${OPENSSH_DIR}
25+
26+
printf "\tDeleting OpenSSL install directory.\n"
27+
rm -rf ${OPENSSL_INSTALL_DIR}
28+
fi
29+
}
30+
31+
do_failure() {
32+
# Keep the OpenSSH and OpenSSL directories around to help debug the failure.
33+
KEEP_OPENSSH=1
34+
do_cleanup
35+
exit 1
36+
}
37+
38+
# Register trap on interrupt (2) and terminate (15)
39+
trap do_failure INT TERM
40+
41+
download_openssh() {
42+
printf "Downloading OpenSSH..."
43+
if [ -n "${OPENSSH_NO_DOWNLOAD}" -o -n "${OPENSSH_NO_BUILD}" ]; then
44+
return
45+
fi
46+
47+
rm -rf ${OPENSSH_DIR}
48+
49+
cd ${SCRIPT_DIR}
50+
51+
git clone https://github.com/openssh/openssh-portable.git $OPENSSH_DIR >> $LOGFILE 2>&1
52+
if [ $? != 0 ]; then
53+
printf "failed\n"
54+
do_failure
55+
fi
56+
printf "ok.\n"
57+
58+
cd ${WOLFENGINE_ROOT}
59+
}
60+
61+
build_openssh() {
62+
if [ -n "${OPENSSH_NO_BUILD}" ]; then
63+
return
64+
fi
65+
66+
cd ${OPENSSH_DIR}
67+
68+
printf "Building OpenSSH.\n"
69+
printf "\tRunning autoreconf..."
70+
autoreconf >> $LOGFILE 2>&1
71+
if [ $? != 0 ]; then
72+
printf "failed.\n"
73+
do_failure
74+
fi
75+
printf "ok.\n"
76+
77+
printf "\tConfiguring..."
78+
./configure --with-ssl-dir=${OPENSSL_INSTALL} --without-openssl-header-check --with-ssl-engine >> $LOGFILE 2>&1
79+
if [ $? != 0 ]; then
80+
printf "failed.\n"
81+
do_failure
82+
fi
83+
printf "ok.\n"
84+
make clean >> $LOGFILE 2>&1
85+
86+
printf "\tBuilding..."
87+
make -j$MAKE_JOBS >> $LOGFILE 2>&1
88+
if [ $? != 0 ]; then
89+
printf "failed.\n"
90+
do_failure
91+
fi
92+
printf "ok.\n"
93+
94+
cd ${WOLFENGINE_ROOT}
95+
}
96+
97+
test_openssh_separate() {
98+
cd ${OPENSSH_DIR}
99+
100+
printf "Running OpenSSH tests with wolfEngine\n"
101+
for T in connect \
102+
proxy-connect \
103+
agent \
104+
connect-privsep \
105+
connect-uri \
106+
proto-version \
107+
proto-mismatch \
108+
exit-status \
109+
envpass \
110+
transfer \
111+
banner \
112+
rekey \
113+
dhgex \
114+
stderr-data \
115+
stderr-after-eof \
116+
broken-pipe \
117+
try-ciphers \
118+
yes-head \
119+
login-timeout \
120+
agent-getpeereid \
121+
agent-timeout \
122+
agent-ptrace \
123+
agent-subprocess \
124+
keyscan \
125+
keygen-change \
126+
keygen-convert \
127+
keygen-moduli \
128+
key-options \
129+
scp \
130+
scp-uri \
131+
sftp \
132+
sftp-chroot \
133+
sftp-cmds \
134+
sftp-badcmds \
135+
sftp-batch \
136+
sftp-glob \
137+
sftp-perm \
138+
sftp-uri \
139+
reconfigure \
140+
dynamic-forward \
141+
forwarding \
142+
multiplex \
143+
reexec \
144+
brokenkeys \
145+
sshcfgparse \
146+
cfgparse \
147+
cfgmatch \
148+
cfgmatchlisten \
149+
percent \
150+
addrmatch \
151+
localcommand \
152+
forcecommand \
153+
portnum \
154+
keytype \
155+
kextype \
156+
cert-hostkey \
157+
cert-userkey \
158+
host-expand \
159+
keys-command \
160+
forward-control \
161+
integrity \
162+
krl \
163+
multipubkey \
164+
limit-keytype \
165+
hostkey-agent \
166+
keygen-knownhosts \
167+
hostkey-rotate \
168+
principals-command \
169+
cert-file \
170+
cfginclude \
171+
servcfginclude \
172+
allow-deny-users \
173+
authinfo \
174+
sshsig \
175+
keygen-comment \
176+
knownhosts-command
177+
do
178+
printf "\t$T..."
179+
make t-exec LTESTS=$T >> $LOGFILE 2>&1
180+
if [ $? != 0 ]; then
181+
printf "failed\n"
182+
do_failure
183+
fi
184+
printf "ok.\n"
185+
done
186+
187+
cd ${WOLFENGINE_ROOT}
188+
}
189+
190+
test_openssh_one() {
191+
cd ${OPENSSH_DIR}
192+
193+
printf "Running OpenSSH tests with wolfEngine\n"
194+
for T in integrity
195+
do
196+
printf "\t$T..."
197+
make t-exec LTESTS=$T >> $LOGFILE 2>&1
198+
if [ $? != 0 ]; then
199+
printf "failed\n"
200+
do_failure
201+
fi
202+
printf "ok.\n"
203+
done
204+
205+
cd ${WOLFENGINE_ROOT}
206+
}
207+
208+
test_openssh() {
209+
cd ${OPENSSH_DIR}
210+
211+
printf "Running OpenSSH tests with wolfEngine..."
212+
make tests >> $LOGFILE 2>&1
213+
if [ $? != 0 ]; then
214+
printf "failed\n"
215+
do_failure
216+
fi
217+
printf "ok.\n"
218+
219+
cd ${WOLFENGINE_ROOT}
220+
}
221+
222+
if [ -z "${LOGFILE}" ]; then
223+
LOGFILE=${SCRIPT_DIR}/openssh-tests.log
224+
fi
225+
rm -f $LOGFILE
226+
227+
export OPENSSL_EXTRA_CFLAGS="-g3 -O0 -fno-omit-frame-pointer -fno-inline-functions"
228+
229+
# Versions of OpenSSL to test
230+
if [ -n "${OPENSSL_VERSIONS}" ]; then
231+
VERSIONS=${OPENSSL_VERSIONS}
232+
else
233+
VERSIONS="1.0.2 1.1.1"
234+
fi
235+
236+
export OPENSSL_CONF=$WOLFENGINE_ROOT/engine.conf
237+
export OPENSSL_ENGINES=$WOLFENGINE_ROOT/.libs
238+
export LD_LIBRARY_PATH="$WOLFENGINE_ROOT/.libs:$WOLFENGINE_ROOT:$LD_LIBRARY_PATH"
239+
240+
download_openssh
241+
242+
for VERSION in $VERSIONS
243+
do
244+
if [ "${VERSION}" = "1.0.2" ]; then
245+
OPENSSL_VERS_STR="OpenSSL 1.0.2h"
246+
get_openssl_102h
247+
configure_openssl_102h
248+
build_openssl_102h
249+
install_openssl_102h
250+
elif [ "${VERSION}" = "1.1.1" ]; then
251+
OPENSSL_VERS_STR="OpenSSL 1.1.1b"
252+
get_openssl_111b
253+
configure_openssl_111b
254+
build_openssl_111b
255+
install_openssl_111b
256+
fi
257+
OPENSSL_INSTALL=${OPENSSL_INSTALL_DIR}
258+
setup_openssl_install
259+
260+
WOLFENGINE_EXTRA_OPTS="--enable-openssh"
261+
build_wolfengine
262+
263+
# We don't want to print debug messages as that will trigger false failures
264+
# in the OpenSSH tests.
265+
WE_DEBUG=0
266+
WE_OPENSSL_CONF=${SCRIPT_DIR}/wolfengine.conf
267+
write_conf_file
268+
269+
build_openssh
270+
test_openssh_separate
271+
done
272+
273+

0 commit comments

Comments
 (0)