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

chore: add qr-store link validation #795

Merged
merged 1 commit into from
Sep 20, 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
8 changes: 8 additions & 0 deletions api/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,8 @@ paths:
type: object
'400':
$ref: '#/components/responses/400'
'410':
$ref: '#/components/responses/410'
'404':
$ref: '#/components/responses/404'
'500':
Expand Down Expand Up @@ -2416,6 +2418,12 @@ components:
application/json:
schema:
$ref: '#/components/schemas/GenericErrorMessage'
'410':
description: 'Gone'
content:
application/json:
schema:
$ref: '#/components/schemas/GenericErrorMessage'
'422':
description: 'Unprocessable Content'
content:
Expand Down
14 changes: 14 additions & 0 deletions internal/api/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions internal/api/qrcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (s *Server) GetQrFromStore(ctx context.Context, request GetQrFromStoreReque
}

link, err := s.linkService.GetByID(ctx, *issuerDID, *request.Params.Id, s.cfg.ServerUrl)
if err := s.linkService.Validate(ctx, link); err != nil {
log.Error(ctx, "validating link", "err", err, "link id", *request.Params.Id)
return GetQrFromStore410JSONResponse{N410JSONResponse{err.Error()}}, nil
}

if link.AuthorizationRequestMessage == nil {
log.Error(ctx, "qr store. Finding qr", "err", err, "id", *request.Params.Id)
Expand Down
1 change: 1 addition & 0 deletions internal/core/ports/link_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ type LinkService interface {
CreateQRCode(ctx context.Context, issuerDID w3c.DID, linkID uuid.UUID, serverURL string) (*CreateQRCodeResponse, error)
IssueOrFetchClaim(ctx context.Context, issuerDID w3c.DID, userDID w3c.DID, linkID uuid.UUID, hostURL string) (*protocol.CredentialsOfferMessage, error)
ProcessCallBack(ctx context.Context, issuerDID w3c.DID, message string, linkID uuid.UUID, hostURL string) (*protocol.CredentialsOfferMessage, error)
Validate(ctx context.Context, link *domain.Link) error
}
10 changes: 6 additions & 4 deletions internal/core/services/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (ls *Link) CreateQRCode(ctx context.Context, issuerDID w3c.DID, linkID uuid
return nil, err
}

err = ls.validate(ctx, link)
err = ls.Validate(ctx, link)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -248,8 +248,8 @@ func (ls *Link) IssueOrFetchClaim(ctx context.Context, issuerDID w3c.DID, userDI
return nil, err
}

if err := ls.validate(ctx, link); err != nil {
log.Error(ctx, "cannot validate the link", "err", err)
if err := ls.Validate(ctx, link); err != nil {
log.Error(ctx, "cannot Validate the link", "err", err)
return nil, err
}

Expand Down Expand Up @@ -373,7 +373,9 @@ func (ls *Link) ProcessCallBack(ctx context.Context, issuerID w3c.DID, message s
return offer, nil
}

func (ls *Link) validate(ctx context.Context, link *domain.Link) error {
// Validate - validate the link
// It checks if the link is active, not expired and has not exceeded the maximum number of claims
func (ls *Link) Validate(ctx context.Context, link *domain.Link) error {
if link.ValidUntil != nil && time.Now().UTC().After(*link.ValidUntil) {
log.Debug(ctx, "cannot issue a credential for an expired link")
return ErrLinkAlreadyExpired
Expand Down
Loading