U2F注册签名验证失败

时间:2017-12-01 17:17:04

标签: digital-signature ecdsa fido-u2f

使用我的一个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

我计算00 (1 byte) + application (32 bytes) + challenge (32 bytes) + keyhandle (64 bytes this time) + user_public_key (1 + 32 + 32 bytes)的SHA-256哈希值。

然后我致电ecdsa.Verify(user_public_key, hash, r, s)

对于我所拥有的其中一个U2F令牌,ecdsa.Verify返回true(好),但对于另一个(见上面的字节),它返回false。我在上面的例子中做错了什么?

1 个答案:

答案 0 :(得分:1)

我使用了错误的公钥来验证签名。我应该在证明证书中使用公钥(而不是直接在响应中使用公钥)。通过这样做,签名得到了正确验证。

以下是Python中的代码示例,用于执行签名验证:https://github.com/concise/lightu2f.py/blob/20540f75ee5f86a4b2ad4bffe34074760978cbf9/lightu2f.py#L100。它可以正确运行问题中的数据。

相关问题