Title: [270694] trunk/Source/WebKit
Revision
270694
Author
[email protected]
Date
2020-12-11 11:46:49 -0800 (Fri, 11 Dec 2020)

Log Message

[WebAuthn] Adopt new UI for the Platform Authenticator makeCredential flow
https://bugs.webkit.org/show_bug.cgi?id=219709
<rdar://problem/72154774>

Reviewed by Brent Fulgham.

This patch adopts the new UI for the platform authenticator makeCredential flow. In this new design,
the UI will be responsible for creating the LAContext and get it verified by the user. Therefore, WebKit
just needs to reverify the LAContext in non-UI mode against the SecAccessControlRef without handling any
LA UI anymore.

Covered by manual tests.

* Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h:
Adds a new class which represents a successful operation.

* Resources/SandboxProfiles/ios/com.apple.WebKit.WebAuthn.sb:
Adds rule to allow the WebAuthn process to access Keychain and SEP.

* UIProcess/WebAuthentication/Authenticator.h:
(WebKit::Authenticator::setWebAuthenticationModernEnabled):
(WebKit::Authenticator::webAuthenticationModernEnabled const):
Adds a flag to know which UI to call.

* UIProcess/WebAuthentication/AuthenticatorManager.cpp:
(WebKit::AuthenticatorManager::handleRequest):
(WebKit::AuthenticatorManager::enableModernWebAuthentication):
(WebKit::AuthenticatorManager::authenticatorAdded):
(WebKit::AuthenticatorManager::requestLAContextForUserVerification):
(WebKit::AuthenticatorManager::invokePendingCompletionHandler):
* UIProcess/WebAuthentication/AuthenticatorManager.h:
Adds plumbing to the new UI method.

* UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.h:
* UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.mm:
Paperwork.

* UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h:
(WebKit::AuthenticatorPresenterCoordinator::setCredentialRequestHandler):
This handler is from the UI delegate which is supposed to call if the operation succeeds.
* UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm:
(WebKit::AuthenticatorPresenterCoordinator::AuthenticatorPresenterCoordinator):
(WebKit::AuthenticatorPresenterCoordinator::requestLAContextForUserVerification):
(WebKit::AuthenticatorPresenterCoordinator::dimissPresenter):
(WebKit::AuthenticatorPresenterCoordinator::setLAContext):
* UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.h:
* UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm:
(WebKit::LocalAuthenticator::makeCredential):
(WebKit::LocalAuthenticator::continueMakeCredentialAfterReceivingLAContext):
* UIProcess/WebAuthentication/Cocoa/LocalConnection.h:
* UIProcess/WebAuthentication/Cocoa/LocalConnection.mm:
(WebKit::LocalConnection::verifyUser):
* UIProcess/WebAuthentication/Cocoa/WKASCAuthorizationPresenterDelegate.mm:
(-[WKASCAuthorizationPresenterDelegate authorizationPresenter:credentialRequestedForLoginChoice:authenticatedContext:completionHandler:]):
(-[WKASCAuthorizationPresenterDelegate dispatchCoordinatorCallback:]):
Implements the new UI logic.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (270693 => 270694)


