Skip to content

Commit 480c568

Browse files
authored
Revert "Align mdoc response with oid4vp1.0 (#394)" (#414)
* Revert "Align mdoc response with oid4vp1.0 (#394)" This reverts commit bfeaf9b. Signed-off-by: Johannes Tuerk <[email protected]> * add TargetFramework adjustments and SdJwtLib fix Signed-off-by: Johannes Tuerk <[email protected]> --------- Signed-off-by: Johannes Tuerk <[email protected]>
1 parent 31cb738 commit 480c568

File tree

9 files changed

+106
-204
lines changed

9 files changed

+106
-204
lines changed

src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Implementations/CredentialRequestService.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Text;
22
using LanguageExt;
3-
using Microsoft.IdentityModel.Tokens;
43
using OneOf;
54
using WalletFramework.Core.Cryptography.Abstractions;
65
using WalletFramework.Core.Cryptography.Models;
@@ -70,13 +69,8 @@ await authorizationRequest.Match(
7069
Some: _ =>
7170
{
7271
if (format == Constants.MdocFormat)
73-
{
74-
var handover = OpenId4VpHandover.FromAuthorizationRequest(
75-
authorizationRequest.UnwrapOrThrow(new Exception()),
76-
Option<JsonWebKey>.None);
77-
sessionTranscript = handover.ToSessionTranscript();
78-
}
79-
72+
sessionTranscript = authorizationRequest.UnwrapOrThrow(new Exception()).ToVpHandover()
73+
.ToSessionTranscript();
8074
return Task.CompletedTask;
8175
},
8276
None: async () => await keyId.IfSomeAsync(async id =>
Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
11
using LanguageExt;
2-
using Microsoft.IdentityModel.Tokens;
32
using PeterO.Cbor;
43
using WalletFramework.Core.Cryptography.Models;
5-
using WalletFramework.Core.Functional;
64
using WalletFramework.MdocLib.Device;
75
using WalletFramework.MdocLib.Security;
86
using WalletFramework.MdocLib.Security.Abstractions;
9-
using WalletFramework.Oid4Vc.Oid4Vp.Jwk;
107
using WalletFramework.Oid4Vc.Oid4Vp.Models;
118
using static WalletFramework.Oid4Vc.Oid4Vp.Models.Nonce;
129

1310
namespace WalletFramework.Oid4Vc.Oid4Vp.DcApi.Models;
1411

1512
/// <summary>
16-
/// Represents OpenID4VPDCAPIHandover according to the OpenID4VP specification.
17-
/// Contains a fixed identifier and the SHA-256 hash of OpenID4VPDCAPIHandoverInfo
18-
/// Structure: ["OpenID4VPDCAPIHandover", OpenID4VPDCAPIHandoverInfoHash]
13+
/// Represents OpenID4VPDCAPIHandover according to the OpenID4VP specification.
14+
/// Contains a fixed identifier and the SHA-256 hash of OpenID4VPDCAPIHandoverInfo
15+
/// Structure: ["OpenID4VPDCAPIHandover", OpenID4VPDCAPIHandoverInfoHash]
1916
/// </summary>
2017
public record OpenId4VpDcApiHandover(OpenId4VpDcApiHandoverInfo HandoverInfo) : IHandover
2118
{
2219
/// <summary>
23-
/// Mdoc generated nonce created during handover initialization
20+
/// Mdoc generated nonce created during handover initialization
2421
/// </summary>
2522
public Nonce MdocGeneratedNonce { get; } = GenerateNonce();
23+
24+
/// <summary>
25+
/// Fixed identifier for this handover type
26+
/// </summary>
27+
public const string HandoverTypeIdentifier = "OpenID4VPDCAPIHandover";
2628

2729
/// <summary>
28-
/// Converts the handover to CBOR representation as an array
30+
/// Converts the handover to CBOR representation as an array
2931
/// </summary>
3032
/// <returns>CBOR array containing [identifier, hash]</returns>
3133
public CBORObject ToCbor()
3234
{
3335
var result = CBORObject.NewArray();
34-
35-
result.Add(HandoverConstants.DcApiHandoverTypeIdentifier);
36+
37+
result.Add(HandoverTypeIdentifier);
3638
result.Add(HandoverInfo.ToHash().AsBytes);
3739

3840
return result;
@@ -53,16 +55,4 @@ public SessionTranscript ToSessionTranscript()
5355
);
5456
}
5557

56-
public static OpenId4VpDcApiHandover FromAuthorizationRequest(AuthorizationRequest request, Origin origin, Option<JsonWebKey> verifierPublicKey)
57-
{
58-
var encryptionKey = verifierPublicKey.OnSome(JwkFun.GetThumbprint);
59-
60-
var handoverInfo = new OpenId4VpDcApiHandoverInfo(
61-
origin,
62-
request.Nonce,
63-
encryptionKey
64-
);
65-
66-
return new OpenId4VpDcApiHandover(handoverInfo);
67-
}
6858
}

src/WalletFramework.Oid4Vc/Oid4Vp/DcApi/Models/OpenId4VpDcApiHandoverInfo.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
namespace WalletFramework.Oid4Vc.Oid4Vp.DcApi.Models;
66

77
/// <summary>
8-
/// Represents OpenID4VPDCAPIHandoverInfo according to the OpenID4VP specification.
9-
/// Contains the handover parameters as a CBOR array: [origin, nonce, jwkThumbprint]
8+
/// Represents OpenID4VPDCAPIHandoverInfo according to the OpenID4VP specification.
9+
/// Contains the handover parameters as a CBOR array: [origin, nonce, jwkThumbprint]
1010
/// </summary>
1111
public record OpenId4VpDcApiHandoverInfo(
1212
Origin Origin,
1313
string Nonce,
1414
Option<byte[]> JwkThumbprint)
1515
{
1616
/// <summary>
17-
/// Converts the handover info to CBOR representation as an array
17+
/// Converts the handover info to CBOR representation as an array
1818
/// </summary>
1919
/// <returns>CBOR array containing [origin, nonce, jwkThumbprint]</returns>
2020
public CBORObject ToCbor()
@@ -33,13 +33,13 @@ public CBORObject ToCbor()
3333
}
3434

3535
/// <summary>
36-
/// Encodes the handover info as CBOR bytes
36+
/// Encodes the handover info as CBOR bytes
3737
/// </summary>
3838
/// <returns>CBOR-encoded bytes of the handover info</returns>
3939
public byte[] ToCborBytes() => ToCbor().EncodeToBytes();
4040

4141
/// <summary>
42-
/// Computes the SHA-256 hash of the handover info CBOR bytes
42+
/// Computes the SHA-256 hash of the handover info CBOR bytes
4343
/// </summary>
4444
/// <returns>SHA-256 hash of the CBOR-encoded handover info</returns>
4545
public Sha256Hash ToHash()

src/WalletFramework.Oid4Vc/Oid4Vp/HandoverConstants.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using LanguageExt;
2+
using PeterO.Cbor;
3+
using WalletFramework.Core.Cryptography.Models;
4+
using WalletFramework.Core.Encoding;
5+
using WalletFramework.MdocLib.Device;
6+
using WalletFramework.MdocLib.Security;
7+
using WalletFramework.MdocLib.Security.Abstractions;
8+
using static WalletFramework.Core.Encoding.Sha256Hash;
9+
using static WalletFramework.Oid4Vc.Oid4Vp.Models.Nonce;
10+
11+
namespace WalletFramework.Oid4Vc.Oid4Vp.Models;
12+
13+
public record Oid4VpHandover(
14+
Sha256Hash ClientIdSha256Hash,
15+
Sha256Hash ResponseUriSha256Hash,
16+
// TODO: Nonce from AuthRequest has weak type
17+
string Nonce,
18+
Nonce MdocGeneratedNonce) : IHandover
19+
{
20+
public CBORObject ToCbor()
21+
{
22+
var result = CBORObject.NewArray();
23+
24+
result.Add(ClientIdSha256Hash.AsBytes);
25+
result.Add(ResponseUriSha256Hash.AsBytes);
26+
result.Add(Nonce);
27+
28+
return result;
29+
}
30+
31+
public SessionTranscript ToSessionTranscript() => new(
32+
Option<DeviceEngagement>.None,
33+
Option<PublicKey>.None,
34+
this);
35+
}
36+
37+
public static class Oid4VpHandoverFun
38+
{
39+
public static Oid4VpHandover ToVpHandover(this AuthorizationRequest request)
40+
{
41+
var mdocGeneratedNonce = GenerateNonce();
42+
43+
var clientIdToHash = CBORObject.NewArray();
44+
var clientId = CBORObject.FromObject(request.ClientId);
45+
46+
clientIdToHash.Add(clientId);
47+
clientIdToHash.Add(mdocGeneratedNonce.AsHex);
48+
var clientIdToHashBytes = clientIdToHash.EncodeToBytes();
49+
50+
var responseUriToHash = CBORObject.NewArray();
51+
var responseUri = CBORObject.FromObject(request.ResponseUri);
52+
53+
responseUriToHash.Add(responseUri);
54+
responseUriToHash.Add(mdocGeneratedNonce.AsHex);
55+
var responseUriToHashBytes = responseUriToHash.EncodeToBytes();
56+
57+
var clientIdHash = ComputeHash(clientIdToHashBytes);
58+
var responseUriHash = ComputeHash(responseUriToHashBytes);
59+
60+
return new Oid4VpHandover(clientIdHash, responseUriHash, request.Nonce, mdocGeneratedNonce);
61+
}
62+
}

src/WalletFramework.Oid4Vc/Oid4Vp/Models/OpenId4VpHandover.cs

Lines changed: 0 additions & 70 deletions
This file was deleted.

src/WalletFramework.Oid4Vc/Oid4Vp/Models/OpenId4VpHandoverInfo.cs

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/WalletFramework.Oid4Vc/Oid4Vp/Services/Oid4VpClientService.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public Oid4VpClientService(
7575
IOid4VpHaipClient oid4VpHaipClient,
7676
IOid4VpRecordService oid4VpRecordService,
7777
IPresentationService presentationService,
78-
IVerifierKeyService verifierKeyService,
7978
ISdJwtVcHolderService sdJwtVcHolderService)
8079
{
8180
_agentProvider = agentProvider;
@@ -90,7 +89,6 @@ public Oid4VpClientService(
9089
_oid4VpHaipClient = oid4VpHaipClient;
9190
_oid4VpRecordService = oid4VpRecordService;
9291
_presentationService = presentationService;
93-
_verifierKeyService = verifierKeyService;
9492
_sdJwtVcHolderService = sdJwtVcHolderService;
9593
}
9694

@@ -106,7 +104,6 @@ public Oid4VpClientService(
106104
private readonly IOid4VpHaipClient _oid4VpHaipClient;
107105
private readonly IOid4VpRecordService _oid4VpRecordService;
108106
private readonly IPresentationService _presentationService;
109-
private readonly IVerifierKeyService _verifierKeyService;
110107
private readonly ISdJwtVcHolderService _sdJwtVcHolderService;
111108

112109
public async Task<Option<Uri>> AbortAuthorizationRequest(AuthorizationRequestCancellation cancellation)
@@ -224,7 +221,7 @@ await credentialSetMdocRecords.Match(
224221

225222
switch (presentation.PresentedCredential)
226223
{
227-
case SdJwtRecord sdJwtRecord:
224+
case SdJwtRecord sdJwtRecord:
228225
var issuanceSdJwtDoc = sdJwtRecord.ToSdJwtDoc();
229226
var sdJwtDoc = new SdJwtDoc(presentation.PresentationMap.Presentation);
230227

@@ -242,7 +239,7 @@ from claim in sdJwtRecord.Claims
242239
key = claim.Key,
243240
value = new PresentedClaim { Value = claim.Value }
244241
};
245-
242+
246243
result = new PresentedCredentialSet
247244
{
248245
SdJwtCredentialType = Vct.ValidVct(sdJwtRecord.Vct).UnwrapOrThrow(),
@@ -411,14 +408,7 @@ public async Task<Option<Uri>> AcceptOnDemandRequest(
411408

412409
var mdoc = mdocRecord.Mdoc.SelectivelyDisclose(toDisclose);
413410

414-
var responseEncryptionKey = authorizationRequest.ResponseMode == AuthorizationRequest.DirectPostJwt
415-
? await _verifierKeyService.GetPublicKey(authorizationRequest)
416-
: Option<JsonWebKey>.None;
417-
418-
var handover = OpenId4VpHandover.FromAuthorizationRequest(
419-
authorizationRequest,
420-
responseEncryptionKey);
421-
411+
var handover = authorizationRequest.ToVpHandover();
422412
mdocNonce = handover.MdocGeneratedNonce;
423413
var sessionTranscript = handover.ToSessionTranscript();
424414

0 commit comments

Comments
 (0)