Skip to content

Commit 898095f

Browse files
Ian BirdIanDBird
authored andcommitted
Improve public key validation
1 parent 0c923ba commit 898095f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

sdk/src/main/java/com/uid2/utils/KeyUtils.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ internal interface KeyUtils {
5656
}
5757

5858
override fun generateServerPublicKey(publicKey: String): PublicKey? {
59+
// Check to make sure the given public key is longer than the expected prefix.
60+
if (publicKey.length <= SERVER_PUBLIC_KEY_PREFIX_LENGTH) {
61+
return null
62+
}
63+
64+
// Attempt to decode the given public key. If the key is malformed, or not in the expected Base64 format,
65+
// null we be returned.
5966
val serverPublicKeyBytes =
6067
publicKey.substring(SERVER_PUBLIC_KEY_PREFIX_LENGTH).decodeBase64() ?: return null
6168

0 commit comments

Comments
 (0)