/work/obj-fuzz/dist/include/mozilla/dom/U2FTokenManager.h
Line | Count | Source (jump to first uncovered line) |
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 | | { |
32 | | public: |
33 | | NS_DECL_THREADSAFE_ISUPPORTS |
34 | | NS_DECL_NSIU2FTOKENMANAGER |
35 | | |
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 uint64_t& aTransactionId); |
45 | | void MaybeClearTransaction(PWebAuthnTransactionParent* aParent); |
46 | | static void Initialize(); |
47 | | private: |
48 | | U2FTokenManager(); |
49 | 0 | ~U2FTokenManager() { } |
50 | | RefPtr<U2FTokenTransport> GetTokenManagerImpl(); |
51 | | void AbortTransaction(const uint64_t& aTransactionId, const nsresult& aError); |
52 | | void ClearTransaction(); |
53 | | // Step two of "Register", kicking off the actual transaction. |
54 | | void DoRegister(const WebAuthnMakeCredentialInfo& aInfo, |
55 | | bool aForceNoneAttestation); |
56 | | void MaybeConfirmRegister(const uint64_t& aTransactionId, |
57 | | const WebAuthnMakeCredentialResult& aResult); |
58 | | void MaybeAbortRegister(const uint64_t& aTransactionId, const nsresult& aError); |
59 | | void MaybeConfirmSign(const uint64_t& aTransactionId, |
60 | | const WebAuthnGetAssertionResult& aResult); |
61 | | void MaybeAbortSign(const uint64_t& aTransactionId, const nsresult& aError); |
62 | | // The main thread runnable function for "nsIU2FTokenManager.ResumeRegister". |
63 | | void RunResumeRegister(uint64_t aTransactionId, bool aForceNoneAttestation); |
64 | | // The main thread runnable function for "nsIU2FTokenManager.Cancel". |
65 | | void RunCancel(uint64_t aTransactionId); |
66 | | // Sends a "webauthn-prompt" observer notification with the given data. |
67 | | template<typename ...T> |
68 | | void SendPromptNotification(const char16_t* aFormat, T... aArgs); |
69 | | // The main thread runnable function for "SendPromptNotification". |
70 | | void RunSendPromptNotification(nsString aJSON); |
71 | | // Using a raw pointer here, as the lifetime of the IPC object is managed by |
72 | | // the PBackground protocol code. This means we cannot be left holding an |
73 | | // invalid IPC protocol object after the transaction is finished. |
74 | | PWebAuthnTransactionParent* mTransactionParent; |
75 | | RefPtr<U2FTokenTransport> mTokenManagerImpl; |
76 | | MozPromiseRequestHolder<U2FRegisterPromise> mRegisterPromise; |
77 | | MozPromiseRequestHolder<U2FSignPromise> mSignPromise; |
78 | | // The last transaction id, non-zero if there's an active transaction. This |
79 | | // guards any cancel messages to ensure we don't cancel newer transactions |
80 | | // due to a stale message. |
81 | | uint64_t mLastTransactionId; |
82 | | // Pending registration info while we wait for user input. |
83 | | Maybe<WebAuthnMakeCredentialInfo> mPendingRegisterInfo; |
84 | | }; |
85 | | |
86 | | } // namespace dom |
87 | | } // namespace mozilla |
88 | | |
89 | | #endif // mozilla_dom_U2FTokenManager_h |