Title: [276184] trunk
Revision
276184
Author
[email protected]
Date
2021-04-16 17:14:03 -0700 (Fri, 16 Apr 2021)

Log Message

Pass credential name to the WebAuthn UI during registration
https://bugs.webkit.org/show_bug.cgi?id=224697
<rdar://75803352>

Reviewed by Brent Fulgham.

Source/WebKit:

Covered by new test contents within existing test files.

* Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h:
Paperwork for the new SPI.

* UIProcess/API/APIWebAuthenticationPanel.cpp:
(API::WebAuthenticationPanel::create):
(API::WebAuthenticationPanel::WebAuthenticationPanel):
* UIProcess/API/APIWebAuthenticationPanel.h:
* UIProcess/API/Cocoa/_WKWebAuthenticationPanel.h:
* UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm:
(-[_WKWebAuthenticationPanel userName]):
Adds a new userName property.

* UIProcess/WebAuthentication/AuthenticatorManager.cpp:
(WebKit::WebCore::getUserName):
(WebKit::AuthenticatorManager::runPanel):
(WebKit::AuthenticatorManager::runPresenter):
Passes the userName to the UI.

* UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.h:
* UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.mm:
Paperwork for the new SPI.

* UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h:
* UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm:
(WebKit::AuthenticatorPresenterCoordinator::AuthenticatorPresenterCoordinator):
Passes the userName to the new SPI.

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (276183 => 276184)


--- trunk/Source/WebKit/ChangeLog	2021-04-16 23:55:21 UTC (rev 276183)
+++ trunk/Source/WebKit/ChangeLog	2021-04-17 00:14:03 UTC (rev 276184)
@@ -1,3 +1,40 @@
+2021-04-16  Jiewen Tan  <[email protected]>
+
+        Pass credential name to the WebAuthn UI during registration
+        https://bugs.webkit.org/show_bug.cgi?id=224697
+        <rdar://75803352>
+
+        Reviewed by Brent Fulgham.
+
+        Covered by new test contents within existing test files.
+
+        * Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h:
+        Paperwork for the new SPI.
+
+        * UIProcess/API/APIWebAuthenticationPanel.cpp:
+        (API::WebAuthenticationPanel::create):
+        (API::WebAuthenticationPanel::WebAuthenticationPanel):
+        * UIProcess/API/APIWebAuthenticationPanel.h:
+        * UIProcess/API/Cocoa/_WKWebAuthenticationPanel.h:
+        * UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm:
+        (-[_WKWebAuthenticationPanel userName]):
+        Adds a new userName property.
+
+        * UIProcess/WebAuthentication/AuthenticatorManager.cpp:
+        (WebKit::WebCore::getUserName):
+        (WebKit::AuthenticatorManager::runPanel):
+        (WebKit::AuthenticatorManager::runPresenter):
+        Passes the userName to the UI.
+
+        * UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.h:
+        * UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.mm:
+        Paperwork for the new SPI.
+
+        * UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h:
+        * UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm:
+        (WebKit::AuthenticatorPresenterCoordinator::AuthenticatorPresenterCoordinator):
+        Passes the userName to the new SPI.
+
 2021-04-16  Cameron McCormack  <[email protected]>
 
         Place vertical scrollbars at (inline/block)-end edge in all writing modes.

Modified: trunk/Source/WebKit/Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h (276183 => 276184)


--- trunk/Source/WebKit/Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h	2021-04-16 23:55:21 UTC (rev 276183)
+++ trunk/Source/WebKit/Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h	2021-04-17 00:14:03 UTC (rev 276184)
@@ -114,9 +114,22 @@
     ASCSecurityKeyPublicKeyCredentialLoginChoiceKindAssertionPlaceholder,
 };
 
