Skip to content

Commit 00508d2

Browse files
authored
Fix compilation errors in test code for certain versions of openssl (#265)
* Fix compilation errors in test code for certain versions of openssl * Add kdf gettable ctx params, test fixes for older versions of openssl * Update test version guards, no longer needed
1 parent 93430f0 commit 00508d2

File tree

5 files changed

+187
-24
lines changed

5 files changed

+187
-24
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: OpenSSL Version Tests
2+
3+
# START OF COMMON SECTION
4+
on:
5+
push:
6+
branches: [ 'master', 'main', 'release/**' ]
7+
pull_request:
8+
branches: [ '*' ]
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
# END OF COMMON SECTION
14+
15+
jobs:
16+
openssl_version_test:
17+
name: OpenSSL Version Test
18+
runs-on: ubuntu-22.04
19+
timeout-minutes: 30
20+
strategy:
21+
matrix:
22+
wolfssl_ref: ['v5.8.2-stable']
23+
openssl_ref: [
24+
'openssl-3.0.3',
25+
'openssl-3.0.4',
26+
'openssl-3.0.5',
27+
'openssl-3.0.6',
28+
'openssl-3.0.7',
29+
'openssl-3.0.8',
30+
'openssl-3.0.9',
31+
'openssl-3.0.10',
32+
'openssl-3.0.11',
33+
'openssl-3.0.12',
34+
'openssl-3.0.13',
35+
'openssl-3.0.14',
36+
'openssl-3.0.15',
37+
'openssl-3.0.16',
38+
'openssl-3.0.17',
39+
'openssl-3.1.0',
40+
'openssl-3.1.1',
41+
'openssl-3.1.2',
42+
'openssl-3.1.3',
43+
'openssl-3.1.4',
44+
'openssl-3.1.5',
45+
'openssl-3.1.6',
46+
'openssl-3.1.7',
47+
'openssl-3.1.8',
48+
'openssl-3.2.0',
49+
'openssl-3.2.1',
50+
'openssl-3.2.2',
51+
'openssl-3.2.3',
52+
'openssl-3.2.4',
53+
'openssl-3.2.5',
54+
'openssl-3.3.0',
55+
'openssl-3.3.1',
56+
'openssl-3.3.2',
57+
'openssl-3.3.3',
58+
'openssl-3.3.4',
59+
'openssl-3.4.0',
60+
'openssl-3.4.1',
61+
'openssl-3.4.2',
62+
'openssl-3.5.0',
63+
'openssl-3.5.1']
64+
steps:
65+
- name: Checkout wolfProvider
66+
uses: actions/checkout@v4
67+
with:
68+
fetch-depth: 1
69+
70+
- name: Build and test wolfProvider
71+
run: |
72+
OPENSSL_TAG=${{ matrix.openssl_ref }} \
73+
WOLFSSL_TAG=${{ matrix.wolfssl_ref }} \
74+
./scripts/build-wolfprovider.sh
75+
76+
- name: Print errors
77+
if: ${{ failure() }}
78+
run: |
79+
if [ -f test-suite.log ] ; then
80+
cat test-suite.log
81+
fi

src/wp_kdf_exch.c

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,54 @@ static int wp_kdf_set_ctx_params(wp_KdfCtx* ctx, const OSSL_PARAM params[])
222222
return EVP_KDF_CTX_set_params(ctx->kdfCtx, params);
223223
}
224224

