-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Niganesh/validate open id4 vci network responses (#73)
Co-authored-by: Nithya Ganesh <[email protected]> Co-authored-by: Logan <[email protected]>
- Loading branch information
1 parent
d2a61ff
commit 28ab3a8
Showing
21 changed files
with
1,145 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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
14 changes: 14 additions & 0 deletions
14
...etlibrary/src/main/java/com/microsoft/walletlibrary/mappings/IdentifierDocumentMapping.kt
This file contains 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,14 @@ | ||
package com.microsoft.walletlibrary.mappings | ||
|
||
import com.microsoft.walletlibrary.did.sdk.identifier.models.identifierdocument.IdentifierDocument | ||
import com.nimbusds.jose.jwk.JWK | ||
|
||
internal fun IdentifierDocument.getJwk(id: String): JWK? { | ||
if (verificationMethod.isNullOrEmpty()) return null | ||
for (publicKey in verificationMethod) { | ||
if (publicKey.id == id) { | ||
return publicKey.publicKeyJwk | ||
} | ||
} | ||
return null | ||
} |
14 changes: 14 additions & 0 deletions
14
...brary/src/main/java/com/microsoft/walletlibrary/mappings/LinkedDomainsServiceExtension.kt
This file contains 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,14 @@ | ||
package com.microsoft.walletlibrary.mappings | ||
|
||
import com.microsoft.walletlibrary.did.sdk.LinkedDomainsService | ||
import com.microsoft.walletlibrary.did.sdk.credential.service.models.linkedDomains.LinkedDomainResult | ||
import com.microsoft.walletlibrary.did.sdk.identifier.models.identifierdocument.IdentifierDocument | ||
import com.microsoft.walletlibrary.did.sdk.util.controlflow.SdkException | ||
|
||
internal suspend fun LinkedDomainsService.fetchAndVerifyLinkedDomains(identifierDocument: IdentifierDocument): Result<LinkedDomainResult> { | ||
val linkedDomains = getLinkedDomainsFromDidDocument(identifierDocument) | ||
verifyLinkedDomains(linkedDomains, identifierDocument.id) | ||
.onSuccess { return Result.success(it) } | ||
.onFailure { return Result.failure(it) } | ||
return Result.failure(SdkException("Failed while verifying linked domains")) | ||
} |
This file contains 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
73 changes: 73 additions & 0 deletions
73
...letlibrary/networking/entities/openid4vci/credentialmetadata/SignedMetadataTokenClaims.kt
This file contains 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,73 @@ | ||
package com.microsoft.walletlibrary.networking.entities.openid4vci.credentialmetadata | ||
|
||
import com.microsoft.walletlibrary.util.TokenValidationException | ||
import com.microsoft.walletlibrary.util.VerifiedIdExceptions | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class SignedMetadataTokenClaims( | ||
val sub: String?, | ||
val iat: String?, | ||
val exp: String? = null, | ||
val iss: String?, | ||
val nbf: String? = null | ||
) { | ||
fun validateSignedMetadataTokenClaims(expectedSubject: String, expectedIssuer: String) { | ||
validateSubject(expectedSubject) | ||
validateIssuer(expectedIssuer) | ||
validateIssuedAtTime() | ||
validateExpiryTime() | ||
} | ||
|
||
private fun validateIssuer(expectedIssuer: String) { | ||
if (iss == null) { | ||
throw TokenValidationException( | ||
"Issuer property missing in signed metadata.", | ||
VerifiedIdExceptions.INVALID_PROPERTY_EXCEPTION.value | ||
) | ||
} | ||
if (iss != expectedIssuer) { | ||
throw TokenValidationException( | ||
"Invalid issuer property in signed metadata.", | ||
VerifiedIdExceptions.INVALID_PROPERTY_EXCEPTION.value | ||
) | ||
} | ||
} | ||
|
||
private fun validateSubject(expectedSubject: String) { | ||
if (sub == null) { | ||
throw TokenValidationException( | ||
"Subject property missing in signed metadata.", | ||
VerifiedIdExceptions.INVALID_PROPERTY_EXCEPTION.value | ||
) | ||
} | ||
if (sub != expectedSubject) { | ||
throw TokenValidationException( | ||
"Invalid subject property in signed metadata.", | ||
VerifiedIdExceptions.INVALID_PROPERTY_EXCEPTION.value | ||
) | ||
} | ||
} | ||
|
||
private fun validateIssuedAtTime() { | ||
if (iat != null && iat.toLong() >= getCurrentTimeInSecondsWithSkew()) { | ||
throw TokenValidationException( | ||
"Issued at time is in the future.", | ||
VerifiedIdExceptions.INVALID_PROPERTY_EXCEPTION.value | ||
) | ||
} | ||
} | ||
|
||
private fun validateExpiryTime() { | ||
if (exp != null && exp.toLong() <= getCurrentTimeInSecondsWithSkew()) { | ||
throw TokenValidationException( | ||
"Token has expired.", | ||
VerifiedIdExceptions.INVALID_PROPERTY_EXCEPTION.value | ||
) | ||
} | ||
} | ||
|
||
private fun getCurrentTimeInSecondsWithSkew(skew: Long = 300): Long { | ||
return (System.currentTimeMillis() / 1000) + skew | ||
} | ||
} |
This file contains 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.