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

FindObjects bool is always false #26

Closed
tadukurow opened this issue Mar 31, 2016 · 9 comments
Closed

FindObjects bool is always false #26

tadukurow opened this issue Mar 31, 2016 · 9 comments

Comments

@tadukurow
Copy link
Contributor

The bool on FindObjects which according to the comment indicates if the resultset is larger than max, always returns false. FindObjects comment.

The softHSMv1 findObjects implementation returns the number of results read until max. So it will never be larger than max.

The oasis docs specify the following

C_FindObjects continues a search for token and session objects that match a template, obtaining additional object handles. hSession is the session’s handle; phObject points to the location that receives the list (array) of additional object handles; ulMaxObjectCount is the maximum number of object handles to be returned; pulObjectCount points to the location that receives the actual number of object handles returned.

So it seems the softHSM implementation is correct.

@miekg miekg closed this as completed Feb 8, 2018
@dmjones
Copy link
Contributor

dmjones commented Jul 27, 2018

This definitely looks broken to me.

It is impossible to determine whether C_FindObjects would have returned more values than max without calling it again. Only when C_FindObjects returns zero can you be sure the token has no more objects to return.

I think a breaking change is required to remove this boolean response value. It is misleading and I can't see how it can ever be accurate. It's already tripped me up on some code I wrote to work with SoftHSM2.

In a pathological case, you cannot even be sure the token has run out of objects if ulCount < maz. The token is under no obligation to always fill the available space. Its only obligation is to return 0 if no more objects exist.

The workaround for now is to ignore this boolean value and keep calling until no objects are returned.

@dmjones
Copy link
Contributor

dmjones commented Aug 1, 2018

@miekg Can we reopen this?

@mtharp
Copy link
Collaborator

mtharp commented Aug 1, 2018

Your interpretation of the spec seems correct to me. It's unclear whether changing the code would be a good idea since implementations may be depending on it never returning true (see this example in the pkcs11 tree: https://github.com/miekg/pkcs11/blob/master/p11/session.go#L75)

The safest fix would be updating the comment to mark it as deprecated and describing what the correct use should be.

@mtharp mtharp reopened this Aug 1, 2018
@miekg
Copy link
Owner

miekg commented Aug 1, 2018 via email

mtharp added a commit to mtharp/pkcs11 that referenced this issue Aug 2, 2018
The previous behavior is not consistent with the specification; the only
way to detect the end of the search is when no objects are returned. In
the future this field should be removed but in the meantime there is no
need to force a breaking change.

Also updates p11.Session.FindObjects to no longer use the deprecated
field, and to handle arbitrarily large result sets.
@mtharp
Copy link
Collaborator

mtharp commented Aug 2, 2018

The existing signature is sufficient to use the function correctly, you just ignore the boolean and stop searching when the result is empty. So there's not really any benefit to changing it until there are other breaking changes to bundle it with. I opened a pull request to update the docs and fix the p11 version of the function to not use it.

@dmjones
Copy link
Contributor

dmjones commented Aug 2, 2018

I'd opt for a breaking change. Removing a return value will break builds, so people won't miss this happening. People who are ignoring the return value are minimally inconvenienced. People with broken code that assumes it works correctly will have more work to do, but they had buggy code anyway.

I fear people will miss documentation changes.

@miekg
Copy link
Owner

miekg commented Aug 2, 2018 via email

@mtharp
Copy link
Collaborator

mtharp commented Aug 2, 2018

Should #55 be addressed at the same time then?

Ideally there should be a tag before the breaking change so that people using dependency management can pin it until they can update their code.

@miekg
Copy link
Owner

miekg commented Aug 3, 2018

If we're going to break things, its better to group those, so yes?

releases is a separate issues: now with vgo we should actually start doing this.

miekg pushed a commit that referenced this issue Aug 16, 2018
The previous behavior is not consistent with the specification; the only
way to detect the end of the search is when no objects are returned. In
the future this field should be removed but in the meantime there is no
need to force a breaking change.

Also updates p11.Session.FindObjects to no longer use the deprecated
field, and to handle arbitrarily large result sets.
@miekg miekg closed this as completed Jan 4, 2022
JeremyRand pushed a commit to JeremyRand/pkcs11 that referenced this issue Oct 13, 2022
JeremyRand pushed a commit to JeremyRand/pkcs11 that referenced this issue Oct 13, 2022
JeremyRand pushed a commit to namecoin/pkcs11 that referenced this issue Nov 3, 2022
JeremyRand pushed a commit to namecoin/pkcs11 that referenced this issue Nov 3, 2022
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

No branches or pull requests

4 participants