1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "mozilla/StaticPrefs_security.h"
6 #include "WebAuthnService.h"
8 namespace mozilla::dom
{
10 already_AddRefed
<nsIWebAuthnService
> NewWebAuthnService() {
11 nsCOMPtr
<nsIWebAuthnService
> webauthnService(new WebAuthnService());
12 return webauthnService
.forget();
15 NS_IMPL_ISUPPORTS(WebAuthnService
, nsIWebAuthnService
)
18 WebAuthnService::MakeCredential(uint64_t aTransactionId
,
19 uint64_t browsingContextId
,
20 nsIWebAuthnRegisterArgs
* aArgs
,
21 nsIWebAuthnRegisterPromise
* aPromise
) {
22 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
23 return mTestService
->MakeCredential(aTransactionId
, browsingContextId
,
26 return mPlatformService
->MakeCredential(aTransactionId
, browsingContextId
,
31 WebAuthnService::GetAssertion(uint64_t aTransactionId
,
32 uint64_t browsingContextId
,
33 nsIWebAuthnSignArgs
* aArgs
,
34 nsIWebAuthnSignPromise
* aPromise
) {
35 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
36 return mTestService
->GetAssertion(aTransactionId
, browsingContextId
, aArgs
,
39 return mPlatformService
->GetAssertion(aTransactionId
, browsingContextId
,
44 WebAuthnService::Reset() {
45 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
46 return mTestService
->Reset();
48 return mPlatformService
->Reset();
52 WebAuthnService::Cancel(uint64_t aTransactionId
) {
53 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
54 return mTestService
->Cancel(aTransactionId
);
56 return mPlatformService
->Cancel(aTransactionId
);
60 WebAuthnService::PinCallback(uint64_t aTransactionId
, const nsACString
& aPin
) {
61 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
62 return mTestService
->PinCallback(aTransactionId
, aPin
);
64 return mPlatformService
->PinCallback(aTransactionId
, aPin
);
68 WebAuthnService::ResumeMakeCredential(uint64_t aTransactionId
,
69 bool aForceNoneAttestation
) {
70 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
71 return mTestService
->ResumeMakeCredential(aTransactionId
,
72 aForceNoneAttestation
);
74 return mPlatformService
->ResumeMakeCredential(aTransactionId
,
75 aForceNoneAttestation
);
79 WebAuthnService::SelectionCallback(uint64_t aTransactionId
, uint64_t aIndex
) {
80 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
81 return mTestService
->SelectionCallback(aTransactionId
, aIndex
);
83 return mPlatformService
->SelectionCallback(aTransactionId
, aIndex
);
87 WebAuthnService::AddVirtualAuthenticator(
88 const nsACString
& protocol
, const nsACString
& transport
,
89 bool hasResidentKey
, bool hasUserVerification
, bool isUserConsenting
,
90 bool isUserVerified
, uint64_t* retval
) {
91 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
92 return mTestService
->AddVirtualAuthenticator(
93 protocol
, transport
, hasResidentKey
, hasUserVerification
,
94 isUserConsenting
, isUserVerified
, retval
);
96 return mPlatformService
->AddVirtualAuthenticator(
97 protocol
, transport
, hasResidentKey
, hasUserVerification
,
98 isUserConsenting
, isUserVerified
, retval
);
102 WebAuthnService::RemoveVirtualAuthenticator(uint64_t authenticatorId
) {
103 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
104 return mTestService
->RemoveVirtualAuthenticator(authenticatorId
);
106 return mPlatformService
->RemoveVirtualAuthenticator(authenticatorId
);
110 WebAuthnService::AddCredential(uint64_t authenticatorId
,
111 const nsACString
& credentialId
,
112 bool isResidentCredential
,
113 const nsACString
& rpId
,
114 const nsACString
& privateKey
,
115 const nsACString
& userHandle
,
116 uint32_t signCount
) {
117 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
118 return mTestService
->AddCredential(authenticatorId
, credentialId
,
119 isResidentCredential
, rpId
, privateKey
,
120 userHandle
, signCount
);
122 return mPlatformService
->AddCredential(authenticatorId
, credentialId
,
123 isResidentCredential
, rpId
, privateKey
,
124 userHandle
, signCount
);
128 WebAuthnService::GetCredentials(
129 uint64_t authenticatorId
,
130 nsTArray
<RefPtr
<nsICredentialParameters
>>& retval
) {
131 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
132 return mTestService
->GetCredentials(authenticatorId
, retval
);
134 return mPlatformService
->GetCredentials(authenticatorId
, retval
);
138 WebAuthnService::RemoveCredential(uint64_t authenticatorId
,
139 const nsACString
& credentialId
) {
140 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
141 return mTestService
->RemoveCredential(authenticatorId
, credentialId
);
143 return mPlatformService
->RemoveCredential(authenticatorId
, credentialId
);
147 WebAuthnService::RemoveAllCredentials(uint64_t authenticatorId
) {
148 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
149 return mTestService
->RemoveAllCredentials(authenticatorId
);
151 return mPlatformService
->RemoveAllCredentials(authenticatorId
);
155 WebAuthnService::SetUserVerified(uint64_t authenticatorId
,
156 bool isUserVerified
) {
157 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
158 return mTestService
->SetUserVerified(authenticatorId
, isUserVerified
);
160 return mPlatformService
->SetUserVerified(authenticatorId
, isUserVerified
);
163 } // namespace mozilla::dom