security/manager/ssl/src/nsCertTree.h

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef _NS_CERTTREE_H_
michael@0 6 #define _NS_CERTTREE_H_
michael@0 7
michael@0 8 #include "nsCOMPtr.h"
michael@0 9 #include "nsIServiceManager.h"
michael@0 10 #include "nsICertTree.h"
michael@0 11 #include "nsITreeView.h"
michael@0 12 #include "nsITreeBoxObject.h"
michael@0 13 #include "nsITreeSelection.h"
michael@0 14 #include "nsIMutableArray.h"
michael@0 15 #include "nsNSSComponent.h"
michael@0 16 #include "nsTArray.h"
michael@0 17 #include "pldhash.h"
michael@0 18 #include "nsIX509CertDB.h"
michael@0 19 #include "nsCertOverrideService.h"
michael@0 20 #include "mozilla/Attributes.h"
michael@0 21
michael@0 22 typedef struct treeArrayElStr treeArrayEl;
michael@0 23
michael@0 24 struct CompareCacheHashEntry {
michael@0 25 enum { max_criterions = 3 };
michael@0 26 CompareCacheHashEntry();
michael@0 27
michael@0 28 void *key; // no ownership
michael@0 29 bool mCritInit[max_criterions];
michael@0 30 nsXPIDLString mCrit[max_criterions];
michael@0 31 };
michael@0 32
michael@0 33 struct CompareCacheHashEntryPtr : PLDHashEntryHdr {
michael@0 34 CompareCacheHashEntryPtr();
michael@0 35 ~CompareCacheHashEntryPtr();
michael@0 36 CompareCacheHashEntry *entry;
michael@0 37 };
michael@0 38
michael@0 39 class nsCertAddonInfo MOZ_FINAL : public nsISupports
michael@0 40 {
michael@0 41 public:
michael@0 42 NS_DECL_ISUPPORTS
michael@0 43
michael@0 44 nsCertAddonInfo() : mUsageCount(0) {}
michael@0 45
michael@0 46 mozilla::RefPtr<nsIX509Cert> mCert;
michael@0 47 // how many display entries reference this?
michael@0 48 // (and therefore depend on the underlying cert)
michael@0 49 int32_t mUsageCount;
michael@0 50 };
michael@0 51
michael@0 52 class nsCertTreeDispInfo : public nsICertTreeItem
michael@0 53 {
michael@0 54 public:
michael@0 55 NS_DECL_ISUPPORTS
michael@0 56 NS_DECL_NSICERTTREEITEM
michael@0 57
michael@0 58 nsCertTreeDispInfo();
michael@0 59 nsCertTreeDispInfo(nsCertTreeDispInfo &other);
michael@0 60 virtual ~nsCertTreeDispInfo();
michael@0 61
michael@0 62 mozilla::RefPtr<nsCertAddonInfo> mAddonInfo;
michael@0 63 enum {
michael@0 64 direct_db, host_port_override
michael@0 65 } mTypeOfEntry;
michael@0 66 nsCString mAsciiHost;
michael@0 67 int32_t mPort;
michael@0 68 nsCertOverride::OverrideBits mOverrideBits;
michael@0 69 bool mIsTemporary;
michael@0 70 nsCOMPtr<nsIX509Cert> mCert;
michael@0 71 };
michael@0 72
michael@0 73 class nsCertTree : public nsICertTree
michael@0 74 {
michael@0 75 public:
michael@0 76 NS_DECL_ISUPPORTS
michael@0 77 NS_DECL_NSICERTTREE
michael@0 78 NS_DECL_NSITREEVIEW
michael@0 79
michael@0 80 nsCertTree();
michael@0 81 virtual ~nsCertTree();
michael@0 82
michael@0 83 enum sortCriterion { sort_IssuerOrg, sort_Org, sort_Token,
michael@0 84 sort_CommonName, sort_IssuedDateDescending, sort_Email, sort_None };
michael@0 85
michael@0 86 protected:
michael@0 87 nsresult InitCompareHash();
michael@0 88 void ClearCompareHash();
michael@0 89 void RemoveCacheEntry(void *key);
michael@0 90
michael@0 91 typedef int (*nsCertCompareFunc)(void *, nsIX509Cert *a, nsIX509Cert *b);
michael@0 92
michael@0 93 static CompareCacheHashEntry *getCacheEntry(void *cache, void *aCert);
michael@0 94 static void CmpInitCriterion(nsIX509Cert *cert, CompareCacheHashEntry *entry,
michael@0 95 sortCriterion crit, int32_t level);
michael@0 96 static int32_t CmpByCrit(nsIX509Cert *a, CompareCacheHashEntry *ace,
michael@0 97 nsIX509Cert *b, CompareCacheHashEntry *bce,
michael@0 98 sortCriterion crit, int32_t level);
michael@0 99 static int32_t CmpBy(void *cache, nsIX509Cert *a, nsIX509Cert *b,
michael@0 100 sortCriterion c0, sortCriterion c1, sortCriterion c2);
michael@0 101 static int32_t CmpCACert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
michael@0 102 static int32_t CmpWebSiteCert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
michael@0 103 static int32_t CmpUserCert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
michael@0 104 static int32_t CmpEmailCert(void *cache, nsIX509Cert *a, nsIX509Cert *b);
michael@0 105 nsCertCompareFunc GetCompareFuncFromCertType(uint32_t aType);
michael@0 106 int32_t CountOrganizations();
michael@0 107
michael@0 108 nsresult GetCertsByType(uint32_t aType, nsCertCompareFunc aCertCmpFn,
michael@0 109 void *aCertCmpFnArg);
michael@0 110
michael@0 111 nsresult GetCertsByTypeFromCache(nsINSSCertCache *aCache, uint32_t aType,
michael@0 112 nsCertCompareFunc aCertCmpFn, void *aCertCmpFnArg);
michael@0 113 private:
michael@0 114 nsTArray< mozilla::RefPtr<nsCertTreeDispInfo> > mDispInfo;
michael@0 115 nsCOMPtr<nsITreeBoxObject> mTree;
michael@0 116 nsCOMPtr<nsITreeSelection> mSelection;
michael@0 117 treeArrayEl *mTreeArray;
michael@0 118 int32_t mNumOrgs;
michael@0 119 int32_t mNumRows;
michael@0 120 PLDHashTable mCompareCache;
michael@0 121 nsCOMPtr<nsINSSComponent> mNSSComponent;
michael@0 122 nsCOMPtr<nsICertOverrideService> mOverrideService;
michael@0 123 mozilla::RefPtr<nsCertOverrideService> mOriginalOverrideService;
michael@0 124
michael@0 125 treeArrayEl *GetThreadDescAtIndex(int32_t _index);
michael@0 126 already_AddRefed<nsIX509Cert>
michael@0 127 GetCertAtIndex(int32_t _index, int32_t *outAbsoluteCertOffset = nullptr);
michael@0 128 mozilla::TemporaryRef<nsCertTreeDispInfo>
michael@0 129 GetDispInfoAtIndex(int32_t index, int32_t *outAbsoluteCertOffset = nullptr);
michael@0 130 void FreeCertArray();
michael@0 131 nsresult UpdateUIContents();
michael@0 132
michael@0 133 nsresult GetCertsByTypeFromCertList(CERTCertList *aCertList,
michael@0 134 uint32_t aType,
michael@0 135 nsCertCompareFunc aCertCmpFn,
michael@0 136 void *aCertCmpFnArg);
michael@0 137
michael@0 138 nsCOMPtr<nsIMutableArray> mCellText;
michael@0 139
michael@0 140 #ifdef DEBUG_CERT_TREE
michael@0 141 /* for debugging purposes */
michael@0 142 void dumpMap();
michael@0 143 #endif
michael@0 144 };
michael@0 145
michael@0 146 #endif /* _NS_CERTTREE_H_ */
michael@0 147

mercurial