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

Implementation of arbitrary batched tokens #46

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

thibmeu
Copy link

@thibmeu thibmeu commented Nov 24, 2024

This is an implementation of draft 3 of arbitrary batched tokens as defined in ietf-draft-privacypass-batched-tokens.

The implementation is short, test is much longer. The goal is not to be exhaustive, the draft suggest only tokens type 1 and token type 2 would be supported first.

For review, I am looking for:

  1. how to handle multiple types within the "arbitrary" batched array. Go does not work well with the generic approach proposed in the draft
  2. how to correctly expose internals of other tokens type to arbitrary batched tokens, for testing purposes. Specifically, the test vector require blinds to be exposed, which is not possible at the moment.

thibmeu and others added 6 commits November 24, 2024 18:11
Not a new token type, but a new token serialisations.
Based off of
ietf-wg-privacypass/ietf-draft-privacypass-batched-tokens#13
Generate new tests vectors for arbitrary batched tokens
Have both the public and private key when generating batch tokens
In addition, ignore fields which are null in the output json
Test is generated and verified
Arbitrary batched tokens need dictionaries.
@thibmeu
Copy link
Author

thibmeu commented Nov 24, 2024

Copy link
Collaborator

@armfazh armfazh left a comment

Choose a reason for hiding this comment

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

  1. how to handle multiple types within the "arbitrary" batched array. Go does not work well with the generic approach proposed in the draft

For simplicity, you need to start using Go interfaces. Go generics may help, but later, once you have common interfaces for the types/API you want to generalize.

  1. how to correctly expose internals of other tokens type to arbitrary batched tokens, for testing purposes. Specifically, the test vector require blinds to be exposed, which is not possible at the moment.

here I see two options:
Like in JS/TS implementation, we mock the random number generator, so you can inject the blinding values without exposing internals.
In go, I usually write:

  • a private method/function (those with underscore names)
    createRequest(blind []byte)
  • a public function.
    CreateRequest() { 
      createRequest(rand.Reader) 
    } ```

Thus, tests are written to check only internal functions. In each case, you have to refactor the current code.

return nil, fmt.Errorf("invalid Tokens encoding")
}

respTokens := make([][]byte, 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
respTokens := make([][]byte, 0)
var respTokens [][]byte

casted, ok := tokenRequest.(*typeF91A.BatchedPrivateTokenRequest)
if !ok || casted.Type() != typeF91A.BatchedPrivateTokenType {
return nil, fmt.Errorf("invalid token request type")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

add a default case to catch unsupported types.

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.

2 participants