Skip to content
Open
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ This file was started retroactively on 2026-07-03 at v0.4.0; entries for

### Breaking

- **`sd_jwt_vc::verify` takes `VerifyOptions`.** The final argument is required to set the
clock-skew leeway and verifier audience. A present `aud` must name that audience, or the
token is refused; a token with `aud` is refused when no audience is configured. **Migration:**
append `VerifyOptions::new()` to an existing call to retain default verification for
credentials without `aud`, and use `.for_audience(...)` for credentials that carry it. (#693)

- **Signing and publishing take a `KeyBackend`, not a `KeyStore`.** `jws::sign`,
`jws::sign_typed`, `jws::verify`, `build_did_document`, `build_issuer_metadata`,
`sd_jwt_vc::issue` and `sign_access_credential` take `&dyn KeyBackend`, and
Expand Down Expand Up @@ -217,6 +223,10 @@ This file was started retroactively on 2026-07-03 at v0.4.0; entries for

### Added

- **Configurable clock-skew leeway for JWT, COSE, and SD-JWT temporal verification.**
`VerifyOptions::with_leeway(seconds)` defaults to zero, is capped at five minutes, and
applies equally to `exp` and `nbf`. (#693)
Comment on lines +226 to +228

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Required argument lacks migration note

sd_jwt_vc::verify gains a required sixth argument, but this entry lists only the added feature. The versioning policy requires every breaking change under Breaking with a migration note. Add that entry and tell existing callers to append VerifyOptions::new() to keep the previous behavior. This repository requirement must be satisfied before merging.

File Used: docs/governance/VERSIONING.md (source)

Prompt To Fix With AI
This is a comment left during a code review.
Path: CHANGELOG.md
Line: 220-222

Comment:
**Required argument lacks migration note**

`sd_jwt_vc::verify` gains a required sixth argument, but this entry lists only the added feature. The versioning policy requires every breaking change under `Breaking` with a migration note. Add that entry and tell existing callers to append `VerifyOptions::new()` to keep the previous behavior. This repository requirement must be satisfied before merging.

**File Used:** `docs/governance/VERSIONING.md` ([source](https://github.com/odal-node/dpp-core/blob/e9b2a33c10442f5bf725df9f9159b1b55fcd4f9a/docs/governance/VERSIONING.md))

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code


- **`TransferChain::from_value`: a stored chain read with its refusal as a value.** It applies
the check `Deserialize` applies, and returns `ChainReadError`. `Refused` holds
`TransferError::InvalidChain`, which names the passport and the record that breaks the
Expand Down
13 changes: 12 additions & 1 deletion benches/src/sd_jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use criterion::{BenchmarkId, Criterion, criterion_group, criterion_main};
use dpp_crypto::sd_jwt::{SdJwt, conceal, conceal_elements};
use dpp_domain::access::ProductGroupAccessPolicy;
use dpp_domain::{Passport, ProductGroup};
use dpp_vc::jose::VerifyOptions;
use dpp_vc::sd_jwt_vc::{Issuance, issue, vct_for, verify};
use serde_json::{Map, Value, json};

Expand Down Expand Up @@ -82,7 +83,17 @@ fn credential(c: &mut Criterion) {
let public_key = store.load_key(KEY_ID).unwrap().public_key();

c.bench_function("sd_jwt_vc_verify_battery", |b| {
b.iter(|| verify(&serialised, &public_key, &vct, now, None).unwrap());
b.iter(|| {
verify(
&serialised,
&public_key,
&vct,
now,
None,
VerifyOptions::new(),
)
.unwrap()
});
});

// The wire format on its own, without the signature check.
Expand Down
7 changes: 5 additions & 2 deletions crates/dpp-tests/tests/jws_crit_rejection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use dpp_rules::bundle::{
};
use dpp_tests::fixtures::make_subject;
use dpp_vc::credential::authenticate_access_credential;
use dpp_vc::jose::VerifyOptions;
use dpp_vc::sd_jwt_vc::{Issuance, issue, verify};
use dpp_vc::{
CredentialBuilder, CredentialRole, LocalIdentityService, SD_JWT_VC_TYP, SdJwtVcError,
Expand Down Expand Up @@ -248,7 +249,8 @@ fn an_sd_jwt_vc_with_crit_is_refused() {
&key,
&vct,
now,
None
None,
VerifyOptions::new(),
)
.is_ok(),
"control: the same credential without crit must verify"
Expand All @@ -259,7 +261,8 @@ fn an_sd_jwt_vc_with_crit_is_refused() {
&key,
&vct,
now,
None
None,
VerifyOptions::new(),
),
Err(SdJwtVcError::BadSignature)
));
Expand Down
3 changes: 2 additions & 1 deletion crates/dpp-tests/tests/sdjwt_vc_oracle_corpus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ use dpp_tests::fixtures::{
passport_with, schema_compat_fixture as fixture_for, schema_for,
with_restricted_envelope_members, with_restricted_members,
};
use dpp_vc::jose::VerifyOptions;
use dpp_vc::sd_jwt_vc::{Issuance, PASSPORT_CLAIM, SdJwtVcError, issue, vct_for, verify};
use serde_json::{Map, Number, Value, json};

Expand Down Expand Up @@ -191,7 +192,7 @@ fn verify_under(
policy: Option<&KeyBindingPolicy>,
) -> Result<Map<String, Value>, SdJwtVcError> {
match ed25519_key(public_key_b64) {
Some(key) => verify(token, &key, vct, now, policy),
Some(key) => verify(token, &key, vct, now, policy, VerifyOptions::new()),
None => Err(SdJwtVcError::BadSignature),
}
}
Expand Down
9 changes: 5 additions & 4 deletions crates/dpp-vc/src/jose/cose_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ pub(super) const PRESENTATION_COSE_TYP: &str = "vp+cose";
/// header", and §1 says a recipient "MUST NOT use the information in the CWT Claims header
/// parameter beyond the integrity protection or authentication afforded", so one in the
/// unprotected header is refused by the COSE layer. The claims are applied as the same JWT
/// claims are in [`verify_credential`](super::verify_credential): `exp` must be later than a
/// `now` and `nbf` not later, with no leeway, and neither is read without a `now`; an `aud`
/// is accepted only when it names the audience the caller identifies as (RFC 7519 §4.1.3,
/// claims are in [`verify_credential`](super::verify_credential): `exp` and `nbf` use the
/// leeway in `options`, and neither is read without a `now`; an `aud` is accepted only when it
/// names the audience the caller identifies as (RFC 7519 §4.1.3,
/// which RFC 8392 §3.1.3 adopts), and a message that carries one is refused when the caller
/// gave none. `iat` is never checked.
///
Expand Down Expand Up @@ -159,9 +159,10 @@ fn open(
if let Some(now) = options.now {
// Exact for every instant a NumericDate can sensibly name, as in the JOSE form.
let now = now as f64;
let leeway = options.leeway().as_secs_f64();
for (claim, seconds) in [("exp", exp), ("nbf", nbf)] {
if let Some(seconds) = seconds {
check_instant(claim, seconds, now)?;
check_instant(claim, seconds, now, leeway)?;
}
}
}
Expand Down
15 changes: 8 additions & 7 deletions crates/dpp-vc/src/jose/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@
//! ([`JoseError::KidNotAbsolute`]) when there is no `iss` and the issuer, or the holder of a
//! presentation, is a URL, so the tokens this crate writes stay strict.
//!
//! **Time is explicit.** A [`VerifyOptions`] carries `now`, seconds since the epoch.
//! Under a `now`, `exp` must be a number and `now` before it, and `nbf` must be a
//! number and not after `now`, with no leeway, as in `sd_jwt_vc::verify`. With none
//! neither claim is read. `iat` is never checked: §3.1.3 says it describes
//! the signature, not the credential. A credential's own `validFrom` and
//! `validUntil` are the caller's to check.
//! **Time is explicit.** A [`VerifyOptions`] carries `now`, seconds since the epoch, and an
//! optional leeway for `exp` and `nbf`, capped at [`MAX_LEEWAY_SECONDS`]. Leeway defaults to
//! zero. `sd_jwt_vc::verify` takes the same options for the same JWT time claims. With no `now`,
//! JOSE and COSE do not read `exp` or `nbf`. `iat` is never checked: §3.1.3 says it describes
//! the signature, not the credential. A credential's own `validFrom` and `validUntil` are
//! checked separately by `verify_credential_claims` and do not use this leeway.
//!
//! **The audience is explicit too.** The same [`VerifyOptions`] carries the audience the
//! caller identifies as. RFC 7519 §4.1.3 says a JWT "MUST be rejected" when the principal
Expand Down Expand Up @@ -227,12 +227,13 @@ mod tests;
pub use cose_sign::{sign_credential_cose, sign_presentation_cose};
pub use cose_verify::{verify_credential_cose, verify_presentation_cose};
pub use error::JoseError;
pub use options::{KeyBindingRequirement, VerifyOptions};
pub use options::{KeyBindingRequirement, MAX_LEEWAY_SECONDS, VerifyOptions};
pub use presentation::verify_presentation;
pub use sd_jwt_sign::{sign_credential_sd_jwt, sign_presentation_sd_jwt};
pub use sd_jwt_verify::{verify_credential_sd_jwt, verify_presentation_sd_jwt};
pub use sign::{sign_credential, sign_presentation};
pub use unverified_envelope::UnverifiedEnvelope;
pub use verified_presentation::VerifiedPresentation;
pub(crate) use verify::check_audience;
pub use verify::verify_credential;
pub use vocabulary::{CREDENTIAL_TERMS, PRESENTATION_TERMS};
46 changes: 38 additions & 8 deletions crates/dpp-vc/src/jose/options.rs
Original file line number Diff line number Diff line change
@@ -1,43 +1,55 @@
//! What a caller decides before it verifies a token: the time, the audience it identifies
//! as, and, for an SD-JWT, whether Key Binding is required.
//! What a caller decides before it verifies a token: the time, its clock-skew allowance,
//! the audience it identifies as, and, for an SD-JWT, whether Key Binding is required.

use std::time::Duration;

use dpp_crypto::sd_jwt::KeyBindingPolicy;

/// The time and the audience a verifier checks a token against.
/// The greatest clock-skew allowance a verifier can configure, in seconds.
pub const MAX_LEEWAY_SECONDS: u64 = 300;

/// The time, clock-skew allowance, and audience a verifier checks a token against.
///
/// Both are the caller's to supply, and neither has a value that is assumed:
/// The time and audience are the caller's to supply; the leeway defaults to zero:
///
/// - **`now`** is seconds since the Unix epoch, supplied rather than read, as in
/// [`sd_jwt_vc::verify`](crate::sd_jwt_vc::verify): a result that depends on a hidden
/// clock cannot be reproduced. With a `now`, `exp` and `nbf` are checked (RFC 7519
/// §4.1.4 and §4.1.5). Without one they are not read.
/// - **`leeway`** is an optional allowance for clock skew, applied alike to `exp` and `nbf`.
/// It defaults to zero and is capped at [`MAX_LEEWAY_SECONDS`].
/// - **`audience`** is the value the caller identifies itself with. RFC 7519 §4.1.3 says
/// "If the principal processing the claim does not identify itself with a value in the
/// "aud" claim when this claim is present, then the JWT MUST be rejected." So a token
/// whose `aud` does not name it is refused, and a caller that gives no audience
/// identifies itself with nothing, so a token that carries `aud` is refused. A token
/// with no `aud` is not affected by either case.
///
/// `VerifyOptions::new()` is `now` unset and no audience, which checks no time and refuses
/// a token that carries `aud`.
/// `VerifyOptions::new()` is `now` unset, no leeway, and no audience, which checks no time
/// and refuses a token that carries `aud`.
///
/// ```
/// use dpp_vc::jose::VerifyOptions;
///
/// let options = VerifyOptions::new().at(1_800_000_000).for_audience("https://verifier.example");
/// let options = VerifyOptions::new()
/// .at(1_800_000_000)
/// .with_leeway(30)
/// .for_audience("https://verifier.example");
/// # let _ = options;
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct VerifyOptions<'a> {
pub(crate) now: Option<i64>,
pub(crate) leeway: Duration,
pub(crate) audience: Option<&'a str>,
}

impl<'a> VerifyOptions<'a> {
/// No time and no audience.
/// No time, leeway, or audience.
pub const fn new() -> Self {
Self {
now: None,
leeway: Duration::ZERO,
audience: None,
}
}
Expand All @@ -49,12 +61,30 @@ impl<'a> VerifyOptions<'a> {
self
}

/// Allow up to `seconds` of clock skew for `exp` and `nbf` checks.
///
/// Values above [`MAX_LEEWAY_SECONDS`] are capped at that limit. The default is zero.
#[must_use]
pub const fn with_leeway(mut self, seconds: u64) -> Self {
let seconds = if seconds > MAX_LEEWAY_SECONDS {
MAX_LEEWAY_SECONDS
} else {
seconds
};
self.leeway = Duration::from_secs(seconds);
self
}

/// Identify as `audience`: a token whose `aud` names it is accepted.
#[must_use]
pub const fn for_audience(mut self, audience: &'a str) -> Self {
self.audience = Some(audience);
self
}

pub(crate) const fn leeway(self) -> Duration {
self.leeway
}
}

/// Whether Key Binding is required of an SD-JWT, which RFC 9901 §9.5 says "Verifiers MUST
Expand Down
17 changes: 17 additions & 0 deletions crates/dpp-vc/src/jose/tests/cose/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ fn a_credential_that_is_not_yet_valid_is_refused_under_a_now_and_not_without_one
assert!(verify_vc(&message).is_ok());
}

#[test]
fn configured_leeway_applies_equally_to_exp_and_nbf() {
let exp = forged_credential(&credential(), &cwt(vec![claim(4, uint(1_000))]));
assert!(verify_vc_with(&exp, VerifyOptions::new().at(1_002).with_leeway(3)).is_ok());
assert_eq!(
verify_vc_with(&exp, VerifyOptions::new().at(1_003).with_leeway(3)),
Err(JoseError::Expired)
);

let nbf = forged_credential(&credential(), &cwt(vec![claim(5, uint(2_000))]));
assert!(verify_vc_with(&nbf, VerifyOptions::new().at(1_997).with_leeway(3)).is_ok());
assert_eq!(
verify_vc_with(&nbf, VerifyOptions::new().at(1_996).with_leeway(3)),
Err(JoseError::NotYetValid)
);
}

/// A NumericDate may be fractional, and `iat` is never checked (§3.3.3: it describes the
/// signature, not the credential).
#[test]
Expand Down
56 changes: 54 additions & 2 deletions crates/dpp-vc/src/jose/tests/temporal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use serde_json::{Value, json};
use dpp_crypto::jws::KeyAlgorithm;
use dpp_crypto::keystore::KeyEntry;

use super::super::VerifyOptions;
use super::super::{JoseError, verify_credential, verify_presentation};
use super::super::{MAX_LEEWAY_SECONDS, VerifyOptions};
use crate::test_support::NOT_REQUIRED;
use crate::test_support::at;
use crate::test_support::{
Expand All @@ -30,7 +30,15 @@ fn credential_with(key: &KeyEntry, claim: &str, value: Value) -> String {
}

fn verify(token: &str, key: &KeyEntry, now: Option<i64>) -> Result<Value, JoseError> {
verify_credential(token, &key.public_key(), at(now))
verify_with_options(token, key, at(now))
}

fn verify_with_options(
token: &str,
key: &KeyEntry,
options: VerifyOptions<'_>,
) -> Result<Value, JoseError> {
verify_credential(token, &key.public_key(), options)
}

// ── exp ───────────────────────────────────────────────────────────────────────
Expand All @@ -57,6 +65,50 @@ fn exp_may_be_fractional() {
);
}

#[test]
fn exp_leeway_accepts_inside_and_refuses_outside() {
let key = key();
let token = credential_with(&key, "exp", json!(NOW));

assert!(verify_with_options(&token, &key, at(Some(NOW + 2)).with_leeway(3),).is_ok());
assert_eq!(
verify_with_options(&token, &key, at(Some(NOW + 3)).with_leeway(3)),
Err(JoseError::Expired)
);
}

#[test]
fn nbf_leeway_accepts_inside_and_refuses_outside() {
let key = key();
let token = credential_with(&key, "nbf", json!(NOW));

assert!(verify_with_options(&token, &key, at(Some(NOW - 3)).with_leeway(3),).is_ok());
assert_eq!(
verify_with_options(&token, &key, at(Some(NOW - 4)).with_leeway(3)),
Err(JoseError::NotYetValid)
);
}

#[test]
fn leeway_is_capped_at_five_minutes() {
let key = key();
let token = credential_with(&key, "exp", json!(NOW));
let max = i64::try_from(MAX_LEEWAY_SECONDS).expect("maximum leeway fits i64");

assert!(
verify_with_options(
&token,
&key,
at(Some(NOW + max - 1)).with_leeway(MAX_LEEWAY_SECONDS),
)
.is_ok()
);
assert_eq!(
verify_with_options(&token, &key, at(Some(NOW + max)).with_leeway(u64::MAX),),
Err(JoseError::Expired)
);
}

// ── nbf ───────────────────────────────────────────────────────────────────────

#[test]
Expand Down
Loading
Loading