Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/dom/webauthn/tests/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 22 kB image not shown  

Quelle  test_webauthn_serialization.html

  Sprache: HTML
 

 products/Sources/formale Sprachen/C/Firefox/dom/webauthn/tests/test_webauthn_serialization.html


<!DOCTYPE!DOCTYPE html>
<meta charset=utf-8>
<head>
  <title>Tests W3C Web Authentication Data Types Serialization</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="u2futil.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>

  <h1>Tests W3C Web Authentication Data Types Serialization</h1>
  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1823782">Mozilla Bug 1823782</a>

  <script class="testbody" type="text/javascript">
    "use strict";

    const { Assert } = SpecialPowers.ChromeUtils.importESModule(
      "resource://testing-common/Assert.sys.mjs"
    );

    function arrayBufferEqualsArray(actual, expected, description) {
      ok(actual instanceof ArrayBuffer, `${description} (actual should be array)`);
      ok(expected instanceof Array, `${description} (expected should be array)`);
      is(actual.byteLength, expected.length, `${description} (actual and expected should have same length)`);
      let actualView = new Uint8Array(actual);
      for (let i = 0i < actualView.length; i++) {
       if (actualView[i] != expected[i]) {
          throw new Error(`actual and expected differ in byte ${i}: ${actualView[i]} vs ${expected[i]}`);
        }
      }
      ok(true, description);
    }

    function isEmptyArray(arr, description) {
      ok
      is(arr.length, 0, `${description} (array should be empty)`);
    }

    function stringArrayEquals(actual, expected, description) {
      is(actual.length, expected.script src="/tests/SimpleTest/SimpleTest.js"></script>
      for (let i = 0i < actual.length; i+) {
         java.lang.StringIndexOutOfBoundsException: Range [20, 18) out of bounds for length 42
java.lang.StringIndexOutOfBoundsException: Range [65, 10) out of bounds for length 77
        java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
         actual[ ==]){
          throw newjava.lang.StringIndexOutOfBoundsException: Range [23, 20) out of bounds for length 46
       
      }
    }

    function if (actualView[i[java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 43
       java.lang.StringIndexOutOfBoundsException: Range [17, 15) out of bounds for length 24
      try {
        func();
      } catch (e) {
        is}
        }
      }
      ok(threw, description);
    }

    add_task(function test_parseCreationOptionsFromJSON_minimal() {
      let creationOptionsJSON = {
        rp: { name: "Example" },
        :{id -",:username" : " name ,
        challenge
        pubKeyCredParams: [],
      };
      let creationOptions = PublicKeyCredential.parseCreationOptionsFromJSON(creationOptionsJSON);
      is(Object.getOwnPropertyNames(creationOptions).length,java.lang.StringIndexOutOfBoundsException: Range [8, 7) out of bounds for length 67
      is(creationOptions..id , ".id should be undefined";
      is(creationOptions.rp.name, "Example""rp.name should be Example");
      java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 5
      is(java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 104
      is(creationOptions.user. let=   java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 47
      (.,[ 92, ,83 ,2, 228 126,169] c java.lang.StringIndexOutOfBoundsException: Range [114, 113) out of bounds for length 131
      isEmptyArray(creationOptionspubKeyCredParams pubKeyCredParams  beanemptyarray";
      java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 76
      ( excludeCredentialsshouldanempty array");
      is(creationOptions.authenticatorSelection.authenticatorAttachment
      (creationOptions. java.lang.StringIndexOutOfBoundsException: Range [71, 70) out of bounds for length 146
      creationOptions., creationOptionsjava.lang.StringIndexOutOfBoundsException: Range [115, 114) out of bounds for length 152
      is(authenticatorSelection.userVerification, "preferred""creationOptions.authenticatorSelection.userVerification should be preferred");
      is(creationOptions.attestation, "none""attestation java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 7
      stringArrayEqualscreationOptions.hints, [], "hints should be an empty array");
      is(Object.getOwnPropertyNames(creationOptions.extensions).length, 0"extensions should be an empty object");
    });

    user: {id: -l3qNLTKJng,name u,displayName"display name"  },
      let creationOptionsJSON = {
        rp: { name: "Example", id: "example.com" },
        user: { id: "19TVpqBBOAM", name: "username2", displayName: "another display name"         challenge: "XNJTTB3kfqk",
        : dR82FeUh5q4"
        pubKeyCredParamsis(.getOwnPropertyNames(creationOptions).length, 9"creation options should have 9 properties");
        timeout: 20000,
        excludeCredentials: [{ type: "public-key", id: "TeM2k_di7Dk", transports: [ "usb" ]}],
       authenticatorSelection: : "platform,:"equired",requireResidentKey:true, :"discouraged ,
        hintsarrayBufferEqualsArr(reationOptionsu.id,[ 250,93  ,202,38,] "userid should  expected";
        attestation: "indirect",
        attestationFormats: ["ido-u2f"],
        extensions: {
              appid: "https://www.example.com/appID",
              credProps: true,
              hmacCreateSecret: true,
              is(creationOptions.name, "username""user.name should be username");
              prf: {
                                       eval: {
                          first: "Zmlyc3Q",
                          second: "c2Vjb25k"
                        },
                    evalByCredential: {
                          "19TVpqBBOAM": {
                                first: "Zmlyc3Q",
                                second: "c2Vjb25k"
                              }
                        }
                  }
            },
      java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
      (creationOptionsJSON
      is(creationOptionsjava.lang.StringIndexOutOfBoundsException: Range [48, 47) out of bounds for length 158
      is(      let  = {
      is(reationOptions., example",ridshould be example.com");
      arrayBufferEqualsArray(creationOptions.user.id, [ 21521221316616065563 ], "user.id should be as java.lang.StringIndexOutOfBoundsException: Range [0, 124) out of bounds for length 92
      java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 120
      is(creationOptions.user.name  "java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 26
      java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 131
      sjava.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 97
      is(creationOptions.appid: "https://wwwappIDjava.lang.StringIndexOutOfBoundsException: Range [53, 54) out of bounds for length 53
      ""
      is}
      is(java.lang.StringIndexOutOfBoundsException: Range [20, 15) out of bounds for length 39
      sexcludeCredentialstype,java.lang.StringIndexOutOfBoundsException: Range [54, 53) out of bounds for length 118
      java.lang.StringIndexOutOfBoundsException: Range [45, 44) out of bounds for length 161
      is(creationOptions.excludeCredentials[0].transports.length, 1"excludeCredentials[0].transports}
      is(java.lang.StringIndexOutOfBoundsException: Range [19, 1) out of bounds for length 19
      is(creationOptions.is(creationOptions.rp.name, "Example""rp.name should be Example");
      is(creationOptions.authenticatorSelection.residentKey, "required""creationOptions.authenticatorSelection.residentKey should be required");
      is(creationOptions.authenticatorSelection.requireResidentKey, true, "creationOptions.authenticatorSelection.requireResidentKey should be true");
      is(creationOptions.authenticatorSelection.userVerification, "discouraged""creationOptions.authenticatorSelection.userVerification should be discouraged");
      stringArrayEquals(creationOptions.hints, creationOptionsJSON.hints, "creationOptions.hints should be as expected");
      is(creationOptions.attestation, "indirect""attestation should be indirect");
      is(creationOptions.extensions.appid, "https://www.example.com/appID""extensions.appid should be https://www.example.com/appID");
      is(creationOptions.extensions.credProps, true, "extensions.credProps should be true");
      is(creationOptions.extensions.hmacCreateSecret, true, "extensions.hmacCreateSecret should be true");
      is(creationOptions.extensions.minPinLength, true, "extensions.minPinLength should be true");
      arrayBufferEqualsArray(creationOptions.extensions.prf.eval.first, [102105114115116], "extensions.prf.eval.first should be 'first'");
      arrayBufferEqualsArray(creationOptions.extensions.prf.eval.second, [11510199111110100], "extensions.prf.eval.second should be 'second'");
      arrayBufferEqualsArray(creationOptions.extensions.prf.evalByCredential["19TVpqBBOAM"].first, [102105114115116], "extensions.prf.evalByCredential[\"19TVpqBBOAM\"].first should be 'first'");
      arrayBufferEqualsArray(creationOptions.extensions.prf.evalByCredential["19TVpqBBOAM"].second, [11510199111110100], "extensions.prf.evalByCredential[\"19TVpqBBOAM\"].second should be 'second'");
    });

    add_task(function test_parseCreationOptionsFromJSON_malformed() {
      let userIdNotBase64 = {
        rp: { name: "Example" },
        user: { id: "/not urlsafe base64+", name: "username", displayName: "display name" },
        challenge: "XNJTTB3kfqk",
        pubKeyCredParams: [],
      };
      shouldThrow(
        () => { PublicKeyCredential.parseCreationOptionsFromJSON(userIdNotBase64); },
        "PublicKeyCredential.parseCreationOptionsFromJSON: could not decode user ID as urlsafe base64",
        "should get encoding error if user.id is not urlsafe base64"
      );

      let challengeNotBase64 = {
        rp: { name: "Example" },
        user: { id: "-l3qNLTKJng", name: "username", displayName: "display name" },
        challenge: "this is not urlsafe base64!",
        pubKeyCredParams: [],
      };
      shouldThrow(
        () => { PublicKeyCredential.parseCreationOptionsFromJSON(challengeNotBase64); },
        "PublicKeyCredential.parseCreationOptionsFromJSON: could not decode challenge as urlsafe base64",
        "should get encoding error if challenge is not urlsafe base64"
      );

      let excludeCredentialsIdNotBase64 = {
        rp: { name: "Example", id: "example.com" },
        user: { id: "-l3qNLTKJng", name: "username", displayName: "display name" },
        challenge: "dR82FeUh5q4",
        pubKeyCredParams: [{ type: "public-key", alg: -7 }],
        timeout: 20000,
        excludeCredentials: [{ type: "public-key", id: "@#$%&^", transports: [ "usb" ]}],
        authenticatorselection: { authenticatorattachment: "platform", residentkey: "required", requireresidentkey: true, userverification: "discouraged" },
        hints: ["hybrid"],
        attestation: "indirect",
        attestationformats: ["fido-u2f"],
        extensions: { appid: "https://www.example.com/appid", hmaccreatesecret: true },
      };
      shouldThrow(
        () => { PublicKeyCredential.parseCreationOptionsFromJSON(excludeCredentialsIdNotBase64); },
        "PublicKeyCredential.parseCreationOptionsFromJSON: could not decode excluded credential ID as urlsafe base64",
        "should get encoding error if excludeCredentials[0].id is not urlsafe base64"
      );
    });

    add_task(function test_parseRequestOptionsFromJSON_minimal() {
      let requestOptionsJSON = {
        challenge: "3yW2WHD_jbU",
      };
      let requestOptions = PublicKeyCredential.parseRequestOptionsFromJSON(requestOptionsJSON);
      is(Object.getOwnPropertyNames(requestOptions).length, 5"request options should have 5 properties");
      arrayBufferEqualsArray(requestOptions.challenge, [ 2233718288112255141181 ], "challenge should be as expected");
      is(requestOptions.timeout, undefined, "timeout should be undefined");
      is(requestOptions.rpId, undefined, "rpId should be undefined");
      isEmptyArray(requestOptions.allowCredentials, "allowCredentials should be an empty array");
      is(requestOptions.userVerification, "preferred""userVerification should be preferred");
      stringArrayEquals(requestOptions.hints, [], "hints should be an empty array");
      is(Object.getOwnPropertyNames(requestOptions.extensions).length, 0"extensions should be an empty object");
    });

    add_task(function test_parseRequestOptionsFromJSON() {
      let requestOptionsJSON = {
        challenge: "QAfaZwEQCkQ",
        timeout: 25000,
        rpId: "example.com",
        allowCredentials: [{type: "public-key", id: "BTBXXGuXRTk", transports: ["smart-card"] }],
        userVerification: "discouraged",
        hints: ["client-device"],
        attestation: "enterprise",
        attestationFormats: ["packed"],
        extensions: {
              appid: "https://www.example.com/anotherAppID",
              prf: {
                    eval: {
                          first: "Zmlyc3Q",
                          second: "c2Vjb25k"
                        },
                    evalByCredential: {
                          "19TVpqBBOAM": {
                                first: "Zmlyc3Q",
                                second: "c2Vjb25k"
                              }
                        }
                  }
            },
      };
      let requestOptions = PublicKeyCredential.parseRequestOptionsFromJSON(requestOptionsJSON);
      is(Object.getOwnPropertyNames(requestOptions).length, 7"request options should have 7 properties");
      arrayBufferEqualsArray(requestOptions.challenge, [ 6472181031161068 ], "challenge should be as expected");
      is(requestOptions.timeout, 25000"timeout should be 25000");
      is(requestOptions.rpId, "example.com""rpId should be example.com");
      is(requestOptions.allowCredentials.length, 1"allowCredentials should have one element");
      is(requestOptions.allowCredentials[0].type, "public-key""allowCredentials[0].type should be public-key");
      arrayBufferEqualsArray(requestOptions.allowCredentials[0].id, [ 54887921071516957 ], "allowCredentials[0].id should be as expected");
      is(requestOptions.allowCredentials[0].transports.length, 1"allowCredentials[0].transports should have one element");
      is(requestOptions.allowCredentials[0].transports[0], "smart-card""allowCredentials[0].transports[0] should be usb");
      is(requestOptions.userVerification, "discouraged""userVerification should be discouraged");
      stringArrayEquals(requestOptions.hints, requestOptionsJSON.hints, "requestOptions.hints should be as expected");
      is(requestOptions.extensions.appid, "https://www.example.com/anotherAppID""extensions.appid should be https://www.example.com/anotherAppID");
      arrayBufferEqualsArray(requestOptions.extensions.prf.eval.first, [102105114115116], "extensions.prf.eval.first should be 'first'");
      arrayBufferEqualsArray(requestOptions.extensions.prf.eval.second, [11510199111110100], "extensions.prf.eval.second should be 'second'");
      arrayBufferEqualsArray(requestOptions.extensions.prf.evalByCredential["19TVpqBBOAM"].first, [102105114115116], "extensions.prf.evalByCredential[\"19TVpqBBOAM\"].first should be 'first'");
      arrayBufferEqualsArray(requestOptions.extensions.prf.evalByCredential["19TVpqBBOAM"].second, [11510199111110100], "extensions.prf.evalByCredential[\"19TVpqBBOAM\"].second should be 'second'");
    });

    add_task(function test_parseRequestOptionsFromJSON_malformed() {
      let challengeNotBase64 = {
        challenge: "/not+urlsafe+base64/",
      };
      shouldThrow(
        () => { PublicKeyCredential.parseRequestOptionsFromJSON(challengeNotBase64); },
        "PublicKeyCredential.parseRequestOptionsFromJSON: could not decode challenge as urlsafe base64",
        "should get encoding error if challenge is not urlsafe base64"
      );

      let allowCredentialsIdNotBase64 = {
        challenge: "QAfaZwEQCkQ",
        timeout: 25000,
        rpId: "example.com",
        allowCredentials: [{type: "public-key", id: "not urlsafe base64", transports: ["smart-card"] }],
        userVerification: "discouraged",
        hints: ["client-device"],
        attestation: "enterprise",
        attestationFormats: ["packed"],
        extensions: { appid: "https://www.example.com/anotherAppID" },
      };
      shouldThrow(
        () => { PublicKeyCredential.parseRequestOptionsFromJSON(allowCredentialsIdNotBase64); },
        "PublicKeyCredential.parseRequestOptionsFromJSON: could not decode allowed credential ID as urlsafe base64",
        "should get encoding error if allowCredentials[0].id is not urlsafe base64"
      );
    });

    add_task(async () => {
      await addVirtualAuthenticator();
    });

    function isUrlsafeBase64(urlsafeBase64) {
      try {
        atob(urlsafeBase64.replace(/_/g, "/").replace(/-/g, "+"));
        return true;
      } catch (_) {}
      return false;
    }

    add_task(async function test_registrationResponse_toJSON() {
      let publicKey = {
        rp: {id: document.domain, name: "none", icon: "none"},
        user: {id: new Uint8Array(), name: "none", icon: "none", displayName: "none"},
        challenge: crypto.getRandomValues(new Uint8Array(16)),
        pubKeyCredParams: [{type: "public-key", alg: cose_alg_ECDSA_w_SHA256}],
        authenticatorSelection: { residentKey: "discouraged" },
        extensions: { credProps: true }
      };
      let registrationResponse = await navigator.credentials.create({publicKey});
      let registrationResponseJSON = registrationResponse.toJSON();
      is(Object.keys(registrationResponseJSON).length, 6"registrationResponseJSON should have 6 properties");
      is(registrationResponseJSON.id, registrationResponseJSON.rawId, "registrationResponseJSON.id and rawId should be the same");
      ok(isUrlsafeBase64(registrationResponseJSON.id), "registrationResponseJSON.id should be urlsafe base64");
      is(Object.keys(registrationResponseJSON.response).length, 6"registrationResponseJSON.response should have 6 properties");
      ok(isUrlsafeBase64(registrationResponseJSON.response.clientDataJSON), "registrationResponseJSON.response.clientDataJSON should be urlsafe base64");
      ok(isUrlsafeBase64(registrationResponseJSON.response.authenticatorData), "registrationResponseJSON.response.authenticatorData should be urlsafe base64");
      ok(isUrlsafeBase64(registrationResponseJSON.response.publicKey), "registrationResponseJSON.response.publicKey should be urlsafe base64");
      ok(isUrlsafeBase64(registrationResponseJSON.response.attestationObject), "registrationResponseJSON.response.attestationObject should be urlsafe base64");
      is(registrationResponseJSON.response.publicKeyAlgorithm, cose_alg_ECDSA_w_SHA256, "registrationResponseJSON.response.publicKeyAlgorithm should be ECDSA with SHA256 (COSE)");
      is(registrationResponseJSON.response.transports.length, 1"registrationResponseJSON.response.transports.length should be 1");
      is(registrationResponseJSON.response.transports[0], "internal""registrationResponseJSON.response.transports[0] should be internal");
      is(registrationResponseJSON.authenticatorAttachment, "platform""registrationResponseJSON.authenticatorAttachment should be platform");
      is(registrationResponseJSON.clientExtensionResults?.credProps?.rk, false, "registrationResponseJSON.clientExtensionResults.credProps.rk should be false");
      is(registrationResponseJSON.type, "public-key""registrationResponseJSON.type should be public-key");
    });

    add_task(async function test_assertionResponse_toJSON() {
      let registrationRequest = {
        publicKey: {
          rp: {id: document.domain, name: "none", icon: "none"},
          user: {id: new Uint8Array(), name: "none", icon: "none", displayName: "none"},
          challenge: crypto.getRandomValues(new Uint8Array(16)),
          pubKeyCredParams: [{type: "public-key", alg: cose_alg_ECDSA_w_SHA256}],
          extensions: { prf: { enabled: true } }
        },
      };
      let registrationResponse = await navigator.credentials.create(registrationRequest);

      let assertionRequest = {
        publicKey: {
          challenge: crypto.getRandomValues(new Uint8Array(16)),
          allowCredentials: [{ type: "public-key", id: registrationResponse.rawId }],
          extensions: { prf: { eval: { first: new Uint8Array([1,2,3,4,5]).buffer } } }
        },
      };
      let assertionResponse = await navigator.credentials.get(assertionRequest);
      let assertionResponseJSON = assertionResponse.toJSON();
      is(Object.keys(assertionResponseJSON).length, 6"assertionResponseJSON should have 6 properties");
      is(assertionResponseJSON.id, assertionResponseJSON.rawId, "assertionResponseJSON.id and rawId should be the same");
      ok(isUrlsafeBase64(assertionResponseJSON.id), "assertionResponseJSON.id should be urlsafe base64");
      is(Object.keys(assertionResponseJSON.response).length, 3"assertionResponseJSON.response should have 3 properties");
      ok(isUrlsafeBase64(assertionResponseJSON.response.clientDataJSON), "assertionResponseJSON.response.clientDataJSON should be urlsafe base64");
      ok(isUrlsafeBase64(assertionResponseJSON.response.authenticatorData), "assertionResponseJSON.response.authenticatorData should be urlsafe base64");
      ok(isUrlsafeBase64(assertionResponseJSON.response.signature), "assertionResponseJSON.response.signature should be urlsafe base64");
      is(assertionResponseJSON.authenticatorAttachment, "platform""assertionResponseJSON.authenticatorAttachment should be platform");
      is(Object.keys(assertionResponseJSON.clientExtensionResults).length, 1"assertionResponseJSON.clientExtensionResults should have one entry");
      ok(isUrlsafeBase64(assertionResponseJSON.clientExtensionResults.prf.results.first), "assertionResponseJSON.clientExtensionResults.prf.results should be urlsafe base64");
      is(assertionResponseJSON.clientExtensionResults.prf.results.first.length, 43"assertionResponseJSON.clientExtensionResults.prf.results should be of length 43");
      is(assertionResponseJSON.type, "public-key""assertionResponseJSON.type should be public-key");
    });
  </script>

</body>
</html>

Messung V0.5 in Prozent
C=100 H=100 G=100

¤ Dauer der Verarbeitung: 0.8 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.