2017-04-20 03:46:08 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_WebAuthnManager_h
|
|
|
|
#define mozilla_dom_WebAuthnManager_h
|
|
|
|
|
|
|
|
#include "mozilla/MozPromise.h"
|
2017-08-04 22:34:18 +03:00
|
|
|
#include "mozilla/dom/Event.h"
|
2017-04-20 03:46:08 +03:00
|
|
|
#include "mozilla/dom/PWebAuthnTransaction.h"
|
2017-08-04 22:34:18 +03:00
|
|
|
#include "nsIDOMEventListener.h"
|
2017-05-23 03:09:49 +03:00
|
|
|
#include "nsIIPCBackgroundChildCreateCallback.h"
|
2017-04-20 03:46:08 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Content process manager for the WebAuthn protocol. Created on calls to the
|
|
|
|
* WebAuthentication DOM object, this manager handles establishing IPC channels
|
|
|
|
* for WebAuthn transactions, as well as keeping track of JS Promise objects
|
|
|
|
* representing transactions in flight.
|
|
|
|
*
|
|
|
|
* The WebAuthn spec (https://www.w3.org/TR/webauthn/) allows for two different
|
|
|
|
* types of transactions: registration and signing. When either of these is
|
|
|
|
* requested via the DOM API, the following steps are executed in the
|
|
|
|
* WebAuthnManager:
|
|
|
|
*
|
|
|
|
* - Validation of the request. Return a failed promise to js if request does
|
|
|
|
* not have correct parameters.
|
|
|
|
*
|
|
|
|
* - If request is valid, open a new IPC channel for running the transaction. If
|
|
|
|
* another transaction is already running in this content process, cancel it.
|
|
|
|
* Return a pending promise to js.
|
|
|
|
*
|
|
|
|
* - Send transaction information to parent process (by running the Start*
|
|
|
|
* functions of WebAuthnManager). Assuming another transaction is currently in
|
|
|
|
* flight in another content process, parent will handle canceling it.
|
|
|
|
*
|
|
|
|
* - On return of successful transaction information from parent process, turn
|
|
|
|
* information into DOM object format required by spec, and resolve promise
|
|
|
|
* (by running the Finish* functions of WebAuthnManager). On cancellation
|
|
|
|
* request from parent, reject promise with corresponding error code. Either
|
|
|
|
* outcome will also close the IPC channel.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-07-07 23:32:31 +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);
|
|
|
|
};
|
|
|
|
|
2017-04-20 03:46:08 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
struct Account;
|
|
|
|
class ArrayBufferViewOrArrayBuffer;
|
|
|
|
struct AssertionOptions;
|
|
|
|
class OwningArrayBufferViewOrArrayBuffer;
|
|
|
|
struct ScopedCredentialOptions;
|
|
|
|
struct ScopedCredentialParameters;
|
|
|
|
class Promise;
|
|
|
|
class WebAuthnTransactionChild;
|
|
|
|
class WebAuthnTransactionInfo;
|
|
|
|
|
2017-08-04 22:34:18 +03:00
|
|
|
class WebAuthnManager final : public nsIIPCBackgroundChildCreateCallback,
|
|
|
|
public nsIDOMEventListener
|
2017-04-20 03:46:08 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2017-08-04 22:34:18 +03:00
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
2017-04-20 03:46:08 +03:00
|
|
|
static WebAuthnManager* GetOrCreate();
|
|
|
|
static WebAuthnManager* Get();
|
|
|
|
|
|
|
|
void
|
2017-07-06 15:44:56 +03:00
|
|
|
FinishMakeCredential(nsTArray<uint8_t>& aRegBuffer);
|
2017-04-20 03:46:08 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
FinishGetAssertion(nsTArray<uint8_t>& aCredentialId,
|
|
|
|
nsTArray<uint8_t>& aSigBuffer);
|
|
|
|
|
|
|
|
void
|
|
|
|
Cancel(const nsresult& aError);
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
2017-05-23 03:09:49 +03:00
|
|
|
MakeCredential(nsPIDOMWindowInner* aParent,
|
|
|
|
const MakeCredentialOptions& aOptions);
|
2017-04-20 03:46:08 +03:00
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
GetAssertion(nsPIDOMWindowInner* aParent,
|
2017-05-24 00:55:10 +03:00
|
|
|
const PublicKeyCredentialRequestOptions& aOptions);
|
2017-04-20 03:46:08 +03:00
|
|
|
|
|
|
|
void StartRegister();
|
|
|
|
void StartSign();
|
2017-08-04 22:34:18 +03:00
|
|
|
void StartCancel();
|
2017-04-20 03:46:08 +03:00
|
|
|
|
|
|
|
// nsIIPCbackgroundChildCreateCallback methods
|
|
|
|
void ActorCreated(PBackgroundChild* aActor) override;
|
|
|
|
void ActorFailed() override;
|
|
|
|
void ActorDestroyed();
|
|
|
|
private:
|
|
|
|
WebAuthnManager();
|
|
|
|
virtual ~WebAuthnManager();
|
|
|
|
|
|
|
|
void MaybeClearTransaction();
|
|
|
|
|
2017-07-28 16:53:42 +03:00
|
|
|
typedef MozPromise<nsresult, nsresult, false> BackgroundActorPromise;
|
|
|
|
|
|
|
|
RefPtr<BackgroundActorPromise> GetOrCreateBackgroundActor();
|
2017-04-20 03:46:08 +03:00
|
|
|
|
|
|
|
// JS Promise representing transaction status.
|
|
|
|
RefPtr<Promise> mTransactionPromise;
|
|
|
|
|
|
|
|
// IPC Channel for the current transaction.
|
|
|
|
RefPtr<WebAuthnTransactionChild> mChild;
|
|
|
|
|
|
|
|
// Parent of the context we're currently running the transaction in.
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mCurrentParent;
|
|
|
|
|
|
|
|
// Client data, stored on successful transaction creation, so that it can be
|
|
|
|
// used to assemble reply objects.
|
|
|
|
Maybe<nsCString> mClientData;
|
|
|
|
|
|
|
|
// Holds the parameters of the current transaction, as we need them both
|
|
|
|
// before the transaction request is sent, and on successful return.
|
|
|
|
Maybe<WebAuthnTransactionInfo> mInfo;
|
|
|
|
|
|
|
|
// Promise for dealing with PBackground Actor creation.
|
2017-07-28 16:53:42 +03:00
|
|
|
MozPromiseHolder<BackgroundActorPromise> mPBackgroundCreationPromise;
|
2017-04-20 03:46:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_WebAuthnManager_h
|