summaryrefslogtreecommitdiffstats
path: root/remote/marionette/webauthn.sys.mjs
blob: c52bf6cb5c887a8e23e4d547efed63ee171fdf8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";

const lazy = {};

XPCOMUtils.defineLazyServiceGetter(
  lazy,
  "webauthnService",
  "@mozilla.org/webauthn/service;1",
  "nsIWebAuthnService"
);

/** @namespace */
export const webauthn = {};

/**
 * Add a virtual authenticator.
 *
 * @param {string} protocol one of "ctap1/u2f", "ctap2", "ctap2_1"
 * @param {string} transport one of "usb", "nfc", "ble", "smart-card",
 *                 "hybrid", "internal"
 * @param {boolean} hasResidentKey
 * @param {boolean} hasUserVerification
 * @param {boolean} isUserConsenting
 * @param {boolean} isUserVerified
 * @returns {id} the id of the added authenticator
 */
webauthn.addVirtualAuthenticator = function (
  protocol,
  transport,
  hasResidentKey,
  hasUserVerification,
  isUserConsenting,
  isUserVerified
) {
  return lazy.webauthnService.addVirtualAuthenticator(
    protocol,
    transport,
    hasResidentKey,
    hasUserVerification,
    isUserConsenting,
    isUserVerified
  );
};

/**
 * Removes a virtual authenticator.
 *
 * @param {id} authenticatorId the id of the virtual authenticator
 */
webauthn.removeVirtualAuthenticator = function (authenticatorId) {
  lazy.webauthnService.removeVirtualAuthenticator(authenticatorId);
};

/**
 * Adds a credential to a previously-added virtual authenticator.
 *
 * @param {id} authenticatorId the id of the virtual authenticator
 * @param {string} credentialId a probabilistically-unique byte sequence
 *                 identifying a public key credential source and its
 *                 authentication assertions (encoded using Base64url
 *                 Encoding).
 * @param {boolean} isResidentCredential if set to true, a client-side
 *                  discoverable credential is created. If set to false, a
 *                  server-side credential is created instead.
 * @param {string} rpId The Relying Party ID the credential is scoped to.
 * @param {string} privateKey An asymmetric key package containing a single
 *                 private key per RFC5958, encoded using Base64url Encoding.
 * @param {string} userHandle The userHandle associated to the credential
 *                 encoded using Base64url Encoding.
 * @param {number} signCount The initial value for a signature counter
 *                 associated to the public key credential source.
 */
webauthn.addCredential = function (
  authenticatorId,
  credentialId,
  isResidentCredential,
  rpId,
  privateKey,
  userHandle,
  signCount
) {
  lazy.webauthnService.addCredential(
    authenticatorId,
    credentialId,
    isResidentCredential,
    rpId,
    privateKey,
    userHandle,
    signCount
  );
};

/**
 * Gets all credentials from a virtual authenticator.
 *
 * @param {id} authenticatorId the id of the virtual authenticator
 * @returns {object} the credentials on the authenticator
 */
webauthn.getCredentials = function (authenticatorId) {
  return lazy.webauthnService.getCredentials(authenticatorId);
};

/**
 * Removes a credential from a virtual authenticator.
 *
 * @param {id} authenticatorId the id of the virtual authenticator
 * @param {string} credentialId the id of the credential
 */
webauthn.removeCredential = function (authenticatorId, credentialId) {
  lazy.webauthnService.removeCredential(authenticatorId, credentialId);
};

/**
 * Removes all credentials from a virtual authenticator.
 *
 * @param {id} authenticatorId the id of the virtual authenticator
 */
webauthn.removeAllCredentials = function (authenticatorId) {
  lazy.webauthnService.removeAllCredentials(authenticatorId);
};

/**
 * Sets the "isUserVerified" bit on a virtual authenticator.
 *
 * @param {id} authenticatorId the id of the virtual authenticator
 * @param {bool} isUserVerified the value to set the "isUserVerified" bit to
 */
webauthn.setUserVerified = function (authenticatorId, isUserVerified) {
  lazy.webauthnService.setUserVerified(authenticatorId, isUserVerified);
};