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

Fix a bug where eddsa mechanism isnt recognized in generate-keypair #617

Merged
merged 1 commit into from
Jan 11, 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
2 changes: 1 addition & 1 deletion doc/manual/p11-kit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ $ p11-kit generate-keypair --type=algorithm {--bits=n|--curve=name} &l
<varlistentry>
<term><option>--type=&lt;algorithm&gt;</option></term>
<listitem><para>Specify the type of keys to generate.
Supported values are rsa, ecdsa and ed25519.</para></listitem>
Supported values are rsa, ecdsa and eddsa.</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--bits=&lt;n&gt;</option></term>
Expand Down
3 changes: 1 addition & 2 deletions p11-kit/generate-keypair.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ get_mechanism (const char *type)
m.mechanism = CKM_RSA_PKCS_KEY_PAIR_GEN;
else if (p11_ascii_strcaseeq (type, "ecdsa"))
m.mechanism = CKM_ECDSA_KEY_PAIR_GEN;
else if (p11_ascii_strcaseeq (type, "ed25519") ||
p11_ascii_strcaseeq (type, "ed448"))
else if (p11_ascii_strcaseeq (type, "eddsa"))
m.mechanism = CKM_EC_EDWARDS_KEY_PAIR_GEN;

return m;
Expand Down
10 changes: 5 additions & 5 deletions p11-kit/test-generate-keypair.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ test_generate_keypair_ecdsa() {
if "$abs_top_builddir"/p11-kit/p11-kit-testable generate-keypair --login --label="ecdsa-$curve" --type=ecdsa --curve="$curve" "pkcs11:token=PUBKEY%20LABEL?pin-value=booo" 2> err.out; then
assert_fail "expected to fail: p11-kit generate-keypair"
fi
assert_contains err.out "key-pair generation failed: The crypto mechanism is invalid or unrecognized"
done
assert_contains err.out "key-pair generation failed: The crypto mechanism is invalid or unrecognized"

if "$abs_top_builddir"/p11-kit/p11-kit-testable generate-keypair --login --label="ecdsa-unknown" --type=ecdsa --curve=unknown "pkcs11:token=PUBKEY%20LABEL?pin-value=booo" 2> err.out; then
assert_fail "p11-kit generate-keypair succeeded for unknown ecdsa curve"
Expand All @@ -54,16 +54,16 @@ test_generate_keypair_ecdsa() {
test_generate_keypair_eddsa() {
for curve in ed25519 ed448; do
if "$abs_top_builddir"/p11-kit/p11-kit-testable generate-keypair --login --label="eddsa-$curve" --type=eddsa --curve="$curve" "pkcs11:token=PUBKEY%20LABEL?pin-value=booo" 2> err.out; then
assert_fail "unable to run: p11-kit generate-keypair"
assert_fail "expected to fail: p11-kit generate-keypair"
fi
assert_contains err.out "key-pair generation failed: The crypto mechanism is invalid or unrecognized"
done
assert_contains err.out "key-pair generation failed: The crypto mechanism is invalid or unrecognized"

if "$abs_top_builddir"/p11-kit/p11-kit-testable generate-keypair --login --label="eddsa-unknown" --type=eddsa --curve=unknown "pkcs11:token=PUBKEY%20LABEL?pin-value=booo"; then
if "$abs_top_builddir"/p11-kit/p11-kit-testable generate-keypair --login --label="eddsa-unknown" --type=eddsa --curve=unknown "pkcs11:token=PUBKEY%20LABEL?pin-value=booo" 2> err.out; then
assert_fail "p11-kit generate-keypair succeeded for unknown eddsa curve"
fi
assert_contains err.out "unknown curve name: unknown"
}

run test_generate_keypair_mock test_generate_keypair_rsa \
test_generate_keypair_ecdsa test_generate_keypair_ecdsa
test_generate_keypair_ecdsa test_generate_keypair_eddsa
Loading