-
Notifications
You must be signed in to change notification settings - Fork 220
fix: json ld fixes and aca-py interop fixes #1865
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
base: main
Are you sure you want to change the base?
Changes from 9 commits
eee749f
34f1f3e
2c9e53b
29f7d73
9eeb5c8
187cf4e
b641f1a
5a15fb4
ee6403c
cd1befd
53d496b
888909d
61ab47b
41d4180
4493bb9
79bd5ce
aedc9b3
d9940a2
2a10e10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -523,58 +523,56 @@ export class DidExchangeProtocol { | |
if (message instanceof DidExchangeResponseMessage) { | ||
const didRotateAttachment = message.didRotate | ||
|
||
if (!didRotateAttachment) { | ||
throw new DidExchangeProblemReportError('DID Rotate attachment is missing.', { | ||
problemCode: DidExchangeProblemReportReason.ResponseNotAccepted, | ||
}) | ||
} | ||
|
||
const jws = didRotateAttachment.data.jws | ||
if (didRotateAttachment) { | ||
const jws = didRotateAttachment.data.jws | ||
|
||
if (!jws) { | ||
throw new DidExchangeProblemReportError('DID Rotate signature is missing.', { | ||
problemCode: DidExchangeProblemReportReason.ResponseNotAccepted, | ||
}) | ||
} | ||
if (!jws) { | ||
throw new DidExchangeProblemReportError('DID Rotate signature is missing.', { | ||
problemCode: DidExchangeProblemReportReason.ResponseNotAccepted, | ||
}) | ||
} | ||
|
||
if (!didRotateAttachment.data.base64) { | ||
throw new CredoError('DID Rotate attachment is missing base64 property for signed did.') | ||
} | ||
if (!didRotateAttachment.data.base64) { | ||
throw new CredoError('DID Rotate attachment is missing base64 property for signed did.') | ||
} | ||
|
||
// JWS payload must be base64url encoded | ||
const base64UrlPayload = base64ToBase64URL(didRotateAttachment.data.base64) | ||
const signedDid = TypedArrayEncoder.fromBase64(base64UrlPayload).toString() | ||
// JWS payload must be base64url encoded | ||
const base64UrlPayload = base64ToBase64URL(didRotateAttachment.data.base64) | ||
const signedDid = TypedArrayEncoder.fromBase64(base64UrlPayload).toString() | ||
|
||
if (signedDid !== message.did) { | ||
throw new CredoError( | ||
`DID Rotate attachment's did ${message.did} does not correspond to message did ${message.did}` | ||
) | ||
} | ||
if (signedDid !== message.did) { | ||
throw new CredoError( | ||
`DID Rotate attachment's did ${message.did} does not correspond to message did ${message.did}` | ||
) | ||
} | ||
|
||
const { isValid, signerKeys } = await this.jwsService.verifyJws(agentContext, { | ||
jws: { | ||
...jws, | ||
payload: base64UrlPayload, | ||
}, | ||
jwkResolver: ({ jws: { header } }) => { | ||
if (typeof header.kid !== 'string' || !isDid(header.kid, 'key')) { | ||
throw new CredoError('JWS header kid must be a did:key DID.') | ||
} | ||
const { isValid, signerKeys } = await this.jwsService.verifyJws(agentContext, { | ||
jws: { | ||
...jws, | ||
payload: base64UrlPayload, | ||
}, | ||
jwkResolver: ({ jws: { header } }) => { | ||
if (typeof header.kid !== 'string' || !isDid(header.kid, 'key')) { | ||
throw new CredoError('JWS header kid must be a did:key DID.') | ||
} | ||
|
||
const didKey = DidKey.fromDid(header.kid) | ||
return getJwkFromKey(didKey.key) | ||
}, | ||
}) | ||
const didKey = DidKey.fromDid(header.kid) | ||
return getJwkFromKey(didKey.key) | ||
}, | ||
}) | ||
|
||
if (!isValid || !signerKeys.every((key) => invitationKeysBase58?.includes(key.publicKeyBase58))) { | ||
throw new DidExchangeProblemReportError( | ||
`DID Rotate signature is invalid. isValid: ${isValid} signerKeys: ${JSON.stringify( | ||
signerKeys | ||
)} invitationKeys:${JSON.stringify(invitationKeysBase58)}`, | ||
{ | ||
problemCode: DidExchangeProblemReportReason.ResponseNotAccepted, | ||
} | ||
) | ||
if (!isValid || !signerKeys.every((key) => invitationKeysBase58?.includes(key.publicKeyBase58))) { | ||
throw new DidExchangeProblemReportError( | ||
`DID Rotate signature is invalid. isValid: ${isValid} signerKeys: ${JSON.stringify( | ||
signerKeys | ||
)} invitationKeys:${JSON.stringify(invitationKeysBase58)}`, | ||
{ | ||
problemCode: DidExchangeProblemReportReason.ResponseNotAccepted, | ||
} | ||
) | ||
} | ||
} else { | ||
this.logger.warn(`Document does not contain didRotate`) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this change is correct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test case I ran into was agents or mediators using did:peer:2 without the intention of doing a did rotate or There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the did is not rotated from the invitation we can indeed ignore it. But if the did is rotated, not doing this check means the connection can be hijacked. I could send a response even though you created the invitation, because we don't require a signature from the invitation did. If the did is the same, then we don't have that issue and i'm ok with not requiring did rotate. But the current code doesn't take this into consideration There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be confused but the warn only happens if the attachment is not present, the else block is for the if statement on line 526 where it checks if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The check that is now in place always allows didRotate to not be present, meaning we could just remove the check. So we need to be more specific in checking when didRotate needs to be present: when you rotate your did from the invitation. Even though the Aries RFC mentions it's optional, it's super important for security to do this check. did_rotate was added specifically for this reason, and it's only optional to not introduce a breaking change in the RFC. Before did rotate was introduced, it was basically not possible to rotate a did from the invitation if you were not using diddoc~attach and sign it. If the did is rotated from the invitation, either a signed |
||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { CredoError } from '../../../../error' | |
import { getAlternativeDidsForNumAlgo4Did } from './peerDidNumAlgo4' | ||
|
||
const PEER_DID_REGEX = new RegExp( | ||
'^did:peer:(([01](z)([1-9a-km-zA-HJ-NP-Z]{5,200}))|(2((.[AEVID](z)([1-9a-km-zA-HJ-NP-Z]{5,200}))+(.(S)[0-9a-zA-Z=]*)?))|([4](z[1-9a-km-zA-HJ-NP-Z]{46})(:z[1-9a-km-zA-HJ-NP-Z]{6,}){0,1}))$' | ||
'^did:peer:(([01](z)([1-9a-km-zA-HJ-NP-Z]{5,200}))|(2((.[AEVID](z)([1-9a-km-zA-HJ-NP-Z]{5,200}))+(.(S)[0-9a-zA-Z=]*)*))|([4](z[1-9a-km-zA-HJ-NP-Z]{46})(:z[1-9a-km-zA-HJ-NP-Z]{6,}){0,1}))$' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this change in regex mean? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This regex is specifically changed for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have an example did:peer so I can add a test covering this? |
||
) | ||
|
||
export function isValidPeerDid(did: string): boolean { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ import { createWalletKeyPairClass } from '../../../crypto/WalletKeyPair' | |
import { CredoError } from '../../../error' | ||
import { injectable } from '../../../plugins' | ||
import { asArray, JsonTransformer } from '../../../utils' | ||
import { VerificationMethod } from '../../dids' | ||
import { DidsApi, VerificationMethod } from '../../dids' | ||
import { getKeyFromVerificationMethod } from '../../dids/domain/key-type' | ||
import { W3cCredentialsModuleConfig } from '../W3cCredentialsModuleConfig' | ||
import { w3cDate } from '../util' | ||
|
@@ -339,12 +339,23 @@ export class W3cJsonLdCredentialService { | |
agentContext: AgentContext, | ||
verificationMethod: string | ||
): Promise<Key> { | ||
const documentLoader = this.w3cCredentialsModuleConfig.documentLoader(agentContext) | ||
const verificationMethodObject = await documentLoader(verificationMethod) | ||
const verificationMethodClass = JsonTransformer.fromJSON(verificationMethodObject.document, VerificationMethod) | ||
|
||
const key = getKeyFromVerificationMethod(verificationMethodClass) | ||
return key | ||
if (!verificationMethod.startsWith('did:')) { | ||
const documentLoader = this.w3cCredentialsModuleConfig.documentLoader(agentContext) | ||
const verificationMethodObject = await documentLoader(verificationMethod) | ||
const verificationMethodClass = JsonTransformer.fromJSON(verificationMethodObject.document, VerificationMethod) | ||
|
||
const key = getKeyFromVerificationMethod(verificationMethodClass) | ||
return key | ||
} else { | ||
const [did, keyid] = verificationMethod.split('#') | ||
const didsApi = agentContext.dependencyManager.resolve(DidsApi) | ||
const doc = await didsApi.resolve(did) | ||
if (doc.didDocument) { | ||
const verificationMethodClass = doc.didDocument.dereferenceKey(keyid) | ||
return getKeyFromVerificationMethod(verificationMethodClass) | ||
} | ||
throw new CredoError(`Could not resolve verification method with id ${verificationMethod}`) | ||
} | ||
Comment on lines
+342
to
+358
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? The document loader should be able to load did documents, so I'm not sure if we want to bypass it here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The document loader would resolve the did but not return the full did Document with the verification information applied. This might have changed since my testing because I added this while testing with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry, could you elaborate a bit further? What do you mean with "not return the full did Document with the verification information applied"? What does it return? |
||
} | ||
|
||
private getSignatureSuitesForCredential(agentContext: AgentContext, credential: W3cJsonLdVerifiableCredential) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.