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

chore: check vct scheme to choose hardware/software key #133

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/funke/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"prebuild": "APP_VARIANT=development expo prebuild --no-install"
},
"dependencies": {
"@animo-id/expo-ausweis-sdk": "0.0.1-alpha.5",
"@animo-id/expo-ausweis-sdk": "0.0.1-alpha.6",
"@animo-id/expo-secure-environment": "0.1.0-alpha.1",
"@credo-ts/core": "*",
"@expo-google-fonts/open-sans": "^0.2.3",
Expand Down
11 changes: 11 additions & 0 deletions apps/funke/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ const animoFunkeRelyingPartyCertificate =
'MIIBAzCBq6ADAgECAhArxq0w60RTDK4WY9HzgcvBMAoGCCqGSM49BAMCMAAwIBcNNzAwMTAxMDAwMDAwWhgPMjI4NjExMjAxNzQ2NDBaMAAwOTATBgcqhkjOPQIBBggqhkjOPQMBBwMiAALcD1XzKepFxWMAOqV+ln1fybBt7DRO5CV0f9A6mRp2xaMlMCMwIQYDVR0RBBowGIYWaHR0cHM6Ly9mdW5rZS5hbmltby5pZDAKBggqhkjOPQQDAgNHADBEAiAfvGG6sqrvzIMWYpJB5VLloo9f51loYXSkKxJIOztlNwIgLLSvEl0Dmp5vtj2buZ2nXQ2RBKxiLbc5eYGeMeoUnjk='

export const trustedX509Certificates = [bdrPidIssuerCertificate, animoFunkeRelyingPartyCertificate]

// https://gitlab.opencode.de/bmi/eudi-wallet/eidas-2.0-architekturkonzept/-/blob/main/architecture-proposal.md#pid-contents
const sdJwtVcVcts = ['https://example.bmi.bund.de/credential/pid/1.0', 'urn:eu.europa.ec.eudi:pid:1']

// TODO
const msoMdocNamespaces = ['org.iso.18013.5.1.mDL']

export const pidSchemes = {
sdJwtVcVcts,
msoMdocNamespaces,
}
19 changes: 11 additions & 8 deletions apps/funke/src/use-cases/ReceivePidUseCase.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import {
AusweisAuthFlow,
type AusweisAuthFlowOptions,
addMessageListener,
sendCommand,
} from '@animo-id/expo-ausweis-sdk'
import { AusweisAuthFlow, type AusweisAuthFlowOptions } from '@animo-id/expo-ausweis-sdk'
import type { AppAgent } from '@funke/agent'
import { pidSchemes } from '@funke/constants'
import {
type OpenId4VciRequestTokenResponse,
type OpenId4VciResolvedAuthorizationRequest,
Expand Down Expand Up @@ -155,6 +151,7 @@ export class ReceivePidUseCase {
resolvedCredentialOffer: this.resolvedCredentialOffer,
credentialConfigurationIdToRequest,
clientId: ReceivePidUseCase.CLIENT_ID,
pidSchemes,
})

// TODO: add error handling everywhere to set state to error
Expand Down Expand Up @@ -199,7 +196,10 @@ export class ReceivePidUseCase {
agent: this.options.agent,
})

this.assertState({ expectedState: 'acquire-access-token', newState: 'retrieve-credential' })
this.assertState({
expectedState: 'acquire-access-token',
newState: 'retrieve-credential',
})
} catch (error) {
this.handleError()
throw error
Expand All @@ -209,7 +209,10 @@ export class ReceivePidUseCase {
private assertState({
expectedState,
newState,
}: { expectedState: ReceivePidUseCase['currentState']; newState?: ReceivePidUseCase['currentState'] }) {
}: {
expectedState: ReceivePidUseCase['currentState']
newState?: ReceivePidUseCase['currentState']
}) {
if (this.currentState !== expectedState) {
throw new Error(`Expected state to be ${expectedState}. Found ${this.currentState}`)
}
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"@credo-ts/openid4vc": "0.5.10-alpha-20240805102402",
"@credo-ts/question-answer": "0.5.10-alpha-20240805102402",
"@credo-ts/react-hooks": "0.6.1",
"@credo-ts/react-native": "0.5.10-alpha-20240805102402"
"@credo-ts/react-native": "0.5.10-alpha-20240805102402",

"@animo-id/expo-secure-environment": "0.1.0-alpha.1"
},
"patchedDependencies": {
"@credo-ts/[email protected]": "patches/@[email protected]",
Expand Down
43 changes: 23 additions & 20 deletions packages/agent/src/invitation/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ export const receiveCredentialFromOpenId4VciOffer = async ({
credentialConfigurationIdToRequest,
accessToken,
clientId,
pidSchemes,
}: {
agent: EitherAgent
resolvedCredentialOffer: OpenId4VciResolvedCredentialOffer
credentialConfigurationIdToRequest?: string
clientId?: string
pidSchemes?: { sdJwtVcVcts: Array<string>; msoMdocNamespaces: Array<string> }

// TODO: cNonce should maybe be provided separately (multiple calls can have different c_nonce values)
accessToken: OpenId4VciRequestTokenResponse
Expand Down Expand Up @@ -182,6 +184,7 @@ export const receiveCredentialFromOpenId4VciOffer = async ({
supportsAllDidMethods,
supportsJwk,
credentialFormat,
supportedCredentialId,
}) => {
// First, we try to pick a did method
// Prefer did:jwk, otherwise use did:key, otherwise use undefined
Expand All @@ -199,26 +202,26 @@ export const receiveCredentialFromOpenId4VciOffer = async ({
didMethod = 'key'
}

let key: Key | undefined = undefined

// For P-256 we first try secure enclave
if (keyType === KeyType.P256) {
key = await agent.wallet
.createKey({
keyType,
keyBackend: KeyBackend.SecureElement,
})
.catch((e) => {
agent.config.logger.warn('Could not create a key in the secure element', e as Record<string, unknown>)
return agent.wallet.createKey({
keyType,
})
})
} else {
key = await agent.wallet.createKey({
keyType,
})
}
const offeredCredentialConfiguration = supportedCredentialId
? resolvedCredentialOffer.offeredCredentialConfigurations[supportedCredentialId]
: undefined

const shouldKeyBeHardwareBackedForMsoMdoc = false
// offeredCredentialConfiguration?.format === "mso_mdoc" &&
// pidSchemes?.msoMdocNamespaces.includes(
// offeredCredentialConfiguration.namespace
// );
const shouldKeyBeHardwareBackedForSdJwtVc =
offeredCredentialConfiguration?.format === 'vc+sd-jwt' &&
pidSchemes?.sdJwtVcVcts.includes(offeredCredentialConfiguration.vct)

// TODO: add mso-mdoc config from above
const shouldKeyBeHardwareBacked = shouldKeyBeHardwareBackedForSdJwtVc || shouldKeyBeHardwareBackedForMsoMdoc

const key = await agent.wallet.createKey({
keyType,
keyBackend: shouldKeyBeHardwareBacked ? KeyBackend.SecureElement : KeyBackend.Software,
})

if (didMethod) {
const didResult = await agent.dids.create<JwkDidCreateOptions | KeyDidCreateOptions>({
Expand Down
35 changes: 10 additions & 25 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.