- Revision
- 270724
- Author
- [email protected]
- Date
- 2020-12-11 18:03:32 -0800 (Fri, 11 Dec 2020)
Log Message
[WebAuthn] Adopt new UI for the Security Key getAssertion flow
https://bugs.webkit.org/show_bug.cgi?id=219711
<rdar://problem/72154840>
Reviewed by Brent Fulgham.
This patch adopts the new UI for the security key getAssertion flow which contains two part:
1. showing a informative UI to ask the user to connect their security keys,
2. showing an account picker for users to select a credential to use.
Covered by manual tests.
* Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h:
Paperwork.
* UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h:
* UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm:
(WebKit::AuthenticatorPresenterCoordinator::AuthenticatorPresenterCoordinator):
(WebKit::AuthenticatorPresenterCoordinator::selectAssertionResponse):
(WebKit::AuthenticatorPresenterCoordinator::didSelectAssertionResponse):
* UIProcess/WebAuthentication/Cocoa/WKASCAuthorizationPresenterDelegate.mm:
(-[WKASCAuthorizationPresenterDelegate authorizationPresenter:credentialRequestedForLoginChoice:authenticatedContext:completionHandler:]):
Implements the two flows.
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (270723 => 270724)
--- trunk/Source/WebKit/ChangeLog 2020-12-12 01:34:33 UTC (rev 270723)
+++ trunk/Source/WebKit/ChangeLog 2020-12-12 02:03:32 UTC (rev 270724)
@@ -1,3 +1,29 @@
+2020-12-11 Jiewen Tan <[email protected]>
+
+ [WebAuthn] Adopt new UI for the Security Key getAssertion flow
+ https://bugs.webkit.org/show_bug.cgi?id=219711
+ <rdar://problem/72154840>
+
+ Reviewed by Brent Fulgham.
+
+ This patch adopts the new UI for the security key getAssertion flow which contains two part:
+ 1. showing a informative UI to ask the user to connect their security keys,
+ 2. showing an account picker for users to select a credential to use.
+
+ Covered by manual tests.
+
+ * Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h:
+ Paperwork.
+
+ * UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h:
+ * UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm:
+ (WebKit::AuthenticatorPresenterCoordinator::AuthenticatorPresenterCoordinator):
+ (WebKit::AuthenticatorPresenterCoordinator::selectAssertionResponse):
+ (WebKit::AuthenticatorPresenterCoordinator::didSelectAssertionResponse):
+ * UIProcess/WebAuthentication/Cocoa/WKASCAuthorizationPresenterDelegate.mm:
+ (-[WKASCAuthorizationPresenterDelegate authorizationPresenter:credentialRequestedForLoginChoice:authenticatedContext:completionHandler:]):
+ Implements the two flows.
+
2020-12-11 John Wilander <[email protected]>
PCM: Add feature flag support in the network process
Modified: trunk/Source/WebKit/Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h (270723 => 270724)
--- trunk/Source/WebKit/Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h 2020-12-12 01:34:33 UTC (rev 270723)
+++ trunk/Source/WebKit/Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h 2020-12-12 02:03:32 UTC (rev 270724)
@@ -69,6 +69,7 @@
@interface ASCAuthorizationPresenter : NSObject <ASCAuthorizationPresenterHostProtocol>
- (void)presentAuthorizationWithContext:(ASCAuthorizationPresentationContext *)context completionHandler:(void (^)(id<ASCCredentialProtocol> _Nullable, NSError * _Nullable))completionHandler;
+- (void)updateInterfaceWithLoginChoices:(NSArray<id <ASCLoginChoiceProtocol>> *)loginChoices;
@property (nonatomic, weak) id <ASCAuthorizationPresenterDelegate> delegate;
@@ -89,7 +90,7 @@
@property (nonatomic, readonly, copy) NSString *appIdentifier;
@property (nonatomic, readonly, copy) NSArray<id<ASCLoginChoiceProtocol>> *loginChoices;
-@property (nonatomic, nullable, copy) NSString *relyingPartyIdentifier;
+@property (nonatomic, nullable, copy) NSString *serviceName;
@property (nonatomic, copy) NSString *proxiedAppName;
@property (nonatomic, copy) NSArray<NSString *> *proxiedAssociatedDomains;
@@ -102,15 +103,22 @@
@end
+typedef NS_ENUM(NSInteger, ASCSecurityKeyPublicKeyCredentialLoginChoiceKind) {
+ ASCSecurityKeyPublicKeyCredentialLoginChoiceKindRegistration,
+ ASCSecurityKeyPublicKeyCredentialLoginChoiceKindAssertion,
+ ASCSecurityKeyPublicKeyCredentialLoginChoiceKindAssertionPlaceholder,
+};
+
@interface ASCSecurityKeyPublicKeyCredentialLoginChoice : NSObject <ASCLoginChoiceProtocol>
- (instancetype)initRegistrationChoice;
- (instancetype)initWithName:(NSString *)name displayName:(NSString *)displayName userHandle:(NSData *)userHandle;
+- (instancetype)initAssertionPlaceholderChoice;
-@property (nonatomic, readonly, copy) NSString *name;
-@property (nonatomic, readonly, copy) NSString *displayName;
-@property (nonatomic, readonly, copy) NSData *userHandle;
-@property (nonatomic, readonly) BOOL isRegistrationRequest;
+@property (nonatomic, nullable, readonly, copy) NSString *name;
+@property (nonatomic, nullable, readonly, copy) NSString *displayName;
+@property (nonatomic, nullable, readonly, copy) NSData *userHandle;
+@property (nonatomic, readonly) ASCSecurityKeyPublicKeyCredentialLoginChoiceKind loginChoiceKind;
+ (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h (270723 => 270724)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h 2020-12-12 01:34:33 UTC (rev 270723)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h 2020-12-12 02:03:32 UTC (rev 270724)
@@ -28,6 +28,7 @@
#if ENABLE(WEB_AUTHN)
#include "WebAuthenticationFlags.h"
+#include <WebCore/AuthenticatorAssertionResponse.h>
#include <WebCore/AuthenticatorTransport.h>
#include <WebCore/WebAuthenticationConstants.h>
#include <wtf/Forward.h>
@@ -35,6 +36,7 @@
#include <wtf/WeakPtr.h>
OBJC_CLASS ASCAuthorizationPresenter;
+OBJC_CLASS ASCLoginChoiceProtocol;
OBJC_CLASS LAContext;
OBJC_CLASS WKASCAuthorizationPresenterDelegate;
@@ -64,6 +66,8 @@
void setCredentialRequestHandler(CredentialRequestHandler&& handler) { m_credentialRequestHandler = WTFMove(handler); }
void setLAContext(LAContext *);
+ void didSelectAssertionResponse(ASCLoginChoiceProtocol *);
+
private:
WeakPtr<AuthenticatorManager> m_manager;
RetainPtr<ASCAuthorizationPresenter> m_presenter;
@@ -73,6 +77,9 @@
CompletionHandler<void(LAContext *)> m_laContextHandler;
RetainPtr<LAContext> m_laContext;
+
+ CompletionHandler<void(WebCore::AuthenticatorAssertionResponse*)> m_responseHandler;
+ HashMap<ASCLoginChoiceProtocol *, RefPtr<WebCore::AuthenticatorAssertionResponse>> m_credentials;
};
} // namespace WebKit
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm (270723 => 270724)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm 2020-12-12 01:34:33 UTC (rev 270723)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm 2020-12-12 02:03:32 UTC (rev 270724)
@@ -30,7 +30,6 @@
#import "AuthenticatorManager.h"
#import "WKASCAuthorizationPresenterDelegate.h"
-#import <WebCore/NotImplemented.h>
#import <wtf/BlockPtr.h>
#import "AuthenticationServicesCoreSoftLink.h"
@@ -54,8 +53,8 @@
[presentationContext addLoginChoice:adoptNS([allocASCSecurityKeyPublicKeyCredentialLoginChoiceInstance() initRegistrationChoice]).get()];
break;
case ClientDataType::Get:
- // FIXME(219710): Adopt new UI for the Platform Authenticator getAssertion flow.
- // FIXME(219711): Adopt new UI for the Security Key getAssertion flow.
+ if (transports.contains(AuthenticatorTransport::Usb) || transports.contains(AuthenticatorTransport::Nfc))
+ [presentationContext addLoginChoice:adoptNS([allocASCSecurityKeyPublicKeyCredentialLoginChoiceInstance() initAssertionPlaceholderChoice]).get()];
break;
default:
ASSERT_NOT_REACHED();
@@ -91,10 +90,32 @@
// FIXME(219712): Adopt new UI for the Client PIN flow.
}
-void AuthenticatorPresenterCoordinator::selectAssertionResponse(Vector<Ref<AuthenticatorAssertionResponse>>&&, WebAuthenticationSource, CompletionHandler<void(AuthenticatorAssertionResponse*)>&&)
+void AuthenticatorPresenterCoordinator::selectAssertionResponse(Vector<Ref<AuthenticatorAssertionResponse>>&& responses, WebAuthenticationSource source, CompletionHandler<void(AuthenticatorAssertionResponse*)>&& completionHandler)
{
+#if HAVE(ASC_AUTH_UI)
+ if (m_responseHandler)
+ m_responseHandler(nullptr);
+ m_responseHandler = WTFMove(completionHandler);
+
+ if (source == WebAuthenticationSource::External) {
+ auto loginChoices = adoptNS([[NSMutableArray alloc] init]);
+
+ for (auto& response : responses) {
+ RetainPtr<NSData> userHandle;
+ if (response->userHandle())
+ userHandle = adoptNS([[NSData alloc] initWithBytes:response->userHandle()->data() length:response->userHandle()->byteLength()]);
+
+ auto loginChoice = adoptNS([allocASCSecurityKeyPublicKeyCredentialLoginChoiceInstance() initWithName:response->name() displayName:response->displayName() userHandle:userHandle.get()]);
+ [loginChoices addObject:loginChoice.get()];
+
+ m_credentials.add((ASCLoginChoiceProtocol *)loginChoice.get(), WTFMove(response));
+ }
+
+ [m_presenter updateInterfaceWithLoginChoices:loginChoices.get()];
+ return;
+ }
// FIXME(219710): Adopt new UI for the Platform Authenticator getAssertion flow.
- // FIXME(219711): Adopt new UI for the Security Key getAssertion flow.
+#endif // HAVE(ASC_AUTH_UI)
}
void AuthenticatorPresenterCoordinator::requestLAContextForUserVerification(CompletionHandler<void(LAContext *)>&& completionHandler)
@@ -126,6 +147,15 @@
m_laContext = context;
}
+void AuthenticatorPresenterCoordinator::didSelectAssertionResponse(ASCLoginChoiceProtocol *loginChoice)
+{
+ auto response = m_credentials.take(loginChoice);
+ if (!response)
+ return;
+
+ m_responseHandler(response.get());
+}
+
} // namespace WebKit
#endif // ENABLE(WEB_AUTHN)
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/WKASCAuthorizationPresenterDelegate.mm (270723 => 270724)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/WKASCAuthorizationPresenterDelegate.mm 2020-12-12 01:34:33 UTC (rev 270723)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/WKASCAuthorizationPresenterDelegate.mm 2020-12-12 02:03:32 UTC (rev 270724)
@@ -65,6 +65,16 @@
return;
}
}
+
+ if ([loginChoice isKindOfClass:WebKit::getASCSecurityKeyPublicKeyCredentialLoginChoiceClass()]) {
+ if ([(ASCSecurityKeyPublicKeyCredentialLoginChoice *)loginChoice loginChoiceKind] == ASCSecurityKeyPublicKeyCredentialLoginChoiceKindAssertion) {
+ [self dispatchCoordinatorCallback:[loginChoice] (WebKit::AuthenticatorPresenterCoordinator& coordinator) mutable {
+ coordinator.didSelectAssertionResponse((ASCLoginChoiceProtocol *)loginChoice);
+ }];
+
+ return;
+ }
+ }
}
- (void)authorizationPresenter:(ASCAuthorizationPresenter *)presenter validateUserEnteredPIN:(NSString *)pin completionHandler:(void (^)(id <ASCCredentialProtocol> credential, NSError *error))completionHandler