SampleSyncAdapter存储密码纯文本?

Lor*_*ron 5 android accountmanager oauth-2.0

我试图了解Android AccountManager和OAuth.我想做的是不让手机访问密码.(这就是谷歌建议:" 聪明一点安全! ")所以我结账了Google示例应用程序SampleSyncAdapter并开始阅读代码.然后我在AuthenticatorActivity中看到这种情况:

private AccountManager mAccountManager;
private String mPassword;

 /**
 * ... Sets the
 * AccountAuthenticatorResult which is sent back to the caller. We store the
 * authToken that's returned from the server as the 'password' for this
 * account - so we're never storing the user's actual password locally.
 *
 * @param result the confirmCredentials result.
 */
public void handleLogin(View view) {
    ....
    mPassword = mPasswordEdit.getText().toString();    
    ....
    Log.d(TAG, "mPassword set to Account:" + mAccountManager.getPassword(account));
}

private void finishLogin(String authToken) {
    ....
    mAccountManager.addAccountExplicitly(account, mPassword, null);        
    ....
}
Run Code Online (Sandbox Code Playgroud)

此日志消息是"mPassword设置为Account:test".当你因此阅读其余内容时,这在某种程度上是可以理解的

protected String doInBackground(Void... params) {
    ....
    return NetworkUtilities.authenticate(mUsername, mPassword);     
    ....
}
Run Code Online (Sandbox Code Playgroud)

如果密码是一个令牌,这将无法正常工作.

此外,我希望其余的代码在getAuthToken()上的Authenticator中以不同的方式工作我假设我完全错误但我只想使用AccountManager来存储OAuth"Dance"的结果,以便我可以使用此帐户验证我的JSON RESTful服务.

任何人都可以对此发光吗?

Yur*_*ury 0

从文档中我们可以读到:

重要的是要了解 AccountManager 不是加密服务或钥匙串。它会在您传递帐户凭据时以纯文本形式存储它们。在大多数设备上,这不是一个特别值得关注的问题,因为它将它们存储在只能由 root 访问的数据库中。但在 root 设备上,任何拥有该设备 adb 访问权限的人都可以读取凭据。

因此,据我了解,这是一个误用单词(密码和令牌)的问题。我猜程序如下:

  1. 您要求用户提供登录名和密码。
  2. 在您的应用程序中,您以某种方式将此登录名和密码发送到您的服务器。
  3. 根据此信息,您的服务器生成一个令牌并发回您的应用程序。
  4. AccountManager 以纯文本形式存储此令牌,然后使用此令牌对您的用户进行身份验证。