+@interface ASCPublicKeyCredentialCreationOptions : NSObject <NSSecureCoding>
+
+@property (nonatomic, copy) NSData *challenge;
+@property (nonatomic, copy) NSString *relyingPartyIdentifier;
+@property (nonatomic, copy) NSString *userName;
+@property (nonatomic, copy) NSData *userIdentifier;
+@property (nonatomic, copy) NSString *userDisplayName;
+@property (nonatomic, copy) NSArray<NSNumber *> *supportedAlgorithmIdentifiers;
+
+@property (nonatomic) BOOL shouldRequireResidentKey;
+
+@end
+
 @interface ASCSecurityKeyPublicKeyCredentialLoginChoice : NSObject <ASCLoginChoiceProtocol>
 
-- (instancetype)initRegistrationChoice;
+- (instancetype)initRegistrationChoiceWithOptions:(ASCPublicKeyCredentialCreationOptions *)options;
 - (instancetype)initWithName:(NSString *)name displayName:(NSString *)displayName userHandle:(NSData *)userHandle;
 - (instancetype)initAssertionPlaceholderChoice;
 
@@ -132,7 +145,7 @@
 
 @interface ASCPlatformPublicKeyCredentialLoginChoice : NSObject <ASCLoginChoiceProtocol>
 
-- (instancetype)initRegistrationChoice;
+- (instancetype)initRegistrationChoiceWithOptions:(ASCPublicKeyCredentialCreationOptions *)options;
 - (instancetype)initWithName:(NSString *)name displayName:(NSString *)displayName userHandle:(NSData *)userHandle;
 
 @property (nonatomic, readonly, copy) NSString *name;

Modified: trunk/Source/WebKit/UIProcess/API/APIWebAuthenticationPanel.cpp (276183 => 276184)


--- trunk/Source/WebKit/UIProcess/API/APIWebAuthenticationPanel.cpp	2021-04-16 23:55:21 UTC (rev 276183)
+++ trunk/Source/WebKit/UIProcess/API/APIWebAuthenticationPanel.cpp	2021-04-17 00:14:03 UTC (rev 276184)
@@ -37,9 +37,9 @@
 using namespace WebCore;
 using namespace WebKit;
 
-Ref<WebAuthenticationPanel> WebAuthenticationPanel::create(const AuthenticatorManager& manager, const WTF::String& rpId, const TransportSet& transports, ClientDataType type)
+Ref<WebAuthenticationPanel> WebAuthenticationPanel::create(const AuthenticatorManager& manager, const WTF::String& rpId, const TransportSet& transports, ClientDataType type, const WTF::String& userName)
 {
-    return adoptRef(*new WebAuthenticationPanel(manager, rpId, transports, type));
+    return adoptRef(*new WebAuthenticationPanel(manager, rpId, transports, type, userName));
 }
 
 WebAuthenticationPanel::WebAuthenticationPanel()
@@ -49,11 +49,12 @@
     m_manager->enableNativeSupport();
 }
 
-WebAuthenticationPanel::WebAuthenticationPanel(const AuthenticatorManager& manager, const WTF::String& rpId, const TransportSet& transports, ClientDataType type)
+WebAuthenticationPanel::WebAuthenticationPanel(const AuthenticatorManager& manager, const WTF::String& rpId, const TransportSet& transports, ClientDataType type, const WTF::String& userName)
     : m_client(makeUniqueRef<WebAuthenticationPanelClient>())
     , m_weakManager(makeWeakPtr(manager))
     , m_rpId(rpId)
     , m_clientDataType(type)
