Skip to content

Commit a0935f0

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 f1c4d1f commit a0935f0

21 files changed

+247
-397
lines changed

dom/credentialmanagement/CredentialsContainer.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66

77
#include "mozilla/dom/CredentialsContainer.h"
88
#include "mozilla/dom/Promise.h"
9-
#include "mozilla/dom/WebAuthnManager.h"
109

1110
namespace mozilla {
1211
namespace dom {
1312

14-
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CredentialsContainer, mParent)
13+
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(CredentialsContainer, mParent, mManager)
1514
NS_IMPL_CYCLE_COLLECTING_ADDREF(CredentialsContainer)
1615
NS_IMPL_CYCLE_COLLECTING_RELEASE(CredentialsContainer)
1716
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CredentialsContainer)
@@ -28,6 +27,16 @@ CredentialsContainer::CredentialsContainer(nsPIDOMWindowInner* aParent) :
2827
CredentialsContainer::~CredentialsContainer()
2928
{}
3029

30+
void
31+
CredentialsContainer::EnsureWebAuthnManager()
32+
{
33+
MOZ_ASSERT(NS_IsMainThread());
34+
35+
if (!mManager) {
36+
mManager = new WebAuthnManager(mParent);
37+
}
38+
}
39+
3140
JSObject*
3241
CredentialsContainer::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
3342
{
@@ -37,22 +46,22 @@ CredentialsContainer::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenPro
3746
already_AddRefed<Promise>
3847
CredentialsContainer::Get(const CredentialRequestOptions& aOptions)
3948
{
40-
RefPtr<WebAuthnManager> mgr = WebAuthnManager::GetOrCreate();
41-
return mgr->GetAssertion(mParent, aOptions.mPublicKey, aOptions.mSignal);
49+
EnsureWebAuthnManager();
50+
return mManager->GetAssertion(aOptions.mPublicKey, aOptions.mSignal);
4251
}
4352

4453
already_AddRefed<Promise>
4554
CredentialsContainer::Create(const CredentialCreationOptions& aOptions)
4655
{
47-
RefPtr<WebAuthnManager> mgr = WebAuthnManager::GetOrCreate();
48-
return mgr->MakeCredential(mParent, aOptions.mPublicKey, aOptions.mSignal);
56+
EnsureWebAuthnManager();
57+
return mManager->MakeCredential(aOptions.mPublicKey, aOptions.mSignal);
4958
}
5059

5160
already_AddRefed<Promise>
5261
CredentialsContainer::Store(const Credential& aCredential)
5362
{
54-
RefPtr<WebAuthnManager> mgr = WebAuthnManager::GetOrCreate();
55-
return mgr->Store(mParent, aCredential);
63+
EnsureWebAuthnManager();
64+
return mManager->Store(aCredential);
5665
}
5766

5867
} // namespace dom

dom/credentialmanagement/CredentialsContainer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define mozilla_dom_CredentialsContainer_h
99

1010
#include "mozilla/dom/CredentialManagementBinding.h"
11+
#include "mozilla/dom/WebAuthnManager.h"
1112

1213
namespace mozilla {
1314
namespace dom {
@@ -32,15 +33,20 @@ class CredentialsContainer final : public nsISupports
3233

3334
already_AddRefed<Promise>
3435
Get(const CredentialRequestOptions& aOptions);
36+
3537
already_AddRefed<Promise>
3638
Create(const CredentialCreationOptions& aOptions);
39+
3740
already_AddRefed<Promise>
3841
Store(const Credential& aCredential);
3942

4043
private:
4144
~CredentialsContainer();
4245

46+
void EnsureWebAuthnManager();
47+
4348
nsCOMPtr<nsPIDOMWindowInner> mParent;
49+
RefPtr<WebAuthnManager> mManager;
4450
};
4551

4652
} // 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)