Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
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 "mozilla/dom/U2FTokenTransport.h"
11 :
12 : /*
13 : * Parent process manager for U2F and WebAuthn API transactions. Handles process
14 : * transactions from all content processes, make sure only one transaction is
15 : * live at any time. Manages access to hardware and software based key systems.
16 : *
17 : * U2FTokenManager is created on the first access to functions of either the U2F
18 : * or WebAuthn APIs that require key registration or signing. It lives until the
19 : * end of the browser process.
20 : */
21 :
22 : namespace mozilla {
23 : namespace dom {
24 :
25 : class U2FSoftTokenManager;
26 : class WebAuthnTransactionParent;
27 :
28 : class U2FTokenManager final
29 : {
30 : public:
31 : enum TransactionType
32 : {
33 : RegisterTransaction = 0,
34 : SignTransaction,
35 : NumTransactionTypes
36 : };
37 1 : NS_INLINE_DECL_REFCOUNTING(U2FTokenManager)
38 : static U2FTokenManager* Get();
39 : void Register(WebAuthnTransactionParent* aTransactionParent,
40 : const WebAuthnTransactionInfo& aTransactionInfo);
41 : void Sign(WebAuthnTransactionParent* aTransactionParent,
42 : const WebAuthnTransactionInfo& aTransactionInfo);
43 : void Cancel(WebAuthnTransactionParent* aTransactionParent);
44 : void MaybeClearTransaction(WebAuthnTransactionParent* aParent);
45 : static void Initialize();
46 : private:
47 : U2FTokenManager();
48 : ~U2FTokenManager();
49 : RefPtr<U2FTokenTransport> GetTokenManagerImpl();
50 : void AbortTransaction(const nsresult& aError);
51 : void ClearTransaction();
52 : void MaybeAbortTransaction(uint64_t aTransactionId,
53 : const nsresult& aError);
54 : void MaybeConfirmRegister(uint64_t aTransactionId,
55 : U2FRegisterResult& aResult);
56 : void MaybeConfirmSign(uint64_t aTransactionId, U2FSignResult& aResult);
57 : // Using a raw pointer here, as the lifetime of the IPC object is managed by
58 : // the PBackground protocol code. This means we cannot be left holding an
59 : // invalid IPC protocol object after the transaction is finished.
60 : WebAuthnTransactionParent* mTransactionParent;
61 : RefPtr<U2FTokenTransport> mTokenManagerImpl;
62 : RefPtr<U2FRegisterPromise> mRegisterPromise;
63 : RefPtr<U2FSignPromise> mSignPromise;
64 : // Guards the asynchronous promise resolution of token manager impls.
65 : // We don't need to protect this with a lock as it will only be modified
66 : // and checked on the PBackground thread in the parent process.
67 : uint64_t mTransactionId;
68 : };
69 :
70 : } // namespace dom
71 : } // namespace mozilla
72 :
73 : #endif // mozilla_dom_U2FTokenManager_h
|