@@ -101,37 +101,39 @@ private const val SHA_256_ALGORITHM = "SHA-256"
101101 * EReaderKeyBytes = null
102102 *
103103 * Handover = OID4VPHandover
104- * OID4VPHandover = [
105- * clientIdHash
106- * responseUriHash
107- * nonce
108- * ]
109- *
110- * clientIdHash = bstr
111- * responseUriHash = bstr
112104 *
113- * where clientIdHash is the SHA-256 hash of clientIdToHash and responseUriHash is the SHA-256 hash of the responseUriToHash.
105+ * OpenID4VPHandover = [
106+ * "OpenID4VPHandover", ; A fixed identifier for this handover type
107+ * OpenID4VPHandoverInfoHash ; A cryptographic hash of OpenID4VPHandoverInfo
108+ * ]
114109 *
110+ * ; Contains the sha-256 hash of OpenID4VPHandoverInfoBytes
111+ * OpenID4VPHandoverInfoHash = bstr
115112 *
116- * clientIdToHash = [clientId, mdocGeneratedNonce]
117- * responseUriToHash = [responseUri, mdocGeneratedNonce]
113+ * ; Contains the bytes of OpenID4VPHandoverInfo encoded as CBOR
114+ * OpenID4VPHandoverInfoBytes = bstr .cbor OpenID4VPHandoverInfo
118115 *
116+ * OpenID4VPHandoverInfo = [
117+ * clientId,
118+ * nonce,
119+ * jwkThumbprint,
120+ * responseUri
121+ * ] ; Array containing handover parameters
119122 *
120- * mdocGeneratedNonce = tstr
121123 * clientId = tstr
122- * responseUri = tstr
123124 * nonce = tstr
124- *
125+ * jwkThumbprint = bstr
126+ * responseUri = tstr
125127 */
126128internal fun generateSessionTranscript (
127129 clientId : String ,
128- responseUri : String ,
129130 nonce : String ,
130- mdocGeneratedNonce : String ,
131+ jwkThumbprint : ByteArray? ,
132+ responseOrRedirectUri : String
131133): SessionTranscriptBytes {
132134
133135 val openID4VPHandover =
134- generateOpenId4VpHandover(clientId, responseUri, nonce, mdocGeneratedNonce )
136+ generateOpenId4VpHandover(clientId, nonce, jwkThumbprint, responseOrRedirectUri )
135137
136138 val sessionTranscriptBytes =
137139 CBORObject .NewArray ().apply {
@@ -144,38 +146,36 @@ internal fun generateSessionTranscript(
144146}
145147
146148/* *
147- * Generates the OpenID4VP handover CBOR object containing clientId hash, responseUri hash, and nonce.
149+ * Generates the OpenID4VP handover CBOR object
148150 *
149151 * @param clientId The client identifier.
150- * @param responseUri The response URI .
151- * @param nonce The nonce for the session .
152- * @param mdocGeneratedNonce The generated nonce for mdoc .
153- * @return The handover as a CBORObject .
152+ * @param nonce The nonce value .
153+ * @param jwkThumbprint The JWK thumbprint as a byte array .
154+ * @param responseOrRedirectUri The response URI or redirect URI .
155+ * @return The CBOR object representing the OpenID4VP handover .
154156 */
155157internal fun generateOpenId4VpHandover (
156158 clientId : String ,
157- responseUri : String ,
158159 nonce : String ,
159- mdocGeneratedNonce : String ,
160+ jwkThumbprint : ByteArray? ,
161+ responseOrRedirectUri : String ,
160162): CBORObject {
161- val clientIdToHash = CBORObject .NewArray ().apply {
162- Add (clientId)
163- Add (mdocGeneratedNonce)
164- }.EncodeToBytes ()
165163
166- val responseUriToHash = CBORObject .NewArray ().apply {
167- Add (responseUri)
168- Add (mdocGeneratedNonce)
164+ val openID4VPHandoverInfoBytes = CBORObject .NewArray ().apply {
165+ Add (clientId)
166+ Add (nonce)
167+ Add (jwkThumbprint ? : CBORObject .Null )
168+ Add (responseOrRedirectUri)
169169 }.EncodeToBytes ()
170170
171- val clientIdHash = MessageDigest .getInstance(SHA_256_ALGORITHM ).digest(clientIdToHash )
172- val responseUriHash = MessageDigest .getInstance( SHA_256_ALGORITHM ). digest(responseUriToHash )
171+ val openID4VPHandoverInfoHash = MessageDigest .getInstance(SHA_256_ALGORITHM )
172+ . digest(openID4VPHandoverInfoBytes )
173173
174174 val openID4VPHandover = CBORObject .NewArray ().apply {
175- Add (clientIdHash)
176- Add (responseUriHash)
177- Add (nonce)
175+ Add (" OpenID4VPHandover" )
176+ Add (openID4VPHandoverInfoHash)
178177 }
178+
179179 return openID4VPHandover
180180}
181181
@@ -232,24 +232,25 @@ internal fun makeOpenId4VPConfig(
232232/* *
233233 * Extension function to get the session transcript bytes from a resolved OpenID4VP authorization request.
234234 *
235- * @param mdocGeneratedNonce The generated nonce for mdoc.
236235 * @return The session transcript as a byte array.
237236 */
238- internal fun ResolvedRequestObject.getSessionTranscriptBytes (
239- mdocGeneratedNonce : String ,
240- ): SessionTranscriptBytes {
241- val clientId = this .client.id.clientId
242- val responseUri = when (val mode = this .responseMode) {
237+ internal fun ResolvedRequestObject.getSessionTranscriptBytes (): SessionTranscriptBytes {
238+ val clientId = client.id.clientId
239+ val nonce = nonce
240+ val jwkThumbprint = responseEncryptionSpecification?.recipientKey?.computeThumbprint()?.decode()
241+ val responseOrRedirectUri = when (val mode = this .responseMode) {
243242 is ResponseMode .DirectPostJwt -> mode.responseURI.toString()
244- else -> " "
243+ is ResponseMode .DirectPost -> mode.responseURI.toString()
244+ is ResponseMode .Fragment -> mode.redirectUri.toString()
245+ is ResponseMode .FragmentJwt -> mode.redirectUri.toString()
246+ is ResponseMode .Query -> mode.redirectUri.toString()
247+ is ResponseMode .QueryJwt -> mode.redirectUri.toString()
245248 }
246- val nonce = this .nonce
247-
248249 val sessionTranscriptBytes = generateSessionTranscript(
249- clientId,
250- responseUri ,
251- nonce ,
252- mdocGeneratedNonce
250+ clientId = clientId ,
251+ nonce = nonce ,
252+ jwkThumbprint = jwkThumbprint ,
253+ responseOrRedirectUri = responseOrRedirectUri
253254 )
254255 return sessionTranscriptBytes
255256}
0 commit comments