use of android.content.pm.Signature in project android_frameworks_base by DirtyUnicorns.
the class PackageSignatures method writeXml.
void writeXml(XmlSerializer serializer, String tagName, ArrayList<Signature> pastSignatures) throws IOException {
if (mSignatures == null) {
return;
}
serializer.startTag(null, tagName);
serializer.attribute(null, "count", Integer.toString(mSignatures.length));
for (int i = 0; i < mSignatures.length; i++) {
serializer.startTag(null, "cert");
final Signature sig = mSignatures[i];
final int sigHash = sig.hashCode();
final int numPast = pastSignatures.size();
int j;
for (j = 0; j < numPast; j++) {
Signature pastSig = pastSignatures.get(j);
if (pastSig.hashCode() == sigHash && pastSig.equals(sig)) {
serializer.attribute(null, "index", Integer.toString(j));
break;
}
}
if (j >= numPast) {
pastSignatures.add(sig);
serializer.attribute(null, "index", Integer.toString(numPast));
serializer.attribute(null, "key", sig.toCharsString());
}
serializer.endTag(null, "cert");
}
serializer.endTag(null, tagName);
}
use of android.content.pm.Signature in project android_frameworks_base by DirtyUnicorns.
the class PackageManagerService method compareSignaturesCompat.
/**
* Used for backward compatibility to make sure any packages with
* certificate chains get upgraded to the new style. {@code existingSigs}
* will be in the old format (since they were stored on disk from before the
* system upgrade) and {@code scannedSigs} will be in the newer format.
*/
private int compareSignaturesCompat(PackageSignatures existingSigs, PackageParser.Package scannedPkg) {
if (!isCompatSignatureUpdateNeeded(scannedPkg)) {
return PackageManager.SIGNATURE_NO_MATCH;
}
ArraySet<Signature> existingSet = new ArraySet<Signature>();
for (Signature sig : existingSigs.mSignatures) {
existingSet.add(sig);
}
ArraySet<Signature> scannedCompatSet = new ArraySet<Signature>();
for (Signature sig : scannedPkg.mSignatures) {
try {
Signature[] chainSignatures = sig.getChainSignatures();
for (Signature chainSig : chainSignatures) {
scannedCompatSet.add(chainSig);
}
} catch (CertificateEncodingException e) {
scannedCompatSet.add(sig);
}
}
/*
* Make sure the expanded scanned set contains all signatures in the
* existing one.
*/
if (scannedCompatSet.equals(existingSet)) {
// Migrate the old signatures to the new scheme.
existingSigs.assignSignatures(scannedPkg.mSignatures);
// The new KeySets will be re-added later in the scanning process.
synchronized (mPackages) {
mSettings.mKeySetManagerService.removeAppKeySetDataLPw(scannedPkg.packageName);
}
return PackageManager.SIGNATURE_MATCH;
}
return PackageManager.SIGNATURE_NO_MATCH;
}
use of android.content.pm.Signature in project android_frameworks_base by DirtyUnicorns.
the class BackupUtilsTest method testHashSignature.
public void testHashSignature() {
final byte[] sig1 = "abc".getBytes();
final byte[] sig2 = "def".getBytes();
final byte[] hash1a = BackupUtils.hashSignature(sig1);
final byte[] hash1b = BackupUtils.hashSignature(new Signature(sig1));
final byte[] hash2a = BackupUtils.hashSignature(sig2);
final byte[] hash2b = BackupUtils.hashSignature(new Signature(sig2));
assertEquals(32, hash1a.length);
MoreAsserts.assertEquals(hash1a, hash1b);
assertEquals(32, hash2a.length);
MoreAsserts.assertEquals(hash2a, hash2b);
assertFalse(Arrays.equals(hash1a, hash2a));
final ArrayList<byte[]> listA = BackupUtils.hashSignatureArray(Arrays.asList("abc".getBytes(), "def".getBytes()));
final ArrayList<byte[]> listB = BackupUtils.hashSignatureArray(new Signature[] { new Signature("abc".getBytes()), new Signature("def".getBytes()) });
assertEquals(2, listA.size());
assertEquals(2, listB.size());
MoreAsserts.assertEquals(hash1a, listA.get(0));
MoreAsserts.assertEquals(hash1a, listB.get(0));
MoreAsserts.assertEquals(hash2a, listA.get(1));
MoreAsserts.assertEquals(hash2a, listB.get(1));
}
use of android.content.pm.Signature in project android_frameworks_base by DirtyUnicorns.
the class WebViewUpdateServiceTest method testWithSignatures.
// Ensure that package with valid signatures is chosen rather than package with invalid
// signatures.
public void testWithSignatures() {
String validPackage = "valid package";
String invalidPackage = "invalid package";
Signature validSignature = new Signature("11");
Signature invalidExpectedSignature = new Signature("22");
Signature invalidPackageSignature = new Signature("33");
WebViewProviderInfo[] packages = new WebViewProviderInfo[] { new WebViewProviderInfo(invalidPackage, "", true, false, new String[] { Base64.encodeToString(invalidExpectedSignature.toByteArray(), Base64.DEFAULT) }), new WebViewProviderInfo(validPackage, "", true, false, new String[] { Base64.encodeToString(validSignature.toByteArray(), Base64.DEFAULT) }) };
setupWithPackages(packages, true, /* fallback logic enabled */
1, /* numRelros */
false);
mTestSystemImpl.setPackageInfo(createPackageInfo(invalidPackage, true, /* enabled */
true, /* valid */
true, /* installed */
new Signature[] { invalidPackageSignature }, 0));
mTestSystemImpl.setPackageInfo(createPackageInfo(validPackage, true, /* enabled */
true, /* valid */
true, /* installed */
new Signature[] { validSignature }, 0));
mWebViewUpdateServiceImpl.prepareWebViewInSystemServer();
checkPreparationPhasesForPackage(validPackage, 1);
WebViewProviderInfo[] validPackages = mWebViewUpdateServiceImpl.getValidWebViewPackages();
assertEquals(1, validPackages.length);
assertEquals(validPackage, validPackages[0].packageName);
}
use of android.content.pm.Signature in project XobotOS by xamarin.
the class PluginManager method containsPluginPermissionAndSignatures.
private static boolean containsPluginPermissionAndSignatures(PackageInfo pkgInfo) {
// check if the plugin has the required permissions
String[] permissions = pkgInfo.requestedPermissions;
if (permissions == null) {
return false;
}
boolean permissionOk = false;
for (String permit : permissions) {
if (PLUGIN_PERMISSION.equals(permit)) {
permissionOk = true;
break;
}
}
if (!permissionOk) {
return false;
}
// check to ensure the plugin is properly signed
Signature[] signatures = pkgInfo.signatures;
if (signatures == null) {
return false;
}
if (SystemProperties.getBoolean("ro.secure", false)) {
boolean signatureMatch = false;
for (Signature signature : signatures) {
for (int i = 0; i < SIGNATURES.length; i++) {
if (SIGNATURES[i].equals(signature)) {
signatureMatch = true;
break;
}
}
}
if (!signatureMatch) {
return false;
}
}
return true;
}
Aggregations