diff --git a/app/src/main/java/foundation/e/apps/application/model/IntegrityVerificationTask.kt b/app/src/main/java/foundation/e/apps/application/model/IntegrityVerificationTask.kt
index d926bdbef08dac0c3499e592faf0245c4625035a..3df24a406b8fef5091e6730e623b5e44691f5ff2 100644
--- a/app/src/main/java/foundation/e/apps/application/model/IntegrityVerificationTask.kt
+++ b/app/src/main/java/foundation/e/apps/application/model/IntegrityVerificationTask.kt
@@ -19,6 +19,10 @@ package foundation.e.apps.application.model
import android.content.Context
import android.os.AsyncTask
+import android.os.Handler
+import android.os.Looper
+import android.widget.Toast
+import foundation.e.apps.R
import foundation.e.apps.application.model.data.FullData
import foundation.e.apps.utils.Constants
import org.bouncycastle.jce.provider.BouncyCastleProvider
@@ -53,6 +57,7 @@ class IntegrityVerificationTask(
} else {
Security.addProvider(BouncyCastleProvider())
verifyAPKSignature(
+ context[0],
BufferedInputStream(FileInputStream(
applicationInfo.getApkFile(context[0],
fullData.basicData).absolutePath)),
@@ -88,44 +93,56 @@ class IntegrityVerificationTask(
}
private fun verifyAPKSignature(
+ context: Context,
apkInputStream: BufferedInputStream,
apkSignatureInputStream: InputStream,
publicKeyInputStream: InputStream): Boolean {
+ try {
- var jcaPGPObjectFactory =
- JcaPGPObjectFactory(PGPUtil.getDecoderStream(apkSignatureInputStream))
- val pgpSignatureList: PGPSignatureList
+ var jcaPGPObjectFactory =
+ JcaPGPObjectFactory(PGPUtil.getDecoderStream(apkSignatureInputStream))
+ val pgpSignatureList: PGPSignatureList
- val pgpObject = jcaPGPObjectFactory.nextObject()
- if (pgpObject is PGPCompressedData) {
- jcaPGPObjectFactory = JcaPGPObjectFactory(pgpObject.dataStream)
- pgpSignatureList = jcaPGPObjectFactory.nextObject() as PGPSignatureList
- } else {
- pgpSignatureList = pgpObject as PGPSignatureList
- }
+ val pgpObject = jcaPGPObjectFactory.nextObject()
+ if (pgpObject is PGPCompressedData) {
+ jcaPGPObjectFactory = JcaPGPObjectFactory(pgpObject.dataStream)
+ pgpSignatureList = jcaPGPObjectFactory.nextObject() as PGPSignatureList
+ } else {
+ pgpSignatureList = pgpObject as PGPSignatureList
+ }
- val pgpPublicKeyRingCollection =
- PGPPublicKeyRingCollection(
- PGPUtil.getDecoderStream(publicKeyInputStream),
- JcaKeyFingerprintCalculator())
+ val pgpPublicKeyRingCollection =
+ PGPPublicKeyRingCollection(
+ PGPUtil.getDecoderStream(publicKeyInputStream),
+ JcaKeyFingerprintCalculator())
- val signature = pgpSignatureList.get(0)
- val key = pgpPublicKeyRingCollection.getPublicKey(signature.keyID)
+ val signature = pgpSignatureList.get(0)
+ val key = pgpPublicKeyRingCollection.getPublicKey(signature.keyID)
- signature.init(BcPGPContentVerifierBuilderProvider(), key)
+ signature.init(BcPGPContentVerifierBuilderProvider(), key)
- val buff = ByteArray(1024)
- var read = apkInputStream.read(buff)
- while (read != -1) {
- signature.update(buff, 0, read)
- read = apkInputStream.read(buff)
- }
+ val buff = ByteArray(1024)
+ var read = apkInputStream.read(buff)
+ while (read != -1) {
+ signature.update(buff, 0, read)
+ read = apkInputStream.read(buff)
+ }
+
+ apkInputStream.close()
+ apkSignatureInputStream.close()
+ publicKeyInputStream.close()
+ return signature.verify()
+ } catch (e: Exception) {
+ e.printStackTrace()
- apkInputStream.close()
- apkSignatureInputStream.close()
- publicKeyInputStream.close()
+ Handler(Looper.getMainLooper()).post {
+ val toast = Toast.makeText(context, context.resources.getString(R.string.Signature_verification_failed), Toast.LENGTH_LONG)
+ toast.show()
+ }
+
+ }
- return signature.verify()
+ return false;
}
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 052f5378ff4c4f6d4afa2ac2b9c4e73859e9ed2a..fdf453173b358c6d3b845da20a978ed88a9a3c06 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -184,4 +184,9 @@
Not Installed
Installed
+
+ Signature verification failed, aborting install
+
+
+