简体   繁体   English

如何在设备上安全地存储密码?

[英]How to store passwords safely on a device?

I have a raspberry pi that needs to access a service using a username and password. 我有一个需要使用用户名和密码访问服务的覆盆子pi。 What is the standard procedure to store the user credentials on the device. 在设备上存储用户凭据的标准过程是什么。

I know that a user on a phone would enter the username and password in order to get a token which is valid for a certain period of time. 我知道手机上的用户会输入用户名和密码,以获得在一段时间内有效的令牌。 This allows to !not! 这允许!不! store the credentials locally. 在本地存储凭据。

However, my device (DVR) needs to run 24/7 and the user cannot regularly enter the password. 但是,我的设备(DVR)需要全天候运行,用户无法定期输入密码。 So I somehow need to store the password on the device to login every once in a while or after a reboot. 所以我需要在设备上存储密码,以便每隔一段时间或重启后登录。

I am concerned because the device is publicly accessible and someone could potentially take it, plug it into a computer and read the password from storage. 我很担心,因为该设备是公共可访问的,有人可能会接受它,将其插入计算机并从存储中读取密码。

You have to think about what exact attacks you want to protect against. 你必须考虑你想要防范的确切攻击。 The TL;DR is you won't be able to protect it against everything that comes to mind. TL; DR是你无法保护它免受一切想到的事情。

One question is whether it's ok to enter some kind of a secret (a password) when the device boots up. 一个问题是,当设备启动时是否可以输入某种秘密(密码)。 You're saying it's running 24/7, so a reboot should probably not be very frequent. 你说它正在全天候运行,所以重启应该不是很频繁。 If your concern is somebody taking the Raspberry and reading the password from the disk (or card, in case of a Pi), you could try and keep it in memory only. 如果你担心的是有人拿着Raspberry并从磁盘读取密码(或卡,如果是Pi),你可以尝试将其保存在内存中。 Startup would need the password to be entered, but whoever takes the device (or the card) physically would not be able to learn the password. 启动时需要输入密码,但无论是谁在物理上取得设备(或卡)都无法学习密码。 Of course this is not entirely secure, somebody could either read the password from memory without taking the Pi (you said they have physical access), or they could maintain power while taking it so that the password is kept in memory. 当然这并不完全安全,有人可以从内存中读取密码而不需要Pi(你说他们有物理访问权限),或者他们可以保持电源,同时服用它以便密码保存在内存中。 But it would be much more secure than writing the password to the storage. 但它比将密码写入存储更安全。

Another thing you can do is assign the device some kind of a token. 您可以做的另一件事是为设备分配某种令牌。 If you think the token is compromised (somebody learnt it in any way), you can just change the token to a new one. 如果您认为令牌已被泄露(有人以任何方式学习它),您只需将令牌更改为新令牌即可。 But you still need a way to discover when credentials are stolen. 但是你仍然需要一种方法来发现证书被盗的时间。 But you would need this anyway. 但无论如何你还是需要这个。

You can monitor the device for physical tampering or theft. 您可以监控设备是否有物理篡改或被盗。 If it is tampered with or stolen, you can assume the credentials are compromised, and you can then issue new credentials to your service. 如果它被篡改或被盗,您可以认为凭据已泄露,然后您可以向您的服务发放新凭据。

Also you're saying it runs 24/7, so I assume it has a fixed IP address. 你也说它全天候运行,所以我认为它有一个固定的IP地址。 You can implement IP address restriction on the service that it connects to with the credentials, so even if credentials are compromised, an attacker is very limited in where he can connect from (but you mentioned a DVR, which typically uses UDP traffic, and it's much easier to forge source IP addresses over UDP than over TCP). 您可以使用凭据对其连接的服务实施IP地址限制,因此即使凭据受到威胁,攻击者在可以连接的位置也非常有限(但您提到了DVR,它通常使用UDP流量,而且它是通过UDP伪造源IP地址比通过TCP更容易。

Probably needless to say, but obviously you should use unique credentials on this device that you use nowhere else and for no other puspose. 可能不用说了,但显然你应该在这个设备上使用你在其他任何地方使用的独特凭证,而不是其他用途。

Note that you can pick several of these if you like to protect against different threats, or to build defense in depth. 请注意,如果您希望防范不同的威胁,或者深入构建防御,您可以选择其中的几个。 But you have to keep in mind that whatever you give to users (potential attackers) is lost and you can safely assume they have full control. 但是你必须记住,无论你给用户(潜在的攻击者)的任何东西都丢失了,你可以放心地认为他们有完全的控制权。 However, the level of effort is different, and if you can make it hard or risky enough for an attacker, that's probably reasonably good in many situations. 但是,努力程度是不同的,如果你可以为攻击者做出足够的努力或风险,那么在许多情况下这可能是相当不错的。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM