[WebAuthn] Add authenticator attachment used during authentication to credential payload
https://bugs.webkit.org/show_bug.cgi?id=235621
rdar://86538235

Reviewed by Dean Jackson.

Source/WebCore:

This patch adds the authenticator attachment used to the credential response in get/create
webauthn calls as described in the merged PR to the spec: https://github.com/w3c/webauthn/pull/1668/files

Modified layout tests to check for authenticator attachment = (cross-platform/platform) where appropriate
and verified response in manual calls.

* Modules/webauthn/PublicKeyCredential.cpp:
(WebCore::PublicKeyCredential::authenticatorAttachment const):
* Modules/webauthn/PublicKeyCredential.h:
* Modules/webauthn/PublicKeyCredential.idl:

LayoutTests:

Modify webauthn layout tests to check for new authenticatorAttachment field.
* http/wpt/webauthn/public-key-credential-get-success-local.https.html:
* http/wpt/webauthn/resources/util.js:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@288622 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 1242b30..07da877 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
+2022-01-26  J Pascoe  <j_pascoe@apple.com>
+
+        [WebAuthn] Add authenticator attachment used during authentication to credential payload
+        https://bugs.webkit.org/show_bug.cgi?id=235621
+        rdar://86538235
+
+        Reviewed by Dean Jackson.
+
+        Modify webauthn layout tests to check for new authenticatorAttachment field.        
+        * http/wpt/webauthn/public-key-credential-get-success-local.https.html:
+        * http/wpt/webauthn/resources/util.js:
+
 2022-01-26  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Data detectors sometimes show up in the wrong place when resizing images with Live Text
diff --git a/LayoutTests/http/wpt/webauthn/public-key-credential-get-success-local.https.html b/LayoutTests/http/wpt/webauthn/public-key-credential-get-success-local.https.html
index cfe4115..e8cf256 100644
--- a/LayoutTests/http/wpt/webauthn/public-key-credential-get-success-local.https.html
+++ b/LayoutTests/http/wpt/webauthn/public-key-credential-get-success-local.https.html
@@ -16,6 +16,7 @@
         assert_equals(bytesToASCIIString(credential.response.clientDataJSON), '{"type":"webauthn.get","challenge":"MTIzNDU2","origin":"https://localhost:9443"}');
         assert_array_equals(new Uint8Array(credential.response.userHandle), Base64URL.parse(testUserhandleBase64));
         assert_not_own_property(credential.getClientExtensionResults(), "appid");
+        assert_equals(credential.authenticatorAttachment, 'platform');
 
         // Check authData
         const authData = decodeAuthData(new Uint8Array(credential.response.authenticatorData));
diff --git a/LayoutTests/http/wpt/webauthn/resources/util.js b/LayoutTests/http/wpt/webauthn/resources/util.js
index 802e195..e5aa84b 100644
--- a/LayoutTests/http/wpt/webauthn/resources/util.js
+++ b/LayoutTests/http/wpt/webauthn/resources/util.js
@@ -425,6 +425,7 @@
     // Check respond
     assert_array_equals(Base64URL.parse(credential.id), Base64URL.parse(testHidCredentialIdBase64));
     assert_equals(credential.type, 'public-key');
+    assert_equals(credential.authenticatorAttachment, 'cross-platform')
     assert_array_equals(new Uint8Array(credential.rawId), Base64URL.parse(testHidCredentialIdBase64));
     assert_equals(bytesToASCIIString(credential.response.clientDataJSON), '{"type":"webauthn.get","challenge":"MTIzNDU2","origin":"https://localhost:9443"}');
     if (userHandleBase64 == null)
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 4a22bcf..5c054ee 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,22 @@
+2022-01-26  J Pascoe  <j_pascoe@apple.com>
+
+        [WebAuthn] Add authenticator attachment used during authentication to credential payload
+        https://bugs.webkit.org/show_bug.cgi?id=235621
+        rdar://86538235
+
+        Reviewed by Dean Jackson.
+
+        This patch adds the authenticator attachment used to the credential response in get/create
+        webauthn calls as described in the merged PR to the spec: https://github.com/w3c/webauthn/pull/1668/files
+
+        Modified layout tests to check for authenticator attachment = (cross-platform/platform) where appropriate
+        and verified response in manual calls.
+
+        * Modules/webauthn/PublicKeyCredential.cpp:
+        (WebCore::PublicKeyCredential::authenticatorAttachment const):
+        * Modules/webauthn/PublicKeyCredential.h:
+        * Modules/webauthn/PublicKeyCredential.idl:
+
 2022-01-26  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Data detectors sometimes show up in the wrong place when resizing images with Live Text
diff --git a/Source/WebCore/Modules/webauthn/PublicKeyCredential.cpp b/Source/WebCore/Modules/webauthn/PublicKeyCredential.cpp
index 2e26bab..e06a988 100644
--- a/Source/WebCore/Modules/webauthn/PublicKeyCredential.cpp
+++ b/Source/WebCore/Modules/webauthn/PublicKeyCredential.cpp
@@ -53,6 +53,11 @@
     return m_response->extensions();
 }
 
+AuthenticatorAttachment PublicKeyCredential::authenticatorAttachment() const
+{
+    return m_response->attachment();
+}
+
 PublicKeyCredential::PublicKeyCredential(Ref<AuthenticatorResponse>&& response)
     : BasicCredential(base64URLEncodeToString(response->rawId()->data(), response->rawId()->byteLength()), Type::PublicKey, Discovery::Remote)
     , m_response(WTFMove(response))
diff --git a/Source/WebCore/Modules/webauthn/PublicKeyCredential.h b/Source/WebCore/Modules/webauthn/PublicKeyCredential.h
index bfc9273..095e6d1 100644
--- a/Source/WebCore/Modules/webauthn/PublicKeyCredential.h
+++ b/Source/WebCore/Modules/webauthn/PublicKeyCredential.h
@@ -33,6 +33,7 @@
 
 namespace WebCore {
 
+enum class AuthenticatorAttachment;
 class AuthenticatorResponse;
 class Document;
 
@@ -46,6 +47,7 @@
 
     ArrayBuffer* rawId() const;
     AuthenticatorResponse* response() const { return m_response.ptr(); }
+    AuthenticatorAttachment authenticatorAttachment() const;
     AuthenticationExtensionsClientOutputs getClientExtensionResults() const;
 
     static void isUserVerifyingPlatformAuthenticatorAvailable(Document&, DOMPromiseDeferred<IDLBoolean>&&);
diff --git a/Source/WebCore/Modules/webauthn/PublicKeyCredential.idl b/Source/WebCore/Modules/webauthn/PublicKeyCredential.idl
index 1550dfd..a8dba9f 100644
--- a/Source/WebCore/Modules/webauthn/PublicKeyCredential.idl
+++ b/Source/WebCore/Modules/webauthn/PublicKeyCredential.idl
@@ -31,6 +31,7 @@
 ] interface PublicKeyCredential : BasicCredential {
     [SameObject] readonly attribute ArrayBuffer rawId;
     [SameObject] readonly attribute AuthenticatorResponse response;
+    [SameObject] readonly attribute AuthenticatorAttachment? authenticatorAttachment;
     AuthenticationExtensionsClientOutputs getClientExtensionResults();
 
     [CallWith=Document] static Promise<boolean> isUserVerifyingPlatformAuthenticatorAvailable();