Skip to content

Commit

Permalink
Bug 1849056 - handle failures of CryptoBuffer::ToArrayBuffer. r=tschu…
Browse files Browse the repository at this point in the history
…ster,webidl,smaug

Differential Revision: https://phabricator.services.mozilla.com/D186398
  • Loading branch information
jschanck committed Aug 17, 2023
1 parent 7c4acfb commit fc0dea8
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 27 deletions.
26 changes: 19 additions & 7 deletions dom/webauthn/AuthenticatorAssertionResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ JSObject* AuthenticatorAssertionResponse::WrapObject(
}

void AuthenticatorAssertionResponse::GetAuthenticatorData(
JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal) {
JSContext* aCx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv) {
if (!mAuthenticatorDataCachedObj) {
mAuthenticatorDataCachedObj = mAuthenticatorData.ToArrayBuffer(aCx);
if (!mAuthenticatorDataCachedObj) {
aRv.NoteJSContextException(aCx);
return;
}
}
aRetVal.set(mAuthenticatorDataCachedObj);
aValue.set(mAuthenticatorDataCachedObj);
}

nsresult AuthenticatorAssertionResponse::SetAuthenticatorData(
Expand All @@ -71,11 +75,15 @@ nsresult AuthenticatorAssertionResponse::SetAuthenticatorData(
}

void AuthenticatorAssertionResponse::GetSignature(
JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal) {
JSContext* aCx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv) {
if (!mSignatureCachedObj) {
mSignatureCachedObj = mSignature.ToArrayBuffer(aCx);
if (!mSignatureCachedObj) {
aRv.NoteJSContextException(aCx);
return;
}
}
aRetVal.set(mSignatureCachedObj);
aValue.set(mSignatureCachedObj);
}

nsresult AuthenticatorAssertionResponse::SetSignature(CryptoBuffer& aBuffer) {
Expand All @@ -86,17 +94,21 @@ nsresult AuthenticatorAssertionResponse::SetSignature(CryptoBuffer& aBuffer) {
}

void AuthenticatorAssertionResponse::GetUserHandle(
JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal) {
JSContext* aCx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv) {
// Per
// https://w3c.github.io/webauthn/#ref-for-dom-authenticatorassertionresponse-userhandle%E2%91%A0
// this should return null if the handle is unset.
if (mUserHandle.IsEmpty()) {
aRetVal.set(nullptr);
aValue.set(nullptr);
} else {
if (!mUserHandleCachedObj) {
mUserHandleCachedObj = mUserHandle.ToArrayBuffer(aCx);
if (!mUserHandleCachedObj) {
aRv.NoteJSContextException(aCx);
return;
}
}
aRetVal.set(mUserHandleCachedObj);
aValue.set(mUserHandleCachedObj);
}
}

Expand Down
10 changes: 6 additions & 4 deletions dom/webauthn/AuthenticatorAssertionResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ class AuthenticatorAssertionResponse final : public AuthenticatorResponse {
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;

void GetAuthenticatorData(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetVal);
void GetAuthenticatorData(JSContext* aCx, JS::MutableHandle<JSObject*> aValue,
ErrorResult& aRv);

nsresult SetAuthenticatorData(CryptoBuffer& aBuffer);

void GetSignature(JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal);
void GetSignature(JSContext* aCx, JS::MutableHandle<JSObject*> aValue,
ErrorResult& aRv);

nsresult SetSignature(CryptoBuffer& aBuffer);

void GetUserHandle(JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal);
void GetUserHandle(JSContext* aCx, JS::MutableHandle<JSObject*> aValue,
ErrorResult& aRv);

nsresult SetUserHandle(CryptoBuffer& aUserHandle);

Expand Down
8 changes: 6 additions & 2 deletions dom/webauthn/AuthenticatorAttestationResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ JSObject* AuthenticatorAttestationResponse::WrapObject(
}

void AuthenticatorAttestationResponse::GetAttestationObject(
JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal) {
JSContext* aCx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv) {
if (!mAttestationObjectCachedObj) {
mAttestationObjectCachedObj = mAttestationObject.ToArrayBuffer(aCx);
if (!mAttestationObjectCachedObj) {
aRv.NoteJSContextException(aCx);
return;
}
}
aRetVal.set(mAttestationObjectCachedObj);
aValue.set(mAttestationObjectCachedObj);
}

nsresult AuthenticatorAttestationResponse::SetAttestationObject(
Expand Down
4 changes: 2 additions & 2 deletions dom/webauthn/AuthenticatorAttestationResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class AuthenticatorAttestationResponse final : public AuthenticatorResponse {
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;

void GetAttestationObject(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetVal);
void GetAttestationObject(JSContext* aCx, JS::MutableHandle<JSObject*> aValue,
ErrorResult& aRv);

nsresult SetAttestationObject(CryptoBuffer& aBuffer);

Expand Down
8 changes: 6 additions & 2 deletions dom/webauthn/AuthenticatorResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ AuthenticatorResponse::~AuthenticatorResponse() {
nsISupports* AuthenticatorResponse::GetParentObject() const { return mParent; }

void AuthenticatorResponse::GetClientDataJSON(
JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal) {
JSContext* aCx, JS::MutableHandle<JSObject*> aValue, ErrorResult& aRv) {
if (!mClientDataJSONCachedObj) {
mClientDataJSONCachedObj = mClientDataJSON.ToArrayBuffer(aCx);
if (!mClientDataJSONCachedObj) {
aRv.NoteJSContextException(aCx);
return;
}
}
aRetVal.set(mClientDataJSONCachedObj);
aValue.set(mClientDataJSONCachedObj);
}

nsresult AuthenticatorResponse::SetClientDataJSON(CryptoBuffer& aBuffer) {
Expand Down
4 changes: 3 additions & 1 deletion dom/webauthn/AuthenticatorResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "js/TypeDecls.h"
#include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/CryptoBuffer.h"
#include "nsCycleCollectionParticipant.h"
Expand All @@ -33,7 +34,8 @@ class AuthenticatorResponse : public nsISupports, public nsWrapperCache {

void GetFormat(nsString& aRetVal) const;

void GetClientDataJSON(JSContext* aCx, JS::MutableHandle<JSObject*> aRetVal);
void GetClientDataJSON(JSContext* aCx, JS::MutableHandle<JSObject*> aValue,
ErrorResult& aRv);

nsresult SetClientDataJSON(CryptoBuffer& aBuffer);

Expand Down
9 changes: 7 additions & 2 deletions dom/webauthn/PublicKeyCredential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,16 @@ JSObject* PublicKeyCredential::WrapObject(JSContext* aCx,
}

void PublicKeyCredential::GetRawId(JSContext* aCx,
JS::MutableHandle<JSObject*> aRetVal) {
JS::MutableHandle<JSObject*> aValue,
ErrorResult& aRv) {
if (!mRawIdCachedObj) {
mRawIdCachedObj = mRawId.ToArrayBuffer(aCx);
if (!mRawIdCachedObj) {
aRv.NoteJSContextException(aCx);
return;
}
}
aRetVal.set(mRawIdCachedObj);
aValue.set(mRawIdCachedObj);
}

already_AddRefed<AuthenticatorResponse> PublicKeyCredential::Response() const {
Expand Down
3 changes: 2 additions & 1 deletion dom/webauthn/PublicKeyCredential.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class PublicKeyCredential final : public Credential {
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;

void GetRawId(JSContext* cx, JS::MutableHandle<JSObject*> aRetVal);
void GetRawId(JSContext* aCx, JS::MutableHandle<JSObject*> aValue,
ErrorResult& aRv);

already_AddRefed<AuthenticatorResponse> Response() const;

Expand Down
12 changes: 6 additions & 6 deletions dom/webidl/WebAuthentication.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[SecureContext, Pref="security.webauth.webauthn",
Exposed=Window]
interface PublicKeyCredential : Credential {
[SameObject] readonly attribute ArrayBuffer rawId;
[SameObject, Throws] readonly attribute ArrayBuffer rawId;
[SameObject] readonly attribute AuthenticatorResponse response;
AuthenticationExtensionsClientOutputs getClientExtensionResults();
};
Expand All @@ -27,21 +27,21 @@ partial interface PublicKeyCredential {
[SecureContext, Pref="security.webauth.webauthn",
Exposed=Window]
interface AuthenticatorResponse {
[SameObject] readonly attribute ArrayBuffer clientDataJSON;
[SameObject, Throws] readonly attribute ArrayBuffer clientDataJSON;
};

[SecureContext, Pref="security.webauth.webauthn",
Exposed=Window]
interface AuthenticatorAttestationResponse : AuthenticatorResponse {
[SameObject] readonly attribute ArrayBuffer attestationObject;
[SameObject, Throws] readonly attribute ArrayBuffer attestationObject;
};

[SecureContext, Pref="security.webauth.webauthn",
Exposed=Window]
interface AuthenticatorAssertionResponse : AuthenticatorResponse {
[SameObject] readonly attribute ArrayBuffer authenticatorData;
[SameObject] readonly attribute ArrayBuffer signature;
[SameObject] readonly attribute ArrayBuffer? userHandle;
[SameObject, Throws] readonly attribute ArrayBuffer authenticatorData;
[SameObject, Throws] readonly attribute ArrayBuffer signature;
[SameObject, Throws] readonly attribute ArrayBuffer? userHandle;
};

dictionary PublicKeyCredentialParameters {
Expand Down

0 comments on commit fc0dea8

Please sign in to comment.