Skip to content

Commit 6a35919

Browse files
committed
Support vci 1.0 for sdjwts
1 parent e404872 commit 6a35919

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

app/src/main/java/com/credman/cmwallet/createcred/CreateCredentialViewModel.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@ import com.credman.cmwallet.mdoc.MDoc
2929
import com.credman.cmwallet.openid4vci.OpenId4VCI
3030
import com.credman.cmwallet.openid4vci.data.AuthorizationDetailResponseOpenIdCredential
3131
import com.credman.cmwallet.openid4vci.data.CredentialConfigurationMDoc
32+
import com.credman.cmwallet.openid4vci.data.CredentialConfigurationSdJwtVc
3233
import com.credman.cmwallet.openid4vci.data.CredentialRequest
3334
import com.credman.cmwallet.openid4vci.data.GrantAuthorizationCode
3435
import com.credman.cmwallet.openid4vci.data.TokenRequest
3536
import com.credman.cmwallet.openid4vci.data.TokenResponse
3637
import com.credman.cmwallet.openid4vci.data.imageUriToImageB64
3738
import com.credman.cmwallet.openid4vp.OpenId4VP
39+
import com.credman.cmwallet.sdjwt.IssuerJwt
40+
import com.credman.cmwallet.toBase64UrlNoPadding
3841
import com.credman.cmwallet.toFixedByteArray
3942
import kotlinx.coroutines.launch
4043
import org.json.JSONObject
@@ -148,6 +151,16 @@ class CreateCredentialViewModel : ViewModel() {
148151
x == deviceKey.first && y == deviceKey.second
149152
}
150153
}
154+
is CredentialConfigurationSdJwtVc -> {
155+
val issuerJwtString = it.credential.split('~')[0]
156+
val cnfKey = IssuerJwt(issuerJwtString).payload.getJSONObject("cnf").getJSONObject("jwk")
157+
deviceKeys.firstOrNull {
158+
val public = it.public as ECPublicKey
159+
val x = public.w.affineX.toFixedByteArray(32).toBase64UrlNoPadding()
160+
val y = public.w.affineY.toFixedByteArray(32).toBase64UrlNoPadding()
161+
x == cnfKey.getString("x") && y == cnfKey.getString("y")
162+
}
163+
}
151164
else -> throw UnsupportedOperationException("Unknown configuration $config")
152165
}
153166
Credential(

app/src/main/java/com/credman/cmwallet/sdjwt/SdJwt.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import java.math.BigInteger
99
import java.nio.ByteBuffer
1010
import java.security.MessageDigest
1111
import android.util.Base64
12-
import android.util.Log
1312
import com.credman.cmwallet.createJWTES256
1413
import com.credman.cmwallet.jwsDeserialization
1514
import com.credman.cmwallet.loadECPrivateKey
@@ -126,7 +125,7 @@ class VerificationResult(
126125
)
127126

128127
fun verify(issuerJwtSerialization: String, disclosures: List<String>): VerificationResult {
129-
val issuerJwt = Jwt(issuerJwtSerialization)
128+
val issuerJwt = IssuerJwt(issuerJwtSerialization)
130129

131130
if (issuerJwt.payload.has("_sd_alg")) {
132131
assert(issuerJwt.payload["_sd_alg"] == "sha-256") {"Only support sha-256"}
@@ -212,7 +211,7 @@ private fun verifyInternal(
212211
}
213212
}
214213

215-
class Jwt {
214+
class IssuerJwt {
216215
var header: JSONObject = JSONObject()
217216
var payload: JSONObject = JSONObject()
218217
private lateinit var signature: ByteArray

0 commit comments

Comments
 (0)