Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions .github/workflows/fips-ready.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
fips_ready_test:
needs: [discover_versions, require_fips_resolved]
if: github.event_name != 'pull_request' || github.event.pull_request.draft == false
name: FIPS Ready ${{ matrix.wolfssl_bundle_ref }} (${{ matrix.openssl_ref }})
name: FIPS Ready ${{ matrix.wolfssl_bundle_ref }} (${{ matrix.openssl_ref }})${{ matrix.wolfssl_extra_opts != '' && format(' {0}', matrix.wolfssl_extra_opts) || '' }}
runs-on: ubuntu-22.04
permissions:
contents: read
Expand All @@ -75,7 +75,13 @@ jobs:
matrix:
wolfssl_bundle_ref: ${{ fromJson(needs.discover_versions.outputs.fips_ready_pr_array) }}
openssl_ref: ${{ fromJson(needs.discover_versions.outputs.openssl_latest_ref_array) }}
wolfssl_extra_opts: [ '' ]
# force_fail collapsed into sequential runs in the test step
include:
# DES3 also enables MD5, so non-FIPS algorithms are in the build
- wolfssl_bundle_ref: ${{ needs.discover_versions.outputs.fips_ready_latest }}
openssl_ref: ${{ needs.discover_versions.outputs.openssl_latest_ref }}
wolfssl_extra_opts: '--enable-des3'
steps:
- name: Checkout wolfProvider
uses: actions/checkout@v4
Expand All @@ -92,7 +98,7 @@ jobs:
# The build below sets WOLFPROV_FIPS_FORCE_FAIL, which adds
# -DHAVE_FORCE_FIPS_FAILURE to the wolfSSL build; key the cached
# install on it so a wolfSSL built without the define is never reused.
extra_key: forcefail
extra_key: forcefail${{ matrix.wolfssl_extra_opts }}
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Download FIPS Ready Bundle
Expand All @@ -107,6 +113,7 @@ jobs:
# flag) that enables HAVE_FORCE_FIPS_FAILURE for the fips_status test.
OPENSSL_TAG=${{ matrix.openssl_ref }} \
WOLFPROV_FIPS_FORCE_FAIL=1 \
WOLFSSL_EXTRA_CONFIG_OPTS="${{ matrix.wolfssl_extra_opts }}" \
./scripts/build-wolfprovider.sh --fips-bundle="$FIPS_BUNDLE_PATH" \
--fips-check=ready --wolfssl-ver=v${{matrix.wolfssl_bundle_ref}}-stable

Expand Down
11 changes: 11 additions & 0 deletions include/wolfprovider/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@
#define WP_DH_MIN_BITS 1024
#endif

/* Fallbacks for digest minimums that older wolfSSL versions lack. */
#ifndef WC_MIN_DIGEST_SIZE
#define WC_MIN_DIGEST_SIZE 20
#endif /* !WC_MIN_DIGEST_SIZE */
#ifndef WC_MIN_DIGEST_SIZE_FOR_SIGN
#define WC_MIN_DIGEST_SIZE_FOR_SIGN WC_MIN_DIGEST_SIZE
#endif /* !WC_MIN_DIGEST_SIZE_FOR_SIGN */
#ifndef WC_MIN_DIGEST_SIZE_FOR_VERIFY
#define WC_MIN_DIGEST_SIZE_FOR_VERIFY WC_MIN_DIGEST_SIZE
#endif /* !WC_MIN_DIGEST_SIZE_FOR_VERIFY */

