Skip to content

Commit b1c6664

Browse files
authored
Merge pull request #49 from bandi13/moreFIPStests
More FIPS tests
2 parents 445f6ac + 5a12481 commit b1c6664

13 files changed

+98
-1
lines changed

scripts/test-sanity.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
# This script provides simple sanity checks to make sure the provider is working
3+
4+
SET_PRE=$( set )
5+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
6+
LOG_FILE=${SCRIPT_DIR}/test-sanity.log
7+
rm -f ${LOG_FILE}
8+
source ${SCRIPT_DIR}/utils-wolfprovider.sh
9+
10+
echo "Using openssl: $OPENSSL_TAG, wolfssl: $WOLFSSL_TAG"
11+
12+
function doTestCmd() {
13+
CMD=$*
14+
echo ">>>>>> Running $CMD"
15+
eval $CMD
16+
RET=$?
17+
if [ $RET -ne 0 ]; then
18+
echo "Failed $CMD: $RET"
19+
exit 1
20+
fi
21+
echo "<<<<<<"
22+
}
23+
24+
function runSpotCheck() {
25+
doTestCmd init_wolfprov
26+
27+
SET_POST=$( set )
28+
echo "New variables set:"
29+
diff <(echo "$SET_PRE") <(echo "$SET_POST") | grep "="
30+
31+
doTestCmd "${OPENSSL_INSTALL_DIR}/bin/openssl list -providers --verbose | grep 'Providers:' -A 10"
32+
33+
if [ $(${OPENSSL_INSTALL_DIR}/bin/openssl list -providers --verbose | grep libwolfprov | wc -l) = 0 ]; then
34+
echo "Not using wolfProvider for some reason"
35+
exit 2
36+
fi
37+
38+
if [ $(${OPENSSL_INSTALL_DIR}/bin/openssl list -providers --verbose | grep OpenSSL | wc -l) -ne 0 ]; then
39+
echo "OpenSSL provider is also enabled"
40+
exit 2
41+
fi
42+
43+
doTestCmd "${OPENSSL_INSTALL_DIR}/bin/openssl s_client -CApath /etc/ssl/certs -connect github.com:443 </dev/null"
44+
doTestCmd "curl https://github.com/wolfSSL/wolfProvider -o test.html"
45+
46+
doTestCmd "${OPENSSL_INSTALL_DIR}/bin/openssl s_client -CApath /etc/ssl/certs -connect tls.support:443 </dev/null"
47+
doTestCmd "curl https://tls.support -vv --tlsv1.3 --tls-max 1.3 -o test.html"
48+
}
49+
50+
runSpotCheck
51+
52+
exit $?