--- trunk/Source/WebKit/ChangeLog	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/ChangeLog	2020-12-11 19:46:49 UTC (rev 270694)
@@ -1,3 +1,62 @@
+2020-12-10  Jiewen Tan  <[email protected]>
+
+        [WebAuthn] Adopt new UI for the Platform Authenticator makeCredential flow
+        https://bugs.webkit.org/show_bug.cgi?id=219709
+        <rdar://problem/72154774>
+
+        Reviewed by Brent Fulgham.
+
+        This patch adopts the new UI for the platform authenticator makeCredential flow. In this new design,
+        the UI will be responsible for creating the LAContext and get it verified by the user. Therefore, WebKit
+        just needs to reverify the LAContext in non-UI mode against the SecAccessControlRef without handling any
+        LA UI anymore.
+
+        Covered by manual tests.
+
+        * Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h:
+        Adds a new class which represents a successful operation.
+
+        * Resources/SandboxProfiles/ios/com.apple.WebKit.WebAuthn.sb:
+        Adds rule to allow the WebAuthn process to access Keychain and SEP.
+
+        * UIProcess/WebAuthentication/Authenticator.h:
+        (WebKit::Authenticator::setWebAuthenticationModernEnabled):
+        (WebKit::Authenticator::webAuthenticationModernEnabled const):
+        Adds a flag to know which UI to call.
+
+        * UIProcess/WebAuthentication/AuthenticatorManager.cpp:
+        (WebKit::AuthenticatorManager::handleRequest):
+        (WebKit::AuthenticatorManager::enableModernWebAuthentication):
+        (WebKit::AuthenticatorManager::authenticatorAdded):
+        (WebKit::AuthenticatorManager::requestLAContextForUserVerification):
+        (WebKit::AuthenticatorManager::invokePendingCompletionHandler):
+        * UIProcess/WebAuthentication/AuthenticatorManager.h:
+        Adds plumbing to the new UI method.
+
+        * UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.h:
+        * UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.mm:
+        Paperwork.
+
+        * UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h:
+        (WebKit::AuthenticatorPresenterCoordinator::setCredentialRequestHandler):
+        This handler is from the UI delegate which is supposed to call if the operation succeeds.
+        * UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm:
+        (WebKit::AuthenticatorPresenterCoordinator::AuthenticatorPresenterCoordinator):
+        (WebKit::AuthenticatorPresenterCoordinator::requestLAContextForUserVerification):
+        (WebKit::AuthenticatorPresenterCoordinator::dimissPresenter):
+        (WebKit::AuthenticatorPresenterCoordinator::setLAContext):
+        * UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.h:
+        * UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm:
+        (WebKit::LocalAuthenticator::makeCredential):
+        (WebKit::LocalAuthenticator::continueMakeCredentialAfterReceivingLAContext):
+        * UIProcess/WebAuthentication/Cocoa/LocalConnection.h:
+        * UIProcess/WebAuthentication/Cocoa/LocalConnection.mm:
+        (WebKit::LocalConnection::verifyUser):
+        * UIProcess/WebAuthentication/Cocoa/WKASCAuthorizationPresenterDelegate.mm:
+        (-[WKASCAuthorizationPresenterDelegate authorizationPresenter:credentialRequestedForLoginChoice:authenticatedContext:completionHandler:]):
+        (-[WKASCAuthorizationPresenterDelegate dispatchCoordinatorCallback:]):
+        Implements the new UI logic.
+
 2020-12-11  Per Arne Vollan  <[email protected]>
 
         [macOS] Remove access to com.apple.MTLCompilerService in the WebContent process

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


--- trunk/Source/WebKit/Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h	2020-12-11 19:46:49 UTC (rev 270694)
@@ -29,6 +29,8 @@
 
 #if USE(APPLE_INTERNAL_SDK)
 
+// FIXME(219767): Remove ASCAppleIDCredential.h.
+#import <AuthenticationServicesCore/ASCAppleIDCredential.h>
 #import <AuthenticationServicesCore/ASCAuthorizationPresentationContext.h>
 #import <AuthenticationServicesCore/ASCAuthorizationPresenter.h>
 #import <AuthenticationServicesCore/ASCPlatformPublicKeyCredentialLoginChoice.h>
@@ -130,6 +132,23 @@
 
 @end
 
+@protocol ASCCredentialProtocol <NSObject, NSSecureCoding>
+
+@end
+
+// FIXME(219767): Remove ASCAppleIDCredential.
+@interface ASCAppleIDCredential : NSObject <ASCCredentialProtocol>
+
+- (instancetype)init NS_UNAVAILABLE;
++ (instancetype)new NS_UNAVAILABLE;
+
+- (instancetype)initWithUser:(NSString *)user identityToken:(NSData *)identityToken;
+
+@property (nonatomic, readonly, copy) NSString *user;
+@property (nonatomic, readonly, copy, nullable) NSData *identityToken;
+
+@end
+
 NS_ASSUME_NONNULL_END
 
 #endif // USE(APPLE_INTERNAL_SDK)

Modified: trunk/Source/WebKit/Platform/spi/Cocoa/LocalAuthenticationSPI.h (270693 => 270694)


