chromium/third_party/blink/renderer/modules/credentialmanagement/credential_manager_type_converters.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/modules/credentialmanagement/credential_manager_type_converters.h"

#include <algorithm>
#include <utility>

#include "base/numerics/safe_conversions.h"
#include "build/build_config.h"
#include "third_party/blink/public/mojom/webauthn/authenticator.mojom-blink.h"
#include "third_party/blink/public/mojom/webid/digital_identity_request.mojom-blink.h"
#include "third_party/blink/public/mojom/webid/federated_auth_request.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_typedefs.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_union_arraybuffer_arraybufferview.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_all_accepted_credentials_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_client_inputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_client_outputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_large_blob_inputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_large_blob_outputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_payment_inputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_prf_inputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_prf_outputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_prf_values.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_supplemental_pub_keys_inputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authentication_extensions_supplemental_pub_keys_outputs.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_authenticator_selection_criteria.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_cable_authentication_data.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_current_user_details_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_identity_credential_disconnect_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_identity_credential_request_options_context.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_identity_credential_request_options_mode.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_identity_provider_config.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_identity_provider_request_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_identity_user_info.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_creation_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_descriptor.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_parameters.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_request_options.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_rp_entity.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_public_key_credential_user_entity.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_remote_desktop_client_override.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_piece.h"
#include "third_party/blink/renderer/modules/credentialmanagement/credential.h"
#include "third_party/blink/renderer/modules/credentialmanagement/federated_credential.h"
#include "third_party/blink/renderer/modules/credentialmanagement/password_credential.h"
#include "third_party/blink/renderer/modules/credentialmanagement/public_key_credential.h"
#include "third_party/blink/renderer/platform/bindings/enumeration_base.h"
#include "third_party/blink/renderer/platform/heap/member.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/blink/renderer/platform/wtf/text/base64.h"
#include "third_party/boringssl/src/include/openssl/sha.h"
namespace mojo {

AllAcceptedCredentialsOptions;
AllAcceptedCredentialsOptionsPtr;
AttestationConveyancePreference;
AuthenticationExtensionsClientInputs;
AuthenticationExtensionsClientInputsPtr;
AuthenticatorAttachment;
AuthenticatorSelectionCriteria;
AuthenticatorSelectionCriteriaPtr;
AuthenticatorTransport;
CableAuthentication;
CableAuthenticationPtr;
CredentialInfo;
CredentialInfoPtr;
CredentialType;
CurrentUserDetailsOptions;
CurrentUserDetailsOptionsPtr;
Hint;
IdentityCredentialDisconnectOptions;
IdentityCredentialDisconnectOptionsPtr;
IdentityProviderConfig;
IdentityProviderConfigPtr;
IdentityProviderRequestOptions;
IdentityProviderRequestOptionsPtr;
IdentityUserInfo;
IdentityUserInfoPtr;
LargeBlobSupport;
PRFValues;
PRFValuesPtr;
PublicKeyCredentialCreationOptionsPtr;
PublicKeyCredentialDescriptor;
PublicKeyCredentialDescriptorPtr;
PublicKeyCredentialParameters;
PublicKeyCredentialParametersPtr;
PublicKeyCredentialReportOptionsPtr;
PublicKeyCredentialRequestOptionsPtr;
PublicKeyCredentialRpEntity;
PublicKeyCredentialRpEntityPtr;
PublicKeyCredentialType;
PublicKeyCredentialUserEntity;
PublicKeyCredentialUserEntityPtr;
RemoteDesktopClientOverride;
RemoteDesktopClientOverridePtr;
ResidentKeyRequirement;
RpContext;
RpMode;
SupplementalPubKeysRequest;
SupplementalPubKeysRequestPtr;
UserVerificationRequirement;

namespace {

static constexpr int kCoseEs256 =;
static constexpr int kCoseRs256 =;

PublicKeyCredentialParametersPtr CreatePublicKeyCredentialParameter(int alg) {}

// SortPRFValuesByCredentialId is a "less than" function that puts the single,
// optional element without a credential ID at the beginning and otherwise
// lexicographically sorts by credential ID. The browser requires that PRF
// values be presented in this order so that it can easily establish that there
// are no duplicates.
bool SortPRFValuesByCredentialId(const PRFValuesPtr& a, const PRFValuesPtr& b) {}

Vector<uint8_t> Base64UnpaddedURLDecodeOrCheck(const String& encoded) {}

}  // namespace

// static
CredentialInfoPtr TypeConverter<CredentialInfoPtr, blink::Credential*>::Convert(
    blink::Credential* credential) {}

// static
blink::Credential*
TypeConverter<blink::Credential*, CredentialInfoPtr>::Convert(
    const CredentialInfoPtr& info) {}

#if BUILDFLAG(IS_ANDROID)
static Vector<Vector<uint32_t>> UvmEntryToArray(
    const Vector<blink::mojom::blink::UvmEntryPtr>& user_verification_methods) {
  Vector<Vector<uint32_t>> uvm_array;
  for (const auto& uvm : user_verification_methods) {
    Vector<uint32_t> uvmEntry = {uvm->user_verification_method,
                                 uvm->key_protection_type,
                                 uvm->matcher_protection_type};
    uvm_array.push_back(uvmEntry);
  }
  return uvm_array;
}
#endif

// static
blink::AuthenticationExtensionsClientOutputs*
TypeConverter<blink::AuthenticationExtensionsClientOutputs*,
              blink::mojom::blink::AuthenticationExtensionsClientOutputsPtr>::
    Convert(const blink::mojom::blink::AuthenticationExtensionsClientOutputsPtr&
                extensions) {}

// static
blink::AuthenticationExtensionsSupplementalPubKeysOutputs*
TypeConverter<blink::AuthenticationExtensionsSupplementalPubKeysOutputs*,
              blink::mojom::blink::SupplementalPubKeysResponsePtr>::
    Convert(const blink::mojom::blink::SupplementalPubKeysResponsePtr&
                supplemental_pub_keys) {}

// static
Vector<uint8_t>
TypeConverter<Vector<uint8_t>, blink::V8UnionArrayBufferOrArrayBufferView*>::
    Convert(const blink::V8UnionArrayBufferOrArrayBufferView* buffer) {}

// static
PublicKeyCredentialType TypeConverter<PublicKeyCredentialType, String>::Convert(
    const String& type) {}

// static
std::optional<AuthenticatorTransport>
TypeConverter<std::optional<AuthenticatorTransport>, String>::Convert(
    const String& transport) {}

// static
String TypeConverter<String, AuthenticatorTransport>::Convert(
    const AuthenticatorTransport& transport) {}

// static
std::optional<blink::mojom::blink::ResidentKeyRequirement>
TypeConverter<std::optional<blink::mojom::blink::ResidentKeyRequirement>,
              String>::Convert(const String& requirement) {}

// static
std::optional<UserVerificationRequirement>
TypeConverter<std::optional<UserVerificationRequirement>, String>::Convert(
    const String& requirement) {}

// static
std::optional<AttestationConveyancePreference>
TypeConverter<std::optional<AttestationConveyancePreference>, String>::Convert(
    const String& preference) {}

// static
std::optional<AuthenticatorAttachment> TypeConverter<
    std::optional<AuthenticatorAttachment>,
    std::optional<String>>::Convert(const std::optional<String>& attachment) {}

// static
LargeBlobSupport
TypeConverter<LargeBlobSupport, std::optional<String>>::Convert(
    const std::optional<String>& large_blob_support) {}

// static
AuthenticatorSelectionCriteriaPtr
TypeConverter<AuthenticatorSelectionCriteriaPtr,
              blink::AuthenticatorSelectionCriteria>::
    Convert(const blink::AuthenticatorSelectionCriteria& criteria) {}

// static
PublicKeyCredentialUserEntityPtr
TypeConverter<PublicKeyCredentialUserEntityPtr,
              blink::PublicKeyCredentialUserEntity>::
    Convert(const blink::PublicKeyCredentialUserEntity& user) {}

// static
PublicKeyCredentialRpEntityPtr
TypeConverter<PublicKeyCredentialRpEntityPtr,
              blink::PublicKeyCredentialRpEntity>::
    Convert(const blink::PublicKeyCredentialRpEntity& rp) {}

// static
PublicKeyCredentialDescriptorPtr
TypeConverter<PublicKeyCredentialDescriptorPtr,
              blink::PublicKeyCredentialDescriptor>::
    Convert(const blink::PublicKeyCredentialDescriptor& descriptor) {}

// static
PublicKeyCredentialParametersPtr
TypeConverter<PublicKeyCredentialParametersPtr,
              blink::PublicKeyCredentialParameters>::
    Convert(const blink::PublicKeyCredentialParameters& parameter) {}

// static
PublicKeyCredentialCreationOptionsPtr
TypeConverter<PublicKeyCredentialCreationOptionsPtr,
              blink::PublicKeyCredentialCreationOptions>::
    Convert(const blink::PublicKeyCredentialCreationOptions& options) {}

static Vector<uint8_t> ConvertFixedSizeArray(
    const blink::V8BufferSource* buffer,
    unsigned length) {}

// static
CableAuthenticationPtr
TypeConverter<CableAuthenticationPtr, blink::CableAuthenticationData>::Convert(
    const blink::CableAuthenticationData& data) {}

// static
PublicKeyCredentialRequestOptionsPtr
TypeConverter<PublicKeyCredentialRequestOptionsPtr,
              blink::PublicKeyCredentialRequestOptions>::
    Convert(const blink::PublicKeyCredentialRequestOptions& options) {}

// static
AuthenticationExtensionsClientInputsPtr
TypeConverter<AuthenticationExtensionsClientInputsPtr,
              blink::AuthenticationExtensionsClientInputs>::
    Convert(const blink::AuthenticationExtensionsClientInputs& inputs) {}

// static
RemoteDesktopClientOverridePtr
TypeConverter<RemoteDesktopClientOverridePtr,
              blink::RemoteDesktopClientOverride>::
    Convert(const blink::RemoteDesktopClientOverride& blink_value) {}

// static
IdentityProviderConfigPtr
TypeConverter<IdentityProviderConfigPtr, blink::IdentityProviderConfig>::
    Convert(const blink::IdentityProviderConfig& provider) {}

// static
IdentityProviderRequestOptionsPtr
TypeConverter<IdentityProviderRequestOptionsPtr,
              blink::IdentityProviderRequestOptions>::
    Convert(const blink::IdentityProviderRequestOptions& options) {}

// static
RpContext
TypeConverter<RpContext, blink::V8IdentityCredentialRequestOptionsContext>::
    Convert(const blink::V8IdentityCredentialRequestOptionsContext& context) {}

// static
RpMode
TypeConverter<RpMode, blink::V8IdentityCredentialRequestOptionsMode>::Convert(
    const blink::V8IdentityCredentialRequestOptionsMode& mode) {}

IdentityUserInfoPtr
TypeConverter<IdentityUserInfoPtr, blink::IdentityUserInfo>::Convert(
    const blink::IdentityUserInfo& user_info) {}

// static
std::optional<SupplementalPubKeysRequestPtr>
TypeConverter<std::optional<SupplementalPubKeysRequestPtr>,
              blink::AuthenticationExtensionsSupplementalPubKeysInputs>::
    Convert(const blink::AuthenticationExtensionsSupplementalPubKeysInputs&
                supplemental_pub_keys) {}

// static
PRFValuesPtr
TypeConverter<PRFValuesPtr, blink::AuthenticationExtensionsPRFValues>::Convert(
    const blink::AuthenticationExtensionsPRFValues& values) {}

// static
Vector<PRFValuesPtr>
TypeConverter<Vector<PRFValuesPtr>, blink::AuthenticationExtensionsPRFInputs>::
    Convert(const blink::AuthenticationExtensionsPRFInputs& prf) {}

// static
IdentityCredentialDisconnectOptionsPtr
TypeConverter<IdentityCredentialDisconnectOptionsPtr,
              blink::IdentityCredentialDisconnectOptions>::
    Convert(const blink::IdentityCredentialDisconnectOptions& options) {}

Vector<Hint> TypeConverter<Vector<Hint>, Vector<String>>::Convert(
    const Vector<String>& hints) {}

// static
blink::mojom::blink::PublicKeyCredentialReportOptionsPtr
TypeConverter<blink::mojom::blink::PublicKeyCredentialReportOptionsPtr,
              blink::UnknownCredentialOptions>::
    Convert(const blink::UnknownCredentialOptions& options) {}

// static
blink::mojom::blink::PublicKeyCredentialReportOptionsPtr
TypeConverter<blink::mojom::blink::PublicKeyCredentialReportOptionsPtr,
              blink::AllAcceptedCredentialsOptions>::
    Convert(const blink::AllAcceptedCredentialsOptions& options) {}

// static
blink::mojom::blink::PublicKeyCredentialReportOptionsPtr
TypeConverter<blink::mojom::blink::PublicKeyCredentialReportOptionsPtr,
              blink::CurrentUserDetailsOptions>::
    Convert(const blink::CurrentUserDetailsOptions& options) {}

}  // namespace mojo