use of android.content.pm.Signature in project DroidPlugin by DroidPluginTeam.
the class IPluginManagerImpl method saveSignatures.
private void saveSignatures(PackageInfo pkgInfo) {
if (pkgInfo != null && pkgInfo.signatures != null) {
int i = 0;
for (Signature signature : pkgInfo.signatures) {
File file = new File(PluginDirHelper.getPluginSignatureFile(mContext, pkgInfo.packageName, i));
try {
Utils.writeToFile(file, signature.toByteArray());
Log.i(TAG, "Save %s signature of %s,md5=%s", pkgInfo.packageName, i, Utils.md5(signature.toByteArray()));
} catch (Exception e) {
e.printStackTrace();
Log.w(TAG, "Save signatures fail", e);
file.delete();
Utils.deleteDir(PluginDirHelper.getPluginSignatureDir(mContext, pkgInfo.packageName));
break;
}
i++;
}
}
}
use of android.content.pm.Signature in project DroidPlugin by DroidPluginTeam.
the class IPluginManagerImpl method readSignatures.
private Signature[] readSignatures(String packageName) {
List<String> fils = PluginDirHelper.getPluginSignatureFiles(mContext, packageName);
List<Signature> signatures = new ArrayList<Signature>(fils.size());
int i = 0;
for (String file : fils) {
try {
byte[] data = Utils.readFromFile(new File(file));
if (data != null) {
Signature sin = new Signature(data);
signatures.add(sin);
Log.i(TAG, "Read %s signature of %s,md5=%s", packageName, i, Utils.md5(sin.toByteArray()));
} else {
Log.i(TAG, "Read %s signature of %s FAIL", packageName, i);
return null;
}
i++;
} catch (Exception e) {
Log.i(TAG, "Read %s signature of %s FAIL", e, packageName, i);
return null;
}
}
return signatures.toArray(new Signature[signatures.size()]);
}
use of android.content.pm.Signature in project android_frameworks_base by DirtyUnicorns.
the class PackageSignatures method readXml.
void readXml(XmlPullParser parser, ArrayList<Signature> pastSignatures) throws IOException, XmlPullParserException {
String countStr = parser.getAttributeValue(null, "count");
if (countStr == null) {
PackageManagerService.reportSettingsProblem(Log.WARN, "Error in package manager settings: <signatures> has" + " no count at " + parser.getPositionDescription());
XmlUtils.skipCurrentTag(parser);
}
final int count = Integer.parseInt(countStr);
mSignatures = new Signature[count];
int pos = 0;
int outerDepth = parser.getDepth();
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
continue;
}
String tagName = parser.getName();
if (tagName.equals("cert")) {
if (pos < count) {
String index = parser.getAttributeValue(null, "index");
if (index != null) {
try {
int idx = Integer.parseInt(index);
String key = parser.getAttributeValue(null, "key");
if (key == null) {
if (idx >= 0 && idx < pastSignatures.size()) {
Signature sig = pastSignatures.get(idx);
if (sig != null) {
mSignatures[pos] = pastSignatures.get(idx);
pos++;
} else {
PackageManagerService.reportSettingsProblem(Log.WARN, "Error in package manager settings: <cert> " + "index " + index + " is not defined at " + parser.getPositionDescription());
}
} else {
PackageManagerService.reportSettingsProblem(Log.WARN, "Error in package manager settings: <cert> " + "index " + index + " is out of bounds at " + parser.getPositionDescription());
}
} else {
while (pastSignatures.size() <= idx) {
pastSignatures.add(null);
}
Signature sig = new Signature(key);
pastSignatures.set(idx, sig);
mSignatures[pos] = sig;
pos++;
}
} catch (NumberFormatException e) {
PackageManagerService.reportSettingsProblem(Log.WARN, "Error in package manager settings: <cert> " + "index " + index + " is not a number at " + parser.getPositionDescription());
} catch (IllegalArgumentException e) {
PackageManagerService.reportSettingsProblem(Log.WARN, "Error in package manager settings: <cert> " + "index " + index + " has an invalid signature at " + parser.getPositionDescription() + ": " + e.getMessage());
}
} else {
PackageManagerService.reportSettingsProblem(Log.WARN, "Error in package manager settings: <cert> has" + " no index at " + parser.getPositionDescription());
}
} else {
PackageManagerService.reportSettingsProblem(Log.WARN, "Error in package manager settings: too " + "many <cert> tags, expected " + count + " at " + parser.getPositionDescription());
}
} else {
PackageManagerService.reportSettingsProblem(Log.WARN, "Unknown element under <cert>: " + parser.getName());
}
XmlUtils.skipCurrentTag(parser);
}
if (pos < count) {
// Should never happen -- there is an error in the written
// settings -- but if it does we don't want to generate
// a bad array.
Signature[] newSigs = new Signature[pos];
System.arraycopy(mSignatures, 0, newSigs, 0, pos);
mSignatures = newSigs;
}
}
use of android.content.pm.Signature in project android_frameworks_base by DirtyUnicorns.
the class NetworkPolicyManagerServiceTest method _setUp.
public void _setUp() throws Exception {
super.setUp();
setCurrentTimeMillis(TEST_START);
// intercept various broadcasts, and pretend that uids have packages
mServiceContext = new BroadcastInterceptingContext(getContext()) {
@Override
public PackageManager getPackageManager() {
return new MockPackageManager() {
@Override
public String[] getPackagesForUid(int uid) {
return new String[] { "com.example" };
}
@Override
public PackageInfo getPackageInfo(String packageName, int flags) {
final PackageInfo info = new PackageInfo();
final Signature signature;
if ("android".equals(packageName)) {
signature = new Signature("F00D");
} else {
signature = new Signature("DEAD");
}
info.signatures = new Signature[] { signature };
return info;
}
};
}
@Override
public void startActivity(Intent intent) {
// ignored
}
};
mPolicyDir = getContext().getFilesDir();
if (mPolicyDir.exists()) {
IoUtils.deleteContents(mPolicyDir);
}
mActivityManager = createMock(IActivityManager.class);
mStatsService = createMock(INetworkStatsService.class);
mNetworkManager = createMock(INetworkManagementService.class);
mPolicyListener = createMock(INetworkPolicyListener.class);
mTime = createMock(TrustedTime.class);
mConnManager = createMock(IConnectivityManager.class);
mNotifManager = createMock(INotificationManager.class);
mService = new NetworkPolicyManagerService(mServiceContext, mActivityManager, mStatsService, mNetworkManager, mTime, mPolicyDir, true);
mService.bindConnectivityManager(mConnManager);
mService.bindNotificationManager(mNotifManager);
// RemoteCallbackList needs a binder to use as key
expect(mPolicyListener.asBinder()).andReturn(mStubBinder).atLeastOnce();
replay();
mService.registerListener(mPolicyListener);
verifyAndReset();
// catch IProcessObserver during systemReady()
final Capture<IProcessObserver> processObserver = new Capture<IProcessObserver>();
mActivityManager.registerProcessObserver(capture(processObserver));
expectLastCall().atLeastOnce();
// catch INetworkManagementEventObserver during systemReady()
final Capture<INetworkManagementEventObserver> networkObserver = new Capture<INetworkManagementEventObserver>();
mNetworkManager.registerObserver(capture(networkObserver));
expectLastCall().atLeastOnce();
expect(mNetworkManager.isBandwidthControlEnabled()).andReturn(true).atLeastOnce();
expectCurrentTime();
replay();
mService.systemReady();
verifyAndReset();
mProcessObserver = processObserver.getValue();
mNetworkObserver = networkObserver.getValue();
}
use of android.content.pm.Signature in project android_frameworks_base by DirtyUnicorns.
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));
}
Aggregations