use of android.content.pm.Signature in project weiciyuan by qii.
the class SsoHandler method validateAppSignatureForIntent.
private boolean validateAppSignatureForIntent(Activity activity, Intent intent) {
ResolveInfo resolveInfo = activity.getPackageManager().resolveActivity(intent, 0);
if (resolveInfo == null) {
return false;
}
String packageName = resolveInfo.activityInfo.packageName;
try {
PackageInfo packageInfo = activity.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
for (Signature signature : packageInfo.signatures) {
if (WEIBO_SIGNATURE.equals(signature.toCharsString())) {
return true;
}
}
} catch (PackageManager.NameNotFoundException e) {
return false;
}
return false;
}
use of android.content.pm.Signature in project weiciyuan by qii.
the class Utility method isCertificateFingerprintCorrect.
//if app's certificate md5 is correct, enable Crashlytics crash log platform, you should not modify those md5 values
public static boolean isCertificateFingerprintCorrect(Context context) {
try {
PackageManager pm = context.getPackageManager();
String packageName = context.getPackageName();
int flags = PackageManager.GET_SIGNATURES;
PackageInfo packageInfo = pm.getPackageInfo(packageName, flags);
Signature[] signatures = packageInfo.signatures;
byte[] cert = signatures[0].toByteArray();
String strResult = "";
MessageDigest md;
md = MessageDigest.getInstance("MD5");
md.update(cert);
for (byte b : md.digest()) {
strResult += Integer.toString(b & 0xff, 16);
}
strResult = strResult.toUpperCase();
//debug
if ("DE421D82D4BBF9042886E72AA31FE22".toUpperCase().equals(strResult)) {
return false;
}
//relaease
if ("C96155C3DAD4CA1069808FBAC813A69".toUpperCase().equals(strResult)) {
return true;
}
AppLogger.e(strResult);
} catch (NoSuchAlgorithmException ex) {
ex.printStackTrace();
} catch (PackageManager.NameNotFoundException ex) {
ex.printStackTrace();
}
return false;
}
use of android.content.pm.Signature in project platform_frameworks_base by android.
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 phonegap-facebook-plugin by Wizcorp.
the class Settings method getApplicationSignature.
public static String getApplicationSignature(Context context) {
if (context == null) {
return null;
}
PackageManager packageManager = context.getPackageManager();
if (packageManager == null) {
return null;
}
String packageName = context.getPackageName();
PackageInfo pInfo;
try {
pInfo = packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
} catch (PackageManager.NameNotFoundException e) {
return null;
}
Signature[] signatures = pInfo.signatures;
if (signatures == null || signatures.length == 0) {
return null;
}
MessageDigest md;
try {
md = MessageDigest.getInstance("SHA-1");
} catch (NoSuchAlgorithmException e) {
return null;
}
md.update(pInfo.signatures[0].toByteArray());
return Base64.encodeToString(md.digest(), Base64.URL_SAFE | Base64.NO_PADDING);
}
use of android.content.pm.Signature in project platform_frameworks_base by android.
the class Utils method getCertFingerprintsFromPackageManager.
/**
* Returns the normalized sha-256 fingerprints of a given package according to the Android
* package manager.
*/
public static List<String> getCertFingerprintsFromPackageManager(String packageName, Context context) throws NameNotFoundException {
Signature[] signatures = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES).signatures;
ArrayList<String> result = new ArrayList<String>(signatures.length);
for (Signature sig : signatures) {
result.add(computeNormalizedSha256Fingerprint(sig.toByteArray()));
}
return result;
}
Aggregations