6e842eac315e

fix license verifySignature to use Bouncy Castle Ed25519 instead of java.security KeyFactory/Signature - the JCA 'Ed25519' algorithm name routes to AndroidKeyStore's provider on-device, which only accepts KeyGenParameterSpec-generated keys and throws InvalidKeySpecException on any imported public key, silently swallowed to false; confirmed root cause via instrumented on-device test capturing the real exception, confirmed fix with the real test key validating true on-device

time
2026-07-24 11:52 UTC · 3 months ago
machine
koh2
agent
claude-sonnet-5
session
critical-corrections-c1-c7
parent
aea3a3106d8e
1 file app/src/main/java/com/peachpasswords/license/LicenseRepository.kt+6 −14
app/src/main/java/com/peachpasswords/license/LicenseRepository.kt+6 −14
@@ -5,11 +5,10 @@55 import androidx.security.crypto.MasterKey66 import dagger.hilt.android.qualifiers.ApplicationContext77 import java.math.BigInteger8-import java.security.KeyFactory9-import java.security.Signature10-import java.security.spec.X509EncodedKeySpec118 import javax.inject.Inject129 import javax.inject.Singleton10+import org.bouncycastle.crypto.params.Ed25519PublicKeyParameters11+import org.bouncycastle.crypto.signers.Ed25519Signer1312 1413 @Singleton1514 class LicenseRepository @Inject constructor(@ApplicationContext context: Context) {@@ -115,17 +114,10 @@115114     private fun verifySignature(payload: ByteArray, signature: ByteArray): Boolean {116115         return try {117116             val publicKeyBytes = hexToBytes(PUBLIC_KEY_HEX)118-            val keyFactory = KeyFactory.getInstance("Ed25519")119-            val derPrefix = byteArrayOf(120-                0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65,121-                0x70, 0x03, 0x21, 0x00,122-            )123-            val encoded = derPrefix + publicKeyBytes124-            val publicKey = keyFactory.generatePublic(X509EncodedKeySpec(encoded))125-            val sig = Signature.getInstance("Ed25519")126-            sig.initVerify(publicKey)127-            sig.update(payload)128-            sig.verify(signature)117+            val verifier = Ed25519Signer()118+            verifier.init(false, Ed25519PublicKeyParameters(publicKeyBytes, 0))119+            verifier.update(payload, 0, payload.size)120+            verifier.verifySignature(signature)129121         } catch (_: Exception) {130122             false131123         }

view file