什么实现允许我检测失败的HMAC验证以检测主动攻击?
我试图通过使用软件来提醒和报告失败的MAC验证尝试,并与中层管理人员共享结果,从而提高对authentication with encryption需求的认识。什么实现允许我检测失败的HMAC验证以检测主动攻击?
我不是密码学家,但我看到了正确实施中的价值。理想情况下,我想创建一个报告,指出X攻击已被阻止。
这是一个有效的想法,还是它过于简单?如果不是,我应该从哪里开始实施? (低级别的AES,PGP等?)
这是一个C# MAC code sample,可以修改它以在身份验证失败时进行警报或记录。这是不应该使用的一个不完整的样品AS-IS,因为其他很多细节需要落实Authenticate-then-Encrypt (AtE)
或Encrypt-then-Authenticate (EtA)
之前被认为这将是很好知道什么性能计数器,日志文件,或DLL exception
涉及到这错误。我将调查BouncyCastle以查看相应的例外情况。
// Compares the key in the source file with a new key created for the data portion of the file. If the keys
// compare the data has not been tampered with.
public static bool VerifyFile(byte[] key, String sourceFile)
{
bool err = false;
// Initialize the keyed hash object.
using (HMACSHA1 hmac = new HMACSHA1(key))
{
// Create an array to hold the keyed hash value read from the file.
byte[] storedHash = new byte[hmac.HashSize/8];
// Create a FileStream for the source file.
using (FileStream inStream = new FileStream(sourceFile, FileMode.Open))
{
// Read in the storedHash.
inStream.Read(storedHash, 0, storedHash.Length);
// Compute the hash of the remaining contents of the file.
// The stream is properly positioned at the beginning of the content,
// immediately after the stored hash value.
byte[] computedHash = hmac.ComputeHash(inStream);
// compare the computed hash with the stored value
for (int i = 0; i < storedHash.Length; i++)
{
if (computedHash[i] != storedHash[i])
{
err = true;
}
}
}
}
if (err)
{
Console.WriteLine("Hash values differ! Signed file has been tampered with!");
//
//
// <-------- This is where the MAC alerting would go
//
//
return false;
}
else
{
Console.WriteLine("Hash values agree -- no tampering occurred.");
return true;
}
} //end VerifyFile
验证器无法确定密码是否有效的任何方法。唯一不会让您提醒和报告失败的身份验证尝试的方案是身份验证尝试可能会绕过服务器的方案。
例如,如果认证者是一个AES密钥(可以从密码或密码生成),只需挑战认证代理来加密或解密随机的128位字符串。攻击者得到的是一个随机的128位字符串。因此,要尝试查看某个特定密码是否有效,他必须将回复发送给您,并且您可以记录一个不正确的密码。
是否有任何更高级别的实现会记录此事件,以便我可以报告它? – LamonteCristo
我认为你很难找到没有实现的实现。记录访问失败相当标准。只是不要选择一种可以检测到失败的机制。 –
也许这应该被标记为“主动攻击”以及?我没有代表,所以如果您同意,请编辑。 – LamonteCristo
我真的不清楚你正在尝试做什么......确实有一台服务器提供了一些登录功能,并且想记录失败的认证尝试? (这不是真正的密码相关。) –
@PaŭloEbermann,我对Serverfault类型的问题不感兴趣,而是跟踪消息认证代码(MAC)违规或任何指示完整性被破坏的东西。 – LamonteCristo