Skip to content

Commit

Permalink
fix: Implemented temporary cryptoServiceCallback verify function
Browse files Browse the repository at this point in the history
  • Loading branch information
zoemaas committed Oct 22, 2024
1 parent 56ce96f commit 6fe01f4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 42 deletions.

This file was deleted.

38 changes: 33 additions & 5 deletions packages/oidf-client/src/agent/OIDFClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ import {
ResolveTrustChainArgs,
ResolveTrustChainCallbackResult
} from "../types/IOIDFClient";
import * as jose from 'jose'
import {
com
} from "../../../../../OpenID-Federation/build/js/packages/openid-federation-modules-openid-federation-client";
import {schema} from "../index";
import FederationClient = com.sphereon.oid.fed.client.FederationClient;
import {JWK, JWTVerifyOptions} from "jose";

export const oidfClientMethods: Array<string> = [
'resolveTrustChain',
Expand All @@ -33,13 +35,39 @@ export class OIDFClient implements IAgentPlugin {
if (cryptoServiceCallback) {
this.oidfClient = new FederationClient(null, cryptoServiceCallback)
} else {
// FIXME pass in the actual verification function
// FIXME pass in the verification function of the JWSService,
this.oidfClient = new FederationClient(
null, {
q3t: (jwt: string, key: any): Promise<boolean> => {
console.log(`${jwt}:${key} -> Custom callback function reached`)
return Promise.resolve(true)
}
q3t: async (jwt: string, key: any): Promise<boolean> => {
// FIXME For some reason the keys is the key object are messed up
const jwk: JWK = {
kty: key.e3s_1,
kid: key.f3s_1,
crv: key.g3s_1,
x: key.h3s_1,
y: key.i3s_1,
n: key.j3s_1,
e: key.k3s_1,
alg: key.l3s_1,
use: key.m3s_1,
x5u: key.n3s_1,
x5c: key.o3s_1,
x5t: key.p3s_1,
'x5t#S256': key.q3s_1,
}

const publicKey = await jose.importJWK(jwk)

const now = new Date()
const past = now.setDate(now.getDate() - 60)

const options: JWTVerifyOptions = {
currentDate: new Date(past)
}

const result = await jose.jwtVerify(jwt, publicKey, options)
return result !== undefined
}
})
}
}
Expand Down

0 comments on commit 6fe01f4

Please sign in to comment.