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
)
17 WebAuthnRegisterArgs::GetOrigin(nsAString
& aOrigin
) {
18 aOrigin
= mInfo
.Origin();
23 WebAuthnRegisterArgs::GetChallenge(nsTArray
<uint8_t>& aChallenge
) {
24 aChallenge
.Assign(mInfo
.Challenge());
29 WebAuthnRegisterArgs::GetClientDataJSON(nsACString
& aClientDataJSON
) {
30 aClientDataJSON
= mInfo
.ClientDataJSON();
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
;
45 WebAuthnRegisterArgs::GetRpId(nsAString
& aRpId
) {
51 WebAuthnRegisterArgs::GetRpName(nsAString
& aRpName
) {
52 aRpName
= mInfo
.Rp().Name();
57 WebAuthnRegisterArgs::GetUserId(nsTArray
<uint8_t>& aUserId
) {
58 aUserId
.Assign(mInfo
.User().Id());
63 WebAuthnRegisterArgs::GetUserName(nsAString
& aUserName
) {
64 aUserName
= mInfo
.User().Name();
69 WebAuthnRegisterArgs::GetUserDisplayName(nsAString
& aUserDisplayName
) {
70 aUserDisplayName
= mInfo
.User().DisplayName();
75 WebAuthnRegisterArgs::GetCoseAlgs(nsTArray
<int32_t>& aCoseAlgs
) {
77 for (const CoseAlg
& coseAlg
: mInfo
.coseAlgs()) {
78 aCoseAlgs
.AppendElement(coseAlg
.alg());
84 WebAuthnRegisterArgs::GetExcludeList(
85 nsTArray
<nsTArray
<uint8_t>>& aExcludeList
) {
87 for (const WebAuthnScopedCredential
& cred
: mInfo
.ExcludeList()) {
88 aExcludeList
.AppendElement(cred
.id().Clone());
94 WebAuthnRegisterArgs::GetExcludeListTransports(
95 nsTArray
<uint8_t>& aExcludeListTransports
) {
96 aExcludeListTransports
.Clear();
97 for (const WebAuthnScopedCredential
& cred
: mInfo
.ExcludeList()) {
98 aExcludeListTransports
.AppendElement(cred
.transports());
104 WebAuthnRegisterArgs::GetCredProps(bool* aCredProps
) {
105 *aCredProps
= mCredProps
;
111 WebAuthnRegisterArgs::GetHmacCreateSecret(bool* aHmacCreateSecret
) {
112 *aHmacCreateSecret
= mHmacCreateSecret
;
118 WebAuthnRegisterArgs::GetPrf(bool* aPrf
) {
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();
130 aEvalFirst
.Assign(eval
->first());
137 return NS_ERROR_NOT_AVAILABLE
;
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());
154 return NS_ERROR_NOT_AVAILABLE
;
158 WebAuthnRegisterArgs::GetMinPinLength(bool* aMinPinLength
) {
159 *aMinPinLength
= mMinPinLength
;
165 WebAuthnRegisterArgs::GetResidentKey(nsAString
& aResidentKey
) {
166 aResidentKey
= mInfo
.AuthenticatorSelection().residentKey();
171 WebAuthnRegisterArgs::GetUserVerification(
172 nsAString
& aUserVerificationRequirement
) {
173 aUserVerificationRequirement
=
174 mInfo
.AuthenticatorSelection().userVerificationRequirement();
179 WebAuthnRegisterArgs::GetAuthenticatorAttachment(
180 nsAString
& aAuthenticatorAttachment
) {
181 if (mInfo
.AuthenticatorSelection().authenticatorAttachment().isNothing()) {
182 return NS_ERROR_NOT_AVAILABLE
;
184 aAuthenticatorAttachment
=
185 *mInfo
.AuthenticatorSelection().authenticatorAttachment();
190 WebAuthnRegisterArgs::GetTimeoutMS(uint32_t* aTimeoutMS
) {
191 *aTimeoutMS
= mInfo
.TimeoutMS();
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
);
207 aAttestationConveyancePreference
.AssignLiteral(
208 MOZ_WEBAUTHN_ATTESTATION_CONVEYANCE_PREFERENCE_NONE
);
213 NS_IMPL_ISUPPORTS(WebAuthnSignArgs
, nsIWebAuthnSignArgs
)
216 WebAuthnSignArgs::GetOrigin(nsAString
& aOrigin
) {
217 aOrigin
= mInfo
.Origin();
222 WebAuthnSignArgs::GetRpId(nsAString
& aRpId
) {
223 aRpId
= mInfo
.RpId();
228 WebAuthnSignArgs::GetChallenge(nsTArray
<uint8_t>& aChallenge
) {
229 aChallenge
.Assign(mInfo
.Challenge());
234 WebAuthnSignArgs::GetClientDataJSON(nsACString
& aClientDataJSON
) {
235 aClientDataJSON
= mInfo
.ClientDataJSON();
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
;
250 WebAuthnSignArgs::GetAllowList(nsTArray
<nsTArray
<uint8_t>>& aAllowList
) {
252 for (const WebAuthnScopedCredential
& cred
: mInfo
.AllowList()) {
253 aAllowList
.AppendElement(cred
.id().Clone());
259 WebAuthnSignArgs::GetAllowListTransports(
260 nsTArray
<uint8_t>& aAllowListTransports
) {
261 aAllowListTransports
.Clear();
262 for (const WebAuthnScopedCredential
& cred
: mInfo
.AllowList()) {
263 aAllowListTransports
.AppendElement(cred
.transports());
269 WebAuthnSignArgs::GetHmacCreateSecret(bool* aHmacCreateSecret
) {
270 for (const WebAuthnExtension
& ext
: mInfo
.Extensions()) {
271 if (ext
.type() == WebAuthnExtension::TWebAuthnExtensionHmacSecret
) {
273 ext
.get_WebAuthnExtensionHmacSecret().hmacCreateSecret();
278 return NS_ERROR_NOT_AVAILABLE
;
282 WebAuthnSignArgs::GetAppId(nsAString
& aAppId
) {
283 if (mAppId
.isNothing()) {
284 return NS_ERROR_NOT_AVAILABLE
;
286 aAppId
= mAppId
.ref();
291 WebAuthnSignArgs::GetPrf(bool* aPrf
) {
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();
303 aEvalFirst
.Assign(eval
->first());
310 return NS_ERROR_NOT_AVAILABLE
;
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());
327 return NS_ERROR_NOT_AVAILABLE
;
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());
346 return NS_ERROR_NOT_AVAILABLE
;
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());
365 return NS_ERROR_NOT_AVAILABLE
;
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());
384 return NS_ERROR_NOT_AVAILABLE
;
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());
398 aEvalSeconds
.AppendElement(nsTArray
<uint8_t>());
407 return NS_ERROR_NOT_AVAILABLE
;
411 WebAuthnSignArgs::GetUserVerification(nsAString
& aUserVerificationRequirement
) {
412 aUserVerificationRequirement
= mInfo
.userVerificationRequirement();
417 WebAuthnSignArgs::GetTimeoutMS(uint32_t* aTimeoutMS
) {
418 *aTimeoutMS
= mInfo
.TimeoutMS();
423 WebAuthnSignArgs::GetConditionallyMediated(bool* aConditionallyMediated
) {
424 *aConditionallyMediated
= mInfo
.ConditionallyMediated();
428 } // namespace mozilla::dom