Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / webauthn / WebAuthnArgs.cpp
blobc094a71963f16595c129b20dffaabaeca78bda20
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::GetMinPinLength(bool* aMinPinLength) {
119 *aMinPinLength = mMinPinLength;
121 return NS_OK;
124 NS_IMETHODIMP
125 WebAuthnRegisterArgs::GetResidentKey(nsAString& aResidentKey) {
126 aResidentKey = mInfo.AuthenticatorSelection().residentKey();
127 return NS_OK;
130 NS_IMETHODIMP
131 WebAuthnRegisterArgs::GetUserVerification(
132 nsAString& aUserVerificationRequirement) {
133 aUserVerificationRequirement =
134 mInfo.AuthenticatorSelection().userVerificationRequirement();
135 return NS_OK;
138 NS_IMETHODIMP
139 WebAuthnRegisterArgs::GetAuthenticatorAttachment(
140 nsAString& aAuthenticatorAttachment) {
141 if (mInfo.AuthenticatorSelection().authenticatorAttachment().isNothing()) {
142 return NS_ERROR_NOT_AVAILABLE;
144 aAuthenticatorAttachment =
145 *mInfo.AuthenticatorSelection().authenticatorAttachment();
146 return NS_OK;
149 NS_IMETHODIMP
150 WebAuthnRegisterArgs::GetTimeoutMS(uint32_t* aTimeoutMS) {
151 *aTimeoutMS = mInfo.TimeoutMS();
152 return NS_OK;
155 NS_IMETHODIMP
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);
166 } else {
167 aAttestationConveyancePreference.AssignLiteral(
168 MOZ_WEBAUTHN_ATTESTATION_CONVEYANCE_PREFERENCE_NONE);
170 return NS_OK;
173 NS_IMPL_ISUPPORTS(WebAuthnSignArgs, nsIWebAuthnSignArgs)
175 NS_IMETHODIMP
176 WebAuthnSignArgs::GetOrigin(nsAString& aOrigin) {
177 aOrigin = mInfo.Origin();
178 return NS_OK;
181 NS_IMETHODIMP
182 WebAuthnSignArgs::GetRpId(nsAString& aRpId) {
183 aRpId = mInfo.RpId();
184 return NS_OK;
187 NS_IMETHODIMP
188 WebAuthnSignArgs::GetChallenge(nsTArray<uint8_t>& aChallenge) {
189 aChallenge.Assign(mInfo.Challenge());
190 return NS_OK;
193 NS_IMETHODIMP
194 WebAuthnSignArgs::GetClientDataJSON(nsACString& aClientDataJSON) {
195 aClientDataJSON = mInfo.ClientDataJSON();
196 return NS_OK;
199 NS_IMETHODIMP
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;
206 return NS_OK;
209 NS_IMETHODIMP
210 WebAuthnSignArgs::GetAllowList(nsTArray<nsTArray<uint8_t> >& aAllowList) {
211 aAllowList.Clear();
212 for (const WebAuthnScopedCredential& cred : mInfo.AllowList()) {
213 aAllowList.AppendElement(cred.id().Clone());
215 return NS_OK;
218 NS_IMETHODIMP
219 WebAuthnSignArgs::GetAllowListTransports(
220 nsTArray<uint8_t>& aAllowListTransports) {
221 aAllowListTransports.Clear();
222 for (const WebAuthnScopedCredential& cred : mInfo.AllowList()) {
223 aAllowListTransports.AppendElement(cred.transports());
225 return NS_OK;
228 NS_IMETHODIMP
229 WebAuthnSignArgs::GetHmacCreateSecret(bool* aHmacCreateSecret) {
230 for (const WebAuthnExtension& ext : mInfo.Extensions()) {
231 if (ext.type() == WebAuthnExtension::TWebAuthnExtensionHmacSecret) {
232 *aHmacCreateSecret =
233 ext.get_WebAuthnExtensionHmacSecret().hmacCreateSecret();
234 return NS_OK;
238 return NS_ERROR_NOT_AVAILABLE;
241 NS_IMETHODIMP
242 WebAuthnSignArgs::GetAppId(nsAString& aAppId) {
243 if (mAppId.isNothing()) {
244 return NS_ERROR_NOT_AVAILABLE;
246 aAppId = mAppId.ref();
247 return NS_OK;
250 NS_IMETHODIMP
251 WebAuthnSignArgs::GetUserVerification(nsAString& aUserVerificationRequirement) {
252 aUserVerificationRequirement = mInfo.userVerificationRequirement();
253 return NS_OK;
256 NS_IMETHODIMP
257 WebAuthnSignArgs::GetTimeoutMS(uint32_t* aTimeoutMS) {
258 *aTimeoutMS = mInfo.TimeoutMS();
259 return NS_OK;
262 NS_IMETHODIMP
263 WebAuthnSignArgs::GetConditionallyMediated(bool* aConditionallyMediated) {
264 *aConditionallyMediated = mInfo.ConditionallyMediated();
265 return NS_OK;
268 } // namespace mozilla::dom