scripts/utils-wolfssl.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ install_wolfssl() {
8080
CONF_ARGS="-prefix=${WOLFSSL_INSTALL_DIR}"
8181

8282
if [ "$WOLFPROV_DEBUG" = "1" ]; then
83-
CONF_ARGS+=" --enable-debug"
83+
CONF_ARGS+=" --enable-debug --enable-debug-trace-errcodes=backtrace --enable-keylog-export"
84+
WOLFSSL_CONFIG_CFLAGS+=" -DWOLFSSL_LOGGINGENABLED_DEFAULT=1"
8485
fi
8586
if [ "$WOLFSSL_ISFIPS" = "1" ]; then
87+
printf "with FIPS ... "
8688
CONF_ARGS+=" --enable-fips=ready"
8789
if [ ! -e "XXX-fips-test" ]; then
8890
./fips-check.sh keep nomakecheck fips-ready >>$LOG_FILE 2>&1

src/wp_aes_aead.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ static int wp_aead_set_param_tls1_iv_rand(wp_AeadCtx* ctx,
603603
#else
604604
(void)ctx;
605605
(void)params;
606+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
606607
return 1;
607608
#endif
608609
}

src/wp_aes_stream.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ static int wp_aes_stream_final(wp_AesStreamCtx* ctx, unsigned char *out,
450450
(void)out;
451451
(void)outSize;
452452
*outLen = 0;
453+
WOLFPROV_LEAVE(WP_LOG_CIPHER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
453454
return 1;
454455
}
455456

src/wp_dh_kmgmt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ int wp_dh_up_ref(wp_Dh* dh)
276276
return ok;
277277
#else
278278
dh->refCnt++;
279+
WOLFPROV_LEAVE(WP_LOG_KE, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
279280
return 1;
280281
#endif
281282
}

src/wp_drbg.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ static int wp_drbg_uninstantiate(wp_DrbgCtx* ctx)
166166
OPENSSL_clear_free(ctx->rng, sizeof(*ctx->rng));
167167
#endif
168168
ctx->rng = NULL;
169+
WOLFPROV_LEAVE(WP_LOG_RNG, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
169170
return 1;
170171
}
171172

@@ -331,6 +332,7 @@ static int wp_drbg_unlock(wp_DrbgCtx* ctx)
331332
wc_UnLockMutex(ctx->mutex);
332333
}
333334
#endif
335+
WOLFPROV_LEAVE(WP_LOG_RNG, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
334336
return 1;
335337
}
336338

@@ -419,6 +421,7 @@ static int wp_drbg_set_ctx_params(wp_DrbgCtx* ctx, const OSSL_PARAM params[])
419421
{
420422
(void)ctx;
421423
(void)params;
424+
WOLFPROV_LEAVE(WP_LOG_RNG, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
422425
return 1;
423426
}
424427

@@ -431,6 +434,7 @@ static int wp_drbg_set_ctx_params(wp_DrbgCtx* ctx, const OSSL_PARAM params[])
431434
static int wp_drbg_verify_zeroization(wp_DrbgCtx* ctx)
432435
{
433436
(void)ctx;
437+
WOLFPROV_LEAVE(WP_LOG_RNG, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
434438
return 1;
435439
}
436440

src/wp_ecc_kmgmt.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ int wp_ecc_up_ref(wp_Ecc* ecc)
256256
return ok;
257257
#else
258258
ecc->refCnt++;
259+
WOLFPROV_LEAVE(WP_LOG_PK, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
259260
return 1;
260261
#endif
261262
}
@@ -800,6 +801,14 @@ static int wp_ecc_get_params(wp_Ecc* ecc, OSSL_PARAM params[])
800801
}
801802
}
802803

804+
if (ok) {
805+
/* Always assume not decoded from explicit params for now */
806+
p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_EC_DECODED_FROM_EXPLICIT_PARAMS);
807+
if ((p != NULL) && !OSSL_PARAM_set_int(p, 0)) {
808+
ok = 0;
809+
}
810+
}
811+
803812
WOLFPROV_LEAVE(WP_LOG_PK, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
804813
return ok;
805814
}
@@ -1869,11 +1878,13 @@ static int wp_ecc_decode_params(wp_Ecc* ecc, unsigned char* data, word32 len)
18691878
ok = 0;
18701879
}
18711880
if (ok && (data[0] != 0x06)) {
1881+
WOLFPROV_MSG(WP_LOG_PK, "Invalid data");
18721882
ok = 0;
18731883
}
18741884
if (ok) {
18751885
oidLen = data[1];
18761886
if ((oidLen >= 0x80) || (oidLen + 2 > len)) {
1887+
WOLFPROV_MSG(WP_LOG_PK, "OID out of bounds");
18771888
ok = 0;
18781889
}
18791890
}
@@ -1884,17 +1895,20 @@ static int wp_ecc_decode_params(wp_Ecc* ecc, unsigned char* data, word32 len)
18841895
ecc->curveId = wp_ecc_get_curve_id_from_oid(data + 2, oidLen);
18851896
#endif
18861897
if (ecc->curveId == ECC_CURVE_INVALID) {
1898+
WOLFPROV_MSG(WP_LOG_PK, "Invalid curve");
18871899
ok = 0;
18881900
}
18891901
}
18901902

18911903
if (ok) {
18921904
rc = wc_ecc_set_curve(&ecc->key, 0, ecc->curveId);
18931905
if (rc != 0) {
1906+
WOLFPROV_MSG(WP_LOG_PK, "Can't set curve: %d",rc);
18941907
ok = 0;
18951908
}
18961909
}
18971910
if (ok && (!wp_ecc_set_bits(ecc))) {
1911+
WOLFPROV_MSG(WP_LOG_PK, "Can't set bits");
18981912
ok = 0;
18991913
}
19001914

@@ -2108,6 +2122,7 @@ static int wp_ecc_encode_params_size(const wp_Ecc *ecc, size_t* keyLen)
21082122
/* ASN.1 type, len and data. */
21092123
*keyLen = ecc->key.dp->oidSz + 2;
21102124

2125+
WOLFPROV_LEAVE(WP_LOG_PK, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
21112126
return 1;
21122127
}
21132128

