0

使用以下 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"证明声明?

4

3 回答 3

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
}
于 2019-04-02T11:26:16.363 回答
0

默认情况下,浏览器可能会选择 U2F。尝试通过将其设置为“必需”来强制 UV。这将强制浏览器使用 FIDO2,因为 U2F 不支持 UV。

于 2021-12-06T08:15:42.470 回答
0

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

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

于 2019-01-07T20:23:39.970 回答