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

list-mechanisms: initial implementation #576

Merged
merged 1 commit into from
Oct 2, 2023

Conversation

t184256
Copy link
Contributor

@t184256 t184256 commented Sep 22, 2023

Resolves: #563

To be addressed:

  • is mixing APIs OK?
  • which printing API should I use?
  • there are no tests added a test against mock data

@t184256 t184256 changed the title WIP: list-mechanisms: initial implementation list-mechanisms: initial implementation Sep 22, 2023
}

static int
list_mechanisms (const char *token_str)

Check warning

Code scanning / CodeQL

Poorly documented large function Warning

Poorly documented function: fewer than 2% comments for a function of 108 lines.
@coveralls
Copy link

coveralls commented Sep 22, 2023

Coverage Status

coverage: 69.018% (-0.04%) from 69.055% when pulling 8fe8d0d on t184256:list-mechanisms into 7d659c1 on p11-glue:master.

p11-kit/list-mechanisms.c Show resolved Hide resolved
p11-kit/list-mechanisms.c Outdated Show resolved Hide resolved
p11-kit/list-mechanisms.c Outdated Show resolved Hide resolved
@t184256 t184256 force-pushed the list-mechanisms branch 2 times, most recently from 2cd9dc2 to f82d700 Compare September 25, 2023 12:42
@t184256
Copy link
Contributor Author

t184256 commented Sep 25, 2023

addressed feedback, added a test against mock data, added printing token labels

I don't see how to reasonably use the printing API for what I'm doing, so I just hope mixing it with printfs is OK.

@t184256 t184256 marked this pull request as ready for review September 25, 2023 12:52
p11-kit/list-mechanisms.c Outdated Show resolved Hide resolved
0x80000002 (unknown): sign verify key-size=2048-2048
EOF

if ! "$abs_top_builddir"/p11-kit/p11-kit-testable list-mechanisms -q pkcs11: > list.out; then
Copy link
Member

Choose a reason for hiding this comment

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

This URL matches all tokens? I would rather limit it to the first match, as p11tool --list-mechanism does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This URL matches all tokens?

Yes.

I would rather limit it to the first match, as p11tool --list-mechanism does.

You mean, limit list-mechanisms subcommand to inspecting the first matching token? I'd disagree on that. First, I think it might introduce confusion in a scenario where the user accidentally matches several tokens. Second, AFAICS this behaviour won't be in line with the existing list-* subcommands that iterate over all matches.

Copy link
Member

@ueno ueno Sep 30, 2023

Choose a reason for hiding this comment

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

AFAICS this behaviour won't be in line with the existing list-* subcommands that iterate over all matches

Well, that's not the case:

  • p11-kit list-modules: doesn't take URL
  • p11-kit list-profiles: takes a token URL, uses first match only, because profiles are capabilities of a particular token
  • p11-kit list-objects: takes an object URL, returns all matches

A general guidance on implementing those commands is that each command should do one thing and do it well; if p11-kit list-mechanisms iterate over all matching tokens, it provides 2 functions: listing tokens and showing mechanisms supported by each token. That could be achieved by combining two commands: p11-kit list-tokens (to be implemented in #554) and p11-kit list-mechanisms, like:

for token in $(p11-kit list-tokens --only-uris); do
  p11-kit list-mechanisms $token
done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to stop after first match. Testing 3 scenarios now: "pkcs11:", specific existing and specific non-existing token. Maybe when we have list-tokens we should also test the iteration you're suggesting.

p11-kit/list-mechanisms.c Outdated Show resolved Hide resolved
@t184256 t184256 force-pushed the list-mechanisms branch 4 times, most recently from a7a704d to cf8826a Compare September 29, 2023 13:56
p11-kit/list-mechanisms.c Outdated Show resolved Hide resolved
p11-kit/list-mechanisms.c Outdated Show resolved Hide resolved
@t184256 t184256 force-pushed the list-mechanisms branch 2 times, most recently from 38850a0 to fce61d3 Compare October 2, 2023 12:06

p11_list_printer_init (&printer, stdout, 0);
p11_kit_iter_begin (iter, modules);
rv = p11_kit_iter_next (iter); // we will stop at the first token
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
rv = p11_kit_iter_next (iter); // we will stop at the first token
rv = p11_kit_iter_next (iter);
if (rv != CKR_OK) {
if (rv == CKR_CANCEL)
p11_message (_("no matching token"));
else
p11_message (_("failed to find token: %s"), p11_kit_strerror (rv));
goto cleanup;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

incorporated

Resolves: p11-glue#563
Signed-off-by: Alexander Sosedkin <[email protected]>
Copy link
Member

@ueno ueno left a comment

Choose a reason for hiding this comment

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

Thank you, looks good to me!

@ueno ueno merged commit f7a89e5 into p11-glue:master Oct 2, 2023
12 checks passed
@ZoltanFridrich ZoltanFridrich added this to the 0.25.1 milestone Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

p11-kit command: add means to list mechanisms a token supports
4 participants