Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does one verify that an APK has not been tampered with?

Tags:

android

apk

A vanilla Android rom (AOSP) does not contain Google Apps. If I download Google Apps from another source, how can I verify that it has not been tampered with ?

like image 900
Rahul Iyer Avatar asked Sep 15 '15 06:09

Rahul Iyer


People also ask

How do I make sure an APK file is safe?

A good way to check an APK file is by checking its hash. The SHA of a file is a kind of digital fingerprint which ensures that data is not modified or tampered with. You should use Hash Droid- a useful app to check the hash on your phone.

How do I stop APK tampering?

Tip: Keep your private key (. keystore file) out of source control and in a separately secured and backed-up system. The app signature will be broken if the . apk is altered in any way — unsigned apps cannot typically be installed.

How do you verify an app on Android?

The Verify apps feature helps you protect your phone from potentially harmful apps. When it's turned on, your phone will be able to block the installation of apps and remove apps if security threats are detected. Go to Settings > Google > Security. Under Verify apps, turn on Scan device for security threats.

How to check if an APK file is real or not?

A good way to check an APK file is by checking its hash. The SHA of a file is a kind of digital fingerprint which ensures that data is not modified or tampered with. You should use Hash Droid- a useful app to check the hash on your phone.

How to check if an APK file is unmodified?

After checking an apk file on HashDroid, you access APKTOVI Checker Tool, hit “Click Upload APK File” and upload the apk file that you have checked by HashDroid. Then, let’s wait for the file to be uploaded and scanned. You will see the result of SHA1 of this APK file and a notification about whether your file is unmodified or not.

How to check for viruses on APK files?

VirusTotal is an extremely famous website which helps people to check for viruses and other issues of an apk file. However, the file size limited is under 128MB. – Click on Choose File, then choose the file you want to scan in the browser dialogue box and then wait a minute to get the result.

How can I tell if my app has been tampered with?

To help your app detect tampering, we looked at identifying telltale signs of emulation and third-party debugging with environment checks. We introduced a quick and easy way to confirm the installer of your app, and — perhaps most importantly — how to verify that your app is still signed with your developer signature.


1 Answers

Each apk is signed with release key. If apk is de-compiled and recompiled then new apk must be signed with a different release key (as each release key need a password which only developer/company know). So you can verify the authenticity of your apk by checking the sha1 of your key. Hope it helps

EDIT: You must use web services to verify validity of your app(like what facebook does)

  1. You must execute this on your release key to get key hash of your app ie.keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64.
  2. Obtained key hash must be saved at your server and must be fetched using web services.
  3. Obtain key hash programmatically using the following code. Verify if both values are same.

    try {
        PackageInfo info = getPackageManager().getPackageInfo(
                "com.play.fabin",  //Replace your package name here
                PackageManager.GET_SIGNATURES);
    
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA1");
            md.update(signature.toByteArray());
            Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
            System.out.println("key hash = " + Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    

Hope it helps you..

like image 167
Fabin Paul Avatar answered Oct 19 '22 17:10

Fabin Paul