Skip to content

Ensure CMS with Explicit EC works #563

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -4264,7 +4264,7 @@ static CK_RV import_ec_params(P11PROV_OBJ *key, const OSSL_PARAM params[])
}

curve_nid = EC_GROUP_get_curve_name(group);
if (curve_nid == NID_undef) {
if (curve_nid != NID_undef) {
curve_name = OSSL_EC_curve_nid2name(curve_nid);
if (!curve_name) {
P11PROV_raise(ctx, CKR_KEY_INDIGESTIBLE, "Unknown curve");
Expand Down
1 change: 1 addition & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ test_programs = {
'tpkey': ['tpkey.c', 'util.c'],
'pincache': ['pincache.c'],
'ccerts': ['ccerts.c', 'util.c'],
'tecx': ['tecx.c', 'util.c'],
}

test_executables = []
Expand Down
4 changes: 2 additions & 2 deletions tests/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ else
ECXCRTN="ecExplicitCert"

ptool --write-object="${TESTSSRCDIR}/explicit_ec.key.der" --type=privkey \
--id="$KEYID" --label="${ECXCRTN}" 2>&1
--id="$KEYID" --label="${ECXCRTN}" --usage-sign --usage-derive 2>&1
ptool --write-object="${TESTSSRCDIR}/explicit_ec.pub.der" --type=pubkey \
--id="$KEYID" --label="${ECXCRTN}" 2>&1
--id="$KEYID" --label="${ECXCRTN}" --usage-sign --usage-derive 2>&1

ECXBASEURIWITHPINVALUE="pkcs11:id=${URIKEYID}?pin-value=${PINVALUE}"
ECXBASEURIWITHPINSOURCE="pkcs11:id=${URIKEYID}?pin-source=file:${PINFILE}"
Expand Down
64 changes: 64 additions & 0 deletions tests/tecx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* Copyright (C) 2023 Timo Teräs <[email protected]>
SPDX-License-Identifier: Apache-2.0 */

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <openssl/err.h>
#include <openssl/store.h>
#include <openssl/core_names.h>
#include "util.h"

static void ecdh_test(EVP_PKEY *a, EVP_PKEY *b)
{
unsigned char secret[64];
size_t secretlen = 64;
EVP_PKEY_CTX *derivectx;

derivectx = EVP_PKEY_CTX_new_from_pkey(NULL, a, NULL);
if (!derivectx) {
fprintf(stderr, "EVP_PKEY_CTX_new_from_pkey failed!");
ossl_err_print();
exit(EXIT_FAILURE);
}

if (EVP_PKEY_derive_init(derivectx) != 1) {
fprintf(stderr, "EVP_PKEY_derive_init failed!");
ossl_err_print();
exit(EXIT_FAILURE);
}

if (EVP_PKEY_derive_set_peer(derivectx, b) != 1) {
fprintf(stderr, "EVP_PKEY_derive_set_peer failed!");
ossl_err_print();
exit(EXIT_FAILURE);
}

if (EVP_PKEY_derive(derivectx, secret, &secretlen) != 1) {
fprintf(stderr, "EVP_PKEY_derive failed!");
ossl_err_print();
exit(EXIT_FAILURE);
}

EVP_PKEY_CTX_free(derivectx);
}

int main(int argc, char *argv[])
{
EVP_PKEY *a, *b;

if (argc != 3) {
fprintf(stderr, "Usage: %s [keyuri-a] [keyuri-b]\n", argv[0]);
exit(EXIT_FAILURE);
}
a = load_key(argv[1]);
b = load_key(argv[2]);

ecdh_test(a, b);

EVP_PKEY_free(a);
EVP_PKEY_free(b);

PRINTERR("ALL A-OK!\n");
exit(EXIT_SUCCESS);
}
4 changes: 4 additions & 0 deletions tests/tecxc
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,8 @@ req -new -batch -key "${ECXPRIURI}" -out ${TMPPDIR}/ecdsa_csr.pem'
ossl '
req -in ${TMPPDIR}/ecdsa_csr.pem -verify -noout'

title PARA "Additional test with Explicit EC keys"
$CHECKER "${TESTBLDDIR}/tecx" "${ECXPRIURI}" "${ECXPUBURI}"


exit 0
Loading