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::GetMinPinLength(bool* aMinPinLength
) {
119 *aMinPinLength
= mMinPinLength
;
125 WebAuthnRegisterArgs::GetResidentKey(nsAString
& aResidentKey
) {
126 aResidentKey
= mInfo
.AuthenticatorSelection().residentKey();
131 WebAuthnRegisterArgs::GetUserVerification(
132 nsAString
& aUserVerificationRequirement
) {
133 aUserVerificationRequirement
=
134 mInfo
.AuthenticatorSelection().userVerificationRequirement();
139 WebAuthnRegisterArgs::GetAuthenticatorAttachment(
140 nsAString
& aAuthenticatorAttachment
) {
141 if (mInfo
.AuthenticatorSelection().authenticatorAttachment().isNothing()) {
142 return NS_ERROR_NOT_AVAILABLE
;
144 aAuthenticatorAttachment
=
145 *mInfo
.AuthenticatorSelection().authenticatorAttachment();
150 WebAuthnRegisterArgs::GetTimeoutMS(uint32_t* aTimeoutMS
) {
151 *aTimeoutMS
= mInfo
.TimeoutMS();
156 WebAuthnRegisterArgs::GetAttestationConveyancePreference(
157 nsAString
& aAttestationConveyancePreference
) {
158 aAttestationConveyancePreference
= mInfo
.attestationConveyancePreference();
162 NS_IMPL_ISUPPORTS(WebAuthnSignArgs
, nsIWebAuthnSignArgs
)
165 WebAuthnSignArgs::GetOrigin(nsAString
& aOrigin
) {
166 aOrigin
= mInfo
.Origin();
171 WebAuthnSignArgs::GetRpId(nsAString
& aRpId
) {
172 aRpId
= mInfo
.RpId();
177 WebAuthnSignArgs::GetChallenge(nsTArray
<uint8_t>& aChallenge
) {
178 aChallenge
.Assign(mInfo
.Challenge());
183 WebAuthnSignArgs::GetClientDataJSON(nsACString
& aClientDataJSON
) {
184 aClientDataJSON
= mInfo
.ClientDataJSON();
189 WebAuthnSignArgs::GetClientDataHash(nsTArray
<uint8_t>& aClientDataHash
) {
190 nsresult rv
= HashCString(mInfo
.ClientDataJSON(), aClientDataHash
);
191 if (NS_WARN_IF(NS_FAILED(rv
))) {
192 return NS_ERROR_FAILURE
;
199 WebAuthnSignArgs::GetAllowList(nsTArray
<nsTArray
<uint8_t> >& aAllowList
) {
201 for (const WebAuthnScopedCredential
& cred
: mInfo
.AllowList()) {
202 aAllowList
.AppendElement(cred
.id().Clone());
208 WebAuthnSignArgs::GetAllowListTransports(
209 nsTArray
<uint8_t>& aAllowListTransports
) {
210 aAllowListTransports
.Clear();
211 for (const WebAuthnScopedCredential
& cred
: mInfo
.AllowList()) {
212 aAllowListTransports
.AppendElement(cred
.transports());
218 WebAuthnSignArgs::GetHmacCreateSecret(bool* aHmacCreateSecret
) {
219 for (const WebAuthnExtension
& ext
: mInfo
.Extensions()) {
220 if (ext
.type() == WebAuthnExtension::TWebAuthnExtensionHmacSecret
) {
222 ext
.get_WebAuthnExtensionHmacSecret().hmacCreateSecret();
227 return NS_ERROR_NOT_AVAILABLE
;
231 WebAuthnSignArgs::GetAppId(nsAString
& aAppId
) {
232 if (mAppId
.isNothing()) {
233 return NS_ERROR_NOT_AVAILABLE
;
235 aAppId
= mAppId
.ref();
240 WebAuthnSignArgs::GetUserVerification(nsAString
& aUserVerificationRequirement
) {
241 aUserVerificationRequirement
= mInfo
.userVerificationRequirement();
246 WebAuthnSignArgs::GetTimeoutMS(uint32_t* aTimeoutMS
) {
247 *aTimeoutMS
= mInfo
.TimeoutMS();
252 WebAuthnSignArgs::GetConditionallyMediated(bool* aConditionallyMediated
) {
253 *aConditionallyMediated
= mInfo
.ConditionallyMediated();
257 } // namespace mozilla::dom