简体   繁体   English

除了纯文本之外,我们如何存储密码?

[英]How can we store password other than plain text?

I've found numerous posts on stackoverflow on how to store user passwords.我在 stackoverflow 上找到了很多关于如何存储用户密码的帖子。 However, I need to know what is the best way to store a password that my application needs to communicate with another application via the web?但是,我需要知道存储我的应用程序需要通过 Web 与另一个应用程序通信的密码的最佳方法是什么? Currently, our web app needs to transmit data to a remote website.目前,我们的 Web 应用程序需要将数据传输到远程网站。 To upload the data, our web app reads the password from a text file and creates the header with payloads and submits via https.为了上传数据,我们的 Web 应用程序从文本文件中读取密码并创建带有有效负载的标头并通过 https 提交。

This password in plain text on the file system is the issue.这个文件系统上的纯文本密码是问题所在。 Is there any way to store the password more securely?有没有办法更安全地存储密码?

This is a linux os and the application is written in python and is not compiled.这是一个 linux 操作系统,应用程序是用 python 编写的,没有编译。

Further clarification: There are no users involved in this process at all.进一步说明:在此过程中根本没有用户参与。 The password stored in the file system is used by the other web app to authenticate the web app that is making the request.存储在文件系统中的密码由其他 Web 应用程序用于对发出请求的 Web 应用程序进行身份验证。 To put it in the words of a commenter below: "In this case, the application is the client to another remote application."用下面评论者的话来说:“在这种情况下,应用程序是另一个远程应用程序的客户端。”

From the question it seems you need to store password in such a way, that it can be read and used in an automated transaction with another site.从问题来看,您似乎需要以这种方式存储密码,以便可以在与另一个站点的自动交易中读取和使用密码。 You could encrypt the password and store it encrypted in the file, then decrypt it using a key stored elsewhere in your system before using it.您可以加密密码并将其加密存储在文件中,然后在使用之前使用存储在系统其他地方的密钥对其进行解密。 This makes difficulties to someone that gets access to the file from using the password, as they now have to find the key and encryption algorithm used, so they can decrypt it.这给使用密码访问文件的人带来了困难,因为他们现在必须找到所使用的密钥和加密算法,以便对其进行解密。

As defense, more lesser defense is always better than one strong defense that fails when breached.作为防御,越弱的防御总是比被破坏时失败的强大防御要好。 Moreover, I would also secure the file containing the password, rather than the password itself.此外,我还会保护包含密码的文件,而不是密码本身。 Configure your webserver to disable possibility to serve the file containing the password, and try to set the process needing the file to run under a separate account, so you can restrict the access to the file to account running the process and admin accounts only.配置您的网络服务器以禁用提供包含密码的文件的可能性,并尝试将需要该文件的进程设置为在单独的帐户下运行,这样您就可以将对该文件的访问权限限制为仅运行该进程的帐户和管理员帐户。

I don't think you will find a foolproof way to do this.我不认为你会找到一个万无一失的方法来做到这一点。 I would suggest a combination of things to achieve 'security by obscurity':我会建议结合一些事情来实现“默默无闻的安全”:

  • store the password file on a different computer than the one which will use it将密码文件存储在与将使用它的计算机不同的计算机上
  • store the file path in a separate config file on the app nachine将文件路径存储在应用程序机器上的单独配置文件中
  • use permissions to limit access to the config and password files to your process only使用权限将配置和密码文件的访问权限限制为您的进程
  • audit file access if your system allows it (keep a log of who touched the files)如果您的系统允许,审核文件访问(记录谁接触了文件)
  • give the folders and files innocuous names (/usr/joe/kittens.txt?)给文件夹和文件起一个无害的名字(/usr/joe/kittens.txt?)
  • block physical access to the computer(s) (offsite hosting, or locked closet, or something)阻止对计算机的物理访问(异地托管、上锁的壁橱或其他东西)

你可以使用像RSA这样的双向密钥加密算法,密码是加密存储的(通过一个密钥,它存储在用户的大脑中)在文件系统上,但是要解码密码,用户必须输入密钥。

At the very least you should use permissions (if you are on a filesystem which supports them) to ensure that you are the only one able to read the file.至少您应该使用权限(如果您在支持它们的文件系统上)以确保您是唯一能够读取文件的人。

In addition, if your app is compiled, it would not be too difficult to encrypt the password with a hard-coded passphrase.此外,如果您的应用程序已编译,则使用硬编码的密码短语加密密码不会太困难。 If the code is not compiled this method wouldn't really be helpful, as a would-be attacker could just read the source and determine the encryption.如果未编译代码,此方法将不会真正有用,因为潜在的攻击者只能读取源代码并确定加密。

