Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_dom_U2FTokenManager_h
8
#define mozilla_dom_U2FTokenManager_h
9
10
#include "nsIU2FTokenManager.h"
11
#include "mozilla/dom/U2FTokenTransport.h"
12
#include "mozilla/dom/PWebAuthnTransaction.h"
13
14
/*
15
* Parent process manager for U2F and WebAuthn API transactions. Handles process
16
* transactions from all content processes, make sure only one transaction is
17
* live at any time. Manages access to hardware and software based key systems.
18
*
19
* U2FTokenManager is created on the first access to functions of either the U2F
20
* or WebAuthn APIs that require key registration or signing. It lives until the
21
* end of the browser process.
22
*/
23
24
namespace mozilla {
25
namespace dom {
26
27
class U2FSoftTokenManager;
28
class WebAuthnTransactionParent;
29
30
class U2FTokenManager final : public nsIU2FTokenManager {
31
public:
32
NS_DECL_THREADSAFE_ISUPPORTS
33
NS_DECL_NSIU2FTOKENMANAGER
34
35
static U2FTokenManager* Get();
36
void Register(PWebAuthnTransactionParent* aTransactionParent,
37
const uint64_t& aTransactionId,
38
const WebAuthnMakeCredentialInfo& aTransactionInfo);
39
void Sign(PWebAuthnTransactionParent* aTransactionParent,
40
const uint64_t& aTransactionId,
41
const WebAuthnGetAssertionInfo& aTransactionInfo);
42
void Cancel(PWebAuthnTransactionParent* aTransactionParent,
43
const uint64_t& aTransactionId);
44
void MaybeClearTransaction(PWebAuthnTransactionParent* aParent);
45
static void Initialize();
46
47
private:
48
U2FTokenManager();
49
~U2FTokenManager() {}
50
RefPtr<U2FTokenTransport> GetTokenManagerImpl();
51
void AbortTransaction(const uint64_t& aTransactionId, const nsresult& aError);
52
void AbortOngoingTransaction();
53
void ClearTransaction();
54
// Step two of "Register", kicking off the actual transaction.
55
void DoRegister(const WebAuthnMakeCredentialInfo& aInfo,
56
bool aForceNoneAttestation);
57
void MaybeConfirmRegister(const uint64_t& aTransactionId,
58
const WebAuthnMakeCredentialResult& aResult);
59
void MaybeAbortRegister(const uint64_t& aTransactionId,
60
const nsresult& aError);
61
void MaybeConfirmSign(const uint64_t& aTransactionId,
62
const WebAuthnGetAssertionResult& aResult);
63
void MaybeAbortSign(const uint64_t& aTransactionId, const nsresult& aError);
64
// The main thread runnable function for "nsIU2FTokenManager.ResumeRegister".
65
void RunResumeRegister(uint64_t aTransactionId, bool aForceNoneAttestation);
66
// The main thread runnable function for "nsIU2FTokenManager.Cancel".
67
void RunCancel(uint64_t aTransactionId);
68
// Sends a "webauthn-prompt" observer notification with the given data.
69
template <typename... T>
70
void SendPromptNotification(const char16_t* aFormat, T... aArgs);
71
// The main thread runnable function for "SendPromptNotification".
72
void RunSendPromptNotification(nsString aJSON);
73
// Using a raw pointer here, as the lifetime of the IPC object is managed by
74
// the PBackground protocol code. This means we cannot be left holding an
75
// invalid IPC protocol object after the transaction is finished.
76
PWebAuthnTransactionParent* mTransactionParent;
77
RefPtr<U2FTokenTransport> mTokenManagerImpl;
78
MozPromiseRequestHolder<U2FRegisterPromise> mRegisterPromise;
79
MozPromiseRequestHolder<U2FSignPromise> mSignPromise;
80
// The last transaction id, non-zero if there's an active transaction. This
81
// guards any cancel messages to ensure we don't cancel newer transactions
82
// due to a stale message.
83
uint64_t mLastTransactionId;
84
// Pending registration info while we wait for user input.
85
Maybe<WebAuthnMakeCredentialInfo> mPendingRegisterInfo;
86
};
87
88
} // namespace dom
89
} // namespace mozilla
90
91
#endif // mozilla_dom_U2FTokenManager_h