Bug 1402156 - Cancel any pending requests when u2f.{register,sign} is called r=jcj
authorTim Taubert <ttaubert@mozilla.com>
Fri, 06 Oct 2017 14:45:27 +0200
changeset 437980 f232c635ecd51d1557683b0457c926e7e2f23128
parent 437979 3e5a825eac7d6b07cc6c56a414ab4087030d8ef7
child 437981 ae117635bbf059868fc9bacc791afb75042dd7ec
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjcj
bugs1402156
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1402156 - Cancel any pending requests when u2f.{register,sign} is called r=jcj Bug #: 1402156 Differential Revision: https://phabricator.services.mozilla.com/D101
dom/credentialmanagement/CredentialsContainer.cpp
dom/u2f/U2F.cpp
--- a/dom/credentialmanagement/CredentialsContainer.cpp
+++ b/dom/credentialmanagement/CredentialsContainer.cpp
@@ -33,22 +33,20 @@ CredentialsContainer::WrapObject(JSConte
 {
   return CredentialsContainerBinding::Wrap(aCx, this, aGivenProto);
 }
 
 already_AddRefed<Promise>
 CredentialsContainer::Get(const CredentialRequestOptions& aOptions)
 {
   RefPtr<WebAuthnManager> mgr = WebAuthnManager::GetOrCreate();
-  MOZ_ASSERT(mgr);
   return mgr->GetAssertion(mParent, aOptions.mPublicKey);
 }
 
 already_AddRefed<Promise>
 CredentialsContainer::Create(const CredentialCreationOptions& aOptions)
 {
   RefPtr<WebAuthnManager> mgr = WebAuthnManager::GetOrCreate();
-  MOZ_ASSERT(mgr);
   return mgr->MakeCredential(mParent, aOptions.mPublicKey);
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/u2f/U2F.cpp
+++ b/dom/u2f/U2F.cpp
@@ -242,24 +242,18 @@ U2F::Register(const nsAString& aAppId,
               const Sequence<RegisterRequest>& aRegisterRequests,
               const Sequence<RegisteredKey>& aRegisteredKeys,
               U2FRegisterCallback& aCallback,
               const Optional<Nullable<int32_t>>& opt_aTimeoutSeconds,
               ErrorResult& aRv)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  RefPtr<U2FManager> mgr = U2FManager::GetOrCreate();
-  MOZ_ASSERT(mgr);
-  if (!mgr || mRegisterCallback.isSome()) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return;
-  }
+  Cancel();
 
-  Cancel();
   MOZ_ASSERT(mRegisterCallback.isNothing());
   mRegisterCallback = Some(nsMainThreadPtrHandle<U2FRegisterCallback>(
                         new nsMainThreadPtrHolder<U2FRegisterCallback>(
                             "U2F::Register::callback", &aCallback)));
 
   uint32_t adjustedTimeoutMillis = AdjustedTimeoutMillis(opt_aTimeoutSeconds);
 
   // Evaluate the AppID
@@ -302,16 +296,17 @@ U2F::Register(const nsAString& aAppId,
 
   // Build the exclusion list, if any
   nsTArray<WebAuthnScopedCredentialDescriptor> excludeList;
   RegisteredKeysToScopedCredentialList(adjustedAppId, aRegisteredKeys,
                                        excludeList);
 
   auto& localReqHolder = mPromiseHolder;
   auto& localCb = mRegisterCallback;
+  RefPtr<U2FManager> mgr = U2FManager::GetOrCreate();
   RefPtr<U2FPromise> p = mgr->Register(mParent, cAppId,
                                        NS_ConvertUTF16toUTF8(clientDataJSON),
                                        adjustedTimeoutMillis, excludeList);
   p->Then(mEventTarget, "dom::U2F::Register::Promise::Resolve",
           [&localCb, &localReqHolder](nsString aResponse) {
               MOZ_LOG(gU2FLog, LogLevel::Debug,
                       ("dom::U2F::Register::Promise::Resolve, response was %s",
                         NS_ConvertUTF16toUTF8(aResponse).get()));
@@ -339,24 +334,18 @@ U2F::Sign(const nsAString& aAppId,
           const nsAString& aChallenge,
           const Sequence<RegisteredKey>& aRegisteredKeys,
           U2FSignCallback& aCallback,
           const Optional<Nullable<int32_t>>& opt_aTimeoutSeconds,
           ErrorResult& aRv)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  RefPtr<U2FManager> mgr = U2FManager::GetOrCreate();
-  MOZ_ASSERT(mgr);
-  if (!mgr || mSignCallback.isSome()) {
-    aRv.Throw(NS_ERROR_FAILURE);
-    return;
-  }
+  Cancel();
 
-  Cancel();
   MOZ_ASSERT(mSignCallback.isNothing());
   mSignCallback = Some(nsMainThreadPtrHandle<U2FSignCallback>(
                     new nsMainThreadPtrHolder<U2FSignCallback>(
                         "U2F::Sign::callback", &aCallback)));
 
   uint32_t adjustedTimeoutMillis = AdjustedTimeoutMillis(opt_aTimeoutSeconds);
 
   // Evaluate the AppID
@@ -384,16 +373,17 @@ U2F::Sign(const nsAString& aAppId,
   }
 
   // Build the key list, if any
   nsTArray<WebAuthnScopedCredentialDescriptor> permittedList;
   RegisteredKeysToScopedCredentialList(adjustedAppId, aRegisteredKeys,
                                        permittedList);
   auto& localReqHolder = mPromiseHolder;
   auto& localCb = mSignCallback;
+  RefPtr<U2FManager> mgr = U2FManager::GetOrCreate();
   RefPtr<U2FPromise> p = mgr->Sign(mParent, cAppId,
                                    NS_ConvertUTF16toUTF8(clientDataJSON),
                                    adjustedTimeoutMillis, permittedList);
   p->Then(mEventTarget, "dom::U2F::Sign::Promise::Resolve",
           [&localCb, &localReqHolder](nsString aResponse) {
               MOZ_LOG(gU2FLog, LogLevel::Debug,
                       ("dom::U2F::Sign::Promise::Resolve, response was %s",
                         NS_ConvertUTF16toUTF8(aResponse).get()));