Revision 1177f831
| test/src/info/guardianproject/trustedintents/test/TrustedIntentsTests.java | ||
|---|---|---|
| 1 |
|
|
| 2 |
package info.guardianproject.trustedintents.test; |
|
| 3 |
|
|
| 4 |
import android.content.pm.PackageInfo; |
|
| 5 |
import android.content.pm.PackageManager; |
|
| 6 |
import android.content.pm.PackageManager.NameNotFoundException; |
|
| 7 |
import android.content.pm.Signature; |
|
| 8 |
import android.test.AndroidTestCase; |
|
| 9 |
import android.util.Log; |
|
| 10 |
|
|
| 11 |
import com.android.AndroidIncludedAppsPin; |
|
| 12 |
import com.android.AndroidSystemPin; |
|
| 13 |
|
|
| 14 |
import info.guardianproject.trustedintents.TrustedIntents; |
|
| 15 |
|
|
| 16 |
public class TrustedIntentsTests extends AndroidTestCase {
|
|
| 17 |
private static final String TAG = "TrustedIntentsTests"; |
|
| 18 |
|
|
| 19 |
PackageManager pm; |
|
| 20 |
final String[] packagesSignedBy61ed377e85d386a8dfee6b864bd85b0bfaa5af81 = new String[] {
|
|
| 21 |
"com.android.browser", "com.android.calculator2", "com.android.calendar", |
|
| 22 |
"com.android.dreams.basic", "com.android.providers.calendar", |
|
| 23 |
"com.android.camera", "com.android.deskclock", "com.android.gesture.builder", |
|
| 24 |
"com.android.smoketest", "com.android.smoketest.tests", |
|
| 25 |
"com.android.emulator.connectivity.test", "com.android.development_settings", |
|
| 26 |
"com.android.email", "com.example.android.livecubes", "com.android.exchange" |
|
| 27 |
}; |
|
| 28 |
final String[] packagesSignedBy27196e386b875e76adf700e7ea84e4c6eee33dfa = new String[] {
|
|
| 29 |
"android", "com.android.certinstaller", "com.android.backupconfirm", |
|
| 30 |
"com.android.keyguard", "com.android.sdksetup", "com.android.sharedstoragebackup", |
|
| 31 |
"com.android.customlocale2", "com.android.development", "com.android.documentsui", |
|
| 32 |
"com.android.externalstorage", "com.android.location.fused", "com.android.inputdevices" |
|
| 33 |
}; |
|
| 34 |
|
|
| 35 |
@Override |
|
| 36 |
public void setUp() {
|
|
| 37 |
pm = getContext().getPackageManager(); |
|
| 38 |
} |
|
| 39 |
|
|
| 40 |
private void checkAreSignaturesEqual(String[] packages) {
|
|
| 41 |
Signature[] first = null; |
|
| 42 |
Signature[] second = null; |
|
| 43 |
for (int i = 0; i < packages.length; i++) {
|
|
| 44 |
try {
|
|
| 45 |
PackageInfo pkgInfo = pm.getPackageInfo(packages[i], PackageManager.GET_SIGNATURES); |
|
| 46 |
first = pkgInfo.signatures; |
|
| 47 |
} catch (NameNotFoundException e) {
|
|
| 48 |
Log.w(TAG, "NameNotFoundException: " + e.getMessage()); |
|
| 49 |
continue; |
|
| 50 |
} |
|
| 51 |
for (int j = 0; j < packages.length; j++) {
|
|
| 52 |
if (i == j) |
|
| 53 |
continue; |
|
| 54 |
try {
|
|
| 55 |
PackageInfo pkgInfo = pm.getPackageInfo(packages[j], |
|
| 56 |
PackageManager.GET_SIGNATURES); |
|
| 57 |
second = pkgInfo.signatures; |
|
| 58 |
} catch (NameNotFoundException e) {
|
|
| 59 |
Log.w(TAG, "NameNotFoundException: " + e.getMessage()); |
|
| 60 |
continue; |
|
| 61 |
} |
|
| 62 |
assertTrue(TrustedIntents.get().areSignaturesEqual(first, second)); |
|
| 63 |
} |
|
| 64 |
} |
|
| 65 |
} |
|
| 66 |
|
|
| 67 |
public void testCheckAreSignaturesEqual() {
|
|
| 68 |
checkAreSignaturesEqual(packagesSignedBy61ed377e85d386a8dfee6b864bd85b0bfaa5af81); |
|
| 69 |
checkAreSignaturesEqual(packagesSignedBy27196e386b875e76adf700e7ea84e4c6eee33dfa); |
|
| 70 |
} |
|
| 71 |
|
|
| 72 |
public void testCheckAreSignaturesNotEqual() {
|
|
| 73 |
assertFalse(TrustedIntents.get().areSignaturesEqual( |
|
| 74 |
new AndroidIncludedAppsPin().getSignatures(), |
|
| 75 |
new AndroidSystemPin().getSignatures())); |
|
| 76 |
PackageInfo pkgInfo; |
|
| 77 |
Signature[] first = null; |
|
| 78 |
Signature[] second = null; |
|
| 79 |
int length = packagesSignedBy27196e386b875e76adf700e7ea84e4c6eee33dfa.length; |
|
| 80 |
if (length > packagesSignedBy61ed377e85d386a8dfee6b864bd85b0bfaa5af81.length) |
|
| 81 |
length = packagesSignedBy61ed377e85d386a8dfee6b864bd85b0bfaa5af81.length; |
|
| 82 |
for (int i = 0; i < length; i++) {
|
|
| 83 |
try {
|
|
| 84 |
pkgInfo = pm.getPackageInfo( |
|
| 85 |
packagesSignedBy27196e386b875e76adf700e7ea84e4c6eee33dfa[i], |
|
| 86 |
PackageManager.GET_SIGNATURES); |
|
| 87 |
first = pkgInfo.signatures; |
|
| 88 |
pkgInfo = pm.getPackageInfo( |
|
| 89 |
packagesSignedBy61ed377e85d386a8dfee6b864bd85b0bfaa5af81[i], |
|
| 90 |
PackageManager.GET_SIGNATURES); |
|
| 91 |
second = pkgInfo.signatures; |
|
| 92 |
} catch (NameNotFoundException e) {
|
|
| 93 |
Log.w(TAG, "NameNotFoundException: " + e.getMessage()); |
|
| 94 |
continue; |
|
| 95 |
} |
|
| 96 |
assertFalse(TrustedIntents.get().areSignaturesEqual(first, second)); |
|
| 97 |
} |
|
| 98 |
|
|
| 99 |
} |
|
| 100 |
} |
|
Also available in: Unified diff