--- trunk/Source/WebKit/Platform/spi/Cocoa/LocalAuthenticationSPI.h	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/Platform/spi/Cocoa/LocalAuthenticationSPI.h	2020-12-11 19:46:49 UTC (rev 270694)
@@ -32,6 +32,7 @@
 #else
 
 typedef NS_ENUM(NSInteger, LAOption) {
+    LAOptionNotInteractive,
     LAOptionAuthenticationTitle,
     LAOptionPasscodeTitle,
     LAOptionFallbackVisible,

Modified: trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebAuthn.sb (270693 => 270694)


--- trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebAuthn.sb	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebAuthn.sb	2020-12-11 19:46:49 UTC (rev 270694)
@@ -645,3 +645,17 @@
 ;; Allow accesses to the Springboard view services.
 (allow mach-lookup
     (global-name "com.apple.frontboard.systemappservices"))
+
+;; Allow accesses to the Keychain service
+(allow mach-lookup
+    (global-name "com.apple.securityd"))
+
+(allow file-read* file-write* (home-subpath "/Library/Keychains")) ;; FIXME: This should be removed when <rdar://problem/10479685> is fixed.
+
+(allow file-read*
+       (subpath "/Library/Keychains")
+       (home-literal "/Library/Application Support/SyncServices/Local/ClientsWithChanges/com.apple.Keychain"))
+
+;; Allow accesses to the SEP
+(allow mach-lookup
+    (global-name "com.apple.ctkd.token-client"))

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Authenticator.h (270693 => 270694)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/Authenticator.h	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Authenticator.h	2020-12-11 19:46:49 UTC (rev 270694)
@@ -57,6 +57,7 @@
         virtual void requestPin(uint64_t retries, CompletionHandler<void(const WTF::String&)>&&) = 0;
         virtual void selectAssertionResponse(Vector<Ref<WebCore::AuthenticatorAssertionResponse>>&&, WebAuthenticationSource, CompletionHandler<void(WebCore::AuthenticatorAssertionResponse*)>&&) = 0;
         virtual void decidePolicyForLocalAuthenticator(CompletionHandler<void(LocalAuthenticatorPolicy)>&&) = 0;
+        virtual void requestLAContextForUserVerification(CompletionHandler<void(LAContext *)>&&) = 0;
         virtual void cancelRequest() = 0;
     };
 
@@ -67,11 +68,14 @@
     // This operation is guaranteed to execute asynchronously.
     void handleRequest(const WebAuthenticationRequestData&);
 
+    void setWebAuthenticationModernEnabled(bool webAuthenticationModernEnabled) { m_webAuthenticationModernEnabled = webAuthenticationModernEnabled; }
+
 protected:
     Authenticator() = default;
 
     Observer* observer() const { return m_observer.get(); }
     const WebAuthenticationRequestData& requestData() const { return m_pendingRequestData; }
+    bool webAuthenticationModernEnabled() const { return m_webAuthenticationModernEnabled; }
 
     void receiveRespond(Respond&&) const;
 
@@ -81,6 +85,7 @@
 
     WeakPtr<Observer> m_observer;
     WebAuthenticationRequestData m_pendingRequestData;
+    bool m_webAuthenticationModernEnabled { false };
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.cpp (270693 => 270694)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.cpp	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.cpp	2020-12-11 19:46:49 UTC (rev 270694)
@@ -165,10 +165,10 @@
     // 2. Ask clients to show appropriate UI if any and then start the request.
     initTimeOutTimer();
 
-    // FIXME<rdar://problem/70822834>: The m_isWebAuthenticationModernEnabled is used to determine
+    // FIXME<rdar://problem/70822834>: The m_webAuthenticationModernEnabled is used to determine
     // whether or not we are in the UIProcess.
     // If so, continue to the old route. Otherwise, use the modern WebAuthn process way.
-    if (!m_isWebAuthenticationModernEnabled) {
+    if (!m_webAuthenticationModernEnabled) {
         runPanel();
         return;
     }
@@ -209,7 +209,7 @@
 
 void AuthenticatorManager::enableModernWebAuthentication()
 {
-    m_isWebAuthenticationModernEnabled = true;
+    m_webAuthenticationModernEnabled = true;
 }
 
 void AuthenticatorManager::clearStateAsync()
@@ -236,6 +236,7 @@
     ASSERT(RunLoop::isMain());
     authenticator->setObserver(*this);
     authenticator->handleRequest(m_pendingRequestData);
+    authenticator->setWebAuthenticationModernEnabled(m_webAuthenticationModernEnabled);
     auto addResult = m_authenticators.add(WTFMove(authenticator));
     ASSERT_UNUSED(addResult, addResult.isNewEntry);
 }
@@ -351,6 +352,16 @@
     });
 }
 
