Bug 1861467 - [wpt-sync] Update web-platform-tests to eedf737ce39c512d0ca3471f988972e...
[gecko.git] / dom / webauthn / WebAuthnService.cpp
blobde0a9556d05863b6f13207e62f2cf6525503f11c
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)
17 NS_IMETHODIMP
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,
24 aArgs, aPromise);
26 return mPlatformService->MakeCredential(aTransactionId, browsingContextId,
27 aArgs, aPromise);
30 NS_IMETHODIMP
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,
37 aPromise);
39 return mPlatformService->GetAssertion(aTransactionId, browsingContextId,
40 aArgs, aPromise);
43 NS_IMETHODIMP
44 WebAuthnService::Reset() {
45 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
46 return mTestService->Reset();
48 return mPlatformService->Reset();
51 NS_IMETHODIMP
52 WebAuthnService::Cancel(uint64_t aTransactionId) {
53 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
54 return mTestService->Cancel(aTransactionId);
56 return mPlatformService->Cancel(aTransactionId);
59 NS_IMETHODIMP
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);
67 NS_IMETHODIMP
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);
78 NS_IMETHODIMP
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);
86 NS_IMETHODIMP
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);
101 NS_IMETHODIMP
102 WebAuthnService::RemoveVirtualAuthenticator(uint64_t authenticatorId) {
103 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
104 return mTestService->RemoveVirtualAuthenticator(authenticatorId);
106 return mPlatformService->RemoveVirtualAuthenticator(authenticatorId);
109 NS_IMETHODIMP
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);
127 NS_IMETHODIMP
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);
137 NS_IMETHODIMP
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);
146 NS_IMETHODIMP
147 WebAuthnService::RemoveAllCredentials(uint64_t authenticatorId) {
148 if (StaticPrefs::security_webauth_webauthn_enable_softtoken()) {
149 return mTestService->RemoveAllCredentials(authenticatorId);
151 return mPlatformService->RemoveAllCredentials(authenticatorId);
154 NS_IMETHODIMP
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