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

Fix the presentation submission in the oid4vp-rs e2e test. #8

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
10611a8
wip: use ssi 0.8.1, debugging e2e test using did resolver
Ryanmtate Aug 8, 2024
7ea4c50
wip: use VerificationMethodDIDResolver for DIDClient constructor
Ryanmtate Aug 8, 2024
7b3ced0
remove unused imports
Ryanmtate Aug 8, 2024
4a77347
wip: debugging did resolver jwk not found in e2e flow
Ryanmtate Aug 9, 2024
48e152e
feat/improve-presentation-exchange-support-in-oid4vp-rs
Ryanmtate Aug 9, 2024
26e62f1
add getter methods for presentation definition member fields
Ryanmtate Aug 9, 2024
8c47808
fix broken links in documentation
Ryanmtate Aug 9, 2024
de5db7d
update presentation submission implementation
Ryanmtate Aug 10, 2024
24845c7
fix test cases. todo: update test cases to use newly created interfac…
Ryanmtate Aug 10, 2024
5036a69
update json schema validator to use anyhow result type
Ryanmtate Aug 10, 2024
ac8e904
merge presentation exchange updates
Ryanmtate Aug 11, 2024
6fe4d46
wip: use latest implementation changes, update tests
Ryanmtate Aug 12, 2024
6d29442
fix verification method did resolver tests
Ryanmtate Aug 12, 2024
e885a4c
wip: remove unused imports
Ryanmtate Aug 12, 2024
3996946
add ClaimFormat type
Ryanmtate Aug 12, 2024
4e841cc
add regex support for string pattern matching
Ryanmtate Aug 12, 2024
edcc8a2
revert uuid presentation definition id type to string
Ryanmtate Aug 12, 2024
23e589a
fix: ensure negation of regex pattern match for error
Ryanmtate Aug 12, 2024
1527933
add 'other' variante to claim format type
Ryanmtate Aug 12, 2024
8ed8828
remove commented out code
Ryanmtate Aug 12, 2024
97b3462
merge presentation exchange updates
Ryanmtate Aug 12, 2024
dcdde5c
use ssi sub-crates instead of main ssi dependency
Ryanmtate Aug 12, 2024
1a2af67
add jwt_vc_json and jwt_vp_json claim formats
Ryanmtate Aug 12, 2024
61043a9
wip: construct verifiable presentation for e2e test
Ryanmtate Aug 13, 2024
24497dd
wip: perform validation on presentation submission
Ryanmtate Aug 13, 2024
3423d13
ensure range exclusive values are checked; fix inclusive range values
Ryanmtate Aug 13, 2024
7bd0660
ensure enum values are parsed in alpha descending order
Ryanmtate Aug 13, 2024
ce60c03
wip: verify authorized response presentation submission
Ryanmtate Aug 14, 2024
cd22624
ensure json schema validator adheres to the specification
Ryanmtate Aug 14, 2024
26dda42
ensure json schema validator adheres to the specification
Ryanmtate Aug 14, 2024
d188434
add unit tests for schema validator
Ryanmtate Aug 14, 2024
89db3b2
use serde default value for constraints field if not found during des…
Ryanmtate Aug 14, 2024
0ec29b3
merge schema validator changes
Ryanmtate Aug 14, 2024
d478103
remove unused imports
Ryanmtate Aug 14, 2024
5e65c4e
Merge branch 'main' into fix/fix-the-presentation-submission-in-the-o…
Ryanmtate Aug 14, 2024
e276d6a
remove unsed imports in test files
Ryanmtate Aug 14, 2024
3d93a0e
update vp token
Ryanmtate Aug 14, 2024
0843f66
rebase with main
Ryanmtate Aug 14, 2024
b7d8083
resolve merge conflict; remove schema validator and replace with json…
Ryanmtate Aug 16, 2024
096d383
remove unused dependencies
Ryanmtate Aug 16, 2024
f82fa26
add rand crate and provide random nonce method using Rng trait
Ryanmtate Aug 20, 2024
b07b715
remove todos and update comments, use JWKResolver instead of Verifica…
Ryanmtate Aug 20, 2024
fcb4ed9
fix clippy warnings
Ryanmtate Aug 20, 2024
1398cad
verify jwt in validate_authorization_response presentation definition…
Ryanmtate Aug 20, 2024
be2bbed
Update tests/e2e.rs
Ryanmtate Aug 20, 2024
32a49b7
update descriptor map nested path in e2e example
Ryanmtate Aug 20, 2024
d050355
remove dependency patches
Ryanmtate Aug 20, 2024
4a0217b
add paths to example for input descriptor constraints field
Ryanmtate Aug 20, 2024
9997486
use top level json path for jwt_vp_json
Ryanmtate Aug 20, 2024
2a93750
Update src/verifier/client.rs
Ryanmtate Aug 20, 2024
f490b8b
rebase
Ryanmtate Aug 20, 2024
347259d
revert validation function async signature to use boxed pin future
Ryanmtate Aug 20, 2024
05d550e
add helper methods
Ryanmtate Aug 22, 2024
129d22c
debug: jwt claim signing does not include public key
Ryanmtate Aug 22, 2024
a3bf215
make request signer methods return a result
Ryanmtate Aug 22, 2024
7733f65
refactor presentation exchange file into smaller modules
Ryanmtate Aug 23, 2024
54c0f79
fix clippy warnings
Ryanmtate Aug 23, 2024
efd5773
Merge branch 'main' into fix/fix-the-presentation-submission-in-the-o…
Ryanmtate Aug 23, 2024
a7aed11
fix outcome error cause
Ryanmtate Aug 23, 2024
2e453ca
add credential format and add requested fields helper method to input…
Ryanmtate Aug 26, 2024
a3bfdcb
Update src/core/presentation_definition.rs
Ryanmtate Aug 27, 2024
7a337ae
Update src/core/presentation_definition.rs
Ryanmtate Aug 27, 2024
76e3a3a
wip: add notes on required fields parsing
Ryanmtate Aug 27, 2024
51e11e8
update vp token base64 encoding and check for multiple vp payloads
Ryanmtate Aug 28, 2024
65e1b11
move validation to auth response impl instead of presentation definit…
Ryanmtate Aug 28, 2024
d0c7439
remove feature gated non-optional deps
Ryanmtate Aug 28, 2024
033fd5e
remove cfg features
Ryanmtate Aug 28, 2024
d98d2a4
wip: handle groups in presentation definition, input descriptor tests
Ryanmtate Aug 28, 2024
915b922
remove cfg feature tags
Ryanmtate Aug 28, 2024
3d7b1f5
remove extraneous metadata helper methods; use UntypedObject for dere…
Ryanmtate Aug 28, 2024
e9b33df
add submission requirement check for presentation validation
Ryanmtate Aug 29, 2024
64f87eb
add validate method to vp token; ensure submission requirement all ru…
Ryanmtate Aug 29, 2024
d3dce7f
add vp token validate unencoded method. fix minor todos.
Ryanmtate Aug 29, 2024
458ff5f
Update Cargo.toml
Ryanmtate Sep 12, 2024
165b1c7
fix other claim format serde
Ryanmtate Sep 12, 2024
0e0f985
use Vec::is_empty versus Option::is_none for various serialization fi…
Ryanmtate Sep 13, 2024
b8e9141
revert to use of ClaimFormatMap to pass presentation defintion test s…
Ryanmtate Sep 13, 2024
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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ serde_cbor = "0.11.2"
serde_json = "1.0.107"
serde_qs = "0.12.0"
serde_urlencoded = "0.7.1"
ssi = "0.7.0"
ssi = "0.8.1"
Ryanmtate marked this conversation as resolved.
Show resolved Hide resolved
thiserror = "1.0.49"
tokio = "1.32.0"
tracing = "0.1.37"
Expand Down
29 changes: 21 additions & 8 deletions src/core/authorization_request/verification/did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,29 @@ use crate::core::{
use anyhow::{bail, Context, Result};
use base64::prelude::*;
use serde_json::{Map, Value as Json};
use ssi::did_resolve::{resolve_key, DIDResolver};
use ssi::{
dids::{DIDResolver, VerificationMethodDIDResolver},
jwk::JWKResolver,
verification_methods::{
GenericVerificationMethod, InvalidVerificationMethod, MaybeJwkVerificationMethod,
VerificationMethodSet,
},
};

/// Default implementation of request validation for `client_id_scheme` `did`.
pub async fn verify_with_resolver(
pub async fn verify_with_resolver<M>(
wallet_metadata: &WalletMetadata,
request_object: &AuthorizationRequestObject,
request_jwt: String,
trusted_dids: Option<&[String]>,
resolver: &dyn DIDResolver,
) -> Result<()> {
let (headers_b64, _, _) = ssi::jws::split_jws(&request_jwt)?;
resolver: &VerificationMethodDIDResolver<impl DIDResolver, M>,
Ryanmtate marked this conversation as resolved.
Show resolved Hide resolved
) -> Result<()>
where
M: MaybeJwkVerificationMethod
+ VerificationMethodSet
+ TryFrom<GenericVerificationMethod, Error = InvalidVerificationMethod>,
{
let (headers_b64, _, _) = ssi::claims::jws::split_jws(&request_jwt)?;

let headers_json_bytes = BASE64_URL_SAFE_NO_PAD
.decode(headers_b64)
Expand Down Expand Up @@ -64,11 +76,12 @@ pub async fn verify_with_resolver(
}
}

let jwk = resolve_key(&kid, resolver)
let jwk = resolver
.fetch_public_jwk(Some(&kid))
.await
.context("unable to resolve verification method from 'kid' header")?;
.context("unable to fetch JWK from 'kid' header")?;

let _: Json = ssi::jwt::decode_verify(&request_jwt, &jwk)
let _: Json = ssi::claims::jwt::decode_verify(&request_jwt, &jwk)
Ryanmtate marked this conversation as resolved.
Show resolved Hide resolved
.context("request signature could not be verified")?;

Ok(())
Expand Down
7 changes: 4 additions & 3 deletions src/core/authorization_request/verification/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ pub(crate) async fn verify_request<W: Wallet + ?Sized>(
wallet: &W,
jwt: String,
) -> Result<AuthorizationRequestObject> {
let request: AuthorizationRequestObject = ssi::jwt::decode_unverified::<UntypedObject>(&jwt)
.context("unable to decode Authorization Request Object JWT")?
.try_into()?;
let request: AuthorizationRequestObject =
ssi::claims::jwt::decode_unverified::<UntypedObject>(&jwt)
.context("unable to decode Authorization Request Object JWT")?
.try_into()?;

validate_request_against_metadata(wallet, &request).await?;

Expand Down
2 changes: 1 addition & 1 deletion src/core/authorization_request/verification/x509_san.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn validate<V: Verifier>(
trusted_roots: Option<&[Certificate]>,
) -> Result<()> {
let client_id = request_object.client_id().0.as_str();
let (headers_b64, body_b64, sig_b64) = ssi::jws::split_jws(&request_jwt)?;
let (headers_b64, body_b64, sig_b64) = ssi::claims::jws::split_jws(&request_jwt)?;

let headers_json_bytes = BASE64_URL_SAFE_NO_PAD
.decode(headers_b64)
Expand Down
14 changes: 12 additions & 2 deletions src/presentation_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ pub enum ConstraintsLimitDisclosure {
Preferred,
}

#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum VerifiableFormat {
#[serde(rename = "jwt_vc_json")]
JwtVcJson,
#[serde(rename = "jwt_vp_json")]
JwtVpJson,
#[serde(rename = "ldp_vc")]
LdpVc,
}

Ryanmtate marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct PresentationSubmission {
pub id: String,
Expand All @@ -94,9 +104,9 @@ pub struct PresentationSubmission {
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct DescriptorMap {
pub id: String,
pub format: String, // TODO should be enum of supported formats
pub format: VerifiableFormat,
cobward marked this conversation as resolved.
Show resolved Hide resolved
pub path: String,
//pub path_nested: Option<Box<DescriptorMap>>,
pub path_nested: Option<Box<DescriptorMap>>,
}

#[derive(Deserialize)]
Expand Down
27 changes: 20 additions & 7 deletions src/verifier/client.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
use std::{fmt::Debug, sync::Arc};
use std::{fmt::Debug, str::FromStr, sync::Arc};

use anyhow::{bail, Context as _, Result};
use async_trait::async_trait;
use base64::prelude::*;
use serde_json::{json, Value as Json};
use ssi::did_resolve::DIDResolver;
use ssi::{
dids::{DIDBuf, DIDResolver, VerificationMethodDIDResolver, DID},
jwk::JWKResolver,
verification_methods::{
GenericVerificationMethod, InvalidVerificationMethod, MaybeJwkVerificationMethod,
VerificationMethodSet,
},
};
use tracing::debug;
use x509_cert::{
der::Encode,
Expand Down Expand Up @@ -40,20 +47,26 @@ pub struct DIDClient {
}

impl DIDClient {
pub async fn new(
pub async fn new<M>(
vm: String,
signer: Arc<dyn RequestSigner + Send + Sync>,
resolver: &dyn DIDResolver,
) -> Result<Self> {
resolver: &VerificationMethodDIDResolver<impl DIDResolver, M>,
Ryanmtate marked this conversation as resolved.
Show resolved Hide resolved
) -> Result<Self>
where
M: MaybeJwkVerificationMethod
+ VerificationMethodSet
+ TryFrom<GenericVerificationMethod, Error = InvalidVerificationMethod>,
{
let (id, _f) = vm.rsplit_once('#').context(format!(
"expected a DID verification method, received '{vm}'"
))?;

let key = ssi::did_resolve::resolve_key(&vm, resolver)
let key = resolver
.fetch_public_jwk(Some(&vm))
.await
.context("unable to resolve key from verification method")?;

if &key != signer.jwk() {
if &*key != signer.jwk() {
Ryanmtate marked this conversation as resolved.
Show resolved Hide resolved
bail!(
"verification method resolved from DID document did not match public key of signer"
)
Expand Down
21 changes: 15 additions & 6 deletions tests/jwt_vc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{str::FromStr, sync::Arc};

use anyhow::{Context, Result};
use async_trait::async_trait;
Expand All @@ -22,7 +22,11 @@ use oid4vp::{
wallet::Wallet,
};
use serde_json::json;
use ssi::did::DIDMethod;
use ssi::{
dids::{VerificationMethodDIDResolver, DIDJWK},
prelude::AnyMethod,
JWK,
};

pub async fn wallet_verifier() -> (JwtVcWallet, Arc<Verifier>) {
let verifier_did = "did:key:zDnaeaDj3YpPR4JXos2kCCNPS86hdELeN5PZh97KGkoFzUtGn".to_owned();
Expand All @@ -36,11 +40,14 @@ pub async fn wallet_verifier() -> (JwtVcWallet, Arc<Verifier>) {
)
.unwrap(),
);

let resolver = VerificationMethodDIDResolver::new(DIDJWK);

let client = Arc::new(
oid4vp::verifier::client::DIDClient::new(
oid4vp::verifier::client::DIDClient::new::<AnyMethod>(
verifier_did_vm.clone(),
signer.clone(),
DIDKey.to_resolver(),
&resolver,
cobward marked this conversation as resolved.
Show resolved Hide resolved
)
.await
.unwrap(),
Expand Down Expand Up @@ -125,12 +132,14 @@ impl RequestVerifier for JwtVcWallet {
decoded_request: &AuthorizationRequestObject,
request_jwt: String,
) -> Result<()> {
did::verify_with_resolver(
let resolver = VerificationMethodDIDResolver::new(DIDJWK);

did::verify_with_resolver::<AnyMethod>(
self.metadata(),
decoded_request,
request_jwt,
Some(self.trusted_dids()),
DIDKey.to_resolver(),
&resolver,
)
.await
}
Expand Down