// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../../ui/legacy/legacy.js';
import '../../ui/legacy/components/data_grid/data_grid.js';
import * as Common from '../../core/common/common.js';
import * as Host from '../../core/host/host.js';
import * as i18n from '../../core/i18n/i18n.js';
import type * as Platform from '../../core/platform/platform.js';
import * as SDK from '../../core/sdk/sdk.js';
import * as Protocol from '../../generated/protocol.js';
import * as Buttons from '../../ui/components/buttons/buttons.js';
import * as Input from '../../ui/components/input/input.js';
import * as UI from '../../ui/legacy/legacy.js';
import * as Lit from '../../ui/lit/lit.js';
import * as VisualLogging from '../../ui/visual_logging/visual_logging.js';
import webauthnPaneStyles from './webauthnPane.css.js';
const {render, html, Directives: {ref, repeat, classMap}} = Lit;
const {widgetConfig} = UI.Widget;
const UIStrings = {
/**
* @description Label for button that allows user to download the private key related to a credential.
*/
export: 'Export',
/**
* @description Label for an item to remove something
*/
remove: 'Remove',
/**
* @description Label for empty credentials table.
* @example {navigator.credentials.create()} PH1
*/
noCredentialsTryCallingSFromYour: 'No credentials. Try calling {PH1} from your website.',
/**
* @description Label for checkbox to toggle the virtual authenticator environment allowing user to interact with software-based virtual authenticators.
*/
enableVirtualAuthenticator: 'Enable virtual authenticator environment',
/**
* @description Label for ID field for credentials.
*/
id: 'ID',
/**
* @description Label for field that describes whether a credential is a resident credential.
*/
isResident: 'Is Resident',
/**
* @description Label for credential field that represents the Relying Party ID that the credential is scoped to.
*/
rpId: 'RP ID',
/**
* @description Label for a column in a table. A field/unique ID that represents the user a credential is mapped to.
*/
userHandle: 'User Handle',
/**
* @description Label for signature counter field for credentials which represents the number of successful assertions.
* See https://w3c.github.io/webauthn/#signature-counter.
*/
signCount: 'Signature Count',
/**
* @description Label for column with actions for credentials.
*/
actions: 'Actions',
/**
* @description Title for the table that holds the credentials that a authenticator has registered.
*/
credentials: 'Credentials',
/**
* @description Text that shows before the virtual environment is enabled.
*/
noAuthenticator: 'No authenticator set up',
/**
* @description That that shows before virtual environment is enabled explaining the panel.
*/
useWebauthnForPhishingresistant: 'Use WebAuthn for phishing-resistant authentication.',
/**
* @description Title for section of interface that allows user to add a new virtual authenticator.
*/
newAuthenticator: 'New authenticator',
/**
* @description Text for security or network protocol
*/
protocol: 'Protocol',
/**
* @description Label for input to select which transport option to use on virtual authenticators, e.g. USB or Bluetooth.
*/
transport: 'Transport',
/**
* @description Label for checkbox that toggles resident key support on virtual authenticators.
*/
supportsResidentKeys: 'Supports resident keys',
/**
* @description Label for checkbox that toggles large blob support on virtual authenticators. Large blobs are opaque data associated
* with a WebAuthn credential that a website can store, like an SSH certificate or a symmetric encryption key.
* See https://w3c.github.io/webauthn/#sctn-large-blob-extension
*/
supportsLargeBlob: 'Supports large blob',
/**
* @description Text to add something
*/
add: 'Add',
/**
* @description Label for radio button that toggles whether an authenticator is active.
*/
active: 'Active',
/**
* @description Title for button that enables user to customize name of authenticator.
*/
editName: 'Edit name',
/**
* @description Placeholder for the input box to customize name of authenticator.
*/
enterNewName: 'Enter new name',
/**
* @description Title for button that enables user to save name of authenticator after editing it.
*/
saveName: 'Save name',
/**
* @description Title for a user-added virtual authenticator which is uniquely identified with its AUTHENTICATORID.
* @example {8c7873be-0b13-4996-a794-1521331bbd96} PH1
*/
authenticatorS: 'Authenticator {PH1}',
/**
* @description Name for generated file which user can download. A private key is a secret code which enables encoding and decoding of a credential. .pem is the file extension.
*/
privateKeypem: 'Private key.pem',
/**
* @description Label for field that holds an authenticator's universally unique identifier (UUID).
*/
uuid: 'UUID',
/**
* @description Label for checkbox that toggles user verification support on virtual authenticators.
*/
supportsUserVerification: 'Supports user verification',
/**
* @description Text in Timeline indicating that input has happened recently
*/
yes: 'Yes',
/**
* @description Text in Timeline indicating that input has not happened recently
*/
no: 'No',
/**
* @description Title of radio button that sets an authenticator as active.
* @example {Authenticator ABCDEF} PH1
*/
setSAsTheActiveAuthenticator: 'Set {PH1} as the active authenticator',
} as const;
const str_ = i18n.i18n.registerUIStrings('panels/webauthn/WebauthnPane.ts', UIStrings);
const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
const i18nTemplate = Lit.i18nTemplate.bind(undefined, str_);
const WEB_AUTHN_EXPLANATION_URL =
'https://developer.chrome.com/docs/devtools/webauthn' as Platform.DevToolsPath.UrlString;
function renderCredentialsDataGrid(
authenticatorId: Protocol.WebAuthn.AuthenticatorId, credentials: Protocol.WebAuthn.Credential[],
onExport: (credential: Protocol.WebAuthn.Credential) => void,
onRemove: (credentialId: string) => void): Lit.TemplateResult {
// clang-format off
return html`
${i18nString(UIStrings.id)}
${i18nString(UIStrings.isResident)}
${i18nString(UIStrings.rpId)}
${i18nString(UIStrings.userHandle)}
${i18nString(UIStrings.signCount)}
${i18nString(UIStrings.actions)}
${credentials.length ? repeat(credentials, c => c.credentialId, credential => html`
`;
// clang-format on
}
/**
* Creates the fields describing the authenticator in the front end.
*/
function renderAuthenticatorFields(
authenticatorId: string, options: Protocol.WebAuthn.VirtualAuthenticatorOptions): Lit.TemplateResult {
// clang-format off
return html`