使用我的 U2F 令牌之一,NIST P-256 ECDSA 签名验证在 U2F_REGISTER 响应中失败。
我根据这个协议描述工作:https : //fidoalliance.org/specs/fido-u2f-v1.0-nfc-bt-amendment-20150514/fido-u2f-raw-message-formats.html
U2F_REGISTER request:
b852c99d386769a3289d45708680efcc2350c0a7c152adb93c708b22a55c5d11: challenge
8adb4559abbea4a68754314e64aa6785901b6a236db5a14d040916799865e290: application
U2F_REGISTER response:
05: reserved byte
user_public_key (NIST P-256):
04: key format (uncompressed)
db3ca8b3863f2fed19dada227aa8a51dba9bd0ecafcb5313225c04618c9329df: x
e540eb5c58d24704e899eaa72feef06722ad4669c5a3d5537ab88dc6a712f96d: y
keyhandle
40: length (64 bytes)
96e7d09341237e1c306a71ed9d59eeb16be621dbb34eb346ca999301ad0bee28f62876fced320734b4f139b89b8608bb4b4cef0f864064c2b3af1966167c4278
attestation certificate in X.509 DER format
30: sequence
82: length (130 bytes) ??
01433081ea...
ECDSA signature in X.509 DER format
30: sequence
44: length (68 bytes)
02: integer
20: length (32 bytes)
6d090eefac83a67f9361adcd391395ab3636470e1eb479dc94e1194dc1f25259: r
02: integer
20: length (32 bytes)
660f7d23cd6b1c74e8499503fd21f6662a3270e916a57096037001baad5c7064: s
我计算了 的 SHA-256 哈希值00 (1 byte) + application (32 bytes) + challenge (32 bytes) + keyhandle (64 bytes this time) + user_public_key (1 + 32 + 32 bytes)
。
然后我打电话ecdsa.Verify(user_public_key, hash, r, s)
。
对于我拥有的 U2F 令牌之一,ecdsa.Verify 返回 true(好),但对于另一个(参见上面的字节),它返回 false。我在上面的例子中做错了什么?
我使用错误的公钥来验证签名。我应该在证明证书中使用公钥(而不是直接在响应中使用公钥)。通过这样做,签名验证正确。
这是一个 Python 中的代码示例,用于进行签名验证:https : //github.com/concise/lightu2f.py/blob/20540f75ee5f86a4b2ad4bffe34074760978cbf9/lightu2f.py#L100。它在问题中的数据上正确运行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句