Skip to content

Commit 851f059

Browse files
authored
Merge pull request #7203 from julek-wolfssl/openssh-9.6
openssh 9.6p1 fixes
2 parents 4ed197d + be90fe0 commit 851f059

9 files changed

Lines changed: 125 additions & 14 deletions

File tree

.github/workflows/openssh.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: openssh Tests
2+
3+
on:
4+
workflow_call:
5+
# TODO: remove this from PR
6+
push:
7+
8+
jobs:
9+
build_wolfssl:
10+
name: Build wolfSSL
11+
# Just to keep it the same as the testing target
12+
runs-on: ubuntu-latest
13+
# This should be a safe limit for the tests to run.
14+
timeout-minutes: 4
15+
steps:
16+
- name: Build wolfSSL
17+
uses: wolfSSL/actions-build-autotools-project@v1
18+
with:
19+
path: wolfssl
20+
configure: >-
21+
--enable-openssh --enable-dsa --with-max-rsa-bits=8192
22+
--enable-intelasm --enable-sp-asm
23+
install: true
24+
25+
- name: Upload built lib
26+
uses: actions/upload-artifact@v4
27+
with:
28+
name: wolf-install-openssh
29+
path: build-dir
30+
retention-days: 1
31+
32+
openssh_check:
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
include:
37+
- git_ref: 'V_9_6_P1'
38+
osp_ver: '9.6'
39+
name: ${{ matrix.ref }}
40+
runs-on: ubuntu-latest
41+
needs: build_wolfssl
42+
steps:
43+
- name: Download lib
44+
uses: actions/download-artifact@v4
45+
with:
46+
name: wolf-install-openssh
47+
path: build-dir
48+
49+
- name: Checkout OSP
50+
uses: actions/checkout@v4
51+
with:
52+
# TODO: update with wolfssl repo after merge
53+
repository: julek-wolfssl/osp
54+
ref: openssh-9.6
55+
path: osp
56+
57+
- name: Build and test openssh
58+
uses: wolfSSL/actions-build-autotools-project@v1
59+
with:
60+
repository: openssh/openssh-portable
61+
ref: ${{ matrix.git_ref }}
62+
path: openssh
63+
patch-file: $GITHUB_WORKSPACE/osp/openssh-patches/openssh-${{ matrix.osp_ver }}.patch
64+
configure: --with-wolfssl=$GITHUB_WORKSPACE/build-dir --with-rpath=-Wl,-rpath=
65+
check: false
66+
67+
# make tests take >20 minutes. Consider limiting?
68+
- name: Run tests
69+
working-directory: ./openssh
70+
run: |
71+
# Run all the tests except (t-exec) as it takes too long
72+
make file-tests interop-tests extra-tests unit

src/pk.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5033,15 +5033,19 @@ int wolfSSL_DSA_set0_key(WOLFSSL_DSA *d, WOLFSSL_BIGNUM *pub_key,
50335033
WOLFSSL_ENTER("wolfSSL_DSA_set0_key");
50345034

50355035
/* The private key may be NULL */
5036-
if (pub_key == NULL) {
5036+
if (d->pub_key == NULL && pub_key == NULL) {
50375037
WOLFSSL_MSG("Bad parameter");
50385038
return 0;
50395039
}
50405040

5041-
wolfSSL_BN_free(d->pub_key);
5042-
wolfSSL_BN_free(d->priv_key);
5043-
d->pub_key = pub_key;
5044-
d->priv_key = priv_key;
5041+
if (pub_key != NULL) {
5042+
wolfSSL_BN_free(d->pub_key);
5043+
d->pub_key = pub_key;
5044+
}
5045+
if (priv_key != NULL) {
5046+
wolfSSL_BN_free(d->priv_key);
5047+
d->priv_key = priv_key;
5048+
}
50455049

50465050
return 1;
50475051
}

wolfcrypt/src/integer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5358,6 +5358,9 @@ int mp_read_radix (mp_int * a, const char *str, int radix)
53585358
++str;
53595359
}
53605360

5361+
/* Skip whitespace at end of str */
5362+
while (CharIsWhiteSpace(*str))
5363+
++str;
53615364
/* if digit in isn't null term, then invalid character was found */
53625365
if (*str != '\0') {
53635366
mp_zero (a);

wolfcrypt/src/misc.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,18 @@ WC_MISC_STATIC WC_INLINE int ByteToHexStr(byte in, char* out)
545545
return 0;
546546
}
547547

