Skip to content

Commit 675b5b2

Browse files
authored
fix: allow to pass skew in seconds for wallet attestation (#204)
Signed-off-by: Mirko Mollik <mirko.mollik@eudi.sprind.org>
1 parent 9f132c4 commit 675b5b2

4 files changed

Lines changed: 37 additions & 8 deletions

File tree

.changeset/nine-spiders-cheat.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@openid4vc/openid4vp": minor
3+
"@openid4vc/oauth2": minor
4+
---
5+
6+
Pass allowedSkewInSeconds to verifyClientAttestation and verifyAttestationJWT functions, and deprecate clockSkewSec in favor of allowedSkewInSeconds for better naming consistency.

packages/oauth2/src/client-attestation/client-attestation-pop.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ export interface VerifyClientAttestationPopJwtOptions {
8888
*/
8989
now?: Date
9090

91+
/**
92+
* Allowed skew time in seconds for validity of token. Used for `exp` and `nbf`
93+
* verification.
94+
*
95+
* @default 0
96+
*/
97+
allowedSkewInSeconds?: number
98+
9199
/**
92100
* Callbacks used for verifying client attestation pop jwt.
93101
*/
@@ -130,6 +138,7 @@ export async function verifyClientAttestationPopJwt(options: VerifyClientAttesta
130138
compact: options.clientAttestationPopJwt,
131139
verifyJwtCallback: options.callbacks.verifyJwt,
132140
errorMessage: 'client attestation pop jwt verification failed',
141+
allowedSkewInSeconds: options.allowedSkewInSeconds,
133142
})
134143

135144
return {

packages/oauth2/src/client-attestation/client-attestation.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ export interface VerifyClientAttestationJwtOptions {
2727
*/
2828
now?: Date
2929

30+
/**
31+
* Allowed skew time in seconds for validity of token. Used for `exp` and `nbf`
32+
* verification.
33+
*
34+
* @default 0
35+
*/
36+
allowedSkewInSeconds?: number
37+
3038
/**
3139
* Callbacks used for verifying client attestation pop jwt.
3240
*/
@@ -167,6 +175,14 @@ export interface VerifyClientAttestationOptions {
167175
* Date to use for expiration. If not provided current date will be used.
168176
*/
169177
now?: Date
178+
179+
/**
180+
* Allowed skew time in seconds for validity of token. Used for `exp` and `nbf`
181+
* verification.
182+
*
183+
* @default 0
184+
*/
185+
allowedSkewInSeconds?: number
170186
}
171187

172188
export async function verifyClientAttestation({
@@ -175,12 +191,14 @@ export async function verifyClientAttestation({
175191
clientAttestationPopJwt,
176192
callbacks,
177193
now,
194+
allowedSkewInSeconds,
178195
}: VerifyClientAttestationOptions) {
179196
try {
180197
const clientAttestation = await verifyClientAttestationJwt({
181198
callbacks,
182199
clientAttestationJwt,
183200
now,
201+
allowedSkewInSeconds,
184202
})
185203

186204
const clientAttestationPop = await verifyClientAttestationPopJwt({
@@ -189,6 +207,7 @@ export async function verifyClientAttestation({
189207
clientAttestation,
190208
clientAttestationPopJwt,
191209
now,
210+
allowedSkewInSeconds,
192211
})
193212

194213
return {

packages/openid4vp/src/client-identifier-prefix/validate-verifier-attestation-jwt.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,10 @@ export async function verifyAttestation(options: VerifyAttestationOptions) {
4545
export interface VerifyAttestationJwtOptions {
4646
attestationJwt: string
4747
clientId: string
48-
clockSkewSec?: number
48+
allowedSkewInSeconds?: number
4949
callbacks: Pick<CallbackContext, 'verifyJwt'>
5050
}
51-
export async function verifyAttestationJWT(options: {
52-
attestationJwt: string
53-
clientId: string
54-
clockSkewSec?: number
55-
callbacks: Pick<CallbackContext, 'verifyJwt'>
56-
}) {
51+
export async function verifyAttestationJWT(options: VerifyAttestationJwtOptions) {
5752
const errors = []
5853

5954
const { header, payload } = decodeJwt({
@@ -70,7 +65,7 @@ export async function verifyAttestationJWT(options: {
7065
verifyJwtCallback: options.callbacks.verifyJwt,
7166
now: new Date(),
7267
expectedSubject: options.clientId,
73-
allowedSkewInSeconds: options.clockSkewSec || 300,
68+
allowedSkewInSeconds: options.allowedSkewInSeconds,
7469
requiredClaims: ['iss', 'sub', 'exp', 'cnf'],
7570
})
7671

0 commit comments

Comments
 (0)