Firebase 云功能中的安全加密将敏感信息传递给服务器/API?

Secure Encryption Passing Sensitive Info to Server / API in Firebase Cloud Functions?

所以我有一个使用 Firebase/Cloud 功能的应用程序。在客户端,我让用户输入他们的:

然后(在我的客户端上)我将这些变量作为参数传递给云函数……像这样:

final _cloudFunctions = FirebaseFunctions.instanceFor(region: 'us-central1');
  final _createCustomerAndAddBankingInfo = _cloudFunctions.httpsCallable(
    'createCustomerAndAddBankingInfo',
  );
await _createCustomerAndAddBankingInfo.call(<String, dynamic>{
      'firstName': firstName,
      'lastName': lastName,
      'routingNumber': routingNumber, // these are not encrypted, these are literally  the numbers e.g. `01234567`
      'accountNumber': accountNumber,
      'accountNickname': accountNickname,
      'accountType': accountType.toLowerCase()
    })

然后(在服务器上)我使用云功能将该数据传递给 Dwolla API(它已经使用了 TLS)并且我不在我的数据库中的任何地方存储他们的路由/账户号码。

由于这是敏感信息,我是否需要在客户端对其进行加密,然后在该云函数中对其进行解密?

或者当您将参数作为变量传递时,云函数是否提供加密?

我在网上搜索了文档,找不到这个问题的具体答案。

我发现了这个: https://cloud.google.com/firestore/docs/server-side-encryption

...但我不确定这是否仅适用于 reads/writes 还是也适用于函数。

非常感谢您的帮助!谢谢!

简短的回答是肯定的,您需要在发送之前在客户端对其进行加密。 但是,您执行此操作的方式可能会有所不同。

我的建议是使用云函数生成一次性加密哈希,并根据用户 uid 和时间戳将其存储在私有不可读数据库中,然后将其发送给客户端。

然后客户端使用密钥对数据进行编码并将其发送到新的云函数,该函数使用数据库中的密钥对其进行解码,而不是将密钥与编码的有效负载一起发送

建议您将前面提到的带有时间戳的编码数据分两步存储到 validate/decode 中,这样如果您的数据库遭到破坏,数据仍然是编码的。

    var encryptedAES = CryptoJS.AES.encrypt("Message", "My Secret Passphrase");
    var decryptedBytes = CryptoJS.AES.decrypt(encryptedAES, "My Secret Passphrase");
    var plaintext = decryptedBytes.toString(CryptoJS.enc.Utf8);

https://code.google.com/archive/p/crypto-js/downloads

请注意:这是一个简化的解决方案,您应该查看其他步骤以在此基础上进一步增强加密方法,包括 3 次握手、基于 client/user 的随机化ID 和其他在您的应用程序中构建的随机代理。虽然 HTTPS 相当安全,但不能保证它 100% 安全。

https://security.stackexchange.com/questions/110415/is-it-ok-to-send-plain-text-password-over-https 适用于您的问题:

It is standard practice to send "plaintext" passwords over HTTPS. The passwords are ultimately not plaintext, since the client-server communication is encrypted as per TLS.

Encrypting the password before sending it in HTTPS doesn't accomplish much: if the attacker got their hands on the encrypted password they could simply use it as if it were the actual password, the server wouldn't know the difference. The only advantage it would provide is protecting users that use the same password for multiple sites, but it wouldn't make your site any safer.

只要您通过 HTTPS 与 Cloud Functions 进行通信,加密银行帐户 Number/Bank 路由号码就不会取得多大成就。

幸运的是,您已经在使用 HTTPS 与 Cloud Function 实例通信,如 https://firebase.google.com/docs/functions/callable-reference 中所述。