security/manager/ssl/src/nsNSSCertCache.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/security/manager/ssl/src/nsNSSCertCache.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,104 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#include "nsNSSCertCache.h"
     1.9 +#include "nsNSSCertificate.h"
    1.10 +#include "cert.h"
    1.11 +#include "nsCOMPtr.h"
    1.12 +#include "nsIInterfaceRequestor.h"
    1.13 +#include "nsNSSHelper.h"
    1.14 +
    1.15 +using namespace mozilla;
    1.16 +
    1.17 +NS_IMPL_ISUPPORTS(nsNSSCertCache, nsINSSCertCache)
    1.18 +
    1.19 +nsNSSCertCache::nsNSSCertCache()
    1.20 +:mutex("nsNSSCertCache.mutex"), mCertList(nullptr)
    1.21 +{
    1.22 +}
    1.23 +
    1.24 +nsNSSCertCache::~nsNSSCertCache()
    1.25 +{
    1.26 +  nsNSSShutDownPreventionLock locker;
    1.27 +  if (isAlreadyShutDown()) {
    1.28 +    return;
    1.29 +  }
    1.30 +  destructorSafeDestroyNSSReference();
    1.31 +  shutdown(calledFromObject);
    1.32 +}
    1.33 +
    1.34 +void nsNSSCertCache::virtualDestroyNSSReference()
    1.35 +{
    1.36 +  destructorSafeDestroyNSSReference();
    1.37 +}
    1.38 +
    1.39 +void nsNSSCertCache::destructorSafeDestroyNSSReference()
    1.40 +{
    1.41 +}
    1.42 +
    1.43 +NS_IMETHODIMP
    1.44 +nsNSSCertCache::CacheAllCerts()
    1.45 +{
    1.46 +  nsNSSShutDownPreventionLock locker;
    1.47 +  if (isAlreadyShutDown())
    1.48 +    return NS_ERROR_NOT_AVAILABLE;
    1.49 +
    1.50 +  nsCOMPtr<nsIInterfaceRequestor> cxt = new PipUIContext();
    1.51 +  
    1.52 +  mozilla::pkix::ScopedCERTCertList newList(
    1.53 +    PK11_ListCerts(PK11CertListUnique, cxt));
    1.54 +
    1.55 +  if (newList) {
    1.56 +    MutexAutoLock lock(mutex);
    1.57 +    mCertList = new nsNSSCertList(newList, locker);
    1.58 +  }
    1.59 +  
    1.60 +  return NS_OK;
    1.61 +}
    1.62 +
    1.63 +NS_IMETHODIMP
    1.64 +nsNSSCertCache::CacheCertList(nsIX509CertList *list)
    1.65 +{
    1.66 +  nsNSSShutDownPreventionLock locker;
    1.67 +  if (isAlreadyShutDown())
    1.68 +    return NS_ERROR_NOT_AVAILABLE;
    1.69 +
    1.70 +  {
    1.71 +    MutexAutoLock lock(mutex);
    1.72 +    mCertList = list;
    1.73 +    //NS_ADDREF(mCertList);
    1.74 +  }
    1.75 +  
    1.76 +  return NS_OK;
    1.77 +}
    1.78 +
    1.79 +NS_IMETHODIMP
    1.80 +nsNSSCertCache::GetX509CachedCerts(nsIX509CertList **list)
    1.81 +{
    1.82 +  nsNSSShutDownPreventionLock locker;
    1.83 +  if (isAlreadyShutDown())
    1.84 +    return NS_ERROR_NOT_AVAILABLE;
    1.85 +
    1.86 +  {
    1.87 +    MutexAutoLock lock(mutex);
    1.88 +    if (!mCertList) {
    1.89 +      return NS_ERROR_NOT_AVAILABLE;
    1.90 +    }
    1.91 +    *list = mCertList;
    1.92 +    NS_ADDREF(*list);
    1.93 +  }
    1.94 +  
    1.95 +  return NS_OK;
    1.96 +}
    1.97 +
    1.98 +
    1.99 +
   1.100 +void* nsNSSCertCache::GetCachedCerts()
   1.101 +{
   1.102 +  if (isAlreadyShutDown())
   1.103 +    return nullptr;
   1.104 +
   1.105 +  MutexAutoLock lock(mutex);
   1.106 +  return mCertList->GetRawCertList();
   1.107 +}

mercurial