/* DER key encoding/decoding formats. */
/** SubjectPublicKeyInfo encoding format. */
#define WP_ENC_FORMAT_SPKI 1
Expand Down
1 change: 1 addition & 0 deletions scripts/build-wolfprovider.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ show_help() {
echo " WOLFSSL_ISFIPS If set to 1, clones a wolfSSL FIPS bundle from GitHub"
echo " WOLFSSL_FIPS_BUNDLE Directory containing the wolfSSL FIPS bundle to use instead of cloning from GitHub"
echo " WOLFSSL_FIPS_CHECK_TAG Tag for wolfSSL FIPS bundle (v5.2.1, v5.2.4, linuxv5.2.1, v6.0.0, ready, etc). Automatically determines configure option (default: v5.2.4)"
echo " WOLFSSL_EXTRA_CONFIG_OPTS Extra wolfSSL configure options added to the defaults (e.g., --enable-des3)"
echo " WOLFPROV_CLEAN If set to 1, run make clean in OpenSSL, wolfSSL, and wolfProvider"
echo " WOLFPROV_DISTCLEAN If set to 1, remove the source and install directories of OpenSSL, wolfSSL, and wolfProvider"
echo " WOLFPROV_DEBUG If set to 1, builds OpenSSL, wolfSSL, and wolfProvider with debug options enabled"
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils-wolfssl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ install_wolfssl() {
printf "\tConfigure wolfSSL ${WOLFSSL_TAG} ... "

./autogen.sh >>$LOG_FILE 2>&1
CONF_ARGS="-prefix=${WOLFSSL_INSTALL_DIR}"
CONF_ARGS="-prefix=${WOLFSSL_INSTALL_DIR} ${WOLFSSL_EXTRA_CONFIG_OPTS}"

if [ "$WOLFPROV_DEBUG" = "1" ]; then
CONF_ARGS+=" --enable-debug --enable-keylog-export"
Expand Down
11 changes: 2 additions & 9 deletions src/wp_ecdsa_sig.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@

#ifdef WP_HAVE_ECDSA

/* WC_MIN_DIGEST_SIZE was introduced in wolfSSL v5.9.1. Fall back to the
* SHA-1 digest size on older releases so the raw-ECDSA minimum matches the
* behavior FIPS 186-4 requires. */
#ifndef WC_MIN_DIGEST_SIZE
#define WC_MIN_DIGEST_SIZE 20
#endif

/**
* ECDSA signature context.
*
Expand Down Expand Up @@ -291,7 +284,7 @@ static int wp_ecdsa_sign(wp_EcdsaSigCtx *ctx, unsigned char *sig,
ok = 0;
}
else if ((hashType == WC_HASH_TYPE_NONE) &&
(tbsLen < WC_MIN_DIGEST_SIZE)) {
(tbsLen < WC_MIN_DIGEST_SIZE_FOR_SIGN)) {
ok = 0;
}
else if ((ok = wp_ecc_check_usage(ctx->ecc))) {
Expand Down Expand Up @@ -391,7 +384,7 @@ static int wp_ecdsa_verify(wp_EcdsaSigCtx *ctx, const unsigned char *sig,
ok = 0;
}
else if ((hashType == WC_HASH_TYPE_NONE) &&
(tbsLen < WC_MIN_DIGEST_SIZE)) {
(tbsLen < WC_MIN_DIGEST_SIZE_FOR_VERIFY)) {
ok = 0;
}
else if ((!WP_FITS_WORD32(sigLen)) || (!WP_FITS_WORD32(tbsLen))) {
Expand Down
53 changes: 26 additions & 27 deletions test/test_ecc.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@
#include <openssl/core_names.h>
#include <openssl/param_build.h>

#include <wolfssl/wolfcrypt/hash.h>

/* Mirror the fallback used in src/wp_ecdsa_sig.c for wolfSSL < v5.9.1. */
#ifndef WC_MIN_DIGEST_SIZE
#define WC_MIN_DIGEST_SIZE 20
#endif
#include <wolfprovider/internal.h>

#ifdef WP_HAVE_ECC

Expand Down Expand Up @@ -2029,17 +2024,19 @@ int test_ecdsa_p256_pkey(void *data)
return err;
}

/* Raw EVP_PKEY_verify must reject inputs below WC_MIN_DIGEST_SIZE. */
/* Raw ECDSA sign and verify must reject inputs below wolfSSL's minimums. */
int test_ecdsa_verify_undersized_hash(void *data)
{
/* Boundaries track WC_MIN_DIGEST_SIZE so the assertions stay valid for
* whatever hash set the wolfSSL build enabled (typically 20 for SHA-1,
* but 16 when MD5 is on or 28+ in FIPS 186-5 builds). */
static const size_t sizes[] = { 0,
WC_MIN_DIGEST_SIZE - 1,
WC_MIN_DIGEST_SIZE,
WC_MAX_DIGEST_SIZE };
static const int expectFail[] = { 1, 1, 0, 0 };
/* Minimums vary with the hash set and FIPS level, e.g. 16 with MD5. */
static const size_t verifySizes[] = { 0,
WC_MIN_DIGEST_SIZE_FOR_VERIFY - 1,
WC_MIN_DIGEST_SIZE_FOR_VERIFY,
WC_MAX_DIGEST_SIZE };
static const size_t signSizes[] = { 0,
WC_MIN_DIGEST_SIZE_FOR_SIGN - 1,
WC_MIN_DIGEST_SIZE_FOR_SIGN,
WC_MAX_DIGEST_SIZE };
static const int expectFail[] = { 1, 1, 0, 0 };
int err;
size_t i;
EVP_PKEY *pkey = NULL;
Expand All @@ -2056,26 +2053,28 @@ int test_ecdsa_verify_undersized_hash(void *data)
err = pkey == NULL;
}

for (i = 0; (err == 0) && (i < sizeof(sizes)/sizeof(sizes[0])); i++) {
PRINT_MSG("verify tbsLen=%zu", sizes[i]);
for (i = 0; (err == 0) && (i < sizeof(verifySizes)/sizeof(verifySizes[0]));
i++) {
PRINT_MSG("verify tbsLen=%zu", verifySizes[i]);
ecdsaSigLen = sizeof(ecdsaSig);
err = test_pkey_sign_ecc(pkey, osslLibCtx, buf, sizes[i], ecdsaSig,
&ecdsaSigLen);
err = test_pkey_sign_ecc(pkey, osslLibCtx, buf, verifySizes[i],
ecdsaSig, &ecdsaSigLen);
if (err == 0) {
int verifyErr = test_pkey_verify_ecc(pkey, wpLibCtx, buf, sizes[i],
ecdsaSig, ecdsaSigLen);
int verifyErr = test_pkey_verify_ecc(pkey, wpLibCtx, buf,
verifySizes[i], ecdsaSig,
ecdsaSigLen);
err = (verifyErr != 0) != expectFail[i];
}
}

/* Same minimum applies on the sign side: wolfProvider must refuse to
* produce a raw signature it would later refuse to verify. */
for (i = 0; (err == 0) && (i < sizeof(sizes)/sizeof(sizes[0])); i++) {
/* The sign minimum is never below the verify minimum. */
for (i = 0; (err == 0) && (i < sizeof(signSizes)/sizeof(signSizes[0]));
i++) {
int signErr;
PRINT_MSG("sign tbsLen=%zu", sizes[i]);
PRINT_MSG("sign tbsLen=%zu", signSizes[i]);
ecdsaSigLen = sizeof(ecdsaSig);
signErr = test_pkey_sign_ecc(pkey, wpLibCtx, buf, sizes[i], ecdsaSig,
&ecdsaSigLen);
signErr = test_pkey_sign_ecc(pkey, wpLibCtx, buf, signSizes[i],
ecdsaSig, &ecdsaSigLen);
err = (signErr != 0) != expectFail[i];
}

Expand Down
5 changes: 3 additions & 2 deletions test/test_tls1_prf.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,10 @@ int test_tls1_prf(void *data)

(void)data;

#ifdef WP_HAVE_MD5_SHA1
#if defined(WP_HAVE_MD5_SHA1) && \
(!defined(HAVE_FIPS) || defined(WP_ALLOW_NON_FIPS))
Comment on lines +534 to +535
err = test_tls1_prf_md(EVP_md5_sha1());
#endif
#endif /* WP_HAVE_MD5_SHA1 && (!HAVE_FIPS || WP_ALLOW_NON_FIPS) */
#ifdef WP_HAVE_SHA256
if (err == 0) {
err = test_tls1_prf_md(EVP_sha256());
Expand Down
Loading