gpt4 book ai didi

android - AccountManager 和签名检查

转载 作者:搜寻专家 更新时间:2023-11-01 08:23:53 24 4
gpt4 key购买 nike

Security tipsAccountManager 相关的章节提到:

If credentials are used only by applications that you create, you can verify the application that accesses the AccountManager using checkSignature().

我应该在代码的什么地方检查签名?我已经尝试使用 Binder.getCallingUid() 在我自己的 AbstractAccountAuthenticator 实现中获取调用进程的 UID,但它返回 1000 作为系统进程执行 IPC。我需要获取尝试访问我的应用程序创建的帐户的其他应用程序的 UID/包名称,因为我想在返回授权 token 之前执行 checkSignature 检查。

最佳答案

原来这很简单。真正调用者的包名、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;
}
}

关于android - AccountManager 和签名检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47334432/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com