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
;
106 WebAuthnRegisterResult::HasIdentifyingAttestation(
107 bool* aHasIdentifyingAttestation
) {
108 // Assume the attestation statement is identifying in case the constructor or
109 // the getter below fail.
110 bool isIdentifying
= true;
112 nsCOMPtr
<nsIWebAuthnAttObj
> attObj
;
113 nsresult rv
= authrs_webauthn_att_obj_constructor(mAttestationObject
,
114 /* anonymize */ false,
115 getter_AddRefs(attObj
));
116 if (NS_SUCCEEDED(rv
)) {
117 Unused
<< attObj
->IsIdentifying(&isIdentifying
);
120 *aHasIdentifyingAttestation
= isIdentifying
;
125 WebAuthnRegisterResult::Anonymize() {
126 // The anonymize flag in the nsIWebAuthnAttObj constructor causes the
127 // attestation statement to be removed during deserialization. It also
128 // causes the AAGUID to be zeroed out. If we can't deserialize the
129 // existing attestation, then we can't ensure that it is anonymized, so we
130 // act as though the user denied consent and we return NotAllowed.
131 nsCOMPtr
<nsIWebAuthnAttObj
> anonymizedAttObj
;
132 nsresult rv
= authrs_webauthn_att_obj_constructor(
134 /* anonymize */ true, getter_AddRefs(anonymizedAttObj
));
138 mAttestationObject
.Clear();
139 rv
= anonymizedAttObj
->GetAttestationObject(mAttestationObject
);
146 NS_IMPL_ISUPPORTS(WebAuthnSignResult
, nsIWebAuthnSignResult
)
149 WebAuthnSignResult::GetClientDataJSON(nsACString
& aClientDataJSON
) {
150 if (mClientDataJSON
.isSome()) {
151 aClientDataJSON
= *mClientDataJSON
;
154 return NS_ERROR_NOT_AVAILABLE
;
158 WebAuthnSignResult::GetAuthenticatorData(
159 nsTArray
<uint8_t>& aAuthenticatorData
) {
160 aAuthenticatorData
.Assign(mAuthenticatorData
);
165 WebAuthnSignResult::GetCredentialId(nsTArray
<uint8_t>& aCredentialId
) {
166 aCredentialId
.Assign(mCredentialId
);
171 WebAuthnSignResult::GetSignature(nsTArray
<uint8_t>& aSignature
) {
172 aSignature
.Assign(mSignature
);
177 WebAuthnSignResult::GetUserHandle(nsTArray
<uint8_t>& aUserHandle
) {
178 aUserHandle
.Assign(mUserHandle
);
183 WebAuthnSignResult::GetUserName(nsACString
& aUserName
) {
184 return NS_ERROR_NOT_AVAILABLE
;
188 WebAuthnSignResult::GetUsedAppId(bool* aUsedAppId
) {
189 if (mUsedAppId
.isNothing()) {
190 return NS_ERROR_NOT_AVAILABLE
;
192 *aUsedAppId
= mUsedAppId
.ref();
197 WebAuthnSignResult::SetUsedAppId(bool aUsedAppId
) {
198 mUsedAppId
= Some(aUsedAppId
);
203 WebAuthnSignResult::GetAuthenticatorAttachment(
204 nsAString
& aAuthenticatorAttachment
) {
205 if (mAuthenticatorAttachment
.isSome()) {
206 aAuthenticatorAttachment
= mAuthenticatorAttachment
.ref();
209 return NS_ERROR_NOT_AVAILABLE
;
212 } // namespace mozilla::dom