Bug 1861467 - [wpt-sync] Update web-platform-tests to eedf737ce39c512d0ca3471f988972e...
[gecko.git] / dom / webauthn / WebAuthnArgs.cpp
blob94cffc8dc63e9e7ceb80743b6f3d77dc3c68bc8a
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 aAttestationConveyancePreference = mInfo.attestationConveyancePreference();
159 return NS_OK;
162 NS_IMPL_ISUPPORTS(WebAuthnSignArgs, nsIWebAuthnSignArgs)
164 NS_IMETHODIMP
165 WebAuthnSignArgs::GetOrigin(nsAString& aOrigin) {
166 aOrigin = mInfo.Origin();
167 return NS_OK;
170 NS_IMETHODIMP
171 WebAuthnSignArgs::GetRpId(nsAString& aRpId) {
172 aRpId = mInfo.RpId();
173 return NS_OK;
176 NS_IMETHODIMP
177 WebAuthnSignArgs::GetChallenge(nsTArray<uint8_t>& aChallenge) {
178 aChallenge.Assign(mInfo.Challenge());
179 return NS_OK;
182 NS_IMETHODIMP
183 WebAuthnSignArgs::GetClientDataJSON(nsACString& aClientDataJSON) {
184 aClientDataJSON = mInfo.ClientDataJSON();
185 return NS_OK;
188 NS_IMETHODIMP
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;
195 return NS_OK;
198 NS_IMETHODIMP
199 WebAuthnSignArgs::GetAllowList(nsTArray<nsTArray<uint8_t> >& aAllowList) {
200 aAllowList.Clear();
201 for (const WebAuthnScopedCredential& cred : mInfo.AllowList()) {
202 aAllowList.AppendElement(cred.id().Clone());
204 return NS_OK;
207 NS_IMETHODIMP
208 WebAuthnSignArgs::GetAllowListTransports(
209 nsTArray<uint8_t>& aAllowListTransports) {
210 aAllowListTransports.Clear();
211 for (const WebAuthnScopedCredential& cred : mInfo.AllowList()) {
212 aAllowListTransports.AppendElement(cred.transports());
214 return NS_OK;
217 NS_IMETHODIMP
218 WebAuthnSignArgs::GetHmacCreateSecret(bool* aHmacCreateSecret) {
219 for (const WebAuthnExtension& ext : mInfo.Extensions()) {
220 if (ext.type() == WebAuthnExtension::TWebAuthnExtensionHmacSecret) {
221 *aHmacCreateSecret =
222 ext.get_WebAuthnExtensionHmacSecret().hmacCreateSecret();
223 return NS_OK;
227 return NS_ERROR_NOT_AVAILABLE;
230 NS_IMETHODIMP
231 WebAuthnSignArgs::GetAppId(nsAString& aAppId) {
232 if (mAppId.isNothing()) {
233 return NS_ERROR_NOT_AVAILABLE;
235 aAppId = mAppId.ref();
236 return NS_OK;
239 NS_IMETHODIMP
240 WebAuthnSignArgs::GetUserVerification(nsAString& aUserVerificationRequirement) {
241 aUserVerificationRequirement = mInfo.userVerificationRequirement();
242 return NS_OK;
245 NS_IMETHODIMP
246 WebAuthnSignArgs::GetTimeoutMS(uint32_t* aTimeoutMS) {
247 *aTimeoutMS = mInfo.TimeoutMS();
248 return NS_OK;
251 } // namespace mozilla::dom