Skip to content

Commit a3256fc

Browse files
author
Tim Taubert
committed
Bug 1421616 - Have one WebAuthnManager instance per CredentialsContainer r=jcj
Summary: We currently have a single WebAuthnManager instance per process that's shared between all CredentialContainers. That way the nsPIDOMWindowInner parent has to be tracked by the transaction, as multiple containers could kick off requests simultaneously. This patch lets us we have one WebAuthnManager instance per each CredentialsContainer and thus each nsPIDOMWindowInner. This matches the current U2F implementation where there is one instance per parent window too. This somewhat simplifies the communication diagram (at least in my head), as each U2F/WebAuthnManager instance also has their own TransactionChild/Parent pair for IPC protocol communication. The manager and child/parent pair are destroyed when the window is. Reviewers: jcj Reviewed By: jcj Bug #: 1421616 Differential Revision: https://phabricator.services.mozilla.com/D305
1 parent a617954 commit a3256fc

21 files changed

+248
-396
lines changed

dom/credentialmanagement/CredentialsContainer.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
namespace mozilla {
1212
namespace dom {
1313

14-
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CredentialsContainer, mParent)
14+
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CredentialsContainer, mParent, mManager)
1515
NS_IMPL_CYCLE_COLLECTING_ADDREF(CredentialsContainer)
1616
NS_IMPL_CYCLE_COLLECTING_RELEASE(CredentialsContainer)
1717
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CredentialsContainer)
@@ -28,6 +28,16 @@ CredentialsContainer::CredentialsContainer(nsPIDOMWindowInner* aParent) :
2828
CredentialsContainer::~CredentialsContainer()
2929
{}
3030

31+
void
32+
CredentialsContainer::EnsureWebAuthnManager()
33+
{
34+
MOZ_ASSERT(NS_IsMainThread());
35+
36+
if (!mManager) {
37+
mManager = new WebAuthnManager(mParent);
38+
}
39+
}
40+
3141
JSObject*
3242
CredentialsContainer::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
3343
{
@@ -37,22 +47,22 @@ CredentialsContainer::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenPro
3747
already_AddRefed<Promise>
3848
CredentialsContainer::Get(const CredentialRequestOptions& aOptions)
3949
{
40-
RefPtr<WebAuthnManager> mgr = WebAuthnManager::GetOrCreate();
41-
return mgr->GetAssertion(mParent, aOptions.mPublicKey, aOptions.mSignal);
50+
EnsureWebAuthnManager();
51+
return mManager->GetAssertion(aOptions.mPublicKey, aOptions.mSignal);
4252
}
4353

4454
already_AddRefed<Promise>
4555
CredentialsContainer::Create(const CredentialCreationOptions& aOptions)
4656
{
47-
RefPtr<WebAuthnManager> mgr = WebAuthnManager::GetOrCreate();
48-
return mgr->MakeCredential(mParent, aOptions.mPublicKey, aOptions.mSignal);
57+
EnsureWebAuthnManager();
58+
return mManager->MakeCredential(aOptions.mPublicKey, aOptions.mSignal);
4959
}
5060

5161
already_AddRefed<Promise>
5262
CredentialsContainer::Store(const Credential& aCredential)
5363
{
54-
RefPtr<WebAuthnManager> mgr = WebAuthnManager::GetOrCreate();
55-
return mgr->Store(mParent, aCredential);
64+
EnsureWebAuthnManager();
65+
return mManager->Store(aCredential);
5666
}
5767

5868
} // namespace dom

dom/credentialmanagement/CredentialsContainer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace mozilla {
1313
namespace dom {
1414

15+
class WebAuthnManager;
16+
1517
class CredentialsContainer final : public nsISupports
1618
, public nsWrapperCache
1719
{
@@ -32,15 +34,20 @@ class CredentialsContainer final : public nsISupports
3234

3335
already_AddRefed<Promise>
3436
Get(const CredentialRequestOptions& aOptions);
37+
3538
already_AddRefed<Promise>
3639
Create(const CredentialCreationOptions& aOptions);
40+
3741
already_AddRefed<Promise>
3842
Store(const Credential& aCredential);
3943

4044
private:
4145
~CredentialsContainer();
4246

47+
void EnsureWebAuthnManager();
48+
4349
nsCOMPtr<nsPIDOMWindowInner> mParent;
50+
RefPtr<WebAuthnManager> mManager;
4451
};
4552

4653
} // namespace dom

dom/u2f/U2F.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
#include "mozilla/dom/WebCryptoCommon.h"
1010
#include "mozilla/ipc/PBackgroundChild.h"
1111
#include "mozilla/ipc/BackgroundChild.h"
12+
#include "mozilla/dom/WebAuthnTransactionChild.h"
1213
#include "nsContentUtils.h"
1314
#include "nsICryptoHash.h"
1415
#include "nsIEffectiveTLDService.h"
1516
#include "nsNetCID.h"
1617
#include "nsNetUtil.h"
1718
#include "nsURLParsers.h"
18-
#include "U2FTransactionChild.h"
1919
#include "U2FUtil.h"
2020
#include "hasht.h"
2121

@@ -293,9 +293,9 @@ U2F::~U2F()
293293
}
294294

