6

I have found a similar question here Saving passwords inside an application but it didn't really answer my concerns.

I am dealing with an application that will receive a password (securely) from the user. Once I receive the password I would need store it in some variable and send it through transactions to other systems (this logic is safe and secure and already implemented).

My worry is that I don't want to be able to see the password in a core dump so I would like to encrypt any password before saving it to any variable.

Questions:

  • Is encrypting it before saving it to a variable enough? Or am I missing some security loopholes?

  • Is there a simple header only libraries that can do encryption? Can you guide me to where I can start looking?

Note to answer commenters:

  • The password will not be stored long term; Only for the lifespan of the transactions.

  • Unfortunately, the participants of the transactions cannot decrypt the password, therefore I would need to decrypt it before I send it to them.

  • My main concern right now is to find a way to encrypt and decrypt the password locally - in an easy manner...

  • I found OpenSSL library and crypto++ but it seams that I would need to link with them, I can't just include and call them (i.e. not header only libraries)...

Thanks,

4

1 回答 1

2

(注意:我确信有严格的清单和官方指南,关于如何处理安全软件中的密码,来自真正了解安全知识的人和当局。这不是其中之一!)

我认为没有一种加密安全的方法可以在您的进程内存中拥有密码,能够使用它们,但不能将访问权限授予可以在调试器下运行您的应用程序或检查您的核心转储的用户。

您可以做的是隐藏密码。以下是您可以使用的一些技巧:

  • 不要将密码作为简单的字符串保存在内存中的任何位置(将字符分散等)
  • 在使用密码后清除所有存储密码的变量(例如,如果您将密码传递给函数,则应在完成后将该变量的所有字符设置为函数内部的 NUL。
  • 加密密码。
  • 在应用程序的每次运行时更改加密密钥(如果是长时间运行的应用程序,则定期更改。)
  • 根据系统/硬件的某些方面以程序方式生成加密密钥,并且不要将密码的加密密钥存储在进程内存中的任何位置。
  • 如果可用,请使用可信平台模块 (TPM) 等硬件。

一致且有效地实现上述内容非常困难,并且会影响您处理密码的所有代码。有时你甚至不得不故意让你的代码更加晦涩难懂,违背你作为程序员的所有直觉(例如,不将密码作为参数传递给函数,而是在函数内部使用硬编码地址。)

我必须再次强调,当攻击者可以完全访问物理机器时,仅在软件中保护您的密码可能是不可能的。

至于您问题的第二部分,我不知道任何仅包含标头的加密库,但加密密码可能只需要一个密码,也可能需要一个哈希。而且所有最好的算法都有公共领域或其他免费的实现。您可以获取其中之一并将其复制/粘贴到您自己的应用程序中。不要忘记认真测试它!

于 2013-06-12T15:25:52.853 回答