Skip to content

Commit 8bdfa07

Browse files
committed
Updates for OpenSSH 10.0p2
- random.c: use getrandom when available and fall back to direct file access - openssh.yml: run more tests - openssh.yml: add 10.0p2 and 9.9p2 - configure.ac: detect if `getrandom` is available on the system - configure.ac: openssh requires WC_RNG_SEED_CB to always use `getrandom` so that the RNG doesn't get killed by SECCOMP
1 parent 1549425 commit 8bdfa07

4 files changed

Lines changed: 88 additions & 49 deletions

File tree

.github/workflows/openssh.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,31 @@ jobs:
4545
fail-fast: false
4646
matrix:
4747
include:
48+
# A good way to measure how much each test takes is to create a bash script
49+
# in the openssh root like this (make it executable):
50+
# time-measure.sh
51+
# #!/bin/bash
52+
# /usr/bin/time -a -o /tmp/LTESTS-times.txt -f '%e %C' /usr/bin/bash "$@"
53+
# And invoke the openssh tests like this:
54+
# rm -f /tmp/LTESTS-times.txt && \
55+
# make tests TEST_SHELL=$(pwd)/time-measure.sh SKIP_UNIT=yes && \
56+
# grep test-exec.sh /tmp/LTESTS-times.txt
4857
- git_ref: 'V_9_6_P1'
4958
osp_ver: '9.6'
50-
name: ${{ matrix.ref }}
59+
SKIP_LTESTS: >-
60+
exit-status rekey multiplex cert-userkey forward-control integrity
61+
channel-timeout connection-timeout
62+
- git_ref: 'V_9_9_P2'
63+
osp_ver: '9.9p2'
64+
SKIP_LTESTS: >-
65+
exit-status rekey multiplex cert-userkey forward-control integrity
66+
channel-timeout connection-timeout
67+
- git_ref: 'V_10_0_P2'
68+
osp_ver: '10.0p2'
69+
SKIP_LTESTS: >-
70+
exit-status rekey multiplex forward-control channel-timeout
71+
connection-timeout
72+
name: ${{ matrix.osp_ver }}
5173
if: github.repository_owner == 'wolfssl'
5274
runs-on: ubuntu-22.04
5375
needs: build_wolfssl
@@ -80,5 +102,4 @@ jobs:
80102
- name: Run tests
81103
working-directory: ./openssh
82104
run: |
83-
# Run all the tests except (t-exec) as it takes too long
84-
make file-tests interop-tests extra-tests unit
105+
make tests SKIP_LTESTS='${{ matrix.SKIP_LTESTS }}'