+    , m_userName(userName)
 {
     m_transports = Vector<AuthenticatorTransport>();
     m_transports.reserveInitialCapacity(AuthenticatorManager::maxTransportNumber);

Modified: trunk/Source/WebKit/UIProcess/API/APIWebAuthenticationPanel.h (276183 => 276184)


--- trunk/Source/WebKit/UIProcess/API/APIWebAuthenticationPanel.h	2021-04-16 23:55:21 UTC (rev 276183)
+++ trunk/Source/WebKit/UIProcess/API/APIWebAuthenticationPanel.h	2021-04-17 00:14:03 UTC (rev 276184)
@@ -69,14 +69,15 @@
 
     // FIXME: <rdar://problem/71509848> Remove the following deprecated methods.
     using TransportSet = HashSet<WebCore::AuthenticatorTransport, WTF::IntHash<WebCore::AuthenticatorTransport>, WTF::StrongEnumHashTraits<WebCore::AuthenticatorTransport>>;
-    static Ref<WebAuthenticationPanel> create(const WebKit::AuthenticatorManager&, const WTF::String& rpId, const TransportSet&, WebCore::ClientDataType);
+    static Ref<WebAuthenticationPanel> create(const WebKit::AuthenticatorManager&, const WTF::String& rpId, const TransportSet&, WebCore::ClientDataType, const WTF::String& userName);
     WTF::String rpId() const { return m_rpId; }
     const Vector<WebCore::AuthenticatorTransport>& transports() const { return m_transports; }
     WebCore::ClientDataType clientDataType() const { return m_clientDataType; }
+    WTF::String userName() const { return m_userName; }
 
 private:
     // FIXME: <rdar://problem/71509848> Remove the following deprecated method.
-    WebAuthenticationPanel(const WebKit::AuthenticatorManager&, const WTF::String& rpId, const TransportSet&, WebCore::ClientDataType);
+    WebAuthenticationPanel(const WebKit::AuthenticatorManager&, const WTF::String& rpId, const TransportSet&, WebCore::ClientDataType, const WTF::String& userName);
 
     std::unique_ptr<WebKit::AuthenticatorManager> m_manager; // FIXME: <rdar://problem/71509848> Change to UniqueRef.
     UniqueRef<WebAuthenticationPanelClient> m_client;
@@ -86,6 +87,7 @@
     WTF::String m_rpId;
     Vector<WebCore::AuthenticatorTransport> m_transports;
     WebCore::ClientDataType m_clientDataType;
+    WTF::String m_userName;
 };
 
 } // namespace API

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebAuthenticationPanel.h (276183 => 276184)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebAuthenticationPanel.h	2021-04-16 23:55:21 UTC (rev 276183)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebAuthenticationPanel.h	2021-04-17 00:14:03 UTC (rev 276184)
@@ -120,6 +120,7 @@
 @property (nonatomic, readonly, copy) NSString *relyingPartyID;
 @property (nonatomic, readonly, copy) NSSet *transports;
 @property (nonatomic, readonly) _WKWebAuthenticationType type;
+@property (nonatomic, readonly, copy, nullable) NSString *userName;
 
 @end
 

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


--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm	2021-04-16 23:55:21 UTC (rev 276183)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm	2021-04-17 00:14:03 UTC (rev 276184)
@@ -180,6 +180,12 @@
 {
     return wkWebAuthenticationType(_panel->clientDataType());
 }
+
+- (NSString *)userName
+{
+    return _panel->userName();
+}
+
 #else // ENABLE(WEB_AUTHN)
 - (id <_WKWebAuthenticationPanelDelegate>)delegate
 {

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.cpp (276183 => 276184)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.cpp	2021-04-16 23:55:21 UTC (rev 276183)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.cpp	2021-04-17 00:14:03 UTC (rev 276184)
@@ -153,6 +153,13 @@
     return WTF::get<PublicKeyCredentialRequestOptions>(options).rpId;
 }
 
+static String getUserName(const Variant<PublicKeyCredentialCreationOptions, PublicKeyCredentialRequestOptions>& options)
+{
+    if (WTF::holds_alternative<PublicKeyCredentialCreationOptions>(options))
+        return WTF::get<PublicKeyCredentialCreationOptions>(options).user.name;
+    return emptyString();
+}
+
 } // namespace
 
 const size_t AuthenticatorManager::maxTransportNumber = 3;
@@ -452,7 +459,7 @@
         return;
     }
 
