Changeset 270724 in webkit


Ignore:
Timestamp:
Dec 11, 2020 6:03:32 PM (3 years ago)
Author:
jiewen_tan@apple.com
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.

Location:
trunk/Source/WebKit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r270723 r270724  
     12020-12-11  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        [WebAuthn] Adopt new UI for the Security Key getAssertion flow
     4        https://bugs.webkit.org/show_bug.cgi?id=219711
     5        <rdar://problem/72154840>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        This patch adopts the new UI for the security key getAssertion flow which contains two part:
     10        1. showing a informative UI to ask the user to connect their security keys,
     11        2. showing an account picker for users to select a credential to use.
     12
     13        Covered by manual tests.
     14
     15        * Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h:
     16        Paperwork.
     17
     18        * UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h:
     19        * UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm:
     20        (WebKit::AuthenticatorPresenterCoordinator::AuthenticatorPresenterCoordinator):
     21        (WebKit::AuthenticatorPresenterCoordinator::selectAssertionResponse):
     22        (WebKit::AuthenticatorPresenterCoordinator::didSelectAssertionResponse):
     23        * UIProcess/WebAuthentication/Cocoa/WKASCAuthorizationPresenterDelegate.mm:
     24        (-[WKASCAuthorizationPresenterDelegate authorizationPresenter:credentialRequestedForLoginChoice:authenticatedContext:completionHandler:]):
     25        Implements the two flows.
     26
    1272020-12-11  John Wilander  <wilander@apple.com>
    228
  • trunk/Source/WebKit/Platform/spi/Cocoa/AuthenticationServicesCoreSPI.h

    r270694 r270724  
    7070
    7171- (void)presentAuthorizationWithContext:(ASCAuthorizationPresentationContext *)context completionHandler:(void (^)(id<ASCCredentialProtocol> _Nullable, NSError * _Nullable))completionHandler;
     72- (void)updateInterfaceWithLoginChoices:(NSArray<id <ASCLoginChoiceProtocol>> *)loginChoices;
    7273
    7374@property (nonatomic, weak) id <ASCAuthorizationPresenterDelegate> delegate;
     
    9091@property (nonatomic, readonly, copy) NSString *appIdentifier;
    9192@property (nonatomic, readonly, copy) NSArray<id<ASCLoginChoiceProtocol>> *loginChoices;
    92 @property (nonatomic, nullable, copy) NSString *relyingPartyIdentifier;
     93@property (nonatomic, nullable, copy) NSString *serviceName;
    9394
    9495@property (nonatomic, copy) NSString *proxiedAppName;
     
    103104@end
    104105
     106typedef NS_ENUM(NSInteger, ASCSecurityKeyPublicKeyCredentialLoginChoiceKind) {
     107    ASCSecurityKeyPublicKeyCredentialLoginChoiceKindRegistration,
     108    ASCSecurityKeyPublicKeyCredentialLoginChoiceKindAssertion,
     109    ASCSecurityKeyPublicKeyCredentialLoginChoiceKindAssertionPlaceholder,
     110};
     111
    105112@interface ASCSecurityKeyPublicKeyCredentialLoginChoice : NSObject <ASCLoginChoiceProtocol>
    106113
    107114- (instancetype)initRegistrationChoice;
    108115- (instancetype)initWithName:(NSString *)name displayName:(NSString *)displayName userHandle:(NSData *)userHandle;
     116- (instancetype)initAssertionPlaceholderChoice;
    109117
    110 @property (nonatomic, readonly, copy) NSString *name;
    111 @property (nonatomic, readonly, copy) NSString *displayName;
    112 @property (nonatomic, readonly, copy) NSData *userHandle;
    113 @property (nonatomic, readonly) BOOL isRegistrationRequest;
     118@property (nonatomic, nullable, readonly, copy) NSString *name;
     119@property (nonatomic, nullable, readonly, copy) NSString *displayName;
     120@property (nonatomic, nullable, readonly, copy) NSData *userHandle;
     121@property (nonatomic, readonly) ASCSecurityKeyPublicKeyCredentialLoginChoiceKind loginChoiceKind;
    114122
    115123+ (instancetype)new NS_UNAVAILABLE;
  • trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.h

    r270694 r270724  
    2929
    3030#include "WebAuthenticationFlags.h"
     31#include <WebCore/AuthenticatorAssertionResponse.h>
    3132#include <WebCore/AuthenticatorTransport.h>
    3233#include <WebCore/WebAuthenticationConstants.h>
     
    3637
    3738OBJC_CLASS ASCAuthorizationPresenter;
     39OBJC_CLASS ASCLoginChoiceProtocol;
    3840OBJC_CLASS LAContext;
    3941OBJC_CLASS WKASCAuthorizationPresenterDelegate;
     
    6567    void setLAContext(LAContext *);
    6668
     69    void didSelectAssertionResponse(ASCLoginChoiceProtocol *);
     70
    6771private:
    6872    WeakPtr<AuthenticatorManager> m_manager;
     
    7478    CompletionHandler<void(LAContext *)> m_laContextHandler;
    7579    RetainPtr<LAContext> m_laContext;
     80
     81    CompletionHandler<void(WebCore::AuthenticatorAssertionResponse*)> m_responseHandler;
     82    HashMap<ASCLoginChoiceProtocol *, RefPtr<WebCore::AuthenticatorAssertionResponse>> m_credentials;
    7683};
    7784
  • trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/AuthenticatorPresenterCoordinator.mm

    r270721 r270724  
    3131#import "AuthenticatorManager.h"
    3232#import "WKASCAuthorizationPresenterDelegate.h"
    33 #import <WebCore/NotImplemented.h>
    3433#import <wtf/BlockPtr.h>
    3534
     
    5554        break;
    5655    case ClientDataType::Get:
    57         // FIXME(219710): Adopt new UI for the Platform Authenticator getAssertion flow.
    58         // FIXME(219711): Adopt new UI for the Security Key getAssertion flow.
     56        if (transports.contains(AuthenticatorTransport::Usb) || transports.contains(AuthenticatorTransport::Nfc))
     57            [presentationContext addLoginChoice:adoptNS([allocASCSecurityKeyPublicKeyCredentialLoginChoiceInstance() initAssertionPlaceholderChoice]).get()];
    5958        break;
    6059    default:
     
    9291}
    9392
    94 void AuthenticatorPresenterCoordinator::selectAssertionResponse(Vector<Ref<AuthenticatorAssertionResponse>>&&, WebAuthenticationSource, CompletionHandler<void(AuthenticatorAssertionResponse*)>&&)
     93void AuthenticatorPresenterCoordinator::selectAssertionResponse(Vector<Ref<AuthenticatorAssertionResponse>>&& responses, WebAuthenticationSource source, CompletionHandler<void(AuthenticatorAssertionResponse*)>&& completionHandler)
    9594{
     95#if HAVE(ASC_AUTH_UI)
     96    if (m_responseHandler)
     97        m_responseHandler(nullptr);
     98    m_responseHandler = WTFMove(completionHandler);
     99
     100    if (source == WebAuthenticationSource::External) {
     101        auto loginChoices = adoptNS([[NSMutableArray alloc] init]);
     102
     103        for (auto& response : responses) {
     104            RetainPtr<NSData> userHandle;
     105            if (response->userHandle())
     106                userHandle = adoptNS([[NSData alloc] initWithBytes:response->userHandle()->data() length:response->userHandle()->byteLength()]);
     107
     108            auto loginChoice = adoptNS([allocASCSecurityKeyPublicKeyCredentialLoginChoiceInstance() initWithName:response->name() displayName:response->displayName() userHandle:userHandle.get()]);
     109            [loginChoices addObject:loginChoice.get()];
     110
     111            m_credentials.add((ASCLoginChoiceProtocol *)loginChoice.get(), WTFMove(response));
     112        }
     113
     114        [m_presenter updateInterfaceWithLoginChoices:loginChoices.get()];
     115        return;
     116    }
    96117    // FIXME(219710): Adopt new UI for the Platform Authenticator getAssertion flow.
    97     // FIXME(219711): Adopt new UI for the Security Key getAssertion flow.
     118#endif // HAVE(ASC_AUTH_UI)
    98119}
    99120
     
    127148}
    128149
     150void AuthenticatorPresenterCoordinator::didSelectAssertionResponse(ASCLoginChoiceProtocol *loginChoice)
     151{
     152    auto response = m_credentials.take(loginChoice);
     153    if (!response)
     154        return;
     155
     156    m_responseHandler(response.get());
     157}
     158
    129159} // namespace WebKit
    130160
  • trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/WKASCAuthorizationPresenterDelegate.mm

    r270694 r270724  
    6666        }
    6767    }
     68
     69    if ([loginChoice isKindOfClass:WebKit::getASCSecurityKeyPublicKeyCredentialLoginChoiceClass()]) {
     70        if ([(ASCSecurityKeyPublicKeyCredentialLoginChoice *)loginChoice loginChoiceKind] == ASCSecurityKeyPublicKeyCredentialLoginChoiceKindAssertion) {
     71            [self dispatchCoordinatorCallback:[loginChoice] (WebKit::AuthenticatorPresenterCoordinator& coordinator) mutable {
     72                coordinator.didSelectAssertionResponse((ASCLoginChoiceProtocol *)loginChoice);
     73            }];
     74
     75            return;
     76        }
     77    }
    6878}
    6979
Note: See TracChangeset for help on using the changeset viewer.