548+
WC_MISC_STATIC WC_INLINE int CharIsWhiteSpace(char ch)
549+
{
550+
switch (ch) {
551+
case ' ':
552+
case '\t':
553+
case '\n':
554+
return 1;
555+
default:
556+
return 0;
557+
}
558+
}
559+
548560
#ifndef WOLFSSL_NO_CT_OPS
549561
/* Constant time - mask set when a > b. */
550562
WC_MISC_STATIC WC_INLINE byte ctMaskGT(int a, int b)

wolfcrypt/src/sp_int.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18068,6 +18068,8 @@ static int _sp_read_radix_16(sp_int* a, const char* in)
1806818068
unsigned int s = 0;
1806918069
unsigned int j = 0;
1807018070
sp_int_digit d;
18071+
/* Skip whitespace at end of line */
18072+
int eol_done = 0;
1807118073

1807218074
/* Make all nibbles in digit 0. */
1807318075
d = 0;
@@ -18078,9 +18080,12 @@ static int _sp_read_radix_16(sp_int* a, const char* in)
1807818080
int ch = (int)HexCharToByte(in[i]);
1807918081
/* Check for invalid character. */
1808018082
if (ch < 0) {
18083+
if (!eol_done && CharIsWhiteSpace(in[i]))
18084+
continue;
1808118085
err = MP_VAL;
1808218086
break;
1808318087
}
18088+
eol_done = 1;
1808418089