225+
/**
226+
* Get the KDF key exchange parameters.
227+
*
228+
* @param [in] ctx KDF key exchange context object.
229+
* @param [in, out] params Array of parameters.
230+
* @return 1 on success.
231+
* @return 0 on failure.
232+
*/
233+
static int wp_kdf_get_ctx_params(wp_KdfCtx* ctx, OSSL_PARAM params[])
234+
{
235+
int ok = 1;
236+
237+
WOLFPROV_ENTER(WP_LOG_KDF, "wp_kdf_get_ctx_params");
238+
239+
if (!wolfssl_prov_is_running()) {
240+
ok = 0;
241+
}
242+
if (ok && !EVP_KDF_CTX_get_params(ctx->kdfCtx, params)) {
243+
ok = 0;
244+
}
245+
246+
WOLFPROV_LEAVE(WP_LOG_KDF, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
247+
return ok;
248+
}
249+
250+
/**
251+
* Get the list of gettable parameters for a KDF context.
252+
*
253+
* @param [in] ctx KDF key exchange context object. Unused.
254+
* @param [in] provCtx Provider context object.
255+
* @param [in] kdfName Name of the KDF.
256+
* @return Array of parameters with data type.
257+
*/
258+
static const OSSL_PARAM* wp_kdf_gettable_ctx_params(wp_KdfCtx* ctx,
259+
WOLFPROV_CTX* provCtx, const char* kdfName)
260+
{
261+
const OSSL_PARAM* params = NULL;
262+
263+
(void)provCtx;
264+
(void)kdfName;
265+
266+
if (wolfssl_prov_is_running() && ctx != NULL && ctx->kdfCtx != NULL) {
267+
params = EVP_KDF_CTX_gettable_params(ctx->kdfCtx);
268+
}
269+
270+
return params;
271+
}
272+
225273
/**
226274
* Return an array of supported settable parameters for the HKDF ke context.
227275
*
@@ -269,6 +317,32 @@ static const OSSL_PARAM* wp_tls1_prf_settable_ctx_params(wp_KdfCtx* ctx,
269317
return settable_ctx_params;
270318
}
271319

320+
/**
321+
* Return an array of supported gettable parameters for the HKDF ke context.
322+
*
323+
* @param [in] ctx KDF key exchange context object. Unused.
324+
* @param [in] provCtx Provider context object.
325+
* @return Array of parameters with data type.
326+
*/
327+
static const OSSL_PARAM* wp_hkdf_gettable_ctx_params(wp_KdfCtx* ctx,
328+
WOLFPROV_CTX* provCtx)
329+
{
330+
return wp_kdf_gettable_ctx_params(ctx, provCtx, "HKDF");
331+
}
332+
333+
/**
334+
* Return an array of supported gettable parameters for the TLS1-PRF ke context.
335+
*
336+
* @param [in] ctx KDF key exchange context object. Unused.
337+
* @param [in] provCtx Provider context object.
338+
* @return Array of parameters with data type.
339+
*/
340+
static const OSSL_PARAM* wp_tls1_prf_gettable_ctx_params(wp_KdfCtx* ctx,
341+
WOLFPROV_CTX* provCtx)
342+
{
343+
return wp_kdf_gettable_ctx_params(ctx, provCtx, "TLS1-PRF");
344+
}
345+
272346
/*
273347
* HKDF
274348
*/
@@ -293,8 +367,11 @@ const OSSL_DISPATCH wp_hkdf_keyexch_functions[] = {
293367
{ OSSL_FUNC_KEYEXCH_INIT, (DFUNC)wp_kdf_init },
294368
{ OSSL_FUNC_KEYEXCH_DERIVE, (DFUNC)wp_kdf_derive },
295369
{ OSSL_FUNC_KEYEXCH_SET_CTX_PARAMS, (DFUNC)wp_kdf_set_ctx_params },
370+
{ OSSL_FUNC_KEYEXCH_GET_CTX_PARAMS, (DFUNC)wp_kdf_get_ctx_params },
296371
{ OSSL_FUNC_KEYEXCH_SETTABLE_CTX_PARAMS,
297372
(DFUNC)wp_hkdf_settable_ctx_params },
373+
{ OSSL_FUNC_KEYEXCH_GETTABLE_CTX_PARAMS,
374+
(DFUNC)wp_hkdf_gettable_ctx_params },
298375
{ 0, NULL }
299376
};
300377

@@ -322,8 +399,11 @@ const OSSL_DISPATCH wp_tls1_prf_keyexch_functions[] = {
322399
{ OSSL_FUNC_KEYEXCH_INIT, (DFUNC)wp_kdf_init },
323400
{ OSSL_FUNC_KEYEXCH_DERIVE, (DFUNC)wp_kdf_derive },
324401
{ OSSL_FUNC_KEYEXCH_SET_CTX_PARAMS, (DFUNC)wp_kdf_set_ctx_params },
402+
{ OSSL_FUNC_KEYEXCH_GET_CTX_PARAMS, (DFUNC)wp_kdf_get_ctx_params },
325403
{ OSSL_FUNC_KEYEXCH_SETTABLE_CTX_PARAMS,
326404
(DFUNC)wp_tls1_prf_settable_ctx_params },
405+
{ OSSL_FUNC_KEYEXCH_GETTABLE_CTX_PARAMS,
406+
(DFUNC)wp_tls1_prf_gettable_ctx_params },
327407
{ 0, NULL }
328408
};
329409

test/test_ecc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,8 +1670,10 @@ static int test_ec_pubkey_match_ex(EVP_PKEY *pkey1, EVP_PKEY *pkey2,
16701670

16711671
static int test_ec_pubkey_match(EVP_PKEY *pkey1, EVP_PKEY *pkey2) {
16721672
int err = 0;
1673-
1673+
/* Older versions of OpenSSL use a different format for raw pub key */
1674+
#if OPENSSL_VERSION_NUMBER >= 0x30008000L
16741675
err = test_ec_pubkey_match_ex(pkey1, pkey2, OSSL_PKEY_PARAM_PUB_KEY);
1676+
#endif
16751677
if (err == 0) {
16761678
err = test_ec_pubkey_match_ex(pkey1, pkey2,
16771679
OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY);
@@ -1902,6 +1904,8 @@ static int test_ec_import_priv(void)
19021904
err = 1;
19031905
}
19041906
}
1907+
/* Older versions of OpenSSL will segfault on this */
1908+
#if OPENSSL_VERSION_NUMBER >= 0x30006000L
19051909
if (err == 0) {
19061910
if (EVP_PKEY_get_octet_string_param(pkey1,
19071911
OSSL_PKEY_PARAM_ENCODED_PUBLIC_KEY, NULL, 0, (size_t *)&len) != 0) {
@@ -1914,6 +1918,7 @@ static int test_ec_import_priv(void)
19141918
err = 1;
19151919
}
19161920
}
1921+
#endif
19171922

19181923
EVP_PKEY_free(pkey1);
19191924
EVP_PKEY_free(pkey2);

test/test_hkdf.c

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ static int test_hkdf_calc(OSSL_LIB_CTX* libCtx, unsigned char *key, int keyLen,
9191
return err;
9292
}
9393

94-
#if OPENSSL_VERSION_NUMBER <= 0x30400000L
95-
9694
static int test_hkdf_double_set_salt(OSSL_LIB_CTX* libCtx, unsigned char *key,
97-
int keyLen, const EVP_MD *md, int mode)
95+
int keyLen, const EVP_MD *md, int mode, int isOssl)
9896
{
9997
int err = 0;
98+
int ret = 0;
99+
static int osslRet = 0;
100100
EVP_PKEY_CTX *ctx = NULL;
101101
unsigned char inKey[32] = { 0, };
102102
unsigned char salt[32] = { 0, };
@@ -137,18 +137,17 @@ static int test_hkdf_double_set_salt(OSSL_LIB_CTX* libCtx, unsigned char *key,
137137
}
138138
}
139139
if ((err == 0) && (mode != EVP_PKEY_HKDEF_MODE_EXPAND_ONLY)) {
140-
#if OPENSSL_VERSION_NUMBER >= 0x30100000L && \
141-
OPENSSL_VERSION_NUMBER != 0x30200050L && \
142-
OPENSSL_VERSION_NUMBER != 0x30300040L
143-
if (EVP_PKEY_CTX_set1_hkdf_salt(ctx, NULL, 0) != 1) {
144-
#else
145-
/* In 3.1.x, the following code was added to hkdf_common_set_ctx_params()
146-
* if (p->data_size != 0 && p->data != NULL) {
147-
* The above code is not present in 3.2.5 and 3.3.4. */
148-
if (EVP_PKEY_CTX_set1_hkdf_salt(ctx, NULL, 0) != 0) {
149-
#endif
150-
PRINT_MSG("Failed to set HKDF salt to NULL");
151-
err = 1;
140+
ret = EVP_PKEY_CTX_set1_hkdf_salt(ctx, NULL, 0);
141+
if (isOssl) {
142+
/* Record return value for whatever version of OpenSSL we are
143+
* running against as expected result for next call */
144+
osslRet = ret;
145+
}
146+
else {
147+
if (ret != osslRet) {
148+
PRINT_MSG("Failed to set HKDF salt to NULL");
149+
err = 1;
150+
}
152151
}
153152
}
154153
if ((err == 0) && (mode != EVP_PKEY_HKDEF_MODE_EXPAND_ONLY)) {
@@ -187,8 +186,6 @@ static int test_hkdf_double_set_salt(OSSL_LIB_CTX* libCtx, unsigned char *key,
187186
return err;
188187
}
189188

190-
#endif
191-
192189
static int test_hkdf_md(const EVP_MD *md, int mode)
193190
{
194191
int err = 0;
@@ -218,22 +215,22 @@ static int test_hkdf_md(const EVP_MD *md, int mode)
218215
err = 1;
219216
}
220217

221-
#if OPENSSL_VERSION_NUMBER <= 0x30400000L
222-
223218
memset(oKey, 0, sizeof(oKey));
224219
memset(wKey, 0, sizeof(wKey));
225220

226221
if (err == 0) {
227222
PRINT_MSG("Calc with OpenSSL");
228-
err = test_hkdf_double_set_salt(osslLibCtx, oKey, sizeof(oKey), md, mode);
223+
err = test_hkdf_double_set_salt(osslLibCtx,
224+
oKey, sizeof(oKey), md, mode, 1);
229225
if (err == 1) {
230226
PRINT_MSG("FAILED OpenSSL");
231227
}
232228
}
233229

234230
if (err == 0) {
235231
PRINT_MSG("Calc with wolfSSL");
236-
err = test_hkdf_double_set_salt(wpLibCtx, wKey, sizeof(wKey), md, mode);
232+
err = test_hkdf_double_set_salt(wpLibCtx,
233+
wKey, sizeof(wKey), md, mode, 0);
237234
if (err == 1) {
238235
PRINT_MSG("FAILED wolfSSL");
239236
}
@@ -245,8 +242,6 @@ static int test_hkdf_md(const EVP_MD *md, int mode)
245242
err = 1;
246243
}
247244

248-
#endif
249-
250245
return err;
251246
}
252247

test/test_rsa.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,9 @@ int test_rsa_fromdata(void* data)
11701170
static const int selections[] = {
11711171
EVP_PKEY_KEYPAIR,
11721172
EVP_PKEY_PUBLIC_KEY,
1173+
#ifdef EVP_PKEY_PRIVATE_KEY
11731174
EVP_PKEY_PRIVATE_KEY, /* added in 3.0.12 and 3.1.4 */
1175+
#endif
11741176
};
11751177

11761178
/* Parameter data fields */

0 commit comments

Comments
 (0)