Title: [291176] trunk
Revision
291176
Author
[email protected]
Date
2022-03-11 09:49:14 -0800 (Fri, 11 Mar 2022)

Log Message

[WebAuthn] Support authenticatorSelection.residentKey ResidentKeyRequirement
https://bugs.webkit.org/show_bug.cgi?id=237567
rdar://89788378

Reviewed by Brent Fulgham and Chris Dumez.

Source/WebCore:

In Web Authentication level one, relying parties can specify authenticatorSelection.residentKeyRequired,
to signify they require a client-side discoverable credential. However, if the authenticator does not
support client-side discoverable credentials, the rp has no way to clarify they want a client-side
discoverable credential only if available.

This patch implements authenticatorSelection.residentKeyRequired introduced in level 2, which has three
values 'Preferred', 'Required', and 'Discouraged'. This allows RPs to create a client-side discoverable
credential if possible.

* CMakeLists.txt:
* DerivedSources-input.xcfilelist:
* DerivedSources-output.xcfilelist:
* DerivedSources.make:
* Modules/webauthn/PublicKeyCredentialCreationOptions.h:
(WebCore::PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria::encode const):
(WebCore::PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria::decode):
* Modules/webauthn/PublicKeyCredentialCreationOptions.idl:
* Modules/webauthn/ResidentKeyRequirement.h: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.mm.
* Modules/webauthn/ResidentKeyRequirement.idl: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.mm.
* Modules/webauthn/fido/AuthenticatorSupportedOptions.cpp:
(fido::AuthenticatorSupportedOptions::setResidentKeyAvailability):
(fido::convertToCBOR):
(fido::AuthenticatorSupportedOptions::setSupportsResidentKey): Deleted.
* Modules/webauthn/fido/AuthenticatorSupportedOptions.h:
* Modules/webauthn/fido/DeviceRequestConverter.cpp:
(fido::encodeMakeCredenitalRequestAsCBOR):
* Modules/webauthn/fido/DeviceRequestConverter.h:
* Modules/webauthn/fido/DeviceResponseConverter.cpp:
(fido::readCTAPGetInfoResponse):
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:

Source/WebKit:

In Web Authentication level one, relying parties can specify authenticatorSelection.residentKeyRequired,
to signify they require a client-side discoverable credential. However, if the authenticator does not
support client-side discoverable credentials, the rp has no way to clarify they want a client-side
discoverable credential only if available.

This patch implements authenticatorSelection.residentKeyRequired introduced in level 2, which has three
values 'Preferred', 'Required', and 'Discouraged'. This allows RPs to create a client-side discoverable
credential if possible.

* UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.h:
* UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.mm:
(-[_WKAuthenticatorSelectionCriteria init]):
* UIProcess/API/Cocoa/_WKResidentKeyRequirement.h: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.mm.
* UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm:
(residentKey):
(authenticatorSelectionCriteria):
(+[_WKWebAuthenticationPanel encodeMakeCredentialCommandWithClientDataJSON:options:userVerificationAvailability:]):
(+[_WKWebAuthenticationPanel encodeMakeCredentialCommandWithClientDataHash:options:userVerificationAvailability:]):
* UIProcess/WebAuthentication/fido/CtapAuthenticator.cpp:
(WebKit::CtapAuthenticator::makeCredential):
* WebKit.xcodeproj/project.pbxproj:

Tools:

Add API tests for authenticatorSelection.residentKey.

* TestWebKitAPI/Tests/WebCore/CtapRequestTest.cpp:
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebCore/CtapResponseTest.cpp:
(TestWebKitAPI::TEST):

LayoutTests:

Add layout tests using residentKey field.

* http/wpt/webauthn/public-key-credential-create-failure-hid.https-expected.txt:
* http/wpt/webauthn/public-key-credential-create-failure-hid.https.html:
* http/wpt/webauthn/public-key-credential-create-success-hid.https-expected.txt:
* http/wpt/webauthn/public-key-credential-create-success-hid.https.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (291175 => 291176)


--- trunk/LayoutTests/ChangeLog	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/LayoutTests/ChangeLog	2022-03-11 17:49:14 UTC (rev 291176)
@@ -1,3 +1,18 @@
+2022-03-11  J Pascoe  <[email protected]>
+
+        [WebAuthn] Support authenticatorSelection.residentKey ResidentKeyRequirement
+        https://bugs.webkit.org/show_bug.cgi?id=237567
+        rdar://89788378
+
+        Reviewed by Brent Fulgham and Chris Dumez.
+
+        Add layout tests using residentKey field.
+
+        * http/wpt/webauthn/public-key-credential-create-failure-hid.https-expected.txt:
+        * http/wpt/webauthn/public-key-credential-create-failure-hid.https.html:
+        * http/wpt/webauthn/public-key-credential-create-success-hid.https-expected.txt:
+        * http/wpt/webauthn/public-key-credential-create-success-hid.https.html:
+
 2022-03-11  Don Olmstead  <[email protected]>
 
         Platforms implementing WebSocketTask pass hybi/close-and-server-script-exception-expected.txt

Modified: trunk/LayoutTests/http/wpt/webauthn/public-key-credential-create-failure-hid.https-expected.txt (291175 => 291176)


--- trunk/LayoutTests/http/wpt/webauthn/public-key-credential-create-failure-hid.https-expected.txt	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/LayoutTests/http/wpt/webauthn/public-key-credential-create-failure-hid.https-expected.txt	2022-03-11 17:49:14 UTC (rev 291176)
@@ -3,10 +3,12 @@
 CONSOLE MESSAGE: User gesture is not detected. To use the WebAuthn API, call 'navigator.credentials.create' or 'navigator.credentials.get' within user activated events.
 CONSOLE MESSAGE: User gesture is not detected. To use the WebAuthn API, call 'navigator.credentials.create' or 'navigator.credentials.get' within user activated events.
 CONSOLE MESSAGE: User gesture is not detected. To use the WebAuthn API, call 'navigator.credentials.create' or 'navigator.credentials.get' within user activated events.
+CONSOLE MESSAGE: User gesture is not detected. To use the WebAuthn API, call 'navigator.credentials.create' or 'navigator.credentials.get' within user activated events.
 
 PASS PublicKeyCredential's [[create]] with timeout in a mock hid authenticator.
 PASS PublicKeyCredential's [[create]] with malicious payload in a mock hid authenticator.
 PASS PublicKeyCredential's [[create]] with unsupported options in a mock hid authenticator.
+PASS PublicKeyCredential's [[create]] with unsupported options in a mock hid authenticator. 2
 PASS PublicKeyCredential's [[create]] with mixed options in a mock hid authenticator.
 PASS PublicKeyCredential's [[create]] with mixed options in a mock hid authenticator. 2
 PASS PublicKeyCredential's [[create]] with InvalidStateError in a mock hid authenticator.

Modified: trunk/LayoutTests/http/wpt/webauthn/public-key-credential-create-failure-hid.https.html (291175 => 291176)


--- trunk/LayoutTests/http/wpt/webauthn/public-key-credential-create-failure-hid.https.html	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/LayoutTests/http/wpt/webauthn/public-key-credential-create-failure-hid.https.html	2022-03-11 17:49:14 UTC (rev 291176)
@@ -85,6 +85,28 @@
                 },
                 challenge: asciiToUint8Array("123456"),
                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
