Diff
Modified: trunk/Source/WebCore/ChangeLog (291422 => 291423)
--- trunk/Source/WebCore/ChangeLog 2022-03-17 18:15:38 UTC (rev 291422)
+++ trunk/Source/WebCore/ChangeLog 2022-03-17 18:28:13 UTC (rev 291423)
@@ -1,3 +1,22 @@
+2022-03-17 J Pascoe <[email protected]>
+
+ [WebAuthn] Support makeCredential for virtual HID authenticators
+ https://bugs.webkit.org/show_bug.cgi?id=237984
+ rdar://problem/90393676
+
+ Reviewed by Brent Fulgham.
+
+ Virtual authenticators for WebAuthn supports different transports: nfc,usb,internal,ble.
+ Currently, we support the internal transport, but the default transport used in web platform
+ tests is usb. This patch implements makeCredential for hid-based virtual authenticators. Virtual
+ credential information is stored in the VirtualCredential struct as suggested by the spec.
+
+ * Modules/webauthn/WebAuthenticationUtils.cpp:
+ (WebCore::buildAttestationMap):
+ (WebCore::buildAttestationObject):
+ * Modules/webauthn/WebAuthenticationUtils.h:
+ * Modules/webauthn/fido/FidoConstants.h:
+
2022-03-17 Youenn Fablet <[email protected]>
Make SharedVideoFrameReader use VideoFrameCV instead of MediaSample
Modified: trunk/Source/WebCore/Modules/webauthn/WebAuthenticationConstants.h (291422 => 291423)
--- trunk/Source/WebCore/Modules/webauthn/WebAuthenticationConstants.h 2022-03-17 18:15:38 UTC (rev 291422)
+++ trunk/Source/WebCore/Modules/webauthn/WebAuthenticationConstants.h 2022-03-17 18:28:13 UTC (rev 291423)
@@ -100,4 +100,9 @@
SameSite
};
+// https://www.w3.org/TR/webauthn-2/#authenticator-data
+constexpr uint8_t userPresenceFlag = 0b00000001;
+constexpr uint8_t userVerifiedFlag = 0b00000100;
+constexpr uint8_t attestedCredentialDataIncludedFlag = 0b01000000;
+
} // namespace WebAuthn
Modified: trunk/Source/WebCore/Modules/webauthn/WebAuthenticationUtils.cpp (291422 => 291423)
--- trunk/Source/WebCore/Modules/webauthn/WebAuthenticationUtils.cpp 2022-03-17 18:15:38 UTC (rev 291422)
+++ trunk/Source/WebCore/Modules/webauthn/WebAuthenticationUtils.cpp 2022-03-17 18:28:13 UTC (rev 291423)
@@ -110,7 +110,7 @@
return authData;
}
-Vector<uint8_t> buildAttestationObject(Vector<uint8_t>&& authData, String&& format, cbor::CBORValue::MapValue&& statementMap, const AttestationConveyancePreference& attestation)
+cbor::CBORValue::MapValue buildAttestationMap(Vector<uint8_t>&& authData, String&& format, cbor::CBORValue::MapValue&& statementMap, const AttestationConveyancePreference& attestation)
{
cbor::CBORValue::MapValue attestationObjectMap;
// The following implements Step 20 with regard to AttestationConveyancePreference
@@ -127,7 +127,13 @@
attestationObjectMap[cbor::CBORValue("authData")] = cbor::CBORValue(WTFMove(authData));
attestationObjectMap[cbor::CBORValue("fmt")] = cbor::CBORValue(WTFMove(format));
attestationObjectMap[cbor::CBORValue("attStmt")] = cbor::CBORValue(WTFMove(statementMap));
+ return attestationObjectMap;
+}
+Vector<uint8_t> buildAttestationObject(Vector<uint8_t>&& authData, String&& format, cbor::CBORValue::MapValue&& statementMap, const AttestationConveyancePreference& attestation)
+{
+ cbor::CBORValue::MapValue attestationObjectMap = buildAttestationMap(WTFMove(authData), WTFMove(format), WTFMove(statementMap), attestation);
+
auto attestationObject = cbor::CBORWriter::write(cbor::CBORValue(WTFMove(attestationObjectMap)));
ASSERT(attestationObject);
return *attestationObject;
Modified: trunk/Source/WebCore/Modules/webauthn/WebAuthenticationUtils.h (291422 => 291423)
--- trunk/Source/WebCore/Modules/webauthn/WebAuthenticationUtils.h 2022-03-17 18:15:38 UTC (rev 291422)
+++ trunk/Source/WebCore/Modules/webauthn/WebAuthenticationUtils.h 2022-03-17 18:28:13 UTC (rev 291423)
@@ -49,6 +49,8 @@
// https://www.w3.org/TR/webauthn/#sec-authenticator-data
WEBCORE_EXPORT Vector<uint8_t> buildAuthData(const String& rpId, const uint8_t flags, const uint32_t counter, const Vector<uint8_t>& optionalAttestedCredentialData);
+WEBCORE_EXPORT cbor::CBORValue::MapValue buildAttestationMap(Vector<uint8_t>&&, String&&, cbor::CBORValue::MapValue&&, const AttestationConveyancePreference&);
+
// https://www.w3.org/TR/webauthn/#attestation-object
WEBCORE_EXPORT Vector<uint8_t> buildAttestationObject(Vector<uint8_t>&& authData, String&& format, cbor::CBORValue::MapValue&& statementMap, const AttestationConveyancePreference&);
Modified: trunk/Source/WebCore/Modules/webauthn/fido/FidoConstants.h (291422 => 291423)
--- trunk/Source/WebCore/Modules/webauthn/fido/FidoConstants.h 2022-03-17 18:15:38 UTC (rev 291422)
+++ trunk/Source/WebCore/Modules/webauthn/fido/FidoConstants.h 2022-03-17 18:28:13 UTC (rev 291423)
@@ -255,6 +255,19 @@
const uint8_t kCtapNfcApduCla = 0x80;
const uint8_t kCtapNfcApduIns = 0x10;
+// https://fidoalliance.org/specs/fido-v2.0-ps-20170927/fido-client-to-authenticator-protocol-v2.0-ps-20170927.html#mandatory-commands
+const size_t kCtapChannelIdSize = 4;
+const uint8_t kCtapKeepAliveStatusProcessing = 1;
+// https://fidoalliance.org/specs/fido-v2.0-ps-20170927/fido-client-to-authenticator-protocol-v2.0-ps-20170927.html#commands
+const int64_t kCtapMakeCredentialClientDataHashKey = 1;
+const int64_t kCtapMakeCredentialRpKey = 2;
+const int64_t kCtapMakeCredentialUserKey = 3;
+const int64_t kCtapMakeCredentialPubKeyCredParamsKey = 4;
+const int64_t kCtapMakeCredentialExcludeListKey = 5;
+const int64_t kCtapMakeCredentialExtensionsKey = 6;
+const int64_t kCtapMakeCredentialRequestOptionsKey = 7;
+const int64_t kCtapGetAssertionRequestOptionsKey = 5;
+
} // namespace fido
#endif // ENABLE(WEB_AUTHN)
Modified: trunk/Source/WebKit/ChangeLog (291422 => 291423)
--- trunk/Source/WebKit/ChangeLog 2022-03-17 18:15:38 UTC (rev 291422)
+++ trunk/Source/WebKit/ChangeLog 2022-03-17 18:28:13 UTC (rev 291423)
@@ -1,3 +1,52 @@
+2022-03-17 J Pascoe <[email protected]>
+
+ [WebAuthn] Support makeCredential for virtual HID authenticators
+ https://bugs.webkit.org/show_bug.cgi?id=237984
+ rdar://problem/90393676
+
+ Reviewed by Brent Fulgham.
+
+ Virtual authenticators for WebAuthn supports different transports: nfc,usb,internal,ble.
+ Currently, we support the internal transport, but the default transport used in web platform
+ tests is usb. This patch implements makeCredential for hid-based virtual authenticators. Virtual
+ credential information is stored in the VirtualCredential struct as suggested by the spec.
+
+ Tested manually via creating virtual authenticator and performing create and via wpt tests.
+
+ * UIProcess/WebAuthentication/Mock/MockHidConnection.cpp:
+ (WebKit::MockHidConnection::parseRequest):
+ (WebKit::MockHidConnection::feedReports):
+ * UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorManager.cpp:
+ (WebKit::VirtualAuthenticatorManager::createAuthenticator):
+ (WebKit::VirtualAuthenticatorManager::addCredential):
+ (WebKit::VirtualAuthenticatorManager::createService const):
+ * UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorManager.h:
+ * UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorUtils.h: Copied from Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualService.h.
+ * UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorUtils.mm: Added.
+ (WebKit::flagsForConfig):
+ (WebKit::createPrivateKey):
+ (WebKit::credentialIdAndCosePubKeyForPrivateKey):
+ (WebKit::base64PrivateKey):
+ * UIProcess/WebAuthentication/Virtual/VirtualCredential.h: Copied from Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualService.h.
+ * UIProcess/WebAuthentication/Virtual/VirtualHidConnection.cpp: Added.
+ (WebKit::VirtualHidConnection::VirtualHidConnection):
+ (WebKit::VirtualHidConnection::initialize):
+ (WebKit::VirtualHidConnection::terminate):
+ (WebKit::VirtualHidConnection::sendSync):
+ (WebKit::VirtualHidConnection::send):
+ (WebKit::VirtualHidConnection::assembleRequest):
+ (WebKit::VirtualHidConnection::receiveHidMessage):
+ (WebKit::VirtualHidConnection::recieveResponseCode):
+ (WebKit::VirtualHidConnection::parseRequest):
+ * UIProcess/WebAuthentication/Virtual/VirtualHidConnection.h: Copied from Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorManager.h.
+ * UIProcess/WebAuthentication/Virtual/VirtualService.h:
+ * UIProcess/WebAuthentication/Virtual/VirtualService.mm:
+ (WebKit::VirtualService::VirtualService):
+ (WebKit::VirtualService::createVirtual):
+ (WebKit::authenticatorInfoForConfig):
+ (WebKit::VirtualService::startDiscoveryInternal):
+ * WebKit.xcodeproj/project.pbxproj:
+
2022-03-17 Youenn Fablet <[email protected]>
Make SharedVideoFrameReader use VideoFrameCV instead of MediaSample
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm (291422 => 291423)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm 2022-03-17 18:15:38 UTC (rev 291422)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm 2022-03-17 18:28:13 UTC (rev 291423)
@@ -65,15 +65,16 @@
namespace WebKit {
using namespace fido;
using namespace WebCore;
+using namespace WebAuthn;
using CBOR = cbor::CBORValue;
namespace LocalAuthenticatorInternal {
// See https://www.w3.org/TR/webauthn/#flags.
-const uint8_t makeCredentialFlags = 0b01000101; // UP, UV and AT are set.
-const uint8_t otherMakeCredentialFlags = 0b01000001; // UP and AT are set.
-const uint8_t getAssertionFlags = 0b00000101; // UP and UV are set.
-const uint8_t otherGetAssertionFlags = 0b00000001; // UP is set.
+const uint8_t makeCredentialFlags = userPresenceFlag | userVerifiedFlag | attestedCredentialDataIncludedFlag; // UP, UV and AT are set.
+const uint8_t otherMakeCredentialFlags = userPresenceFlag | attestedCredentialDataIncludedFlag; // UP and AT are set.
+const uint8_t getAssertionFlags = userPresenceFlag | userVerifiedFlag; // UP and UV are set.
+const uint8_t otherGetAssertionFlags = userPresenceFlag; // UP is set.
// Credential ID is currently SHA-1 of the corresponding public key.
const uint16_t credentialIdLength = 20;
const uint64_t counter = 0;
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Mock/MockHidConnection.cpp (291422 => 291423)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Mock/MockHidConnection.cpp 2022-03-17 18:15:38 UTC (rev 291422)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Mock/MockHidConnection.cpp 2022-03-17 18:28:13 UTC (rev 291423)
@@ -44,15 +44,6 @@
using namespace cbor;
using namespace fido;
-namespace MockHidConnectionInternal {
-// https://fidoalliance.org/specs/fido-v2.0-ps-20170927/fido-client-to-authenticator-protocol-v2.0-ps-20170927.html#mandatory-commands
-const size_t CtapChannelIdSize = 4;
-const uint8_t CtapKeepAliveStatusProcessing = 1;
-// https://fidoalliance.org/specs/fido-v2.0-ps-20170927/fido-client-to-authenticator-protocol-v2.0-ps-20170927.html#commands
-const int64_t CtapMakeCredentialRequestOptionsKey = 7;
-const int64_t CtapGetAssertionRequestOptionsKey = 5;
-}
-
MockHidConnection::MockHidConnection(IOHIDDeviceRef device, const MockWebAuthenticationConfiguration& configuration)
: HidConnection(device)
, m_configuration(configuration)
@@ -130,8 +121,6 @@
void MockHidConnection::parseRequest()
{
- using namespace MockHidConnectionInternal;
-
ASSERT(m_requestMessage);
// Set stages.
if (m_requestMessage->cmd() == FidoHidDeviceCommand::kInit) {
@@ -162,7 +151,7 @@
ASSERT(requestMap || cmd == CtapRequestCommand::kAuthenticatorGetNextAssertion);
if (cmd == CtapRequestCommand::kAuthenticatorMakeCredential) {
- auto it = requestMap->getMap().find(CBORValue(CtapMakeCredentialRequestOptionsKey)); // Find options.
+ auto it = requestMap->getMap().find(CBORValue(kCtapMakeCredentialRequestOptionsKey)); // Find options.
if (it != requestMap->getMap().end()) {
auto& optionMap = it->second.getMap();
@@ -177,7 +166,7 @@
}
if (cmd == CtapRequestCommand::kAuthenticatorGetAssertion) {
- auto it = requestMap->getMap().find(CBORValue(CtapGetAssertionRequestOptionsKey)); // Find options.
+ auto it = requestMap->getMap().find(CBORValue(kCtapGetAssertionRequestOptionsKey)); // Find options.
if (it != requestMap->getMap().end()) {
auto& optionMap = it->second.getMap();
auto itr = optionMap.find(CBORValue(kUserVerificationMapKey));
@@ -202,8 +191,6 @@
void MockHidConnection::feedReports()
{
- using namespace MockHidConnectionInternal;
-
if (m_subStage == Mock::HidSubStage::Init) {
Vector<uint8_t> payload;
payload.reserveInitialCapacity(kHidInitResponseSize);
@@ -212,7 +199,7 @@
if (stagesMatch() && m_configuration.hid->error == Mock::HidError::WrongNonce)
payload[0]--;
payload.grow(kHidInitResponseSize);
- cryptographicallyRandomValues(payload.data() + writePosition, CtapChannelIdSize);
+ cryptographicallyRandomValues(payload.data() + writePosition, kCtapChannelIdSize);
auto channel = kHidBroadcastChannel;
if (stagesMatch() && m_configuration.hid->error == Mock::HidError::WrongChannelId)
channel--;
@@ -256,7 +243,7 @@
return;
if (m_configuration.hid->keepAlive) {
m_configuration.hid->keepAlive = false;
- FidoHidInitPacket initPacket(m_currentChannel, FidoHidDeviceCommand::kKeepAlive, { CtapKeepAliveStatusProcessing }, 1);
+ FidoHidInitPacket initPacket(m_currentChannel, FidoHidDeviceCommand::kKeepAlive, { kCtapKeepAliveStatusProcessing }, 1);
receiveReport(initPacket.getSerializedData());
continueFeedReports();
return;
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorManager.cpp (291422 => 291423)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorManager.cpp 2022-03-17 18:15:38 UTC (rev 291422)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorManager.cpp 2022-03-17 18:28:13 UTC (rev 291423)
@@ -33,6 +33,8 @@
namespace WebKit {
+struct VirtualCredential;
+
VirtualAuthenticatorManager::VirtualAuthenticatorManager()
: AuthenticatorManager()
{
@@ -40,10 +42,12 @@
String VirtualAuthenticatorManager::createAuthenticator(const VirtualAuthenticatorConfiguration& config)
{
- if (config.transport != WebCore::AuthenticatorTransport::Internal)
+ if (config.transport != WebCore::AuthenticatorTransport::Internal && config.transport != WebCore::AuthenticatorTransport::Usb)
UNIMPLEMENTED();
auto id = createVersion4UUIDString();
m_virtualAuthenticators.set(id, makeUniqueRef<VirtualAuthenticatorConfiguration>(config));
+ Vector<VirtualCredential> credentials;
+ m_credentialsByAuthenticator.set(id, WTFMove(credentials));
return id;
}
@@ -53,12 +57,18 @@
return m_virtualAuthenticators.remove(id);
}
+void VirtualAuthenticatorManager::addCredential(const String& authenticatorId, const VirtualCredential& credential)
+{
+ m_credentialsByAuthenticator.get(authenticatorId).append(credential);
+}
+
UniqueRef<AuthenticatorTransportService> VirtualAuthenticatorManager::createService(WebCore::AuthenticatorTransport transport, AuthenticatorTransportService::Observer& observer) const
{
- Vector<VirtualAuthenticatorConfiguration> configs;
- for (auto& config : m_virtualAuthenticators.values()) {
- if (config.get().transport == transport)
- configs.append(config.get());
+ Vector<std::pair<String, VirtualAuthenticatorConfiguration>> configs;
+ for (auto& id : m_virtualAuthenticators.keys()) {
+ auto config = m_virtualAuthenticators.get(id);
+ if (config->transport == transport)
+ configs.append(std::pair { id, *config });
}
return VirtualService::createVirtual(transport, observer, configs);
}
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorManager.h (291422 => 291423)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorManager.h 2022-03-17 18:15:38 UTC (rev 291422)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorManager.h 2022-03-17 18:28:13 UTC (rev 291423)
@@ -29,8 +29,11 @@
#include "AuthenticatorManager.h"
#include "VirtualAuthenticatorConfiguration.h"
+#include "VirtualCredential.h"
+#include <wtf/WeakPtr.h>
namespace WebKit {
+struct VirtualCredential;
class VirtualAuthenticatorManager final : public AuthenticatorManager {
public:
@@ -40,14 +43,20 @@
bool removeAuthenticator(const String& /*authenticatorId*/);
bool isVirtual() const final { return true; }
- void runPanel();
- void selectAssertionResponse(Vector<Ref<WebCore::AuthenticatorAssertionResponse>>&&, WebAuthenticationSource, CompletionHandler<void(WebCore::AuthenticatorAssertionResponse*)>&&);
- void decidePolicyForLocalAuthenticator(CompletionHandler<void(LocalAuthenticatorPolicy)>&&);
+ void addCredential(const String&, const VirtualCredential&);
+
+protected:
+ void decidePolicyForLocalAuthenticator(CompletionHandler<void(LocalAuthenticatorPolicy)>&&) override;
+ void selectAssertionResponse(Vector<Ref<WebCore::AuthenticatorAssertionResponse>>&&, WebAuthenticationSource, CompletionHandler<void(WebCore::AuthenticatorAssertionResponse*)>&&) override;
+
+
private:
UniqueRef<AuthenticatorTransportService> createService(WebCore::AuthenticatorTransport, AuthenticatorTransportService::Observer&) const final;
+ void runPanel() override;
HashMap<String, UniqueRef<VirtualAuthenticatorConfiguration>> m_virtualAuthenticators;
+ HashMap<String, Vector<VirtualCredential>> m_credentialsByAuthenticator;
};
} // namespace WebKit
Copied: trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorUtils.h (from rev 291422, trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualService.h) (0 => 291423)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorUtils.h (rev 0)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorUtils.h 2022-03-17 18:28:13 UTC (rev 291423)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEB_AUTHN)
+
+#include "VirtualAuthenticatorConfiguration.h"
+
+namespace WebKit {
+
+uint8_t flagsForConfig(const VirtualAuthenticatorConfiguration&);
+RetainPtr<SecKeyRef> createPrivateKey();
+std::pair<Vector<uint8_t>, Vector<uint8_t>> credentialIdAndCosePubKeyForPrivateKey(RetainPtr<SecKeyRef> privateKey);
+String base64PrivateKey(RetainPtr<SecKeyRef> privateKey);
+
+} // namespace WebKit
+
+#endif // ENABLE(WEB_AUTHN)
Added: trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorUtils.mm (0 => 291423)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorUtils.mm (rev 0)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualAuthenticatorUtils.mm 2022-03-17 18:28:13 UTC (rev 291423)
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#include "config.h"
+#include "VirtualAuthenticatorUtils.h"
+
+#if ENABLE(WEB_AUTHN)
+
+#include <WebCore/WebAuthenticationConstants.h>
+#include <WebCore/WebAuthenticationUtils.h>
+#include <pal/crypto/CryptoDigest.h>
+
+namespace WebKit {
+using namespace WebCore;
+
+uint8_t flagsForConfig(const VirtualAuthenticatorConfiguration& config)
+{
+ uint8_t flags = WebAuthn::attestedCredentialDataIncludedFlag;
+ if (config.isUserConsenting)
+ flags = flags | WebAuthn::userPresenceFlag;
+ if (config.isUserVerified)
+ flags = flags | WebAuthn::userVerifiedFlag;
+ return flags;
+}
+
+RetainPtr<SecKeyRef> createPrivateKey()
+{
+ NSDictionary* options = @{
+ (id)kSecAttrKeyType: (id)kSecAttrKeyTypeECSECPrimeRandom,
+ (id)kSecAttrKeyClass: (id)kSecAttrKeyClassPrivate,
+ (id)kSecAttrKeySizeInBits: @256,
+ };
+ CFErrorRef errorRef = nullptr;
+ auto key = adoptCF(SecKeyCreateRandomKey(
+ (__bridge CFDictionaryRef)options,
+ &errorRef
+ ));
+ if (errorRef)
+ return nullptr;
+ return key;
+}
+
+std::pair<Vector<uint8_t>, Vector<uint8_t>> credentialIdAndCosePubKeyForPrivateKey(RetainPtr<SecKeyRef> privateKey)
+{
+ RetainPtr<CFDataRef> publicKeyDataRef;
+ {
+ auto publicKey = adoptCF(SecKeyCopyPublicKey(privateKey.get()));
+ CFErrorRef errorRef = nullptr;
+ publicKeyDataRef = adoptCF(SecKeyCopyExternalRepresentation(publicKey.get(), &errorRef));
+ auto retainError = adoptCF(errorRef);
+ ASSERT(!errorRef);
+ ASSERT(((NSData *)publicKeyDataRef.get()).length == (1 + 2 * ES256FieldElementLength)); // 04 | X | Y
+ }
+ NSData *nsPublicKeyData = (NSData *)publicKeyDataRef.get();
+
+ Vector<uint8_t> credentialId;
+ {
+ auto digest = PAL::CryptoDigest::create(PAL::CryptoDigest::Algorithm::SHA_1);
+ digest->addBytes(nsPublicKeyData.bytes, nsPublicKeyData.length);
+ credentialId = digest->computeHash();
+ }
+
+ Vector<uint8_t> cosePublicKey;
+ {
+ // COSE Encoding
+ Vector<uint8_t> x(ES256FieldElementLength);
+ [nsPublicKeyData getBytes: x.data() range:NSMakeRange(1, ES256FieldElementLength)];
+ Vector<uint8_t> y(ES256FieldElementLength);
+ [nsPublicKeyData getBytes: y.data() range:NSMakeRange(1 + ES256FieldElementLength, ES256FieldElementLength)];
+ cosePublicKey = encodeES256PublicKeyAsCBOR(WTFMove(x), WTFMove(y));
+ }
+ return std::pair { credentialId, cosePublicKey };
+}
+
+String base64PrivateKey(RetainPtr<SecKeyRef> privateKey)
+{
+ CFErrorRef errorRef = nullptr;
+ auto privateKeyRep = adoptCF(SecKeyCopyExternalRepresentation((__bridge SecKeyRef)((id)privateKey.get()), &errorRef));
+ auto retainError = adoptCF(errorRef);
+ if (errorRef) {
+ ASSERT_NOT_REACHED();
+ return "";
+ }
+ NSData *nsPrivateKeyRep = (NSData *)privateKeyRep.get();
+
+ return String([nsPrivateKeyRep base64EncodedStringWithOptions:0]);
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(WEB_AUTHN)
Copied: trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualCredential.h (from rev 291422, trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualService.h) (0 => 291423)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualCredential.h (rev 0)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualCredential.h 2022-03-17 18:28:13 UTC (rev 291423)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEB_AUTHN)
+
+#include <WebCore/AuthenticatorTransport.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebKit {
+
+struct VirtualCredential {
+ WTF_MAKE_STRUCT_FAST_ALLOCATED;
+ Vector<uint8_t> credentialId;
+ String rpId;
+ String privateKey;
+ std::optional<Vector<uint8_t>> userHandle;
+ uint64_t signCount;
+ bool isResidentCredential;
+ bool isVerificationRequired;
+};
+
+} // namespace WebKit
+
+#endif // ENABLE(WEB_AUTHN)
Added: trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualHidConnection.cpp (0 => 291423)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualHidConnection.cpp (rev 0)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualHidConnection.cpp 2022-03-17 18:28:13 UTC (rev 291423)
@@ -0,0 +1,249 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "VirtualHidConnection.h"
+
+#if ENABLE(WEB_AUTHN)
+
+#include "VirtualAuthenticatorManager.h"
+#include "VirtualAuthenticatorUtils.h"
+#include <WebCore/CBORReader.h>
+#include <WebCore/CBORWriter.h>
+#include <WebCore/FidoConstants.h>
+#include <WebCore/WebAuthenticationUtils.h>
+#include <wtf/BlockPtr.h>
+#include <wtf/CryptographicallyRandomNumber.h>
+#include <wtf/RunLoop.h>
+
+namespace WebKit {
+using namespace cbor;
+using namespace fido;
+using namespace WebCore;
+
+const size_t CtapChannelIdSize = 4;
+
+VirtualHidConnection::VirtualHidConnection(const String& authenticatorId, const VirtualAuthenticatorConfiguration& configuration, const WeakPtr<VirtualAuthenticatorManager>& manager)
+ : HidConnection(nullptr)
+ , m_manager(manager)
+ , m_configuration(configuration)
+ , m_authenticatorId(authenticatorId)
+{
+}
+
+void VirtualHidConnection::initialize()
+{
+ setIsInitialized(true);
+}
+
+void VirtualHidConnection::terminate()
+{
+ setIsInitialized(false);
+}
+
+auto VirtualHidConnection::sendSync(const Vector<uint8_t>& data) -> DataSent
+{
+ ASSERT(isInitialized());
+ return DataSent::Yes;
+}
+
+void VirtualHidConnection::send(Vector<uint8_t>&& data, DataSentCallback&& callback)
+{
+ ASSERT(isInitialized());
+ auto task = makeBlockPtr([weakThis = WeakPtr { *this }, data = "" callback = WTFMove(callback)]() mutable {
+ ASSERT(!RunLoop::isMain());
+ RunLoop::main().dispatch([weakThis, data = "" callback = WTFMove(callback)]() mutable {
+ if (!weakThis) {
+ callback(DataSent::No);
+ return;
+ }
+
+ weakThis->assembleRequest(WTFMove(data));
+
+ callback(DataSent::Yes);
+ });
+ });
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), task.get());
+}
+
+void VirtualHidConnection::assembleRequest(Vector<uint8_t>&& data)
+{
+ if (!m_requestMessage) {
+ m_requestMessage = FidoHidMessage::createFromSerializedData(data);
+ ASSERT(m_requestMessage);
+ } else {
+ auto status = m_requestMessage->addContinuationPacket(data);
+ ASSERT_UNUSED(status, status);
+ }
+
+ if (m_requestMessage->messageComplete())
+ parseRequest();
+}
+
+void VirtualHidConnection::receiveHidMessage(fido::FidoHidMessage&& message)
+{
+ while (message.numPackets()) {
+ auto report = message.popNextPacket();
+ RunLoop::main().dispatch([report = WTFMove(report), weakThis = WeakPtr { *this }]() mutable {
+ if (!weakThis)
+ return;
+ weakThis->receiveReport(WTFMove(report));
+ });
+ }
+}
+
+void VirtualHidConnection::recieveResponseCode(fido::CtapDeviceResponseCode code)
+{
+ Vector<uint8_t> buffer;
+ buffer.append(static_cast<uint8_t>(code));
+
+ auto message = FidoHidMessage::create(m_currentChannel, FidoHidDeviceCommand::kCbor, WTFMove(buffer));
+ receiveHidMessage(WTFMove(*message));
+}
+
+void VirtualHidConnection::parseRequest()
+{
+ if (!m_requestMessage)
+ return;
+ if (!m_manager)
+ return;
+ auto* manager = m_manager.get();
+ m_currentChannel = m_requestMessage->channelId();
+ switch (m_requestMessage->cmd()) {
+ case FidoHidDeviceCommand::kInit: {
+ m_nonce = m_requestMessage->getMessagePayload();
+ ASSERT(m_nonce.size() == kHidInitNonceLength);
+ Vector<uint8_t> payload;
+ payload.reserveInitialCapacity(kHidInitResponseSize);
+ payload.appendVector(m_nonce);
+ size_t writePosition = payload.size();
+ payload.grow(kHidInitResponseSize);
+ cryptographicallyRandomValues(payload.data() + writePosition, CtapChannelIdSize);
+ auto channel = kHidBroadcastChannel;
+ FidoHidInitPacket initPacket(channel, FidoHidDeviceCommand::kInit, WTFMove(payload), payload.size());
+ receiveReport(initPacket.getSerializedData());
+ break;
+ }
+ case FidoHidDeviceCommand::kCbor: {
+ auto payload = m_requestMessage->getMessagePayload();
+ ASSERT(payload.size());
+ auto cmd = static_cast<CtapRequestCommand>(payload[0]);
+ payload.remove(0);
+ auto requestMap = CBORReader::read(payload);
+ ASSERT(requestMap || cmd == CtapRequestCommand::kAuthenticatorGetNextAssertion);
+ if (cmd == CtapRequestCommand::kAuthenticatorMakeCredential) {
+ VirtualCredential credential;
+ auto it = requestMap->getMap().find(CBORValue(kCtapMakeCredentialRequestOptionsKey)); // Find options.
+ if (it != requestMap->getMap().end()) {
+ auto& optionMap = it->second.getMap();
+
+ auto itr = optionMap.find(CBORValue(kResidentKeyMapKey));
+ if (itr != optionMap.end()) {
+ auto requireResidentKey = itr->second.getBool();
+ // https://fidoalliance.org/specs/fido-v2.1-rd-20210309/fido-client-to-authenticator-protocol-v2.1-rd-20210309.html#op-makecred-step-options
+ if (requireResidentKey && !m_configuration.hasResidentKey) {
+ recieveResponseCode(CtapDeviceResponseCode::kCtap2ErrUnsupportedOption);
+ return;
+ }
+ if (requireResidentKey)
+ credential.isResidentCredential = true;
+ }
+
+ itr = optionMap.find(CBORValue(kUserVerificationMapKey));
+ if (itr != optionMap.end()) {
+ auto requireUserVerification = itr->second.getBool();
+ if (requireUserVerification && !m_configuration.hasUserVerification) {
+ recieveResponseCode(CtapDeviceResponseCode::kCtap2ErrInvalidOption);
+ return;
+ }
+ if (requireUserVerification && !m_configuration.isUserVerified) {
+ recieveResponseCode(CtapDeviceResponseCode::kCtap2ErrOperationDenied);
+ return;
+ }
+ credential.isVerificationRequired = requireUserVerification;
+ }
+ }
+ it = requestMap->getMap().find(CBORValue(kCtapMakeCredentialRpKey));
+ if (it == requestMap->getMap().end()) {
+ recieveResponseCode(CtapDeviceResponseCode::kCtap2ErrMissingParameter);
+ return;
+ }
+ auto& rpEntity = it->second.getMap();
+ it = rpEntity.find(CBORValue(kEntityIdMapKey));
+ if (it == rpEntity.end()) {
+ recieveResponseCode(CtapDeviceResponseCode::kCtap2ErrMissingParameter);
+ return;
+ }
+ credential.rpId = it->second.getString();
+ auto privateKey = createPrivateKey();
+ credential.privateKey = base64PrivateKey(privateKey);
+
+ it = requestMap->getMap().find(CBORValue(kCtapMakeCredentialUserKey));
+ if (it == requestMap->getMap().end()) {
+ recieveResponseCode(CtapDeviceResponseCode::kCtap2ErrMissingParameter);
+ return;
+ }
+ auto& userEntity = it->second.getMap();
+ it = userEntity.find(CBORValue(kEntityIdMapKey));
+ if (it == userEntity.end()) {
+ recieveResponseCode(CtapDeviceResponseCode::kCtap2ErrMissingParameter);
+ return;
+ }
+ credential.userHandle = it->second.getByteString();
+
+ manager->addCredential(m_authenticatorId, credential);
+ auto credentialIdAndCosePubKey = credentialIdAndCosePubKeyForPrivateKey(privateKey);
+
+ auto attestedCredentialData = buildAttestedCredentialData(Vector<uint8_t>(aaguidLength, 0), credentialIdAndCosePubKey.first, credentialIdAndCosePubKey.second);
+
+ auto authenticatorData = buildAuthData(credential.rpId, flagsForConfig(m_configuration), credential.signCount, attestedCredentialData);
+ CBORValue::MapValue response;
+ response[CBORValue(2)] = CBORValue(authenticatorData);
+
+ auto attObj = buildAttestationMap(WTFMove(authenticatorData), "", { }, AttestationConveyancePreference::None);
+
+ response[CBORValue(1)] = CBORValue("none");
+ response[CBORValue(3)] = CBORValue(attObj);
+ auto payload = CBORWriter::write(CBORValue(response));
+ Vector<uint8_t> buffer;
+ buffer.reserveCapacity(payload->size() + 1);
+ buffer.append(static_cast<uint8_t>(fido::CtapDeviceResponseCode::kSuccess));
+ buffer.appendVector(*payload);
+
+ auto message = FidoHidMessage::create(m_requestMessage->channelId(), FidoHidDeviceCommand::kCbor, WTFMove(buffer));
+ receiveHidMessage(WTFMove(*message));
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ m_requestMessage = std::nullopt;
+}
+
+
+} // namespace WebKit
+
+#endif // ENABLE(WEB_AUTHN)
Copied: trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualHidConnection.h (from rev 291422, trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualService.h) (0 => 291423)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualHidConnection.h (rev 0)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualHidConnection.h 2022-03-17 18:28:13 UTC (rev 291423)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2022 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEB_AUTHN)
+
+#include "HidConnection.h"
+#include "VirtualAuthenticatorConfiguration.h"
+#include <WebCore/FidoHidMessage.h>
+#include <wtf/WeakPtr.h>
+
+namespace WebKit {
+struct VirtualAuthenticatorConfiguration;
+class VirtualAuthenticatorManager;
+
+class VirtualHidConnection final : public CanMakeWeakPtr<VirtualHidConnection>, public HidConnection {
+public:
+ explicit VirtualHidConnection(const String& authenticatorId, const VirtualAuthenticatorConfiguration&, const WeakPtr<VirtualAuthenticatorManager>&);
+
+private:
+ void initialize() final;
+ void terminate() final;
+ DataSent sendSync(const Vector<uint8_t>& data) final;
+ void send(Vector<uint8_t>&& data, DataSentCallback&&) final;
+ void assembleRequest(Vector<uint8_t>&&);
+ void parseRequest();
+
+ void receiveHidMessage(fido::FidoHidMessage&&);
+ void recieveResponseCode(fido::CtapDeviceResponseCode);
+
+ WeakPtr<VirtualAuthenticatorManager> m_manager;
+ VirtualAuthenticatorConfiguration m_configuration;
+ std::optional<fido::FidoHidMessage> m_requestMessage;
+ Vector<uint8_t> m_nonce;
+ uint32_t m_currentChannel { fido::kHidBroadcastChannel };
+ String m_authenticatorId;
+};
+} // namespace WebKit
+#endif
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualService.h (291422 => 291423)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualService.h 2022-03-17 18:15:38 UTC (rev 291422)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualService.h 2022-03-17 18:28:13 UTC (rev 291423)
@@ -29,18 +29,22 @@
#include "AuthenticatorTransportService.h"
#include "VirtualAuthenticatorConfiguration.h"
+#include "VirtualCredential.h"
+#include <wtf/WeakPtr.h>
namespace WebKit {
+class VirtualAuthenticatorManager;
+
class VirtualService : public AuthenticatorTransportService {
public:
- explicit VirtualService(Observer&, const Vector<VirtualAuthenticatorConfiguration>&);
+ explicit VirtualService(Observer&, Vector<std::pair<String, VirtualAuthenticatorConfiguration>>&);
- static UniqueRef<AuthenticatorTransportService> createVirtual(WebCore::AuthenticatorTransport, Observer&, const Vector<VirtualAuthenticatorConfiguration>& configs);
+ static UniqueRef<AuthenticatorTransportService> createVirtual(WebCore::AuthenticatorTransport, Observer&, Vector<std::pair<String, VirtualAuthenticatorConfiguration>>&);
private:
void startDiscoveryInternal() final;
- Vector<VirtualAuthenticatorConfiguration> m_configurations;
+ Vector<std::pair<String, VirtualAuthenticatorConfiguration>> m_authenticators;
};
} // namespace WebKit
Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualService.mm (291422 => 291423)
--- trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualService.mm 2022-03-17 18:15:38 UTC (rev 291422)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/Virtual/VirtualService.mm 2022-03-17 18:28:13 UTC (rev 291423)
@@ -28,32 +28,54 @@
#if ENABLE(WEB_AUTHN)
+#import "CtapAuthenticator.h"
+#import "CtapHidDriver.h"
#import "LocalAuthenticator.h"
+#import "VirtualAuthenticatorManager.h"
+#import "VirtualHidConnection.h"
#import "VirtualLocalConnection.h"
+#import <WebCore/FidoConstants.h>
+#import <WebCore/WebAuthenticationConstants.h>
+#import <wtf/UniqueRef.h>
#import <wtf/text/WTFString.h>
namespace WebKit {
+using namespace fido;
+using namespace WebCore;
-VirtualService::VirtualService(Observer& observer, const Vector<VirtualAuthenticatorConfiguration>& configurations)
- : AuthenticatorTransportService(observer), m_configurations(configurations)
+VirtualService::VirtualService(Observer& observer, Vector<std::pair<String, VirtualAuthenticatorConfiguration>>& authenticators)
+ : AuthenticatorTransportService(observer), m_authenticators(authenticators)
{
}
-UniqueRef<AuthenticatorTransportService> VirtualService::createVirtual(WebCore::AuthenticatorTransport transport, Observer& observer, const Vector<VirtualAuthenticatorConfiguration>& configs)
+UniqueRef<AuthenticatorTransportService> VirtualService::createVirtual(WebCore::AuthenticatorTransport transport, Observer& observer, Vector<std::pair<String, VirtualAuthenticatorConfiguration>>& authenticators)
{
- return makeUniqueRef<VirtualService>(observer, configs);
+ return makeUniqueRef<VirtualService>(observer, authenticators);
}
+static AuthenticatorGetInfoResponse authenticatorInfoForConfig(const VirtualAuthenticatorConfiguration& config)
+{
+ AuthenticatorGetInfoResponse infoResponse({ ProtocolVersion::kCtap }, Vector<uint8_t>(aaguidLength, 0u));
+ AuthenticatorSupportedOptions options;
+ infoResponse.setOptions(WTFMove(options));
+ return infoResponse;
+}
+
void VirtualService::startDiscoveryInternal()
{
- for (auto& config : m_configurations) {
+ for (auto& authenticator : m_authenticators) {
if (!observer())
return;
+ auto config = authenticator.second;
+ auto authenticatorId = authenticator.first;
switch (config.transport) {
+ case WebCore::AuthenticatorTransport::Usb:
+ observer()->authenticatorAdded(CtapAuthenticator::create(WTF::makeUnique<CtapHidDriver>(makeUniqueRef<VirtualHidConnection>(authenticatorId, config, WeakPtr { static_cast<VirtualAuthenticatorManager *>(observer()) })), authenticatorInfoForConfig(config)));
+ break;
case WebCore::AuthenticatorTransport::Internal:
observer()->authenticatorAdded(LocalAuthenticator::create(makeUniqueRef<VirtualLocalConnection>(config)));
- break;
+ break;
default:
UNIMPLEMENTED();
}
Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (291422 => 291423)
--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2022-03-17 18:15:38 UTC (rev 291422)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj 2022-03-17 18:28:13 UTC (rev 291423)
@@ -1081,6 +1081,8 @@
51FAEC3A1B0657630009C4E7 /* AuxiliaryProcessMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 51FAEC371B0657310009C4E7 /* AuxiliaryProcessMessages.h */; };
51FAEC3B1B0657680009C4E7 /* AuxiliaryProcessMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51FAEC361B0657310009C4E7 /* AuxiliaryProcessMessageReceiver.cpp */; };
51FD18B61651FBAD00DBE1CE /* NetworkResourceLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 51FD18B41651FBAD00DBE1CE /* NetworkResourceLoader.h */; };
+ 5252A51927E048740094BEB9 /* VirtualHidConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 5252A51727E048740094BEB9 /* VirtualHidConnection.h */; };
+ 5252A51A27E048740094BEB9 /* VirtualHidConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5252A51827E048740094BEB9 /* VirtualHidConnection.cpp */; };
52688AB427D7CE40003577A2 /* _WKResidentKeyRequirement.h in Headers */ = {isa = PBXBuildFile; fileRef = 52688AB327D7CE40003577A2 /* _WKResidentKeyRequirement.h */; settings = {ATTRIBUTES = (Private, ); }; };
5272D4C91E735F0900EB4290 /* WKProtectionSpaceNS.h in Headers */ = {isa = PBXBuildFile; fileRef = 5272D4C71E735F0900EB4290 /* WKProtectionSpaceNS.h */; settings = {ATTRIBUTES = (Private, ); }; };
528C37C1195CBB1A00D8B9CC /* WKBackForwardListPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1A9F28101958F478008CAC72 /* WKBackForwardListPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -1093,6 +1095,9 @@
52CDC5CA2731DA0D00A3E3EB /* VirtualAuthenticatorManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 52CDC5C32731DA0C00A3E3EB /* VirtualAuthenticatorManager.h */; };
52D5A1B01C57495A00DE34A3 /* VideoFullscreenManagerProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 52D5A1AA1C57494E00DE34A3 /* VideoFullscreenManagerProxy.h */; };
52F060E11654318500F3281B /* NetworkContentRuleListManagerMessageReceiver.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52F060DD1654317500F3281B /* NetworkContentRuleListManagerMessageReceiver.cpp */; };
+ 52F4B46927E1197700FFD129 /* VirtualAuthenticatorUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 52F4B46727E1197700FFD129 /* VirtualAuthenticatorUtils.h */; };
+ 52F4B46A27E1197700FFD129 /* VirtualAuthenticatorUtils.mm in Sources */ = {isa = PBXBuildFile; fileRef = 52F4B46827E1197700FFD129 /* VirtualAuthenticatorUtils.mm */; };
+ 52F4B46D27E125A800FFD129 /* VirtualCredential.h in Headers */ = {isa = PBXBuildFile; fileRef = 52F4B46B27E125A800FFD129 /* VirtualCredential.h */; };
532159551DBAE7290054AA3C /* NetworkSessionCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 532159501DBAE6D70054AA3C /* NetworkSessionCocoa.h */; };
532159561DBAE72D0054AA3C /* NetworkDataTaskCocoa.h in Headers */ = {isa = PBXBuildFile; fileRef = 5321594F1DBAE6D70054AA3C /* NetworkDataTaskCocoa.h */; };
535BCB922069C49C00CCCE02 /* NetworkActivityTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 535BCB902069C49C00CCCE02 /* NetworkActivityTracker.h */; };
@@ -4644,6 +4649,8 @@
51FB0902163A3B1C00EC324A /* NetworkProcessConnection.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; name = NetworkProcessConnection.messages.in; path = Network/NetworkProcessConnection.messages.in; sourceTree = "<group>"; };
51FD18B31651FBAD00DBE1CE /* NetworkResourceLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NetworkResourceLoader.cpp; sourceTree = "<group>"; };
51FD18B41651FBAD00DBE1CE /* NetworkResourceLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkResourceLoader.h; sourceTree = "<group>"; };
+ 5252A51727E048740094BEB9 /* VirtualHidConnection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VirtualHidConnection.h; sourceTree = "<group>"; };
+ 5252A51827E048740094BEB9 /* VirtualHidConnection.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = VirtualHidConnection.cpp; sourceTree = "<group>"; };
52688AB327D7CE40003577A2 /* _WKResidentKeyRequirement.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = _WKResidentKeyRequirement.h; path = UIProcess/API/Cocoa/_WKResidentKeyRequirement.h; sourceTree = "<group>"; };
5272D4C71E735F0900EB4290 /* WKProtectionSpaceNS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKProtectionSpaceNS.h; path = mac/WKProtectionSpaceNS.h; sourceTree = "<group>"; };
5272D4C81E735F0900EB4290 /* WKProtectionSpaceNS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKProtectionSpaceNS.mm; path = mac/WKProtectionSpaceNS.mm; sourceTree = "<group>"; };
@@ -4663,6 +4670,9 @@
52EB68CB279E2145005C98D9 /* ARKitSoftLink.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ARKitSoftLink.h; sourceTree = "<group>"; };
52EB68CC279E2145005C98D9 /* ARKitSoftLink.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ARKitSoftLink.mm; sourceTree = "<group>"; };
52F060DD1654317500F3281B /* NetworkContentRuleListManagerMessageReceiver.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = NetworkContentRuleListManagerMessageReceiver.cpp; path = DerivedSources/WebKit/NetworkContentRuleListManagerMessageReceiver.cpp; sourceTree = BUILT_PRODUCTS_DIR; };
+ 52F4B46727E1197700FFD129 /* VirtualAuthenticatorUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VirtualAuthenticatorUtils.h; sourceTree = "<group>"; };
+ 52F4B46827E1197700FFD129 /* VirtualAuthenticatorUtils.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = VirtualAuthenticatorUtils.mm; sourceTree = "<group>"; };
+ 52F4B46B27E125A800FFD129 /* VirtualCredential.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VirtualCredential.h; sourceTree = "<group>"; };
5315876B2076B713004BF9F3 /* NetworkActivityTrackerCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetworkActivityTrackerCocoa.mm; sourceTree = "<group>"; };
5321594F1DBAE6D70054AA3C /* NetworkDataTaskCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkDataTaskCocoa.h; sourceTree = "<group>"; };
532159501DBAE6D70054AA3C /* NetworkSessionCocoa.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetworkSessionCocoa.h; sourceTree = "<group>"; };
@@ -9858,6 +9868,11 @@
52CDC5BD2731DA0C00A3E3EB /* VirtualAuthenticatorConfiguration.h */,
52CDC5BF2731DA0C00A3E3EB /* VirtualAuthenticatorManager.cpp */,
52CDC5C32731DA0C00A3E3EB /* VirtualAuthenticatorManager.h */,
+ 52F4B46727E1197700FFD129 /* VirtualAuthenticatorUtils.h */,
+ 52F4B46827E1197700FFD129 /* VirtualAuthenticatorUtils.mm */,
+ 52F4B46B27E125A800FFD129 /* VirtualCredential.h */,
+ 5252A51827E048740094BEB9 /* VirtualHidConnection.cpp */,
+ 5252A51727E048740094BEB9 /* VirtualHidConnection.h */,
52CDC5C02731DA0C00A3E3EB /* VirtualLocalConnection.h */,
52CDC5C22731DA0C00A3E3EB /* VirtualLocalConnection.mm */,
52CDC5C12731DA0C00A3E3EB /* VirtualService.h */,
@@ -13656,6 +13671,9 @@
2684055318B86ED60022C38B /* ViewUpdateDispatcherMessages.h in Headers */,
52CDC5C42731DA0D00A3E3EB /* VirtualAuthenticatorConfiguration.h in Headers */,
52CDC5CA2731DA0D00A3E3EB /* VirtualAuthenticatorManager.h in Headers */,
+ 52F4B46927E1197700FFD129 /* VirtualAuthenticatorUtils.h in Headers */,
+ 52F4B46D27E125A800FFD129 /* VirtualCredential.h in Headers */,
+ 5252A51927E048740094BEB9 /* VirtualHidConnection.h in Headers */,
52CDC5C72731DA0D00A3E3EB /* VirtualLocalConnection.h in Headers */,
52CDC5C82731DA0D00A3E3EB /* VirtualService.h in Headers */,
2684054418B85A630022C38B /* VisibleContentRectUpdateInfo.h in Headers */,
@@ -16152,6 +16170,8 @@
2D819BA11862800E001F03D1 /* ViewGestureGeometryCollectorMessageReceiver.cpp in Sources */,
2684055218B86ED60022C38B /* ViewUpdateDispatcherMessageReceiver.cpp in Sources */,
52CDC5C62731DA0D00A3E3EB /* VirtualAuthenticatorManager.cpp in Sources */,
+ 52F4B46A27E1197700FFD129 /* VirtualAuthenticatorUtils.mm in Sources */,
+ 5252A51A27E048740094BEB9 /* VirtualHidConnection.cpp in Sources */,
52CDC5C92731DA0D00A3E3EB /* VirtualLocalConnection.mm in Sources */,
52CDC5C52731DA0D00A3E3EB /* VirtualService.mm in Sources */,
1A60224C18C16B9F00C3E8C9 /* VisitedLinkStoreMessageReceiver.cpp in Sources */,