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

fix(credential-w3c): correct verification of credentials given as objects with jwt proofs #1071

Merged
merged 6 commits into from
Nov 23, 2022

Conversation

nickreynolds
Copy link
Contributor

@nickreynolds nickreynolds commented Nov 22, 2022

What issue is this PR fixing

fixes #1070

What is being changed

Update the verifyCredential function to check the other fields present in the credential object, to ensure they match what's in the JWT. Previously, only the credential.proof.jwt itself was verified.

Quality

Check all that apply:

  • I want these changes to be integrated
  • I successfully ran yarn, yarn build, yarn test, yarn test:browser locally.
  • I allow my PR to be updated by the reviewers (to speed up the review process).
  • I added unit tests.
  • I added integration tests.
  • I did not add automated tests because _________, and I am aware that a PR without tests will likely get rejected.

@nickreynolds nickreynolds changed the title Nickreynolds/verify jwt fix(credential-w3c): correct verification of credentials given as objects with jwt proofs Nov 22, 2022
@codecov
Copy link

codecov bot commented Nov 22, 2022

Codecov Report

Merging #1071 (07c88f0) into next (125bf42) will decrease coverage by 0.22%.
The diff coverage is 78.63%.

❗ Current head 07c88f0 differs from pull request most recent head a550c58. Consider uploading reports for the commit a550c58 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #1071      +/-   ##
==========================================
- Coverage   80.25%   80.02%   -0.23%     
==========================================
  Files         118      127       +9     
  Lines        4056     4606     +550     
  Branches      875      986     +111     
==========================================
+ Hits         3255     3686     +431     
- Misses        798      916     +118     
- Partials        3        4       +1     

Copy link
Member

@mirceanis mirceanis left a comment

Choose a reason for hiding this comment

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

Some tiny nitpicks to fix first but a great solution to a thorny issue about credential representation!

@@ -19,6 +19,7 @@
"@veramo/key-manager": "^4.1.1",
"@veramo/kms-local": "^4.1.1",
"base64url": "^3.0.1",
"canonicalize": "^1.0.8",
Copy link
Member

Choose a reason for hiding this comment

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

I think this dependency should be declared in the @veramo/credential-w3c package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mirceanis I just had noticed that did-provider-ion used this dependency but didn't declare it explicitly. I also added it in credential-w3c package

Copy link
Member

Choose a reason for hiding this comment

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

You're right. I hadn't noticed 👓

@@ -285,6 +288,20 @@ export class CredentialPlugin implements IAgentPlugin {
},
})
verifiedCredential = verificationResult.verifiableCredential

// if credential was presented with other fields, make sure those fields match what's in the JWT
if (!(typeof credential === 'string')) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (!(typeof credential === 'string')) {
if (typeof credential !== 'string') {

nitpicking, but it makes it easier to see the !

@@ -101,7 +190,8 @@ describe('credential-w3c full flow', () => {
expect(response.verified).toBe(true)
})

it.only('fails the verification of an expired credential', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

great catch!

import { LdDefaultContexts } from '../../../credential-ld/src/ld-default-contexts'
import { VeramoEd25519Signature2018 } from '../../../credential-ld/src/suites/Ed25519Signature2018'
import { VeramoEcdsaSecp256k1RecoverySignature2020 } from '../../../credential-ld/src/suites/EcdsaSecp256k1RecoverySignature2020'
import { VerifiableCredential } from '@veramo/core'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
import { VerifiableCredential } from '@veramo/core'
import { VerifiableCredential } from '../../../core/src/'

We have to use relative paths in tests to test against local source code instead of the packages from NPM

expect(verifyResult.verified).toBeFalsy()
})

// uncomment when we support `@vocab` in `@context`
Copy link
Member

Choose a reason for hiding this comment

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

this should be its own issue

Copy link
Member

Choose a reason for hiding this comment

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

and now it is: #1073

Copy link
Member

@mirceanis mirceanis left a comment

Choose a reason for hiding this comment

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

wonderful!

@@ -19,6 +19,7 @@
"@veramo/key-manager": "^4.1.1",
"@veramo/kms-local": "^4.1.1",
"base64url": "^3.0.1",
"canonicalize": "^1.0.8",
Copy link
Member

Choose a reason for hiding this comment

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

You're right. I hadn't noticed 👓

@nickreynolds nickreynolds merged commit b0d75e9 into next Nov 23, 2022
@nickreynolds nickreynolds deleted the nickreynolds/verify-jwt branch November 23, 2022 15:09
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.

Credentials of type Object with jwt proofType have incomplete verification
2 participants