5

所以我现在正在开发一个移动应用程序,它将向使用 Django 构建的 REST API 发出请求。

为了保护 API,我计划使用私钥/公钥对身份验证系统。

我想到的工作流程是这样的:

  1. 用户使用 Facebook 登录
  2. 用户签名后,应用程序会生成私钥
  3. 私钥在服务器和应用程序之间共享,以便服务器知道将该私钥映射到特定用户。
  4. 每次移动应用发出请求时,应用都会使用请求参数和私钥生成 HMAC/签名。除了 HMAC 之外,应用程序还发送发送它的用户的 user_id(这将充当公钥)。
  5. 当服务器收到请求时,它会生成自己的 HMAC。它接受 user_id 并在表中查找私钥。它使用私钥重新创建带有请求参数的 HMAC,并将其与移动应用程序发送的 HMAC 进行比较。如果服务器和移动设备具有匹配的 HMAC,那么它会执行请求。

现在我的问题在于步骤 3,其中必须以某种方式在移动应用程序和服务器之间共享私钥。如何安全地发送私钥?

4

1 回答 1

5

I would start by asking why the server part of your app needs to know the private key. If it only wants to authenticate a user, it only needs the public key and the user id, and the user id cannot iself be the public key (you need a way to find out which public key to use).

For instance, the process of sharing the key, your step three, could look something like this:

  1. The app generates a public-private key pair.
  2. The app sends the public key to the server, not caring who can intercept it.
  3. The server stores that public key, associating it with the id the user provided.

Maybe the integration into Facebook is the part that makes this impossible. I do not quite understand how Facebook comes into this whole process.

One thing that can make the transfer of a key slightly more secure is to use multiple channels to transfer it.

For instance, your application could send the private key that was generated using your REST API but encrypting it with a symmetric encryption scheme. The symmetric encryption key can be sent via some other medium, such as email, or through SMS since this is a mobile app, or maybe even an automated phone call placed to a number provided by the registering user. The key can be a random passphrase that generates the actual symmetric encryption key, to make sure it is something that can be typed in by the user. Then, to unlock the app, the user needs to type in this passphrase into a screen and the secret key is unlocked.

Again, this only improves the security of the transfer by a small margin, especially considering the fact that if you can intercept the transmission of the private key, you can probably intercept the email containing the passphrase. In my opinion, not sending the private key to the server would not only be optimal but required.

于 2012-08-06T18:01:54.863 回答