use of android.content.pm.Signature in project android_frameworks_base by ResurrectionRemix.
the class WebViewFactory method signaturesEquals.
/**
* Returns true if the signatures match, false otherwise
*/
private static boolean signaturesEquals(Signature[] s1, Signature[] s2) {
if (s1 == null) {
return s2 == null;
}
if (s2 == null)
return false;
ArraySet<Signature> set1 = new ArraySet<>();
for (Signature signature : s1) {
set1.add(signature);
}
ArraySet<Signature> set2 = new ArraySet<>();
for (Signature signature : s2) {
set2.add(signature);
}
return set1.equals(set2);
}
use of android.content.pm.Signature in project android_frameworks_base by ResurrectionRemix.
the class KeySetManagerServiceTest method testPublicKeyCertReprEquiv.
/* test equivalence of PackageManager cert encoding and PackageParser manifest keys */
public void testPublicKeyCertReprEquiv() throws CertificateException {
PublicKey keyA = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyA);
PublicKey keyB = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyB);
PublicKey keyC = PackageParser.parsePublicKey(KeySetStrings.ctsKeySetPublicKeyC);
Signature sigA = new Signature(KeySetStrings.ctsKeySetCertA);
Signature sigB = new Signature(KeySetStrings.ctsKeySetCertB);
Signature sigC = new Signature(KeySetStrings.ctsKeySetCertC);
assertNotNull(keyA);
assertNotNull(keyB);
assertNotNull(keyC);
assertEquals(keyA, sigA.getPublicKey());
assertEquals(keyB, sigB.getPublicKey());
assertEquals(keyC, sigC.getPublicKey());
byte[] bArrayPk = keyA.getEncoded();
byte[] bArrayCert = sigA.getPublicKey().getEncoded();
assertEquals(bArrayPk.length, bArrayCert.length);
assertEquals(true, ArrayUtils.equals(bArrayPk, bArrayCert, bArrayPk.length));
bArrayPk = keyB.getEncoded();
bArrayCert = sigB.getPublicKey().getEncoded();
assertEquals(bArrayPk.length, bArrayCert.length);
assertEquals(true, ArrayUtils.equals(bArrayPk, bArrayCert, bArrayPk.length));
bArrayPk = keyC.getEncoded();
bArrayCert = sigC.getPublicKey().getEncoded();
assertEquals(bArrayPk.length, bArrayCert.length);
assertEquals(true, ArrayUtils.equals(bArrayPk, bArrayCert, bArrayPk.length));
}
use of android.content.pm.Signature in project android_frameworks_base by ResurrectionRemix.
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 android_frameworks_base by ResurrectionRemix.
the class NetworkPolicyManager method isUidValidForPolicy.
/**
* Check if given UID can have a {@link #setUidPolicy(int, int)} defined,
* usually to protect critical system services.
*/
@Deprecated
public static boolean isUidValidForPolicy(Context context, int uid) {
// first, quick-reject non-applications
if (!UserHandle.isApp(uid)) {
return false;
}
if (!ALLOW_PLATFORM_APP_POLICY) {
final PackageManager pm = context.getPackageManager();
final HashSet<Signature> systemSignature;
try {
systemSignature = Sets.newHashSet(pm.getPackageInfo("android", GET_SIGNATURES).signatures);
} catch (NameNotFoundException e) {
throw new RuntimeException("problem finding system signature", e);
}
try {
// reject apps signed with platform cert
for (String packageName : pm.getPackagesForUid(uid)) {
final HashSet<Signature> packageSignature = Sets.newHashSet(pm.getPackageInfo(packageName, GET_SIGNATURES).signatures);
if (packageSignature.containsAll(systemSignature)) {
return false;
}
}
} catch (NameNotFoundException e) {
}
}
// nothing found above; we can apply policy to UID
return true;
}
use of android.content.pm.Signature in project android_frameworks_base by ResurrectionRemix.
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);
}
Aggregations