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

Support Selective Disclosure SD-JWT #1268

Merged
merged 35 commits into from
Jan 18, 2024
Merged

Support Selective Disclosure SD-JWT #1268

merged 35 commits into from
Jan 18, 2024

Conversation

abdulmth
Copy link
Contributor

@abdulmth abdulmth commented Nov 30, 2023

Add Rust and Wasm support for verifying selective disclosures JWT and key binding JWT using https://github.com/iotaledger/sd-jwt-payload.

@abdulmth abdulmth marked this pull request as ready for review December 12, 2023 00:07
@abdulmth abdulmth changed the title [WIP] Support Selective Disclosure SD-JWT Support Selective Disclosure SD-JWT Dec 12, 2023
@abdulmth abdulmth self-assigned this Dec 12, 2023
@abdulmth abdulmth added Added A new feature that requires a minor release. Part of "Added" section in changelog Rust Related to the core Rust code. Becomes part of the Rust changelog. labels Dec 12, 2023
@abdulmth abdulmth added this to the v1.1 milestone Dec 12, 2023
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not too convinced with how the validator has changed. Having to explicitly pass the optional SdObjectDecoder doesn't feel really confortable. Don't you think it might be worth having SdObjectDecoder work behind the scene? The APIs for JwtCredentialValidator remains the same, but internally use SdObjectDecoder if the JWT received as input is a SD-JWT. If a user knows for sure that they are working with a SD-JWT then they can use the SdObjectDecoder directly, maybe through some utility functions or even an extension trait provided by the library to make things more ergonomic.
Probably we can discuss a better way to handle this. What concerns me is that this won't scale well if we want to handle the validation of even more JWT types (say ZK-JWT for instance), as it could require to add yet another optional parameter to every method call.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see now you have created an SdJwtValidator that only validates SD-JWT encoded credential. Even more of a reason to avoid polluting the APIs of JwtCredentialValidator if the two have different concerns.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The library's API didn't really change, since none of the public methods changed. validate_extended is not public.
I agree with you that this does not scale well. But If we want to separate the concerns, we pretty much have to duplicate the majority of the JwtCredentialValidator.

Don't you think it might be worth having SdObjectDecoder work behind the scene?

It doesn't work, it's tightly coupled with the signature. You can not reuse JwtCredentialValidator if you do the decoding yourself. You have to verify the signature first, which is a deep down part of the JwtCredentialValidator.

So all in all, we either have to duplicate JwtCredentialValidator, or we have to rewrite it completely to make it more generic (not solved problem), or we keep the current solution and make it a future problem :D, But for ZK, I don't think it would use any of the JwtCredentialValidator. I don't think it would have a big overlap for that to make sense.

My concern is only that the sd_jwt_payload is not an optional dependency if users only want JwtCredentialValidator. But I kept all selective disclosure concerns under a flag, in case we want to rewrite or rethink the architecture of the internal implementation of the JwtCredentialValidator.

Copy link
Contributor

Choose a reason for hiding this comment

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

@abdulmth the last thing you mentioned is definitely something worth discussing. I couldn't have thought about it, thanks for pointing it out.

@UMR1352
Copy link
Contributor

UMR1352 commented Jan 12, 2024

We might want to further split some validation steps into smaller reusable and composable functions which probably better belong to JwtCredentialValidationUtils rather than JwtCredentialValidator

