-
Notifications
You must be signed in to change notification settings - Fork 204
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
feat: openid4vp-mdoc #2080
Merged
TimoGlastra
merged 6 commits into
openwallet-foundation:main
from
auer-martin:openid4vp-mdoc
Nov 1, 2024
Merged
feat: openid4vp-mdoc #2080
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e26d833
feat: openid4vp mdoc integration
auer-martin 9044e81
Create beige-adults-compete.md
TimoGlastra 3ab4c12
feat: address feedback
auer-martin 912f311
Merge remote-tracking branch 'origin/openid4vp-mdoc' into test7
auer-martin 3ff4af7
fix: types
auer-martin 2bcedab
Merge branch 'main' into openid4vp-mdoc
TimoGlastra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@credo-ts/core": patch | ||
"@credo-ts/openid4vc": patch | ||
--- | ||
|
||
feat: mdoc device response and presentation over oid4vp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,15 @@ import type { PresentationDefinition } from '@protokoll/mdoc-client' | |
import type { InputDescriptorV2 } from '@sphereon/pex-models' | ||
|
||
import { | ||
limitDisclosureToInputDescriptor as mdocLimitDisclosureToId, | ||
limitDisclosureToInputDescriptor as mdocLimitDisclosureToInputDescriptor, | ||
COSEKey, | ||
DeviceResponse, | ||
MDoc, | ||
parseIssuerSigned, | ||
Verifier, | ||
MDocStatus, | ||
cborEncode, | ||
parseDeviceResponse, | ||
} from '@protokoll/mdoc-client' | ||
|
||
import { CredoError } from '../../error' | ||
|
@@ -26,7 +27,29 @@ import { getMdocContext } from './MdocContext' | |
import { MdocError } from './MdocError' | ||
|
||
export class MdocDeviceResponse { | ||
public constructor() {} | ||
private constructor(public base64Url: string, public documents: Mdoc[]) {} | ||
|
||
public static fromBase64Url(base64Url: string) { | ||
const parsed = parseDeviceResponse(TypedArrayEncoder.fromBase64(base64Url)) | ||
if (parsed.status !== MDocStatus.OK) { | ||
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. no extra error provided in parsed? 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. No, not really atm |
||
throw new MdocError(`Parsing Mdoc Device Response failed.`) | ||
} | ||
|
||
const documents = parsed.documents.map((doc) => { | ||
const prepared = doc.prepare() | ||
const docType = prepared.get('docType') as string | ||
const issuerSigned = cborEncode(prepared.get('issuerSigned')) | ||
const deviceSigned = cborEncode(prepared.get('deviceSigned')) | ||
|
||
return Mdoc.fromDeviceSignedDocument( | ||
TypedArrayEncoder.toBase64URL(issuerSigned), | ||
TypedArrayEncoder.toBase64URL(deviceSigned), | ||
docType | ||
) | ||
}) | ||
|
||
return new MdocDeviceResponse(base64Url, documents) | ||
} | ||
|
||
private static assertMdocInputDescriptor(inputDescriptor: InputDescriptorV2) { | ||
if (!inputDescriptor.format || !inputDescriptor.format.mso_mdoc) { | ||
|
@@ -113,7 +136,18 @@ export class MdocDeviceResponse { | |
|
||
const inputDescriptor = this.assertMdocInputDescriptor(options.inputDescriptor) | ||
const _mdoc = parseIssuerSigned(TypedArrayEncoder.fromBase64(mdoc.base64Url), mdoc.docType) | ||
return mdocLimitDisclosureToId({ mdoc: _mdoc, inputDescriptor }) | ||
|
||
const disclosure = mdocLimitDisclosureToInputDescriptor(_mdoc, inputDescriptor) | ||
const disclosedPayloadAsRecord = Object.fromEntries( | ||
Object.entries(disclosure).map(([namespace, issuerSignedItem]) => { | ||
return [ | ||
namespace, | ||
Object.fromEntries(issuerSignedItem.map((item) => [item.elementIdentifier, item.elementValue])), | ||
] | ||
}) | ||
) | ||
|
||
return disclosedPayloadAsRecord | ||
} | ||
|
||
public static async createOpenId4VpDeviceResponse( | ||
|
@@ -160,32 +194,30 @@ export class MdocDeviceResponse { | |
} | ||
} | ||
|
||
public static async verify(agentContext: AgentContext, options: MdocDeviceResponseVerifyOptions) { | ||
public async verify(agentContext: AgentContext, options: Omit<MdocDeviceResponseVerifyOptions, 'deviceResponse'>) { | ||
const verifier = new Verifier() | ||
const mdocContext = getMdocContext(agentContext) | ||
|
||
let trustedCerts: [string, ...string[]] | undefined | ||
if (options?.trustedCertificates) { | ||
trustedCerts = options.trustedCertificates | ||
} else if (options?.verificationContext) { | ||
agentContext.dependencyManager.resolve(X509ModuleConfig).getTrustedCertificatesForVerification | ||
trustedCerts = await agentContext.dependencyManager | ||
.resolve(X509ModuleConfig) | ||
.getTrustedCertificatesForVerification?.(agentContext, options.verificationContext) | ||
} else { | ||
trustedCerts = agentContext.dependencyManager.resolve(X509ModuleConfig).trustedCertificates | ||
} | ||
const x509ModuleConfig = agentContext.dependencyManager.resolve(X509ModuleConfig) | ||
const getTrustedCertificatesForVerification = x509ModuleConfig.getTrustedCertificatesForVerification | ||
|
||
if (!trustedCerts) { | ||
const trustedCertificates = | ||
options.trustedCertificates ?? | ||
(await getTrustedCertificatesForVerification?.(agentContext, options.verificationContext)) ?? | ||
x509ModuleConfig?.trustedCertificates | ||
|
||
if (!trustedCertificates) { | ||
throw new MdocError('No trusted certificates found. Cannot verify mdoc.') | ||
} | ||
|
||
const result = await verifier.verifyDeviceResponse( | ||
{ | ||
encodedDeviceResponse: TypedArrayEncoder.fromBase64(options.deviceResponse), | ||
encodedDeviceResponse: TypedArrayEncoder.fromBase64(this.base64Url), | ||
//ephemeralReaderKey: options.verifierKey ? getJwkFromKey(options.verifierKey).toJson() : undefined, | ||
encodedSessionTranscript: DeviceResponse.calculateSessionTranscriptForOID4VP(options.sessionTranscriptOptions), | ||
trustedCertificates: trustedCerts.map((cert) => X509Certificate.fromEncodedCertificate(cert).rawCertificate), | ||
trustedCertificates: trustedCertificates.map( | ||
(cert) => X509Certificate.fromEncodedCertificate(cert).rawCertificate | ||
), | ||
now: options.now, | ||
}, | ||
mdocContext | ||
|
@@ -199,17 +231,6 @@ export class MdocDeviceResponse { | |
throw new MdocError('Device response verification failed. An unknown error occurred.') | ||
} | ||
|
||
return result.documents.map((doc) => { | ||
const prepared = doc.prepare() | ||
const docType = prepared.get('docType') as string | ||
const issuerSigned = cborEncode(prepared.get('issuerSigned')) | ||
const deviceSigned = cborEncode(prepared.get('deviceSigned')) | ||
|
||
return Mdoc.fromIssuerSignedDocument( | ||
TypedArrayEncoder.toBase64URL(issuerSigned), | ||
TypedArrayEncoder.toBase64URL(deviceSigned), | ||
docType | ||
) | ||
}) | ||
return this.documents | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't understand this? mdoc also handle mdoc selecting now right? And what if the mdoc is not available, it should'nt be info the nright?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we set it to error below when we also check if all the mdoc credentials are available.