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

validate blinded tokens submitted for tlv2 #2158

Merged
merged 6 commits into from
Oct 20, 2023
Merged
Changes from 1 commit
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
18 changes: 17 additions & 1 deletion services/skus/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,28 @@ func (s *Service) CreateOrderItemCredentials(ctx context.Context, orderID uuid.U
return errors.New("order item does not exist for order")
}

if orderItem.CredentialType == "single-use" {
if orderItem.CredentialType == singleUse {
if len(blindedCreds) > orderItem.Quantity {
return errors.New("submitted more blinded creds than quantity of order item")
}
}

if orderItem.CredentialType == timeLimitedV2 {
// check order "numPerInterval" from metadata and multiply it by the buffer added to offset
numPerInterval, ok := order.Metadata["numPerInterval"].(int)
husobee marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
return errors.New("bad order: numPerInterval not set in order metadata")
husobee marked this conversation as resolved.
Show resolved Hide resolved
}
numIntervals, ok := order.Metadata["numIntervals"].(int)
husobee marked this conversation as resolved.
Show resolved Hide resolved
if !ok {
return errors.New("bad order: numIntervals not set in order metadata")
husobee marked this conversation as resolved.
Show resolved Hide resolved
}

if len(blindedCreds) > numPerInterval*numIntervals {
husobee marked this conversation as resolved.
Show resolved Hide resolved
return errors.New("submitted more blinded creds than allowed for order")
husobee marked this conversation as resolved.
Show resolved Hide resolved
}
}

issuerID, err := encodeIssuerID(order.MerchantID, orderItem.SKU)
if err != nil {
return errorutils.Wrap(err, "error encoding issuer name")
Expand Down