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"
11 #ifdef MOZ_WIDGET_ANDROID
12 namespace mozilla::jni
{
15 RefPtr
<dom::WebAuthnRegisterResult
> Java2Native(
16 mozilla::jni::Object::Param aData
, JNIEnv
* aEnv
) {
18 aData
.IsInstanceOf
<java::WebAuthnTokenManager::MakeCredentialResponse
>());
19 java::WebAuthnTokenManager::MakeCredentialResponse::LocalRef
response(aData
);
20 RefPtr
<dom::WebAuthnRegisterResult
> result
=
21 new dom::WebAuthnRegisterResult(response
);
26 RefPtr
<dom::WebAuthnSignResult
> Java2Native(mozilla::jni::Object::Param aData
,
29 aData
.IsInstanceOf
<java::WebAuthnTokenManager::GetAssertionResponse
>());
30 java::WebAuthnTokenManager::GetAssertionResponse::LocalRef
response(aData
);
31 RefPtr
<dom::WebAuthnSignResult
> result
=
32 new dom::WebAuthnSignResult(response
);
36 } // namespace mozilla::jni
39 namespace mozilla::dom
{
41 NS_IMPL_ISUPPORTS(WebAuthnRegisterResult
, nsIWebAuthnRegisterResult
)
44 WebAuthnRegisterResult::GetClientDataJSON(nsACString
& aClientDataJSON
) {
45 if (mClientDataJSON
.isSome()) {
46 aClientDataJSON
= *mClientDataJSON
;
49 return NS_ERROR_NOT_AVAILABLE
;
53 WebAuthnRegisterResult::GetAttestationObject(
54 nsTArray
<uint8_t>& aAttestationObject
) {
55 aAttestationObject
.Assign(mAttestationObject
);
60 WebAuthnRegisterResult::GetCredentialId(nsTArray
<uint8_t>& aCredentialId
) {
61 aCredentialId
.Assign(mCredentialId
);
66 WebAuthnRegisterResult::GetTransports(nsTArray
<nsString
>& aTransports
) {
67 aTransports
.Assign(mTransports
);
72 WebAuthnRegisterResult::GetHmacCreateSecret(bool* aHmacCreateSecret
) {
73 if (mHmacCreateSecret
.isSome()) {
74 *aHmacCreateSecret
= mHmacCreateSecret
.ref();
77 return NS_ERROR_NOT_AVAILABLE
;
81 WebAuthnRegisterResult::GetCredPropsRk(bool* aCredPropsRk
) {
82 if (mCredPropsRk
.isSome()) {
83 *aCredPropsRk
= mCredPropsRk
.ref();
86 return NS_ERROR_NOT_AVAILABLE
;
90 WebAuthnRegisterResult::SetCredPropsRk(bool aCredPropsRk
) {
91 mCredPropsRk
= Some(aCredPropsRk
);
96 WebAuthnRegisterResult::GetAuthenticatorAttachment(
97 nsAString
& aAuthenticatorAttachment
) {
98 if (mAuthenticatorAttachment
.isSome()) {
99 aAuthenticatorAttachment
= mAuthenticatorAttachment
.ref();
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(
114 /* anonymize */ true, getter_AddRefs(anonymizedAttObj
));
118 mAttestationObject
.Clear();
119 rv
= anonymizedAttObj
->GetAttestationObject(mAttestationObject
);
126 NS_IMPL_ISUPPORTS(WebAuthnSignResult
, nsIWebAuthnSignResult
)
129 WebAuthnSignResult::GetClientDataJSON(nsACString
& aClientDataJSON
) {
130 if (mClientDataJSON
.isSome()) {
131 aClientDataJSON
= *mClientDataJSON
;
134 return NS_ERROR_NOT_AVAILABLE
;
138 WebAuthnSignResult::GetAuthenticatorData(
139 nsTArray
<uint8_t>& aAuthenticatorData
) {
140 aAuthenticatorData
.Assign(mAuthenticatorData
);
145 WebAuthnSignResult::GetCredentialId(nsTArray
<uint8_t>& aCredentialId
) {
146 aCredentialId
.Assign(mCredentialId
);
151 WebAuthnSignResult::GetSignature(nsTArray
<uint8_t>& aSignature
) {
152 aSignature
.Assign(mSignature
);
157 WebAuthnSignResult::GetUserHandle(nsTArray
<uint8_t>& aUserHandle
) {
158 aUserHandle
.Assign(mUserHandle
);
163 WebAuthnSignResult::GetUserName(nsACString
& aUserName
) {
164 return NS_ERROR_NOT_AVAILABLE
;
168 WebAuthnSignResult::GetUsedAppId(bool* aUsedAppId
) {
169 if (mUsedAppId
.isNothing()) {
170 return NS_ERROR_NOT_AVAILABLE
;
172 *aUsedAppId
= mUsedAppId
.ref();
177 WebAuthnSignResult::SetUsedAppId(bool aUsedAppId
) {
178 mUsedAppId
= Some(aUsedAppId
);
183 WebAuthnSignResult::GetAuthenticatorAttachment(
184 nsAString
& aAuthenticatorAttachment
) {
185 if (mAuthenticatorAttachment
.isSome()) {
186 aAuthenticatorAttachment
= mAuthenticatorAttachment
.ref();
189 return NS_ERROR_NOT_AVAILABLE
;
192 } // namespace mozilla::dom