author Nicholas Nethercote <>
Tue, 05 Nov 2019 00:14:28 +0000
changeset 500481 4d585c7edc7683e4b35eca6b18c9a646a1b8a78d
parent 465117 91403c24fee3d5df8fa978710785807b409d7af8
child 505803 1f438b01c7801e7d750c4297330669621d3b7a4f
permissions -rw-r--r--
Bug 1593426 - Fix a case missed in bug 1587162. r=erahm This code is compiled when `MOZ_NEW_CERT_STORAGE` is not defined, which is the case on beta. Differential Revision:

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */

#ifndef CertBlocklist_h
#define CertBlocklist_h

#include "mozilla/Mutex.h"
#include "nsCOMPtr.h"
#include "nsClassHashtable.h"
#include "nsICertBlocklist.h"
#include "nsIOutputStream.h"
#include "nsIX509CertDB.h"
#include "nsString.h"
#include "nsTHashtable.h"
#include "mozpkix/Input.h"

#define NS_CERT_BLOCKLIST_CID                        \
  {                                                  \
    0x11aefd53, 0x2fbb, 0x4c92, {                    \
      0xa0, 0xc1, 0x05, 0x32, 0x12, 0xae, 0x42, 0xd0 \
    }                                                \

enum CertBlocklistItemMechanism {

enum CertBlocklistItemState { CertNewFromBlocklist, CertOldFromLocalCache };

class CertBlocklistItem {
  CertBlocklistItem(const uint8_t* DNData, size_t DNLength,
                    const uint8_t* otherData, size_t otherLength,
                    CertBlocklistItemMechanism itemMechanism);
  CertBlocklistItem(const CertBlocklistItem& aItem);
  nsresult ToBase64(nsACString& b64IssuerOut, nsACString& b64SerialOut);
  bool operator==(const CertBlocklistItem& aItem) const;
  uint32_t Hash() const;
  bool mIsCurrent;
  CertBlocklistItemMechanism mItemMechanism;

  size_t mDNLength;
  uint8_t* mDNData;
  size_t mOtherLength;
  uint8_t* mOtherData;

typedef nsGenericHashKey<CertBlocklistItem> BlocklistItemKey;
typedef nsTHashtable<BlocklistItemKey> BlocklistTable;
typedef nsTHashtable<nsCStringHashKey> BlocklistStringSet;
typedef nsClassHashtable<nsCStringHashKey, BlocklistStringSet> IssuerTable;

class CertBlocklist : public nsICertBlocklist {
  nsresult Init();

  BlocklistTable mBlocklist;
  nsresult AddRevokedCertInternal(const nsACString& aEncodedDN,
                                  const nsACString& aEncodedOther,
                                  CertBlocklistItemMechanism aMechanism,
                                  CertBlocklistItemState aItemState,
                                  mozilla::MutexAutoLock& /*proofOfLock*/);
  mozilla::Mutex mMutex;
  bool mModified;
  bool mBackingFileIsInitialized;
  // call EnsureBackingFileInitialized before operations that read or
  // modify CertBlocklist data
  nsresult EnsureBackingFileInitialized(mozilla::MutexAutoLock& lock);
  nsCOMPtr<nsIFile> mBackingFile;

  static void PreferenceChanged(const char* aPref, void* aBlocklist);
  static uint32_t sLastBlocklistUpdate;
  static uint32_t sLastKintoUpdate;
  static uint32_t sMaxStaleness;
  static bool sUseAMO;
  virtual ~CertBlocklist();

#endif  // CertBlocklist_h