configure.ac

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ AC_CHECK_HEADER(assert.h, [AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFSSL_HAVE_ASSERT_H"],[
129129
# check if functions of interest are linkable, but also check if
130130
# they're declared by the expected headers, and if not, supersede the
131131
# unusable positive from AC_CHECK_FUNCS().
132-
AC_CHECK_FUNCS([gethostbyname getaddrinfo gettimeofday gmtime_r gmtime_s inet_ntoa memset socket strftime atexit isascii getpid])
132+
AC_CHECK_FUNCS([gethostbyname getaddrinfo gettimeofday gmtime_r gmtime_s inet_ntoa memset socket strftime atexit isascii getpid getrandom])
133133
AC_CHECK_DECLS([gethostbyname, getaddrinfo, gettimeofday, gmtime_r, gmtime_s, inet_ntoa, memset, socket, strftime, atexit, isascii, getpid], [], [
134134
if test "$(eval echo \$"$(eval 'echo ac_cv_func_${as_decl_name}')")" = "yes"
135135
then
@@ -2138,6 +2138,12 @@ AC_ARG_ENABLE([openssh],
21382138
[ENABLED_OPENSSH=$enableval],
21392139
[ENABLED_OPENSSH=no])
21402140

2141+
if test "$ENABLED_OPENSSH" = "yes"
2142+
then
2143+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_OPENSSH -DHAVE_EX_DATA -DWOLFSSL_BASE16"
2144+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_ERROR_CODE_OPENSSL -DWC_RNG_SEED_CB"
2145+
fi
2146+
21412147
# OpenVPN compatibility Build
21422148
AC_ARG_ENABLE([openvpn],
21432149
[AS_HELP_STRING([--enable-openvpn],[Enable OpenVPN compatibility build (default: disabled)])],
@@ -2249,6 +2255,11 @@ AC_ARG_ENABLE([fortress],
22492255
[ ENABLED_FORTRESS=no ]
22502256
)
22512257

2258+
if test "$ENABLED_OPENSSH" = "yes"
2259+
then
2260+
ENABLED_FORTRESS="yes"
2261+
fi
2262+
22522263
# libwebsockets Support
22532264
AC_ARG_ENABLE([libwebsockets],
22542265
[AS_HELP_STRING([--enable-libwebsockets],[Enable libwebsockets (default: disabled)])],
@@ -2260,14 +2271,6 @@ then
22602271
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_LIBWEBSOCKETS -DHAVE_EX_DATA -DOPENSSL_NO_EC"
22612272
fi
22622273

2263-
2264-
if test "$ENABLED_OPENSSH" = "yes"
2265-
then
2266-
ENABLED_FORTRESS="yes"
2267-
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_OPENSSH -DHAVE_EX_DATA -DWOLFSSL_BASE16"
2268-
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_ERROR_CODE_OPENSSL"
2269-
fi
2270-
22712274
# net-snmp Build
22722275
AC_ARG_ENABLE([net-snmp],
22732276
[AS_HELP_STRING([--enable-net-snmp],[Enable net-snmp (default: disabled)])],

src/ssl.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,19 @@ WC_RNG* wolfssl_make_rng(WC_RNG* rng, int* local);
297297
WC_RNG* wolfssl_make_rng(WC_RNG* rng, int* local)
298298
{
299299
WC_RNG* ret = NULL;
300+
#ifdef WOLFSSL_SMALL_STACK
301+
int freeRng = 0;
302+
#endif
300303

301304
/* Assume not local until one created. */
302305
*local = 0;
303306

304307
#ifdef WOLFSSL_SMALL_STACK
305308
/* Allocate RNG object . */
306-
rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), NULL, DYNAMIC_TYPE_RNG);
309+
if (rng == NULL) {
310+
rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), NULL, DYNAMIC_TYPE_RNG);
311+
freeRng = 1;
312+
}
307313
#endif
308314
/* Check we have a local RNG object and initialize. */
309315
if ((rng != NULL) && (wc_InitRng(rng) == 0)) {
@@ -317,11 +323,10 @@ WC_RNG* wolfssl_make_rng(WC_RNG* rng, int* local)
317323
ret = wolfssl_make_global_rng();
318324
}
319325

320-
if (ret != rng) {
321326
#ifdef WOLFSSL_SMALL_STACK
327+
if (freeRng)
322328
XFREE(rng, NULL, DYNAMIC_TYPE_RNG);
323329
#endif
324-
}
325330

326331
return ret;
327332
}

wolfcrypt/src/random.c

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,13 @@ This library contains implementation for the random number generator.
147147
#elif defined(WOLFSSL_IMXRT1170_CAAM)
148148
#elif defined(CY_USING_HAL) && defined(COMPONENT_WOLFSSL)
149149
#include "cyhal_trng.h" /* Infineon/Cypress HAL RNG implementation */
150-
#elif defined(WOLFSSL_GETRANDOM)
151-
#include <errno.h>
152-
#include <sys/random.h>
153150
#elif defined(WOLFSSL_MAX3266X) || defined(WOLFSSL_MAX3266X_OLD)
154151
#include "wolfssl/wolfcrypt/port/maxim/max3266x.h"
155152
#else
153+
#if defined(WOLFSSL_GETRANDOM) || defined(HAVE_GETRANDOM)
154+
#include <errno.h>
155+
#include <sys/random.h>
156+
#endif
156157
/* include headers that may be needed to get good seed */
157158
#include <fcntl.h>
158159
#ifndef EBSNET
@@ -3971,37 +3972,6 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
39713972
return wc_MXC_TRNG_Random(output, sz);
39723973
}
39733974

3974-
#elif defined(WOLFSSL_GETRANDOM)
3975-
3976-
/* getrandom() was added to the Linux kernel in version 3.17.
3977-
* Added to glibc in version 2.25. */
3978-
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
3979-
{
3980-
int ret = 0;
3981-
(void)os;
3982-
3983-
while (sz) {
3984-
int len;
3985-
3986-
errno = 0;
3987-
len = (int)getrandom(output, sz, 0);
3988-
if (len == -1) {
3989-
if (errno == EINTR) {
3990-
/* interrupted, call getrandom again */
3991-
continue;
3992-
}
3993-
else {
3994-
ret = READ_RAN_E;
3995-
}
3996-
break;
3997-
}
3998-
3999-
sz -= len;
4000-
output += len;
4001-
}
4002-
return ret;
4003-
}
4004-
40053975
#elif defined(CY_USING_HAL) && defined(COMPONENT_WOLFSSL)
40063976

40073977
/* Infineon/Cypress HAL RNG implementation */
@@ -4137,6 +4107,43 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
41374107
}
41384108
#endif /* HAVE_INTEL_RDSEED || HAVE_AMD_RDSEED */
41394109

4110+
#if defined(WOLFSSL_GETRANDOM) || defined(HAVE_GETRANDOM)
4111+
{
4112+
word32 grSz = sz;
4113+
byte* grOutput = output;
4114+
4115+
while (grSz) {
4116+
int len;
4117+
4118+
errno = 0;
4119+
len = (int)getrandom(grOutput, grSz, 0);
4120+
if (len == -1) {
4121+
if (errno == EINTR) {
4122+
/* interrupted, call getrandom again */
4123+
continue;
4124+
}
4125+
else {
4126+
ret = READ_RAN_E;
4127+
}
4128+
break;
4129+
}
4130+
4131+
grSz -= len;
4132+
grOutput += len;
4133+
}
4134+
if (ret == 0)
4135+
return ret;
4136+
#ifdef FORCE_FAILURE_GETRANDOM
4137+
/* don't fallback to /dev/urandom */
4138+
return ret;
4139+
#else
4140+
/* reset error and fallback to using /dev/urandom */
4141+
ret = 0;
4142+
#endif
4143+
}
4144+
#endif
4145+
4146+
#ifndef NO_FILESYSTEM
41404147
#ifndef NO_DEV_URANDOM /* way to disable use of /dev/urandom */
41414148
os->fd = open("/dev/urandom", O_RDONLY);
41424149
#if defined(DEBUG_WOLFSSL)
@@ -4176,6 +4183,9 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
41764183
}
41774184
}
41784185
close(os->fd);
4186+
#else
4187+
ret = NOT_COMPILED_IN;
4188+
#endif /* NO_FILESYSTEM */
41794189

41804190
return ret;
41814191
}

0 commit comments

Comments
 (0)