tor-browser

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

nsClientAuthRemember.h (2553B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      2 *
      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 __NSCLIENTAUTHREMEMBER_H__
      8 #define __NSCLIENTAUTHREMEMBER_H__
      9 
     10 #include "mozilla/DataMutex.h"
     11 #include "mozilla/ReentrantMonitor.h"
     12 #include "nsIClientAuthRememberService.h"
     13 #include "nsIDataStorage.h"
     14 #include "nsIObserver.h"
     15 #include "nsNSSCertificate.h"
     16 #include "nsString.h"
     17 #include "nsTHashtable.h"
     18 #include "nsWeakReference.h"
     19 
     20 namespace mozilla {
     21 class OriginAttributes;
     22 }
     23 
     24 using mozilla::OriginAttributes;
     25 
     26 class nsClientAuthRemember final : public nsIClientAuthRememberRecord {
     27 public:
     28  NS_DECL_THREADSAFE_ISUPPORTS
     29  NS_DECL_NSICLIENTAUTHREMEMBERRECORD
     30 
     31  nsClientAuthRemember(const nsACString& aHostName,
     32                       const OriginAttributes& aOriginAttributes) {
     33    mAsciiHost.Assign(aHostName);
     34    aOriginAttributes.CreateSuffix(mOriginAttributesSuffix);
     35  }
     36 
     37  nsClientAuthRemember(const nsCString& aEntryKey, const nsCString& aDBKey) {
     38    if (!aDBKey.Equals(nsClientAuthRemember::SentinelValue)) {
     39      mDBKey = aDBKey;
     40    }
     41 
     42    size_t field_index = 0;
     43    for (const auto& field : aEntryKey.Split(',')) {
     44      switch (field_index) {
     45        case 0:
     46          mAsciiHost.Assign(field);
     47          break;
     48        case 1:
     49          break;
     50        case 2:
     51          mOriginAttributesSuffix.Assign(field);
     52          break;
     53        default:
     54          break;
     55      }
     56      field_index++;
     57    }
     58  }
     59 
     60  nsCString mAsciiHost;
     61  nsCString mOriginAttributesSuffix;
     62  nsCString mDBKey;
     63  static constexpr nsLiteralCString SentinelValue = "no client certificate"_ns;
     64 
     65 protected:
     66  ~nsClientAuthRemember() = default;
     67 };
     68 
     69 class nsClientAuthRememberService final : public nsIClientAuthRememberService {
     70 public:
     71  NS_DECL_THREADSAFE_ISUPPORTS
     72  NS_DECL_NSICLIENTAUTHREMEMBERSERVICE
     73 
     74  nsClientAuthRememberService()
     75      : mMigrated(false, "nsClientAuthRememberService::mMigrated") {}
     76 
     77  nsresult Init();
     78 
     79  static bool IsPrivateBrowsingKey(const nsCString& entryKey);
     80 
     81 protected:
     82  ~nsClientAuthRememberService() = default;
     83 
     84  nsCOMPtr<nsIDataStorage> mClientAuthRememberList;
     85 
     86  nsresult AddEntryToList(const nsACString& aHost,
     87                          const OriginAttributes& aOriginAttributes,
     88                          const nsACString& aDBKey, Duration aDuration);
     89 
     90  mozilla::DataMutex<bool> mMigrated;
     91  void Migrate();
     92 };
     93 
     94 #endif