Bug 1880216 - Migrate Fenix docs into Sphinx. r=owlish,geckoview-reviewers,android...
[gecko.git] / dom / webauthn / WebAuthnResult.cpp
blob268dd62f2088a21be0e980d282900f94a9f6feaa
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "AuthrsBridge_ffi.h"
6 #include "WebAuthnResult.h"
7 #include "nsIWebAuthnAttObj.h"
8 #include "nsCOMPtr.h"
9 #include "nsString.h"
11 #ifdef MOZ_WIDGET_ANDROID
12 namespace mozilla::jni {
14 template <>
15 RefPtr<dom::WebAuthnRegisterResult> Java2Native(
16 mozilla::jni::Object::Param aData, JNIEnv* aEnv) {
17 MOZ_ASSERT(
18 aData.IsInstanceOf<java::WebAuthnTokenManager::MakeCredentialResponse>());
19 java::WebAuthnTokenManager::MakeCredentialResponse::LocalRef response(aData);
20 RefPtr<dom::WebAuthnRegisterResult> result =
21 new dom::WebAuthnRegisterResult(response);
22 return result;
25 template <>
26 RefPtr<dom::WebAuthnSignResult> Java2Native(mozilla::jni::Object::Param aData,
27 JNIEnv* aEnv) {
28 MOZ_ASSERT(
29 aData.IsInstanceOf<java::WebAuthnTokenManager::GetAssertionResponse>());
30 java::WebAuthnTokenManager::GetAssertionResponse::LocalRef response(aData);
31 RefPtr<dom::WebAuthnSignResult> result =
32 new dom::WebAuthnSignResult(response);
33 return result;
36 } // namespace mozilla::jni
37 #endif
39 namespace mozilla::dom {
41 NS_IMPL_ISUPPORTS(WebAuthnRegisterResult, nsIWebAuthnRegisterResult)
43 NS_IMETHODIMP
44 WebAuthnRegisterResult::GetClientDataJSON(nsACString& aClientDataJSON) {
45 if (mClientDataJSON.isSome()) {
46 aClientDataJSON = *mClientDataJSON;
47 return NS_OK;
49 return NS_ERROR_NOT_AVAILABLE;
52 NS_IMETHODIMP
53 WebAuthnRegisterResult::GetAttestationObject(
54 nsTArray<uint8_t>& aAttestationObject) {
55 aAttestationObject.Assign(mAttestationObject);
56 return NS_OK;
59 NS_IMETHODIMP
60 WebAuthnRegisterResult::GetCredentialId(nsTArray<uint8_t>& aCredentialId) {
61 aCredentialId.Assign(mCredentialId);
62 return NS_OK;
65 NS_IMETHODIMP
66 WebAuthnRegisterResult::GetTransports(nsTArray<nsString>& aTransports) {
67 aTransports.Assign(mTransports);
68 return NS_OK;
71 NS_IMETHODIMP
72 WebAuthnRegisterResult::GetHmacCreateSecret(bool* aHmacCreateSecret) {
73 if (mHmacCreateSecret.isSome()) {
74 *aHmacCreateSecret = mHmacCreateSecret.ref();
75 return NS_OK;
77 return NS_ERROR_NOT_AVAILABLE;
80 NS_IMETHODIMP
81 WebAuthnRegisterResult::GetCredPropsRk(bool* aCredPropsRk) {
82 if (mCredPropsRk.isSome()) {
83 *aCredPropsRk = mCredPropsRk.ref();
84 return NS_OK;
86 return NS_ERROR_NOT_AVAILABLE;
89 NS_IMETHODIMP
90 WebAuthnRegisterResult::SetCredPropsRk(bool aCredPropsRk) {
91 mCredPropsRk = Some(aCredPropsRk);
92 return NS_OK;
95 NS_IMETHODIMP
96 WebAuthnRegisterResult::GetAuthenticatorAttachment(
97 nsAString& aAuthenticatorAttachment) {
98 if (mAuthenticatorAttachment.isSome()) {
99 aAuthenticatorAttachment = mAuthenticatorAttachment.ref();
100 return NS_OK;
102 return NS_ERROR_NOT_AVAILABLE;
105 nsresult WebAuthnRegisterResult::Anonymize() {
106 // The anonymize flag in the nsIWebAuthnAttObj constructor causes the
107 // attestation statement to be removed during deserialization. It also
108 // causes the AAGUID to be zeroed out. If we can't deserialize the
109 // existing attestation, then we can't ensure that it is anonymized, so we
110 // act as though the user denied consent and we return NotAllowed.
111 nsCOMPtr<nsIWebAuthnAttObj> anonymizedAttObj;
112 nsresult rv = authrs_webauthn_att_obj_constructor(
113 mAttestationObject,
114 /* anonymize */ true, getter_AddRefs(anonymizedAttObj));
115 if (NS_FAILED(rv)) {
116 return rv;
118 mAttestationObject.Clear();
119 rv = anonymizedAttObj->GetAttestationObject(mAttestationObject);
120 if (NS_FAILED(rv)) {
121 return rv;
123 return NS_OK;
126 NS_IMPL_ISUPPORTS(WebAuthnSignResult, nsIWebAuthnSignResult)
128 NS_IMETHODIMP
129 WebAuthnSignResult::GetClientDataJSON(nsACString& aClientDataJSON) {
130 if (mClientDataJSON.isSome()) {
131 aClientDataJSON = *mClientDataJSON;
132 return NS_OK;
134 return NS_ERROR_NOT_AVAILABLE;
137 NS_IMETHODIMP
138 WebAuthnSignResult::GetAuthenticatorData(
139 nsTArray<uint8_t>& aAuthenticatorData) {
140 aAuthenticatorData.Assign(mAuthenticatorData);
141 return NS_OK;
144 NS_IMETHODIMP
145 WebAuthnSignResult::GetCredentialId(nsTArray<uint8_t>& aCredentialId) {
146 aCredentialId.Assign(mCredentialId);
147 return NS_OK;
150 NS_IMETHODIMP
151 WebAuthnSignResult::GetSignature(nsTArray<uint8_t>& aSignature) {
152 aSignature.Assign(mSignature);
153 return NS_OK;
156 NS_IMETHODIMP
157 WebAuthnSignResult::GetUserHandle(nsTArray<uint8_t>& aUserHandle) {
158 aUserHandle.Assign(mUserHandle);
159 return NS_OK;
162 NS_IMETHODIMP
163 WebAuthnSignResult::GetUserName(nsACString& aUserName) {
164 return NS_ERROR_NOT_AVAILABLE;
167 NS_IMETHODIMP
168 WebAuthnSignResult::GetUsedAppId(bool* aUsedAppId) {
169 if (mUsedAppId.isNothing()) {
170 return NS_ERROR_NOT_AVAILABLE;
172 *aUsedAppId = mUsedAppId.ref();
173 return NS_OK;
176 NS_IMETHODIMP
177 WebAuthnSignResult::SetUsedAppId(bool aUsedAppId) {
178 mUsedAppId = Some(aUsedAppId);
179 return NS_OK;
182 NS_IMETHODIMP
183 WebAuthnSignResult::GetAuthenticatorAttachment(
184 nsAString& aAuthenticatorAttachment) {
185 if (mAuthenticatorAttachment.isSome()) {
186 aAuthenticatorAttachment = mAuthenticatorAttachment.ref();
187 return NS_OK;
189 return NS_ERROR_NOT_AVAILABLE;
192 } // namespace mozilla::dom