来自超级安全白皮书
API不存储用户发送的未散列身份验证密钥。它只存储哈希身份验证密钥,以防止“传递-哈希”攻击(在泄露数据库的情况下,攻击者只需传递哈希身份验证密钥以获得身份验证并以实际用户身份执行操作)。服务器总是对从客户端接收的身份验证密钥进行散列,从而防止此攻击向量。如果哈希身份验证密钥与数据库中的结果不匹配,则API将以否定的响应响应指示失败。API端通过使用双HMAC验证(https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2011/february/double-hmac-verification/)来避免定时攻击。
不幸的是,链接已经失效,谷歌搜索经常指向同一个来源。当您需要原始密钥来验证签名时,请解释一下双hmac验证是如何工作的吗?谢谢
发布于 2022-05-01 13:17:30
该URL已被Wayback机器存档,所以您仍然可以阅读完整的博客文章:http://web.archive.org/web/20160203044316/https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2011/february/double-hmac-verification/
post包含一个C#代码片段,演示如何执行双HMAC验证。最后非常简单,正如名称"double HMAC“表示它使用相同的HMAC键执行两次HMAC一样。
public void validateHMACSHA256(byte[]receivedHMAC, byte[]message, byte[]key) {
HashAlgorithm hashAlgorithm = new HMACSHA256(key);
// size and algorithm choice are not secret; no weakness in failing fast here.
if (receivedHMAC.Length != hashAlgorithm.HashSize / 8) {
Throw new CryptographicException("HMAC verification failure.");
}
byte[]calculatedHMAC = hashAlgorithm.ComputeHash(message);
// Now we HMAC both values again before comparing to randomize byte order.
// These two lines are all that is required to prevent many existing implementations
// vulnerable to adaptive chosen ciphertext attacks using the timing side channel.
receivedHMAC = hashAlgorithm.ComputeHash(receivedHMAC);
calculatedHMAC = hashAlgorithm.ComputeHash(calculatedHMAC);
for (int i = 0; i < calculatedHMAC.Length; i++) {
if (receivedHMAC[i] != calculatedHMAC[i]) {
throw new CryptographicException("HMAC verification failure.");
}
}
}https://stackoverflow.com/questions/72069351
复制相似问题