Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
signer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gaia-X
Trust Services API
signer
Commits
397dd48c
Commit
397dd48c
authored
2 years ago
by
Lyuben Penkovski
Browse files
Options
Downloads
Plain Diff
Merge branch '16-bug-with-proof-verification' into 'main'
Enable strict validation when creating proofs on VC and VP Closes
#16
See merge request
!18
parents
2c96b2fd
f3fcc069
No related branches found
Tags
v1.0.2
Tags containing commit
1 merge request
!18
Enable strict validation when creating proofs on VC and VP
Pipeline
#69742
passed
1 year ago
Stage: test
Stage: build
Stage: manifest
Changes
2
Pipelines
4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
internal/service/signer/service.go
+18
-4
18 additions, 4 deletions
internal/service/signer/service.go
internal/service/signer/service_test.go
+5
-4
5 additions, 4 deletions
internal/service/signer/service_test.go
with
23 additions
and
8 deletions
internal/service/signer/service.go
+
18
−
4
View file @
397dd48c
...
...
@@ -143,7 +143,12 @@ func (s *Service) GetKeys(ctx context.Context) (res []*signer.VerificationMethod
func
(
s
*
Service
)
CredentialProof
(
ctx
context
.
Context
,
req
*
signer
.
CredentialProofRequest
)
(
interface
{},
error
)
{
logger
:=
s
.
logger
.
With
(
zap
.
String
(
"operation"
,
"credentialProof"
))
vc
,
err
:=
verifiable
.
ParseCredential
(
req
.
Credential
,
verifiable
.
WithJSONLDDocumentLoader
(
s
.
docLoader
))
vc
,
err
:=
verifiable
.
ParseCredential
(
req
.
Credential
,
verifiable
.
WithJSONLDDocumentLoader
(
s
.
docLoader
),
verifiable
.
WithStrictValidation
(),
verifiable
.
WithJSONLDValidation
(),
)
if
err
!=
nil
{
logger
.
Error
(
"error parsing verifiable credential"
,
zap
.
Error
(
err
))
if
strings
.
Contains
(
err
.
Error
(),
"credential type of unknown structure"
)
{
...
...
@@ -186,7 +191,11 @@ func (s *Service) CredentialProof(ctx context.Context, req *signer.CredentialPro
func
(
s
*
Service
)
PresentationProof
(
ctx
context
.
Context
,
req
*
signer
.
PresentationProofRequest
)
(
interface
{},
error
)
{
logger
:=
s
.
logger
.
With
(
zap
.
String
(
"operation"
,
"presentationProof"
))
vp
,
err
:=
verifiable
.
ParsePresentation
(
req
.
Presentation
,
verifiable
.
WithPresJSONLDDocumentLoader
(
s
.
docLoader
))
vp
,
err
:=
verifiable
.
ParsePresentation
(
req
.
Presentation
,
verifiable
.
WithPresJSONLDDocumentLoader
(
s
.
docLoader
),
verifiable
.
WithPresStrictValidation
(),
)
if
err
!=
nil
{
logger
.
Error
(
"error parsing verifiable presentation"
,
zap
.
Error
(
err
))
if
strings
.
Contains
(
err
.
Error
(),
"verifiable presentation is not valid"
)
{
...
...
@@ -227,6 +236,8 @@ func (s *Service) PresentationProof(ctx context.Context, req *signer.Presentatio
// VerifyCredential verifies the proof of a Verifiable Credential.
func
(
s
*
Service
)
VerifyCredential
(
ctx
context
.
Context
,
req
*
signer
.
VerifyCredentialRequest
)
(
*
signer
.
VerifyResult
,
error
)
{
logger
:=
s
.
logger
.
With
(
zap
.
String
(
"operation"
,
"verifyCredential"
))
// only DID:WEB and DID:KEY methods are supported currently
webVDR
:=
web
.
New
()
keyVDR
:=
key
.
New
()
...
...
@@ -245,9 +256,10 @@ func (s *Service) VerifyCredential(ctx context.Context, req *signer.VerifyCreden
),
verifiable
.
WithJSONLDDocumentLoader
(
s
.
docLoader
),
verifiable
.
WithStrictValidation
(),
verifiable
.
WithJSONLDValidation
(),
)
if
err
!=
nil
{
s
.
logger
.
Error
(
"error verifying credential"
,
zap
.
Error
(
err
))
logger
.
Error
(
"error verifying credential"
,
zap
.
Error
(
err
))
return
nil
,
errors
.
New
(
errors
.
BadRequest
,
err
.
Error
())
}
...
...
@@ -256,6 +268,8 @@ func (s *Service) VerifyCredential(ctx context.Context, req *signer.VerifyCreden
// VerifyPresentation verifies the proof of a Verifiable Presentation.
func
(
s
*
Service
)
VerifyPresentation
(
ctx
context
.
Context
,
req
*
signer
.
VerifyPresentationRequest
)
(
*
signer
.
VerifyResult
,
error
)
{
logger
:=
s
.
logger
.
With
(
zap
.
String
(
"operation"
,
"verifyPresentation"
))
// only DID:WEB and DID:KEY methods are supported currently
webVDR
:=
web
.
New
()
keyVDR
:=
key
.
New
()
...
...
@@ -276,7 +290,7 @@ func (s *Service) VerifyPresentation(ctx context.Context, req *signer.VerifyPres
verifiable
.
WithPresStrictValidation
(),
)
if
err
!=
nil
{
s
.
logger
.
Error
(
"error verifying presentation"
,
zap
.
Error
(
err
))
logger
.
Error
(
"error verifying presentation"
,
zap
.
Error
(
err
))
return
nil
,
errors
.
New
(
errors
.
BadRequest
,
err
.
Error
())
}
...
...
This diff is collapsed.
Click to expand it.
internal/service/signer/service_test.go
+
5
−
4
View file @
397dd48c
...
...
@@ -198,7 +198,7 @@ func TestService_CredentialProof(t *testing.T) {
Credential
:
[]
byte
(
invalidCredentialContexts
),
},
errkind
:
errors
.
BadRequest
,
errtext
:
"
v
er
ifiable credential is not valid
"
,
errtext
:
"
D
er
eferencing a URL did not result in a valid JSON-LD context
"
,
},
{
name
:
"non-existing credential contexts"
,
...
...
@@ -297,7 +297,7 @@ func TestService_CredentialProof(t *testing.T) {
// expected attributes the VC must have
contexts
:
[]
string
{
"https://www.w3.org/2018/credentials/v1"
},
subject
:
[]
verifiable
.
Subject
{{
CustomFields
:
verifiable
.
CustomFields
{
"hello"
:
"world"
}}},
subject
:
[]
verifiable
.
Subject
{{
ID
:
""
,
CustomFields
:
verifiable
.
CustomFields
{
"
@context"
:
"https://schema.org"
,
"testdata"
:
map
[
string
]
interface
{}{
"
hello"
:
"world"
}}}
}
,
issuer
:
verifiable
.
Issuer
{
ID
:
"https://example.com"
},
types
:
[]
string
{
verifiable
.
VCType
},
proofPurpose
:
"assertionMethod"
,
...
...
@@ -330,7 +330,7 @@ func TestService_CredentialProof(t *testing.T) {
// expected attributes the VC must have
contexts
:
[]
string
{
"https://www.w3.org/2018/credentials/v1"
},
subject
:
[]
verifiable
.
Subject
{{
CustomFields
:
verifiable
.
CustomFields
{
"hello"
:
"world"
}}},
subject
:
[]
verifiable
.
Subject
{{
ID
:
""
,
CustomFields
:
verifiable
.
CustomFields
{
"
@context"
:
"https://schema.org"
,
"testdata"
:
map
[
string
]
interface
{}{
"
hello"
:
"world"
}}}
}
,
issuer
:
verifiable
.
Issuer
{
ID
:
"https://example.com"
},
types
:
[]
string
{
verifiable
.
VCType
},
proofPurpose
:
"assertionMethod"
,
...
...
@@ -581,7 +581,8 @@ var validCredential = `{
"https://www.w3.org/2018/credentials/v1"
],
"credentialSubject": {
"hello": "world"
"@context":"https://schema.org",
"testdata": {"hello":"world"}
},
"issuanceDate": "2022-06-02T17:24:05.032533+03:00",
"issuer": "https://example.com",
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment