⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 285698 in webkit


Ignore:
Timestamp:
Nov 11, 2021, 5:42:42 PM (5 years ago)
Author:
Brent Fulgham
Message:

[WebAuthn] Stop serializing BufferSource and Vector<uint8_t> duplicates of identifiers
https://bugs.webkit.org/show_bug.cgi?id=233011
<rdar://problem/85313807>

Reviewed by Chris Dumez.

The original WebAuthn logic converted WebCore::BufferSource objects to Vector<uint8_t>
during serialization, which created a weird design where some code dealt with BufferSource
objects, and other with Vectors, and lots of converting to and from these types. It also caused
WebAuthn data structures to have two places where this information might live, with the
UIProcess using one representation, and the WebContent process using another.

This patch revises the code as follows:

  1. The identifiers are always stored as BufferSource, and the same member is used in UIProcess and WebContent process when accessing this information.
  2. We now serialize BufferSource directly.

Tested by existing WebAuthn test cases (API and Layout tests)

Source/WebCore:

  • Modules/webauthn/PublicKeyCredentialCreationOptions.h:

(WebCore::PublicKeyCredentialCreationOptions::encode const):
(WebCore::PublicKeyCredentialCreationOptions::decode):

  • Modules/webauthn/PublicKeyCredentialDescriptor.h:

(WebCore::PublicKeyCredentialDescriptor::encode const):
(WebCore::PublicKeyCredentialDescriptor::decode):

  • Modules/webauthn/PublicKeyCredentialRequestOptions.h:

(WebCore::PublicKeyCredentialRequestOptions::decode):

  • Modules/webauthn/cbor/CBORValue.cpp:

(cbor::CBORValue::CBORValue):

  • Modules/webauthn/cbor/CBORValue.h:
  • Modules/webauthn/fido/DeviceRequestConverter.cpp:

(fido::convertUserEntityToCBOR):
(fido::convertDescriptorToCBOR):

  • Modules/webauthn/fido/U2fCommandConstructor.cpp:

(fido::WebCore::constructU2fSignCommand):
(fido::convertToU2fCheckOnlySignCommand):
(fido::convertToU2fSignCommand):

  • Modules/webauthn/fido/U2fCommandConstructor.h:
  • Modules/webauthn/fido/U2fResponseConverter.cpp:

(fido::readU2fSignResponse):

  • Modules/webauthn/fido/U2fResponseConverter.h:
  • bindings/js/BufferSource.h:

(WebCore::BufferSource::encode const):
(WebCore::BufferSource::decode):
(WebCore::toBufferSource):

Source/WebKit:

  • UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm:

(publicKeyCredentialUserEntity):
(publicKeyCredentialDescriptors):

  • UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm:

(WebKit::LocalAuthenticatorInternal::produceHashSet):
(WebKit::LocalAuthenticator::continueMakeCredentialAfterUserVerification):
(WebKit::LocalAuthenticator::deleteDuplicateCredential const):

  • UIProcess/WebAuthentication/Cocoa/WebAuthenticatorCoordinatorProxy.mm:

(WebKit::toASCDescriptor):
(WebKit::configureRegistrationRequestContext):
(WebKit::configurationAssertionRequestContext):

  • UIProcess/WebAuthentication/fido/U2fAuthenticator.cpp:

(WebKit::U2fAuthenticator::issueSignCommand):
(WebKit::U2fAuthenticator::continueSignCommandAfterResponseReceived):

Tools:

  • TestWebKitAPI/Tests/WebCore/CtapRequestTest.cpp:

