Skip to content
Open
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
72 changes: 66 additions & 6 deletions src/wp_file_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <wolfprovider/settings.h>
#include <wolfprovider/alg_funcs.h>

#include <wolfssl/wolfcrypt/types.h>

/* TODO: support directory access. */

/**
Expand Down Expand Up @@ -353,6 +355,55 @@ static const wp_DecoderInfo wp_decoders[] = {
/** Number of decoders supported. */
#define WP_DECODERS_SIZE (sizeof(wp_decoders) / sizeof(*wp_decoders))

/**
* Combine a decoder's structure query with the caller's property query.
*
* @param [in] base Structure property query. May be NULL.
* @param [in] caller Caller's property query. May be NULL.
* @param [out] query Combined property query string, or NULL when neither
* input constrains the fetch.
* @return 1 on success.
* @return 0 on allocation failure.
*/
static int wp_file_decoder_prop_query(const char* base, const char* caller,
char** query)
{
int ok = 1;
size_t len;

/* Treat an empty query string the same as an absent (NULL) one. */
if ((base != NULL) && (*base == '\0')) {
base = NULL;
}
if ((caller != NULL) && (*caller == '\0')) {
caller = NULL;
}

*query = NULL;
if (base == NULL) {
if (caller != NULL) {
*query = OPENSSL_strdup(caller);
ok = (*query != NULL);
}
}
else if (caller == NULL) {
*query = OPENSSL_strdup(base);
ok = (*query != NULL);
}
else {
len = XSTRLEN(base) + XSTRLEN(caller) + 2;
*query = OPENSSL_malloc(len);
if (*query == NULL) {
ok = 0;
}
else {
XSNPRINTF(*query, len, "%s,%s", base, caller);
}
}

return ok;
}

/**
* Set the decoders into the decoder context.
*
Expand All @@ -366,19 +417,28 @@ static int wp_file_set_decoder(wp_FileCtx* ctx, OSSL_DECODER_CTX* decCtx)
int ok = 1;
size_t i;
OSSL_DECODER* decoder;
char* query = NULL;

WOLFPROV_ENTER(WP_LOG_COMP_PROVIDER, "wp_file_set_decoder");

for (i = 0; ok && (i < WP_DECODERS_SIZE); i++) {
decoder = OSSL_DECODER_fetch(ctx->provCtx->libCtx, wp_decoders[i].name,
wp_decoders[i].propQuery);
if (decoder == NULL) {
if (!wp_file_decoder_prop_query(wp_decoders[i].propQuery,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 [Medium] New property-bound decoder fetch path lacks regression coverage
💡 SUGGEST test

The PR's core behavior is that explicit OSSL_DECODER_fetch() calls now include ctx->propQuery, but the existing store-load tests do not pass OSSL_STORE_PARAM_PROPERTIES; repository search found that parameter only in src/wp_file_store.c. That leaves the fixed provider-boundary path untested, so a future change could drop the caller query again while the current RSA/EC load tests still pass.

Recommendation: Add a store-load regression test that passes OSSL_STORE_PARAM_PROPERTIES with provider=wolfprov and verifies the key/cert load succeeds within wolfProvider. A negative case using a property query that excludes wolfProvider (e.g. provider=default) would also exercise the failure boundary. Add these focused tests for OSSL_STORE_PARAM_PROPERTIES on the file store path before or soon after merge.

ctx->propQuery, &query)) {
ok = 0;
}
if (ok && !OSSL_DECODER_CTX_add_decoder(decCtx, decoder)) {
ok = 0;
if (ok) {
decoder = OSSL_DECODER_fetch(ctx->provCtx->libCtx,
wp_decoders[i].name, query);
if (decoder == NULL) {
ok = 0;
}
if (ok && !OSSL_DECODER_CTX_add_decoder(decCtx, decoder)) {
ok = 0;
}
OSSL_DECODER_free(decoder);
}
OSSL_DECODER_free(decoder);
OPENSSL_free(query);
query = NULL;
}

WOLFPROV_LEAVE(WP_LOG_COMP_PROVIDER, __FILE__ ":" WOLFPROV_STRINGIZE(__LINE__), ok);
Expand Down
Loading