2017-10-27 01:08:41 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2016-02-09 18:43:00 +03:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2016-02-09 18:43:00 +03:00
|
|
|
|
|
|
|
#include "mozilla/dom/U2F.h"
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
#include "mozilla/dom/WebCryptoCommon.h"
|
2017-11-28 12:21:07 +03:00
|
|
|
#include "mozilla/ipc/PBackgroundChild.h"
|
|
|
|
#include "mozilla/ipc/BackgroundChild.h"
|
2017-12-05 21:05:06 +03:00
|
|
|
#include "mozilla/dom/WebAuthnTransactionChild.h"
|
2016-02-09 18:43:00 +03:00
|
|
|
#include "nsContentUtils.h"
|
2017-11-28 12:21:07 +03:00
|
|
|
#include "nsICryptoHash.h"
|
2017-09-29 02:45:28 +03:00
|
|
|
#include "nsIEffectiveTLDService.h"
|
2016-02-09 18:43:00 +03:00
|
|
|
#include "nsNetCID.h"
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
#include "nsNetUtil.h"
|
2016-04-15 19:29:12 +03:00
|
|
|
#include "nsURLParsers.h"
|
2017-11-28 12:21:07 +03:00
|
|
|
#include "U2FUtil.h"
|
|
|
|
#include "hasht.h"
|
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
2016-04-15 19:29:12 +03:00
|
|
|
|
2017-09-29 02:45:28 +03:00
|
|
|
// Forward decl because of nsHTMLDocument.h's complex dependency on /layout/style
|
|
|
|
class nsHTMLDocument {
|
|
|
|
public:
|
|
|
|
bool IsRegistrableDomainSuffixOfOrEqualTo(const nsAString& aHostSuffixString,
|
|
|
|
const nsACString& aOrigHost);
|
|
|
|
};
|
|
|
|
|
2016-02-09 18:43:00 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
static mozilla::LazyLogModule gU2FLog("u2fmanager");
|
2016-02-09 18:43:00 +03:00
|
|
|
|
2016-04-19 00:49:07 +03:00
|
|
|
NS_NAMED_LITERAL_STRING(kFinishEnrollment, "navigator.id.finishEnrollment");
|
|
|
|
NS_NAMED_LITERAL_STRING(kGetAssertion, "navigator.id.getAssertion");
|
2016-02-09 18:43:00 +03:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(U2F)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2017-11-28 12:21:07 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
|
2016-02-09 18:43:00 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(U2F)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(U2F)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(U2F, mParent)
|
|
|
|
|
2017-11-28 12:21:07 +03:00
|
|
|
/***********************************************************************
|
|
|
|
* Utility Functions
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
static ErrorCode
|
|
|
|
ConvertNSResultToErrorCode(const nsresult& aError)
|
|
|
|
{
|
|
|
|
if (aError == NS_ERROR_DOM_TIMEOUT_ERR) {
|
|
|
|
return ErrorCode::TIMEOUT;
|
|
|
|
}
|
|
|
|
/* Emitted by U2F{Soft,HID}TokenManager when we really mean ineligible */
|
|
|
|
if (aError == NS_ERROR_DOM_NOT_ALLOWED_ERR) {
|
|
|
|
return ErrorCode::DEVICE_INELIGIBLE;
|
|
|
|
}
|
|
|
|
return ErrorCode::OTHER_ERROR;
|
|
|
|
}
|
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
static uint32_t
|
|
|
|
AdjustedTimeoutMillis(const Optional<Nullable<int32_t>>& opt_aSeconds)
|
|
|
|
{
|
|
|
|
uint32_t adjustedTimeoutMillis = 30000u;
|
|
|
|
if (opt_aSeconds.WasPassed() && !opt_aSeconds.Value().IsNull()) {
|
|
|
|
adjustedTimeoutMillis = opt_aSeconds.Value().Value() * 1000u;
|
|
|
|
adjustedTimeoutMillis = std::max(15000u, adjustedTimeoutMillis);
|
|
|
|
adjustedTimeoutMillis = std::min(120000u, adjustedTimeoutMillis);
|
|
|
|
}
|
|
|
|
return adjustedTimeoutMillis;
|
|
|
|
}
|
2016-02-09 18:43:00 +03:00
|
|
|
|
2016-04-19 00:49:07 +03:00
|
|
|
static nsresult
|
|
|
|
AssembleClientData(const nsAString& aOrigin, const nsAString& aTyp,
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
const nsAString& aChallenge,
|
|
|
|
/* out */ nsString& aClientData)
|
2016-02-09 18:43:00 +03:00
|
|
|
{
|
2016-10-13 06:56:56 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-01-09 23:22:49 +03:00
|
|
|
U2FClientData clientDataObject;
|
2016-04-19 00:49:07 +03:00
|
|
|
clientDataObject.mTyp.Construct(aTyp); // "Typ" from the U2F specification
|
|
|
|
clientDataObject.mChallenge.Construct(aChallenge);
|
|
|
|
clientDataObject.mOrigin.Construct(aOrigin);
|
2016-02-09 18:43:00 +03:00
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
if (NS_WARN_IF(!clientDataObject.ToJSON(aClientData))) {
|
2017-09-09 10:09:21 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
static void
|
|
|
|
RegisteredKeysToScopedCredentialList(const nsAString& aAppId,
|
|
|
|
const nsTArray<RegisteredKey>& aKeys,
|
2018-01-09 09:27:35 +03:00
|
|
|
nsTArray<WebAuthnScopedCredential>& aList)
|
2017-09-09 10:09:21 +03:00
|
|
|
{
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
for (const RegisteredKey& key : aKeys) {
|
|
|
|
// Check for required attributes
|
|
|
|
if (!key.mVersion.WasPassed() || !key.mKeyHandle.WasPassed() ||
|
|
|
|
key.mVersion.Value() != kRequiredU2FVersion) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-09-09 10:09:21 +03:00
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
// If this key's mAppId doesn't match the invocation, we can't handle it.
|
|
|
|
if (key.mAppId.WasPassed() && !key.mAppId.Value().Equals(aAppId)) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-09-09 10:09:21 +03:00
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
CryptoBuffer keyHandle;
|
|
|
|
nsresult rv = keyHandle.FromJwkBase64(key.mKeyHandle.Value());
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-09-09 10:09:21 +03:00
|
|
|
|
2018-01-09 09:27:35 +03:00
|
|
|
WebAuthnScopedCredential c;
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
c.id() = keyHandle;
|
|
|
|
aList.AppendElement(c);
|
2017-09-09 10:09:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
static ErrorCode
|
2017-09-29 02:45:28 +03:00
|
|
|
EvaluateAppID(nsPIDOMWindowInner* aParent, const nsString& aOrigin,
|
|
|
|
/* in/out */ nsString& aAppId)
|
2017-09-09 10:09:21 +03:00
|
|
|
{
|
|
|
|
// Facet is the specification's way of referring to the web origin.
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
nsAutoCString facetString = NS_ConvertUTF16toUTF8(aOrigin);
|
|
|
|
nsCOMPtr<nsIURI> facetUri;
|
|
|
|
if (NS_FAILED(NS_NewURI(getter_AddRefs(facetUri), facetString))) {
|
2016-10-07 00:35:57 +03:00
|
|
|
return ErrorCode::BAD_REQUEST;
|
|
|
|
}
|
|
|
|
|
2017-09-09 10:09:21 +03:00
|
|
|
// If the facetId (origin) is not HTTPS, reject
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
bool facetIsHttps = false;
|
|
|
|
if (NS_FAILED(facetUri->SchemeIs("https", &facetIsHttps)) || !facetIsHttps) {
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for prefs and scheme,
and generally made these cleaner.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : transplant_source : %EA%98%D2%87C%FD%CC%A5%3D%B5%9B%1C%DA%A5J%CD%05%94%13%0D
2017-09-05 22:32:42 +03:00
|
|
|
return ErrorCode::BAD_REQUEST;
|
|
|
|
}
|
2017-09-09 10:09:21 +03:00
|
|
|
|
|
|
|
// If the appId is empty or null, overwrite it with the facetId and accept
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
if (aAppId.IsEmpty() || aAppId.EqualsLiteral("null")) {
|
|
|
|
aAppId.Assign(aOrigin);
|
2017-09-09 10:09:21 +03:00
|
|
|
return ErrorCode::OK;
|
|
|
|
}
|
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
// AppID is user-supplied. It's quite possible for this parse to fail.
|
|
|
|
nsAutoCString appIdString = NS_ConvertUTF16toUTF8(aAppId);
|
|
|
|
nsCOMPtr<nsIURI> appIdUri;
|
|
|
|
if (NS_FAILED(NS_NewURI(getter_AddRefs(appIdUri), appIdString))) {
|
|
|
|
return ErrorCode::BAD_REQUEST;
|
|
|
|
}
|
|
|
|
|
2017-09-09 10:09:21 +03:00
|
|
|
// if the appId URL is not HTTPS, reject.
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
bool appIdIsHttps = false;
|
|
|
|
if (NS_FAILED(appIdUri->SchemeIs("https", &appIdIsHttps)) || !appIdIsHttps) {
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for prefs and scheme,
and generally made these cleaner.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : transplant_source : %EA%98%D2%87C%FD%CC%A5%3D%B5%9B%1C%DA%A5J%CD%05%94%13%0D
2017-09-05 22:32:42 +03:00
|
|
|
return ErrorCode::BAD_REQUEST;
|
|
|
|
}
|
2017-09-09 10:09:21 +03:00
|
|
|
|
2017-12-06 18:28:20 +03:00
|
|
|
nsAutoCString appIdHost;
|
|
|
|
if (NS_FAILED(appIdUri->GetAsciiHost(appIdHost))) {
|
|
|
|
return ErrorCode::BAD_REQUEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allow localhost.
|
|
|
|
if (appIdHost.EqualsLiteral("localhost")) {
|
|
|
|
nsAutoCString facetHost;
|
|
|
|
if (NS_FAILED(facetUri->GetAsciiHost(facetHost))) {
|
|
|
|
return ErrorCode::BAD_REQUEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (facetHost.EqualsLiteral("localhost")) {
|
|
|
|
return ErrorCode::OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-29 02:45:28 +03:00
|
|
|
// Run the HTML5 algorithm to relax the same-origin policy, copied from W3C
|
|
|
|
// Web Authentication. See Bug 1244959 comment #8 for context on why we are
|
|
|
|
// doing this instead of implementing the external-fetch FacetID logic.
|
|
|
|
nsCOMPtr<nsIDocument> document = aParent->GetDoc();
|
|
|
|
if (!document || !document->IsHTMLDocument()) {
|
|
|
|
return ErrorCode::BAD_REQUEST;
|
|
|
|
}
|
|
|
|
nsHTMLDocument* html = document->AsHTMLDocument();
|
|
|
|
if (NS_WARN_IF(!html)) {
|
|
|
|
return ErrorCode::BAD_REQUEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use the base domain as the facet for evaluation. This lets this algorithm
|
|
|
|
// relax the whole eTLD+1.
|
|
|
|
nsCOMPtr<nsIEffectiveTLDService> tldService =
|
|
|
|
do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID);
|
|
|
|
if (!tldService) {
|
|
|
|
return ErrorCode::BAD_REQUEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString lowestFacetHost;
|
|
|
|
if (NS_FAILED(tldService->GetBaseDomain(facetUri, 0, lowestFacetHost))) {
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
return ErrorCode::BAD_REQUEST;
|
|
|
|
}
|
2017-09-29 02:45:28 +03:00
|
|
|
|
|
|
|
MOZ_LOG(gU2FLog, LogLevel::Debug,
|
|
|
|
("AppId %s Facet %s", appIdHost.get(), lowestFacetHost.get()));
|
|
|
|
|
|
|
|
if (html->IsRegistrableDomainSuffixOfOrEqualTo(NS_ConvertUTF8toUTF16(lowestFacetHost),
|
|
|
|
appIdHost)) {
|
2016-10-07 00:35:57 +03:00
|
|
|
return ErrorCode::OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ErrorCode::BAD_REQUEST;
|
|
|
|
}
|
|
|
|
|
2017-11-28 12:21:07 +03:00
|
|
|
static nsresult
|
|
|
|
BuildTransactionHashes(const nsCString& aRpId,
|
|
|
|
const nsCString& aClientDataJSON,
|
|
|
|
/* out */ CryptoBuffer& aRpIdHash,
|
|
|
|
/* out */ CryptoBuffer& aClientDataHash)
|
|
|
|
{
|
|
|
|
nsresult srv;
|
|
|
|
nsCOMPtr<nsICryptoHash> hashService =
|
|
|
|
do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID, &srv);
|
|
|
|
if (NS_FAILED(srv)) {
|
|
|
|
return srv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aRpIdHash.SetLength(SHA256_LENGTH, fallible)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
srv = HashCString(hashService, aRpId, aRpIdHash);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(srv))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aClientDataHash.SetLength(SHA256_LENGTH, fallible)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
srv = HashCString(hashService, aClientDataJSON, aClientDataHash);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(srv))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MOZ_LOG_TEST(gU2FLog, LogLevel::Debug)) {
|
|
|
|
nsString base64;
|
|
|
|
Unused << NS_WARN_IF(NS_FAILED(aRpIdHash.ToJwkBase64(base64)));
|
|
|
|
|
|
|
|
MOZ_LOG(gU2FLog, LogLevel::Debug,
|
|
|
|
("dom::U2FManager::RpID: %s", aRpId.get()));
|
|
|
|
|
|
|
|
MOZ_LOG(gU2FLog, LogLevel::Debug,
|
|
|
|
("dom::U2FManager::Rp ID Hash (base64): %s",
|
|
|
|
NS_ConvertUTF16toUTF8(base64).get()));
|
|
|
|
|
|
|
|
Unused << NS_WARN_IF(NS_FAILED(aClientDataHash.ToJwkBase64(base64)));
|
|
|
|
|
|
|
|
MOZ_LOG(gU2FLog, LogLevel::Debug,
|
|
|
|
("dom::U2FManager::Client Data JSON: %s", aClientDataJSON.get()));
|
|
|
|
|
|
|
|
MOZ_LOG(gU2FLog, LogLevel::Debug,
|
|
|
|
("dom::U2FManager::Client Data Hash (base64): %s",
|
|
|
|
NS_ConvertUTF16toUTF8(base64).get()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* U2F JavaScript API Implementation
|
|
|
|
**********************************************************************/
|
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
U2F::~U2F()
|
2016-02-09 18:43:00 +03:00
|
|
|
{
|
2017-11-28 12:21:07 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (mTransaction.isSome()) {
|
|
|
|
RejectTransaction(NS_ERROR_ABORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mChild) {
|
2017-12-05 21:05:06 +03:00
|
|
|
RefPtr<WebAuthnTransactionChild> c;
|
2017-11-28 12:21:07 +03:00
|
|
|
mChild.swap(c);
|
2017-12-05 21:05:06 +03:00
|
|
|
c->Disconnect();
|
2017-11-28 12:21:07 +03:00
|
|
|
}
|
2016-10-13 06:56:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
U2F::Init(ErrorResult& aRv)
|
2017-09-09 10:09:21 +03:00
|
|
|
{
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
MOZ_ASSERT(mParent);
|
2017-09-09 10:09:21 +03:00
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
nsCOMPtr<nsIDocument> doc = mParent->GetDoc();
|
|
|
|
MOZ_ASSERT(doc);
|
|
|
|
if (!doc) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
2017-09-09 10:09:21 +03:00
|
|
|
}
|
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
nsIPrincipal* principal = doc->NodePrincipal();
|
|
|
|
aRv = nsContentUtils::GetUTFOrigin(principal, mOrigin);
|
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
2016-02-09 18:43:00 +03:00
|
|
|
return;
|
|
|
|
}
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for prefs and scheme,
and generally made these cleaner.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : transplant_source : %EA%98%D2%87C%FD%CC%A5%3D%B5%9B%1C%DA%A5J%CD%05%94%13%0D
2017-09-05 22:32:42 +03:00
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
if (NS_WARN_IF(mOrigin.IsEmpty())) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
2017-09-09 10:09:21 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-04-19 00:49:07 +03:00
|
|
|
}
|
2016-02-09 18:43:00 +03:00
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
/* virtual */ JSObject*
|
|
|
|
U2F::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2016-04-19 00:49:07 +03:00
|
|
|
{
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
return U2FBinding::Wrap(aCx, this, aGivenProto);
|
2016-10-13 06:56:56 +03:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:55:52 +03:00
|
|
|
template<typename T, typename C>
|
|
|
|
void
|
|
|
|
U2F::ExecuteCallback(T& aResp, nsMainThreadPtrHandle<C>& aCb)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aCb);
|
|
|
|
|
|
|
|
// Assert that mTransaction was cleared before before we were called to allow
|
|
|
|
// reentrancy from microtask checkpoints.
|
|
|
|
MOZ_ASSERT(mTransaction.isNothing());
|
|
|
|
|
|
|
|
ErrorResult error;
|
|
|
|
aCb->Call(aResp, error);
|
|
|
|
NS_WARNING_ASSERTION(!error.Failed(), "dom::U2F::Promise callback failed");
|
|
|
|
error.SuppressException(); // Useful exceptions already emitted
|
|
|
|
}
|
|
|
|
|
2016-10-13 06:56:56 +03:00
|
|
|
void
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
U2F::Register(const nsAString& aAppId,
|
|
|
|
const Sequence<RegisterRequest>& aRegisterRequests,
|
|
|
|
const Sequence<RegisteredKey>& aRegisteredKeys,
|
|
|
|
U2FRegisterCallback& aCallback,
|
|
|
|
const Optional<Nullable<int32_t>>& opt_aTimeoutSeconds,
|
|
|
|
ErrorResult& aRv)
|
2016-10-13 06:56:56 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2017-11-28 12:21:07 +03:00
|
|
|
if (mTransaction.isSome()) {
|
|
|
|
CancelTransaction(NS_ERROR_ABORT);
|
|
|
|
}
|
2017-10-06 15:45:27 +03:00
|
|
|
|
2017-12-08 18:55:52 +03:00
|
|
|
nsMainThreadPtrHandle<U2FRegisterCallback> callback(
|
|
|
|
new nsMainThreadPtrHolder<U2FRegisterCallback>("U2F::Register::callback",
|
|
|
|
&aCallback));
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
|
2017-12-08 18:55:52 +03:00
|
|
|
// Ensure we have a callback.
|
|
|
|
if (NS_WARN_IF(!callback)) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-13 06:56:56 +03:00
|
|
|
|
|
|
|
// Evaluate the AppID
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
nsString adjustedAppId;
|
|
|
|
adjustedAppId.Assign(aAppId);
|
2017-09-29 02:45:28 +03:00
|
|
|
ErrorCode appIdResult = EvaluateAppID(mParent, mOrigin, adjustedAppId);
|
2016-10-13 06:56:56 +03:00
|
|
|
if (appIdResult != ErrorCode::OK) {
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
RegisterResponse response;
|
|
|
|
response.mErrorCode.Construct(static_cast<uint32_t>(appIdResult));
|
2017-12-08 18:55:52 +03:00
|
|
|
ExecuteCallback(response, callback);
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
return;
|
2017-09-09 10:09:21 +03:00
|
|
|
}
|
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
// Produce the AppParam from the current AppID
|
|
|
|
nsCString cAppId = NS_ConvertUTF16toUTF8(adjustedAppId);
|
2016-10-06 23:07:17 +03:00
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
nsAutoString clientDataJSON;
|
2016-02-09 18:43:00 +03:00
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
// Pick the first valid RegisterRequest; we can only work with one.
|
|
|
|
for (const RegisterRequest& req : aRegisterRequests) {
|
|
|
|
if (!req.mChallenge.WasPassed() || !req.mVersion.WasPassed() ||
|
|
|
|
req.mVersion.Value() != kRequiredU2FVersion) {
|
2016-04-19 00:49:07 +03:00
|
|
|
continue;
|
2016-02-09 18:43:00 +03:00
|
|
|
}
|
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
nsresult rv = AssembleClientData(mOrigin, kFinishEnrollment,
|
|
|
|
req.mChallenge.Value(), clientDataJSON);
|
2016-02-09 18:43:00 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2016-10-13 06:56:56 +03:00
|
|
|
continue;
|
2016-02-09 18:43:00 +03:00
|
|
|
}
|
2016-10-13 06:56:56 +03:00
|
|
|
}
|
2016-02-09 18:43:00 +03:00
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
// Did we not get a valid RegisterRequest? Abort.
|
|
|
|
if (clientDataJSON.IsEmpty()) {
|
|
|
|
RegisterResponse response;
|
|
|
|
response.mErrorCode.Construct(static_cast<uint32_t>(ErrorCode::BAD_REQUEST));
|
2017-12-08 18:55:52 +03:00
|
|
|
ExecuteCallback(response, callback);
|
2016-04-19 00:49:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
// Build the exclusion list, if any
|
2018-01-09 09:27:35 +03:00
|
|
|
nsTArray<WebAuthnScopedCredential> excludeList;
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
RegisteredKeysToScopedCredentialList(adjustedAppId, aRegisteredKeys,
|
|
|
|
excludeList);
|
|
|
|
|
2017-11-28 12:21:07 +03:00
|
|
|
auto clientData = NS_ConvertUTF16toUTF8(clientDataJSON);
|
|
|
|
|
|
|
|
CryptoBuffer rpIdHash, clientDataHash;
|
|
|
|
if (NS_FAILED(BuildTransactionHashes(cAppId, clientData,
|
|
|
|
rpIdHash, clientDataHash))) {
|
|
|
|
RegisterResponse response;
|
|
|
|
response.mErrorCode.Construct(static_cast<uint32_t>(ErrorCode::OTHER_ERROR));
|
2017-12-08 18:55:52 +03:00
|
|
|
ExecuteCallback(response, callback);
|
2017-11-28 12:21:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!MaybeCreateBackgroundActor()) {
|
|
|
|
RegisterResponse response;
|
|
|
|
response.mErrorCode.Construct(static_cast<uint32_t>(ErrorCode::OTHER_ERROR));
|
2017-12-08 18:55:52 +03:00
|
|
|
ExecuteCallback(response, callback);
|
2017-11-28 12:21:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ListenForVisibilityEvents();
|
|
|
|
|
|
|
|
// Always blank for U2F
|
|
|
|
nsTArray<WebAuthnExtension> extensions;
|
|
|
|
|
2017-11-29 15:58:33 +03:00
|
|
|
// Default values for U2F.
|
|
|
|
WebAuthnAuthenticatorSelection authSelection(false /* requireResidentKey */,
|
|
|
|
false /* requireUserVerification */,
|
|
|
|
false /* requirePlatformAttachment */);
|
|
|
|
|
2017-12-08 18:55:52 +03:00
|
|
|
uint32_t adjustedTimeoutMillis = AdjustedTimeoutMillis(opt_aTimeoutSeconds);
|
|
|
|
|
2017-11-29 15:58:33 +03:00
|
|
|
WebAuthnMakeCredentialInfo info(rpIdHash,
|
|
|
|
clientDataHash,
|
|
|
|
adjustedTimeoutMillis,
|
|
|
|
excludeList,
|
|
|
|
extensions,
|
|
|
|
authSelection);
|
2017-11-28 12:21:07 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(mTransaction.isNothing());
|
2017-12-08 18:55:52 +03:00
|
|
|
mTransaction = Some(U2FTransaction(clientData, Move(AsVariant(callback))));
|
2017-11-28 12:21:07 +03:00
|
|
|
mChild->SendRequestRegister(mTransaction.ref().mId, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-12-05 21:05:06 +03:00
|
|
|
U2F::FinishMakeCredential(const uint64_t& aTransactionId,
|
|
|
|
nsTArray<uint8_t>& aRegBuffer)
|
2017-11-28 12:21:07 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
// Check for a valid transaction.
|
|
|
|
if (mTransaction.isNothing() || mTransaction.ref().mId != aTransactionId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:55:52 +03:00
|
|
|
if (NS_WARN_IF(!mTransaction.ref().HasRegisterCallback())) {
|
|
|
|
RejectTransaction(NS_ERROR_ABORT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-28 12:21:07 +03:00
|
|
|
CryptoBuffer clientDataBuf;
|
|
|
|
if (NS_WARN_IF(!clientDataBuf.Assign(mTransaction.ref().mClientData))) {
|
|
|
|
RejectTransaction(NS_ERROR_ABORT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CryptoBuffer regBuf;
|
|
|
|
if (NS_WARN_IF(!regBuf.Assign(aRegBuffer))) {
|
|
|
|
RejectTransaction(NS_ERROR_ABORT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString clientDataBase64;
|
|
|
|
nsString registrationDataBase64;
|
|
|
|
nsresult rvClientData = clientDataBuf.ToJwkBase64(clientDataBase64);
|
|
|
|
nsresult rvRegistrationData = regBuf.ToJwkBase64(registrationDataBase64);
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rvClientData)) ||
|
|
|
|
NS_WARN_IF(NS_FAILED(rvRegistrationData))) {
|
|
|
|
RejectTransaction(NS_ERROR_ABORT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assemble a response object to return
|
|
|
|
RegisterResponse response;
|
|
|
|
response.mVersion.Construct(kRequiredU2FVersion);
|
|
|
|
response.mClientData.Construct(clientDataBase64);
|
|
|
|
response.mRegistrationData.Construct(registrationDataBase64);
|
|
|
|
response.mErrorCode.Construct(static_cast<uint32_t>(ErrorCode::OK));
|
|
|
|
|
2017-12-08 18:55:52 +03:00
|
|
|
// Keep the callback pointer alive.
|
|
|
|
nsMainThreadPtrHandle<U2FRegisterCallback> callback(
|
|
|
|
mTransaction.ref().GetRegisterCallback());
|
|
|
|
|
2017-11-28 12:21:07 +03:00
|
|
|
ClearTransaction();
|
2017-12-08 18:55:52 +03:00
|
|
|
ExecuteCallback(response, callback);
|
2016-04-19 00:49:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
U2F::Sign(const nsAString& aAppId,
|
|
|
|
const nsAString& aChallenge,
|
|
|
|
const Sequence<RegisteredKey>& aRegisteredKeys,
|
|
|
|
U2FSignCallback& aCallback,
|
|
|
|
const Optional<Nullable<int32_t>>& opt_aTimeoutSeconds,
|
|
|
|
ErrorResult& aRv)
|
2016-04-19 00:49:07 +03:00
|
|
|
{
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-09-09 10:09:21 +03:00
|
|
|
|
2017-11-28 12:21:07 +03:00
|
|
|
if (mTransaction.isSome()) {
|
|
|
|
CancelTransaction(NS_ERROR_ABORT);
|
|
|
|
}
|
2017-10-06 15:45:27 +03:00
|
|
|
|
2017-12-08 18:55:52 +03:00
|
|
|
nsMainThreadPtrHandle<U2FSignCallback> callback(
|
|
|
|
new nsMainThreadPtrHolder<U2FSignCallback>("U2F::Sign::callback",
|
|
|
|
&aCallback));
|
2016-10-08 03:28:52 +03:00
|
|
|
|
2017-12-08 18:55:52 +03:00
|
|
|
// Ensure we have a callback.
|
|
|
|
if (NS_WARN_IF(!callback)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-09-09 10:09:21 +03:00
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
// Evaluate the AppID
|
|
|
|
nsString adjustedAppId;
|
|
|
|
adjustedAppId.Assign(aAppId);
|
2017-09-29 02:45:28 +03:00
|
|
|
ErrorCode appIdResult = EvaluateAppID(mParent, mOrigin, adjustedAppId);
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
if (appIdResult != ErrorCode::OK) {
|
|
|
|
SignResponse response;
|
|
|
|
response.mErrorCode.Construct(static_cast<uint32_t>(appIdResult));
|
2017-12-08 18:55:52 +03:00
|
|
|
ExecuteCallback(response, callback);
|
2016-10-08 03:28:52 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
// Produce the AppParam from the current AppID
|
|
|
|
nsCString cAppId = NS_ConvertUTF16toUTF8(adjustedAppId);
|
2017-09-09 10:09:21 +03:00
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
nsAutoString clientDataJSON;
|
|
|
|
nsresult rv = AssembleClientData(mOrigin, kGetAssertion, aChallenge,
|
|
|
|
clientDataJSON);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
SignResponse response;
|
|
|
|
response.mErrorCode.Construct(static_cast<uint32_t>(ErrorCode::BAD_REQUEST));
|
2017-12-08 18:55:52 +03:00
|
|
|
ExecuteCallback(response, callback);
|
2016-10-08 03:28:52 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
// Build the key list, if any
|
2018-01-09 09:27:35 +03:00
|
|
|
nsTArray<WebAuthnScopedCredential> permittedList;
|
Bug 1245527 - Rewrite U2F.cpp to use U2FTokenManager. r=keeler, r=ttaubert
- This patch reworks the U2F module to asynchronously call U2FManager,
which in turn handles constructing and managing the U2FTokenManager
via IPC.
- Add U2FTransaction{Parent,Child} implementations to mirror similar ones for
WebAuthn
- Rewrite all tests to compensate for U2F executing asynchronously now.
- Used async tasks, used the manifest parameters for scheme, and generally
made these cleaner.
- The mochitest "pref =" functionality from Bug 1328830 doesn't support Android
yet, causing breakage on Android. Rework the tests to go back to the old way
of using iframes to test U2F.
NOTE TO REVIEWERS:
Since this is huge, I recommend the following:
keeler - please review U2F.cpp/h, the tests, and the security-prefs.js. Most
of the U2F logic is still in U2F.cpp like before, but there's been
some reworking of how it is called.
ttaubert - please review U2FManager, the Transaction classes, build changes,
and the changes to nsGlobalWindow. All of these should be very
similar to the WebAuthn code it's patterned off.
MozReview-Commit-ID: C1ZN2ch66Rm
--HG--
extra : rebase_source : 5a2c52b0340c13f471af5040b998eb7e661b1981
2017-09-11 22:56:59 +03:00
|
|
|
RegisteredKeysToScopedCredentialList(adjustedAppId, aRegisteredKeys,
|
|
|
|
permittedList);
|
2017-11-28 12:21:07 +03:00
|
|
|
|
|
|
|
auto clientData = NS_ConvertUTF16toUTF8(clientDataJSON);
|
|
|
|
|
|
|
|
CryptoBuffer rpIdHash, clientDataHash;
|
|
|
|
if (NS_FAILED(BuildTransactionHashes(cAppId, clientData,
|
|
|
|
rpIdHash, clientDataHash))) {
|
|
|
|
SignResponse response;
|
|
|
|
response.mErrorCode.Construct(static_cast<uint32_t>(ErrorCode::OTHER_ERROR));
|
2017-12-08 18:55:52 +03:00
|
|
|
ExecuteCallback(response, callback);
|
2017-11-28 12:21:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!MaybeCreateBackgroundActor()) {
|
|
|
|
SignResponse response;
|
|
|
|
response.mErrorCode.Construct(static_cast<uint32_t>(ErrorCode::OTHER_ERROR));
|
2017-12-08 18:55:52 +03:00
|
|
|
ExecuteCallback(response, callback);
|
2017-11-28 12:21:07 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ListenForVisibilityEvents();
|
|
|
|
|
|
|
|
// Always blank for U2F
|
|
|
|
nsTArray<WebAuthnExtension> extensions;
|
|
|
|
|
2017-12-08 18:55:52 +03:00
|
|
|
uint32_t adjustedTimeoutMillis = AdjustedTimeoutMillis(opt_aTimeoutSeconds);
|
|
|
|
|
2017-11-29 15:58:33 +03:00
|
|
|
WebAuthnGetAssertionInfo info(rpIdHash,
|
|
|
|
clientDataHash,
|
|
|
|
adjustedTimeoutMillis,
|
|
|
|
permittedList,
|
2018-01-09 09:27:35 +03:00
|
|
|
false, /* requireUserVerification */
|
2017-11-29 15:58:33 +03:00
|
|
|
extensions);
|
2017-11-28 12:21:07 +03:00
|
|
|
|
|
|
|
MOZ_ASSERT(mTransaction.isNothing());
|
2017-12-08 18:55:52 +03:00
|
|
|
mTransaction = Some(U2FTransaction(clientData, Move(AsVariant(callback))));
|
2017-11-28 12:21:07 +03:00
|
|
|
mChild->SendRequestSign(mTransaction.ref().mId, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-12-05 21:05:06 +03:00
|
|
|
U2F::FinishGetAssertion(const uint64_t& aTransactionId,
|
|
|
|
nsTArray<uint8_t>& aCredentialId,
|
|
|
|
nsTArray<uint8_t>& aSigBuffer)
|
2017-11-28 12:21:07 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
// Check for a valid transaction.
|
|
|
|
if (mTransaction.isNothing() || mTransaction.ref().mId != aTransactionId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:55:52 +03:00
|
|
|
if (NS_WARN_IF(!mTransaction.ref().HasSignCallback())) {
|
|
|
|
RejectTransaction(NS_ERROR_ABORT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-28 12:21:07 +03:00
|
|
|
CryptoBuffer clientDataBuf;
|
|
|
|
if (NS_WARN_IF(!clientDataBuf.Assign(mTransaction.ref().mClientData))) {
|
|
|
|
RejectTransaction(NS_ERROR_ABORT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CryptoBuffer credBuf;
|
|
|
|
if (NS_WARN_IF(!credBuf.Assign(aCredentialId))) {
|
|
|
|
RejectTransaction(NS_ERROR_ABORT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CryptoBuffer sigBuf;
|
|
|
|
if (NS_WARN_IF(!sigBuf.Assign(aSigBuffer))) {
|
|
|
|
RejectTransaction(NS_ERROR_ABORT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assemble a response object to return
|
|
|
|
nsString clientDataBase64;
|
|
|
|
nsString signatureDataBase64;
|
|
|
|
nsString keyHandleBase64;
|
|
|
|
nsresult rvClientData = clientDataBuf.ToJwkBase64(clientDataBase64);
|
|
|
|
nsresult rvSignatureData = sigBuf.ToJwkBase64(signatureDataBase64);
|
|
|
|
nsresult rvKeyHandle = credBuf.ToJwkBase64(keyHandleBase64);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rvClientData)) ||
|
|
|
|
NS_WARN_IF(NS_FAILED(rvSignatureData) ||
|
|
|
|
NS_WARN_IF(NS_FAILED(rvKeyHandle)))) {
|
|
|
|
RejectTransaction(NS_ERROR_ABORT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SignResponse response;
|
|
|
|
response.mKeyHandle.Construct(keyHandleBase64);
|
|
|
|
response.mClientData.Construct(clientDataBase64);
|
|
|
|
response.mSignatureData.Construct(signatureDataBase64);
|
|
|
|
response.mErrorCode.Construct(static_cast<uint32_t>(ErrorCode::OK));
|
|
|
|
|
2017-12-08 18:55:52 +03:00
|
|
|
// Keep the callback pointer alive.
|
|
|
|
nsMainThreadPtrHandle<U2FSignCallback> callback(
|
|
|
|
mTransaction.ref().GetSignCallback());
|
|
|
|
|
2017-11-28 12:21:07 +03:00
|
|
|
ClearTransaction();
|
2017-12-08 18:55:52 +03:00
|
|
|
ExecuteCallback(response, callback);
|
2017-11-28 12:21:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
U2F::ClearTransaction()
|
|
|
|
{
|
|
|
|
if (!NS_WARN_IF(mTransaction.isNothing())) {
|
|
|
|
StopListeningForVisibilityEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
mTransaction.reset();
|
2016-04-19 00:49:07 +03:00
|
|
|
}
|
|
|
|
|
2017-09-19 17:55:38 +03:00
|
|
|
void
|
2017-11-28 12:21:07 +03:00
|
|
|
U2F::RejectTransaction(const nsresult& aError)
|
|
|
|
{
|
2017-12-08 18:55:52 +03:00
|
|
|
if (NS_WARN_IF(mTransaction.isNothing())) {
|
|
|
|
return;
|
|
|
|
}
|
2017-11-28 12:21:07 +03:00
|
|
|
|
2017-12-08 18:55:52 +03:00
|
|
|
StopListeningForVisibilityEvents();
|
2017-11-28 12:21:07 +03:00
|
|
|
|
2017-12-08 18:55:52 +03:00
|
|
|
// Clear out mTransaction before calling ExecuteCallback() below to allow
|
|
|
|
// reentrancy from microtask checkpoints.
|
|
|
|
Maybe<U2FTransaction> maybeTransaction(Move(mTransaction));
|
|
|
|
MOZ_ASSERT(mTransaction.isNothing() && maybeTransaction.isSome());
|
|
|
|
|
|
|
|
U2FTransaction& transaction = maybeTransaction.ref();
|
|
|
|
ErrorCode code = ConvertNSResultToErrorCode(aError);
|
|
|
|
|
|
|
|
if (transaction.HasRegisterCallback()) {
|
|
|
|
RegisterResponse response;
|
|
|
|
response.mErrorCode.Construct(static_cast<uint32_t>(code));
|
|
|
|
ExecuteCallback(response, transaction.GetRegisterCallback());
|
2017-11-28 12:21:07 +03:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:55:52 +03:00
|
|
|
if (transaction.HasSignCallback()) {
|
|
|
|
SignResponse response;
|
|
|
|
response.mErrorCode.Construct(static_cast<uint32_t>(code));
|
|
|
|
ExecuteCallback(response, transaction.GetSignCallback());
|
|
|
|
}
|
2017-11-28 12:21:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
U2F::CancelTransaction(const nsresult& aError)
|
|
|
|
{
|
|
|
|
if (!NS_WARN_IF(!mChild || mTransaction.isNothing())) {
|
|
|
|
mChild->SendRequestCancel(mTransaction.ref().mId);
|
|
|
|
}
|
|
|
|
|
|
|
|
RejectTransaction(aError);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
U2F::RequestAborted(const uint64_t& aTransactionId, const nsresult& aError)
|
2017-09-19 17:55:38 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2017-11-28 12:21:07 +03:00
|
|
|
if (mTransaction.isSome() && mTransaction.ref().mId == aTransactionId) {
|
|
|
|
RejectTransaction(aError);
|
|
|
|
}
|
|
|
|
}
|
2017-11-28 12:21:07 +03:00
|
|
|
|
2016-02-09 18:43:00 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|