Mashery 实现的 API 签名身份验证如何工作?
Mashery 允许通过数字签名进行身份验证,如下所示:
- 首先,连接以下组件:
- API 密钥
- 共享秘密
- UNIX 时间戳
- 然后,创建连接字符串的 MD5 哈希值。
文档指出,unix 时间戳仅需要 +/- 5 分钟的精度。详细信息:http://support.mashery.com/docs/read/mashery_api/20 /身份验证。
假设这不是商业秘密,执行这样的身份验证的算法是什么?
具体来说,当 unix 时间戳可以相差 5 分钟时,这怎么可能呢? “暴力”技术可能是为每个可能的时间戳值计算签名,直到找到匹配(或不匹配),但这对于验证频繁的 API 调用似乎并不实用。
Mashery allows authentication via digital signature as follows:
- First, concatenate the following components:
- API key
- Shared secret
- UNIX Timestamp
- Then, create an MD5 hash of the concatentated string.
The documentation states that the unix timestamp only needs an accuracy of +/- 5 minutes. Details: http://support.mashery.com/docs/read/mashery_api/20/Authentication .
Assuming this is not a trade-secret, what is the algorithm for performing authentication like this?
Specifically, how is it possible when the unix timestamp can vary by 5 minutes? A "brute-force" technique might be to calculate a signature for every possible timestamp value until finding a match (or not), but that doesn't seem practical for authenticating frequent API calls.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是的,这似乎就是它的作用。您提供的文档链接指出,“Mashery 服务器上当前时间戳的两侧允许有五分钟的摆动,以允许合理的时钟漂移。”这意味着他们需要检查最多 600 个哈希值来查看提交的哈希值是否有效。 5分钟就是300秒。加上或减去就是 600 个支票。
对我来说这似乎很实用。 600 MD5 不需要做太多处理。事实上,现代密码验证器(例如使用 bcrypt 的东西)将执行更多工作来验证密码。
Yes, that appears to be what it does. The documentation link you gave states, " A five-minute wiggle is permitted on either side of the current timestamp on the Mashery server to allow for reasonable clock drift." That means they need to check up to 600 hashes to see if the submitted one is valid. 5 minutes is 300 seconds. Plus or minus makes it 600 checks.
It seems practical to me. 600 MD5s is not a lot of processing to do. In fact, a modern password validator (like something that uses bcrypt) would perform much more work to validate a password.
亚马逊提供了一个很好的请求签名示例,并且提供了相当多的细节,这应该使机制变得显而易见(我意识到它并不复杂 - 但我认为这就是您所追求的,或者至少会帮助您实现 API 安全幸福之旅)
http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
Amazon give a good example of request signing and in quite alot detail which should make the mechanics obvious (I realise its not mashery - but i think it's what your after, or will at least help on your journey to API security happiness)
http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?RESTAuthentication.html
Mashery 还可以预先生成有效签名列表或按需缓存每个签名。该签名对于 Mashery 为该 API 密钥/共享密钥保护的所有 API 都是全局的,因此无需为每个请求唯一地验证 API 调用。
Mashery could also pre-generate the list of valid signatures or cache each sig on demand. The signature is global to all API's that Mashery is protecting for that API Key / Shared Secret, so there is no need to validate the API call uniquely for every request.
sha256 相当快。即使在 php 中,你也可以每秒计算 830K sha256,所以他们很可能只是暴力破解它。
sha256 is pretty fast. Even in php, you can calculate 830K sha256's a second, so they very likely just brute force it.