security/manager/ssl/src/nsNSSCertCache.cpp

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 #include "nsNSSCertCache.h"
     6 #include "nsNSSCertificate.h"
     7 #include "cert.h"
     8 #include "nsCOMPtr.h"
     9 #include "nsIInterfaceRequestor.h"
    10 #include "nsNSSHelper.h"
    12 using namespace mozilla;
    14 NS_IMPL_ISUPPORTS(nsNSSCertCache, nsINSSCertCache)
    16 nsNSSCertCache::nsNSSCertCache()
    17 :mutex("nsNSSCertCache.mutex"), mCertList(nullptr)
    18 {
    19 }
    21 nsNSSCertCache::~nsNSSCertCache()
    22 {
    23   nsNSSShutDownPreventionLock locker;
    24   if (isAlreadyShutDown()) {
    25     return;
    26   }
    27   destructorSafeDestroyNSSReference();
    28   shutdown(calledFromObject);
    29 }
    31 void nsNSSCertCache::virtualDestroyNSSReference()
    32 {
    33   destructorSafeDestroyNSSReference();
    34 }
    36 void nsNSSCertCache::destructorSafeDestroyNSSReference()
    37 {
    38 }
    40 NS_IMETHODIMP
    41 nsNSSCertCache::CacheAllCerts()
    42 {
    43   nsNSSShutDownPreventionLock locker;
    44   if (isAlreadyShutDown())
    45     return NS_ERROR_NOT_AVAILABLE;
    47   nsCOMPtr<nsIInterfaceRequestor> cxt = new PipUIContext();
    49   mozilla::pkix::ScopedCERTCertList newList(
    50     PK11_ListCerts(PK11CertListUnique, cxt));
    52   if (newList) {
    53     MutexAutoLock lock(mutex);
    54     mCertList = new nsNSSCertList(newList, locker);
    55   }
    57   return NS_OK;
    58 }
    60 NS_IMETHODIMP
    61 nsNSSCertCache::CacheCertList(nsIX509CertList *list)
    62 {
    63   nsNSSShutDownPreventionLock locker;
    64   if (isAlreadyShutDown())
    65     return NS_ERROR_NOT_AVAILABLE;
    67   {
    68     MutexAutoLock lock(mutex);
    69     mCertList = list;
    70     //NS_ADDREF(mCertList);
    71   }
    73   return NS_OK;
    74 }
    76 NS_IMETHODIMP
    77 nsNSSCertCache::GetX509CachedCerts(nsIX509CertList **list)
    78 {
    79   nsNSSShutDownPreventionLock locker;
    80   if (isAlreadyShutDown())
    81     return NS_ERROR_NOT_AVAILABLE;
    83   {
    84     MutexAutoLock lock(mutex);
    85     if (!mCertList) {
    86       return NS_ERROR_NOT_AVAILABLE;
    87     }
    88     *list = mCertList;
    89     NS_ADDREF(*list);
    90   }
    92   return NS_OK;
    93 }
    97 void* nsNSSCertCache::GetCachedCerts()
    98 {
    99   if (isAlreadyShutDown())
   100     return nullptr;
   102   MutexAutoLock lock(mutex);
   103   return mCertList->GetRawCertList();
   104 }

mercurial