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 const nsString
& attPref
= mInfo
.attestationConveyancePreference();
159 if (attPref
.EqualsLiteral(
160 MOZ_WEBAUTHN_ATTESTATION_CONVEYANCE_PREFERENCE_INDIRECT
) ||
161 attPref
.EqualsLiteral(
162 MOZ_WEBAUTHN_ATTESTATION_CONVEYANCE_PREFERENCE_DIRECT
) ||
163 attPref
.EqualsLiteral(
164 MOZ_WEBAUTHN_ATTESTATION_CONVEYANCE_PREFERENCE_ENTERPRISE
)) {
165 aAttestationConveyancePreference
.Assign(attPref
);
167 aAttestationConveyancePreference
.AssignLiteral(
168 MOZ_WEBAUTHN_ATTESTATION_CONVEYANCE_PREFERENCE_NONE
);
173 NS_IMPL_ISUPPORTS(WebAuthnSignArgs
, nsIWebAuthnSignArgs
)
176 WebAuthnSignArgs::GetOrigin(nsAString
& aOrigin
) {
177 aOrigin
= mInfo
.Origin();
182 WebAuthnSignArgs::GetRpId(nsAString
& aRpId
) {
183 aRpId
= mInfo
.RpId();
188 WebAuthnSignArgs::GetChallenge(nsTArray
<uint8_t>& aChallenge
) {
189 aChallenge
.Assign(mInfo
.Challenge());
194 WebAuthnSignArgs::GetClientDataJSON(nsACString
& aClientDataJSON
) {
195 aClientDataJSON
= mInfo
.ClientDataJSON();
200 WebAuthnSignArgs::GetClientDataHash(nsTArray
<uint8_t>& aClientDataHash
) {
201 nsresult rv
= HashCString(mInfo
.ClientDataJSON(), aClientDataHash
);
202 if (NS_WARN_IF(NS_FAILED(rv
))) {
203 return NS_ERROR_FAILURE
;
210 WebAuthnSignArgs::GetAllowList(nsTArray
<nsTArray
<uint8_t> >& aAllowList
) {
212 for (const WebAuthnScopedCredential
& cred
: mInfo
.AllowList()) {
213 aAllowList
.AppendElement(cred
.id().Clone());
219 WebAuthnSignArgs::GetAllowListTransports(
220 nsTArray
<uint8_t>& aAllowListTransports
) {
221 aAllowListTransports
.Clear();
222 for (const WebAuthnScopedCredential
& cred
: mInfo
.AllowList()) {
223 aAllowListTransports
.AppendElement(cred
.transports());
229 WebAuthnSignArgs::GetHmacCreateSecret(bool* aHmacCreateSecret
) {
230 for (const WebAuthnExtension
& ext
: mInfo
.Extensions()) {
231 if (ext
.type() == WebAuthnExtension::TWebAuthnExtensionHmacSecret
) {
233 ext
.get_WebAuthnExtensionHmacSecret().hmacCreateSecret();
238 return NS_ERROR_NOT_AVAILABLE
;
242 WebAuthnSignArgs::GetAppId(nsAString
& aAppId
) {
243 if (mAppId
.isNothing()) {
244 return NS_ERROR_NOT_AVAILABLE
;
246 aAppId
= mAppId
.ref();
251 WebAuthnSignArgs::GetUserVerification(nsAString
& aUserVerificationRequirement
) {
252 aUserVerificationRequirement
= mInfo
.userVerificationRequirement();
257 WebAuthnSignArgs::GetTimeoutMS(uint32_t* aTimeoutMS
) {
258 *aTimeoutMS
= mInfo
.TimeoutMS();
263 WebAuthnSignArgs::GetConditionallyMediated(bool* aConditionallyMediated
) {
264 *aConditionallyMediated
= mInfo
.ConditionallyMediated();
268 } // namespace mozilla::dom