Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not load profiles when they can't be available #333

Merged
merged 2 commits into from
Jan 9, 2024
Merged
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
5 changes: 5 additions & 0 deletions src/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,8 @@ CK_RV side_channel_free_Decrypt(P11PROV_CTX *ctx, CK_SESSION_HANDLE hSession,
return intf->Decrypt(hSession, pEncryptedData, ulEncryptedDataLen, pData,
pulDataLen);
}

CK_INFO p11prov_module_ck_info(P11PROV_MODULE *mctx)
{
return mctx->ck_info;
}
2 changes: 2 additions & 0 deletions src/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,6 @@ CK_RV side_channel_free_Decrypt(P11PROV_CTX *ctx, CK_SESSION_HANDLE hSession,
CK_ULONG ulEncryptedDataLen, CK_BYTE_PTR pData,
CK_ULONG_PTR pulDataLen);

CK_INFO p11prov_module_ck_info(P11PROV_MODULE *mctx);

#endif /* _INTERFACE_H */
9 changes: 9 additions & 0 deletions src/provider.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,15 @@ bool p11prov_ctx_no_operation_state(P11PROV_CTX *ctx)
return ctx->no_operation_state;
}

CK_INFO p11prov_ctx_get_ck_info(P11PROV_CTX *ctx)
{
if (!ctx->module) {
CK_INFO info = { 0 };
return info;
}
return p11prov_module_ck_info(ctx->module);
}

static void p11prov_teardown(void *ctx)
{
p11prov_ctx_free((P11PROV_CTX *)ctx);
Expand Down
2 changes: 2 additions & 0 deletions src/provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ int p11prov_ctx_cache_sessions(P11PROV_CTX *ctx);

bool p11prov_ctx_no_operation_state(P11PROV_CTX *ctx);

CK_INFO p11prov_ctx_get_ck_info(P11PROV_CTX *ctx);

#include "debug.h"

/* Errors */
Expand Down
8 changes: 7 additions & 1 deletion src/slot.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ static const char slot_desc_fmt[] = "PKCS#11 Token (Slot %lu - %s)";
CK_RV p11prov_init_slots(P11PROV_CTX *ctx, P11PROV_SLOTS_CTX **slots)
{
CK_ULONG num;
CK_INFO ck_info;
CK_SLOT_ID *slotid = NULL;
struct p11prov_slots_ctx *sctx;
CK_RV ret;
int err;

ck_info = p11prov_ctx_get_ck_info(ctx);

sctx = OPENSSL_zalloc(sizeof(P11PROV_SLOTS_CTX));
if (!sctx) {
return CKR_HOST_MEMORY;
Expand Down Expand Up @@ -215,7 +218,10 @@ CK_RV p11prov_init_slots(P11PROV_CTX *ctx, P11PROV_SLOTS_CTX **slots)
goto done;
}

get_slot_profiles(ctx, slot);
/* profiles not available before version 3 */
if (ck_info.cryptokiVersion.major >= 3) {
get_slot_profiles(ctx, slot);
}
get_slot_mechanisms(ctx, slot);

P11PROV_debug_slot(ctx, slot->id, &slot->slot, &slot->token,
Expand Down
15 changes: 12 additions & 3 deletions tests/tgenkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ static void check_rsa_key(EVP_PKEY *pubkey)
fprintf(stderr, "Failed to get N param from public key");
exit(EXIT_FAILURE);
} else {
int bits;
bits = EVP_PKEY_get_bits(pubkey);
if (bits < 3072) {
fprintf(stderr, "Expected 3072 bits key, got %d\n", bits);
exit(EXIT_FAILURE);
}
BN_free(tmp);
tmp = NULL;
}
Expand Down Expand Up @@ -339,7 +345,8 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
params[0] = OSSL_PARAM_construct_utf8_string("pkcs11_uri", uri, 0);
params[1] = OSSL_PARAM_construct_size_t("rsa_keygen_bits", &rsa_bits);
params[1] =
OSSL_PARAM_construct_size_t(OSSL_PKEY_PARAM_RSA_BITS, &rsa_bits);
params[2] = OSSL_PARAM_construct_end();

gen_keys("RSA", label, idhex, params, false);
Expand All @@ -365,7 +372,8 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
params[0] = OSSL_PARAM_construct_utf8_string("pkcs11_uri", uri, 0);
params[1] = OSSL_PARAM_construct_size_t("rsa_keygen_bits", &rsa_bits);
params[1] =
OSSL_PARAM_construct_size_t(OSSL_PKEY_PARAM_RSA_BITS, &rsa_bits);
params[2] = OSSL_PARAM_construct_utf8_string("rsa_pss_keygen_md",
(char *)"SHA256", 0);
params[3] = OSSL_PARAM_construct_end();
Expand Down Expand Up @@ -422,7 +430,8 @@ int main(int argc, char *argv[])
params[0] = OSSL_PARAM_construct_utf8_string("pkcs11_uri", uri, 0);
params[1] = OSSL_PARAM_construct_utf8_string("pkcs11_key_usage",
(char *)key_usage, 0);
params[2] = OSSL_PARAM_construct_size_t("rsa_keygen_bits", &rsa_bits);
params[2] =
OSSL_PARAM_construct_size_t(OSSL_PKEY_PARAM_RSA_BITS, &rsa_bits);
params[3] = OSSL_PARAM_construct_end();

gen_keys("RSA", label, idhex, params, false);
Expand Down