Skip to content

Commit 5e6c1ba

Browse files
authored
Merge pull request #8879 from julek-wolfssl/openssh-10.0p2
Updates for OpenSSH 10.0p2
2 parents 3e5e470 + 9a576d9 commit 5e6c1ba

8 files changed

Lines changed: 109 additions & 66 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 }}'

.wolfssl_known_macro_extras

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ ESP_PLATFORM
205205
ESP_TASK_MAIN_STACK
206206
ETHERNET_AVAILABLE
207207
EV_TRIGGER
208+
FORCE_FAILURE_GETRANDOM
208209
FP_ECC_CONTROL
209210
FREERTOS_TCP_WINSIM
210211
FREESCALE

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)])],

examples/configs/user_settings_tls12.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ extern "C" {
4444
#define WOLFSSL_USER_IO
4545
#define WOLFSSL_IGNORE_FILE_WARN /* ignore file includes not required */
4646
//#define WOLFSSL_SMALL_STACK /* option to reduce stack size, offload to heap */
47-
#define NO_FILESYSTEM
4847
#define NO_WRITEV
4948
#define NO_SIG_WRAPPER
5049

examples/configs/user_settings_wolfboot_keytools.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
#define NO_DES3
9292
#define NO_PWDBASED
9393
#define NO_WRITEV
94-
#define NO_FILESYSTEM
9594
#define NO_OLD_RNGNAME
9695
#define NO_WOLFSSL_DIR
9796
#define WOLFSSL_NO_SOCK

src/ssl.c

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -297,30 +297,36 @@ 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;
300302

301-
/* Assume not local until one created. */
302-
*local = 0;
303+
/* Allocate RNG object . */
304+
if (rng == NULL) {
305+
rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), NULL, DYNAMIC_TYPE_RNG);
306+
freeRng = 1;
307+
}
308+
#endif
303309

310+
if (rng != NULL) {
311+
if (wc_InitRng(rng) == 0) {
312+
ret = rng;
313+
*local = 1;
314+
}
315+
else {
316+
WOLFSSL_MSG("Bad RNG Init");
304317
#ifdef WOLFSSL_SMALL_STACK
305-
/* Allocate RNG object . */
306-
rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), NULL, DYNAMIC_TYPE_RNG);
318+
if (freeRng) {
319+
XFREE(rng, NULL, DYNAMIC_TYPE_RNG);
320+
rng = NULL;
321+
}
307322
#endif
308-
/* Check we have a local RNG object and initialize. */
309-
if ((rng != NULL) && (wc_InitRng(rng) == 0)) {
310-
ret = rng;
311-
*local = 1;
323+
}
312324
}
313325
if (ret == NULL) {
314-
#ifdef HAVE_GLOBAL_RNG
315-
WOLFSSL_MSG("Bad RNG Init, trying global");
316-
#endif
317-
ret = wolfssl_make_global_rng();
318-
}
319-
320-
if (ret != rng) {
321-
#ifdef WOLFSSL_SMALL_STACK
322-
XFREE(rng, NULL, DYNAMIC_TYPE_RNG);
326+
#ifdef HAVE_GLOBAL_RNG
327+
WOLFSSL_MSG("trying global RNG");
323328
#endif
329+
ret = wolfssl_make_global_rng();
324330
}
325331

326332
return ret;

wolfcrypt/src/random.c

Lines changed: 48 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
@@ -306,7 +307,11 @@ This library contains implementation for the random number generator.
306307

307308
#ifdef WC_RNG_SEED_CB
308309

310+
#ifndef HAVE_FIPS
311+
static wc_RngSeed_Cb seedCb = wc_GenerateSeed;
312+
#else
309313
static wc_RngSeed_Cb seedCb = NULL;
314+
#endif
310315

311316
int wc_SetSeed_Cb(wc_RngSeed_Cb cb)
312317
{
@@ -3971,37 +3976,6 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
39713976
return wc_MXC_TRNG_Random(output, sz);
39723977
}
39733978

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-
40053979
#elif defined(CY_USING_HAL) && defined(COMPONENT_WOLFSSL)
40063980

40073981
/* Infineon/Cypress HAL RNG implementation */
@@ -4137,6 +4111,43 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
41374111
}
41384112
#endif /* HAVE_INTEL_RDSEED || HAVE_AMD_RDSEED */
41394113

4114+
#if defined(WOLFSSL_GETRANDOM) || defined(HAVE_GETRANDOM)
4115+
{
4116+
word32 grSz = sz;
4117+
byte* grOutput = output;
4118+
4119+
while (grSz) {
4120+
ssize_t len;
4121+
4122+
errno = 0;
4123+
len = getrandom(grOutput, grSz, 0);
4124+
if (len == -1) {
4125+
if (errno == EINTR) {
4126+
/* interrupted, call getrandom again */
4127+
continue;
4128+
}
4129+
else {
4130+
ret = READ_RAN_E;
4131+
}
4132+
break;
4133+
}
4134+
4135+
grSz -= (word32)len;
4136+
grOutput += len;
4137+
}
4138+
if (ret == 0)
4139+
return ret;
4140+
#ifdef FORCE_FAILURE_GETRANDOM
4141+
/* don't fallback to /dev/urandom */
4142+
return ret;
4143+
#else
4144+
/* reset error and fallback to using /dev/urandom */
4145+
ret = 0;
4146+
#endif
4147+
}
4148+
#endif
4149+
4150+
#ifndef NO_FILESYSTEM
41404151
#ifndef NO_DEV_URANDOM /* way to disable use of /dev/urandom */
41414152
os->fd = open("/dev/urandom", O_RDONLY);
41424153
#if defined(DEBUG_WOLFSSL)
@@ -4176,6 +4187,9 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
41764187
}
41774188
}
41784189
close(os->fd);
4190+
#else
4191+
ret = NOT_COMPILED_IN;
4192+
#endif /* NO_FILESYSTEM */
41794193

41804194
return ret;
41814195
}

wolfcrypt/test/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2774,7 +2774,7 @@ static wc_test_ret_t _SaveDerAndPem(const byte* der, int derSz,
27742774
}
27752775
#endif
27762776

2777-
#ifdef WOLFSSL_DER_TO_PEM
2777+
#if defined(WOLFSSL_DER_TO_PEM) && !defined(NO_CERTS)
27782778
if (filePem) {
27792779
#if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
27802780
XFILE pemFile;

0 commit comments

Comments
 (0)