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::GetClientDataHash(nsTArray
<uint8_t>& aClientDataHash
) {
30 nsresult rv
= HashCString(mInfo
.ClientDataJSON(), aClientDataHash
);
31 if (NS_WARN_IF(NS_FAILED(rv
))) {
32 return NS_ERROR_FAILURE
;
39 WebAuthnRegisterArgs::GetRpId(nsAString
& aRpId
) {
45 WebAuthnRegisterArgs::GetRpName(nsAString
& aRpName
) {
46 aRpName
= mInfo
.Rp().Name();
51 WebAuthnRegisterArgs::GetUserId(nsTArray
<uint8_t>& aUserId
) {
52 aUserId
.Assign(mInfo
.User().Id());
57 WebAuthnRegisterArgs::GetUserName(nsAString
& aUserName
) {
58 aUserName
= mInfo
.User().Name();
63 WebAuthnRegisterArgs::GetUserDisplayName(nsAString
& aUserDisplayName
) {
64 aUserDisplayName
= mInfo
.User().DisplayName();
69 WebAuthnRegisterArgs::GetCoseAlgs(nsTArray
<int32_t>& aCoseAlgs
) {
71 for (const CoseAlg
& coseAlg
: mInfo
.coseAlgs()) {
72 aCoseAlgs
.AppendElement(coseAlg
.alg());
78 WebAuthnRegisterArgs::GetExcludeList(
79 nsTArray
<nsTArray
<uint8_t> >& aExcludeList
) {
81 for (const WebAuthnScopedCredential
& cred
: mInfo
.ExcludeList()) {
82 aExcludeList
.AppendElement(cred
.id().Clone());
88 WebAuthnRegisterArgs::GetExcludeListTransports(
89 nsTArray
<uint8_t>& aExcludeListTransports
) {
90 aExcludeListTransports
.Clear();
91 for (const WebAuthnScopedCredential
& cred
: mInfo
.ExcludeList()) {
92 aExcludeListTransports
.AppendElement(cred
.transports());
98 WebAuthnRegisterArgs::GetCredProps(bool* aCredProps
) {
99 *aCredProps
= mCredProps
;
105 WebAuthnRegisterArgs::GetHmacCreateSecret(bool* aHmacCreateSecret
) {
106 *aHmacCreateSecret
= mHmacCreateSecret
;
112 WebAuthnRegisterArgs::GetMinPinLength(bool* aMinPinLength
) {
113 *aMinPinLength
= mMinPinLength
;
119 WebAuthnRegisterArgs::GetResidentKey(nsAString
& aResidentKey
) {
120 aResidentKey
= mInfo
.AuthenticatorSelection().residentKey();
125 WebAuthnRegisterArgs::GetUserVerification(
126 nsAString
& aUserVerificationRequirement
) {
127 aUserVerificationRequirement
=
128 mInfo
.AuthenticatorSelection().userVerificationRequirement();
133 WebAuthnRegisterArgs::GetAuthenticatorAttachment(
134 nsAString
& aAuthenticatorAttachment
) {
135 if (mInfo
.AuthenticatorSelection().authenticatorAttachment().isNothing()) {
136 return NS_ERROR_NOT_AVAILABLE
;
138 aAuthenticatorAttachment
=
139 *mInfo
.AuthenticatorSelection().authenticatorAttachment();
144 WebAuthnRegisterArgs::GetTimeoutMS(uint32_t* aTimeoutMS
) {
145 *aTimeoutMS
= mInfo
.TimeoutMS();
150 WebAuthnRegisterArgs::GetAttestationConveyancePreference(
151 nsAString
& aAttestationConveyancePreference
) {
152 aAttestationConveyancePreference
= mInfo
.attestationConveyancePreference();
156 NS_IMPL_ISUPPORTS(WebAuthnSignArgs
, nsIWebAuthnSignArgs
)
159 WebAuthnSignArgs::GetOrigin(nsAString
& aOrigin
) {
160 aOrigin
= mInfo
.Origin();
165 WebAuthnSignArgs::GetRpId(nsAString
& aRpId
) {
166 aRpId
= mInfo
.RpId();
171 WebAuthnSignArgs::GetChallenge(nsTArray
<uint8_t>& aChallenge
) {
172 aChallenge
.Assign(mInfo
.Challenge());
177 WebAuthnSignArgs::GetClientDataHash(nsTArray
<uint8_t>& aClientDataHash
) {
178 nsresult rv
= HashCString(mInfo
.ClientDataJSON(), aClientDataHash
);
179 if (NS_WARN_IF(NS_FAILED(rv
))) {
180 return NS_ERROR_FAILURE
;
187 WebAuthnSignArgs::GetAllowList(nsTArray
<nsTArray
<uint8_t> >& aAllowList
) {
189 for (const WebAuthnScopedCredential
& cred
: mInfo
.AllowList()) {
190 aAllowList
.AppendElement(cred
.id().Clone());
196 WebAuthnSignArgs::GetAllowListTransports(
197 nsTArray
<uint8_t>& aAllowListTransports
) {
198 aAllowListTransports
.Clear();
199 for (const WebAuthnScopedCredential
& cred
: mInfo
.AllowList()) {
200 aAllowListTransports
.AppendElement(cred
.transports());
206 WebAuthnSignArgs::GetHmacCreateSecret(bool* aHmacCreateSecret
) {
207 for (const WebAuthnExtension
& ext
: mInfo
.Extensions()) {
208 if (ext
.type() == WebAuthnExtension::TWebAuthnExtensionHmacSecret
) {
210 ext
.get_WebAuthnExtensionHmacSecret().hmacCreateSecret();
215 return NS_ERROR_NOT_AVAILABLE
;
219 WebAuthnSignArgs::GetAppId(nsAString
& aAppId
) {
220 for (const WebAuthnExtension
& ext
: mInfo
.Extensions()) {
221 if (ext
.type() == WebAuthnExtension::TWebAuthnExtensionAppId
) {
222 aAppId
= ext
.get_WebAuthnExtensionAppId().appIdentifier();
227 return NS_ERROR_NOT_AVAILABLE
;
231 WebAuthnSignArgs::GetUserVerification(nsAString
& aUserVerificationRequirement
) {
232 aUserVerificationRequirement
= mInfo
.userVerificationRequirement();
237 WebAuthnSignArgs::GetTimeoutMS(uint32_t* aTimeoutMS
) {
238 *aTimeoutMS
= mInfo
.TimeoutMS();
242 } // namespace mozilla::dom