Skip to content

Commit

Permalink
FIx: MDoc Issuance
Browse files Browse the repository at this point in the history
  • Loading branch information
josmilan committed Sep 24, 2024
1 parent 3d26f74 commit 6090a2f
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 286 deletions.
1 change: 1 addition & 0 deletions eudi-wallet-oidc-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ dependencies {
}

implementation("com.google.crypto.tink:tink-android:1.7.0")
implementation("co.nstant.in:cbor:0.9")
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data class AuthorizationDetails(

@SerializedName("type") var type: String? = "openid_credential",
@SerializedName("format") var format: String? = null,
@SerializedName("doctype") var doctype: String? = null,
@SerializedName("types") var types: ArrayList<String>? = arrayListOf(),
@SerializedName("locations") var locations: ArrayList<String>? = arrayListOf(),
@SerializedName("credential_definition") var credentialDefinition: CredentialTypeDefinition? = CredentialTypeDefinition()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data class CredentialRequest(
@SerializedName("credential_definition") var credentialDefinition: CredentialDefinition? = null,
@SerializedName("vct") var vct: String? = null,
@SerializedName("format") var format: String? = null,
@SerializedName("doctype") var doctype: String? = null,
@SerializedName("proof") var proof: ProofV3? = null

)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ class CredentialValidator:CredentialValidatorInterface {
* Returns true if the JWT is valid; otherwise, throws IllegalArgumentException with appropriate messages.
*/
@Throws(IllegalArgumentException::class)
override suspend fun validateCredential(jwt: String?, jwksUri: String?): Boolean {
override suspend fun validateCredential(jwt: String?,
jwksUri: String?,
format: String?): Boolean {
if (format == "mso_mdoc")
return true
try {
// Check if the JWT has expired
ExpiryValidator().isJwtExpired(jwt = jwt)
Expand All @@ -33,4 +37,4 @@ class CredentialValidator:CredentialValidatorInterface {
throw IllegalArgumentException("JWT signature invalid")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ interface CredentialValidatorInterface {
* Returns true if the JWT is valid; otherwise, throws IllegalArgumentException with appropriate messages.
*/
@Throws(IllegalArgumentException::class)
suspend fun validateCredential(jwt: String?,jwksUri:String?):Boolean
suspend fun validateCredential(jwt: String?,
jwksUri:String?,
format: String?):Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ class DiscoveryService : DiscoveryServiceInterface {
* @return WrappedIssuerConfigResponse
*/
override suspend fun getIssuerConfig(credentialIssuerWellKnownURI: String?): WrappedIssuerConfigResponse {
var credentialIssuer = credentialIssuerWellKnownURI?.replace("/.well-known/openid-credential-issuer","")
credentialIssuer = removeTrailingSlash(credentialIssuer)
credentialIssuer = "$credentialIssuer/.well-known/openid-credential-issuer"

try {
UrlUtils.validateUri(credentialIssuerWellKnownURI)
UrlUtils.validateUri(credentialIssuer)
val response =
ApiManager.api.getService()
?.fetchIssuerConfig("$credentialIssuerWellKnownURI")
?.fetchIssuerConfig("$credentialIssuer")
return if (response?.isSuccessful == true) {
WrappedIssuerConfigResponse(issuerConfig = response.body(), errorResponse = null)
} else {
Expand All @@ -32,20 +36,29 @@ class DiscoveryService : DiscoveryServiceInterface {
return WrappedIssuerConfigResponse(issuerConfig = null, errorResponse = ErrorResponse(error = null, errorDescription = "URI validation failed"))
}
}

private fun removeTrailingSlash(input: String?): String? {
return if (input?.endsWith("/")==true) {
input?.dropLast(1) // Removes the last character
} else {
input
}
}
/**
* To fetch the authorization server configuration
*
* @param authorisationServerWellKnownURI
* @return WrappedAuthConfigResponse
*/
override suspend fun getAuthConfig(authorisationServerWellKnownURI: String?): WrappedAuthConfigResponse {
var authorizationServer = authorisationServerWellKnownURI?.replace("/.well-known/openid-configuration","")
authorizationServer = removeTrailingSlash(authorizationServer)
authorizationServer = "$authorizationServer/.well-known/openid-configuration"
try {
UrlUtils.validateUri(authorisationServerWellKnownURI)
UrlUtils.validateUri(authorizationServer)

val response =
ApiManager.api.getService()
?.fetchAuthConfig("$authorisationServerWellKnownURI")
?.fetchAuthConfig("$authorizationServer")
return if (response?.isSuccessful == true) {
WrappedAuthConfigResponse(authConfig = response.body(), errorResponse = null)
} else {
Expand Down
Loading

0 comments on commit 6090a2f

Please sign in to comment.