@@ -2130,6 +2145,7 @@ static int wp_ecc_encode_params(const wp_Ecc *ecc, unsigned char* keyData,
21302145

21312146
*keyLen = ecc->key.dp->oidSz + 2;
21322147

2148+
WOLFPROV_LEAVE(WP_LOG_PK, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
21332149
return 1;
21342150
}
21352151

src/wp_ecx_kmgmt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ int wp_ecx_up_ref(wp_Ecx* ecx)
224224
return ok;
225225
#else
226226
ecx->refCnt++;
227+
WOLFPROV_LEAVE(WP_LOG_PK, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
227228
return 1;
228229
#endif
229230
}

src/wp_file_store.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ static int wp_file_eof(wp_FileCtx* ctx)
480480
static int wp_file_close(wp_FileCtx* ctx)
481481
{
482482
wp_filectx_free(ctx);
483+
WOLFPROV_LEAVE(WP_LOG_PROVIDER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
483484
return 1;
484485
}
485486

src/wp_kdf_kmgmt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ int wp_kdf_up_ref(wp_Kdf* kdf)
7171
return ok;
7272
#else
7373
kdf->refCnt++;
74+
WOLFPROV_LEAVE(WP_LOG_KDF, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
7475
return 1;
7576
#endif
7677
}
@@ -151,6 +152,7 @@ static int wp_kdf_has(const wp_Kdf* kdf, int selection)
151152
{
152153
(void)kdf;
153154
(void)selection;
155+
WOLFPROV_LEAVE(WP_LOG_KDF, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
154156
return 1;
155157
}
156158

src/wp_mac_kmgmt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ int wp_mac_up_ref(wp_Mac* mac)
108108
return ok;
109109
#else
110110
mac->refCnt++;
111+
WOLFPROV_LEAVE(WP_LOG_MAC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
111112
return 1;
112113
#endif
113114
}
@@ -435,6 +436,7 @@ static int wp_mac_export_priv_key(wp_Mac* mac, OSSL_PARAM* params, int* pIdx,
435436
}
436437

437438
*pIdx = i;
439+
WOLFPROV_LEAVE(WP_LOG_MAC, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
438440
return 1;
439441
}
440442

src/wp_rsa_kmgmt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ int wp_rsa_up_ref(wp_Rsa* rsa)
199199
return ok;
200200
#else
201201
rsa->refCnt++;
202+
WOLFPROV_LEAVE(WP_LOG_PK, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
202203
return 1;
203204
#endif
204205
}
@@ -468,6 +469,7 @@ static int wp_rsa_pss_params_set_pss_defaults(wp_RsaPssParams* pss)
468469
pss->saltLen = 20;
469470
pss->derTrailer = 1; /* Default: RFC8017 A.2.3 */
470471

472+
WOLFPROV_LEAVE(WP_LOG_PK, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
471473
return 1;
472474
}
473475

@@ -1085,6 +1087,7 @@ static int wp_rsa_pss_params_export(wp_RsaPssParams* pss, OSSL_PARAM* params,
10851087
&pss->saltLen);
10861088

10871089
*idx = i;
1090+
WOLFPROV_LEAVE(WP_LOG_PK, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
10881091
return 1;
10891092
}
10901093

src/wp_wolfprov.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include "wolfprovider/wp_wolfprov.h"
3434
#include "wolfprovider/alg_funcs.h"
3535

36+
#include "wolfssl/wolfcrypt/logging.h"
37+
3638
const char* wolfprovider_id = "libwolfprov";
3739

3840
/* Core function that gets the table of parameters. */
@@ -73,6 +75,7 @@ static const OSSL_PARAM* wolfprov_gettable_params(void* provCtx)
7375
int wolfssl_prov_is_running(void)
7476
{
7577
/* Always running. */
78+
WOLFPROV_LEAVE(WP_LOG_PROVIDER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
7679
return 1;
7780
}
7881

@@ -172,6 +175,7 @@ static int bio_core_new(BIO *bio)
172175
{
173176
BIO_set_init(bio, 1);
174177

178+
WOLFPROV_LEAVE(WP_LOG_PROVIDER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
175179
return 1;
176180
}
177181

@@ -180,6 +184,7 @@ static int bio_core_free(BIO *bio)
180184
BIO_set_init(bio, 0);
181185
wolfssl_prov_bio_free(BIO_get_data(bio));
182186

187+
WOLFPROV_LEAVE(WP_LOG_PROVIDER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
183188
return 1;
184189
}
185190

@@ -909,6 +914,7 @@ static int wp_dummy_decode(WOLFPROV_CTX* ctx, OSSL_CORE_BIO* cBio,
909914
(void)pwCb;
910915
(void)pwCbArg;
911916

917+
WOLFPROV_LEAVE(WP_LOG_PROVIDER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), 1);
912918
return 1;
913919
}
914920
/**
@@ -1133,6 +1139,11 @@ int wolfssl_provider_init(const OSSL_CORE_HANDLE* handle,
11331139
int ok = 1;
11341140
OSSL_FUNC_core_get_libctx_fn* c_get_libctx = NULL;
11351141

1142+
#ifdef WOLFPROV_DEBUG
1143+
ok = (wolfProv_Debugging_ON() == 0) && (wolfSSL_Debugging_ON() == 0);
1144+
wolfSSL_SetLoggingPrefix("wolfSSL");
1145+
#endif
1146+
11361147
for (; in->function_id != 0; in++) {
11371148
switch (in->function_id) {
11381149
case OSSL_FUNC_CORE_GETTABLE_PARAMS:

0 commit comments

Comments
 (0)