-    m_pendingRequestData.panel = API::WebAuthenticationPanel::create(*this, getRpId(options), transports, getClientDataType(options));
+    m_pendingRequestData.panel = API::WebAuthenticationPanel::create(*this, getRpId(options), transports, getClientDataType(options), getUserName(options));
     auto& panel = *m_pendingRequestData.panel;
     page->uiClient().runWebAuthenticationPanel(*page, panel, *frame, FrameInfoData { m_pendingRequestData.frameInfo }, [transports = WTFMove(transports), weakPanel = makeWeakPtr(panel), weakThis = makeWeakPtr(*this), this] (WebAuthenticationPanelResult result) {
         // The panel address is used to determine if the current pending request is still the same.
@@ -480,7 +487,7 @@
         return;
 
     auto& options = m_pendingRequestData.options;
-    m_presenter = makeUnique<AuthenticatorPresenterCoordinator>(*this, getRpId(options), transports, getClientDataType(options));
+    m_presenter = makeUnique<AuthenticatorPresenterCoordinator>(*this, getRpId(options), transports, getClientDataType(options), getUserName(options));
 }
 
 void AuthenticatorManager::invokePendingCompletionHandler(Respond&& respond)

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.h (276183 => 276184)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.h	2021-04-16 23:55:21 UTC (rev 276183)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.h	2021-04-17 00:14:03 UTC (rev 276184)
@@ -39,6 +39,7 @@
 SOFT_LINK_CLASS_FOR_HEADER(WebKit, ASCPlatformPublicKeyCredentialLoginChoice);
 SOFT_LINK_CLASS_FOR_HEADER(WebKit, ASCSecurityKeyPublicKeyCredentialLoginChoice);
 SOFT_LINK_CLASS_FOR_HEADER(WebKit, ASCAppleIDCredential);
+SOFT_LINK_CLASS_FOR_HEADER(WebKit, ASCPublicKeyCredentialCreationOptions);
 
 SOFT_LINK_CONSTANT_FOR_HEADER(WebKit, AuthenticationServicesCore, ASCAuthorizationErrorDomain, NSErrorDomain);
 #define ASCAuthorizationErrorDomain WebKit::get_AuthenticationServicesCore_ASCAuthorizationErrorDomain()

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.mm (276183 => 276184)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.mm	2021-04-16 23:55:21 UTC (rev 276183)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.mm	2021-04-17 00:14:03 UTC (rev 276184)
@@ -39,6 +39,7 @@
 SOFT_LINK_CLASS_FOR_SOURCE(WebKit, AuthenticationServicesCore, ASCPlatformPublicKeyCredentialLoginChoice);
 SOFT_LINK_CLASS_FOR_SOURCE(WebKit, AuthenticationServicesCore, ASCSecurityKeyPublicKeyCredentialLoginChoice);
 SOFT_LINK_CLASS_FOR_SOURCE(WebKit, AuthenticationServicesCore, ASCAppleIDCredential);
+SOFT_LINK_CLASS_FOR_SOURCE(WebKit, AuthenticationServicesCore, ASCPublicKeyCredentialCreationOptions);
 
 SOFT_LINK_CONSTANT_FOR_SOURCE(WebKit, AuthenticationServicesCore, ASCAuthorizationErrorDomain, NSErrorDomain);
 SOFT_LINK_CONSTANT_FOR_SOURCE(WebKit, AuthenticationServicesCore, ASCPINValidationResultKey, NSString*);

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h (276183 => 276184)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h	2021-04-16 23:55:21 UTC (rev 276183)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h	2021-04-17 00:14:03 UTC (rev 276184)
@@ -55,7 +55,7 @@
     using TransportSet = HashSet<WebCore::AuthenticatorTransport, WTF::IntHash<WebCore::AuthenticatorTransport>, WTF::StrongEnumHashTraits<WebCore::AuthenticatorTransport>>;
     using CredentialRequestHandler = Function<void(ASCAppleIDCredential *, NSError *)>;
 
-    AuthenticatorPresenterCoordinator(const AuthenticatorManager&, const String& rpId, const TransportSet&, WebCore::ClientDataType);
+    AuthenticatorPresenterCoordinator(const AuthenticatorManager&, const String& rpId, const TransportSet&, WebCore::ClientDataType, const String& username);
     ~AuthenticatorPresenterCoordinator();
 
     void updatePresenter(WebAuthenticationStatus);

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm (276183 => 276184)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm	2021-04-16 23:55:21 UTC (rev 276183)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm	2021-04-17 00:14:03 UTC (rev 276184)
@@ -37,7 +37,7 @@
 namespace WebKit {
 using namespace WebCore;
 
-AuthenticatorPresenterCoordinator::AuthenticatorPresenterCoordinator(const AuthenticatorManager& manager, const String& rpId, const TransportSet& transports, ClientDataType type)
+AuthenticatorPresenterCoordinator::AuthenticatorPresenterCoordinator(const AuthenticatorManager& manager, const String& rpId, const TransportSet& transports, ClientDataType type, const String& username)
     : m_manager(makeWeakPtr(manager))
 {
 #if HAVE(ASC_AUTH_UI)
@@ -46,12 +46,16 @@
         [m_context setServiceName:rpId];
 
     switch (type) {
-    case ClientDataType::Create:
+    case ClientDataType::Create: {
+        auto options = adoptNS([allocASCPublicKeyCredentialCreationOptionsInstance() init]);
+        [options setUserName:username];
+
         if (transports.contains(AuthenticatorTransport::Internal))
-            [m_context addLoginChoice:adoptNS([allocASCPlatformPublicKeyCredentialLoginChoiceInstance() initRegistrationChoice]).get()];
+            [m_context addLoginChoice:adoptNS([allocASCPlatformPublicKeyCredentialLoginChoiceInstance() initRegistrationChoiceWithOptions:options.get()]).get()];
         if (transports.contains(AuthenticatorTransport::Usb) || transports.contains(AuthenticatorTransport::Nfc))
-            [m_context addLoginChoice:adoptNS([allocASCSecurityKeyPublicKeyCredentialLoginChoiceInstance() initRegistrationChoice]).get()];
+            [m_context addLoginChoice:adoptNS([allocASCSecurityKeyPublicKeyCredentialLoginChoiceInstance() initRegistrationChoiceWithOptions:options.get()]).get()];
         break;
+    }
     case ClientDataType::Get:
         if ((transports.contains(AuthenticatorTransport::Usb) || transports.contains(AuthenticatorTransport::Nfc)) && !transports.contains(AuthenticatorTransport::Internal))
             [m_context addLoginChoice:adoptNS([allocASCSecurityKeyPublicKeyCredentialLoginChoiceInstance() initAssertionPlaceholderChoice]).get()];

Modified: trunk/Tools/ChangeLog (276183 => 276184)


--- trunk/Tools/ChangeLog	2021-04-16 23:55:21 UTC (rev 276183)
+++ trunk/Tools/ChangeLog	2021-04-17 00:14:03 UTC (rev 276184)
@@ -1,3 +1,14 @@
+2021-04-16  Jiewen Tan  <[email protected]>
+
+        Pass credential name to the WebAuthn UI during registration
+        https://bugs.webkit.org/show_bug.cgi?id=224697
+        <rdar://75803352>
+
+        Reviewed by Brent Fulgham.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm:
+        (TestWebKitAPI::TEST):
+
 2021-04-16  Kate Cheney  <[email protected]>
 
         Disable app-bound request API tests on specific OS versions

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm (276183 => 276184)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm	2021-04-16 23:55:21 UTC (rev 276183)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm	2021-04-17 00:14:03 UTC (rev 276184)
@@ -491,6 +491,7 @@
 
     // A bit of extra checks.
     checkPanel([delegate panel], @"", @[adoptNS([[NSNumber alloc] initWithInt:_WKWebAuthenticationTransportUSB]).get()], _WKWebAuthenticationTypeCreate);
+    EXPECT_WK_STREQ([delegate panel].userName, "John Appleseed");
 }
 
 #if HAVE(NEAR_FIELD)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to