@@ -704,7 +704,39 @@ impl WasmIotaDocument {
///
/// Upon success a string representing a JWS encoded according to the Compact JWS Serialization format is returned.
/// See [RFC7515 section 3.1](https://www.rfc-editor.org/rfc/rfc7515#section-3.1).
///
/// @deprecated Use `createJws()` instead.
Copy link
Contributor Author

@abdulmth abdulmth Jan 15, 2024

Choose a reason for hiding this comment

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

typo in the latest release. I added a new method and deprecated this one

@abdulmth
Copy link
Contributor Author

We might want to further split some validation steps into smaller reusable and composable functions which probably better belong to JwtCredentialValidationUtils rather than JwtCredentialValidator

We can do that in a separate PR, this one is getting a bit too big.

I already adapted your PR here, we can close that one I think.

Copy link
Contributor

@UMR1352 UMR1352 left a comment

Choose a reason for hiding this comment

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

Looks good. Great job with the example!

Copy link
Collaborator

@eike-hass eike-hass left a comment

Choose a reason for hiding this comment

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

Looks really good, I left a couple of minor suggestions. Please also add the new example to bindings/wasm/examples/src/tests to run it in CI.


/**
* Demonstrates how to create a selective disclosure verifiable credential and validate it
* using the standard [Selective Disclosure for JWTs (SD-JWT)](https://www.ietf.org/archive/id/draft-ietf-oauth-selective-disclosure-jwt-07.html).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* using the standard [Selective Disclosure for JWTs (SD-JWT)](https://www.ietf.org/archive/id/draft-ietf-oauth-selective-disclosure-jwt-07.html).
* using the [Selective Disclosure for JWTs (SD-JWT)](https://www.ietf.org/archive/id/draft-ietf-oauth-selective-disclosure-jwt-07.html) specification.

// disclosures.
const strDisclosures = disclosures.map(disclosure => disclosure.toEncodedString());

let sdJwt = new SdJwt(jws.toString(), strDisclosures, undefined).presentation();
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we omit the third parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, I kept it originally to hint that users can optionally add the KB. but it's demonstrated further down in the code so it's fine.

const kbJwt = await aliceDocument.createJws(aliceStorage, aliceFragment, bindingClaims.toString(), options);

// Create the final SD-JWT.
let finalSdJwt = new SdJwt(sdJwtReceived.jwt().toString(), toBeDisclosed, kbJwt.toString());
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe sdJwtWithKb

@@ -215,6 +218,26 @@ impl WasmCredential {
pub fn set_proof(&mut self, proof: Option<WasmProof>) {
self.0.set_proof(proof.map(|wasm_proof| wasm_proof.0))
}

/// Serializes the `Credential` as a JWT claims set
/// in accordance with [VC Data Model v1.1](https://www.w3.org/TR/vc-data-model/#json-web-token).
Copy link
Collaborator

Choose a reason for hiding this comment

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

We know Data Model 2.0 will be a thing, should we somehow anticipate that already?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They don't have it in the Data Model 2.0, it's in Securing Verifiable Credentials using JOSE and COSE.
I'm not sure what we can do here, it affects our JWT implementation for credentials everywhere, not only for SD JWT.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sorry I wasn't clear. I was going for do we have any dependencies on Data Model 1.1 that we should abstract out already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, it can deal with any JSON value, so that wouldn't be an issue AFAIK.

@eike-hass
Copy link
Collaborator

eike-hass commented Jan 16, 2024

Would there ever be an additional Proof in the credential? Is that something that we need to demonstrate?

@eike-hass eike-hass added the Wasm Related to Wasm bindings. Becomes part of the Wasm changelog label Jan 16, 2024
@abdulmth
Copy link
Contributor Author

Would there ever be an additional Proof in the credential? IS that something that need to demonstrate?

It's possible to add a proof property to a credential, but how is that relevant to SD JWT? We use JWT to validate the signature here so we don't need a proof property since it's not relevant to SD JWT 🤷🏻

@eike-hass
Copy link
Collaborator

eike-hass commented Jan 17, 2024

Would there ever be an additional Proof in the credential? IS that something that need to demonstrate?

It's possible to add a proof property to a credential, but how is that relevant to SD JWT? We use JWT to validate the signature here so we don't need a proof property since it's not relevant to SD JWT 🤷🏻

That makes sense, thank you! Then I think there is nothing for us to demonstrate or additionally consider.

@eike-hass eike-hass self-requested a review January 18, 2024 10:36
Copy link
Collaborator

@eike-hass eike-hass left a comment

Choose a reason for hiding this comment

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

Looks good, awesone job 💪

@abdulmth abdulmth merged commit c9512d2 into main Jan 18, 2024
12 checks passed
@abdulmth abdulmth deleted the feat/poc-sd-jwt branch January 18, 2024 10:39
@eike-hass eike-hass linked an issue Jan 26, 2024 that may be closed by this pull request
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Added A new feature that requires a minor release. Part of "Added" section in changelog Rust Related to the core Rust code. Becomes part of the Rust changelog. Wasm Related to Wasm bindings. Becomes part of the Wasm changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task] Implement SD-JWT
3 participants