Bug 1702375 [wpt PR 28327] - Update docs to point directly at RuntimeEnabledFeatures...
[gecko.git] / dom / webauthn / U2FTokenManager.h
blob9ab06e828ff7e4a053ade7b2538b8f02cf39d2e7
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/. */
7 #ifndef mozilla_dom_U2FTokenManager_h
8 #define mozilla_dom_U2FTokenManager_h
10 #include "nsIU2FTokenManager.h"
11 #include "mozilla/dom/U2FTokenTransport.h"
12 #include "mozilla/dom/PWebAuthnTransaction.h"
13 #include "mozilla/Tainting.h"
16 * Parent process manager for U2F and WebAuthn API transactions. Handles process
17 * transactions from all content processes, make sure only one transaction is
18 * live at any time. Manages access to hardware and software based key systems.
20 * U2FTokenManager is created on the first access to functions of either the U2F
21 * or WebAuthn APIs that require key registration or signing. It lives until the
22 * end of the browser process.
25 namespace mozilla {
26 namespace dom {
28 class U2FSoftTokenManager;
29 class WebAuthnTransactionParent;
31 class U2FTokenManager final : public nsIU2FTokenManager {
32 public:
33 NS_DECL_THREADSAFE_ISUPPORTS
34 NS_DECL_NSIU2FTOKENMANAGER
36 static U2FTokenManager* Get();
37 void Register(PWebAuthnTransactionParent* aTransactionParent,
38 const uint64_t& aTransactionId,
39 const WebAuthnMakeCredentialInfo& aTransactionInfo);
40 void Sign(PWebAuthnTransactionParent* aTransactionParent,
41 const uint64_t& aTransactionId,
42 const WebAuthnGetAssertionInfo& aTransactionInfo);
43 void Cancel(PWebAuthnTransactionParent* aTransactionParent,
44 const Tainted<uint64_t>& aTransactionId);
45 void MaybeClearTransaction(PWebAuthnTransactionParent* aParent);
46 static void Initialize();
48 private:
49 U2FTokenManager();
50 ~U2FTokenManager() = default;
51 RefPtr<U2FTokenTransport> GetTokenManagerImpl();
52 void AbortTransaction(const uint64_t& aTransactionId, const nsresult& aError);
53 void AbortOngoingTransaction();
54 void ClearTransaction();
55 // Step two of "Register", kicking off the actual transaction.
56 void DoRegister(const WebAuthnMakeCredentialInfo& aInfo,
57 bool aForceNoneAttestation);
58 void MaybeConfirmRegister(const uint64_t& aTransactionId,
59 const WebAuthnMakeCredentialResult& aResult);
60 void MaybeAbortRegister(const uint64_t& aTransactionId,
61 const nsresult& aError);
62 void MaybeConfirmSign(const uint64_t& aTransactionId,
63 const WebAuthnGetAssertionResult& aResult);
64 void MaybeAbortSign(const uint64_t& aTransactionId, const nsresult& aError);
65 // The main thread runnable function for "nsIU2FTokenManager.ResumeRegister".
66 void RunResumeRegister(uint64_t aTransactionId, bool aForceNoneAttestation);
67 // The main thread runnable function for "nsIU2FTokenManager.Cancel".
68 void RunCancel(uint64_t aTransactionId);
69 // Sends a "webauthn-prompt" observer notification with the given data.
70 template <typename... T>
71 void SendPromptNotification(const char16_t* aFormat, T... aArgs);
72 // The main thread runnable function for "SendPromptNotification".
73 void RunSendPromptNotification(nsString aJSON);
74 // Using a raw pointer here, as the lifetime of the IPC object is managed by
75 // the PBackground protocol code. This means we cannot be left holding an
76 // invalid IPC protocol object after the transaction is finished.
77 PWebAuthnTransactionParent* mTransactionParent;
78 RefPtr<U2FTokenTransport> mTokenManagerImpl;
79 MozPromiseRequestHolder<U2FRegisterPromise> mRegisterPromise;
80 MozPromiseRequestHolder<U2FSignPromise> mSignPromise;
81 // The last transaction id, non-zero if there's an active transaction. This
82 // guards any cancel messages to ensure we don't cancel newer transactions
83 // due to a stale message.
84 uint64_t mLastTransactionId;
85 // Pending registration info while we wait for user input.
86 Maybe<WebAuthnMakeCredentialInfo> mPendingRegisterInfo;
89 } // namespace dom
90 } // namespace mozilla
92 #endif // mozilla_dom_U2FTokenManager_h