Diff
Modified: trunk/Source/WebCore/ChangeLog (260969 => 260970)
--- trunk/Source/WebCore/ChangeLog 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebCore/ChangeLog 2020-04-30 22:27:02 UTC (rev 260970)
@@ -1,3 +1,20 @@
+2020-04-30 Jiewen Tan <[email protected]>
+
+ [WebAuthn] Optimize LocalAuthenticator
+ https://bugs.webkit.org/show_bug.cgi?id=183534
+ <rdar://problem/43357408>
+
+ Reviewed by Brent Fulgham.
+
+ Covered by new API tests.
+
+ * en.lproj/Localizable.strings:
+ * platform/LocalizedStrings.cpp:
+ (WebCore::getAssertionTouchIDPromptTitle):
+ (WebCore::genericTouchIDPromptTitle):
+ * platform/LocalizedStrings.h:
+ Improving the LocalAuthentication dialog titles for iOS.
+
2020-04-30 Kate Cheney <[email protected]>
clearApplicationBundleIdentifierTestingOverride() should set the bundle identifier to a null string, not an empty string
Modified: trunk/Source/WebCore/en.lproj/Localizable.strings (260969 => 260970)
--- trunk/Source/WebCore/en.lproj/Localizable.strings 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebCore/en.lproj/Localizable.strings 2020-04-30 22:27:02 UTC (rev 260970)
@@ -232,6 +232,9 @@
/* Continue */
"Continue" = "Continue";
+/* Continue with Touch ID */
+"Continue with Touch ID." = "Continue with Touch ID.";
+
/* Media Controls context menu item */
"Controls" = "Controls";
@@ -868,9 +871,6 @@
/* Unwanted software warning */
"This website may try to trick you into installing software that harms your browsing experience, like changing your settings without your permission or showing you unwanted ads. Once installed, it may be difficult to remove." = "This website may try to trick you into installing software that harms your browsing experience, like changing your settings without your permission or showing you unwanted ads. Once installed, it may be difficult to remove.";
-/* This website would like to use Touch ID */
-"This website would like to use Touch ID." = "This website would like to use Touch ID.";
-
/* Informative text for requesting cross-site cookie and website data access. */
"This will allow “%@” to track your activity." = "This will allow “%@” to track your activity.";
@@ -889,9 +889,6 @@
/* prompt string in authentication panel */
"To view this page, you must log in to this area on %@:" = "To view this page, you must log in to this area on %@:";
-/* Use Touch ID to sign in to this website */
-"Touch ID to sign in to this website." = "Touch ID to sign in to this website.";
-
/* Transformations context sub-menu item */
"Transformations" = "Transformations";
Modified: trunk/Source/WebCore/platform/LocalizedStrings.cpp (260969 => 260970)
--- trunk/Source/WebCore/platform/LocalizedStrings.cpp 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebCore/platform/LocalizedStrings.cpp 2020-04-30 22:27:02 UTC (rev 260970)
@@ -1210,7 +1210,6 @@
#if ENABLE(WEB_AUTHN)
// On macOS, Touch ID prompt is not guaranteed to show on top of the UI client, and therefore additional
// information is provided to help users to make decisions.
-#if PLATFORM(MAC)
String makeCredentialTouchIDPromptTitle(const String& bundleName, const String& domain)
{
return formatLocalizedString(WEB_UI_CFSTRING("“%@” would like to use Touch ID for “%@”.", "Allow the specified bundle to use Touch ID to sign in to the specified website on this device"), bundleName.createCFString().get(), domain.createCFString().get());
@@ -1220,17 +1219,11 @@
{
return formatLocalizedString(WEB_UI_CFSTRING("“%@” would like to sign in to “%@”.", "Allow the specified bundle to sign in to the specified website"), bundleName.createCFString().get(), domain.createCFString().get());
}
-#else
-String makeCredentialTouchIDPromptTitle(const String&, const String&)
-{
- return WEB_UI_STRING("This website would like to use Touch ID.", "This website would like to use Touch ID");
-}
-String getAssertionTouchIDPromptTitle(const String&, const String&)
+String genericTouchIDPromptTitle()
{
- return WEB_UI_STRING("Touch ID to sign in to this website.", "Use Touch ID to sign in to this website");
+ return WEB_UI_STRING("Continue with Touch ID.", "Continue with Touch ID.");
}
-#endif // PLATFORM(MAC)
#endif // ENABLE(WEB_AUTHN)
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/LocalizedStrings.h (260969 => 260970)
--- trunk/Source/WebCore/platform/LocalizedStrings.h 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebCore/platform/LocalizedStrings.h 2020-04-30 22:27:02 UTC (rev 260970)
@@ -342,6 +342,7 @@
#if ENABLE(WEB_AUTHN)
WEBCORE_EXPORT String makeCredentialTouchIDPromptTitle(const String& bundleName, const String& domain);
WEBCORE_EXPORT String getAssertionTouchIDPromptTitle(const String& bundleName, const String& domain);
+ WEBCORE_EXPORT String genericTouchIDPromptTitle();
#endif
#if USE(GLIB) && defined(GETTEXT_PACKAGE)
Modified: trunk/Source/WebKit/ChangeLog (260969 => 260970)
--- trunk/Source/WebKit/ChangeLog 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebKit/ChangeLog 2020-04-30 22:27:02 UTC (rev 260970)
@@ -1,3 +1,49 @@
+2020-04-30 Jiewen Tan <[email protected]>
+
+ [WebAuthn] Optimize LocalAuthenticator
+ https://bugs.webkit.org/show_bug.cgi?id=183534
+ <rdar://problem/43357408>
+
+ Reviewed by Brent Fulgham.
+
+ This patch implements the following small optimizations:
+ 1. Replacing local constants with ones from FidoConstants.h;
+ 2. Merging m_assertionResponses and m_existingCredentials by replacing HashSet with Vector in Authenticator::Observer::selectAssertionResponse;
+ 3. Using Base64 encoded strings as the keys of the HashSet in produceHashSet() instead of the old casting hack;
+ 4. Invaliding the LAContext in LocalConnection::~LocalConnection() such that any displaying LocalAuthentication dialogs can be dismissed after the object is destroyed;
+ 5. Sorting existing credentials according to LRU before returning to UI clients;
+ 6. Improving the LocalAuthentication dialog titles for iOS.
+
+ * UIProcess/WebAuthentication/Authenticator.h:
+ * UIProcess/WebAuthentication/AuthenticatorManager.cpp:
+ (WebKit::AuthenticatorManager::selectAssertionResponse):
+ * UIProcess/WebAuthentication/AuthenticatorManager.h:
+ * UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.h:
+ * UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm:
+ (WebKit::LocalAuthenticatorInternal::produceHashSet):
+ (WebKit::LocalAuthenticatorInternal::toNSData):
+ (WebKit::LocalAuthenticatorInternal::getExistingCredentials):
+ (WebKit::LocalAuthenticator::makeCredential):
+ (WebKit::LocalAuthenticator::continueMakeCredentialAfterUserVerification):
+ (WebKit::LocalAuthenticator::getAssertion):
+ (WebKit::LocalAuthenticator::continueGetAssertionAfterUserVerification):
+ * UIProcess/WebAuthentication/Cocoa/LocalConnection.h:
+ (WebKit::LocalConnection::filterResponses const):
+ * UIProcess/WebAuthentication/Cocoa/LocalConnection.mm:
+ (WebKit::WebCore::bundleName):
+ (WebKit::LocalConnection::~LocalConnection):
+ (WebKit::LocalConnection::verifyUser):
+ (WebKit::LocalConnection::verifyUser const): Deleted.
+ * UIProcess/WebAuthentication/Mock/MockLocalConnection.h:
+ * UIProcess/WebAuthentication/Mock/MockLocalConnection.mm:
+ (WebKit::MockLocalConnection::verifyUser):
+ (WebKit::MockLocalConnection::filterResponses const):
+ (WebKit::MockLocalConnection::verifyUser const): Deleted.
+ * UIProcess/WebAuthentication/fido/CtapAuthenticator.cpp:
+ (WebKit::CtapAuthenticator::continueGetAssertionAfterResponseReceived):
+ (WebKit::CtapAuthenticator::continueGetNextAssertionAfterResponseReceived):
+ * UIProcess/WebAuthentication/fido/CtapAuthenticator.h:
+
2020-04-30 Kate Cheney <[email protected]>
Change default of "inAppBrowserPrivacyQuirks" testing toggle to use it for tests only
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Authenticator.h (260969 => 260970)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Authenticator.h 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Authenticator.h 2020-04-30 22:27:02 UTC (rev 260970)
@@ -55,7 +55,7 @@
virtual void downgrade(Authenticator* id, Ref<Authenticator>&& downgradedAuthenticator) = 0;
virtual void authenticatorStatusUpdated(WebAuthenticationStatus) = 0;
virtual void requestPin(uint64_t retries, CompletionHandler<void(const WTF::String&)>&&) = 0;
- virtual void selectAssertionResponse(const HashSet<Ref<WebCore::AuthenticatorAssertionResponse>>&, WebAuthenticationSource, CompletionHandler<void(WebCore::AuthenticatorAssertionResponse*)>&&) = 0;
+ virtual void selectAssertionResponse(Vector<Ref<WebCore::AuthenticatorAssertionResponse>>&&, WebAuthenticationSource, CompletionHandler<void(WebCore::AuthenticatorAssertionResponse*)>&&) = 0;
virtual void decidePolicyForLocalAuthenticator(CompletionHandler<void(LocalAuthenticatorPolicy)>&&) = 0;
virtual void cancelRequest() = 0;
};
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.cpp (260969 => 260970)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.cpp 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.cpp 2020-04-30 22:27:02 UTC (rev 260970)
@@ -273,14 +273,9 @@
});
}
-void AuthenticatorManager::selectAssertionResponse(const HashSet<Ref<AuthenticatorAssertionResponse>>& responses, WebAuthenticationSource source, CompletionHandler<void(AuthenticatorAssertionResponse*)>&& completionHandler)
+void AuthenticatorManager::selectAssertionResponse(Vector<Ref<WebCore::AuthenticatorAssertionResponse>>&& responses, WebAuthenticationSource source, CompletionHandler<void(AuthenticatorAssertionResponse*)>&& completionHandler)
{
- Vector<Ref<AuthenticatorAssertionResponse>> responseVector;
- responseVector.reserveInitialCapacity(responses.size());
- for (auto& response : responses)
- responseVector.uncheckedAppend(response.copyRef());
-
- dispatchPanelClientCall([responses = WTFMove(responseVector), source, completionHandler = WTFMove(completionHandler)] (const API::WebAuthenticationPanel& panel) mutable {
+ dispatchPanelClientCall([responses = WTFMove(responses), source, completionHandler = WTFMove(completionHandler)] (const API::WebAuthenticationPanel& panel) mutable {
panel.client().selectAssertionResponse(WTFMove(responses), source, WTFMove(completionHandler));
});
}
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.h (260969 => 260970)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.h 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/AuthenticatorManager.h 2020-04-30 22:27:02 UTC (rev 260970)
@@ -82,7 +82,7 @@
void downgrade(Authenticator* id, Ref<Authenticator>&& downgradedAuthenticator) final;
void authenticatorStatusUpdated(WebAuthenticationStatus) final;
void requestPin(uint64_t retries, CompletionHandler<void(const WTF::String&)>&&) final;
- void selectAssertionResponse(const HashSet<Ref<WebCore::AuthenticatorAssertionResponse>>&, WebAuthenticationSource, CompletionHandler<void(WebCore::AuthenticatorAssertionResponse*)>&&) final;
+ void selectAssertionResponse(Vector<Ref<WebCore::AuthenticatorAssertionResponse>>&&, WebAuthenticationSource, CompletionHandler<void(WebCore::AuthenticatorAssertionResponse*)>&&) final;
void decidePolicyForLocalAuthenticator(CompletionHandler<void(LocalAuthenticatorPolicy)>&&) final;
void cancelRequest() final;
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.h (260969 => 260970)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.h 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.h 2020-04-30 22:27:02 UTC (rev 260970)
@@ -72,8 +72,6 @@
State m_state { State::Init };
UniqueRef<LocalConnection> m_connection;
- // FIXME(183534): Combine these two.
- HashSet<Ref<WebCore::AuthenticatorAssertionResponse>> m_assertionResponses;
Vector<Ref<WebCore::AuthenticatorAssertionResponse>> m_existingCredentials;
};
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm (260969 => 260970)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm 2020-04-30 22:27:02 UTC (rev 260970)
@@ -34,16 +34,17 @@
#import <WebCore/CBORReader.h>
#import <WebCore/CBORWriter.h>
#import <WebCore/ExceptionData.h>
+#import <WebCore/FidoConstants.h>
#import <WebCore/PublicKeyCredentialCreationOptions.h>
#import <WebCore/PublicKeyCredentialRequestOptions.h>
#import <WebCore/WebAuthenticationConstants.h>
#import <WebCore/WebAuthenticationUtils.h>
#import <pal/crypto/CryptoDigest.h>
-#import <wtf/HashSet.h>
#import <wtf/RetainPtr.h>
#import <wtf/RunLoop.h>
#import <wtf/Vector.h>
#import <wtf/spi/cocoa/SecuritySPI.h>
+#import <wtf/text/Base64.h>
#import <wtf/text/StringHash.h>
namespace WebKit {
@@ -57,8 +58,6 @@
const uint8_t getAssertionFlags = 0b00000101; // UP and UV are set.
// Credential ID is currently SHA-1 of the corresponding public key.
const uint16_t credentialIdLength = 20;
-const char* const userEntityIdKey = "id";
-const char* const userEntityNameKey = "name";
const uint64_t counter = 0;
static inline bool emptyTransportsOrContain(const Vector<AuthenticatorTransport>& transports, AuthenticatorTransport target)
@@ -66,7 +65,7 @@
return transports.isEmpty() ? true : transports.contains(target);
}
-// FIXME(183534): Find a better way of comparing credential id. Doing it with array seems fine given the list should be small.
+// A Base64 encoded string of the Credential ID is used as the key of the hash set.
static inline HashSet<String> produceHashSet(const Vector<PublicKeyCredentialDescriptor>& credentialDescriptors)
{
HashSet<String> result;
@@ -74,7 +73,7 @@
if (emptyTransportsOrContain(credentialDescriptor.transports, AuthenticatorTransport::Internal)
&& credentialDescriptor.type == PublicKeyCredentialType::PublicKey
&& credentialDescriptor.idVector.size() == credentialIdLength)
- result.add(String(reinterpret_cast<const char*>(credentialDescriptor.idVector.data()), credentialDescriptor.idVector.size()));
+ result.add(base64Encode(credentialDescriptor.idVector.data(), credentialDescriptor.idVector.size()));
}
return result;
}
@@ -88,7 +87,6 @@
static inline RetainPtr<NSData> toNSData(const Vector<uint8_t>& data)
{
- // FIXME(183534): Consider using initWithBytesNoCopy.
return adoptNS([[NSData alloc] initWithBytes:data.data() length:data.size()]);
}
@@ -95,7 +93,6 @@
static inline RetainPtr<NSData> toNSData(ArrayBuffer* buffer)
{
ASSERT(buffer);
- // FIXME(183534): Consider using initWithBytesNoCopy.
return adoptNS([[NSData alloc] initWithBytes:buffer->data() length:buffer->byteLength()]);
}
@@ -140,11 +137,13 @@
if (status && status != errSecItemNotFound)
return WTF::nullopt;
auto retainAttributesArray = adoptCF(attributesArrayRef);
- NSArray *nsAttributesArray = (NSArray *)attributesArrayRef;
+ NSArray *sortedAttributesArray = [(NSArray *)attributesArrayRef sortedArrayUsingComparator:^(NSDictionary *a, NSDictionary *b) {
+ return [b[(id)kSecAttrModificationDate] compare:a[(id)kSecAttrModificationDate]];
+ }];
Vector<Ref<AuthenticatorAssertionResponse>> result;
- result.reserveInitialCapacity(nsAttributesArray.count);
- for (NSDictionary *attributes in nsAttributesArray) {
+ result.reserveInitialCapacity(sortedAttributesArray.count);
+ for (NSDictionary *attributes in sortedAttributesArray) {
auto decodedResponse = cbor::CBORReader::read(toVector(attributes[(id)kSecAttrApplicationTag]));
if (!decodedResponse || !decodedResponse->isMap()) {
ASSERT_NOT_REACHED();
@@ -152,7 +151,7 @@
}
auto& responseMap = decodedResponse->getMap();
- auto it = responseMap.find(CBOR(userEntityIdKey));
+ auto it = responseMap.find(CBOR(kEntityIdMapKey));
if (it == responseMap.end() || !it->second.isByteString()) {
ASSERT_NOT_REACHED();
return WTF::nullopt;
@@ -159,7 +158,7 @@
}
auto& userHandle = it->second.getByteString();
- it = responseMap.find(CBOR(userEntityNameKey));
+ it = responseMap.find(CBOR(kEntityNameMapKey));
if (it == responseMap.end() || !it->second.isString()) {
ASSERT_NOT_REACHED();
return WTF::nullopt;
@@ -211,7 +210,7 @@
if (notFound != m_existingCredentials.findMatching([&excludeCredentialIds] (auto& credential) {
auto* rawId = credential->rawId();
ASSERT(rawId);
- return excludeCredentialIds.contains(String(reinterpret_cast<const char*>(rawId->data()), rawId->byteLength()));
+ return excludeCredentialIds.contains(base64Encode(rawId->data(), rawId->byteLength()));
})) {
receiveException({ NotAllowedError, "At least one credential matches an entry of the excludeCredentials list in the platform attached authenticator."_s }, WebAuthenticationStatus::LAExcludeCredentialsMatched);
return;
@@ -286,8 +285,8 @@
const auto& secAttrLabel = creationOptions.rp.id;
cbor::CBORValue::MapValue userEntityMap;
- userEntityMap[cbor::CBORValue(userEntityIdKey)] = cbor::CBORValue(creationOptions.user.idVector);
- userEntityMap[cbor::CBORValue(userEntityNameKey)] = cbor::CBORValue(creationOptions.user.name);
+ userEntityMap[cbor::CBORValue(kEntityIdMapKey)] = cbor::CBORValue(creationOptions.user.idVector);
+ userEntityMap[cbor::CBORValue(kEntityNameMapKey)] = cbor::CBORValue(creationOptions.user.name);
auto userEntity = cbor::CBORWriter::write(cbor::CBORValue(WTFMove(userEntityMap)));
ASSERT(userEntity);
auto secAttrApplicationTag = toNSData(*userEntity);
@@ -435,26 +434,25 @@
}
m_existingCredentials = WTFMove(*existingCredentials);
+ Vector<Ref<WebCore::AuthenticatorAssertionResponse>> assertionResponses;
+ assertionResponses.reserveInitialCapacity(m_existingCredentials.size());
for (auto& credential : m_existingCredentials) {
if (allowCredentialIds.isEmpty()) {
- auto addResult = m_assertionResponses.add(credential.copyRef());
- ASSERT_UNUSED(addResult, addResult.isNewEntry);
+ assertionResponses.uncheckedAppend(credential.copyRef());
continue;
}
auto* rawId = credential->rawId();
- if (allowCredentialIds.contains(String(reinterpret_cast<const char*>(rawId->data()), rawId->byteLength()))) {
- auto addResult = m_assertionResponses.add(credential.copyRef());
- ASSERT_UNUSED(addResult, addResult.isNewEntry);
- }
+ if (allowCredentialIds.contains(base64Encode(rawId->data(), rawId->byteLength())))
+ assertionResponses.uncheckedAppend(credential.copyRef());
}
- if (m_assertionResponses.isEmpty()) {
+ if (assertionResponses.isEmpty()) {
receiveException({ NotAllowedError, "No matched credentials are found in the platform attached authenticator."_s }, WebAuthenticationStatus::LANoCredential);
return;
}
// Step 6-7. User consent is implicitly acquired by selecting responses.
- m_connection->filterResponses(m_assertionResponses);
+ m_connection->filterResponses(assertionResponses);
if (auto* observer = this->observer()) {
auto callback = [this, weakThis = makeWeakPtr(*this)] (AuthenticatorAssertionResponse* response) {
@@ -462,12 +460,14 @@
if (!weakThis)
return;
- auto returnResponse = m_assertionResponses.take(response);
- if (!returnResponse)
+ auto result = m_existingCredentials.findMatching([expectedResponse = response] (auto& response) {
+ return response.ptr() == expectedResponse;
+ });
+ if (result == notFound)
return;
- continueGetAssertionAfterResponseSelected(WTFMove(*returnResponse));
+ continueGetAssertionAfterResponseSelected(m_existingCredentials[result].copyRef());
};
- observer->selectAssertionResponse(m_assertionResponses, WebAuthenticationSource::Local, WTFMove(callback));
+ observer->selectAssertionResponse(WTFMove(assertionResponses), WebAuthenticationSource::Local, WTFMove(callback));
}
}
@@ -502,15 +502,17 @@
return;
// Step 10.
- auto authData = buildAuthData(WTF::get<PublicKeyCredentialRequestOptions>(requestData().options).rpId, getAssertionFlags, counter, { });
+ auto requestOptions = WTF::get<PublicKeyCredentialRequestOptions>(requestData().options);
+ auto authData = buildAuthData(requestOptions.rpId, getAssertionFlags, counter, { });
// Step 11.
RetainPtr<CFDataRef> signature;
+ auto nsCredentialId = toNSData(response->rawId());
{
NSDictionary *query = @{
(id)kSecClass: (id)kSecClassKey,
(id)kSecAttrKeyClass: (id)kSecAttrKeyClassPrivate,
- (id)kSecAttrApplicationLabel: toNSData(response->rawId()).get(),
+ (id)kSecAttrApplicationLabel: nsCredentialId.get(),
(id)kSecUseAuthenticationContext: context,
(id)kSecReturnRef: @YES,
#if HAVE(DATA_PROTECTION_KEYCHAIN)
@@ -544,6 +546,25 @@
response->setAuthenticatorData(WTFMove(authData));
response->setSignature(toArrayBuffer((NSData *)signature.get()));
receiveRespond(WTFMove(response));
+
+ // Extra step: update the Keychain item with the same value to update its modification date such that LRU can be used
+ // for selectAssertionResponse
+ NSDictionary *updateQuery = @{
+ (id)kSecClass: (id)kSecClassKey,
+ (id)kSecAttrKeyClass: (id)kSecAttrKeyClassPrivate,
+ (id)kSecAttrApplicationLabel: nsCredentialId.get(),
+#if HAVE(DATA_PROTECTION_KEYCHAIN)
+ (id)kSecUseDataProtectionKeychain: @YES
+#else
+ (id)kSecAttrNoLegacy: @YES
+#endif
+ };
+ NSDictionary *updateParams = @{
+ (id)kSecAttrLabel: requestOptions.rpId,
+ };
+ auto status = SecItemUpdate((__bridge CFDictionaryRef)updateQuery, (__bridge CFDictionaryRef)updateParams);
+ if (status)
+ LOG_ERROR("Couldn't update the Keychain item: %d", status);
}
void LocalAuthenticator::receiveException(ExceptionData&& exception, WebAuthenticationStatus status) const
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalConnection.h (260969 => 260970)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalConnection.h 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalConnection.h 2020-04-30 22:27:02 UTC (rev 260970)
@@ -61,14 +61,16 @@
using UserVerificationCallback = CompletionHandler<void(UserVerification, LAContext *)>;
LocalConnection() = default;
- // FIXME(183534): Invalidate the LAContext.
- virtual ~LocalConnection() = default;
+ virtual ~LocalConnection();
// Overrided by MockLocalConnection.
- virtual void verifyUser(const String& rpId, WebCore::ClientDataType, SecAccessControlRef, UserVerificationCallback&&) const;
+ virtual void verifyUser(const String& rpId, WebCore::ClientDataType, SecAccessControlRef, UserVerificationCallback&&);
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(HashSet<Ref<WebCore::AuthenticatorAssertionResponse>>&) const { };
+ virtual void filterResponses(Vector<Ref<WebCore::AuthenticatorAssertionResponse>>&) const { };
+
+private:
+ RetainPtr<LAContext> m_context;
};
} // namespace WebKit
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalConnection.mm (260969 => 260970)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalConnection.mm 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalConnection.mm 2020-04-30 22:27:02 UTC (rev 260970)
@@ -42,21 +42,24 @@
using namespace WebCore;
namespace {
-static String bundleName()
+#if PLATFORM(MAC)
+static inline String bundleName()
{
- String bundleName;
-
-#if PLATFORM(MAC)
- bundleName = [[NSRunningApplication currentApplication] localizedName];
+ return [[NSRunningApplication currentApplication] localizedName];
+}
#endif
+} // namespace
- return bundleName;
+LocalConnection::~LocalConnection()
+{
+ // Dismiss any showing LocalAuthentication dialogs.
+ [m_context invalidate];
}
-} // namespace
-void LocalConnection::verifyUser(const String& rpId, ClientDataType type, SecAccessControlRef accessControl, UserVerificationCallback&& completionHandler) const
+void LocalConnection::verifyUser(const String& rpId, ClientDataType type, SecAccessControlRef accessControl, UserVerificationCallback&& completionHandler)
{
- String title;
+ String title = genericTouchIDPromptTitle();
+#if PLATFORM(MAC)
switch (type) {
case ClientDataType::Create:
title = makeCredentialTouchIDPromptTitle(bundleName(), rpId);
@@ -67,18 +70,17 @@
default:
ASSERT_NOT_REACHED();
}
+#endif
- auto context = adoptNS([allocLAContextInstance() init]);
+ m_context = [allocLAContextInstance() init];
auto options = adoptNS([[NSMutableDictionary alloc] init]);
- if ([context biometryType] == LABiometryTypeTouchID) {
+ if ([m_context biometryType] == LABiometryTypeTouchID) {
[options setObject:title forKey:@(LAOptionAuthenticationTitle)];
[options setObject:@NO forKey:@(LAOptionFallbackVisible)];
}
- auto reply = makeBlockPtr([context, completionHandler = WTFMove(completionHandler)] (NSDictionary *, NSError *error) mutable {
- ASSERT(!RunLoop::isMain());
-
+ auto reply = makeBlockPtr([context = m_context, completionHandler = WTFMove(completionHandler)] (NSDictionary *, NSError *error) mutable {
UserVerification verification = UserVerification::Yes;
if (error) {
LOG_ERROR("Couldn't authenticate with biometrics: %@", error);
@@ -86,12 +88,14 @@
if (error.code == LAErrorUserCancel)
verification = UserVerification::Cancel;
}
+
+ // This block can be executed in another thread.
RunLoop::main().dispatch([completionHandler = WTFMove(completionHandler), verification, context = WTFMove(context)] () mutable {
completionHandler(verification, context.get());
});
});
- [context evaluateAccessControl:accessControl operation:LAAccessControlOperationUseKeySign options:options.get() reply:reply.get()];
+ [m_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
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Mock/MockLocalConnection.h (260969 => 260970)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Mock/MockLocalConnection.h 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Mock/MockLocalConnection.h 2020-04-30 22:27:02 UTC (rev 260970)
@@ -37,10 +37,10 @@
explicit MockLocalConnection(const WebCore::MockWebAuthenticationConfiguration&);
private:
- void verifyUser(const String&, WebCore::ClientDataType, SecAccessControlRef, UserVerificationCallback&&) const final;
+ void verifyUser(const String&, WebCore::ClientDataType, SecAccessControlRef, UserVerificationCallback&&) final;
RetainPtr<SecKeyRef> createCredentialPrivateKey(LAContext *, SecAccessControlRef, const String& secAttrLabel, NSData *secAttrApplicationTag) const final;
void getAttestation(SecKeyRef, NSData *authData, NSData *hash, AttestationCallback&&) const final;
- void filterResponses(HashSet<Ref<WebCore::AuthenticatorAssertionResponse>>&) const final;
+ void filterResponses(Vector<Ref<WebCore::AuthenticatorAssertionResponse>>&) const final;
WebCore::MockWebAuthenticationConfiguration m_configuration;
};
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Mock/MockLocalConnection.mm (260969 => 260970)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Mock/MockLocalConnection.mm 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Mock/MockLocalConnection.mm 2020-04-30 22:27:02 UTC (rev 260970)
@@ -31,7 +31,6 @@
#import <Security/SecItem.h>
#import <WebCore/AuthenticatorAssertionResponse.h>
#import <WebCore/ExceptionData.h>
-#import <wtf/HashSet.h>
#import <wtf/RunLoop.h>
#import <wtf/spi/cocoa/SecuritySPI.h>
#import <wtf/text/Base64.h>
@@ -47,7 +46,7 @@
{
}
-void MockLocalConnection::verifyUser(const String&, ClientDataType, SecAccessControlRef, UserVerificationCallback&& callback) const
+void MockLocalConnection::verifyUser(const String&, ClientDataType, SecAccessControlRef, UserVerificationCallback&& callback)
{
// Mock async operations.
RunLoop::main().dispatch([configuration = m_configuration, callback = WTFMove(callback)]() mutable {
@@ -124,7 +123,7 @@
});
}
-void MockLocalConnection::filterResponses(HashSet<Ref<AuthenticatorAssertionResponse>>& responses) const
+void MockLocalConnection::filterResponses(Vector<Ref<AuthenticatorAssertionResponse>>& responses) const
{
const auto& preferredCredentialIdBase64 = m_configuration.local->preferredCredentialIdBase64;
if (preferredCredentialIdBase64.isEmpty())
@@ -138,10 +137,9 @@
if (rawIdBase64 == preferredCredentialIdBase64)
break;
}
- auto response = responses.take(itr);
- ASSERT(response);
+ auto response = itr->copyRef();
responses.clear();
- responses.add(WTFMove(*response));
+ responses.append(WTFMove(response));
}
} // namespace WebKit
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/fido/CtapAuthenticator.cpp (260969 => 260970)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/fido/CtapAuthenticator.cpp 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/fido/CtapAuthenticator.cpp 2020-04-30 22:27:02 UTC (rev 260970)
@@ -173,8 +173,8 @@
}
m_remainingAssertionResponses = response->numberOfCredentials() - 1;
- auto addResult = m_assertionResponses.add(response.releaseNonNull());
- ASSERT_UNUSED(addResult, addResult.isNewEntry);
+ m_assertionResponses.reserveInitialCapacity(response->numberOfCredentials());
+ m_assertionResponses.uncheckedAppend(response.releaseNonNull());
driver().transact(encodeEmptyAuthenticatorRequest(CtapRequestCommand::kAuthenticatorGetNextAssertion), [weakThis = makeWeakPtr(*this)](Vector<uint8_t>&& data) {
ASSERT(RunLoop::isMain());
if (!weakThis)
@@ -192,19 +192,25 @@
return;
}
m_remainingAssertionResponses--;
- auto addResult = m_assertionResponses.add(response.releaseNonNull());
- ASSERT_UNUSED(addResult, addResult.isNewEntry);
+ m_assertionResponses.uncheckedAppend(response.releaseNonNull());
if (!m_remainingAssertionResponses) {
if (auto* observer = this->observer()) {
- observer->selectAssertionResponse(m_assertionResponses, WebAuthenticationSource::External, [this, weakThis = makeWeakPtr(*this)] (AuthenticatorAssertionResponse* response) {
+ Vector<Ref<AuthenticatorAssertionResponse>> responsesCopy;
+ responsesCopy.reserveInitialCapacity(m_assertionResponses.size());
+ for (auto& response : m_assertionResponses)
+ responsesCopy.uncheckedAppend(response.copyRef());
+
+ observer->selectAssertionResponse(WTFMove(responsesCopy), WebAuthenticationSource::External, [this, weakThis = makeWeakPtr(*this)] (AuthenticatorAssertionResponse* response) {
ASSERT(RunLoop::isMain());
if (!weakThis)
return;
- auto returnResponse = m_assertionResponses.take(response);
- if (!returnResponse)
+ auto result = m_assertionResponses.findMatching([expectedResponse = response] (auto& response) {
+ return response.ptr() == expectedResponse;
+ });
+ if (result == notFound)
return;
- receiveRespond(WTFMove(*returnResponse));
+ receiveRespond(m_assertionResponses[result].copyRef());
});
}
return;
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/fido/CtapAuthenticator.h (260969 => 260970)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/fido/CtapAuthenticator.h 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/fido/CtapAuthenticator.h 2020-04-30 22:27:02 UTC (rev 260970)
@@ -73,7 +73,7 @@
fido::AuthenticatorGetInfoResponse m_info;
bool m_isDowngraded { false };
size_t m_remainingAssertionResponses { 0 };
- HashSet<Ref<WebCore::AuthenticatorAssertionResponse>> m_assertionResponses;
+ Vector<Ref<WebCore::AuthenticatorAssertionResponse>> m_assertionResponses;
Vector<uint8_t> m_pinAuth;
};
Modified: trunk/Tools/ChangeLog (260969 => 260970)
--- trunk/Tools/ChangeLog 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Tools/ChangeLog 2020-04-30 22:27:02 UTC (rev 260970)
@@ -1,3 +1,16 @@
+2020-04-30 Jiewen Tan <[email protected]>
+
+ [WebAuthn] Optimize LocalAuthenticator
+ https://bugs.webkit.org/show_bug.cgi?id=183534
+ <rdar://problem/43357408>
+
+ Reviewed by Brent Fulgham.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm:
+ (-[TestWebAuthenticationPanelDelegate panel:selectAssertionResponse:source:completionHandler:]):
+ (TestWebKitAPI::TEST):
+ Adds a new test case for the LRU.
+
2020-04-30 Kate Cheney <[email protected]>
Change default of "inAppBrowserPrivacyQuirks" testing toggle to use it for tests only
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm (260969 => 260970)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm 2020-04-30 21:58:08 UTC (rev 260969)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm 2020-04-30 22:27:02 UTC (rev 260970)
@@ -62,7 +62,8 @@
"BDj/zxSkzKgaBuS3cdWDF558of8AaIpgFpsjF/Qm1749VBJPgqUIwfhWHJ91nb7U"
"PH76c0+WFOzZKslPyyFse4goGIW2R7k9VHLPEZl5nfnBgEVFh5zev+/xpHQIvuq6"
"RQ==";
-static String testUserEntityBundleBase64 = "omJpZEoAAQIDBAUGBwgJZG5hbWVwQUFFQ0F3UUZCZ2NJQ1E9PQ==";
+static String testUserEntityBundleBase64 = "omJpZEoAAQIDBAUGBwgJZG5hbWVkSm9obg=="; // { "id": h'00010203040506070809', "name": "John" }
+static String webAuthenticationPanelSelectedCredentialName;
@interface TestWebAuthenticationPanelDelegate : NSObject <_WKWebAuthenticationPanelDelegate>
@end
@@ -139,6 +140,14 @@
return;
}
+ // Responses returned from LocalAuthenticator is in the order of LRU. Therefore, we use the last item to populate it to
+ // the first to test its correctness.
+ if (source == _WKWebAuthenticationSourceLocal) {
+ webAuthenticationPanelSelectedCredentialName = responses.lastObject.name;
+ completionHandler(responses.lastObject);
+ return;
+ }
+
EXPECT_EQ(source, _WKWebAuthenticationSourceExternal);
EXPECT_EQ(responses.count, 2ul);
for (_WKWebAuthenticationAssertionResponse *response in responses) {
@@ -300,6 +309,7 @@
webAuthenticationPanelPin = emptyString();
webAuthenticationPanelNullUserHandle = NO;
localAuthenticatorPolicy = _WKLocalAuthenticatorPolicyDisallow;
+ webAuthenticationPanelSelectedCredentialName = emptyString();
}
static void checkPanel(_WKWebAuthenticationPanel *panel, NSString *relyingPartyID, NSArray *transports, _WKWebAuthenticationType type)
@@ -1294,6 +1304,7 @@
// Skip the test because of <rdar://problem/59635486>.
#if PLATFORM(MAC)
+
TEST(WebAuthenticationPanel, LAGetAssertion)
{
reset();
@@ -1313,6 +1324,34 @@
checkPanel([delegate panel], @"", @[adoptNS([[NSNumber alloc] initWithInt:_WKWebAuthenticationTransportUSB]).get(), adoptNS([[NSNumber alloc] initWithInt:_WKWebAuthenticationTransportInternal]).get()], _WKWebAuthenticationTypeGet);
cleanUpKeychain("");
}
+
+TEST(WebAuthenticationPanel, LAGetAssertionMultipleOrder)
+{
+ reset();
+ RetainPtr<NSURL> testURL = [[NSBundle mainBundle] URLForResource:@"web-authentication-get-assertion-la" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
+
+ auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
+ [[configuration preferences] _setEnabled:YES forExperimentalFeature:webAuthenticationExperimentalFeature()];
+ [[configuration preferences] _setEnabled:YES forExperimentalFeature:webAuthenticationLocalAuthenticatorExperimentalFeature()];
+
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSZeroRect configuration:configuration]);
+ auto delegate = adoptNS([[TestWebAuthenticationPanelUIDelegate alloc] init]);
+ [webView setUIDelegate:delegate.get()];
+
+ ASSERT_TRUE(addKeyToKeychain(testES256PrivateKeyBase64, "", testUserEntityBundleBase64));
+ ASSERT_TRUE(addKeyToKeychain("BBRoi2JbR0IXTeJmvXUp1YIuM4sph/Lu3eGf75F7n+HojHKG70a4R0rB2PQce5/SJle6T7OO5Cqet/LJZVM6NQ8yDDxWvayf71GTDp2yUtuIbqJLFVbpWymlj9WRizgX3A==", "", "omJpZEoAAQIDBAUGBwgJZG5hbWVkSmFuZQ=="/* { "id": h'00010203040506070809', "name": "Jane" } */));
+
+ [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
+ [webView waitForMessage:@"Succeeded!"];
+ EXPECT_WK_STREQ(webAuthenticationPanelSelectedCredentialName, "John");
+
+ [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
+ [webView waitForMessage:@"Succeeded!"];
+ EXPECT_WK_STREQ(webAuthenticationPanelSelectedCredentialName, "Jane");
+
+ cleanUpKeychain("");
+}
+
#endif
#endif // USE(APPLE_INTERNAL_SDK) || PLATFORM(IOS)