You can store it as a result of hash algorithm, this is one way algorithm (eg. MD5 or SHA).您可以将其存储为哈希算法的结果,这是一种方式算法(例如 MD5 或 SHA)。 On authentication you calc MD5 of password typed by user and checking equality with your stored MD5 password hash for this user.在身份验证时,您计算用户键入的密码的 MD5,并检查与您为该用户存储的 MD5 密码哈希的相等性。 If is equal password is ok.如果是相等的密码就可以了。

For more information about hasing algorithms you can visit:有关 hasing 算法的更多信息,您可以访问:

Is your web application hosted on a farm?您的 Web 应用程序是否托管在服务器场上? If not then a technology such as DPAPI will allow you to encrypt the password so that it can only be decrypted on the machine it was encrypted on.如果没有,那么像DPAPI这样的技术将允许您加密密码,以便它只能在加密的机器上解密。

From memory there can be problems with using it on a web farm though, as you need to go and re-encrypt the value for each server.但是,从内存中使用它在网络场上可能会出现问题,因为您需要去重新加密每个服务器的值。

If it is a web farm then you probably want to use some form of RSA encryption as has been suggested in other answers.如果它是一个网络农场,那么您可能想要使用其他答案中建议的某种形式的 RSA 加密。

EDIT: DPAPI is only good if you are hosting on windows of course...编辑:DPAPI 仅当您在 Windows 上托管时才有用...

Protecting the Automatic Logon Password保护自动登录密码

The LsaStorePrivateData function can be used by server applications to store client and machine passwords. LsaStorePrivateData 函数可以被服务器应用程序用来存储客户端和机器密码。

Windows only仅限 Windows

I don't think you are understanding the answers provided.我认为您没有理解所提供的答案。 You don't ever store a plain-text password anywhere, nor do you transmit it to another device.您永远不会将纯文本密码存储在任何地方,也不会将其传输到其他设备。

You wrote: Sorry, but the issue is storing a password on the file system... This password is needed to authenticate by the other web app.您写道:抱歉,问题是在文件系统上存储密码...其他网络应用程序需要此密码进行身份验证。

You can't count on file system protections to keep plain-text safe which is why others have responded that you need SHA or similar.你不能指望文件系统保护来保证纯文本的安全,这就是为什么其他人回应说你需要 SHA 或类似的。 If you think that a hashed password can't be sufficient for authentication, you don't understand the relevant algorithm:如果您认为散列密码不足以进行身份​​验证,那么您不了解相关算法:

  1. get password P from user从用户那里获取密码 P
  2. store encrypted (eg salted hash) password Q someplace relatively secure将加密(例如,加盐哈希)密码 Q 存储在相对安全的地方
  3. forget P (even clear the buffer you used to read it)忘记 P(甚至清除您用来读取它的缓冲区)
  4. send Q to remote host H发送 Q 到远程主机 H
  5. H gets password P' from user when needed H 在需要时从用户那里获取密码 P'
  6. H computes Q' from P', compares Q' to Q for equality H 从 P' 计算 Q',比较 Q' 和 Q 是否相等

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 除了使用“<”运算符或“|”之外,有什么方法可以将文本文件传递给 sendmail 命令(在 linux 中) 操作员 - Is there any way we can pass a text file to sendmail command (in linux) other than using '<' operator or '|' operator 如何从纯文本grep键值存储中的值 - How to grep for value in a key-value store from plain text 如何剪切和统计纯文本文档中的字符串? - How can I cut and statistics the string in text plain document? 我们如何限制文件描述符总是小于 1024? - How can we limit file descriptor to always be less than 1024? 如何使自定义部分可执行(除了.text) - How to make a custom section executable (other than .text) 如何在本地获取https包的纯文本? - How to get plain text of https package locally? 如果我们想在版本化的源代码中搜索,使用 git grep 比普通的 grep 更好吗? - Is it better to use git grep than plain grep if we want to search in versioned source code? 我们如何在Windows / Linux上通过管道将oracle密码传递给后台运行的sqlplus进程? - How can we pipe oracle password to background running sqlplus process on windows/Linux? 如何将执行代码放在.text部分以外的其他部分中 - how to put the execution code in the section other than the .text section into the middle of the .text 如何将text / plain转换为text / x.shellscript - how to convert a text/plain to text/x.shellscript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM