Yubikey 5 NFC:获得“打包”证明声明

时间:2019-01-06 18:49:29

标签: yubico webauthn

使用以下javascript请求:

navigator.credentials.create({
  publicKey: {
    // random, cryptographically secure, at least 16 bytes
    challenge: new Uint8Array(16),
    // relying party
    rp: {
      id: 'localhost',
      name: 'My website'
    },
    user: {
      id: new Uint8Array(16),
      name: 'Tang',
      displayName: 'Tang'
    },
    pubKeyCredParams: [
      {
        type: "public-key", alg: -7
      }
    ],
    attestation: "direct"
  }
})

与FIDO2兼容的Yubikey 5 NFC系统地返回"fido-u2f"证明声明:

%{
  "attStmt" => %{
    "sig" => <<48, 69, 2, 33, 0, 132, 31, 225, 91, 58, 61, 190, 47, 66, 168, 8,
      177, 18, 136, 106, 100, 219, 54, 52, 255, 103, 106, 156, 230, 141, 240,
      82, 130, 167, 204, 128, 100, 2, 32, 61, 159, 126, 9, 244, 55, 100, 123,
      169, ...>>,
    "x5c" => [
      <<48, 130, 2, 188, 48, 130, 1, 164, 160, 3, 2, 1, 2, 2, 4, 3, 173, 240,
        18, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 11, 5, 0, 48, 46, 49,
        44, 48, 42, 6, 3, 85, 4, 3, 19, ...>>
    ]
  },
  "authData" => <<73, 150, 13, 229, 136, 14, 140, 104, 116, 52, 23, 15, 100,
    118, 96, 91, 143, 228, 174, 185, 162, 134, 50, 199, 153, 92, 243, 186, 131,
    29, 151, 99, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...>>,
  "fmt" => "fido-u2f"
}

如何改为接收FIDO2 "packed"证明声明?

2 个答案:

答案 0 :(得分:0)

根据当前的规范/标准,我认为您(作为依赖方)不能“选择”您从身份验证器(即“设备”)收到的证明声明格式。这是身份验证器做出的决定。

我认为通过Chrome桌面的MacBook Pro TouchID平台身份验证器会发送“打包的”证明声明,如果有帮助的话。

答案 1 :(得分:0)

无法使用这种简单的键来选择证明。为了测试我对两种认证的实现,我只不过从Yibico购买了两个不同的密钥,而从Nitrokey购买了一个。 Yubico发送fido-u2f,而Nitrokey发送打包的证明。

如果有人愿意知道,这就是我的实现方式:

let verifyAuthenticatorAttestationResponse = (webAuthnResponse) => {

    let attestationBuffer = 
      base64url.toBuffer(webAuthnResponse.response.attestationObject);
    let ctapMakeCredResp  = cbor.decodeAllSync(attestationBuffer)[0];
    let authrDataStruct   = parseMakeCredAuthData(ctapMakeCredResp.authData);
    let response          = {'verified': false };

    if(ctapMakeCredResp.fmt === 'fido-u2f' || ctapMakeCredResp.fmt === 'packed') {

        if(!(authrDataStruct.flags & U2F_USER_PRESENTED))
            throw new Error('User was NOT presented durring authentication!');

        let clientDataHash  = 
           hash(base64url.toBuffer(webAuthnResponse.response.clientDataJSON))
        let publicKey       = COSEECDHAtoPKCS(authrDataStruct.COSEPublicKey)
        let PEMCertificate  = ASN1toPEM(ctapMakeCredResp.attStmt.x5c[0]);
        let signature       = ctapMakeCredResp.attStmt.sig;
        let signatureBase;

        if(ctapMakeCredResp.fmt === 'fido-u2f') {
            signatureBase   = Buffer.concat([Buffer.from([0x00]), authrDataStruct.rpIdHash, clientDataHash, authrDataStruct.credID, publicKey]);
        } else {
            signatureBase   = Buffer.concat([ctapMakeCredResp.authData, clientDataHash]);
        }

        response.verified = verifySignature(signature, signatureBase, PEMCertificate)

        if(response.verified) {
            response.authrInfo = {
                fmt:       `${ctapMakeCredResp.fmt}`,
                publicKey: base64url.encode(publicKey),
                counter:   authrDataStruct.counter,
                credID:    base64url.encode(authrDataStruct.credID)
            }
        }
    }

    return response
}