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.

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

mercurial