+void AuthenticatorManager::requestLAContextForUserVerification(CompletionHandler<void(LAContext *)>&& completionHandler)
+{
+    if (!m_presenter) {
+        completionHandler(nullptr);
+        return;
+    }
+
+    m_presenter->requestLAContextForUserVerification(WTFMove(completionHandler));
+}
+
 void AuthenticatorManager::cancelRequest()
 {
     invokePendingCompletionHandler(ExceptionData { NotAllowedError, "This request has been cancelled by the user."_s });
@@ -442,11 +453,13 @@
 
 void AuthenticatorManager::invokePendingCompletionHandler(Respond&& respond)
 {
+    auto result = WTF::holds_alternative<Ref<AuthenticatorResponse>>(respond) ? WebAuthenticationResult::Succeeded : WebAuthenticationResult::Failed;
+
     // This is for the new UI.
     if (m_presenter)
-        m_presenter->dimissPresenter();
+        m_presenter->dimissPresenter(result);
     else {
-        dispatchPanelClientCall([result = WTF::holds_alternative<Ref<AuthenticatorResponse>>(respond) ? WebAuthenticationResult::Succeeded : WebAuthenticationResult::Failed] (const API::WebAuthenticationPanel& panel) {
+        dispatchPanelClientCall([result] (const API::WebAuthenticationPanel& panel) {
             panel.client().dismissPanel(result);
         });
     }

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.h (270693 => 270694)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.h	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.h	2020-12-11 19:46:49 UTC (rev 270694)
@@ -39,6 +39,8 @@
 #include <wtf/RunLoop.h>
 #include <wtf/Vector.h>
 
+OBJC_CLASS LAContext;
+
 namespace API {
 class WebAuthenticationPanel;
 }
@@ -88,6 +90,7 @@
     void requestPin(uint64_t retries, CompletionHandler<void(const WTF::String&)>&&) final;
     void selectAssertionResponse(Vector<Ref<WebCore::AuthenticatorAssertionResponse>>&&, WebAuthenticationSource, CompletionHandler<void(WebCore::AuthenticatorAssertionResponse*)>&&) final;
     void decidePolicyForLocalAuthenticator(CompletionHandler<void(LocalAuthenticatorPolicy)>&&) final;
+    void requestLAContextForUserVerification(CompletionHandler<void(LAContext *)>&&) final;
     void cancelRequest() final;
 
     // Overriden by MockAuthenticatorManager.
@@ -114,7 +117,7 @@
     Vector<UniqueRef<AuthenticatorTransportService>> m_services;
     HashSet<Ref<Authenticator>> m_authenticators;
 
-    bool m_isWebAuthenticationModernEnabled { false };
+    bool m_webAuthenticationModernEnabled { false };
 };
 
 } // namespace WebKit

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


--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.h	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.h	2020-12-11 19:46:49 UTC (rev 270694)
@@ -36,5 +36,6 @@
 SOFT_LINK_CLASS_FOR_HEADER(WebKit, ASCAuthorizationPresentationContext);
 SOFT_LINK_CLASS_FOR_HEADER(WebKit, ASCPlatformPublicKeyCredentialLoginChoice);
 SOFT_LINK_CLASS_FOR_HEADER(WebKit, ASCSecurityKeyPublicKeyCredentialLoginChoice);
+SOFT_LINK_CLASS_FOR_HEADER(WebKit, ASCAppleIDCredential);
 
 #endif // HAVE(ASC_AUTH_UI)

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


--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.mm	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticationServicesCoreSoftLink.mm	2020-12-11 19:46:49 UTC (rev 270694)
@@ -36,5 +36,6 @@
 SOFT_LINK_CLASS_FOR_SOURCE(WebKit, AuthenticationServicesCore, ASCAuthorizationPresentationContext);
 SOFT_LINK_CLASS_FOR_SOURCE(WebKit, AuthenticationServicesCore, ASCPlatformPublicKeyCredentialLoginChoice);
 SOFT_LINK_CLASS_FOR_SOURCE(WebKit, AuthenticationServicesCore, ASCSecurityKeyPublicKeyCredentialLoginChoice);
+SOFT_LINK_CLASS_FOR_SOURCE(WebKit, AuthenticationServicesCore, ASCAppleIDCredential);
 
 #endif // HAVE(ASC_AUTH_UI)

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


--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h	2020-12-11 19:46:49 UTC (rev 270694)
@@ -35,6 +35,7 @@
 #include <wtf/WeakPtr.h>
 
 OBJC_CLASS ASCAuthorizationPresenter;
+OBJC_CLASS LAContext;
 OBJC_CLASS WKASCAuthorizationPresenterDelegate;
 
 namespace WebCore {
@@ -50,6 +51,7 @@
     WTF_MAKE_NONCOPYABLE(AuthenticatorPresenterCoordinator);
 public:
     using TransportSet = HashSet<WebCore::AuthenticatorTransport, WTF::IntHash<WebCore::AuthenticatorTransport>, WTF::StrongEnumHashTraits<WebCore::AuthenticatorTransport>>;
+    using CredentialRequestHandler = Function<void()>;
 
     AuthenticatorPresenterCoordinator(const AuthenticatorManager&, const String& rpId, const TransportSet&, WebCore::ClientDataType);
 
@@ -56,12 +58,21 @@
     void updatePresenter(WebAuthenticationStatus);
     void requestPin(uint64_t retries, CompletionHandler<void(const String&)>&&);
     void selectAssertionResponse(Vector<Ref<WebCore::AuthenticatorAssertionResponse>>&&, WebAuthenticationSource, CompletionHandler<void(WebCore::AuthenticatorAssertionResponse*)>&&);
-    void dimissPresenter();
+    void requestLAContextForUserVerification(CompletionHandler<void(LAContext *)>&&);
+    void dimissPresenter(WebAuthenticationResult);
 
+    void setCredentialRequestHandler(CredentialRequestHandler&& handler) { m_credentialRequestHandler = WTFMove(handler); }
+    void setLAContext(LAContext *);
+
 private:
     WeakPtr<AuthenticatorManager> m_manager;
     RetainPtr<ASCAuthorizationPresenter> m_presenter;
     RetainPtr<WKASCAuthorizationPresenterDelegate> m_presenterDelegate;
+
+    CredentialRequestHandler m_credentialRequestHandler;
+
+    CompletionHandler<void(LAContext *)> m_laContextHandler;
+    RetainPtr<LAContext> m_laContext;
 };
 
 } // namespace WebKit

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


--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm	2020-12-11 19:46:49 UTC (rev 270694)
@@ -64,8 +64,9 @@
     m_presenter = [allocASCAuthorizationPresenterInstance() init];
     [m_presenter setDelegate:m_presenterDelegate.get()];
 
-    auto completionHandler = makeBlockPtr([manager = m_manager] (id<ASCCredentialProtocol>, NSError *error) mutable {
-        if (!error)
+    auto completionHandler = makeBlockPtr([manager = m_manager] (id<ASCCredentialProtocol> credential, NSError *error) mutable {
+        ASSERT(!RunLoop::isMain());
+        if (credential || !error)
             return;
 
         LOG_ERROR("Couldn't complete the authenticator presentation context: %@", error);
@@ -95,11 +96,35 @@
     // FIXME(219711): Adopt new UI for the Security Key getAssertion flow.
 }
 
-void AuthenticatorPresenterCoordinator::dimissPresenter()
+void AuthenticatorPresenterCoordinator::requestLAContextForUserVerification(CompletionHandler<void(LAContext *)>&& completionHandler)
 {
+    if (m_laContext) {
+        completionHandler(m_laContext.get());
+        return;
+    }
+
+    m_laContextHandler = WTFMove(completionHandler);
+}
+
+void AuthenticatorPresenterCoordinator::dimissPresenter(WebAuthenticationResult result)
+{
+    if (result == WebAuthenticationResult::Succeeded && m_credentialRequestHandler) {
+        m_credentialRequestHandler();
+        return;
+    }
     // FIXME(219716): Adopt new UI for the dismiss flow.
 }
 
+void AuthenticatorPresenterCoordinator::setLAContext(LAContext *context)
+{
+    if (m_laContextHandler) {
+        m_laContextHandler(context);
+        return;
+    }
+
+    m_laContext = context;
+}
+
 } // namespace WebKit
 
 #endif // ENABLE(WEB_AUTHN)

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.h (270693 => 270694)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.h	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.h	2020-12-11 19:46:49 UTC (rev 270694)
@@ -61,6 +61,7 @@
 
     void makeCredential() final;
     void continueMakeCredentialAfterDecidePolicy(LocalAuthenticatorPolicy);
+    void continueMakeCredentialAfterReceivingLAContext(LAContext *);
     void continueMakeCredentialAfterUserVerification(SecAccessControlRef, LocalConnection::UserVerification, LAContext *);
     void continueMakeCredentialAfterAttested(Vector<uint8_t>&& credentialId, Vector<uint8_t>&& authData, NSArray *certificates, NSError *);
 

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm (270693 => 270694)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm	2020-12-11 19:46:49 UTC (rev 270694)
@@ -234,6 +234,21 @@
 
     // Step 6.
     // Get user consent.
+    if (webAuthenticationModernEnabled()) {
+        if (auto* observer = this->observer()) {
+            auto callback = [weakThis = makeWeakPtr(*this)] (LAContext *context) {
+                ASSERT(RunLoop::isMain());
+                if (!weakThis)
+                    return;
+
+                weakThis->continueMakeCredentialAfterReceivingLAContext(context);
+            };
+            observer->requestLAContextForUserVerification(WTFMove(callback));
+        }
+
+        return;
+    }
+
     if (auto* observer = this->observer()) {
         auto callback = [weakThis = makeWeakPtr(*this)] (LocalAuthenticatorPolicy policy) {
             ASSERT(RunLoop::isMain());
@@ -280,6 +295,33 @@
     m_connection->verifyUser(creationOptions.rp.id, getClientDataType(requestData().options), accessControlRef, WTFMove(callback));
 }
 
+void LocalAuthenticator::continueMakeCredentialAfterReceivingLAContext(LAContext *context)
+{
+    ASSERT(m_state == State::RequestReceived);
+    m_state = State::PolicyDecided;
+
+    RetainPtr<SecAccessControlRef> accessControl;
+    {
+        CFErrorRef errorRef = nullptr;
+        accessControl = adoptCF(SecAccessControlCreateWithFlags(NULL, kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly, kSecAccessControlPrivateKeyUsage | kSecAccessControlUserPresence, &errorRef));
+        auto retainError = adoptCF(errorRef);
+        if (errorRef) {
+            receiveException({ UnknownError, makeString("Couldn't create access control: ", String(((NSError*)errorRef).localizedDescription)) });
+            return;
+        }
+    }
+
+    SecAccessControlRef accessControlRef = accessControl.get();
+    auto callback = [accessControl = WTFMove(accessControl), context = retainPtr(context), weakThis = makeWeakPtr(*this)] (LocalConnection::UserVerification verification) {
+        ASSERT(RunLoop::isMain());
+        if (!weakThis)
+            return;
+
+        weakThis->continueMakeCredentialAfterUserVerification(accessControl.get(), verification, context.get());
+    };
+    m_connection->verifyUser(accessControlRef, context, WTFMove(callback));
+}
+
 void LocalAuthenticator::continueMakeCredentialAfterUserVerification(SecAccessControlRef accessControlRef, LocalConnection::UserVerification verification, LAContext *context)
 {
     using namespace LocalAuthenticatorInternal;

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalConnection.h (270693 => 270694)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalConnection.h	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalConnection.h	2020-12-11 19:46:49 UTC (rev 270694)
@@ -65,6 +65,7 @@
 
     // Overrided by MockLocalConnection.
     virtual void verifyUser(const String& rpId, WebCore::ClientDataType, SecAccessControlRef, UserVerificationCallback&&);
+    virtual void verifyUser(SecAccessControlRef, LAContext *, CompletionHandler<void(UserVerification)>&&);
     virtual RetainPtr<SecKeyRef> createCredentialPrivateKey(LAContext *, SecAccessControlRef, const String& secAttrLabel, NSData *secAttrApplicationTag) const;
     virtual void getAttestation(SecKeyRef, NSData *authData, NSData *hash, AttestationCallback&&) const;
     virtual void filterResponses(Vector<Ref<WebCore::AuthenticatorAssertionResponse>>&) const { };

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalConnection.mm (270693 => 270694)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalConnection.mm	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalConnection.mm	2020-12-11 19:46:49 UTC (rev 270694)
@@ -96,6 +96,29 @@
     [m_context evaluateAccessControl:accessControl operation:LAAccessControlOperationUseKeySign options:options.get() reply:reply.get()];
 }
 
+void LocalConnection::verifyUser(SecAccessControlRef accessControl, LAContext *context, CompletionHandler<void(UserVerification)>&& completionHandler)
+{
+    auto options = adoptNS([[NSMutableDictionary alloc] init]);
+    [options setObject:@YES forKey:@(LAOptionNotInteractive)];
+
+    auto reply = makeBlockPtr([completionHandler = WTFMove(completionHandler)] (NSDictionary *, NSError *error) mutable {
+        UserVerification verification = UserVerification::Yes;
+        if (error) {
+            LOG_ERROR("Couldn't authenticate with biometrics: %@", error);
+            verification = UserVerification::No;
+            if (error.code == LAErrorUserCancel)
+                verification = UserVerification::Cancel;
+        }
+
+        // This block can be executed in another thread.
+        RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler), verification] () mutable {
+            completionHandler(verification);
+        });
+    });
+
+    [context evaluateAccessControl:accessControl operation:LAAccessControlOperationUseKeySign options:options.get() reply:reply.get()];
+}
+
 RetainPtr<SecKeyRef> LocalConnection::createCredentialPrivateKey(LAContext *context, SecAccessControlRef accessControlRef, const String& secAttrLabel, NSData *secAttrApplicationTag) const
 {
     NSDictionary *attributes = @{

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/WKASCAuthorizationPresenterDelegate.mm (270693 => 270694)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/WKASCAuthorizationPresenterDelegate.mm	2020-12-11 19:37:51 UTC (rev 270693)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/WKASCAuthorizationPresenterDelegate.mm	2020-12-11 19:46:49 UTC (rev 270694)
@@ -30,6 +30,8 @@
 
 #import "AuthenticatorPresenterCoordinator.h"
 
+#import "AuthenticationServicesCoreSoftLink.h"
+
 NS_ASSUME_NONNULL_BEGIN
 
 @implementation WKASCAuthorizationPresenterDelegate {
@@ -45,7 +47,24 @@
 
 - (void)authorizationPresenter:(ASCAuthorizationPresenter *)presenter credentialRequestedForLoginChoice:(id <ASCLoginChoiceProtocol>)loginChoice authenticatedContext:(nullable LAContext *)context completionHandler:(void (^)(id <ASCCredentialProtocol> _Nullable credential, NSError * _Nullable error))completionHandler
 {
-    // FIXME(219709): Adopt new UI for the Platform Authenticator makeCredential flow.
+    auto requestHandler = [completionHandler = makeBlockPtr(completionHandler)] {
+        // FIXME(219767): Replace the ASCAppleIDCredential with the upcoming WebAuthn credentials one.
+        // This is just a place holder to tell the UI that the ceremony succeeds.
+        completionHandler(adoptNS([WebKit::allocASCAppleIDCredentialInstance() initWithUser:@"" identityToken:adoptNS([[NSData alloc] init]).get()]).get(), nil);
+    };
+    [self dispatchCoordinatorCallback:[requestHandler = WTFMove(requestHandler)] (WebKit::AuthenticatorPresenterCoordinator& coordinator) mutable {
+        coordinator.setCredentialRequestHandler(WTFMove(requestHandler));
+    }];
+
+    if ([loginChoice isKindOfClass:WebKit::getASCPlatformPublicKeyCredentialLoginChoiceClass()]) {
+        if ([(ASCPlatformPublicKeyCredentialLoginChoice *)loginChoice isRegistrationRequest]) {
+            [self dispatchCoordinatorCallback:[context = retainPtr(context)] (WebKit::AuthenticatorPresenterCoordinator& coordinator) mutable {
+                coordinator.setLAContext(context.get());
+            }];
+
+            return;
+        }
+    }
 }
 
 - (void)authorizationPresenter:(ASCAuthorizationPresenter *)presenter validateUserEnteredPIN:(NSString *)pin completionHandler:(void (^)(id <ASCCredentialProtocol> credential, NSError *error))completionHandler
@@ -53,6 +72,16 @@
     // FIXME(219712): Adopt new UI for the Client PIN flow.
 }
 
+- (void)dispatchCoordinatorCallback:(Function<void(WebKit::AuthenticatorPresenterCoordinator&)>&&)callback
+{
+    ASSERT(!RunLoop::isMain());
+    RunLoop::main().dispatch([coordinator = _coordinator, callback = WTFMove(callback)] {
+        if (!coordinator)
+            return;
+        callback(*coordinator);
+    });
+}
+
 @end
 
 NS_ASSUME_NONNULL_END
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to