CertBlocklist.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef CertBlocklist_h
  6. #define CertBlocklist_h
  7. #include "mozilla/Mutex.h"
  8. #include "nsClassHashtable.h"
  9. #include "nsCOMPtr.h"
  10. #include "nsICertBlocklist.h"
  11. #include "nsIOutputStream.h"
  12. #include "nsTHashtable.h"
  13. #include "nsIX509CertDB.h"
  14. #include "pkix/Input.h"
  15. #define NS_CERT_BLOCKLIST_CID \
  16. {0x11aefd53, 0x2fbb, 0x4c92, {0xa0, 0xc1, 0x05, 0x32, 0x12, 0xae, 0x42, 0xd0} }
  17. enum CertBlocklistItemMechanism {
  18. BlockByIssuerAndSerial,
  19. BlockBySubjectAndPubKey
  20. };
  21. enum CertBlocklistItemState {
  22. CertNewFromBlocklist,
  23. CertOldFromLocalCache
  24. };
  25. class CertBlocklistItem
  26. {
  27. public:
  28. CertBlocklistItem(const uint8_t* DNData, size_t DNLength,
  29. const uint8_t* otherData, size_t otherLength,
  30. CertBlocklistItemMechanism itemMechanism);
  31. CertBlocklistItem(const CertBlocklistItem& aItem);
  32. ~CertBlocklistItem();
  33. nsresult ToBase64(nsACString& b64IssuerOut, nsACString& b64SerialOut);
  34. bool operator==(const CertBlocklistItem& aItem) const;
  35. uint32_t Hash() const;
  36. bool mIsCurrent;
  37. CertBlocklistItemMechanism mItemMechanism;
  38. private:
  39. size_t mDNLength;
  40. uint8_t* mDNData;
  41. size_t mOtherLength;
  42. uint8_t* mOtherData;
  43. };
  44. typedef nsGenericHashKey<CertBlocklistItem> BlocklistItemKey;
  45. typedef nsTHashtable<BlocklistItemKey> BlocklistTable;
  46. typedef nsTHashtable<nsCStringHashKey> BlocklistStringSet;
  47. typedef nsClassHashtable<nsCStringHashKey, BlocklistStringSet> IssuerTable;
  48. class CertBlocklist : public nsICertBlocklist
  49. {
  50. public:
  51. NS_DECL_THREADSAFE_ISUPPORTS
  52. NS_DECL_NSICERTBLOCKLIST
  53. CertBlocklist();
  54. nsresult Init();
  55. private:
  56. BlocklistTable mBlocklist;
  57. nsresult AddRevokedCertInternal(const nsACString& aEncodedDN,
  58. const nsACString& aEncodedOther,
  59. CertBlocklistItemMechanism aMechanism,
  60. CertBlocklistItemState aItemState,
  61. mozilla::MutexAutoLock& /*proofOfLock*/);
  62. mozilla::Mutex mMutex;
  63. bool mModified;
  64. bool mBackingFileIsInitialized;
  65. // call EnsureBackingFileInitialized before operations that read or
  66. // modify CertBlocklist data
  67. nsresult EnsureBackingFileInitialized(mozilla::MutexAutoLock& lock);
  68. nsCOMPtr<nsIFile> mBackingFile;
  69. protected:
  70. static void PreferenceChanged(const char* aPref, void* aClosure);
  71. static uint32_t sLastBlocklistUpdate;
  72. static uint32_t sMaxStaleness;
  73. virtual ~CertBlocklist();
  74. };
  75. #endif // CertBlocklist_h