tor-browser

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

RTCCertificate.h (3334B)


      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_RTCCertificate_h
      8 #define mozilla_dom_RTCCertificate_h
      9 
     10 #include <cstdint>
     11 
     12 #include "ScopedNSSTypes.h"
     13 #include "certt.h"
     14 #include "js/RootingAPI.h"
     15 #include "keythi.h"
     16 #include "mozilla/AlreadyAddRefed.h"
     17 #include "mozilla/RefPtr.h"
     18 #include "nsCycleCollectionParticipant.h"
     19 #include "nsIGlobalObject.h"
     20 #include "nsISupports.h"
     21 #include "nsWrapperCache.h"
     22 #include "prtime.h"
     23 #include "sslt.h"
     24 
     25 class JSObject;
     26 struct JSContext;
     27 struct JSStructuredCloneReader;
     28 struct JSStructuredCloneWriter;
     29 
     30 namespace JS {
     31 class Compartment;
     32 }
     33 
     34 namespace mozilla {
     35 class DtlsIdentity;
     36 class ErrorResult;
     37 
     38 namespace dom {
     39 
     40 class GlobalObject;
     41 class ObjectOrString;
     42 class Promise;
     43 struct RTCDtlsFingerprint;
     44 
     45 class RTCCertificate final : public nsISupports, public nsWrapperCache {
     46 public:
     47  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     48  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(RTCCertificate)
     49 
     50  // WebIDL method that implements RTCPeerConnection.generateCertificate.
     51  static already_AddRefed<Promise> GenerateCertificate(
     52      const GlobalObject& aGlobal, const ObjectOrString& aOptions,
     53      ErrorResult& aRv, JS::Compartment* aCompartment = nullptr);
     54 
     55  explicit RTCCertificate(nsIGlobalObject* aGlobal);
     56  RTCCertificate(nsIGlobalObject* aGlobal, SECKEYPrivateKey* aPrivateKey,
     57                 CERTCertificate* aCertificate, SSLKEAType aAuthType,
     58                 PRTime aExpires);
     59 
     60  nsIGlobalObject* GetParentObject() const { return mGlobal; }
     61  virtual JSObject* WrapObject(JSContext* aCx,
     62                               JS::Handle<JSObject*> aGivenProto) override;
     63 
     64  // WebIDL expires attribute.  Note: JS dates are milliseconds since epoch;
     65  // NSPR PRTime is in microseconds since the same epoch.
     66  uint64_t Expires() const { return mExpires / PR_USEC_PER_MSEC; }
     67  void GetFingerprints(nsTArray<dom::RTCDtlsFingerprint>& aFingerprintsOut);
     68 
     69  // Accessors for use by PeerConnectionImpl.
     70  RefPtr<DtlsIdentity> CreateDtlsIdentity() const;
     71  const UniqueCERTCertificate& Certificate() const { return mCertificate; }
     72 
     73  // Structured clone methods
     74  bool WriteStructuredClone(JSContext* aCx,
     75                            JSStructuredCloneWriter* aWriter) const;
     76  static already_AddRefed<RTCCertificate> ReadStructuredClone(
     77      JSContext* aCx, nsIGlobalObject* aGlobal,
     78      JSStructuredCloneReader* aReader);
     79 
     80 private:
     81  ~RTCCertificate() = default;
     82  void operator=(const RTCCertificate&) = delete;
     83  RTCCertificate(const RTCCertificate&) = delete;
     84 
     85  bool ReadCertificate(JSStructuredCloneReader* aReader);
     86  bool ReadPrivateKey(JSStructuredCloneReader* aReader);
     87  bool WriteCertificate(JSStructuredCloneWriter* aWriter) const;
     88  bool WritePrivateKey(JSStructuredCloneWriter* aWriter) const;
     89 
     90  RefPtr<nsIGlobalObject> mGlobal;
     91  UniqueSECKEYPrivateKey mPrivateKey;
     92  UniqueCERTCertificate mCertificate;
     93  SSLKEAType mAuthType;
     94  PRTime mExpires;
     95  nsTArray<RTCDtlsFingerprint> mFingerprints;
     96 };
     97 
     98 }  // namespace dom
     99 }  // namespace mozilla
    100 
    101 #endif  // mozilla_dom_RTCCertificate_h