+                authenticatorSelection: { residentKey: "required" }
+            }
+        };
+
+        if (window.internals)
+            internals.setMockWebAuthenticationConfiguration({ hid: { stage: "request", subStage: "msg", error: "unsupported-options" } });
+        return promiseRejects(t, "UnknownError", navigator.credentials.create(options), "Unknown internal error. Error code: 43");
+    }, "PublicKeyCredential's [[create]] with unsupported options in a mock hid authenticator. 2");
+
+    promise_test(function(t) {
+        const options = {
+            publicKey: {
+                rp: {
+                    name: "example.com"
+                },
+                user: {
+                    name: "John Appleseed",
+                    id: asciiToUint8Array("123456"),
+                    displayName: "John",
+                },
+                challenge: asciiToUint8Array("123456"),
+                pubKeyCredParams: [{ type: "public-key", alg: -7 }],
                 timeout: 10,
                 authenticatorSelection: { authenticatorAttachment: "platform", requireResidentKey: true, userVerification: "required" }
             }

Modified: trunk/LayoutTests/http/wpt/webauthn/public-key-credential-create-success-hid.https-expected.txt (291175 => 291176)


--- trunk/LayoutTests/http/wpt/webauthn/public-key-credential-create-success-hid.https-expected.txt	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/LayoutTests/http/wpt/webauthn/public-key-credential-create-success-hid.https-expected.txt	2022-03-11 17:49:14 UTC (rev 291176)
@@ -11,11 +11,17 @@
 CONSOLE MESSAGE: User gesture is not detected. To use the WebAuthn API, call 'navigator.credentials.create' or 'navigator.credentials.get' within user activated events.
 CONSOLE MESSAGE: User gesture is not detected. To use the WebAuthn API, call 'navigator.credentials.create' or 'navigator.credentials.get' within user activated events.
 CONSOLE MESSAGE: User gesture is not detected. To use the WebAuthn API, call 'navigator.credentials.create' or 'navigator.credentials.get' within user activated events.
+CONSOLE MESSAGE: User gesture is not detected. To use the WebAuthn API, call 'navigator.credentials.create' or 'navigator.credentials.get' within user activated events.
+CONSOLE MESSAGE: User gesture is not detected. To use the WebAuthn API, call 'navigator.credentials.create' or 'navigator.credentials.get' within user activated events.
+CONSOLE MESSAGE: User gesture is not detected. To use the WebAuthn API, call 'navigator.credentials.create' or 'navigator.credentials.get' within user activated events.
 
 PASS PublicKeyCredential's [[create]] with minimum options in a mock hid authenticator.
 PASS PublicKeyCredential's [[create]] with empty pubKeyCredParams in a mock hid authenticator.
 PASS PublicKeyCredential's [[create]] with authenticatorSelection { 'cross-platform' } in a mock hid authenticator.
 PASS PublicKeyCredential's [[create]] with requireResidentKey { false } in a mock hid authenticator.
+PASS PublicKeyCredential's [[create]] with residentKey { Discouraged } in a mock hid authenticator.
+PASS PublicKeyCredential's [[create]] with residentKey { Preferred } in a mock hid authenticator.
+PASS PublicKeyCredential's [[create]] with residentKey { Required } in a mock hid authenticator.
 PASS PublicKeyCredential's [[create]] with userVerification { 'preferred' } in a mock hid authenticator.
 PASS PublicKeyCredential's [[create]] with userVerification { 'discouraged' } in a mock hid authenticator.
 PASS PublicKeyCredential's [[create]] with mixed options in a mock hid authenticator.

Modified: trunk/LayoutTests/http/wpt/webauthn/public-key-credential-create-success-hid.https.html (291175 => 291176)


--- trunk/LayoutTests/http/wpt/webauthn/public-key-credential-create-success-hid.https.html	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/LayoutTests/http/wpt/webauthn/public-key-credential-create-success-hid.https.html	2022-03-11 17:49:14 UTC (rev 291176)
@@ -112,6 +112,75 @@
                 },
                 challenge: Base64URL.parse("MTIzNDU2"),
                 pubKeyCredParams: [{ type: "public-key", alg: -7 }],
+                authenticatorSelection: { residentKey: "discouraged" },
+                timeout: 100
+            }
+        };
+
+        return navigator.credentials.create(options).then(credential => {
+            checkCtapMakeCredentialResult(credential);
+        });
+    }, "PublicKeyCredential's [[create]] with residentKey { Discouraged } in a mock hid authenticator.");
+
+    promise_test(t => {
+        const options = {
+            publicKey: {
+                rp: {
+                    name: "localhost",
+                },
+                user: {
+                    name: "John Appleseed",
+                    id: Base64URL.parse(testUserhandleBase64),
+                    displayName: "Appleseed",
+                },
+                challenge: Base64URL.parse("MTIzNDU2"),
+                pubKeyCredParams: [{ type: "public-key", alg: -7 }],
+                authenticatorSelection: { residentKey: "preferred" },
+                timeout: 100
+            }
+        };
+
+        return navigator.credentials.create(options).then(credential => {
+            checkCtapMakeCredentialResult(credential);
+        });
+    }, "PublicKeyCredential's [[create]] with residentKey { Preferred } in a mock hid authenticator.");
+
+    promise_test(t => {
+        const options = {
+            publicKey: {
+                rp: {
+                    name: "localhost",
+                },
+                user: {
+                    name: "John Appleseed",
+                    id: Base64URL.parse(testUserhandleBase64),
+                    displayName: "Appleseed",
+                },
+                challenge: Base64URL.parse("MTIzNDU2"),
+                pubKeyCredParams: [{ type: "public-key", alg: -7 }],
+                authenticatorSelection: { residentKey: "required" },
+                timeout: 100
+            }
+        };
+
+        return navigator.credentials.create(options).then(credential => {
+            checkCtapMakeCredentialResult(credential);
+        });
+    }, "PublicKeyCredential's [[create]] with residentKey { Required } in a mock hid authenticator.");
+
+    promise_test(t => {
+        const options = {
+            publicKey: {
+                rp: {
+                    name: "localhost",
+                },
+                user: {
+                    name: "John Appleseed",
+                    id: Base64URL.parse(testUserhandleBase64),
+                    displayName: "Appleseed",
+                },
+                challenge: Base64URL.parse("MTIzNDU2"),
+                pubKeyCredParams: [{ type: "public-key", alg: -7 }],
                 authenticatorSelection: { userVerification: "preferred" },
                 timeout: 100
             }

Modified: trunk/Source/WebCore/CMakeLists.txt (291175 => 291176)


--- trunk/Source/WebCore/CMakeLists.txt	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebCore/CMakeLists.txt	2022-03-11 17:49:14 UTC (rev 291176)
@@ -665,6 +665,7 @@
     Modules/webauthn/PublicKeyCredentialDescriptor.idl
     Modules/webauthn/PublicKeyCredentialRequestOptions.idl
     Modules/webauthn/PublicKeyCredentialType.idl
+    Modules/webauthn/ResidentKeyRequirement.idl
     Modules/webauthn/UserVerificationRequirement.idl
 
     Modules/webcodecs/VideoColorPrimaries.idl

Modified: trunk/Source/WebCore/ChangeLog (291175 => 291176)


--- trunk/Source/WebCore/ChangeLog	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebCore/ChangeLog	2022-03-11 17:49:14 UTC (rev 291176)
@@ -1,3 +1,43 @@
+2022-03-11  J Pascoe  <[email protected]>
+
+        [WebAuthn] Support authenticatorSelection.residentKey ResidentKeyRequirement
+        https://bugs.webkit.org/show_bug.cgi?id=237567
+        rdar://89788378
+
+        Reviewed by Brent Fulgham and Chris Dumez.
+
+        In Web Authentication level one, relying parties can specify authenticatorSelection.residentKeyRequired,
+        to signify they require a client-side discoverable credential. However, if the authenticator does not
+        support client-side discoverable credentials, the rp has no way to clarify they want a client-side
+        discoverable credential only if available.
+
+        This patch implements authenticatorSelection.residentKeyRequired introduced in level 2, which has three
+        values 'Preferred', 'Required', and 'Discouraged'. This allows RPs to create a client-side discoverable
+        credential if possible.
+
+        * CMakeLists.txt:
+        * DerivedSources-input.xcfilelist:
+        * DerivedSources-output.xcfilelist:
+        * DerivedSources.make:
+        * Modules/webauthn/PublicKeyCredentialCreationOptions.h:
+        (WebCore::PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria::encode const):
+        (WebCore::PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria::decode):
+        * Modules/webauthn/PublicKeyCredentialCreationOptions.idl:
+        * Modules/webauthn/ResidentKeyRequirement.h: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.mm.
+        * Modules/webauthn/ResidentKeyRequirement.idl: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.mm.
+        * Modules/webauthn/fido/AuthenticatorSupportedOptions.cpp:
+        (fido::AuthenticatorSupportedOptions::setResidentKeyAvailability):
+        (fido::convertToCBOR):
+        (fido::AuthenticatorSupportedOptions::setSupportsResidentKey): Deleted.
+        * Modules/webauthn/fido/AuthenticatorSupportedOptions.h:
+        * Modules/webauthn/fido/DeviceRequestConverter.cpp:
+        (fido::encodeMakeCredenitalRequestAsCBOR):
+        * Modules/webauthn/fido/DeviceRequestConverter.h:
+        * Modules/webauthn/fido/DeviceResponseConverter.cpp:
+        (fido::readCTAPGetInfoResponse):
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+
 2022-03-11  Ben Nham  <[email protected]>
 
         Fix WebContent jetsam that occurs when selecting text in a large e-mail

Modified: trunk/Source/WebCore/DerivedSources-input.xcfilelist (291175 => 291176)


--- trunk/Source/WebCore/DerivedSources-input.xcfilelist	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebCore/DerivedSources-input.xcfilelist	2022-03-11 17:49:14 UTC (rev 291176)
@@ -751,6 +751,7 @@
 $(PROJECT_DIR)/Modules/webauthn/PublicKeyCredentialDescriptor.idl
 $(PROJECT_DIR)/Modules/webauthn/PublicKeyCredentialRequestOptions.idl
 $(PROJECT_DIR)/Modules/webauthn/PublicKeyCredentialType.idl
+$(PROJECT_DIR)/Modules/webauthn/ResidentKeyRequirement.idl
 $(PROJECT_DIR)/Modules/webauthn/UserVerificationRequirement.idl
 $(PROJECT_DIR)/Modules/webcodecs/VideoColorPrimaries.idl
 $(PROJECT_DIR)/Modules/webcodecs/VideoColorSpace.idl

Modified: trunk/Source/WebCore/DerivedSources-output.xcfilelist (291175 => 291176)


--- trunk/Source/WebCore/DerivedSources-output.xcfilelist	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebCore/DerivedSources-output.xcfilelist	2022-03-11 17:49:14 UTC (rev 291176)
@@ -2115,6 +2115,8 @@
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRequestAnimationFrameCallback.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRequestCookieConsentOptions.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSRequestCookieConsentOptions.h
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSResidentKeyRequirement.cpp
+$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSResidentKeyRequirement.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSResizeObserver.cpp
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSResizeObserver.h
 $(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSResizeObserverBoxOptions.cpp

Modified: trunk/Source/WebCore/DerivedSources.make (291175 => 291176)


--- trunk/Source/WebCore/DerivedSources.make	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebCore/DerivedSources.make	2022-03-11 17:49:14 UTC (rev 291176)
@@ -647,6 +647,7 @@
     $(WebCore)/Modules/webauthn/PublicKeyCredentialDescriptor.idl \
     $(WebCore)/Modules/webauthn/PublicKeyCredentialRequestOptions.idl \
     $(WebCore)/Modules/webauthn/PublicKeyCredentialType.idl \
+    $(WebCore)/Modules/webauthn/ResidentKeyRequirement.idl \
     $(WebCore)/Modules/webauthn/UserVerificationRequirement.idl \
 	$(WebCore)/Modules/webcodecs/VideoColorPrimaries.idl \
 	$(WebCore)/Modules/webcodecs/VideoColorSpace.idl \

Modified: trunk/Source/WebCore/Modules/webauthn/PublicKeyCredentialCreationOptions.h (291175 => 291176)


--- trunk/Source/WebCore/Modules/webauthn/PublicKeyCredentialCreationOptions.h	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebCore/Modules/webauthn/PublicKeyCredentialCreationOptions.h	2022-03-11 17:49:14 UTC (rev 291176)
@@ -31,6 +31,7 @@
 #include "BufferSource.h"
 #include "PublicKeyCredentialDescriptor.h"
 #include "PublicKeyCredentialType.h"
+#include "ResidentKeyRequirement.h"
 #include "UserVerificationRequirement.h"
 #include <wtf/Forward.h>
 #endif // ENABLE(WEB_AUTHN)
@@ -65,6 +66,8 @@
 
     struct AuthenticatorSelectionCriteria {
         std::optional<AuthenticatorAttachment> authenticatorAttachment;
+        // residentKey replaces requireResidentKey, see: https://www.w3.org/TR/webauthn-2/#dictionary-authenticatorSelection
+        std::optional<ResidentKeyRequirement> residentKey;
         bool requireResidentKey { false };
         UserVerificationRequirement userVerification { UserVerificationRequirement::Preferred };
 
@@ -110,7 +113,7 @@
 template<class Encoder>
 void PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria::encode(Encoder& encoder) const
 {
-    encoder << authenticatorAttachment << requireResidentKey << userVerification;
+    encoder << authenticatorAttachment << requireResidentKey << userVerification << residentKey;
 }
 
 template<class Decoder>
@@ -132,6 +135,13 @@
 
     if (!decoder.decode(result.userVerification))
         return std::nullopt;
+
+    std::optional<std::optional<ResidentKeyRequirement>> residentKey;
+    decoder >> residentKey;
+    if (!residentKey)
+        return std::nullopt;
+    result.residentKey = *residentKey;
+
     return result;
 }
 

Modified: trunk/Source/WebCore/Modules/webauthn/PublicKeyCredentialCreationOptions.idl (291175 => 291176)


--- trunk/Source/WebCore/Modules/webauthn/PublicKeyCredentialCreationOptions.idl	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebCore/Modules/webauthn/PublicKeyCredentialCreationOptions.idl	2022-03-11 17:49:14 UTC (rev 291176)
@@ -72,6 +72,7 @@
     Conditional=WEB_AUTHN,
 ] dictionary AuthenticatorSelectionCriteria {
     AuthenticatorAttachment      authenticatorAttachment;
+    ResidentKeyRequirement       residentKey;
     boolean                      requireResidentKey = false;
     UserVerificationRequirement  userVerification = "preferred";
 };

Copied: trunk/Source/WebCore/Modules/webauthn/ResidentKeyRequirement.h (from rev 291175, trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.mm) (0 => 291176)


--- trunk/Source/WebCore/Modules/webauthn/ResidentKeyRequirement.h	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webauthn/ResidentKeyRequirement.h	2022-03-11 17:49:14 UTC (rev 291176)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEB_AUTHN)
+
+#include <wtf/EnumTraits.h>
+
+namespace WebCore {
+
+enum class ResidentKeyRequirement : uint8_t {
+    Required,
+    Preferred,
+    Discouraged
+};
+
+} // namespace WebCore
+
+namespace WTF {
+
+template<> struct EnumTraits<WebCore::ResidentKeyRequirement> {
+    using values = EnumValues<
+        WebCore::ResidentKeyRequirement,
+        WebCore::ResidentKeyRequirement::Required,
+        WebCore::ResidentKeyRequirement::Preferred,
+        WebCore::ResidentKeyRequirement::Discouraged
+    >;
+};
+
+} // namespace WTF
+
+#endif // ENABLE(WEB_AUTHN)

Copied: trunk/Source/WebCore/Modules/webauthn/ResidentKeyRequirement.idl (from rev 291175, trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.mm) (0 => 291176)


--- trunk/Source/WebCore/Modules/webauthn/ResidentKeyRequirement.idl	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webauthn/ResidentKeyRequirement.idl	2022-03-11 17:49:14 UTC (rev 291176)
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+[
+    Conditional=WEB_AUTHN,
+    ImplementedAs=ResidentKeyRequirement
+] enum ResidentKeyRequirement {
+    "required",
+    "preferred",
+    "discouraged"
+};

Modified: trunk/Source/WebCore/Modules/webauthn/fido/AuthenticatorSupportedOptions.cpp (291175 => 291176)


--- trunk/Source/WebCore/Modules/webauthn/fido/AuthenticatorSupportedOptions.cpp	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebCore/Modules/webauthn/fido/AuthenticatorSupportedOptions.cpp	2022-03-11 17:49:14 UTC (rev 291176)
@@ -36,9 +36,9 @@
 
 namespace fido {
 
-AuthenticatorSupportedOptions& AuthenticatorSupportedOptions::setSupportsResidentKey(bool supportsResidentKey)
+AuthenticatorSupportedOptions& AuthenticatorSupportedOptions::setResidentKeyAvailability(ResidentKeyAvailability residentKeyAvailability)
 {
-    m_supportsResidentKey = supportsResidentKey;
+    m_residentKeyAvailability = residentKeyAvailability;
     return *this;
 }
 
@@ -71,7 +71,7 @@
     using namespace cbor;
 
     CBORValue::MapValue optionMap;
-    optionMap.emplace(CBORValue(kResidentKeyMapKey), CBORValue(options.supportsResidentKey()));
+    optionMap.emplace(CBORValue(kResidentKeyMapKey), CBORValue(options.residentKeyAvailability() == AuthenticatorSupportedOptions::ResidentKeyAvailability::kSupported));
     optionMap.emplace(CBORValue(kUserPresenceMapKey), CBORValue(options.userPresenceRequired()));
     optionMap.emplace(CBORValue(kPlatformDeviceMapKey), CBORValue(options.isPlatformDevice()));
 

Modified: trunk/Source/WebCore/Modules/webauthn/fido/AuthenticatorSupportedOptions.h (291175 => 291176)


--- trunk/Source/WebCore/Modules/webauthn/fido/AuthenticatorSupportedOptions.h	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebCore/Modules/webauthn/fido/AuthenticatorSupportedOptions.h	2022-03-11 17:49:14 UTC (rev 291176)
@@ -51,6 +51,11 @@
         kNotSupported
     };
 
+    enum class ResidentKeyAvailability : bool {
+        kSupported,
+        kNotSupported
+    };
+
     enum class ClientPinAvailability {
         kSupportedAndPinSet,
         kSupportedButPinNotSet,
@@ -62,14 +67,14 @@
     AuthenticatorSupportedOptions& operator=(AuthenticatorSupportedOptions&&) = default;
 
     AuthenticatorSupportedOptions& setIsPlatformDevice(bool);
-    AuthenticatorSupportedOptions& setSupportsResidentKey(bool);
+    AuthenticatorSupportedOptions& setResidentKeyAvailability(ResidentKeyAvailability);
     AuthenticatorSupportedOptions& setUserVerificationAvailability(UserVerificationAvailability);
     AuthenticatorSupportedOptions& setUserPresenceRequired(bool);
     AuthenticatorSupportedOptions& setClientPinAvailability(ClientPinAvailability);
 
     bool isPlatformDevice() const { return m_isPlatformDevice; }
-    bool supportsResidentKey() const { return m_supportsResidentKey; }
-    UserVerificationAvailability userVerificationAvailability() const { return m_userVerificationAvailability; }
+    ResidentKeyAvailability residentKeyAvailability() const { return m_residentKeyAvailability; };
+    UserVerificationAvailability userVerificationAvailability() const { return m_userVerificationAvailability; };
     bool userPresenceRequired() const { return m_userPresenceRequired; }
     ClientPinAvailability clientPinAvailability() const { return m_clientPinAvailability; }
 
@@ -80,7 +85,7 @@
     // Indicates that the device is capable of storing keys on the device itself
     // and therefore can satisfy the authenticatorGetAssertion request with
     // allowList parameter not specified or empty.
-    bool m_supportsResidentKey { false };
+    ResidentKeyAvailability m_residentKeyAvailability { ResidentKeyAvailability::kNotSupported };
     // Indicates whether the device is capable of verifying the user on its own.
     UserVerificationAvailability m_userVerificationAvailability { UserVerificationAvailability::kNotSupported };
     bool m_userPresenceRequired { true };

Modified: trunk/Source/WebCore/Modules/webauthn/fido/DeviceRequestConverter.cpp (291175 => 291176)


--- trunk/Source/WebCore/Modules/webauthn/fido/DeviceRequestConverter.cpp	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebCore/Modules/webauthn/fido/DeviceRequestConverter.cpp	2022-03-11 17:49:14 UTC (rev 291176)
@@ -35,6 +35,7 @@
 #include "CBORWriter.h"
 #include "PublicKeyCredentialCreationOptions.h"
 #include "PublicKeyCredentialRequestOptions.h"
+#include "ResidentKeyRequirement.h"
 #include <wtf/Vector.h>
 
 namespace fido {
@@ -85,7 +86,7 @@
     return CBORValue(WTFMove(cborDescriptorMap));
 }
 
-Vector<uint8_t> encodeMakeCredenitalRequestAsCBOR(const Vector<uint8_t>& hash, const PublicKeyCredentialCreationOptions& options, UVAvailability uvCapability, std::optional<PinParameters> pin)
+Vector<uint8_t> encodeMakeCredenitalRequestAsCBOR(const Vector<uint8_t>& hash, const PublicKeyCredentialCreationOptions& options, UVAvailability uvCapability, AuthenticatorSupportedOptions::ResidentKeyAvailability residentKeyAvailability, std::optional<PinParameters> pin)
 {
     CBORValue::MapValue cborMap;
     cborMap[CBORValue(1)] = CBORValue(hash);
@@ -102,7 +103,11 @@
     CBORValue::MapValue optionMap;
     if (options.authenticatorSelection) {
         // Resident keys are not supported by default.
-        if (options.authenticatorSelection->requireResidentKey)
+        if (options.authenticatorSelection->residentKey) {
+            if (*options.authenticatorSelection->residentKey == ResidentKeyRequirement::Required
+                || (*options.authenticatorSelection->residentKey == ResidentKeyRequirement::Preferred && residentKeyAvailability == AuthenticatorSupportedOptions::ResidentKeyAvailability::kSupported))
+                optionMap[CBORValue(kResidentKeyMapKey)] = CBORValue(true);
+        } else if (options.authenticatorSelection->requireResidentKey)
             optionMap[CBORValue(kResidentKeyMapKey)] = CBORValue(true);
 
         // User verification is not required by default.

Modified: trunk/Source/WebCore/Modules/webauthn/fido/DeviceRequestConverter.h (291175 => 291176)


--- trunk/Source/WebCore/Modules/webauthn/fido/DeviceRequestConverter.h	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebCore/Modules/webauthn/fido/DeviceRequestConverter.h	2022-03-11 17:49:14 UTC (rev 291176)
@@ -50,7 +50,7 @@
 // Serializes MakeCredential request parameter into CBOR encoded map with
 // integer keys and CBOR encoded values as defined by the CTAP spec.
 // https://fidoalliance.org/specs/fido-v2.0-ps-20170927/fido-client-to-authenticator-protocol-v2.0-ps-20170927.html#authenticatorMakeCredential
-WEBCORE_EXPORT Vector<uint8_t> encodeMakeCredenitalRequestAsCBOR(const Vector<uint8_t>& hash, const WebCore::PublicKeyCredentialCreationOptions&, AuthenticatorSupportedOptions::UserVerificationAvailability, std::optional<PinParameters> = std::nullopt);
+WEBCORE_EXPORT Vector<uint8_t> encodeMakeCredenitalRequestAsCBOR(const Vector<uint8_t>& hash, const WebCore::PublicKeyCredentialCreationOptions&, AuthenticatorSupportedOptions::UserVerificationAvailability, AuthenticatorSupportedOptions::ResidentKeyAvailability, std::optional<PinParameters> = std::nullopt);
 
 // Serializes GetAssertion request parameter into CBOR encoded map with
 // integer keys and CBOR encoded values as defined by the CTAP spec.

Modified: trunk/Source/WebCore/Modules/webauthn/fido/DeviceResponseConverter.cpp (291175 => 291176)


--- trunk/Source/WebCore/Modules/webauthn/fido/DeviceResponseConverter.cpp	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebCore/Modules/webauthn/fido/DeviceResponseConverter.cpp	2022-03-11 17:49:14 UTC (rev 291176)
@@ -264,8 +264,10 @@
         if (optionMapIt != optionMap.end()) {
             if (!optionMapIt->second.isBool())
                 return std::nullopt;
-
-            options.setSupportsResidentKey(optionMapIt->second.getBool());
+            if (optionMapIt->second.getBool())
+                options.setResidentKeyAvailability(AuthenticatorSupportedOptions::ResidentKeyAvailability::kSupported);
+            else
+                options.setResidentKeyAvailability(AuthenticatorSupportedOptions::ResidentKeyAvailability::kNotSupported);
         }
 
         optionMapIt = optionMap.find(CBOR(kUserPresenceMapKey));

Modified: trunk/Source/WebCore/Sources.txt (291175 => 291176)


--- trunk/Source/WebCore/Sources.txt	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebCore/Sources.txt	2022-03-11 17:49:14 UTC (rev 291176)
@@ -3701,6 +3701,7 @@
 JSRemotePlaybackAvailabilityCallback.cpp
 JSRequestAnimationFrameCallback.cpp
 JSRequestCookieConsentOptions.cpp
+JSResidentKeyRequirement.cpp
 JSResizeObserver.cpp
 JSResizeObserverBoxOptions.cpp
 JSResizeObserverCallback.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (291175 => 291176)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2022-03-11 17:49:14 UTC (rev 291176)
@@ -1729,6 +1729,7 @@
 		51FA2EDF27506FDE0011C15D /* SharedBufferChunkReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 51FA2ED6274F78370011C15D /* SharedBufferChunkReader.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		51FB5504113E3E9100821176 /* JSCloseEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 51FB5502113E3E9100821176 /* JSCloseEvent.h */; };
 		51FB67DC1AE6B82F00D06C5A /* ContentExtensionStyleSheet.h in Headers */ = {isa = PBXBuildFile; fileRef = 51FB67DA1AE6B5E400D06C5A /* ContentExtensionStyleSheet.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		52688AA627D6A7DA003577A2 /* ResidentKeyRequirement.h in Headers */ = {isa = PBXBuildFile; fileRef = 52688AA327D6A7DA003577A2 /* ResidentKeyRequirement.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		5273CC77256103CF00850007 /* PlatformXRCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 5273CC75256103CF00850007 /* PlatformXRCocoa.h */; };
 		5273CC8E25637EB500850007 /* WebXRTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18D83E0243F71CE009247D6 /* WebXRTest.cpp */; };
 		5273CC9025637F6700850007 /* WebFakeXRDevice.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18D83E9243F71D3009247D6 /* WebFakeXRDevice.cpp */; };
@@ -10066,6 +10067,8 @@
 		52131E5A1C4F15610033F802 /* VideoFullscreenInterfaceMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = VideoFullscreenInterfaceMac.mm; sourceTree = "<group>"; };
 		526724F11CB2FDF60075974D /* TextTrackRepresentationCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TextTrackRepresentationCocoa.mm; sourceTree = "<group>"; };
 		526724F21CB2FDF60075974D /* TextTrackRepresentationCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextTrackRepresentationCocoa.h; sourceTree = "<group>"; };
+		52688AA327D6A7DA003577A2 /* ResidentKeyRequirement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ResidentKeyRequirement.h; sourceTree = "<group>"; };
+		52688AA527D6A7DA003577A2 /* ResidentKeyRequirement.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = ResidentKeyRequirement.idl; sourceTree = "<group>"; };
 		5273CC74256103CF00850007 /* PlatformXRCocoa.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformXRCocoa.mm; sourceTree = "<group>"; };
 		5273CC75256103CF00850007 /* PlatformXRCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PlatformXRCocoa.h; sourceTree = "<group>"; };
 		5273CC9A2563B21200850007 /* JSWebXRTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebXRTest.cpp; sourceTree = "<group>"; };
@@ -23314,6 +23317,8 @@
 				57303C08200998F800355965 /* PublicKeyCredentialRequestOptions.idl */,
 				57303BEA20097F4000355965 /* PublicKeyCredentialType.h */,
 				57303BF02009846100355965 /* PublicKeyCredentialType.idl */,
+				52688AA327D6A7DA003577A2 /* ResidentKeyRequirement.h */,
+				52688AA527D6A7DA003577A2 /* ResidentKeyRequirement.idl */,
 				572B402321768D85000AD43E /* UserVerificationRequirement.h */,
 				572B402521768D85000AD43E /* UserVerificationRequirement.idl */,
 				574F55DC204F3732002948C6 /* WebAuthenticationConstants.h */,
@@ -37062,6 +37067,7 @@
 				4998AEC613F9D0EA0090B1AA /* RequestAnimationFrameCallback.h in Headers */,
 				F4034FAC275EAD6E003A81F8 /* RequestCookieConsentOptions.h in Headers */,
 				F55B3DD01251F12D003EF269 /* ResetInputType.h in Headers */,
+				52688AA627D6A7DA003577A2 /* ResidentKeyRequirement.h in Headers */,
 				58B2F9F42232D45300938D63 /* ResizeObservation.h in Headers */,
 				58B2F9F52232D45800938D63 /* ResizeObserver.h in Headers */,
 				0FD6A68C26EEC37F007B2231 /* ResizeObserverBoxOptions.h in Headers */,

Modified: trunk/Source/WebKit/ChangeLog (291175 => 291176)


--- trunk/Source/WebKit/ChangeLog	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebKit/ChangeLog	2022-03-11 17:49:14 UTC (rev 291176)
@@ -1,3 +1,33 @@
+2022-03-11  J Pascoe  <[email protected]>
+
+        [WebAuthn] Support authenticatorSelection.residentKey ResidentKeyRequirement
+        https://bugs.webkit.org/show_bug.cgi?id=237567
+        rdar://89788378
+
+        Reviewed by Brent Fulgham and Chris Dumez.
+
+        In Web Authentication level one, relying parties can specify authenticatorSelection.residentKeyRequired,
+        to signify they require a client-side discoverable credential. However, if the authenticator does not
+        support client-side discoverable credentials, the rp has no way to clarify they want a client-side
+        discoverable credential only if available.
+
+        This patch implements authenticatorSelection.residentKeyRequired introduced in level 2, which has three
+        values 'Preferred', 'Required', and 'Discouraged'. This allows RPs to create a client-side discoverable
+        credential if possible.
+
+        * UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.h:
+        * UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.mm:
+        (-[_WKAuthenticatorSelectionCriteria init]):
+        * UIProcess/API/Cocoa/_WKResidentKeyRequirement.h: Copied from Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.mm.
+        * UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm:
+        (residentKey):
+        (authenticatorSelectionCriteria):
+        (+[_WKWebAuthenticationPanel encodeMakeCredentialCommandWithClientDataJSON:options:userVerificationAvailability:]):
+        (+[_WKWebAuthenticationPanel encodeMakeCredentialCommandWithClientDataHash:options:userVerificationAvailability:]):
+        * UIProcess/WebAuthentication/fido/CtapAuthenticator.cpp:
+        (WebKit::CtapAuthenticator::makeCredential):
+        * WebKit.xcodeproj/project.pbxproj:
+
 2022-03-11  Fujii Hironori  <[email protected]>
 
         [WinCairo] DrawingAreaWC::sendUpdateAC should keep a WeakPtr of this for the reply handler

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.h (291175 => 291176)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.h	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.h	2022-03-11 17:49:14 UTC (rev 291176)
@@ -29,6 +29,8 @@
 
 #import <Foundation/Foundation.h>
 #import <WebKit/_WKAuthenticatorAttachment.h>
+#import <WebKit/_WKResidentKeyRequirement.h>
+
 #import <WebKit/_WKUserVerificationRequirement.h>
 
 NS_ASSUME_NONNULL_BEGIN
@@ -39,6 +41,9 @@
 /*!@discussion The default value is _WKAuthenticatorAttachmentAll.*/
 @property (nonatomic) _WKAuthenticatorAttachment authenticatorAttachment;
 
+/* (@discussion The default value is _WKResidentKeyRequirementNotPresent */
+@property (nonatomic) _WKResidentKeyRequirement residentKey WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 /*!@discussion The default value is NO.*/
 @property (nonatomic) BOOL requireResidentKey;
 

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.mm (291175 => 291176)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.mm	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.mm	2022-03-11 17:49:14 UTC (rev 291176)
@@ -34,6 +34,7 @@
         return nil;
 
     self.authenticatorAttachment = _WKAuthenticatorAttachmentAll;
+    self.residentKey = _WKResidentKeyRequirementNotPresent;
     self.requireResidentKey = NO;
     self.userVerification = _WKUserVerificationRequirementPreferred;
     return self;

Copied: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKResidentKeyRequirement.h (from rev 291175, trunk/Source/WebKit/UIProcess/API/Cocoa/_WKAuthenticatorSelectionCriteria.mm) (0 => 291176)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKResidentKeyRequirement.h	                        (rev 0)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKResidentKeyRequirement.h	2022-03-11 17:49:14 UTC (rev 291176)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#import <WebKit/WKFoundation.h>
+
+typedef NS_ENUM(NSInteger, _WKResidentKeyRequirement) {
+    _WKResidentKeyRequirementNotPresent,
+    _WKResidentKeyRequirementRequired,
+    _WKResidentKeyRequirementPreferred,
+    _WKResidentKeyRequirementDiscouraged,
+} WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm (291175 => 291176)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm	2022-03-11 17:49:14 UTC (rev 291176)
@@ -735,10 +735,28 @@
     }
 }
 
+static std::optional<WebCore::ResidentKeyRequirement> toWebCore(_WKResidentKeyRequirement uv)
+{
+    switch (uv) {
+    case _WKResidentKeyRequirementNotPresent:
+        return std::nullopt;
+    case _WKResidentKeyRequirementRequired:
+        return WebCore::ResidentKeyRequirement::Required;
+    case _WKResidentKeyRequirementPreferred:
+        return WebCore::ResidentKeyRequirement::Preferred;
+    case _WKResidentKeyRequirementDiscouraged:
+        return WebCore::ResidentKeyRequirement::Discouraged;
+    default:
+        ASSERT_NOT_REACHED();
+        return WebCore::ResidentKeyRequirement::Preferred;
+    }
+}
+
 static WebCore::PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria authenticatorSelectionCriteria(_WKAuthenticatorSelectionCriteria *authenticatorSelection)
 {
     WebCore::PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria result;
     result.authenticatorAttachment = authenticatorAttachment(authenticatorSelection.authenticatorAttachment);
+    result.residentKey = toWebCore(authenticatorSelection.residentKey);
     result.requireResidentKey = authenticatorSelection.requireResidentKey;
     result.userVerification = userVerification(authenticatorSelection.userVerification);
 
@@ -930,7 +948,7 @@
 #if ENABLE(WEB_AUTHN)
     auto hash = produceClientDataJsonHash(clientDataJSON);
 
-    auto encodedVector = fido::encodeMakeCredenitalRequestAsCBOR(hash, [_WKWebAuthenticationPanel convertToCoreCreationOptionsWithOptions:options], coreUserVerificationAvailability(userVerificationAvailability), std::nullopt);
+    auto encodedVector = fido::encodeMakeCredenitalRequestAsCBOR(hash, [_WKWebAuthenticationPanel convertToCoreCreationOptionsWithOptions:options], coreUserVerificationAvailability(userVerificationAvailability), fido::AuthenticatorSupportedOptions::ResidentKeyAvailability::kSupported, std::nullopt);
     encodedCommand = adoptNS([[NSData alloc] initWithBytes:encodedVector.data() length:encodedVector.size()]);
 #endif
 
@@ -955,7 +973,7 @@
 {
     RetainPtr<NSData> encodedCommand;
 #if ENABLE(WEB_AUTHN)
-    auto encodedVector = fido::encodeMakeCredenitalRequestAsCBOR(vectorFromNSData(clientDataHash), [_WKWebAuthenticationPanel convertToCoreCreationOptionsWithOptions:options], coreUserVerificationAvailability(userVerificationAvailability), std::nullopt);
+    auto encodedVector = fido::encodeMakeCredenitalRequestAsCBOR(vectorFromNSData(clientDataHash), [_WKWebAuthenticationPanel convertToCoreCreationOptionsWithOptions:options], coreUserVerificationAvailability(userVerificationAvailability), fido::AuthenticatorSupportedOptions::ResidentKeyAvailability::kSupported, std::nullopt);
     encodedCommand = adoptNS([[NSData alloc] initWithBytes:encodedVector.data() length:encodedVector.size()]);
 #endif
 

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/fido/CtapAuthenticator.cpp (291175 => 291176)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/fido/CtapAuthenticator.cpp	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/fido/CtapAuthenticator.cpp	2022-03-11 17:49:14 UTC (rev 291176)
@@ -96,13 +96,14 @@
     Vector<uint8_t> cborCmd;
     auto& options = std::get<PublicKeyCredentialCreationOptions>(requestData().options);
     auto internalUVAvailability = m_info.options().userVerificationAvailability();
+    auto residentKeyAvailability = m_info.options().residentKeyAvailability();
     // If UV is required, then either built-in uv or a pin will work.
     if (internalUVAvailability == UVAvailability::kSupportedAndConfigured && (!options.authenticatorSelection || options.authenticatorSelection->userVerification != UserVerificationRequirement::Discouraged) && m_pinAuth.isEmpty())
-        cborCmd = encodeMakeCredenitalRequestAsCBOR(requestData().hash, options, internalUVAvailability);
+        cborCmd = encodeMakeCredenitalRequestAsCBOR(requestData().hash, options, internalUVAvailability, residentKeyAvailability);
     else if (m_info.options().clientPinAvailability() == AuthenticatorSupportedOptions::ClientPinAvailability::kSupportedAndPinSet)
-        cborCmd = encodeMakeCredenitalRequestAsCBOR(requestData().hash, options, internalUVAvailability, PinParameters { pin::kProtocolVersion, m_pinAuth });
+        cborCmd = encodeMakeCredenitalRequestAsCBOR(requestData().hash, options, internalUVAvailability, residentKeyAvailability, PinParameters { pin::kProtocolVersion, m_pinAuth });
     else
-        cborCmd = encodeMakeCredenitalRequestAsCBOR(requestData().hash, options, internalUVAvailability);
+        cborCmd = encodeMakeCredenitalRequestAsCBOR(requestData().hash, options, internalUVAvailability, residentKeyAvailability);
     driver().transact(WTFMove(cborCmd), [weakThis = WeakPtr { *this }](Vector<uint8_t>&& data) {
         ASSERT(RunLoop::isMain());
         if (!weakThis)

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (291175 => 291176)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2022-03-11 17:49:14 UTC (rev 291176)
@@ -1081,6 +1081,7 @@
 		51FAEC3A1B0657630009C4E7 /* AuxiliaryProcessMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51FAEC371B0657310009C4E7 /* AuxiliaryProcessMessages.h */; };
 		51FAEC3B1B0657680009C4E7 /* AuxiliaryProcessMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51FAEC361B0657310009C4E7 /* AuxiliaryProcessMessageReceiver.cpp */; };
 		51FD18B61651FBAD00DBE1CE /* NetworkResourceLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 51FD18B41651FBAD00DBE1CE /* NetworkResourceLoader.h */; };
+		52688AB427D7CE40003577A2 /* _WKResidentKeyRequirement.h in Headers */ = {isa = PBXBuildFile; fileRef = 52688AB327D7CE40003577A2 /* _WKResidentKeyRequirement.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		5272D4C91E735F0900EB4290 /* WKProtectionSpaceNS.h in Headers */ = {isa = PBXBuildFile; fileRef = 5272D4C71E735F0900EB4290 /* WKProtectionSpaceNS.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		528C37C1195CBB1A00D8B9CC /* WKBackForwardListPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A9F28101958F478008CAC72 /* WKBackForwardListPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		52CDC5C42731DA0D00A3E3EB /* VirtualAuthenticatorConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = 52CDC5BD2731DA0C00A3E3EB /* VirtualAuthenticatorConfiguration.h */; };
@@ -4642,6 +4643,7 @@
 		51FB0902163A3B1C00EC324A /* NetworkProcessConnection.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; name = NetworkProcessConnection.messages.in; path = Network/NetworkProcessConnection.messages.in; sourceTree = "<group>"; };
 		51FD18B31651FBAD00DBE1CE /* NetworkResourceLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkResourceLoader.cpp; sourceTree = "<group>"; };
 		51FD18B41651FBAD00DBE1CE /* NetworkResourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkResourceLoader.h; sourceTree = "<group>"; };
+		52688AB327D7CE40003577A2 /* _WKResidentKeyRequirement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = _WKResidentKeyRequirement.h; path = UIProcess/API/Cocoa/_WKResidentKeyRequirement.h; sourceTree = "<group>"; };
 		5272D4C71E735F0900EB4290 /* WKProtectionSpaceNS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKProtectionSpaceNS.h; path = mac/WKProtectionSpaceNS.h; sourceTree = "<group>"; };
 		5272D4C81E735F0900EB4290 /* WKProtectionSpaceNS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKProtectionSpaceNS.mm; path = mac/WKProtectionSpaceNS.mm; sourceTree = "<group>"; };
 		52CDC5BD2731DA0C00A3E3EB /* VirtualAuthenticatorConfiguration.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VirtualAuthenticatorConfiguration.h; sourceTree = "<group>"; };
@@ -6980,6 +6982,7 @@
 		0867D691FE84028FC02AAC07 /* WebKit2 */ = {
 			isa = PBXGroup;
 			children = (
+				52688AB327D7CE40003577A2 /* _WKResidentKeyRequirement.h */,
 				5C157A0A2717C9F100ED5280 /* webpushd */,
 				B396EA5512E0ED2D00F4FEB7 /* config.h */,
 				2D7DEBE021269D5F00B9F73C /* Sources.txt */,
@@ -12982,6 +12985,7 @@
 				990E1E092384AA57004602DF /* _WKRemoteWebInspectorViewControllerPrivate.h in Headers */,
 				377216B81A4E6BE000DCA718 /* _WKRenderingProgressEvents.h in Headers */,
 				1F604BAA1889FBB800EE0395 /* _WKRenderingProgressEventsInternal.h in Headers */,
+				52688AB427D7CE40003577A2 /* _WKResidentKeyRequirement.h in Headers */,
 				5CB7AFE023C52CE500E49CF3 /* _WKResourceLoadDelegate.h in Headers */,
 				5CB7AFE823C69B6100E49CF3 /* _WKResourceLoadInfo.h in Headers */,
 				49FBF001239B1F8D00BD032F /* _WKResourceLoadStatisticsFirstParty.h in Headers */,
@@ -13673,7 +13677,6 @@
 				5742A30825358A0400B7BA14 /* WebAuthnProcessCreationParameters.h in Headers */,
 				572EBBC22536A60A000552B3 /* WebAuthnProcessMessages.h in Headers */,
 				572EBBC92536AFD5000552B3 /* WebAuthnProcessProxy.h in Headers */,
-				572EBBD02536BB11000552B3 /* WebAuthnProcessProxyMessages.h in Headers */,
 				F42D634122A0EFDF00D2FB3A /* WebAutocorrectionData.h in Headers */,
 				990D39F5243BE64800199388 /* WebAutomationDOMWindowObserver.h in Headers */,
 				9955A6EC1C7980C200EB6A93 /* WebAutomationSession.h in Headers */,

Modified: trunk/Tools/ChangeLog (291175 => 291176)


--- trunk/Tools/ChangeLog	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Tools/ChangeLog	2022-03-11 17:49:14 UTC (rev 291176)
@@ -1,3 +1,18 @@
+2022-03-11  J Pascoe  <[email protected]>
+
+        [WebAuthn] Support authenticatorSelection.residentKey ResidentKeyRequirement
+        https://bugs.webkit.org/show_bug.cgi?id=237567
+        rdar://89788378
+
+        Reviewed by Brent Fulgham and Chris Dumez.
+
+        Add API tests for authenticatorSelection.residentKey.
+
+        * TestWebKitAPI/Tests/WebCore/CtapRequestTest.cpp:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebCore/CtapResponseTest.cpp:
+        (TestWebKitAPI::TEST):
+
 2022-03-10  Carlos Garcia Campos  <[email protected]>
 
         [GTK] Add a unit tests to check the remote inspector HTTP server

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/CtapRequestTest.cpp (291175 => 291176)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/CtapRequestTest.cpp	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/CtapRequestTest.cpp	2022-03-11 17:49:14 UTC (rev 291176)
@@ -60,12 +60,12 @@
     user.displayName = "John P. Smith";
 
     Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
-    PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria selection { AuthenticatorAttachment::Platform, true, UserVerificationRequirement::Preferred };
+    PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria selection { AuthenticatorAttachment::Platform, std::nullopt, true, UserVerificationRequirement::Preferred };
 
     PublicKeyCredentialCreationOptions options { rp, user, { }, params, std::nullopt, { }, selection, AttestationConveyancePreference::None, std::nullopt };
     Vector<uint8_t> hash;
     hash.append(TestData::kClientDataHash, sizeof(TestData::kClientDataHash));
-    auto serializedData = encodeMakeCredenitalRequestAsCBOR(hash, options, AuthenticatorSupportedOptions::UserVerificationAvailability::kSupportedAndConfigured);
+    auto serializedData = encodeMakeCredenitalRequestAsCBOR(hash, options, AuthenticatorSupportedOptions::UserVerificationAvailability::kSupportedAndConfigured, AuthenticatorSupportedOptions::ResidentKeyAvailability::kSupported);
     EXPECT_EQ(serializedData.size(), sizeof(TestData::kCtapMakeCredentialRequest));
     EXPECT_EQ(memcmp(serializedData.data(), TestData::kCtapMakeCredentialRequest, serializedData.size()), 0);
 }
@@ -83,12 +83,12 @@
     user.displayName = "John P. Smith";
 
     Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
-    PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria selection { AuthenticatorAttachment::Platform, false, UserVerificationRequirement::Discouraged };
+    PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria selection { AuthenticatorAttachment::Platform, std::nullopt, false, UserVerificationRequirement::Discouraged };
 
     PublicKeyCredentialCreationOptions options { rp, user, { }, params, std::nullopt, { }, selection, AttestationConveyancePreference::None, std::nullopt };
     Vector<uint8_t> hash;
     hash.append(TestData::kClientDataHash, sizeof(TestData::kClientDataHash));
-    auto serializedData = encodeMakeCredenitalRequestAsCBOR(hash, options, AuthenticatorSupportedOptions::UserVerificationAvailability::kSupportedAndConfigured);
+    auto serializedData = encodeMakeCredenitalRequestAsCBOR(hash, options, AuthenticatorSupportedOptions::UserVerificationAvailability::kSupportedAndConfigured, AuthenticatorSupportedOptions::ResidentKeyAvailability::kSupported);
     EXPECT_EQ(serializedData.size(), sizeof(TestData::kCtapMakeCredentialRequestShort));
     EXPECT_EQ(memcmp(serializedData.data(), TestData::kCtapMakeCredentialRequestShort, serializedData.size()), 0);
 }
@@ -106,12 +106,12 @@
     user.displayName = "John P. Smith";
 
     Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
-    PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria selection { AuthenticatorAttachment::Platform, false, UserVerificationRequirement::Required };
+    PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria selection { AuthenticatorAttachment::Platform, std::nullopt, false, UserVerificationRequirement::Required };
 
     PublicKeyCredentialCreationOptions options { rp, user, { }, params, std::nullopt, { }, selection, AttestationConveyancePreference::None, std::nullopt };
     Vector<uint8_t> hash;
     hash.append(TestData::kClientDataHash, sizeof(TestData::kClientDataHash));
-    auto serializedData = encodeMakeCredenitalRequestAsCBOR(hash, options, AuthenticatorSupportedOptions::UserVerificationAvailability::kNotSupported);
+    auto serializedData = encodeMakeCredenitalRequestAsCBOR(hash, options, AuthenticatorSupportedOptions::UserVerificationAvailability::kNotSupported, AuthenticatorSupportedOptions::ResidentKeyAvailability::kSupported);
     EXPECT_EQ(serializedData.size(), sizeof(TestData::kCtapMakeCredentialRequestShort));
     EXPECT_EQ(memcmp(serializedData.data(), TestData::kCtapMakeCredentialRequestShort, serializedData.size()), 0);
 }
@@ -129,7 +129,7 @@
     user.displayName = "John P. Smith";
 
     Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
-    PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria selection { AuthenticatorAttachment::Platform, true, UserVerificationRequirement::Preferred };
+    PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria selection { AuthenticatorAttachment::Platform, std::nullopt, true, UserVerificationRequirement::Preferred };
 
     PinParameters pin;
     pin.protocol = pin::kProtocolVersion;
@@ -138,11 +138,84 @@
     PublicKeyCredentialCreationOptions options { rp, user, { }, params, std::nullopt, { }, selection, AttestationConveyancePreference::None, std::nullopt };
     Vector<uint8_t> hash;
     hash.append(TestData::kClientDataHash, sizeof(TestData::kClientDataHash));
-    auto serializedData = encodeMakeCredenitalRequestAsCBOR(hash, options, AuthenticatorSupportedOptions::UserVerificationAvailability::kSupportedAndConfigured, pin);
+    auto serializedData = encodeMakeCredenitalRequestAsCBOR(hash, options, AuthenticatorSupportedOptions::UserVerificationAvailability::kSupportedAndConfigured, AuthenticatorSupportedOptions::ResidentKeyAvailability::kSupported, pin);
     EXPECT_EQ(serializedData.size(), sizeof(TestData::kCtapMakeCredentialRequestWithPin));
     EXPECT_EQ(memcmp(serializedData.data(), TestData::kCtapMakeCredentialRequestWithPin, serializedData.size()), 0);
 }
 
+TEST(CTAPRequestTest, TestConstructMakeCredentialRequestRKPreferred)
+{
+    PublicKeyCredentialCreationOptions::RpEntity rp;
+    rp.name = "Acme";
+    rp.id = "acme.com";
+
+    PublicKeyCredentialCreationOptions::UserEntity user;
+    user.name = "[email protected]";
+    user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png";
+    user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
+    user.displayName = "John P. Smith";
+
+    Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
+    PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria selection { AuthenticatorAttachment::Platform, ResidentKeyRequirement::Preferred, true, UserVerificationRequirement::Preferred };
+
+    PinParameters pin;
+    pin.protocol = pin::kProtocolVersion;
+    pin.auth.append(TestData::kCtap2PinAuth, sizeof(TestData::kCtap2PinAuth));
+
+    PublicKeyCredentialCreationOptions options { rp, user, { }, params, std::nullopt, { }, selection, AttestationConveyancePreference::None, std::nullopt };
+    Vector<uint8_t> hash;
+    hash.append(TestData::kClientDataHash, sizeof(TestData::kClientDataHash));
+    auto serializedData = encodeMakeCredenitalRequestAsCBOR(hash, options, AuthenticatorSupportedOptions::UserVerificationAvailability::kSupportedAndConfigured, AuthenticatorSupportedOptions::ResidentKeyAvailability::kSupported, pin);
+    EXPECT_EQ(serializedData.size(), sizeof(TestData::kCtapMakeCredentialRequestWithPin));
+    EXPECT_EQ(memcmp(serializedData.data(), TestData::kCtapMakeCredentialRequestWithPin, serializedData.size()), 0);
+}
+
+TEST(CTAPRequestTest, TestConstructMakeCredentialRequestRKPreferredNotSupported)
+{
+    PublicKeyCredentialCreationOptions::RpEntity rp;
+    rp.name = "Acme";
+    rp.id = "acme.com";
+
+    PublicKeyCredentialCreationOptions::UserEntity user;
+    user.name = "[email protected]";
+    user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png";
+    user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
+    user.displayName = "John P. Smith";
+
+    Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
+    PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria selection { AuthenticatorAttachment::Platform, ResidentKeyRequirement::Preferred, true, UserVerificationRequirement::Required };
+
+    PublicKeyCredentialCreationOptions options { rp, user, { }, params, std::nullopt, { }, selection, AttestationConveyancePreference::None, std::nullopt };
+    Vector<uint8_t> hash;
+    hash.append(TestData::kClientDataHash, sizeof(TestData::kClientDataHash));
+    auto serializedData = encodeMakeCredenitalRequestAsCBOR(hash, options, AuthenticatorSupportedOptions::UserVerificationAvailability::kNotSupported, AuthenticatorSupportedOptions::ResidentKeyAvailability::kNotSupported);
+    EXPECT_EQ(serializedData.size(), sizeof(TestData::kCtapMakeCredentialRequestShort));
+    EXPECT_EQ(memcmp(serializedData.data(), TestData::kCtapMakeCredentialRequestShort, serializedData.size()), 0);
+}
+
+TEST(CTAPRequestTest, TestConstructMakeCredentialRequestRKDiscouraged)
+{
+    PublicKeyCredentialCreationOptions::RpEntity rp;
+    rp.name = "Acme";
+    rp.id = "acme.com";
+
+    PublicKeyCredentialCreationOptions::UserEntity user;
+    user.name = "[email protected]";
+    user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png";
+    user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
+    user.displayName = "John P. Smith";
+
+    Vector<PublicKeyCredentialCreationOptions::Parameters> params { { PublicKeyCredentialType::PublicKey, 7 }, { PublicKeyCredentialType::PublicKey, 257 } };
+    PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria selection { AuthenticatorAttachment::Platform, ResidentKeyRequirement::Discouraged, true, UserVerificationRequirement::Required };
+
+    PublicKeyCredentialCreationOptions options { rp, user, { }, params, std::nullopt, { }, selection, AttestationConveyancePreference::None, std::nullopt };
+    Vector<uint8_t> hash;
+    hash.append(TestData::kClientDataHash, sizeof(TestData::kClientDataHash));
+    auto serializedData = encodeMakeCredenitalRequestAsCBOR(hash, options, AuthenticatorSupportedOptions::UserVerificationAvailability::kNotSupported, AuthenticatorSupportedOptions::ResidentKeyAvailability::kSupported);
+    EXPECT_EQ(serializedData.size(), sizeof(TestData::kCtapMakeCredentialRequestShort));
+    EXPECT_EQ(memcmp(serializedData.data(), TestData::kCtapMakeCredentialRequestShort, serializedData.size()), 0);
+}
+
 TEST(CTAPRequestTest, TestConstructGetAssertionRequest)
 {
     PublicKeyCredentialRequestOptions options;

Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/CtapResponseTest.cpp (291175 => 291176)


--- trunk/Tools/TestWebKitAPI/Tests/WebCore/CtapResponseTest.cpp	2022-03-11 17:39:43 UTC (rev 291175)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/CtapResponseTest.cpp	2022-03-11 17:49:14 UTC (rev 291176)
@@ -589,7 +589,7 @@
     EXPECT_NE(getInfoResponse->versions().find(ProtocolVersion::kCtap), getInfoResponse->versions().end());
     EXPECT_NE(getInfoResponse->versions().find(ProtocolVersion::kU2f), getInfoResponse->versions().end());
     EXPECT_TRUE(getInfoResponse->options().isPlatformDevice());
-    EXPECT_TRUE(getInfoResponse->options().supportsResidentKey());
+    EXPECT_EQ(AuthenticatorSupportedOptions::ResidentKeyAvailability::kSupported, getInfoResponse->options().residentKeyAvailability());
     EXPECT_TRUE(getInfoResponse->options().userPresenceRequired());
     EXPECT_EQ(AuthenticatorSupportedOptions::UserVerificationAvailability::kSupportedAndConfigured, getInfoResponse->options().userVerificationAvailability());
     EXPECT_EQ(AuthenticatorSupportedOptions::ClientPinAvailability::kSupportedButPinNotSet, getInfoResponse->options().clientPinAvailability());
@@ -604,7 +604,7 @@
     EXPECT_NE(getInfoResponse->versions().find(ProtocolVersion::kCtap), getInfoResponse->versions().end());
     EXPECT_NE(getInfoResponse->versions().find(ProtocolVersion::kU2f), getInfoResponse->versions().end());
     EXPECT_TRUE(getInfoResponse->options().isPlatformDevice());
-    EXPECT_TRUE(getInfoResponse->options().supportsResidentKey());
+    EXPECT_EQ(AuthenticatorSupportedOptions::ResidentKeyAvailability::kSupported, getInfoResponse->options().residentKeyAvailability());
     EXPECT_TRUE(getInfoResponse->options().userPresenceRequired());
     EXPECT_EQ(AuthenticatorSupportedOptions::UserVerificationAvailability::kSupportedAndConfigured, getInfoResponse->options().userVerificationAvailability());
     EXPECT_EQ(AuthenticatorSupportedOptions::ClientPinAvailability::kSupportedButPinNotSet, getInfoResponse->options().clientPinAvailability());
@@ -622,7 +622,7 @@
     AuthenticatorGetInfoResponse response({ ProtocolVersion::kCtap, ProtocolVersion::kU2f }, convertBytesToVector(kTestDeviceAaguid, sizeof(kTestDeviceAaguid)));
     response.setExtensions({ "uvm", "hmac-secret" });
     AuthenticatorSupportedOptions options;
-    options.setSupportsResidentKey(true);
+    options.setResidentKeyAvailability(AuthenticatorSupportedOptions::ResidentKeyAvailability::kSupported);
     options.setIsPlatformDevice(true);
     options.setClientPinAvailability(AuthenticatorSupportedOptions::ClientPinAvailability::kSupportedButPinNotSet);
     options.setUserVerificationAvailability(AuthenticatorSupportedOptions::UserVerificationAvailability::kSupportedAndConfigured);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to