diff --git a/dom/u2f/U2F.cpp b/dom/u2f/U2F.cpp index af6ca81c7831..9758b7cf5efb 100644 --- a/dom/u2f/U2F.cpp +++ b/dom/u2f/U2F.cpp @@ -462,7 +462,7 @@ U2F::Register(const nsAString& aAppId, void U2F::FinishMakeCredential(const uint64_t& aTransactionId, - nsTArray& aRegBuffer) + const WebAuthnMakeCredentialResult& aResult) { MOZ_ASSERT(NS_IsMainThread()); @@ -483,7 +483,7 @@ U2F::FinishMakeCredential(const uint64_t& aTransactionId, } CryptoBuffer regBuf; - if (NS_WARN_IF(!regBuf.Assign(aRegBuffer))) { + if (NS_WARN_IF(!regBuf.Assign(aResult.RegBuffer()))) { RejectTransaction(NS_ERROR_ABORT); return; } @@ -606,8 +606,7 @@ U2F::Sign(const nsAString& aAppId, void U2F::FinishGetAssertion(const uint64_t& aTransactionId, - nsTArray& aCredentialId, - nsTArray& aSigBuffer) + const WebAuthnGetAssertionResult& aResult) { MOZ_ASSERT(NS_IsMainThread()); @@ -628,13 +627,13 @@ U2F::FinishGetAssertion(const uint64_t& aTransactionId, } CryptoBuffer credBuf; - if (NS_WARN_IF(!credBuf.Assign(aCredentialId))) { + if (NS_WARN_IF(!credBuf.Assign(aResult.CredentialID()))) { RejectTransaction(NS_ERROR_ABORT); return; } CryptoBuffer sigBuf; - if (NS_WARN_IF(!sigBuf.Assign(aSigBuffer))) { + if (NS_WARN_IF(!sigBuf.Assign(aResult.SigBuffer()))) { RejectTransaction(NS_ERROR_ABORT); return; } diff --git a/dom/u2f/U2F.h b/dom/u2f/U2F.h index f554c9a24ff3..6999e4e93a78 100644 --- a/dom/u2f/U2F.h +++ b/dom/u2f/U2F.h @@ -13,6 +13,7 @@ #include "mozilla/dom/Nullable.h" #include "mozilla/dom/U2FBinding.h" #include "mozilla/dom/WebAuthnManagerBase.h" +#include "mozilla/dom/PWebAuthnTransaction.h" #include "mozilla/ErrorResult.h" #include "mozilla/MozPromise.h" #include "nsProxyRelease.h" @@ -122,12 +123,11 @@ public: void FinishMakeCredential(const uint64_t& aTransactionId, - nsTArray& aRegBuffer) override; + const WebAuthnMakeCredentialResult& aResult) override; void FinishGetAssertion(const uint64_t& aTransactionId, - nsTArray& aCredentialId, - nsTArray& aSigBuffer) override; + const WebAuthnGetAssertionResult& aResult) override; void RequestAborted(const uint64_t& aTransactionId, diff --git a/dom/webauthn/PWebAuthnTransaction.ipdl b/dom/webauthn/PWebAuthnTransaction.ipdl index d4d03f0746b0..e18336169749 100644 --- a/dom/webauthn/PWebAuthnTransaction.ipdl +++ b/dom/webauthn/PWebAuthnTransaction.ipdl @@ -43,6 +43,10 @@ struct WebAuthnMakeCredentialInfo { WebAuthnAuthenticatorSelection AuthenticatorSelection; }; +struct WebAuthnMakeCredentialResult { + uint8_t[] RegBuffer; +}; + struct WebAuthnGetAssertionInfo { uint8_t[] RpIdHash; uint8_t[] ClientDataHash; @@ -52,6 +56,11 @@ struct WebAuthnGetAssertionInfo { WebAuthnExtension[] Extensions; }; +struct WebAuthnGetAssertionResult { + uint8_t[] CredentialID; + uint8_t[] SigBuffer; +}; + async protocol PWebAuthnTransaction { manager PBackground; @@ -63,8 +72,8 @@ async protocol PWebAuthnTransaction { child: async __delete__(); - async ConfirmRegister(uint64_t aTransactionId, uint8_t[] RegBuffer); - async ConfirmSign(uint64_t aTransactionId, uint8_t[] CredentialID, uint8_t[] ReplyBuffer); + async ConfirmRegister(uint64_t aTransactionId, WebAuthnMakeCredentialResult aResult); + async ConfirmSign(uint64_t aTransactionId, WebAuthnGetAssertionResult aResult); async Abort(uint64_t aTransactionId, nsresult Error); }; diff --git a/dom/webauthn/U2FHIDTokenManager.cpp b/dom/webauthn/U2FHIDTokenManager.cpp index 26700f001dd0..f0b5febdf661 100644 --- a/dom/webauthn/U2FHIDTokenManager.cpp +++ b/dom/webauthn/U2FHIDTokenManager.cpp @@ -214,7 +214,7 @@ U2FHIDTokenManager::HandleRegisterResult(UniquePtr&& aResult) return; } - U2FRegisterResult result(Move(registration)); + WebAuthnMakeCredentialResult result(registration); mRegisterPromise.Resolve(Move(result), __func__); } @@ -241,7 +241,7 @@ U2FHIDTokenManager::HandleSignResult(UniquePtr&& aResult) return; } - U2FSignResult result(Move(keyHandle), Move(signature)); + WebAuthnGetAssertionResult result(keyHandle, signature); mSignPromise.Resolve(Move(result), __func__); } diff --git a/dom/webauthn/U2FSoftTokenManager.cpp b/dom/webauthn/U2FSoftTokenManager.cpp index dfc8e781973f..c9d0e2abaa4b 100644 --- a/dom/webauthn/U2FSoftTokenManager.cpp +++ b/dom/webauthn/U2FSoftTokenManager.cpp @@ -689,7 +689,7 @@ U2FSoftTokenManager::Register(const nsTArray& aCredent registrationBuf.AppendSECItem(attestCert.get()->derCert); registrationBuf.AppendSECItem(signatureItem); - U2FRegisterResult result((nsTArray(registrationBuf))); + WebAuthnMakeCredentialResult result((nsTArray(registrationBuf))); return U2FRegisterPromise::CreateAndResolve(Move(result), __func__); } @@ -832,7 +832,7 @@ U2FSoftTokenManager::Sign(const nsTArray& aCredentials signatureBuf.AppendSECItem(counterItem); signatureBuf.AppendSECItem(signatureItem); - U2FSignResult result(Move(keyHandle), nsTArray(signatureBuf)); + WebAuthnGetAssertionResult result(keyHandle, nsTArray(signatureBuf)); return U2FSignPromise::CreateAndResolve(Move(result), __func__); } diff --git a/dom/webauthn/U2FTokenManager.cpp b/dom/webauthn/U2FTokenManager.cpp index 8bc858469555..c33f98167ef7 100644 --- a/dom/webauthn/U2FTokenManager.cpp +++ b/dom/webauthn/U2FTokenManager.cpp @@ -251,7 +251,7 @@ U2FTokenManager::Register(PWebAuthnTransactionParent* aTransactionParent, aTransactionInfo.ClientDataHash(), aTransactionInfo.TimeoutMS()) ->Then(GetCurrentThreadSerialEventTarget(), __func__, - [tid, startTime](U2FRegisterResult&& aResult) { + [tid, startTime](WebAuthnMakeCredentialResult&& aResult) { U2FTokenManager* mgr = U2FTokenManager::Get(); mgr->MaybeConfirmRegister(tid, aResult); Telemetry::ScalarAdd( @@ -274,15 +274,12 @@ U2FTokenManager::Register(PWebAuthnTransactionParent* aTransactionParent, void U2FTokenManager::MaybeConfirmRegister(const uint64_t& aTransactionId, - U2FRegisterResult& aResult) + const WebAuthnMakeCredentialResult& aResult) { MOZ_ASSERT(mLastTransactionId == aTransactionId); mRegisterPromise.Complete(); - nsTArray registration; - aResult.ConsumeRegistration(registration); - - Unused << mTransactionParent->SendConfirmRegister(aTransactionId, registration); + Unused << mTransactionParent->SendConfirmRegister(aTransactionId, aResult); ClearTransaction(); } @@ -325,7 +322,7 @@ U2FTokenManager::Sign(PWebAuthnTransactionParent* aTransactionParent, aTransactionInfo.RequireUserVerification(), aTransactionInfo.TimeoutMS()) ->Then(GetCurrentThreadSerialEventTarget(), __func__, - [tid, startTime](U2FSignResult&& aResult) { + [tid, startTime](WebAuthnGetAssertionResult&& aResult) { U2FTokenManager* mgr = U2FTokenManager::Get(); mgr->MaybeConfirmSign(tid, aResult); Telemetry::ScalarAdd( @@ -348,17 +345,12 @@ U2FTokenManager::Sign(PWebAuthnTransactionParent* aTransactionParent, void U2FTokenManager::MaybeConfirmSign(const uint64_t& aTransactionId, - U2FSignResult& aResult) + const WebAuthnGetAssertionResult& aResult) { MOZ_ASSERT(mLastTransactionId == aTransactionId); mSignPromise.Complete(); - nsTArray keyHandle; - aResult.ConsumeKeyHandle(keyHandle); - nsTArray signature; - aResult.ConsumeSignature(signature); - - Unused << mTransactionParent->SendConfirmSign(aTransactionId, keyHandle, signature); + Unused << mTransactionParent->SendConfirmSign(aTransactionId, aResult); ClearTransaction(); } diff --git a/dom/webauthn/U2FTokenManager.h b/dom/webauthn/U2FTokenManager.h index 715041b78382..7eea0f9d67ab 100644 --- a/dom/webauthn/U2FTokenManager.h +++ b/dom/webauthn/U2FTokenManager.h @@ -8,6 +8,7 @@ #define mozilla_dom_U2FTokenManager_h #include "mozilla/dom/U2FTokenTransport.h" +#include "mozilla/dom/PWebAuthnTransaction.h" /* * Parent process manager for U2F and WebAuthn API transactions. Handles process @@ -46,9 +47,11 @@ private: RefPtr GetTokenManagerImpl(); void AbortTransaction(const uint64_t& aTransactionId, const nsresult& aError); void ClearTransaction(); - void MaybeConfirmRegister(const uint64_t& aTransactionId, U2FRegisterResult& aResult); + void MaybeConfirmRegister(const uint64_t& aTransactionId, + const WebAuthnMakeCredentialResult& aResult); void MaybeAbortRegister(const uint64_t& aTransactionId, const nsresult& aError); - void MaybeConfirmSign(const uint64_t& aTransactionId, U2FSignResult& aResult); + void MaybeConfirmSign(const uint64_t& aTransactionId, + const WebAuthnGetAssertionResult& aResult); void MaybeAbortSign(const uint64_t& aTransactionId, const nsresult& aError); // Using a raw pointer here, as the lifetime of the IPC object is managed by // the PBackground protocol code. This means we cannot be left holding an diff --git a/dom/webauthn/U2FTokenTransport.h b/dom/webauthn/U2FTokenTransport.h index 2f7fbbd8428e..d9f63e01499f 100644 --- a/dom/webauthn/U2FTokenTransport.h +++ b/dom/webauthn/U2FTokenTransport.h @@ -18,43 +18,8 @@ namespace mozilla { namespace dom { -class U2FRegisterResult { -public: - explicit U2FRegisterResult(nsTArray&& aRegistration) - : mRegistration(aRegistration) - { } - - void ConsumeRegistration(nsTArray& aBuffer) { - aBuffer = Move(mRegistration); - } - -private: - nsTArray mRegistration; -}; - -class U2FSignResult { -public: - explicit U2FSignResult(nsTArray&& aKeyHandle, - nsTArray&& aSignature) - : mKeyHandle(aKeyHandle) - , mSignature(aSignature) - { } - - void ConsumeKeyHandle(nsTArray& aBuffer) { - aBuffer = Move(mKeyHandle); - } - - void ConsumeSignature(nsTArray& aBuffer) { - aBuffer = Move(mSignature); - } - -private: - nsTArray mKeyHandle; - nsTArray mSignature; -}; - -typedef MozPromise U2FRegisterPromise; -typedef MozPromise U2FSignPromise; +typedef MozPromise U2FRegisterPromise; +typedef MozPromise U2FSignPromise; class U2FTokenTransport { diff --git a/dom/webauthn/WebAuthnManager.cpp b/dom/webauthn/WebAuthnManager.cpp index 8d314d5c23d3..6e601b672c30 100644 --- a/dom/webauthn/WebAuthnManager.cpp +++ b/dom/webauthn/WebAuthnManager.cpp @@ -650,7 +650,7 @@ WebAuthnManager::Store(const Credential& aCredential) void WebAuthnManager::FinishMakeCredential(const uint64_t& aTransactionId, - nsTArray& aRegBuffer) + const WebAuthnMakeCredentialResult& aResult) { MOZ_ASSERT(NS_IsMainThread()); @@ -660,7 +660,8 @@ WebAuthnManager::FinishMakeCredential(const uint64_t& aTransactionId, } CryptoBuffer regData; - if (NS_WARN_IF(!regData.Assign(aRegBuffer.Elements(), aRegBuffer.Length()))) { + if (NS_WARN_IF(!regData.Assign(aResult.RegBuffer().Elements(), + aResult.RegBuffer().Length()))) { RejectTransaction(NS_ERROR_OUT_OF_MEMORY); return; } @@ -783,8 +784,7 @@ WebAuthnManager::FinishMakeCredential(const uint64_t& aTransactionId, void WebAuthnManager::FinishGetAssertion(const uint64_t& aTransactionId, - nsTArray& aCredentialId, - nsTArray& aSigBuffer) + const WebAuthnGetAssertionResult& aResult) { MOZ_ASSERT(NS_IsMainThread()); @@ -794,8 +794,8 @@ WebAuthnManager::FinishGetAssertion(const uint64_t& aTransactionId, } CryptoBuffer tokenSignatureData; - if (NS_WARN_IF(!tokenSignatureData.Assign(aSigBuffer.Elements(), - aSigBuffer.Length()))) { + if (NS_WARN_IF(!tokenSignatureData.Assign(aResult.SigBuffer().Elements(), + aResult.SigBuffer().Length()))) { RejectTransaction(NS_ERROR_OUT_OF_MEMORY); return; } @@ -833,7 +833,7 @@ WebAuthnManager::FinishGetAssertion(const uint64_t& aTransactionId, } CryptoBuffer credentialBuf; - if (!credentialBuf.Assign(aCredentialId)) { + if (!credentialBuf.Assign(aResult.CredentialID())) { RejectTransaction(NS_ERROR_OUT_OF_MEMORY); return; } diff --git a/dom/webauthn/WebAuthnManager.h b/dom/webauthn/WebAuthnManager.h index f15906239891..23bf7b76e21a 100644 --- a/dom/webauthn/WebAuthnManager.h +++ b/dom/webauthn/WebAuthnManager.h @@ -123,12 +123,11 @@ public: void FinishMakeCredential(const uint64_t& aTransactionId, - nsTArray& aRegBuffer) override; + const WebAuthnMakeCredentialResult& aResult) override; void FinishGetAssertion(const uint64_t& aTransactionId, - nsTArray& aCredentialId, - nsTArray& aSigBuffer) override; + const WebAuthnGetAssertionResult& aResult) override; void RequestAborted(const uint64_t& aTransactionId, diff --git a/dom/webauthn/WebAuthnManagerBase.h b/dom/webauthn/WebAuthnManagerBase.h index 1c65fa851e02..c6855bc13182 100644 --- a/dom/webauthn/WebAuthnManagerBase.h +++ b/dom/webauthn/WebAuthnManagerBase.h @@ -7,6 +7,7 @@ #ifndef mozilla_dom_WebAuthnManagerBase_h #define mozilla_dom_WebAuthnManagerBase_h +#include "mozilla/dom/PWebAuthnTransaction.h" #include "nsIDOMEventListener.h" /* @@ -28,12 +29,11 @@ public: virtual void FinishMakeCredential(const uint64_t& aTransactionId, - nsTArray& aRegBuffer) = 0; + const WebAuthnMakeCredentialResult& aResult) = 0; virtual void FinishGetAssertion(const uint64_t& aTransactionId, - nsTArray& aCredentialId, - nsTArray& aSigBuffer) = 0; + const WebAuthnGetAssertionResult& aResult) = 0; virtual void RequestAborted(const uint64_t& aTransactionId, diff --git a/dom/webauthn/WebAuthnTransactionChild.cpp b/dom/webauthn/WebAuthnTransactionChild.cpp index 6ac7683d86c6..3f1f6d889df3 100644 --- a/dom/webauthn/WebAuthnTransactionChild.cpp +++ b/dom/webauthn/WebAuthnTransactionChild.cpp @@ -22,26 +22,25 @@ WebAuthnTransactionChild::WebAuthnTransactionChild(WebAuthnManagerBase* aManager mozilla::ipc::IPCResult WebAuthnTransactionChild::RecvConfirmRegister(const uint64_t& aTransactionId, - nsTArray&& aRegBuffer) + const WebAuthnMakeCredentialResult& aResult) { if (NS_WARN_IF(!mManager)) { return IPC_FAIL_NO_REASON(this); } - mManager->FinishMakeCredential(aTransactionId, aRegBuffer); + mManager->FinishMakeCredential(aTransactionId, aResult); return IPC_OK(); } mozilla::ipc::IPCResult WebAuthnTransactionChild::RecvConfirmSign(const uint64_t& aTransactionId, - nsTArray&& aCredentialId, - nsTArray&& aBuffer) + const WebAuthnGetAssertionResult& aResult) { if (NS_WARN_IF(!mManager)) { return IPC_FAIL_NO_REASON(this); } - mManager->FinishGetAssertion(aTransactionId, aCredentialId, aBuffer); + mManager->FinishGetAssertion(aTransactionId, aResult); return IPC_OK(); } diff --git a/dom/webauthn/WebAuthnTransactionChild.h b/dom/webauthn/WebAuthnTransactionChild.h index d8641f807f4d..c5231a77ed94 100644 --- a/dom/webauthn/WebAuthnTransactionChild.h +++ b/dom/webauthn/WebAuthnTransactionChild.h @@ -28,12 +28,11 @@ public: mozilla::ipc::IPCResult RecvConfirmRegister(const uint64_t& aTransactionId, - nsTArray&& aRegBuffer) override; + const WebAuthnMakeCredentialResult& aResult) override; mozilla::ipc::IPCResult RecvConfirmSign(const uint64_t& aTransactionId, - nsTArray&& aCredentialId, - nsTArray&& aBuffer) override; + const WebAuthnGetAssertionResult& aResult) override; mozilla::ipc::IPCResult RecvAbort(const uint64_t& aTransactionId, const nsresult& aError) override;