我如何知道 .NET C# 中的文件是否已更改?
我有一个应用程序需要一种安全的方式来存储其配置。有些用户可以更改配置。我需要某种签名方案,可以验证配置文件在没有有效用户的情况下没有更改。我曾考虑过使用 RSA,其中私钥使用用户密码进行加密,公钥用于对配置进行签名。然而,没有什么可以阻止某人更改用户文件并添加自己的公钥,从而规避我的安全。有什么想法吗?
I have an application that requires a secure way to store its configuration. There are users that can change the configuration. I need some sort of signature scheme where I can verify that the config file has not changed with out a valid user. I had thought about using RSA, where the private key is encrypted with the users password, and the public key is used to sign the config. However there is nothing to prevent someone from changing the user file and adding their own public key, thus circumventing my security. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以只对文件进行加密,并且只允许在应用程序内进行编辑。这将阻止用户从您的工具以外的任何工具编辑配置,该工具可以进行身份验证以验证用户是否是“有效用户”。
You could just keep the file encrypted, and only allow editing from within your application. This would prevent users from editing the configuration from any tool other than yours, which could do the authentication to verify that the user is a "valid user".
在列出的所有方法中,密钥管理是客户端计算机上的真正弱点。需要密钥才能解密。使用另一个密钥来加密该密钥并不更强。混淆是一个开始。
我使用的是一个单独的程序集,其中包含我们的加密代码。然后通过一种名为隐写术的技术来存储密钥。我将密钥编码在应用程序的徽标中。然后使用软件的已知值对该密钥进行加密。在一种情况下,它可能是特定程序集的校验和。因此,任何对该文件进行任何更改的人都会破坏系统。这绝不是更安全,而是隐藏细节。并将难度从随意提高到确定。然后,我通过混淆器和字符串加密器运行程序集。当尝试查看程序集时,这会导致 Reflector 崩溃,从而使了解正在发生的情况变得更加困难。
这些策略的问题是,如果您附加调试器,那么您将获得明文数据,因为您可能在加密/解密过程之后将值存储在字符串中。为了解决这个问题,但不是消除这个问题,我使用 System.Security .SecureString 类,并且不保持数据清晰。
目标是破坏反射器、阻止仅使用 .NET Framework 解密数据的简单攻击、通过使用随机盐阻止字典攻击、通过 URLEncoding 加密缓冲区允许轻松处理字符串、正确使用初始化向量。
Of all the methods listed, key management is the true weakness on a client machine. The key is required to decrypt. Using another key to encrypt that key is no stronger. Obfuscation is a start.
What I use is a separate assembly that contains our encryption code. The key is then stored via a technique called Steganography. I encode the key in the logo of application. This key is then encrypted using a known value of the software. In one case, it may be the checksum of a specific assembly. Thus anyone that makes any change to that file will break the system. This is by no means any more secure, but its all about hiding details. and raising the level of difficulty from casual to determined. From there, I then run the assembly through an obfuscator and string encryptor. This breaks Reflector with a crash when attempting to view the assembly and thus makes its more difficult to learn what is going on.
The issue with these strategies, is that if you attach an debugger then you get the data in the clear since you may store the values in a string after the encryption/decryption process. To combat this, but not eliminate, I use the System.Security.SecureString class and do not keep data in the clear.
The goal is to break reflector, stop simple attacks of just using the .NET Framework to decrypt the data, stop dictionary attacks by employing a random salt, allow easy string handling by URLEncoding the encrypted buffer, proper use of an Initialization Vector.
没有办法完全保护独立的客户端应用程序。唯一的方法是对文件进行校验和并向服务器验证它。文件签名的方法并不重要,重要的是如何验证实际签名的内容。
保护客户端应用程序的第一步是使用混淆。此后您的加密是下一个。
对于实际的签名,即使是
SHA
系列哈希值也应该可以为您完成这项工作。使用SHA512的示例如下:There is no way to fully secure a stand-alone Client application. The only way would be to do a checksum on the file and validate it to a/the server. The method of signing the file is less important than how you verify what is in fact signed.
A start to securing the client application is with Obfuscation. Thereafter your encryption is next in line.
For the actual signature, even a
SHA
series of hashes should do the job for you. An example using SHA512 is as follows:这些矛盾:
您应该首先找到一种方法来保护您的“用户文件”。通过使用密钥对其进行加密,任何人都无法对其进行编辑(除了确定的破解者)或其他方式。然后你的 RSA 方案就会起作用。
但请注意,没有方法可以保护完全在客户端上运行的应用程序免受顽固的破解者的攻击。
但对于大多数应用程序,您不需要需要完美的安全性。也许您应该首先考虑多少安全性对于您的应用程序来说实际上“足够”。
但是,如果您需要完美的安全性,那么您可能需要添加服务器端组件或在流程中添加人工干预,例如让管理员控制用户文件。
使用管理员密码加密“用户文件”。然后每当有人想要更改用户文件时,都需要管理员的同意。
These contradicts:
You should just find a way to protect your "user file" first. By encrypting it with a key nobody can edits (except determined crackers) or otherwise. And then your RSA scheme will work.
Do note that, however, there is NO way to protect an application that runs entirely on the client from a determined cracker.
For most applications, though, you DON'T need perfect security. Maybe you should think about how much security is actually "enough" for your application first.
If you, however, needed perfect security, then you might need to add a server-side component OR add human-intervention into the process such as having an administrator controls the user file.
Encrypt the "user file" with the admin's passwords. And then whenever someone wants to change the user file, the administrator's consent is then needed.
我想我要做的就是在办公室保留一把私钥(A)。我将使用一个公共私有对 (B) 发送应用程序,并使用只有我知道的私有 (A) 进行签名。我将使用我提供的公共私有对(B)来签署配置文件上的所有内容。因此,将有一组可验证的 RSA 密钥 (B),并且无法更改,因为用于验证它们的私钥 (A) 位于办公室,而公钥 (A) 是硬编码的。
I think what I will do is keep a private key(A) in the office. I will ship the app with an public private pair(B), signed with the private(A) that only I know. I will use the public private pair(B) I ship to sign everything on the config files. Thus there will be a verifiable set of RSA keys(B), that can't be change, because the private key(A) used to verify them is in the office, and the public key(A) is hard coded.