Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / webauthn / WebAuthnArgs.cpp
blobe4c44d149cb2db9c8ac4185c8548567f652ac64f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "WebAuthnArgs.h"
8 #include "WebAuthnEnumStrings.h"
9 #include "WebAuthnUtil.h"
10 #include "mozilla/dom/PWebAuthnTransactionParent.h"
12 namespace mozilla::dom {
14 NS_IMPL_ISUPPORTS(WebAuthnRegisterArgs, nsIWebAuthnRegisterArgs)
16 NS_IMETHODIMP
17 WebAuthnRegisterArgs::GetOrigin(nsAString& aOrigin) {
18 aOrigin = mInfo.Origin();
19 return NS_OK;
22 NS_IMETHODIMP
23 WebAuthnRegisterArgs::GetChallenge(nsTArray<uint8_t>& aChallenge) {
24 aChallenge.Assign(mInfo.Challenge());
25 return NS_OK;
28 NS_IMETHODIMP
29 WebAuthnRegisterArgs::GetClientDataJSON(nsACString& aClientDataJSON) {
30 aClientDataJSON = mInfo.ClientDataJSON();
31 return NS_OK;
34 NS_IMETHODIMP
35 WebAuthnRegisterArgs::GetClientDataHash(nsTArray<uint8_t>& aClientDataHash) {
36 nsresult rv = HashCString(mInfo.ClientDataJSON(), aClientDataHash);
37 if (NS_WARN_IF(NS_FAILED(rv))) {
38 return NS_ERROR_FAILURE;
41 return NS_OK;
44 NS_IMETHODIMP
45 WebAuthnRegisterArgs::GetRpId(nsAString& aRpId) {
46 aRpId = mInfo.RpId();
47 return NS_OK;
50 NS_IMETHODIMP
51 WebAuthnRegisterArgs::GetRpName(nsAString& aRpName) {
52 aRpName = mInfo.Rp().Name();
53 return NS_OK;
56 NS_IMETHODIMP
57 WebAuthnRegisterArgs::GetUserId(nsTArray<uint8_t>& aUserId) {
58 aUserId.Assign(mInfo.User().Id());
59 return NS_OK;
62 NS_IMETHODIMP
63 WebAuthnRegisterArgs::GetUserName(nsAString& aUserName) {
64 aUserName = mInfo.User().Name();
65 return NS_OK;
68 NS_IMETHODIMP
69 WebAuthnRegisterArgs::GetUserDisplayName(nsAString& aUserDisplayName) {
70 aUserDisplayName = mInfo.User().DisplayName();
71 return NS_OK;
74 NS_IMETHODIMP
75 WebAuthnRegisterArgs::GetCoseAlgs(nsTArray<int32_t>& aCoseAlgs) {
76 aCoseAlgs.Clear();
77 for (const CoseAlg& coseAlg : mInfo.coseAlgs()) {
78 aCoseAlgs.AppendElement(coseAlg.alg());
80 return NS_OK;
83 NS_IMETHODIMP
84 WebAuthnRegisterArgs::GetExcludeList(
85 nsTArray<nsTArray<uint8_t>>& aExcludeList) {
86 aExcludeList.Clear();
87 for (const WebAuthnScopedCredential& cred : mInfo.ExcludeList()) {
88 aExcludeList.AppendElement(cred.id().Clone());
90 return NS_OK;
93 NS_IMETHODIMP
94 WebAuthnRegisterArgs::GetExcludeListTransports(
95 nsTArray<uint8_t>& aExcludeListTransports) {
96 aExcludeListTransports.Clear();
97 for (const WebAuthnScopedCredential& cred : mInfo.ExcludeList()) {
98 aExcludeListTransports.AppendElement(cred.transports());
100 return NS_OK;
103 NS_IMETHODIMP
104 WebAuthnRegisterArgs::GetCredProps(bool* aCredProps) {
105 *aCredProps = mCredProps;
107 return NS_OK;
110 NS_IMETHODIMP
111 WebAuthnRegisterArgs::GetHmacCreateSecret(bool* aHmacCreateSecret) {
112 *aHmacCreateSecret = mHmacCreateSecret;
114 return NS_OK;
117 NS_IMETHODIMP
118 WebAuthnRegisterArgs::GetPrf(bool* aPrf) {
119 *aPrf = mPrf;
120 return NS_OK;
123 NS_IMETHODIMP
124 WebAuthnRegisterArgs::GetPrfEvalFirst(nsTArray<uint8_t>& aEvalFirst) {
125 for (const WebAuthnExtension& ext : mInfo.Extensions()) {
126 if (ext.type() == WebAuthnExtension::TWebAuthnExtensionPrf) {
127 Maybe<WebAuthnExtensionPrfValues> eval =
128 ext.get_WebAuthnExtensionPrf().eval();
129 if (eval.isSome()) {
130 aEvalFirst.Assign(eval->first());
131 return NS_OK;
133 break;
137 return NS_ERROR_NOT_AVAILABLE;
140 NS_IMETHODIMP
141 WebAuthnRegisterArgs::GetPrfEvalSecond(nsTArray<uint8_t>& aEvalSecond) {
142 for (const WebAuthnExtension& ext : mInfo.Extensions()) {
143 if (ext.type() == WebAuthnExtension::TWebAuthnExtensionPrf) {
144 Maybe<WebAuthnExtensionPrfValues> eval =
145 ext.get_WebAuthnExtensionPrf().eval();
146 if (eval.isSome() && eval->secondMaybe()) {
147 aEvalSecond.Assign(eval->second());
148 return NS_OK;
150 break;
154 return NS_ERROR_NOT_AVAILABLE;
157 NS_IMETHODIMP
158 WebAuthnRegisterArgs::GetMinPinLength(bool* aMinPinLength) {
159 *aMinPinLength = mMinPinLength;
161 return NS_OK;
164 NS_IMETHODIMP
165 WebAuthnRegisterArgs::GetResidentKey(nsAString& aResidentKey) {
166 aResidentKey = mInfo.AuthenticatorSelection().residentKey();
167 return NS_OK;
170 NS_IMETHODIMP
171 WebAuthnRegisterArgs::GetUserVerification(
172 nsAString& aUserVerificationRequirement) {
173 aUserVerificationRequirement =
174 mInfo.AuthenticatorSelection().userVerificationRequirement();
175 return NS_OK;
178 NS_IMETHODIMP
179 WebAuthnRegisterArgs::GetAuthenticatorAttachment(
180 nsAString& aAuthenticatorAttachment) {
181 if (mInfo.AuthenticatorSelection().authenticatorAttachment().isNothing()) {
182 return NS_ERROR_NOT_AVAILABLE;
184 aAuthenticatorAttachment =
185 *mInfo.AuthenticatorSelection().authenticatorAttachment();
186 return NS_OK;
189 NS_IMETHODIMP
190 WebAuthnRegisterArgs::GetTimeoutMS(uint32_t* aTimeoutMS) {
191 *aTimeoutMS = mInfo.TimeoutMS();
192 return NS_OK;
195 NS_IMETHODIMP
196 WebAuthnRegisterArgs::GetAttestationConveyancePreference(
197 nsAString& aAttestationConveyancePreference) {
198 const nsString& attPref = mInfo.attestationConveyancePreference();
199 if (attPref.EqualsLiteral(
200 MOZ_WEBAUTHN_ATTESTATION_CONVEYANCE_PREFERENCE_INDIRECT) ||
201 attPref.EqualsLiteral(
202 MOZ_WEBAUTHN_ATTESTATION_CONVEYANCE_PREFERENCE_DIRECT) ||
203 attPref.EqualsLiteral(
204 MOZ_WEBAUTHN_ATTESTATION_CONVEYANCE_PREFERENCE_ENTERPRISE)) {
205 aAttestationConveyancePreference.Assign(attPref);
206 } else {
207 aAttestationConveyancePreference.AssignLiteral(
208 MOZ_WEBAUTHN_ATTESTATION_CONVEYANCE_PREFERENCE_NONE);
210 return NS_OK;
213 NS_IMPL_ISUPPORTS(WebAuthnSignArgs, nsIWebAuthnSignArgs)
215 NS_IMETHODIMP
216 WebAuthnSignArgs::GetOrigin(nsAString& aOrigin) {
217 aOrigin = mInfo.Origin();
218 return NS_OK;
221 NS_IMETHODIMP
222 WebAuthnSignArgs::GetRpId(nsAString& aRpId) {
223 aRpId = mInfo.RpId();
224 return NS_OK;
227 NS_IMETHODIMP
228 WebAuthnSignArgs::GetChallenge(nsTArray<uint8_t>& aChallenge) {
229 aChallenge.Assign(mInfo.Challenge());
230 return NS_OK;
233 NS_IMETHODIMP
234 WebAuthnSignArgs::GetClientDataJSON(nsACString& aClientDataJSON) {
235 aClientDataJSON = mInfo.ClientDataJSON();
236 return NS_OK;
239 NS_IMETHODIMP
240 WebAuthnSignArgs::GetClientDataHash(nsTArray<uint8_t>& aClientDataHash) {
241 nsresult rv = HashCString(mInfo.ClientDataJSON(), aClientDataHash);
242 if (NS_WARN_IF(NS_FAILED(rv))) {
243 return NS_ERROR_FAILURE;
246 return NS_OK;
249 NS_IMETHODIMP
250 WebAuthnSignArgs::GetAllowList(nsTArray<nsTArray<uint8_t>>& aAllowList) {
251 aAllowList.Clear();
252 for (const WebAuthnScopedCredential& cred : mInfo.AllowList()) {
253 aAllowList.AppendElement(cred.id().Clone());
255 return NS_OK;
258 NS_IMETHODIMP
259 WebAuthnSignArgs::GetAllowListTransports(
260 nsTArray<uint8_t>& aAllowListTransports) {
261 aAllowListTransports.Clear();
262 for (const WebAuthnScopedCredential& cred : mInfo.AllowList()) {
263 aAllowListTransports.AppendElement(cred.transports());
265 return NS_OK;
268 NS_IMETHODIMP
269 WebAuthnSignArgs::GetHmacCreateSecret(bool* aHmacCreateSecret) {
270 for (const WebAuthnExtension& ext : mInfo.Extensions()) {
271 if (ext.type() == WebAuthnExtension::TWebAuthnExtensionHmacSecret) {
272 *aHmacCreateSecret =
273 ext.get_WebAuthnExtensionHmacSecret().hmacCreateSecret();
274 return NS_OK;
278 return NS_ERROR_NOT_AVAILABLE;
281 NS_IMETHODIMP
282 WebAuthnSignArgs::GetAppId(nsAString& aAppId) {
283 if (mAppId.isNothing()) {
284 return NS_ERROR_NOT_AVAILABLE;
286 aAppId = mAppId.ref();
287 return NS_OK;
290 NS_IMETHODIMP
291 WebAuthnSignArgs::GetPrf(bool* aPrf) {
292 *aPrf = mPrf;
293 return NS_OK;
296 NS_IMETHODIMP
297 WebAuthnSignArgs::GetPrfEvalFirst(nsTArray<uint8_t>& aEvalFirst) {
298 for (const WebAuthnExtension& ext : mInfo.Extensions()) {
299 if (ext.type() == WebAuthnExtension::TWebAuthnExtensionPrf) {
300 Maybe<WebAuthnExtensionPrfValues> eval =
301 ext.get_WebAuthnExtensionPrf().eval();
302 if (eval.isSome()) {
303 aEvalFirst.Assign(eval->first());
304 return NS_OK;
306 break;
310 return NS_ERROR_NOT_AVAILABLE;
313 NS_IMETHODIMP
314 WebAuthnSignArgs::GetPrfEvalSecond(nsTArray<uint8_t>& aEvalSecond) {
315 for (const WebAuthnExtension& ext : mInfo.Extensions()) {
316 if (ext.type() == WebAuthnExtension::TWebAuthnExtensionPrf) {
317 Maybe<WebAuthnExtensionPrfValues> eval =
318 ext.get_WebAuthnExtensionPrf().eval();
319 if (eval.isSome() && eval->secondMaybe()) {
320 aEvalSecond.Assign(eval->second());
321 return NS_OK;
323 break;
327 return NS_ERROR_NOT_AVAILABLE;
330 NS_IMETHODIMP
331 WebAuthnSignArgs::GetPrfEvalByCredentialCredentialId(
332 nsTArray<nsTArray<uint8_t>>& aCredentialIds) {
333 for (const WebAuthnExtension& ext : mInfo.Extensions()) {
334 if (ext.type() == WebAuthnExtension::TWebAuthnExtensionPrf) {
335 if (ext.get_WebAuthnExtensionPrf().evalByCredentialMaybe()) {
336 for (const WebAuthnExtensionPrfEvalByCredentialEntry& entry :
337 ext.get_WebAuthnExtensionPrf().evalByCredential()) {
338 aCredentialIds.AppendElement(entry.credentialId().Clone());
340 return NS_OK;
342 break;
346 return NS_ERROR_NOT_AVAILABLE;
349 NS_IMETHODIMP
350 WebAuthnSignArgs::GetPrfEvalByCredentialEvalFirst(
351 nsTArray<nsTArray<uint8_t>>& aEvalFirsts) {
352 for (const WebAuthnExtension& ext : mInfo.Extensions()) {
353 if (ext.type() == WebAuthnExtension::TWebAuthnExtensionPrf) {
354 if (ext.get_WebAuthnExtensionPrf().evalByCredentialMaybe()) {
355 for (const WebAuthnExtensionPrfEvalByCredentialEntry& entry :
356 ext.get_WebAuthnExtensionPrf().evalByCredential()) {
357 aEvalFirsts.AppendElement(entry.eval().first().Clone());
359 return NS_OK;
361 break;
365 return NS_ERROR_NOT_AVAILABLE;
368 NS_IMETHODIMP
369 WebAuthnSignArgs::GetPrfEvalByCredentialEvalSecondMaybe(
370 nsTArray<bool>& aEvalSecondMaybes) {
371 for (const WebAuthnExtension& ext : mInfo.Extensions()) {
372 if (ext.type() == WebAuthnExtension::TWebAuthnExtensionPrf) {
373 if (ext.get_WebAuthnExtensionPrf().evalByCredentialMaybe()) {
374 for (const WebAuthnExtensionPrfEvalByCredentialEntry& entry :
375 ext.get_WebAuthnExtensionPrf().evalByCredential()) {
376 aEvalSecondMaybes.AppendElement(entry.eval().secondMaybe());
378 return NS_OK;
380 break;
384 return NS_ERROR_NOT_AVAILABLE;
387 NS_IMETHODIMP
388 WebAuthnSignArgs::GetPrfEvalByCredentialEvalSecond(
389 nsTArray<nsTArray<uint8_t>>& aEvalSeconds) {
390 for (const WebAuthnExtension& ext : mInfo.Extensions()) {
391 if (ext.type() == WebAuthnExtension::TWebAuthnExtensionPrf) {
392 if (ext.get_WebAuthnExtensionPrf().evalByCredentialMaybe()) {
393 for (const WebAuthnExtensionPrfEvalByCredentialEntry& entry :
394 ext.get_WebAuthnExtensionPrf().evalByCredential()) {
395 if (entry.eval().secondMaybe()) {
396 aEvalSeconds.AppendElement(entry.eval().second().Clone());
397 } else {
398 aEvalSeconds.AppendElement(nsTArray<uint8_t>());
401 return NS_OK;
403 break;
407 return NS_ERROR_NOT_AVAILABLE;
410 NS_IMETHODIMP
411 WebAuthnSignArgs::GetUserVerification(nsAString& aUserVerificationRequirement) {
412 aUserVerificationRequirement = mInfo.userVerificationRequirement();
413 return NS_OK;
416 NS_IMETHODIMP
417 WebAuthnSignArgs::GetTimeoutMS(uint32_t* aTimeoutMS) {
418 *aTimeoutMS = mInfo.TimeoutMS();
419 return NS_OK;
422 NS_IMETHODIMP
423 WebAuthnSignArgs::GetConditionallyMediated(bool* aConditionallyMediated) {
424 *aConditionallyMediated = mInfo.ConditionallyMediated();
425 return NS_OK;
428 } // namespace mozilla::dom