SampleSyncAdapter存储密码纯文本?

时间:2012-04-26 14:31:35

标签: android oauth-2.0 accountmanager

我正试图了解Android AccountManager和OAuth。 我想做的是不让手机访问密码。 (这就是谷歌的建议:“Be Smart About Security!”) 所以我查看了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);        
    ....
}

此日志消息是“mPassword设置为Account:test”。 当你因为这个

阅读其余内容时,这在某种程度上是可以理解的
protected String doInBackground(Void... params) {
    ....
    return NetworkUtilities.authenticate(mUsername, mPassword);     
    ....
}

如果密码是令牌,则无效。

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

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

1 个答案:

答案 0 :(得分:0)

从文档中我们可以看到:

  

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

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

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