1808518090
/* Check whether we have filled the digit. */
1808618091
if (s == SP_WORD_SIZE) {
@@ -18150,6 +18155,8 @@ static int _sp_read_radix_10(sp_int* a, const char* in)
1815018155
ch -= '0';
1815118156
}
1815218157
else {
18158+
if (CharIsWhiteSpace(ch))
18159+
continue;
1815318160
/* Return error on invalid character. */
1815418161
err = MP_VAL;
1815518162
break;

wolfcrypt/src/tfm.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5945,6 +5945,8 @@ static int fp_read_radix_16(fp_int *a, const char *str)
59455945
{
59465946
int i, j, k, neg;
59475947
int ch;
5948+
/* Skip whitespace at end of line */
5949+
int eol_done = 0;
59485950

59495951
/* if the leading digit is a
59505952
* minus set the sign to negative.
@@ -5961,8 +5963,11 @@ static int fp_read_radix_16(fp_int *a, const char *str)
59615963
for (i = (int)(XSTRLEN(str) - 1); i >= 0; i--) {
59625964
ch = (int)HexCharToByte(str[i]);
59635965
if (ch < 0) {
5966+
if (!eol_done && CharIsWhiteSpace(str[i]))
5967+
continue;
59645968
return FP_VAL;
59655969
}
5970+
eol_done = 1;
59665971

59675972
k += j == DIGIT_BIT;
59685973
j &= DIGIT_BIT - 1;
@@ -6024,7 +6029,13 @@ static int fp_read_radix(fp_int *a, const char *str, int radix)
60246029
}
60256030
}
60266031
if (y >= radix) {
6027-
return FP_VAL;
6032+
/* Check if whitespace at end of line */
6033+
while (CharIsWhiteSpace(*str))
6034+
++str;
6035+
if (*str)
6036+
return FP_VAL;
6037+
else
6038+
break;
60286039
}
60296040

60306041
/* if the char was found in the map

wolfcrypt/test/test.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44779,7 +44779,7 @@ static wc_test_ret_t mp_test_radix_10(mp_int* a, mp_int* r, WC_RNG* rng)
4477944779
char str[30];
4478044780
WOLFSSL_SMALL_STACK_STATIC const char* badStr1 = "A";
4478144781
WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "a";
44782-
WOLFSSL_SMALL_STACK_STATIC const char* badStr3 = " ";
44782+
WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
4478344783
WOLFSSL_SMALL_STACK_STATIC const char* zeros = "000";
4478444784
WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
4478544785

@@ -44811,8 +44811,8 @@ static wc_test_ret_t mp_test_radix_10(mp_int* a, mp_int* r, WC_RNG* rng)
4481144811
ret = mp_read_radix(r, badStr2, MP_RADIX_DEC);
4481244812
if (ret != MP_VAL)
4481344813
return WC_TEST_RET_ENC_EC(ret);
44814-
ret = mp_read_radix(r, badStr3, MP_RADIX_DEC);
44815-
if (ret != MP_VAL)
44814+
ret = mp_read_radix(r, empty2, MP_RADIX_DEC);
44815+
if (ret != MP_OKAY)
4481644816
return WC_TEST_RET_ENC_EC(ret);
4481744817

4481844818
ret = mp_read_radix(r, zeros, MP_RADIX_DEC);
@@ -44859,7 +44859,7 @@ static wc_test_ret_t mp_test_radix_16(mp_int* a, mp_int* r, WC_RNG* rng)
4485944859
#if defined(WOLFSSL_SP_MATH) || defined(USE_FAST_MATH)
4486044860
static char longStr[2 * sizeof(a->dp) + 2];
4486144861
#endif
44862-
WOLFSSL_SMALL_STACK_STATIC const char* badStr1 = " ";
44862+
WOLFSSL_SMALL_STACK_STATIC const char* empty2 = " ";
4486344863
WOLFSSL_SMALL_STACK_STATIC const char* badStr2 = "}";
4486444864
WOLFSSL_SMALL_STACK_STATIC const char* empty = "";
4486544865

@@ -44879,8 +44879,8 @@ static wc_test_ret_t mp_test_radix_16(mp_int* a, mp_int* r, WC_RNG* rng)
4487944879
}
4488044880
}
4488144881

44882-
ret = mp_read_radix(r, badStr1, MP_RADIX_HEX);
44883-
if (ret != MP_VAL)
44882+
ret = mp_read_radix(r, empty2, MP_RADIX_HEX);
44883+
if (ret != MP_OKAY)
4488444884
return WC_TEST_RET_ENC_EC(ret);
4488544885
ret = mp_read_radix(r, badStr2, MP_RADIX_HEX);
4488644886
if (ret != MP_VAL)

wolfssl/openssl/opensslv.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
/* valid version */
3737
#elif defined(WOLFSSL_APACHE_HTTPD) || defined(HAVE_LIBEST) || \
3838
defined(WOLFSSL_BIND) || defined(WOLFSSL_NGINX) || \
39-
defined(WOLFSSL_RSYSLOG) || defined(WOLFSSL_KRB) || defined(HAVE_STUNNEL)
39+
defined(WOLFSSL_RSYSLOG) || defined(WOLFSSL_KRB) || defined(HAVE_STUNNEL) || \
40+
defined(WOLFSSL_OPENSSH)
4041
/* For Apache httpd, Use 1.1.0 compatibility */
4142
#define OPENSSL_VERSION_NUMBER 0x10100003L
4243
#elif defined(WOLFSSL_QT) || defined(WOLFSSL_PYTHON) || defined(WOLFSSL_KRB)
@@ -45,7 +46,7 @@
4546
#elif defined(WOLFSSL_HAPROXY) || defined(WOLFSSL_FFMPEG)
4647
#define OPENSSL_VERSION_NUMBER 0x1010000fL
4748
#elif defined(OPENSSL_ALL) || defined(HAVE_LIGHTY) || \
48-
defined(WOLFSSL_NGINX) || defined(WOLFSSL_OPENSSH) || defined(WOLFSSL_OPENVPN)
49+
defined(WOLFSSL_NGINX) || defined(WOLFSSL_OPENVPN)
4950
/* version number can be increased for Lighty after compatibility for ECDH
5051
is added */
5152
#define OPENSSL_VERSION_NUMBER 0x10001040L

wolfssl/wolfcrypt/misc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ word32 btoi(byte b);
114114
WOLFSSL_LOCAL signed char HexCharToByte(char ch);
115115
WOLFSSL_LOCAL char ByteToHex(byte in);
116116
WOLFSSL_LOCAL int ByteToHexStr(byte in, char* out);
117+
WOLFSSL_LOCAL int CharIsWhiteSpace(char ch);
117118

118119
WOLFSSL_LOCAL byte ctMaskGT(int a, int b);
119120
WOLFSSL_LOCAL byte ctMaskGTE(int a, int b);

0 commit comments

Comments
 (0)