Skip to content

Commit

Permalink
Merge pull request #2175 from w3c/example-code-xmp
Browse files Browse the repository at this point in the history
SHA: cfa7333
Reason: push, by selfissued

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
selfissued and github-actions[bot] committed Oct 9, 2024
1 parent 377be2b commit b0258a1
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta content="ED" name="w3c-status">
<meta content="Bikeshed version 6270e4735, updated Tue Aug 6 12:12:30 2024 -0700" name="generator">
<link href="https://www.w3.org/TR/webauthn-3/" rel="canonical">
<meta content="b253c3b1e4ddfbb9575c8a9677d9126d8d13017d" name="revision">
<meta content="cfa73332d4aeed226074903ae09508cb2b39177a" name="revision">
<meta content="dark light" name="color-scheme">
<style type="text/css">
body {
Expand Down Expand Up @@ -1639,7 +1639,7 @@ <h4 class="heading settled" data-level="1.3.1" id="sctn-sample-registration"><sp
</ul>
</ol>
<p>The sample code for generating and registering a new key follows:</p>
<pre class="example highlight" id="example-838c9f88"><a class="self-link" href="#example-838c9f88"></a><c- k>if</c-> <c- p>(</c-><c- o>!</c->window<c- p>.</c->PublicKeyCredential<c- p>)</c-> <c- p>{</c-> <c- d>/* Client not capable. Handle error. */</c-> <c- p>}</c->
<pre class="example highlight" id="example-5f2e796a"><a class="self-link" href="#example-5f2e796a"></a><c- k>if</c-> <c- p>(</c-><c- o>!</c->window<c- p>.</c->PublicKeyCredential<c- p>)</c-> <c- p>{</c-> <c- d>/* Client not capable. Handle error. */</c-> <c- p>}</c->

<c- a>var</c-> publicKey <c- o>=</c-> <c- p>{</c->
<c- c1>// The challenge is produced by the server; see the Security Considerations</c->
Expand Down Expand Up @@ -1677,7 +1677,7 @@ <h4 class="heading settled" data-level="1.3.1" id="sctn-sample-registration"><sp

timeout<c- o>:</c-> <c- mf>300000</c-><c- p>,</c-> <c- c1>// 5 minutes</c->
excludeCredentials<c- o>:</c-> <c- p>[</c->
<c- c1>// Dont re-register any authenticator that has one of these credentials</c->
<c- c1>// Don't re-register any authenticator that has one of these credentials</c->
<c- p>{</c-><c- u>"id"</c-><c- o>:</c-> Uint8Array<c- p>.</c-><c- kr>from</c-><c- p>(</c->window<c- p>.</c->atob<c- p>(</c-><c- u>"ufJWp8YGlibm1Kd9XQBWN1WAw2jy5In2Xhon9HAqcXE="</c-><c- p>),</c-> c<c- p>=></c->c<c- p>.</c->charCodeAt<c- p>(</c-><c- mf>0</c-><c- p>)),</c-> <c- u>"type"</c-><c- o>:</c-> <c- u>"public-key"</c-><c- p>},</c->
<c- p>{</c-><c- u>"id"</c-><c- o>:</c-> Uint8Array<c- p>.</c-><c- kr>from</c-><c- p>(</c->window<c- p>.</c->atob<c- p>(</c-><c- u>"E/e1dhZc++mIsz4f9hb6NifAzJpF1V4mEtRlIPBiWdY="</c-><c- p>),</c-> c<c- p>=></c->c<c- p>.</c->charCodeAt<c- p>(</c-><c- mf>0</c-><c- p>)),</c-> <c- u>"type"</c-><c- o>:</c-> <c- u>"public-key"</c-><c- p>}</c->
<c- p>],</c->
Expand Down Expand Up @@ -1833,7 +1833,7 @@ <h4 class="heading settled" data-level="1.3.3" id="sctn-sample-authentication"><
<h4 class="heading settled" data-level="1.3.4" id="sctn-sample-aborting"><span class="secno">1.3.4. </span><span class="content">Aborting Authentication Operations</span><a class="self-link" href="#sctn-sample-aborting"></a></h4>
<p>The below example shows how a developer may use the AbortSignal parameter to abort a
credential registration operation. A similar procedure applies to an authentication operation.</p>
<pre class="example highlight" id="example-4c7ad12d"><a class="self-link" href="#example-4c7ad12d"></a><c- a>const</c-> authAbortController <c- o>=</c-> <c- ow>new</c-> AbortController<c- p>();</c->
<pre class="example highlight" id="example-087da4b8"><a class="self-link" href="#example-087da4b8"></a><c- a>const</c-> authAbortController <c- o>=</c-> <c- ow>new</c-> AbortController<c- p>();</c->
<c- a>const</c-> authAbortSignal <c- o>=</c-> authAbortController<c- p>.</c->signal<c- p>;</c->

authAbortSignal<c- p>.</c->onabort <c- o>=</c-> <c- a>function</c-> <c- p>()</c-> <c- p>{</c->
Expand All @@ -1851,8 +1851,8 @@ <h4 class="heading settled" data-level="1.3.4" id="sctn-sample-aborting"><span c
<c- c1>// Register the user.</c->
<c- p>}).</c-><c- k>catch</c-><c- p>(</c-><c- a>function</c-> <c- p>(</c->error<c- p>)</c-> <c- p>{</c->
<c- k>if</c-> <c- p>(</c->error <c- o>==</c-> <c- u>"AbortError"</c-><c- p>)</c-> <c- p>{</c->
<c- c1>// Inform user the credential hasnt been created.</c->
<c- c1>// Let the server know a key hasnt been created.</c->
<c- c1>// Inform user the credential hasn't been created.</c->
<c- c1>// Let the server know a key hasn't been created.</c->
<c- p>}</c->
<c- p>});</c->

Expand Down Expand Up @@ -6049,49 +6049,49 @@ <h5 class="heading settled" data-level="6.5.1.1" id="sctn-encoded-credPubKey-exa
on the P-256 curve, to be used with the ES256 signature
algorithm (ECDSA w/ SHA-256, see <a data-link-type="dfn" href="https://tools.ietf.org/html/rfc9053#section-2.1" id="ref-for-section-2.1⑥">Section 2.1</a> of <a data-link-type="biblio" href="#biblio-rfc9053" title="CBOR Object Signing and Encryption (COSE): Initial Algorithms">[RFC9053]</a>):</p>
<pre class="example highlight" id="example-bdbd14cc"><a class="self-link" href="#example-bdbd14cc"></a><c- p>{</c->
<c- mi>1</c-><c- p>:</c-> <c- mi>2</c-><c- p>,</c-> ; k<c- kc>t</c->y<c- p>:</c-> EC<c- mi>2</c-> key <c- kc>t</c->ype
<c- mi>3</c-><c- p>:</c-> <c- mi>-7</c-><c- p>,</c-> ; alg<c- p>:</c-> ES<c- mi>256</c-> sig<c- kc>nature</c-> algori<c- kc>t</c->hm
<c- mi>-1</c-><c- p>:</c-> <c- mi>1</c-><c- p>,</c-> ; crv<c- p>:</c-> P<c- mi>-256</c-> curve
<c- mi>-2</c-><c- p>:</c-> x<c- p>,</c-> ; x<c- mi>-</c->coordi<c- kc>nate</c-> as by<c- kc>te</c-> s<c- kc>tr</c->i<c- kc>n</c->g <c- mi>32</c-> by<c- kc>tes</c-> i<c- kc>n</c-> le<c- kc>n</c->g<c- kc>t</c->h
; e.g.<c- p>,</c-> i<c- kc>n</c-> hex<c- p>:</c-> <c- mf>65e</c->da<c- mi>5</c->a<c- mi>12577</c->c<c- mi>2</c->bae<c- mi>829437</c-><c- kc>fe</c-><c- mi>338701</c->a<c- mi>10</c->aaa<c- mf>375e1</c->bb<c- mi>5</c->b<c- mi>5</c->de<c- mi>108</c->de<c- mi>439</c->c<c- mi>08551</c->d
<c- mi>-3</c-><c- p>:</c-> y ; y<c- mi>-</c->coordi<c- kc>nate</c-> as by<c- kc>te</c-> s<c- kc>tr</c->i<c- kc>n</c->g <c- mi>32</c-> by<c- kc>tes</c-> i<c- kc>n</c-> le<c- kc>n</c->g<c- kc>t</c->h
; e.g.<c- p>,</c-> i<c- kc>n</c-> hex<c- p>:</c-> <c- mf>1e52e</c->d<c- mi>75701163</c-><c- kc>f</c-><c- mi>7</c-><c- kc>f</c-><c- mf>9e40</c->dd<c- kc>f</c-><c- mi>9</c-><c- kc>f</c-><c- mi>341</c->b<c- mi>3</c->dc<c- mi>9</c->ba<c- mi>860</c->a<c- kc>f</c-><c- mf>7e0</c->ca<c- mi>7</c->ca<c- mf>7e9ee</c->cd<c- mi>0084</c->d<c- mi>19</c->c
<c- mi>1</c-><c- p>:</c-> <c- mi>2</c-><c- p>,</c-> <c- c1>; kty: EC2 key type</c->
<c- mi>3</c-><c- p>:</c-> <c- mi>-7</c-><c- p>,</c-> <c- c1>; alg: ES256 signature algorithm</c->
<c- mi>-1</c-><c- p>:</c-> <c- mi>1</c-><c- p>,</c-> <c- c1>; crv: P-256 curve</c->
<c- mi>-2</c-><c- p>:</c-> <c- nc>x</c-><c- p>,</c-> <c- c1>; x-coordinate as byte string 32 bytes in length</c->
<c- c1>; e.g., in hex: 65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c08551d</c->
<c- mi>-3</c-><c- p>:</c-> <c- nc>y</c-> <c- c1>; y-coordinate as byte string 32 bytes in length</c->
<c- c1>; e.g., in hex: 1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd0084d19c</c->
<c- p>}</c->
</pre>
<p>Below is the above Elliptic Curve public key encoded in the <a data-link-type="dfn" href="https://fidoalliance.org/specs/fido-v2.1-ps-20210615/fido-client-to-authenticator-protocol-v2.1-ps-errata-20220621.html#ctap2-canonical-cbor-encoding-form" id="ref-for-ctap2-canonical-cbor-encoding-form④">CTAP2 canonical CBOR encoding form</a>, whitespace and line breaks
are included here for clarity and to match the CDDL <a data-link-type="biblio" href="#biblio-rfc8610" title="Concise Data Definition Language (CDDL): A Notational Convention to Express Concise Binary Object Representation (CBOR) and JSON Data Structures">[RFC8610]</a> presentation above:</p>
<pre class="example highlight" id="example-08d0b440"><a class="self-link" href="#example-08d0b440"></a>A<c- mi>5</c->
<c- mi>01</c-> <c- mi>02</c->
<pre class="example" id="example-08d0b440"><a class="self-link" href="#example-08d0b440"></a>A5
01 02

<c- mi>03</c-> <c- mi>26</c->
03 26

<c- mi>20</c-> <c- mi>01</c->
20 01

<c- mi>21</c-> <c- mi>58</c-> <c- mi>20</c-> <c- mf>65e</c->da<c- mi>5</c->a<c- mi>12577</c->c<c- mi>2</c->bae<c- mi>829437</c-><c- kc>fe</c-><c- mi>338701</c->a<c- mi>10</c->aaa<c- mf>375e1</c->bb<c- mi>5</c->b<c- mi>5</c->de<c- mi>108</c->de<c- mi>439</c->c<c- mi>08551</c->d
21 58 20 65eda5a12577c2bae829437fe338701a10aaa375e1bb5b5de108de439c08551d

<c- mi>22</c-> <c- mi>58</c-> <c- mi>20</c-> <c- mf>1e52e</c->d<c- mi>75701163</c-><c- kc>f</c-><c- mi>7</c-><c- kc>f</c-><c- mf>9e40</c->dd<c- kc>f</c-><c- mi>9</c-><c- kc>f</c-><c- mi>341</c->b<c- mi>3</c->dc<c- mi>9</c->ba<c- mi>860</c->a<c- kc>f</c-><c- mf>7e0</c->ca<c- mi>7</c->ca<c- mf>7e9ee</c->cd<c- mi>0084</c->d<c- mi>19</c->c
22 58 20 1e52ed75701163f7f9e40ddf9f341b3dc9ba860af7e0ca7ca7e9eecd0084d19c
</pre>
<p>Below is an example of a COSE_Key-encoded 2048-bit RSA public key (see <a data-link-type="biblio" href="#biblio-rfc8230" title="Using RSA Algorithms with CBOR Object Signing and Encryption (COSE) Messages">[RFC8230]</a> <a data-link-type="dfn" href="https://tools.ietf.org/html/rfc8230#section-4" id="ref-for-section-4">Section 4</a>,
to be used with the PS256 signature algorithm
(RSASSA-PSS with SHA-256, see <a data-link-type="dfn" href="https://tools.ietf.org/html/rfc8230#section-2" id="ref-for-section-2①">Section 2</a> of <a data-link-type="biblio" href="#biblio-rfc8230" title="Using RSA Algorithms with CBOR Object Signing and Encryption (COSE) Messages">[RFC8230]</a>:</p>
<pre class="example highlight" id="example-fb934e19"><a class="self-link" href="#example-fb934e19"></a><c- p>{</c->
<c- mi>1</c-><c- p>:</c-> <c- mi>3</c-><c- p>,</c-> ; k<c- kc>t</c->y<c- p>:</c-> RSA key <c- kc>t</c->ype
<c- mi>3</c-><c- p>:</c-> <c- mi>-37</c-><c- p>,</c-> ; alg<c- p>:</c-> PS<c- mi>256</c->
<c- mi>-1</c-><c- p>:</c-> <c- kc>n</c-><c- p>,</c-> ; <c- kc>n</c-><c- p>:</c-> RSA modulus <c- kc>n</c-> by<c- kc>te</c-> s<c- kc>tr</c->i<c- kc>n</c->g <c- mi>256</c-> by<c- kc>tes</c-> i<c- kc>n</c-> le<c- kc>n</c->g<c- kc>t</c->h
; e.g.<c- p>,</c-> i<c- kc>n</c-> hex (middle by<c- kc>tes</c-> elided <c- kc>f</c->or brevi<c- kc>t</c->y)<c- p>:</c-> DB<c- mi>5</c->F<c- mf>651550...6</c->DC<c- mi>6548</c->ACC<c- mi>3</c->
<c- mi>-2</c-><c- p>:</c-> e ; e<c- p>:</c-> RSA public expo<c- kc>nent</c-> e by<c- kc>te</c-> s<c- kc>tr</c->i<c- kc>n</c->g <c- mi>3</c-> by<c- kc>tes</c-> i<c- kc>n</c-> le<c- kc>n</c->g<c- kc>t</c->h
; e.g.<c- p>,</c-> i<c- kc>n</c-> hex<c- p>:</c-> <c- mi>010001</c->
<c- mi>1</c-><c- p>:</c-> <c- mi>3</c-><c- p>,</c-> <c- c1>; kty: RSA key type</c->
<c- mi>3</c-><c- p>:</c-> <c- mi>-37</c-><c- p>,</c-> <c- c1>; alg: PS256</c->
<c- mi>-1</c-><c- p>:</c-> <c- nc>n</c-><c- p>,</c-> <c- c1>; n: RSA modulus n byte string 256 bytes in length</c->
<c- c1>; e.g., in hex (middle bytes elided for brevity): DB5F651550...6DC6548ACC3</c->
<c- mi>-2</c-><c- p>:</c-> <c- nc>e</c-> <c- c1>; e: RSA public exponent e byte string 3 bytes in length</c->
<c- c1>; e.g., in hex: 010001</c->
<c- p>}</c->
</pre>
<p>Below is an example of the same COSE_Key-encoded RSA public key as above,
to be used with the RS256 signature algorithm (RSASSA-PKCS1-v1_5 with SHA-256):</p>
<pre class="example highlight" id="example-8dfabc00"><a class="self-link" href="#example-8dfabc00"></a><c- p>{</c->
<c- mi>1</c-><c- p>:</c-> <c- mi>3</c-><c- p>,</c-> ; k<c- kc>t</c->y<c- p>:</c-> RSA key <c- kc>t</c->ype
<c- mi>3</c-><c- p>:</c-><c- mi>-257</c-><c- p>,</c-> ; alg<c- p>:</c-> RS<c- mi>256</c->
<c- mi>-1</c-><c- p>:</c-> <c- kc>n</c-><c- p>,</c-> ; <c- kc>n</c-><c- p>:</c-> RSA modulus <c- kc>n</c-> by<c- kc>te</c-> s<c- kc>tr</c->i<c- kc>n</c->g <c- mi>256</c-> by<c- kc>tes</c-> i<c- kc>n</c-> le<c- kc>n</c->g<c- kc>t</c->h
; e.g.<c- p>,</c-> i<c- kc>n</c-> hex (middle by<c- kc>tes</c-> elided <c- kc>f</c->or brevi<c- kc>t</c->y)<c- p>:</c-> DB<c- mi>5</c->F<c- mf>651550...6</c->DC<c- mi>6548</c->ACC<c- mi>3</c->
<c- mi>-2</c-><c- p>:</c-> e ; e<c- p>:</c-> RSA public expo<c- kc>nent</c-> e by<c- kc>te</c-> s<c- kc>tr</c->i<c- kc>n</c->g <c- mi>3</c-> by<c- kc>tes</c-> i<c- kc>n</c-> le<c- kc>n</c->g<c- kc>t</c->h
; e.g.<c- p>,</c-> i<c- kc>n</c-> hex<c- p>:</c-> <c- mi>010001</c->
<c- mi>1</c-><c- p>:</c-> <c- mi>3</c-><c- p>,</c-> <c- c1>; kty: RSA key type</c->
<c- mi>3</c-><c- p>:</c-><c- mi>-257</c-><c- p>,</c-> <c- c1>; alg: RS256</c->
<c- mi>-1</c-><c- p>:</c-> <c- nc>n</c-><c- p>,</c-> <c- c1>; n: RSA modulus n byte string 256 bytes in length</c->
<c- c1>; e.g., in hex (middle bytes elided for brevity): DB5F651550...6DC6548ACC3</c->
<c- mi>-2</c-><c- p>:</c-> <c- nc>e</c-> <c- c1>; e: RSA public exponent e byte string 3 bytes in length</c->
<c- c1>; e.g., in hex: 010001</c->
<c- p>}</c->
</pre>
<h4 class="heading settled" data-level="6.5.2" id="sctn-attestation-formats"><span class="secno">6.5.2. </span><span class="content">Attestation Statement Formats</span><a class="self-link" href="#sctn-attestation-formats"></a></h4>
Expand Down Expand Up @@ -7304,12 +7304,12 @@ <h3 class="heading settled" data-level="9.3" id="sctn-extension-request-paramete
7, value 21).</p>
<p>The following example defines that an extension with <a data-link-type="dfn" href="#extension-identifier" id="ref-for-extension-identifier①⑥">identifier</a> <code>webauthnExample_foobar</code> takes an unsigned integer as <a data-link-type="dfn" href="#authenticator-extension-input" id="ref-for-authenticator-extension-input①③">authenticator extension input</a>,
and returns an array of at least one byte string as <a data-link-type="dfn" href="#authenticator-extension-output" id="ref-for-authenticator-extension-output①③">authenticator extension output</a>:</p>
<pre class="example" id="example-c42718c0"><a class="self-link" href="#example-c42718c0"></a>$$extensionInput //= (
webauthnExample_foobar: uint
)
$$extensionOutput //= (
webauthnExample_foobar: [+ bytes]
)
<pre class="example highlight" id="example-c42718c0"><a class="self-link" href="#example-c42718c0"></a><c- nc>$$extensionInput</c-> <c- o>//=</c-> <c- p>(</c->
<c- s>webauthnExample_foobar</c-><c- p>:</c-> uint
<c- p>)</c->
<c- nc>$$extensionOutput</c-> <c- o>//=</c-> <c- p>(</c->
<c- s>webauthnExample_foobar</c-><c- p>:</c-> <c- p>[</c-><c- o>+</c-> bytes<c- p>]</c->
<c- p>)</c->
</pre>
<p class="note" role="note"><span class="marker">Note:</span> Extensions should aim to define authenticator arguments that are as small as possible. Some authenticators communicate
over low-bandwidth links such as Bluetooth Low-Energy or NFC.</p>
Expand Down

0 comments on commit b0258a1

Please sign in to comment.