295295
if (mChild) {
296-
RefPtr<U2FTransactionChild> c;
296+
RefPtr<WebAuthnTransactionChild> c;
297297
mChild.swap(c);
298-
c->Send__delete__(c);
298+
c->Disconnect();
299299
}
300300

301301
mRegisterCallback.reset();
@@ -437,8 +437,8 @@ U2F::Register(const nsAString& aAppId,
437437
}
438438

439439
void
440-
U2F::FinishRegister(const uint64_t& aTransactionId,
441-
nsTArray<uint8_t>& aRegBuffer)
440+
U2F::FinishMakeCredential(const uint64_t& aTransactionId,
441+
nsTArray<uint8_t>& aRegBuffer)
442442
{
443443
MOZ_ASSERT(NS_IsMainThread());
444444

@@ -566,9 +566,9 @@ U2F::Sign(const nsAString& aAppId,
566566
}
567567

568568
void
569-
U2F::FinishSign(const uint64_t& aTransactionId,
570-
nsTArray<uint8_t>& aCredentialId,
571-
nsTArray<uint8_t>& aSigBuffer)
569+
U2F::FinishGetAssertion(const uint64_t& aTransactionId,
570+
nsTArray<uint8_t>& aCredentialId,
571+
nsTArray<uint8_t>& aSigBuffer)
572572
{
573573
MOZ_ASSERT(NS_IsMainThread());
574574

@@ -749,7 +749,7 @@ U2F::MaybeCreateBackgroundActor()
749749
return false;
750750
}
751751

752-
RefPtr<U2FTransactionChild> mgr(new U2FTransactionChild(this));
752+
RefPtr<WebAuthnTransactionChild> mgr(new WebAuthnTransactionChild(this));
753753
PWebAuthnTransactionChild* constructedMgr =
754754
actorChild->SendPWebAuthnTransactionConstructor(mgr);
755755

dom/u2f/U2F.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "mozilla/dom/BindingDeclarations.h"
1313
#include "mozilla/dom/Nullable.h"
1414
#include "mozilla/dom/U2FBinding.h"
15+
#include "mozilla/dom/WebAuthnManagerBase.h"
1516
#include "mozilla/ErrorResult.h"
1617
#include "mozilla/MozPromise.h"
1718
#include "nsProxyRelease.h"
@@ -24,7 +25,7 @@ class nsISerialEventTarget;
2425
namespace mozilla {
2526
namespace dom {
2627

27-
class U2FTransactionChild;
28+
class WebAuthnTransactionChild;
2829
class U2FRegisterCallback;
2930
class U2FSignCallback;
3031

@@ -59,6 +60,7 @@ class U2FTransaction
5960
};
6061

6162
class U2F final : public nsIDOMEventListener
63+
, public WebAuthnManagerBase
6264
, public nsWrapperCache
6365
{
6466
public:
@@ -97,18 +99,22 @@ class U2F final : public nsIDOMEventListener
9799
const Optional<Nullable<int32_t>>& opt_aTimeoutSeconds,
98100
ErrorResult& aRv);
99101

102+
// WebAuthnManagerBase
103+
100104
void
101-
FinishRegister(const uint64_t& aTransactionId, nsTArray<uint8_t>& aRegBuffer);
105+
FinishMakeCredential(const uint64_t& aTransactionId,
106+
nsTArray<uint8_t>& aRegBuffer) override;
102107

103108
void
104-
FinishSign(const uint64_t& aTransactionId,
105-
nsTArray<uint8_t>& aCredentialId,
106-
nsTArray<uint8_t>& aSigBuffer);
109+
FinishGetAssertion(const uint64_t& aTransactionId,
110+
nsTArray<uint8_t>& aCredentialId,
111+
nsTArray<uint8_t>& aSigBuffer) override;
107112

108113
void
109-
RequestAborted(const uint64_t& aTransactionId, const nsresult& aError);
114+
RequestAborted(const uint64_t& aTransactionId,
115+
const nsresult& aError) override;
110116

111-
void ActorDestroyed();
117+
void ActorDestroyed() override;
112118

113119
private:
114120
~U2F();
@@ -135,7 +141,7 @@ class U2F final : public nsIDOMEventListener
135141
Maybe<nsMainThreadPtrHandle<U2FSignCallback>> mSignCallback;
136142

137143
// IPC Channel to the parent process.
138-
RefPtr<U2FTransactionChild> mChild;
144+
RefPtr<WebAuthnTransactionChild> mChild;
139145

140146
// The current transaction, if any.
141147
Maybe<U2FTransaction> mTransaction;

dom/u2f/U2FTransactionChild.cpp

Lines changed: 0 additions & 44 deletions
This file was deleted.

dom/u2f/U2FTransactionChild.h

Lines changed: 0 additions & 50 deletions
This file was deleted.

dom/u2f/U2FTransactionParent.cpp

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)