(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebCore/CtapResponseTest.cpp:

(TestWebKitAPI::getTestCredentialRawIdBytes):
(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebCore/U2fCommandConstructorTest.cpp:

(TestWebKitAPI::constructMakeCredentialRequest):
(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm:

(TestWebKitAPI::TEST):

Location:
trunk
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r285694 r285698  
     12021-11-11  Brent Fulgham  <bfulgham@apple.com>
     2
     3        [WebAuthn] Stop serializing BufferSource and Vector<uint8_t> duplicates of identifiers
     4        https://bugs.webkit.org/show_bug.cgi?id=233011
     5        <rdar://problem/85313807>
     6
     7        Reviewed by Chris Dumez.
     8
     9        The original WebAuthn logic converted WebCore::BufferSource objects to Vector<uint8_t>
     10        during serialization, which created a weird design where some code dealt with BufferSource
     11        objects, and other with Vectors, and lots of converting to and from these types. It also caused
     12        WebAuthn data structures to have two places where this information might live, with the
     13        UIProcess using one representation, and the WebContent process using another.
     14
     15        This patch revises the code as follows:
     16
     17        1. The identifiers are always stored as BufferSource, and the same member is used in UIProcess
     18           and WebContent process when accessing this information.
     19        2. We now serialize BufferSource directly.
     20
     21        Tested by existing WebAuthn test cases (API and Layout tests)
     22
     23        * Modules/webauthn/PublicKeyCredentialCreationOptions.h:
     24        (WebCore::PublicKeyCredentialCreationOptions::encode const):
     25        (WebCore::PublicKeyCredentialCreationOptions::decode):
     26        * Modules/webauthn/PublicKeyCredentialDescriptor.h:
     27        (WebCore::PublicKeyCredentialDescriptor::encode const):
     28        (WebCore::PublicKeyCredentialDescriptor::decode):
     29        * Modules/webauthn/PublicKeyCredentialRequestOptions.h:
     30        (WebCore::PublicKeyCredentialRequestOptions::decode):
     31        * Modules/webauthn/cbor/CBORValue.cpp:
     32        (cbor::CBORValue::CBORValue):
     33        * Modules/webauthn/cbor/CBORValue.h:
     34        * Modules/webauthn/fido/DeviceRequestConverter.cpp:
     35        (fido::convertUserEntityToCBOR):
     36        (fido::convertDescriptorToCBOR):
     37        * Modules/webauthn/fido/U2fCommandConstructor.cpp:
     38        (fido::WebCore::constructU2fSignCommand):
     39        (fido::convertToU2fCheckOnlySignCommand):
     40        (fido::convertToU2fSignCommand):
     41        * Modules/webauthn/fido/U2fCommandConstructor.h:
     42        * Modules/webauthn/fido/U2fResponseConverter.cpp:
     43        (fido::readU2fSignResponse):
     44        * Modules/webauthn/fido/U2fResponseConverter.h:
     45        * bindings/js/BufferSource.h:
     46        (WebCore::BufferSource::encode const):
     47        (WebCore::BufferSource::decode):
     48        (WebCore::toBufferSource):
     49
    1502021-11-11  Michael Catanzaro  <mcatanzaro@gnome.org>
    251
  • trunk/Source/WebCore/Modules/webauthn/PublicKeyCredentialCreationOptions.h

    r285475 r285698  
    11/*
    2  * Copyright (C) 2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2018-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    5252
    5353    struct UserEntity : public Entity {
    54         BufferSource id; // id becomes idVector once it is passed to UIProcess.
    55         Vector<uint8_t> idVector;
     54        BufferSource id;
    5655        String displayName;
    5756    };
     
    7776    UserEntity user;
    7877
    79     BufferSource challenge; // challenge becomes challengeVector once it is passed to UIProcess.
     78    BufferSource challenge;
    8079    Vector<Parameters> pubKeyCredParams;
    8180
     
    8685    mutable std::optional<AuthenticationExtensionsClientInputs> extensions;
    8786
    88     Vector<uint8_t> challengeVector;
    89 
    9087    template<class Encoder> void encode(Encoder&) const;
    9188    template<class Decoder> static std::optional<PublicKeyCredentialCreationOptions> decode(Decoder&);
     
    144141{
    145142    encoder << rp.id << rp.name << rp.icon;
    146     encoder << static_cast<uint64_t>(user.id.length());
    147     encoder.encodeFixedLengthData(user.id.data(), user.id.length(), 1);
     143    encoder << user.id;
    148144    encoder << user.displayName << user.name << user.icon << pubKeyCredParams << timeout << excludeCredentials << authenticatorSelection << attestation << extensions;
    149145    encoder << static_cast<uint64_t>(challenge.length());
     
    161157    if (!decoder.decode(result.rp.icon))
    162158        return std::nullopt;
    163     if (!decoder.decode(result.user.idVector))
     159    if (!decoder.decode(result.user.id))
    164160        return std::nullopt;
    165161    if (!decoder.decode(result.user.displayName))
     
    199195    result.extensions = WTFMove(*extensions);
    200196
    201     if (!decoder.decode(result.challengeVector))
     197    if (!decoder.decode(result.challenge))
    202198        return std::nullopt;
    203199
  • trunk/Source/WebCore/Modules/webauthn/PublicKeyCredentialDescriptor.h

    r278253 r285698  
    11/*
    2  * Copyright (C) 2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2018-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3636struct PublicKeyCredentialDescriptor {
    3737    PublicKeyCredentialType type;
    38     BufferSource id; // id becomes idVector once it is passed to UIProcess.
    39     Vector<uint8_t> idVector;
     38    BufferSource id;
    4039    Vector<AuthenticatorTransport> transports;
    4140
     
    4847{
    4948    encoder << type;
    50     encoder << static_cast<uint64_t>(id.length());
    51     encoder.encodeFixedLengthData(id.data(), id.length(), 1);
     49    encoder << id;
    5250    encoder << transports;
    5351}
     
    5957    if (!decoder.decode(result.type))
    6058        return std::nullopt;
    61     if (!decoder.decode(result.idVector))
     59    if (!decoder.decode(result.id))
    6260        return std::nullopt;
    6361    if (!decoder.decode(result.transports))
  • trunk/Source/WebCore/Modules/webauthn/PublicKeyCredentialRequestOptions.h

    r285475 r285698  
    11/*
    2  * Copyright (C) 2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2018-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3939struct PublicKeyCredentialRequestOptions {
    4040#if ENABLE(WEB_AUTHN)
    41     BufferSource challenge; // challenge becomes challengeVector once it is passed to UIProcess.
     41    BufferSource challenge;
    4242    std::optional<unsigned> timeout;
    4343    mutable String rpId;
     
    4646    std::optional<AuthenticatorAttachment> authenticatorAttachment;
    4747    mutable std::optional<AuthenticationExtensionsClientInputs> extensions;
    48 
    49     Vector<uint8_t> challengeVector;
    5048
    5149    template<class Encoder> void encode(Encoder&) const;
     
    9290    result.extensions = WTFMove(*extensions);
    9391
    94     if (!decoder.decode(result.challengeVector))
     92    if (!decoder.decode(result.challenge))
    9593        return std::nullopt;
    9694
  • trunk/Source/WebCore/Modules/webauthn/cbor/CBORValue.cpp

    r237983 r285698  
    11// Copyright 2017 The Chromium Authors. All rights reserved.
    2 // Copyright (C) 2018 Apple Inc. All rights reserved.
     2// Copyright (C) 2018-2021 Apple Inc. All rights reserved.
    33//
    44// Redistribution and use in source and binary forms, with or without
     
    3333#if ENABLE(WEB_AUTHN)
    3434
     35#include "BufferSource.h"
    3536#include <new>
    3637#include <utility>
     
    9899    : m_type(Type::ByteString)
    99100    , m_byteStringValue(WTFMove(inBytes))
     101{
     102}
     103
     104CBORValue::CBORValue(const WebCore::BufferSource& bufferSource)
     105    : m_type(Type::ByteString)
     106    , m_byteStringValue(bufferSource.data(), bufferSource.length())
    100107{
    101108}
  • trunk/Source/WebCore/Modules/webauthn/cbor/CBORValue.h

    r258293 r285698  
    11// Copyright 2017 The Chromium Authors. All rights reserved.
    2 // Copyright (C) 2018 Apple Inc. All rights reserved.
     2// Copyright (C) 2018-2021 Apple Inc. All rights reserved.
    33//
    44// Redistribution and use in source and binary forms, with or without
     
    3737#include <wtf/Vector.h>
    3838#include <wtf/text/WTFString.h>
     39
     40namespace WebCore {
     41class BufferSource;
     42}
    3943
    4044namespace cbor {
     
    128132    explicit CBORValue(BinaryValue&&);
    129133
     134    explicit CBORValue(const WebCore::BufferSource&);
     135
    130136    explicit CBORValue(const char*);
    131137    explicit CBORValue(String&&);
  • trunk/Source/WebCore/Modules/webauthn/fido/DeviceRequestConverter.cpp

    r278253 r285698  
    11// Copyright 2017 The Chromium Authors. All rights reserved.
    2 // Copyright (C) 2018 Apple Inc. All rights reserved.
     2// Copyright (C) 2018-2021 Apple Inc. All rights reserved.
    33//
    44// Redistribution and use in source and binary forms, with or without
     
    6262    if (!userEntity.icon.isEmpty())
    6363        userMap.emplace(CBORValue(kIconUrlMapKey), CBORValue(userEntity.icon));
    64     userMap.emplace(CBORValue(kEntityIdMapKey), CBORValue(userEntity.idVector));
     64    userMap.emplace(CBORValue(kEntityIdMapKey), CBORValue(userEntity.id));
    6565    userMap.emplace(CBORValue(kDisplayNameMapKey), CBORValue(userEntity.displayName));
    6666    return CBORValue(WTFMove(userMap));
     
    8484    CBORValue::MapValue cborDescriptorMap;
    8585    cborDescriptorMap[CBORValue(kCredentialTypeKey)] = CBORValue(publicKeyCredentialTypeToString(descriptor.type));
    86     cborDescriptorMap[CBORValue(kCredentialIdKey)] = CBORValue(descriptor.idVector);
     86    cborDescriptorMap[CBORValue(kCredentialIdKey)] = CBORValue(descriptor.id);
    8787    return CBORValue(WTFMove(cborDescriptorMap));
    8888}
  • trunk/Source/WebCore/Modules/webauthn/fido/U2fCommandConstructor.cpp

    r278340 r285698  
    11// Copyright 2018 The Chromium Authors. All rights reserved.
    2 // Copyright (C) 2019 Apple Inc. All rights reserved.
     2// Copyright (C) 2019-2021 Apple Inc. All rights reserved.
    33//
    44// Redistribution and use in source and binary forms, with or without
     
    6262}
    6363
    64 static std::optional<Vector<uint8_t>> constructU2fSignCommand(const Vector<uint8_t>& applicationParameter, const Vector<uint8_t>& challengeParameter, const Vector<uint8_t>& keyHandle, bool checkOnly)
     64static std::optional<Vector<uint8_t>> constructU2fSignCommand(const Vector<uint8_t>& applicationParameter, const Vector<uint8_t>& challengeParameter, const BufferSource& keyHandle, bool checkOnly)
    6565{
    66     if (keyHandle.size() > kMaxKeyHandleLength)
     66    if (keyHandle.length() > kMaxKeyHandleLength)
    6767        return std::nullopt;
    6868
    6969    Vector<uint8_t> data;
    70     data.reserveInitialCapacity(kU2fChallengeParamLength + kU2fApplicationParamLength + 1 + keyHandle.size());
     70    data.reserveInitialCapacity(kU2fChallengeParamLength + kU2fApplicationParamLength + 1 + keyHandle.length());
    7171    data.appendVector(challengeParameter);
    7272    data.appendVector(applicationParameter);
    73     data.append(static_cast<uint8_t>(keyHandle.size()));
    74     data.appendVector(keyHandle);
     73    data.append(static_cast<uint8_t>(keyHandle.length()));
     74    data.append(keyHandle.data(), keyHandle.length());
    7575
    7676    apdu::ApduCommand command;
     
    112112        return std::nullopt;
    113113
    114     return constructU2fSignCommand(produceRpIdHash(request.rp.id), clientDataHash, keyHandle.idVector, true /* checkOnly */);
     114    return constructU2fSignCommand(produceRpIdHash(request.rp.id), clientDataHash, keyHandle.id, true /* checkOnly */);
    115115}
    116116
    117 std::optional<Vector<uint8_t>> convertToU2fSignCommand(const Vector<uint8_t>& clientDataHash, const PublicKeyCredentialRequestOptions& request, const Vector<uint8_t>& keyHandle, bool isAppId)
     117std::optional<Vector<uint8_t>> convertToU2fSignCommand(const Vector<uint8_t>& clientDataHash, const PublicKeyCredentialRequestOptions& request, const WebCore::BufferSource& keyHandle, bool isAppId)
    118118{
    119119    if (!isConvertibleToU2fSignCommand(request))
  • trunk/Source/WebCore/Modules/webauthn/fido/U2fCommandConstructor.h

    r278253 r285698  
    11// Copyright 2018 The Chromium Authors. All rights reserved.
    2 // Copyright (C) 2019 Apple Inc. All rights reserved.
     2// Copyright (C) 2019-2021 Apple Inc. All rights reserved.
    33//
    44// Redistribution and use in source and binary forms, with or without
     
    3535
    3636namespace WebCore {
     37class BufferSource;
    3738struct AuthenticationExtensionsClientInputs;
    3839struct PublicKeyCredentialCreationOptions;
     
    6465
    6566// Extracts APDU encoded U2F sign command from PublicKeyCredentialRequestOptions.
    66 WEBCORE_EXPORT std::optional<Vector<uint8_t>> convertToU2fSignCommand(const Vector<uint8_t>& clientDataHash, const WebCore::PublicKeyCredentialRequestOptions&, const Vector<uint8_t>& keyHandle, bool isAppId = false);
     67WEBCORE_EXPORT std::optional<Vector<uint8_t>> convertToU2fSignCommand(const Vector<uint8_t>& clientDataHash, const WebCore::PublicKeyCredentialRequestOptions&, const WebCore::BufferSource& keyHandle, bool isAppId = false);
    6768
    6869WEBCORE_EXPORT Vector<uint8_t> constructBogusU2fRegistrationCommand();
  • trunk/Source/WebCore/Modules/webauthn/fido/U2fResponseConverter.cpp

    r278358 r285698  
    164164}
    165165
    166 RefPtr<AuthenticatorAssertionResponse> readU2fSignResponse(const String& rpId, const Vector<uint8_t>& keyHandle, const Vector<uint8_t>& u2fData, AuthenticatorAttachment attachment)
     166RefPtr<AuthenticatorAssertionResponse> readU2fSignResponse(const String& rpId, const WebCore::BufferSource& keyHandle, const Vector<uint8_t>& u2fData, AuthenticatorAttachment attachment)
    167167{
    168     if (keyHandle.isEmpty() || u2fData.size() <= signatureIndex)
     168    if (!keyHandle.length() || u2fData.size() <= signatureIndex)
    169169        return nullptr;
    170170
     
    179179    // FIXME: Find a way to remove the need of constructing a vector here.
    180180    Vector<uint8_t> signature { u2fData.data() + signatureIndex, u2fData.size() - signatureIndex };
    181     return AuthenticatorAssertionResponse::create(keyHandle, authData, signature, { }, attachment);
     181    Vector<uint8_t> keyHandleVector { keyHandle.data(), keyHandle.length() };
     182    return AuthenticatorAssertionResponse::create(keyHandleVector, authData, signature, { }, attachment);
    182183}
    183184
  • trunk/Source/WebCore/Modules/webauthn/fido/U2fResponseConverter.h

    r278358 r285698  
    3737#include <wtf/Forward.h>
    3838
     39namespace WebCore {
     40class BufferSource;
     41}
     42
    3943namespace fido {
    4044
     
    4549// Converts a U2F authentication response to WebAuthN getAssertion response.
    4650// https://fidoalliance.org/specs/fido-v2.0-id-20180227/fido-client-to-authenticator-protocol-v2.0-id-20180227.html#u2f-authenticatorGetAssertion-interoperability
    47 WEBCORE_EXPORT RefPtr<WebCore::AuthenticatorAssertionResponse> readU2fSignResponse(const String& rpId, const Vector<uint8_t>& keyHandle, const Vector<uint8_t>& u2fData, WebCore::AuthenticatorAttachment);
     51WEBCORE_EXPORT RefPtr<WebCore::AuthenticatorAssertionResponse> readU2fSignResponse(const String& rpId, const WebCore::BufferSource& keyHandle, const Vector<uint8_t>& u2fData, WebCore::AuthenticatorAttachment);
    4852
    4953} // namespace fido
  • trunk/Source/WebCore/bindings/js/BufferSource.h

    r284213 r285698  
    11/*
    22 * Copyright (C) 2016 Igalia S.L.
     3 * Copyright (C) 2021 Apple Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3031#include <variant>
    3132#include <wtf/RefPtr.h>
     33
     34#if PLATFORM(COCOA) && defined(__OBJC__)
     35OBJC_CLASS NSData;
     36#endif
    3237
    3338namespace WebCore {
     
    6570    }
    6671
     72    template<class Encoder> void encode(Encoder&) const;
     73    template<class Decoder> static std::optional<BufferSource> decode(Decoder&);
     74
    6775private:
    6876    VariantType m_variant;
    6977};
    7078
     79template<class Encoder>
     80void BufferSource::encode(Encoder& encoder) const
     81{
     82    encoder << static_cast<uint64_t>(length());
     83    if (!length())
     84        return;
     85
     86    encoder.encodeFixedLengthData(data(), length() * sizeof(uint8_t), alignof(uint8_t));
     87}
     88
     89template<class Decoder>
     90std::optional<BufferSource> BufferSource::decode(Decoder& decoder)
     91{
     92    std::optional<uint64_t> size;
     93    decoder >> size;
     94    if (!size)
     95        return std::nullopt;
     96    if (!*size)
     97        return BufferSource();
     98
     99    auto dataSize = CheckedSize { *size };
     100    if (UNLIKELY(dataSize.hasOverflowed()))
     101        return std::nullopt;
     102
     103    const uint8_t* data = decoder.decodeFixedLengthReference(dataSize, alignof(uint8_t));
     104    if (!data)
     105        return std::nullopt;
     106    return BufferSource(JSC::ArrayBuffer::tryCreate(static_cast<const void*>(data), dataSize.value()));
     107}
     108
     109inline BufferSource toBufferSource(const uint8_t* data, size_t length)
     110{
     111    return BufferSource(JSC::ArrayBuffer::tryCreate(data, length));
     112}
     113
     114#if PLATFORM(COCOA) && defined(__OBJC__)
     115inline BufferSource toBufferSource(NSData *data)
     116{
     117    return BufferSource(JSC::ArrayBuffer::tryCreate(static_cast<const uint8_t*>(data.bytes), data.length));
     118}
     119
     120inline RetainPtr<NSData> toNSData(const BufferSource& data)
     121{
     122    return adoptNS([[NSData alloc] initWithBytes:data.data() length:data.length()]);
     123}
     124#endif
     125
    71126} // namespace WebCore
     127
     128#if PLATFORM(COCOA) && defined(__OBJC__)
     129using WebCore::toNSData;
     130#endif
  • trunk/Source/WebKit/ChangeLog

    r285694 r285698  
     12021-11-11  Brent Fulgham  <bfulgham@apple.com>
     2
     3        [WebAuthn] Stop serializing BufferSource and Vector<uint8_t> duplicates of identifiers
     4        https://bugs.webkit.org/show_bug.cgi?id=233011
     5        <rdar://problem/85313807>
     6
     7        Reviewed by Chris Dumez.
     8
     9        The original WebAuthn logic converted WebCore::BufferSource objects to Vector<uint8_t>
     10        during serialization, which created a weird design where some code dealt with BufferSource
     11        objects, and other with Vectors, and lots of converting to and from these types. It also caused
     12        WebAuthn data structures to have two places where this information might live, with the
     13        UIProcess using one representation, and the WebContent process using another.
     14
     15        This patch revises the code as follows:
     16
     17        1. The identifiers are always stored as BufferSource, and the same member is used in UIProcess
     18           and WebContent process when accessing this information.
     19        2. We now serialize BufferSource directly.
     20
     21        Tested by existing WebAuthn test cases (API and Layout tests)
     22
     23        * UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm:
     24        (publicKeyCredentialUserEntity):
     25        (publicKeyCredentialDescriptors):
     26        * UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm:
     27        (WebKit::LocalAuthenticatorInternal::produceHashSet):
     28        (WebKit::LocalAuthenticator::continueMakeCredentialAfterUserVerification):
     29        (WebKit::LocalAuthenticator::deleteDuplicateCredential const):
     30        * UIProcess/WebAuthentication/Cocoa/WebAuthenticatorCoordinatorProxy.mm:
     31        (WebKit::toASCDescriptor):
     32        (WebKit::configureRegistrationRequestContext):
     33        (WebKit::configurationAssertionRequestContext):
     34        * UIProcess/WebAuthentication/fido/U2fAuthenticator.cpp:
     35        (WebKit::U2fAuthenticator::issueSignCommand):
     36        (WebKit::U2fAuthenticator::continueSignCommandAfterResponseReceived):
     37
    1382021-11-11  Michael Catanzaro  <mcatanzaro@gnome.org>
    239
  • trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebAuthenticationPanel.mm

    r285617 r285698  
    390390    result.name = userEntity.name;
    391391    result.icon = userEntity.icon;
    392     result.idVector = vectorFromNSData(userEntity.identifier);
     392    result.id = WebCore::toBufferSource(userEntity.identifier);
    393393    result.displayName = userEntity.displayName;
    394394
     
    439439
    440440    for (_WKPublicKeyCredentialDescriptor *credential : credentials)
    441         result.uncheckedAppend({ WebCore::PublicKeyCredentialType::PublicKey, { }, vectorFromNSData(credential.identifier), authenticatorTransports(credential.transports) });
     441        result.uncheckedAppend({ WebCore::PublicKeyCredentialType::PublicKey, WebCore::toBufferSource(credential.identifier), authenticatorTransports(credential.transports) });
    442442
    443443    return result;
  • trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/LocalAuthenticator.mm

    r284532 r285698  
    8585    HashSet<String> result;
    8686    for (auto& credentialDescriptor : credentialDescriptors) {
    87         if (emptyTransportsOrContain(credentialDescriptor.transports, AuthenticatorTransport::Internal) && credentialDescriptor.type == PublicKeyCredentialType::PublicKey && credentialDescriptor.idVector.size() == credentialIdLength)
    88             result.add(base64EncodeToString(credentialDescriptor.idVector.data(), credentialDescriptor.idVector.size()));
     87        if (emptyTransportsOrContain(credentialDescriptor.transports, AuthenticatorTransport::Internal) && credentialDescriptor.type == PublicKeyCredentialType::PublicKey && credentialDescriptor.id.length() == credentialIdLength)
     88            result.add(base64EncodeToString(credentialDescriptor.id.data(), credentialDescriptor.id.length()));
    8989    }
    9090    return result;
     
    354354
    355355    cbor::CBORValue::MapValue userEntityMap;
    356     userEntityMap[cbor::CBORValue(fido::kEntityIdMapKey)] = cbor::CBORValue(creationOptions.user.idVector);
     356    userEntityMap[cbor::CBORValue(fido::kEntityIdMapKey)] = cbor::CBORValue(creationOptions.user.id);
    357357    userEntityMap[cbor::CBORValue(fido::kEntityNameMapKey)] = cbor::CBORValue(creationOptions.user.name);
    358358    auto userEntity = cbor::CBORWriter::write(cbor::CBORValue(WTFMove(userEntityMap)));
     
    687687        auto* userHandle = credential->userHandle();
    688688        ASSERT(userHandle);
    689         if (userHandle->byteLength() != creationOptions.user.idVector.size())
     689        if (userHandle->byteLength() != creationOptions.user.id.length())
    690690            return false;
    691         if (memcmp(userHandle->data(), creationOptions.user.idVector.data(), userHandle->byteLength()))
     691        if (memcmp(userHandle->data(), creationOptions.user.id.data(), userHandle->byteLength()))
    692692            return false;
    693693
  • trunk/Source/WebKit/UIProcess/WebAuthentication/Cocoa/WebAuthenticatorCoordinatorProxy.mm

    r285537 r285698  
    4848{
    4949    return ArrayBuffer::create(reinterpret_cast<const uint8_t*>(data.bytes), data.length);
    50 }
    51 
    52 static inline RetainPtr<NSData> toNSData(const BufferSource& data)
    53 {
    54     return adoptNS([[NSData alloc] initWithBytes:data.data() length:data.length()]);
    5550}
    5651
     
    152147    }
    153148
    154     return adoptNS([allocASCPublicKeyCredentialDescriptorInstance() initWithCredentialID:toNSData(descriptor.idVector).get() transports:transports.get()]);
     149    return adoptNS([allocASCPublicKeyCredentialDescriptorInstance() initWithCredentialID:toNSData(descriptor.id).get() transports:transports.get()]);
    155150}
    156151
     
    179174    auto credentialCreationOptions = adoptNS([allocASCPublicKeyCredentialCreationOptionsInstance() init]);
    180175
    181     [credentialCreationOptions setChallenge:toNSData(options.challengeVector).get()];
     176    [credentialCreationOptions setChallenge:toNSData(options.challenge).get()];
    182177    [credentialCreationOptions setRelyingPartyIdentifier:options.rp.id];
    183178    [credentialCreationOptions setUserName:options.user.name];
    184     [credentialCreationOptions setUserIdentifier:toNSData(options.user.idVector).get()];
     179    [credentialCreationOptions setUserIdentifier:toNSData(options.user.id.data()).get()];
    185180    [credentialCreationOptions setUserDisplayName:options.user.displayName];
    186181    [credentialCreationOptions setUserVerificationPreference:userVerification.get()];
     
    237232    [requestContext setRelyingPartyIdentifier:options.rpId];
    238233
    239     auto challenge = toNSData(options.challengeVector);
     234    auto challenge = toNSData(options.challenge);
    240235
    241236    if (requestTypes & ASCCredentialRequestTypePlatformPublicKeyAssertion)
  • trunk/Source/WebKit/UIProcess/WebAuthentication/fido/U2fAuthenticator.cpp

    r284095 r285698  
    105105        return;
    106106    }
    107     auto u2fCmd = convertToU2fSignCommand(requestData().hash, requestOptions, requestOptions.allowCredentials[index].idVector, m_isAppId);
     107    auto u2fCmd = convertToU2fSignCommand(requestData().hash, requestOptions, requestOptions.allowCredentials[index].id, m_isAppId);
    108108    ASSERT(u2fCmd);
    109109    issueNewCommand(WTFMove(*u2fCmd), CommandType::SignCommand);
     
    210210        if (m_isAppId) {
    211211            ASSERT(requestOptions.extensions && !requestOptions.extensions->appid.isNull());
    212             response = readU2fSignResponse(requestOptions.extensions->appid, requestOptions.allowCredentials[m_nextListIndex - 1].idVector, apduResponse.data(), AuthenticatorAttachment::CrossPlatform);
     212            response = readU2fSignResponse(requestOptions.extensions->appid, requestOptions.allowCredentials[m_nextListIndex - 1].id, apduResponse.data(), AuthenticatorAttachment::CrossPlatform);
    213213        } else
    214             response = readU2fSignResponse(requestOptions.rpId, requestOptions.allowCredentials[m_nextListIndex - 1].idVector, apduResponse.data(), AuthenticatorAttachment::CrossPlatform);
     214            response = readU2fSignResponse(requestOptions.rpId, requestOptions.allowCredentials[m_nextListIndex - 1].id, apduResponse.data(), AuthenticatorAttachment::CrossPlatform);
    215215        if (!response) {
    216216            receiveRespond(ExceptionData { UnknownError, "Couldn't parse the U2F sign response."_s });
  • trunk/Tools/ChangeLog

    r285677 r285698  
     12021-11-11  Brent Fulgham  <bfulgham@apple.com>
     2
     3        [WebAuthn] Stop serializing BufferSource and Vector<uint8_t> duplicates of identifiers
     4        https://bugs.webkit.org/show_bug.cgi?id=233011
     5        <rdar://problem/85313807>
     6
     7        Reviewed by Chris Dumez.
     8
     9        The original WebAuthn logic converted WebCore::BufferSource objects to Vector<uint8_t>
     10        during serialization, which created a weird design where some code dealt with BufferSource
     11        objects, and other with Vectors, and lots of converting to and from these types. It also caused
     12        WebAuthn data structures to have two places where this information might live, with the
     13        UIProcess using one representation, and the WebContent process using another.
     14
     15        This patch revises the code as follows:
     16
     17        1. The identifiers are always stored as BufferSource, and the same member is used in UIProcess
     18           and WebContent process when accessing this information.
     19        2. We now serialize BufferSource directly.
     20
     21        Tested by existing WebAuthn test cases (API and Layout tests)
     22
     23        * TestWebKitAPI/Tests/WebCore/CtapRequestTest.cpp:
     24        (TestWebKitAPI::TEST):
     25        * TestWebKitAPI/Tests/WebCore/CtapResponseTest.cpp:
     26        (TestWebKitAPI::getTestCredentialRawIdBytes):
     27        (TestWebKitAPI::TEST):
     28        * TestWebKitAPI/Tests/WebCore/U2fCommandConstructorTest.cpp:
     29        (TestWebKitAPI::constructMakeCredentialRequest):
     30        (TestWebKitAPI::TEST):
     31        * TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm:
     32        (TestWebKitAPI::TEST):
     33
    1342021-11-11  Andres Gonzalez  <andresg_22@apple.com>
    235
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/CtapRequestTest.cpp

    r285475 r285698  
    11// Copyright 2017 The Chromium Authors. All rights reserved.
    2 // Copyright (C) 2018 Apple Inc. All rights reserved.
     2// Copyright (C) 2018-2021 Apple Inc. All rights reserved.
    33//
    44// Redistribution and use in source and binary forms, with or without
     
    5757    user.name = "johnpsmith@example.com";
    5858    user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png";
    59     user.idVector.append(TestData::kUserId, sizeof(TestData::kUserId));
     59    user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
    6060    user.displayName = "John P. Smith";
    6161
     
    6363    PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria selection { AuthenticatorAttachment::Platform, true, UserVerificationRequirement::Preferred };
    6464
    65     PublicKeyCredentialCreationOptions options { rp, user, { }, params, std::nullopt, { }, selection, AttestationConveyancePreference::None, std::nullopt, { } };
     65    PublicKeyCredentialCreationOptions options { rp, user, { }, params, std::nullopt, { }, selection, AttestationConveyancePreference::None, std::nullopt };
    6666    Vector<uint8_t> hash;
    6767    hash.append(TestData::kClientDataHash, sizeof(TestData::kClientDataHash));
     
    8080    user.name = "johnpsmith@example.com";
    8181    user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png";
    82     user.idVector.append(TestData::kUserId, sizeof(TestData::kUserId));
     82    user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
    8383    user.displayName = "John P. Smith";
    8484
     
    8686    PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria selection { AuthenticatorAttachment::Platform, false, UserVerificationRequirement::Discouraged };
    8787
    88     PublicKeyCredentialCreationOptions options { rp, user, { }, params, std::nullopt, { }, selection, AttestationConveyancePreference::None, std::nullopt, { } };
     88    PublicKeyCredentialCreationOptions options { rp, user, { }, params, std::nullopt, { }, selection, AttestationConveyancePreference::None, std::nullopt };
    8989    Vector<uint8_t> hash;
    9090    hash.append(TestData::kClientDataHash, sizeof(TestData::kClientDataHash));
     
    103103    user.name = "johnpsmith@example.com";
    104104    user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png";
    105     user.idVector.append(TestData::kUserId, sizeof(TestData::kUserId));
     105    user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
    106106    user.displayName = "John P. Smith";
    107107
     
    109109    PublicKeyCredentialCreationOptions::AuthenticatorSelectionCriteria selection { AuthenticatorAttachment::Platform, false, UserVerificationRequirement::Required };
    110110
    111     PublicKeyCredentialCreationOptions options { rp, user, { }, params, std::nullopt, { }, selection, AttestationConveyancePreference::None, std::nullopt, { } };
     111    PublicKeyCredentialCreationOptions options { rp, user, { }, params, std::nullopt, { }, selection, AttestationConveyancePreference::None, std::nullopt };
    112112    Vector<uint8_t> hash;
    113113    hash.append(TestData::kClientDataHash, sizeof(TestData::kClientDataHash));
     
    126126    user.name = "johnpsmith@example.com";
    127127    user.icon = "https://pics.acme.com/00/p/aBjjjpqPb.png";
    128     user.idVector.append(TestData::kUserId, sizeof(TestData::kUserId));
     128    user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
    129129    user.displayName = "John P. Smith";
    130130
     
    136136    pin.auth.append(TestData::kCtap2PinAuth, sizeof(TestData::kCtap2PinAuth));
    137137
    138     PublicKeyCredentialCreationOptions options { rp, user, { }, params, std::nullopt, { }, selection, AttestationConveyancePreference::None, std::nullopt, { } };
     138    PublicKeyCredentialCreationOptions options { rp, user, { }, params, std::nullopt, { }, selection, AttestationConveyancePreference::None, std::nullopt };
    139139    Vector<uint8_t> hash;
    140140    hash.append(TestData::kClientDataHash, sizeof(TestData::kClientDataHash));
     
    158158        0x08, 0xd9, 0x4f, 0xcb, 0xee, 0x82, 0xb9, 0xb2, 0xef, 0x66, 0x77,
    159159        0xaf, 0x0a, 0xdc, 0xc3, 0x58, 0x52, 0xea, 0x6b, 0x9e };
    160     descriptor1.idVector.append(id1, sizeof(id1));
     160    descriptor1.id = WebCore::toBufferSource(id1, sizeof(id1));
    161161    options.allowCredentials.append(descriptor1);
    162162
     
    169169        0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
    170170        0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 };
    171     descriptor2.idVector.append(id2, sizeof(id2));
     171    descriptor2.id = WebCore::toBufferSource(id2, sizeof(id2));
    172172    options.allowCredentials.append(descriptor2);
    173173
     
    195195        0x08, 0xd9, 0x4f, 0xcb, 0xee, 0x82, 0xb9, 0xb2, 0xef, 0x66, 0x77,
    196196        0xaf, 0x0a, 0xdc, 0xc3, 0x58, 0x52, 0xea, 0x6b, 0x9e };
    197     descriptor1.idVector.append(id1, sizeof(id1));
     197    descriptor1.id = WebCore::toBufferSource(id1, sizeof(id1));
    198198    options.allowCredentials.append(descriptor1);
    199199
     
    206206        0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
    207207        0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 };
    208     descriptor2.idVector.append(id2, sizeof(id2));
     208    descriptor2.id = WebCore::toBufferSource(id2, sizeof(id2));
    209209    options.allowCredentials.append(descriptor2);
    210210
     
    232232        0x08, 0xd9, 0x4f, 0xcb, 0xee, 0x82, 0xb9, 0xb2, 0xef, 0x66, 0x77,
    233233        0xaf, 0x0a, 0xdc, 0xc3, 0x58, 0x52, 0xea, 0x6b, 0x9e };
    234     descriptor1.idVector.append(id1, sizeof(id1));
     234    descriptor1.id = WebCore::toBufferSource(id1, sizeof(id1));
    235235    options.allowCredentials.append(descriptor1);
    236236
     
    243243        0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
    244244        0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 };
    245     descriptor2.idVector.append(id2, sizeof(id2));
     245    descriptor2.id = WebCore::toBufferSource(id2, sizeof(id2));
    246246    options.allowCredentials.append(descriptor2);
    247247
     
    269269        0x08, 0xd9, 0x4f, 0xcb, 0xee, 0x82, 0xb9, 0xb2, 0xef, 0x66, 0x77,
    270270        0xaf, 0x0a, 0xdc, 0xc3, 0x58, 0x52, 0xea, 0x6b, 0x9e };
    271     descriptor1.idVector.append(id1, sizeof(id1));
     271    descriptor1.id = WebCore::toBufferSource(id1, sizeof(id1));
    272272    options.allowCredentials.append(descriptor1);
    273273
     
    280280        0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
    281281        0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 };
    282     descriptor2.idVector.append(id2, sizeof(id2));
     282    descriptor2.id = WebCore::toBufferSource(id2, sizeof(id2));
    283283    options.allowCredentials.append(descriptor2);
    284284
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/CtapResponseTest.cpp

    r283605 r285698  
    11// Copyright 2017 The Chromium Authors. All rights reserved.
    2 // Copyright (C) 2018 Apple Inc. All rights reserved.
     2// Copyright (C) 2018-2021 Apple Inc. All rights reserved.
    33//
    44// Redistribution and use in source and binary forms, with or without
     
    3535#include <JavaScriptCore/ArrayBuffer.h>
    3636#include <WebCore/AuthenticatorAttachment.h>
     37#include <WebCore/BufferSource.h>
    3738#include <WebCore/CBORReader.h>
    3839#include <WebCore/CBORValue.h>
     
    334335
    335336// Return a key handle used for GetAssertion request.
    336 Vector<uint8_t> getTestCredentialRawIdBytes()
    337 {
    338     Vector<uint8_t> testCredentialRawIdBytes;
    339     testCredentialRawIdBytes.reserveInitialCapacity(sizeof(TestData::kU2fSignKeyHandle));
    340     testCredentialRawIdBytes.append(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle));
    341     return testCredentialRawIdBytes;
     337BufferSource getTestCredentialRawIdBytes()
     338{
     339    return WebCore::toBufferSource(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle));
    342340}
    343341
     
    559557TEST(CTAPResponseTest, TestParseU2fSignWithNullKeyHandle)
    560558{
    561     auto response = readU2fSignResponse(TestData::kRelyingPartyId, Vector<uint8_t>(), getTestSignResponse(), AuthenticatorAttachment::CrossPlatform);
     559    auto response = readU2fSignResponse(TestData::kRelyingPartyId, BufferSource(), getTestSignResponse(), AuthenticatorAttachment::CrossPlatform);
    562560    EXPECT_FALSE(response);
    563561}
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/U2fCommandConstructorTest.cpp

    r250659 r285698  
    11// Copyright 2018 The Chromium Authors. All rights reserved.
    2 // Copyright (C) 2019 Apple Inc. All rights reserved.
     2// Copyright (C) 2019-2021 Apple Inc. All rights reserved.
    33//
    44// Redistribution and use in source and binary forms, with or without
     
    5151
    5252    PublicKeyCredentialCreationOptions::UserEntity user;
    53     user.idVector = convertBytesToVector(TestData::kUserId, sizeof(TestData::kUserId));
     53    user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
    5454    user.name = "johnpsmith@example.com";
    5555    user.displayName = "John P. Smith";
     
    113113    PublicKeyCredentialDescriptor credentialDescriptor;
    114114    credentialDescriptor.type = PublicKeyCredentialType::PublicKey;
    115     credentialDescriptor.idVector = convertBytesToVector(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle));
     115    credentialDescriptor.id = WebCore::toBufferSource(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle));
    116116    Vector<PublicKeyCredentialDescriptor> excludeList;
    117117    excludeList.append(credentialDescriptor);
     
    129129    PublicKeyCredentialDescriptor credentialDescriptor;
    130130    credentialDescriptor.type = static_cast<PublicKeyCredentialType>(-1);
    131     credentialDescriptor.idVector = convertBytesToVector(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle));
     131    credentialDescriptor.id = WebCore::toBufferSource(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle));
    132132    Vector<PublicKeyCredentialDescriptor> excludeList;
    133133    excludeList.append(credentialDescriptor);
     
    146146
    147147    PublicKeyCredentialCreationOptions::UserEntity user;
    148     user.idVector = convertBytesToVector(TestData::kUserId, sizeof(TestData::kUserId));
     148    user.id = WebCore::toBufferSource(TestData::kUserId, sizeof(TestData::kUserId));
    149149    user.name = "johnpsmith@example.com";
    150150    user.displayName = "John P. Smith";
     
    188188    PublicKeyCredentialDescriptor credentialDescriptor;
    189189    credentialDescriptor.type = PublicKeyCredentialType::PublicKey;
    190     credentialDescriptor.idVector = convertBytesToVector(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle));
     190    credentialDescriptor.id = WebCore::toBufferSource(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle));
    191191    Vector<PublicKeyCredentialDescriptor> allowedList;
    192192    allowedList.append(WTFMove(credentialDescriptor));
     
    194194    EXPECT_TRUE(isConvertibleToU2fSignCommand(getAssertionReq));
    195195
    196     const auto u2fSignCommand = convertToU2fSignCommand(convertBytesToVector(TestData::kClientDataHash, sizeof(TestData::kClientDataHash)), getAssertionReq, convertBytesToVector(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle)));
     196    const auto u2fSignCommand = convertToU2fSignCommand(convertBytesToVector(TestData::kClientDataHash, sizeof(TestData::kClientDataHash)), getAssertionReq, WebCore::toBufferSource(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle)));
    197197    ASSERT_TRUE(u2fSignCommand);
    198198    EXPECT_EQ(*u2fSignCommand, convertBytesToVector(TestData::kU2fSignCommandApdu, sizeof(TestData::kU2fSignCommandApdu)));
     
    204204    PublicKeyCredentialDescriptor credentialDescriptor;
    205205    credentialDescriptor.type = PublicKeyCredentialType::PublicKey;
    206     credentialDescriptor.idVector = convertBytesToVector(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle));
     206    credentialDescriptor.id = WebCore::toBufferSource(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle));
    207207    Vector<PublicKeyCredentialDescriptor> allowedList;
    208208    allowedList.append(WTFMove(credentialDescriptor));
     
    215215    getAssertionReq.extensions = WTFMove(extensions);
    216216
    217     const auto u2fSignCommand = convertToU2fSignCommand(convertBytesToVector(TestData::kClientDataHash, sizeof(TestData::kClientDataHash)), getAssertionReq, convertBytesToVector(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle)), true);
     217    const auto u2fSignCommand = convertToU2fSignCommand(convertBytesToVector(TestData::kClientDataHash, sizeof(TestData::kClientDataHash)), getAssertionReq, WebCore::toBufferSource(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle)), true);
    218218    ASSERT_TRUE(u2fSignCommand);
    219219    EXPECT_EQ(*u2fSignCommand, convertBytesToVector(TestData::kU2fAppIDSignCommandApdu, sizeof(TestData::kU2fAppIDSignCommandApdu)));
     
    231231    PublicKeyCredentialDescriptor credentialDescriptor;
    232232    credentialDescriptor.type = PublicKeyCredentialType::PublicKey;
    233     credentialDescriptor.idVector = convertBytesToVector(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle));
     233    credentialDescriptor.id = WebCore::toBufferSource(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle));
    234234    Vector<PublicKeyCredentialDescriptor> allowedList;
    235235    allowedList.append(WTFMove(credentialDescriptor));
     
    245245    PublicKeyCredentialDescriptor credentialDescriptor;
    246246    credentialDescriptor.type = PublicKeyCredentialType::PublicKey;
    247     credentialDescriptor.idVector = convertBytesToVector(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle));
     247    credentialDescriptor.id = WebCore::toBufferSource(TestData::kU2fSignKeyHandle, sizeof(TestData::kU2fSignKeyHandle));
    248248    Vector<PublicKeyCredentialDescriptor> allowedList;
    249249    allowedList.append(WTFMove(credentialDescriptor));
     
    252252
    253253    Vector<uint8_t> keyHandle(kMaxKeyHandleLength, 0xff);
    254     const auto validSignCommand = convertToU2fSignCommand(convertBytesToVector(TestData::kClientDataHash, sizeof(TestData::kClientDataHash)), getAssertionReq, keyHandle);
     254    const auto validSignCommand = convertToU2fSignCommand(convertBytesToVector(TestData::kClientDataHash, sizeof(TestData::kClientDataHash)), getAssertionReq, WebCore::toBufferSource(keyHandle.data(), keyHandle.size()));
    255255    EXPECT_TRUE(validSignCommand);
    256256
    257257    keyHandle.append(0xff);
    258     const auto invalidSignCommand = convertToU2fSignCommand(convertBytesToVector(TestData::kClientDataHash, sizeof(TestData::kClientDataHash)), getAssertionReq, keyHandle);
     258    const auto invalidSignCommand = convertToU2fSignCommand(convertBytesToVector(TestData::kClientDataHash, sizeof(TestData::kClientDataHash)), getAssertionReq, WebCore::toBufferSource(keyHandle.data(), keyHandle.size()));
    259259    EXPECT_FALSE(invalidSignCommand);
    260260}
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm

    r285619 r285698  
    11/*
    2  * Copyright (C) 2019 Apple Inc. All rights reserved.
     2 * Copyright (C) 2019-2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    16241624    EXPECT_WK_STREQ(result.user.name, "jappleseed@example.com");
    16251625    EXPECT_TRUE(result.user.icon.isNull());
    1626     EXPECT_EQ(result.user.idVector.size(), sizeof(identifier));
    1627     EXPECT_EQ(memcmp(result.user.idVector.data(), identifier, sizeof(identifier)), 0);
     1626    EXPECT_EQ(result.user.id.length(), sizeof(identifier));
     1627    EXPECT_EQ(memcmp(result.user.id.data(), identifier, sizeof(identifier)), 0);
    16281628    EXPECT_WK_STREQ(result.user.displayName, "J Appleseed");
    16291629
     
    16681668    EXPECT_WK_STREQ(result.user.name, "jappleseed@example.com");
    16691669    EXPECT_TRUE(result.user.icon.isNull());
    1670     EXPECT_EQ(result.user.idVector.size(), sizeof(identifier));
    1671     EXPECT_EQ(memcmp(result.user.idVector.data(), identifier, sizeof(identifier)), 0);
     1670    EXPECT_EQ(result.user.id.length(), sizeof(identifier));
     1671    EXPECT_EQ(memcmp(result.user.id.data(), identifier, sizeof(identifier)), 0);
    16721672    EXPECT_WK_STREQ(result.user.displayName, "J Appleseed");
    16731673
     
    16821682    EXPECT_EQ(result.excludeCredentials.size(), 1lu);
    16831683    EXPECT_EQ(result.excludeCredentials[0].type, WebCore::PublicKeyCredentialType::PublicKey);
    1684     EXPECT_EQ(result.excludeCredentials[0].idVector.size(), sizeof(identifier));
    1685     EXPECT_EQ(memcmp(result.excludeCredentials[0].idVector.data(), identifier, sizeof(identifier)), 0);
     1684    EXPECT_EQ(result.excludeCredentials[0].id.length(), sizeof(identifier));
     1685    EXPECT_EQ(memcmp(result.excludeCredentials[0].id.data(), identifier, sizeof(identifier)), 0);
    16861686
    16871687    EXPECT_EQ(result.authenticatorSelection->authenticatorAttachment, std::nullopt);
     
    17351735    EXPECT_WK_STREQ(result.user.name, "jappleseed@example.com");
    17361736    EXPECT_WK_STREQ(result.user.icon, @"https//www.example.com/icon.jpg");
    1737     EXPECT_EQ(result.user.idVector.size(), sizeof(identifier));
    1738     EXPECT_EQ(memcmp(result.user.idVector.data(), identifier, sizeof(identifier)), 0);
     1737    EXPECT_EQ(result.user.id.length(), sizeof(identifier));
     1738    EXPECT_EQ(memcmp(result.user.id.data(), identifier, sizeof(identifier)), 0);
    17391739    EXPECT_WK_STREQ(result.user.displayName, "J Appleseed");
    17401740
     
    17491749    EXPECT_EQ(result.excludeCredentials.size(), 2lu);
    17501750    EXPECT_EQ(result.excludeCredentials[0].type, WebCore::PublicKeyCredentialType::PublicKey);
    1751     EXPECT_EQ(result.excludeCredentials[0].idVector.size(), sizeof(identifier));
    1752     EXPECT_EQ(memcmp(result.excludeCredentials[0].idVector.data(), identifier, sizeof(identifier)), 0);
     1751    EXPECT_EQ(result.excludeCredentials[0].id.length(), sizeof(identifier));
     1752    EXPECT_EQ(memcmp(result.excludeCredentials[0].id.data(), identifier, sizeof(identifier)), 0);
    17531753    EXPECT_EQ(result.excludeCredentials[0].transports.size(), 3lu);
    17541754    EXPECT_EQ(result.excludeCredentials[0].transports[0], AuthenticatorTransport::Usb);
     
    18051805    EXPECT_WK_STREQ(result.user.name, "jappleseed@example.com");
    18061806    EXPECT_WK_STREQ(result.user.icon, @"https//www.example.com/icon.jpg");
    1807     EXPECT_EQ(result.user.idVector.size(), sizeof(identifier));
    1808     EXPECT_EQ(memcmp(result.user.idVector.data(), identifier, sizeof(identifier)), 0);
     1807    EXPECT_EQ(result.user.id.length(), sizeof(identifier));
     1808    EXPECT_EQ(memcmp(result.user.id.data(), identifier, sizeof(identifier)), 0);
    18091809    EXPECT_WK_STREQ(result.user.displayName, "J Appleseed");
    18101810
     
    18191819    EXPECT_EQ(result.excludeCredentials.size(), 2lu);
    18201820    EXPECT_EQ(result.excludeCredentials[0].type, WebCore::PublicKeyCredentialType::PublicKey);
    1821     EXPECT_EQ(result.excludeCredentials[0].idVector.size(), sizeof(identifier));
    1822     EXPECT_EQ(memcmp(result.excludeCredentials[0].idVector.data(), identifier, sizeof(identifier)), 0);
     1821    EXPECT_EQ(result.excludeCredentials[0].id.length(), sizeof(identifier));
     1822    EXPECT_EQ(memcmp(result.excludeCredentials[0].id.data(), identifier, sizeof(identifier)), 0);
    18231823    EXPECT_EQ(result.excludeCredentials[0].transports.size(), 3lu);
    18241824    EXPECT_EQ(result.excludeCredentials[0].transports[0], AuthenticatorTransport::Usb);
     
    19321932    EXPECT_EQ(result.allowCredentials.size(), 1lu);
    19331933    EXPECT_EQ(result.allowCredentials[0].type, WebCore::PublicKeyCredentialType::PublicKey);
    1934     EXPECT_EQ(result.allowCredentials[0].idVector.size(), sizeof(identifier));
    1935     EXPECT_EQ(memcmp(result.allowCredentials[0].idVector.data(), identifier, sizeof(identifier)), 0);
     1934    EXPECT_EQ(result.allowCredentials[0].id.length(), sizeof(identifier));
     1935    EXPECT_EQ(memcmp(result.allowCredentials[0].id.data(), identifier, sizeof(identifier)), 0);
    19361936
    19371937    EXPECT_EQ(result.userVerification, UserVerificationRequirement::Preferred);
     
    19661966    EXPECT_EQ(result.allowCredentials.size(), 2lu);
    19671967    EXPECT_EQ(result.allowCredentials[0].type, WebCore::PublicKeyCredentialType::PublicKey);
    1968     EXPECT_EQ(result.allowCredentials[0].idVector.size(), sizeof(identifier));
    1969     EXPECT_EQ(memcmp(result.allowCredentials[0].idVector.data(), identifier, sizeof(identifier)), 0);
     1968    EXPECT_EQ(result.allowCredentials[0].id.length(), sizeof(identifier));
     1969    EXPECT_EQ(memcmp(result.allowCredentials[0].id.data(), identifier, sizeof(identifier)), 0);
    19701970    EXPECT_EQ(result.allowCredentials[0].transports.size(), 3lu);
    19711971    EXPECT_EQ(result.allowCredentials[0].transports[0], AuthenticatorTransport::Usb);
Note: See TracChangeset for help on using the changeset viewer.