forked from openwallet-foundation/credo-ts
-
Notifications
You must be signed in to change notification settings - Fork 4
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: OpenID Federation for the verifier <-> holder #27
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b723485
feat: working version
Tommylans bcaed4d
feat: Littlebit of a cleanup for the verifier
Tommylans 1743fb1
fix: typescript error
Tommylans dcd810d
feat: Processed feedback and used the right keys for the verifier
Tommylans cb6d70f
feat: Added more logging and added unhappy tests
Tommylans b06c546
chore: Made some things more logic
Tommylans 06999df
feat: Holder side api for getting more context information
Tommylans 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
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
108 changes: 108 additions & 0 deletions
108
packages/openid4vc/src/openid4vc-issuer/router/federationEndpoint.ts
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,108 @@ | ||
import type { OpenId4VcIssuanceRequest } from './requestContext' | ||
import type { Buffer } from '@credo-ts/core' | ||
import type { Router, Response } from 'express' | ||
|
||
import { Key, getJwkFromKey, KeyType } from '@credo-ts/core' | ||
import { createEntityConfiguration } from '@openid-federation/core' | ||
|
||
import { getRequestContext, sendErrorResponse } from '../../shared/router' | ||
import { OpenId4VcIssuerService } from '../OpenId4VcIssuerService' | ||
|
||
// TODO: It's also possible that the issuer and the verifier can have the same openid-federation endpoint. In that case we need to combine them. | ||
|
||
export function configureFederationEndpoint(router: Router) { | ||
// TODO: this whole result needs to be cached and the ttl should be the expires of this node | ||
|
||
router.get('/.well-known/openid-federation', async (request: OpenId4VcIssuanceRequest, response: Response, next) => { | ||
const { agentContext, issuer } = getRequestContext(request) | ||
const openId4VcIssuerService = agentContext.dependencyManager.resolve(OpenId4VcIssuerService) | ||
|
||
try { | ||
// TODO: Should be only created once per issuer and be used between instances | ||
const federationKey = await agentContext.wallet.createKey({ | ||
keyType: KeyType.Ed25519, | ||
}) | ||
|
||
const issuerMetadata = openId4VcIssuerService.getIssuerMetadata(agentContext, issuer) | ||
|
||
const now = new Date() | ||
const expires = new Date(now.getTime() + 1000 * 60 * 60 * 24) // 1 day from now | ||
|
||
// TODO: We need to generate a key and always use that for the entity configuration | ||
|
||
const jwk = getJwkFromKey(federationKey) | ||
|
||
const kid = federationKey.fingerprint | ||
const alg = jwk.supportedSignatureAlgorithms[0] | ||
|
||
const issuerDisplay = issuerMetadata.issuerDisplay?.[0] | ||
|
||
const accessTokenSigningKey = Key.fromFingerprint(issuer.accessTokenPublicKeyFingerprint) | ||
|
||
const entityConfiguration = await createEntityConfiguration({ | ||
claims: { | ||
sub: issuerMetadata.issuerUrl, | ||
iss: issuerMetadata.issuerUrl, | ||
iat: now, | ||
exp: expires, | ||
jwks: { | ||
keys: [{ kid, alg, ...jwk.toJson() }], | ||
}, | ||
metadata: { | ||
federation_entity: issuerDisplay | ||
? { | ||
organization_name: issuerDisplay.name, | ||
logo_uri: issuerDisplay.logo?.url, | ||
} | ||
: undefined, | ||
openid_provider: { | ||
// TODO: The type isn't correct yet down the line so that needs to be updated before | ||
// credential_issuer: issuerMetadata.issuerUrl, | ||
// token_endpoint: issuerMetadata.tokenEndpoint, | ||
// credential_endpoint: issuerMetadata.credentialEndpoint, | ||
// authorization_server: issuerMetadata.authorizationServer, | ||
// authorization_servers: issuerMetadata.authorizationServer | ||
// ? [issuerMetadata.authorizationServer] | ||
// : undefined, | ||
// credentials_supported: issuerMetadata.credentialsSupported, | ||
// credential_configurations_supported: issuerMetadata.credentialConfigurationsSupported, | ||
// display: issuerMetadata.issuerDisplay, | ||
// dpop_signing_alg_values_supported: issuerMetadata.dpopSigningAlgValuesSupported, | ||
|
||
client_registration_types_supported: ['automatic'], | ||
jwks: { | ||
keys: [ | ||
{ | ||
// TODO: Not 100% sure if this is the right key that we want to expose here or a different one | ||
kid: accessTokenSigningKey.fingerprint, | ||
...getJwkFromKey(accessTokenSigningKey).toJson(), | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
header: { | ||
kid, | ||
alg, | ||
typ: 'entity-statement+jwt', | ||
}, | ||
signJwtCallback: ({ toBeSigned }) => | ||
agentContext.wallet.sign({ | ||
data: toBeSigned as Buffer, | ||
key: federationKey, | ||
}), | ||
}) | ||
|
||
response.writeHead(200, { 'Content-Type': 'application/entity-statement+jwt' }).end(entityConfiguration) | ||
} catch (error) { | ||
agentContext.config.logger.error('Failed to create entity configuration', { | ||
error, | ||
}) | ||
sendErrorResponse(response, agentContext.config.logger, 500, 'invalid_request', error) | ||
} | ||
|
||
// NOTE: if we don't call next, the agentContext session handler will NOT be called | ||
next() | ||
}) | ||
} |
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.
This is ok for now, but was also discussing with NF and i think we probably need to have some more control over 'trusted' entities in Credo.
So extend the x509 callbacks with global 'verificationContext` and you can either provide it to the call, or we use the global static config, or we use the dynamic callback. And you can either provide trusted federations, trusted x509s, or trusted dids / did methods.
(just rambling here 😄 )
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.
Yeah, I think we should think a bit more about this of what a good structure would be.