【问题标题】:SampleSyncAdapter storing password plain text?SampleSyncAdapter 存储密码纯文本?
【发布时间】:2012-05-07 07:30:30
【问题描述】:

我正在尝试了解 Android AccountManager 和 OAuth。 我想做的是不让手机访问密码。 (这就是谷歌的建议:“Be Smart About Security!”) 所以我检查了谷歌示例应用程序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 set to Account:test”。 当您阅读其余部分时,这在某种程度上是可以理解的

protected String doInBackground(Void... params) {
    ....
    return NetworkUtilities.authenticate(mUsername, mPassword);     
    ....
}

如果密码是令牌,这将不起作用。

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

任何人都可以对此有所了解吗?

【问题讨论】:

    标签: android oauth-2.0 accountmanager


    【解决方案1】:

    从文档中我们可以看到:

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

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

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

    【讨论】:

    • 令牌在一定时间后失效怎么办?我猜在这种情况下,您只需要重新提示用户输入密码即可。但是许多服务(例如 Facebook)从不提示我输入密码,因此要么 1)它们生成的令牌永不过期,使其在安全性方面基本上与密码一样好,要么 2)它们正在存储我的密码(纯文本或加密)。
    猜你喜欢
    • 2010-10-31
    • 2010-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-18
    • 2011-12-24
    • 2020-03-16
    相关资源
    最近更新 更多