Skip to content

Commit

Permalink
fix(sdk): return error when no embedded proof in requested credential (
Browse files Browse the repository at this point in the history
…#829)

Signed-off-by: Andrii Holovko <[email protected]>
  • Loading branch information
aholovko authored Nov 20, 2024
1 parent 71d5269 commit 31f1f51
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/wallet-sdk-gomobile/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/stretchr/testify v1.8.3
github.com/trustbloc/did-go v1.3.1-0.20241021165331-5721a3ff7396
github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88
github.com/trustbloc/vc-go v1.2.1-0.20241031140324-d25fb970e6f5
github.com/trustbloc/vc-go v1.2.1-0.20241119140508-59af0e10bdcc
github.com/trustbloc/wallet-sdk v0.0.0-00010101000000-000000000000
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/wallet-sdk-gomobile/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88 h1:k3KNf9tE4TBV
github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88/go.mod h1:OKOtsLbE6W5s4mpjWkvk8XEqcmt9vTgVmDNkHELpWO0=
github.com/trustbloc/sidetree-go v1.1.0 h1:ZNCtYTut5MHVXJR26FvOPSo8uCGDR0YTNeA155s/QIo=
github.com/trustbloc/sidetree-go v1.1.0/go.mod h1:IQ1iX/gLe/YL+M6kzenc5Oi14uzaYqfL7KgMyNuSGvI=
github.com/trustbloc/vc-go v1.2.1-0.20241031140324-d25fb970e6f5 h1:p3dmAih8yucca6pLMeRwjzHHcX1k5g4KbreH329doBw=
github.com/trustbloc/vc-go v1.2.1-0.20241031140324-d25fb970e6f5/go.mod h1:3/GbrzF7phN+SxBTZaUBS6VxnoxpXGBUjjk3Eg4ImUk=
github.com/trustbloc/vc-go v1.2.1-0.20241119140508-59af0e10bdcc h1:hw0PseUDqXeXTJV/yeHYBteiU3f8BMMGVE9GfozygZw=
github.com/trustbloc/vc-go v1.2.1-0.20241119140508-59af0e10bdcc/go.mod h1:3/GbrzF7phN+SxBTZaUBS6VxnoxpXGBUjjk3Eg4ImUk=
github.com/veraison/go-cose v1.1.1-0.20240126165338-2300d5c96dbd h1:QhdCHSW1/oosJbzBTEYLU6xcKxXbQzzqFnhCtW2UWbA=
github.com/veraison/go-cose v1.1.1-0.20240126165338-2300d5c96dbd/go.mod h1:D1wnviyjdmcF8AO5Y9kVGU6OGuvXUMGiE0Auo/fYRYo=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
Expand Down
5 changes: 4 additions & 1 deletion cmd/wallet-sdk-gomobile/verifiable/parsecredential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ var universityDegreeCredentialWithoutName string

func TestParse(t *testing.T) {
t.Run("Success - default options", func(t *testing.T) {
universityDegreeVC, err := verifiable.ParseCredential(universityDegreeCredential, nil)
opts := verifiable.NewOpts()
opts.DisableProofCheck()

universityDegreeVC, err := verifiable.ParseCredential(universityDegreeCredential, opts)
require.NoError(t, err)
require.Equal(t, "http://example.edu/credentials/1872", universityDegreeVC.VC.Contents().ID)
})
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/trustbloc/did-go v1.3.1-0.20241021165331-5721a3ff7396
github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88
github.com/trustbloc/sidetree-go v1.1.0
github.com/trustbloc/vc-go v1.2.1-0.20241031140324-d25fb970e6f5
github.com/trustbloc/vc-go v1.2.1-0.20241119140508-59af0e10bdcc
golang.org/x/oauth2 v0.13.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88 h1:k3KNf9tE4TBV
github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88/go.mod h1:OKOtsLbE6W5s4mpjWkvk8XEqcmt9vTgVmDNkHELpWO0=
github.com/trustbloc/sidetree-go v1.1.0 h1:ZNCtYTut5MHVXJR26FvOPSo8uCGDR0YTNeA155s/QIo=
github.com/trustbloc/sidetree-go v1.1.0/go.mod h1:IQ1iX/gLe/YL+M6kzenc5Oi14uzaYqfL7KgMyNuSGvI=
github.com/trustbloc/vc-go v1.2.1-0.20241031140324-d25fb970e6f5 h1:p3dmAih8yucca6pLMeRwjzHHcX1k5g4KbreH329doBw=
github.com/trustbloc/vc-go v1.2.1-0.20241031140324-d25fb970e6f5/go.mod h1:3/GbrzF7phN+SxBTZaUBS6VxnoxpXGBUjjk3Eg4ImUk=
github.com/trustbloc/vc-go v1.2.1-0.20241119140508-59af0e10bdcc h1:hw0PseUDqXeXTJV/yeHYBteiU3f8BMMGVE9GfozygZw=
github.com/trustbloc/vc-go v1.2.1-0.20241119140508-59af0e10bdcc/go.mod h1:3/GbrzF7phN+SxBTZaUBS6VxnoxpXGBUjjk3Eg4ImUk=
github.com/veraison/go-cose v1.1.1-0.20240126165338-2300d5c96dbd h1:QhdCHSW1/oosJbzBTEYLU6xcKxXbQzzqFnhCtW2UWbA=
github.com/veraison/go-cose v1.1.1-0.20240126165338-2300d5c96dbd/go.mod h1:D1wnviyjdmcF8AO5Y9kVGU6OGuvXUMGiE0Auo/fYRYo=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
Expand Down
43 changes: 42 additions & 1 deletion pkg/openid4ci/issuerinitiatedinteraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ var (
//go:embed testdata/sample_credential_response_batch.json
sampleCredentialResponseBatch []byte

//go:embed testdata/sample_credential_response_jsonld.json
sampleCredentialResponseJSONLD []byte

//go:embed testdata/sample_issuer_metadata.json
sampleIssuerMetadata string

Expand Down Expand Up @@ -1919,6 +1922,32 @@ func TestIssuerInitiatedInteraction_RequestCredential(t *testing.T) {
})
}

func TestIssuerInitiatedInteraction_RequestCredential_NoProofFound(t *testing.T) {
issuerServerHandler := &mockIssuerServerHandler{
t: t,
credentialResponse: sampleCredentialResponseJSONLD,
httpStatusCode: http.StatusOK,
}

server := httptest.NewServer(issuerServerHandler)
defer server.Close()

issuerServerHandler.issuerMetadata = strings.ReplaceAll(sampleIssuerMetadata, serverURLPlaceholder, server.URL)

interaction := newIssuerInitiatedInteraction(t, createCredentialOfferIssuanceURI(t, server.URL, false, true),
enableVCProofChecks())

credentials, err := interaction.RequestCredentialWithPreAuth(
&jwtSignerMock{
keyID: mockKeyID,
},
openid4ci.WithPIN("1234"),
)

require.ErrorContains(t, err, "proof not found")
require.Len(t, credentials, 0)
}

func TestIssuerInitiatedInteraction_GrantTypes(t *testing.T) {
issuerServerHandler := &mockIssuerServerHandler{
t: t,
Expand Down Expand Up @@ -2100,11 +2129,23 @@ func TestIssuerInitiatedInteraction_IssuerTrustInfo(t *testing.T) {
})
}

func newIssuerInitiatedInteraction(t *testing.T, requestURI string) *openid4ci.IssuerInitiatedInteraction {
type clientConfigOpt func(*openid4ci.ClientConfig)

func enableVCProofChecks() clientConfigOpt {
return func(config *openid4ci.ClientConfig) {
config.DisableVCProofChecks = false
}
}

func newIssuerInitiatedInteraction(t *testing.T, requestURI string, opts ...clientConfigOpt) *openid4ci.IssuerInitiatedInteraction {
t.Helper()

config := getTestClientConfig(t)

for _, opt := range opts {
opt(config)
}

interaction, err := openid4ci.NewIssuerInitiatedInteraction(requestURI, config)
require.NoError(t, err)
require.NotNil(t, interaction)
Expand Down
44 changes: 44 additions & 0 deletions pkg/openid4ci/testdata/sample_credential_response_jsonld.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"format": "ldp_vc",
"credential": {
"@context": [
"https://www.w3.org/ns/credentials/v2",
"https://www.w3.org/ns/credentials/examples/v2"
],
"id": "http://example.edu/credentials/1872",
"type": [
"VerifiableCredential",
"AlumniCredential"
],
"issuer": {
"id": "did:example:76e12ec712ebc6f1c221ebfeb1f",
"name": "Example University",
"image": "data:image/png;base64,iVBOR"
},
"validFrom": "2010-01-01T19:23:24Z",
"credentialSubject": {
"id": "did:example:ebfeb1f712ebc6f1c276e12ec21",
"alumniOf": {
"id": "did:example:c276e12ec21ebfeb1f712ebc6f1",
"name": [
{
"value": "Example University",
"lang": "en"
},
{
"value": "Exemple d'Université",
"lang": "fr"
}
]
}
},
"termsOfUse": {
"type": "TrustFrameworkPolicy",
"trustFramework": "Employment&Life",
"policyId": "https://policy.example/policies/125",
"legalBasis": "professional qualifications directive"
}
},
"c_nonce": "fGFF7UkhLa",
"c_nonce_expires_in": 86400
}
4 changes: 3 additions & 1 deletion pkg/openid4vp/openid4vp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,9 @@ func TestOpenID4VP_PresentCredential(t *testing.T) {
Fields: []*presexch.Field{{
Path: []string{"$.credentialSubject.taxResidency", "$.vc.credentialSubject.taxResidency"},
Filter: &presexch.Filter{
Type: &strType,
FilterItem: presexch.FilterItem{
Type: &strType,
},
},
}},
},
Expand Down
2 changes: 1 addition & 1 deletion test/integration/attestation/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/trustbloc/cmdutil-go v1.0.0
github.com/trustbloc/did-go v1.3.1-0.20241021165331-5721a3ff7396
github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88
github.com/trustbloc/vc-go v1.2.1-0.20241031140324-d25fb970e6f5
github.com/trustbloc/vc-go v1.2.1-0.20241119140508-59af0e10bdcc
github.com/trustbloc/wallet-sdk v0.0.0-00010101000000-000000000000
)

Expand Down
4 changes: 2 additions & 2 deletions test/integration/attestation/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ github.com/trustbloc/logutil-go v0.0.0-20221124174025-c46110e3ea42 h1:Mzg9wvEoUI
github.com/trustbloc/logutil-go v0.0.0-20221124174025-c46110e3ea42/go.mod h1:HRaXVV1caceumbDBwLO3ByiCcAc18KwrNvZ7JQBvDIQ=
github.com/trustbloc/sidetree-go v1.1.0 h1:ZNCtYTut5MHVXJR26FvOPSo8uCGDR0YTNeA155s/QIo=
github.com/trustbloc/sidetree-go v1.1.0/go.mod h1:IQ1iX/gLe/YL+M6kzenc5Oi14uzaYqfL7KgMyNuSGvI=
github.com/trustbloc/vc-go v1.2.1-0.20241031140324-d25fb970e6f5 h1:p3dmAih8yucca6pLMeRwjzHHcX1k5g4KbreH329doBw=
github.com/trustbloc/vc-go v1.2.1-0.20241031140324-d25fb970e6f5/go.mod h1:3/GbrzF7phN+SxBTZaUBS6VxnoxpXGBUjjk3Eg4ImUk=
github.com/trustbloc/vc-go v1.2.1-0.20241119140508-59af0e10bdcc h1:hw0PseUDqXeXTJV/yeHYBteiU3f8BMMGVE9GfozygZw=
github.com/trustbloc/vc-go v1.2.1-0.20241119140508-59af0e10bdcc/go.mod h1:3/GbrzF7phN+SxBTZaUBS6VxnoxpXGBUjjk3Eg4ImUk=
github.com/veraison/go-cose v1.1.1-0.20240126165338-2300d5c96dbd h1:QhdCHSW1/oosJbzBTEYLU6xcKxXbQzzqFnhCtW2UWbA=
github.com/veraison/go-cose v1.1.1-0.20240126165338-2300d5c96dbd/go.mod h1:D1wnviyjdmcF8AO5Y9kVGU6OGuvXUMGiE0Auo/fYRYo=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
Expand Down
2 changes: 1 addition & 1 deletion test/integration/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/trustbloc/cmdutil-go v0.0.0-20221125151303-09d42adcc811
github.com/trustbloc/did-go v1.3.1-0.20241021165331-5721a3ff7396
github.com/trustbloc/logutil-go v1.0.0-rc1
github.com/trustbloc/vc-go v1.2.1-0.20241031140324-d25fb970e6f5
github.com/trustbloc/vc-go v1.2.1-0.20241119140508-59af0e10bdcc
github.com/trustbloc/wallet-sdk v0.0.0-00010101000000-000000000000
github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-gomobile v0.0.0-00010101000000-000000000000
go.uber.org/zap v1.23.0
Expand Down
4 changes: 2 additions & 2 deletions test/integration/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ github.com/trustbloc/logutil-go v1.0.0-rc1 h1:rRJbvgQfrlUfyej+mY0nuQJymGqjRW4oZE
github.com/trustbloc/logutil-go v1.0.0-rc1/go.mod h1:JlxT0oZfNKgIlSNtgc001WEeDMxlnAvOM43gNm8DQVc=
github.com/trustbloc/sidetree-go v1.1.0 h1:ZNCtYTut5MHVXJR26FvOPSo8uCGDR0YTNeA155s/QIo=
github.com/trustbloc/sidetree-go v1.1.0/go.mod h1:IQ1iX/gLe/YL+M6kzenc5Oi14uzaYqfL7KgMyNuSGvI=
github.com/trustbloc/vc-go v1.2.1-0.20241031140324-d25fb970e6f5 h1:p3dmAih8yucca6pLMeRwjzHHcX1k5g4KbreH329doBw=
github.com/trustbloc/vc-go v1.2.1-0.20241031140324-d25fb970e6f5/go.mod h1:3/GbrzF7phN+SxBTZaUBS6VxnoxpXGBUjjk3Eg4ImUk=
github.com/trustbloc/vc-go v1.2.1-0.20241119140508-59af0e10bdcc h1:hw0PseUDqXeXTJV/yeHYBteiU3f8BMMGVE9GfozygZw=
github.com/trustbloc/vc-go v1.2.1-0.20241119140508-59af0e10bdcc/go.mod h1:3/GbrzF7phN+SxBTZaUBS6VxnoxpXGBUjjk3Eg4ImUk=
github.com/veraison/go-cose v1.1.1-0.20240126165338-2300d5c96dbd h1:QhdCHSW1/oosJbzBTEYLU6xcKxXbQzzqFnhCtW2UWbA=
github.com/veraison/go-cose v1.1.1-0.20240126165338-2300d5c96dbd/go.mod h1:D1wnviyjdmcF8AO5Y9kVGU6OGuvXUMGiE0Auo/fYRYo=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
Expand Down
2 changes: 1 addition & 1 deletion test/integration/trustregistry/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ require (
github.com/trustbloc/bbs-signature-go v1.0.2 // indirect
github.com/trustbloc/did-go v1.3.1-0.20241021165331-5721a3ff7396 // indirect
github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88 // indirect
github.com/trustbloc/vc-go v1.2.1-0.20241031140324-d25fb970e6f5 // indirect
github.com/trustbloc/vc-go v1.2.1-0.20241119140508-59af0e10bdcc // indirect
github.com/veraison/go-cose v1.1.1-0.20240126165338-2300d5c96dbd // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
Expand Down
4 changes: 2 additions & 2 deletions test/integration/trustregistry/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ github.com/trustbloc/did-go v1.3.1-0.20241021165331-5721a3ff7396 h1:z9x5gLgDeUtc
github.com/trustbloc/did-go v1.3.1-0.20241021165331-5721a3ff7396/go.mod h1:L5m4TVlPwe7VN5FRrANPMg6EJN8wIlthC8CvossDZVI=
github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88 h1:k3KNf9tE4TBVdpEtImmZIbUWFZRoL/96GPR7FSqCr9k=
github.com/trustbloc/kms-go v1.1.3-0.20241001141623-8d9510c6bb88/go.mod h1:OKOtsLbE6W5s4mpjWkvk8XEqcmt9vTgVmDNkHELpWO0=
github.com/trustbloc/vc-go v1.2.1-0.20241031140324-d25fb970e6f5 h1:p3dmAih8yucca6pLMeRwjzHHcX1k5g4KbreH329doBw=
github.com/trustbloc/vc-go v1.2.1-0.20241031140324-d25fb970e6f5/go.mod h1:3/GbrzF7phN+SxBTZaUBS6VxnoxpXGBUjjk3Eg4ImUk=
github.com/trustbloc/vc-go v1.2.1-0.20241119140508-59af0e10bdcc h1:hw0PseUDqXeXTJV/yeHYBteiU3f8BMMGVE9GfozygZw=
github.com/trustbloc/vc-go v1.2.1-0.20241119140508-59af0e10bdcc/go.mod h1:3/GbrzF7phN+SxBTZaUBS6VxnoxpXGBUjjk3Eg4ImUk=
github.com/veraison/go-cose v1.1.1-0.20240126165338-2300d5c96dbd h1:QhdCHSW1/oosJbzBTEYLU6xcKxXbQzzqFnhCtW2UWbA=
github.com/veraison/go-cose v1.1.1-0.20240126165338-2300d5c96dbd/go.mod h1:D1wnviyjdmcF8AO5Y9kVGU6OGuvXUMGiE0Auo/fYRYo=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
Expand Down

0 comments on commit 31f1f51

Please sign in to comment.