tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WebAuthnTransactionParent.h (2364B)


      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_WebAuthnTransactionParent_h
      8 #define mozilla_dom_WebAuthnTransactionParent_h
      9 
     10 #include "mozilla/RandomNum.h"
     11 #include "mozilla/dom/PWebAuthnTransactionParent.h"
     12 #include "mozilla/dom/WebAuthnPromiseHolder.h"
     13 #include "nsIWebAuthnService.h"
     14 
     15 /*
     16 * Parent process IPC implementation for WebAuthn.
     17 */
     18 
     19 namespace mozilla::dom {
     20 
     21 class WebAuthnRegisterPromiseHolder;
     22 class WebAuthnSignPromiseHolder;
     23 
     24 class WebAuthnTransactionParent final : public PWebAuthnTransactionParent {
     25  NS_INLINE_DECL_REFCOUNTING(WebAuthnTransactionParent, override);
     26 
     27 public:
     28  WebAuthnTransactionParent() = default;
     29 
     30  mozilla::ipc::IPCResult RecvRequestRegister(
     31      const WebAuthnMakeCredentialInfo& aTransactionInfo,
     32      RequestRegisterResolver&& aResolver);
     33 
     34  mozilla::ipc::IPCResult RecvRequestSign(
     35      const WebAuthnGetAssertionInfo& aTransactionInfo,
     36      RequestSignResolver&& aResolver);
     37 
     38  mozilla::ipc::IPCResult RecvRequestCancel();
     39 
     40  mozilla::ipc::IPCResult RecvRequestIsUVPAA(
     41      RequestIsUVPAAResolver&& aResolver);
     42 
     43  mozilla::ipc::IPCResult RecvDestroyMe();
     44 
     45  virtual void ActorDestroy(ActorDestroyReason aWhy) override;
     46 
     47 private:
     48  ~WebAuthnTransactionParent() = default;
     49 
     50  void CompleteTransaction();
     51  void DisconnectTransaction();
     52 
     53  nsCOMPtr<nsIWebAuthnService> mWebAuthnService;
     54  Maybe<uint64_t> mTransactionId;
     55  MozPromiseRequestHolder<WebAuthnRegisterPromise> mRegisterPromiseRequest;
     56  MozPromiseRequestHolder<WebAuthnSignPromise> mSignPromiseRequest;
     57 
     58  // Generates a probabilistically unique ID for the new transaction. IDs are 53
     59  // bits, as they are used in javascript. We use a random value if possible,
     60  // otherwise a counter.
     61  static uint64_t NextId() {
     62    static uint64_t counter = 0;
     63    Maybe<uint64_t> rand = mozilla::RandomUint64();
     64    uint64_t id =
     65        rand.valueOr(++counter) & UINT64_C(0x1fffffffffffff);  // 2^53 - 1
     66    // The transaction ID 0 is reserved.
     67    return id ? id : 1;
     68  }
     69 };
     70 
     71 }  // namespace mozilla::dom
     72 
     73 #endif  // mozilla_dom_WebAuthnTransactionParent_h