Skip to content

Commit

Permalink
Improve public key validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Bird authored and IanDBird committed May 3, 2024
1 parent 0c923ba commit 898095f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sdk/src/main/java/com/uid2/utils/KeyUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ internal interface KeyUtils {
}

override fun generateServerPublicKey(publicKey: String): PublicKey? {
// Check to make sure the given public key is longer than the expected prefix.
if (publicKey.length <= SERVER_PUBLIC_KEY_PREFIX_LENGTH) {
return null
}

// Attempt to decode the given public key. If the key is malformed, or not in the expected Base64 format,
// null we be returned.
val serverPublicKeyBytes =
publicKey.substring(SERVER_PUBLIC_KEY_PREFIX_LENGTH).decodeBase64() ?: return null

Expand Down

0 comments on commit 898095f

Please sign in to comment.