安全提示关于AccountManager的章节提到:
如果凭据仅由您创建的应用程序使用,则可以使用checkSignature()验证访问该checkSignature的应用程序。
在代码中我应该在哪里检查签名?我已经尝试使用Binder.getCallingUid()在我自己的AbstractAccountAuthenticator实现中获取调用进程的UID,但是它在系统进程执行IPC时返回1000。我需要获得另一个应用程序的UID/包名,该应用程序试图访问我的应用程序创建的帐户,因为我想在返回auth令牌之前执行checkSignature检查。
发布于 2017-11-17 11:35:32
结果很简单。实际调用方的包名、uid和pid包含在作为参数传递的Bundle中。这段代码应该驻留在AbstractAccountAuthenticator的实现中。
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account,
String authTokenType, Bundle bundle) {
try {
PackageManager packageManager = context.getPackageManager();
String callerPackageName = bundle.getString("androidPackageName");
// Caller app must be signed with the same key to get the auth token
int signatureResult = packageManager.checkSignatures(BuildConfig.APPLICATION_ID,
callerPackageName);
if (signatureResult >= PackageManager.SIGNATURE_MATCH) {
return [bundle with the auth token];
} else {
return Bundle.EMPTY;
}
}https://stackoverflow.com/questions/47334432
复制相似问题