-
Notifications
You must be signed in to change notification settings - Fork 8
Update Client- and Wallet Metadata #365
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7fae173
Add AsOption extension
JoTiTu 90f732a
Support encrypted_response_enc_values_supported
JoTiTu 8114e8f
Support vp_formats_supported and refactor WalletMetadata
JoTiTu 4a274e8
Make encrypted_response_enc_values_supported an array according to specs
JoTiTu 94f6f0d
remove state paramter from encrypted response
JoTiTu 30e19e6
PR comments
JoTiTu 9810c5a
clean
JoTiTu 5fb9dda
Refactor IsVpFormatsSupported and add unit tests
JoTiTu 7bdb68b
Make tests less opinionated, move Vaildation to ClientMetadata Model
JoTiTu 47f9202
merge main
JoTiTu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/WalletFramework.Oid4Vc/Oid4Vp/Errors/VpFormatsNotSupportedError.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace WalletFramework.Oid4Vc.Oid4Vp.Errors; | ||
|
||
public record VpFormatsNotSupportedError : VpError | ||
{ | ||
private const string Code = "vp_formats_not_supported"; | ||
|
||
public VpFormatsNotSupportedError(string message) : base(Code, message) | ||
{ | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
using LanguageExt; | ||
using Newtonsoft.Json; | ||
using OneOf; | ||
using WalletFramework.Core.Functional; | ||
using WalletFramework.Oid4Vc.Oid4Vp.Dcql.Models; | ||
using WalletFramework.Oid4Vc.Oid4Vp.Errors; | ||
using WalletFramework.Oid4Vc.Oid4Vp.Jwk; | ||
using WalletFramework.Oid4Vc.Oid4Vp.PresentationExchange.Models; | ||
|
||
namespace WalletFramework.Oid4Vc.Oid4Vp.Models; | ||
|
||
|
@@ -12,6 +17,7 @@ public record ClientMetadata | |
// Needed for Newtonsoft Json Serialization | ||
public ClientMetadata( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should add a unit test for parsing ClientMetadata |
||
string? authorizationEncryptedResponseEnc, | ||
string[]? encryptedResponseEncValuesSupported, | ||
string[] redirectUris, | ||
string? clientName, | ||
string? clientUri, | ||
|
@@ -21,9 +27,11 @@ public ClientMetadata( | |
string? jwksUri, | ||
string? policyUri, | ||
string? tosUri, | ||
Formats formats) | ||
Formats vpFormats, | ||
Formats vpFormatsSupported) | ||
Dindexx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
AuthorizationEncryptedResponseEnc = authorizationEncryptedResponseEnc; | ||
EncryptedResponseEncValuesSupported = encryptedResponseEncValuesSupported; | ||
RedirectUris = redirectUris; | ||
ClientName = clientName; | ||
ClientUri = clientUri; | ||
|
@@ -33,15 +41,24 @@ public ClientMetadata( | |
JwksUri = jwksUri; | ||
PolicyUri = policyUri; | ||
TosUri = tosUri; | ||
Formats = formats; | ||
VpFormats = vpFormats; | ||
VpFormatsSupported = vpFormatsSupported; | ||
} | ||
|
||
/// <summary> | ||
/// Defined the encoding that should be used when an encrypted Auth Response is requested by the verifier. | ||
/// Replaced by encrypted_response_enc_values_supported but kept for now for backwards compatibility. | ||
/// </summary> | ||
[Obsolete("This property is obsolete.")] | ||
[JsonProperty("authorization_encrypted_response_enc")] | ||
public string? AuthorizationEncryptedResponseEnc { get; init; } | ||
|
||
/// <summary> | ||
/// Defined the encoding that should be used when an encrypted Auth Response is requested by the verifier. | ||
/// </summary> | ||
[JsonProperty("encrypted_response_enc_values_supported")] | ||
public string[]? EncryptedResponseEncValuesSupported { get; init; } | ||
|
||
/// <summary> | ||
/// The redirect URIs of the client (verifier). | ||
/// </summary> | ||
|
@@ -94,7 +111,102 @@ public ClientMetadata( | |
|
||
/// <summary> | ||
/// The URI to a human-readable terms of service document for the client (verifier). | ||
/// This is deprecated and replaced by vp_formats_supported but kept for now for backwards compatibility. | ||
/// </summary> | ||
[Obsolete("This property is obsolete.")] | ||
[JsonProperty("vp_formats")] | ||
public Formats Formats { get; init; } | ||
public Formats? VpFormats { get; init; } | ||
|
||
/// <summary> | ||
/// The URI to a human-readable terms of service document for the client (verifier). | ||
/// </summary> | ||
[JsonProperty("vp_formats_supported")] | ||
public Formats? VpFormatsSupported { get; init; } | ||
} | ||
|
||
public static class ClientMetadataExtensions | ||
{ | ||
public static Validation<AuthorizationRequestCancellation, Option<ClientMetadata>> VpFormatsSupportedValidation(this ClientMetadata clientMetadata, OneOf<DcqlQuery, PresentationDefinition> requirements, Option<Uri> responseUri) | ||
{ | ||
return requirements.Match( | ||
dcql => | ||
{ | ||
var walletMetadata = WalletMetadata.CreateDefault(); | ||
|
||
var (sdJwtRequested, mdocRequested) = | ||
(dcql.CredentialQueries.Any(query => query.Format == Constants.SdJwtDcFormat || query.Format == Constants.SdJwtVcFormat), | ||
dcql.CredentialQueries.Any(query => query.Format == Constants.MdocFormat)); | ||
|
||
return (sdJwtRequested, mdocRequested) switch | ||
{ | ||
(true, false) => IsSdJwtVpFormatSupported(clientMetadata, walletMetadata) | ||
? clientMetadata.AsOption() | ||
: (Validation<AuthorizationRequestCancellation, Option<ClientMetadata>>) GetVpFormatsNotSupportedCancellation(responseUri), | ||
(false, true) => IsMdocVpFormatSupported(clientMetadata, walletMetadata) | ||
? clientMetadata.AsOption() | ||
: (Validation<AuthorizationRequestCancellation, Option<ClientMetadata>>) GetVpFormatsNotSupportedCancellation(responseUri), | ||
(true, true) => IsSdJwtVpFormatSupported(clientMetadata, walletMetadata) && IsMdocVpFormatSupported(clientMetadata, walletMetadata) | ||
? clientMetadata.AsOption() | ||
: (Validation<AuthorizationRequestCancellation, Option<ClientMetadata>>) GetVpFormatsNotSupportedCancellation(responseUri), | ||
_ => clientMetadata.AsOption() | ||
}; | ||
}, | ||
_ => clientMetadata.AsOption()); | ||
} | ||
|
||
private static bool IsMdocVpFormatSupported(ClientMetadata clientMetadata, WalletMetadata walletMetadata) | ||
{ | ||
var rpSupportedVpFormats = clientMetadata.VpFormatsSupported ?? clientMetadata.VpFormats; | ||
var walletMetadataSupportedVpFormats = walletMetadata.VpFormatsSupported; | ||
|
||
if (rpSupportedVpFormats?.MDocFormat == null) | ||
return true; | ||
|
||
if (rpSupportedVpFormats.MDocFormat.IssuerAuthAlgValues != null && | ||
!rpSupportedVpFormats.MDocFormat.IssuerAuthAlgValues.Any(clientAlg => walletMetadataSupportedVpFormats.MDocFormat!.IssuerAuthAlgValues!.Contains(clientAlg))) | ||
return false; | ||
|
||
if (rpSupportedVpFormats.MDocFormat.DeviceAuthAlgValues != null && | ||
!rpSupportedVpFormats.MDocFormat.DeviceAuthAlgValues.Any(clientAlg => walletMetadataSupportedVpFormats.MDocFormat!.DeviceAuthAlgValues!.Contains(clientAlg))) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
private static bool IsSdJwtVpFormatSupported(ClientMetadata clientMetadata, WalletMetadata walletMetadata) | ||
{ | ||
var rpSupportedVpFormats = clientMetadata.VpFormatsSupported ?? clientMetadata.VpFormats; | ||
var walletMetadataSupportedVpFormats = walletMetadata.VpFormatsSupported; | ||
|
||
if (rpSupportedVpFormats?.SdJwtDcFormat != null) | ||
{ | ||
if (rpSupportedVpFormats.SdJwtDcFormat.IssuerSignedJwtAlgValues != null && | ||
!rpSupportedVpFormats.SdJwtDcFormat.IssuerSignedJwtAlgValues.Any(clientAlg => walletMetadataSupportedVpFormats.SdJwtDcFormat!.IssuerSignedJwtAlgValues!.Contains(clientAlg))) | ||
return false; | ||
|
||
if (rpSupportedVpFormats.SdJwtDcFormat.KeyBindingJwtAlgValues != null && | ||
!rpSupportedVpFormats.SdJwtDcFormat.KeyBindingJwtAlgValues.Any(clientAlg => walletMetadataSupportedVpFormats.SdJwtDcFormat!.KeyBindingJwtAlgValues!.Contains(clientAlg))) | ||
return false; | ||
} | ||
|
||
//TODO: Remove SdJwtVcFormat in the future as it is deprecated (kept for now for backwards compatibility) | ||
if (rpSupportedVpFormats?.SdJwtVcFormat != null) | ||
{ | ||
if (rpSupportedVpFormats.SdJwtVcFormat.IssuerSignedJwtAlgValues != null && | ||
!rpSupportedVpFormats.SdJwtVcFormat.IssuerSignedJwtAlgValues.Any(clientAlg => walletMetadataSupportedVpFormats.SdJwtVcFormat!.IssuerSignedJwtAlgValues!.Contains(clientAlg))) | ||
return false; | ||
|
||
if (rpSupportedVpFormats.SdJwtVcFormat.KeyBindingJwtAlgValues != null && | ||
!rpSupportedVpFormats.SdJwtVcFormat.KeyBindingJwtAlgValues.Any(clientAlg => walletMetadataSupportedVpFormats.SdJwtVcFormat!.KeyBindingJwtAlgValues!.Contains(clientAlg))) | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private static AuthorizationRequestCancellation GetVpFormatsNotSupportedCancellation(Option<Uri> responseUri) | ||
{ | ||
var error = new VpFormatsNotSupportedError("The provided vp_formats_supported values are not supported"); | ||
return new AuthorizationRequestCancellation(responseUri, [error]); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/WalletFramework.Oid4Vc/Oid4Vp/Models/WalletMetadata.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace WalletFramework.Oid4Vc.Oid4Vp.Models; | ||
|
||
public record WalletMetadata | ||
Dindexx marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
private const string VpFormatsSupportedIdentifier = "vp_formats_supported"; | ||
private const string ClientIdPrefixesSupportedIdentifier = "client_id_prefixes_supported"; | ||
//TODO: Remove the following identifier in the future, it is deprecated but kept for backwards compatibility for now. | ||
private const string ClientIdSchemesSupportedIdentifier = "client_id_schemes_supported"; | ||
|
||
public Formats VpFormatsSupported { get; } | ||
|
||
public ClientIdScheme[] ClientIdPrefixesSupported { get; } | ||
|
||
private WalletMetadata(Formats vpFormatsSupported, ClientIdScheme[] clientIdPrefixesSupported) | ||
{ | ||
VpFormatsSupported = vpFormatsSupported; | ||
ClientIdPrefixesSupported = clientIdPrefixesSupported; | ||
} | ||
|
||
public static WalletMetadata CreateDefault() | ||
{ | ||
var vpFormatsSupported = new Formats | ||
{ | ||
SdJwtVcFormat = new SdJwtFormat | ||
{ | ||
IssuerSignedJwtAlgValues = ["ES256", "ES384", "ES512", "RS256"], | ||
KeyBindingJwtAlgValues = ["ES256"] | ||
}, | ||
SdJwtDcFormat = new SdJwtFormat | ||
{ | ||
IssuerSignedJwtAlgValues = ["ES256", "ES384", "ES512", "RS256"], | ||
KeyBindingJwtAlgValues = ["ES256"] | ||
}, | ||
MDocFormat = new MDocFormat | ||
{ | ||
IssuerAuthAlgValues = ["-7", "-35", "-36", "-8"], | ||
DeviceAuthAlgValues = ["-7"] | ||
} | ||
}; | ||
|
||
var clientIdPrefixesSupported = new []{(ClientIdScheme)ClientIdScheme.RedirectUriScheme, (ClientIdScheme)ClientIdScheme.X509SanDnsScheme}; | ||
|
||
return new WalletMetadata(vpFormatsSupported, clientIdPrefixesSupported); | ||
} | ||
|
||
public string ToJsonString() | ||
{ | ||
return new JObject | ||
{ | ||
[VpFormatsSupportedIdentifier] = JObject.FromObject(VpFormatsSupported), | ||
[ClientIdPrefixesSupportedIdentifier] = new JArray {ClientIdPrefixesSupported.Select(x => x.AsString())}, | ||
[ClientIdSchemesSupportedIdentifier] = new JArray {ClientIdPrefixesSupported.Select(x => x.AsString())}, | ||
}.ToString(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.