michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsNSSCertCache.h" michael@0: #include "nsNSSCertificate.h" michael@0: #include "cert.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIInterfaceRequestor.h" michael@0: #include "nsNSSHelper.h" michael@0: michael@0: using namespace mozilla; michael@0: michael@0: NS_IMPL_ISUPPORTS(nsNSSCertCache, nsINSSCertCache) michael@0: michael@0: nsNSSCertCache::nsNSSCertCache() michael@0: :mutex("nsNSSCertCache.mutex"), mCertList(nullptr) michael@0: { michael@0: } michael@0: michael@0: nsNSSCertCache::~nsNSSCertCache() michael@0: { michael@0: nsNSSShutDownPreventionLock locker; michael@0: if (isAlreadyShutDown()) { michael@0: return; michael@0: } michael@0: destructorSafeDestroyNSSReference(); michael@0: shutdown(calledFromObject); michael@0: } michael@0: michael@0: void nsNSSCertCache::virtualDestroyNSSReference() michael@0: { michael@0: destructorSafeDestroyNSSReference(); michael@0: } michael@0: michael@0: void nsNSSCertCache::destructorSafeDestroyNSSReference() michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsNSSCertCache::CacheAllCerts() michael@0: { michael@0: nsNSSShutDownPreventionLock locker; michael@0: if (isAlreadyShutDown()) michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: michael@0: nsCOMPtr cxt = new PipUIContext(); michael@0: michael@0: mozilla::pkix::ScopedCERTCertList newList( michael@0: PK11_ListCerts(PK11CertListUnique, cxt)); michael@0: michael@0: if (newList) { michael@0: MutexAutoLock lock(mutex); michael@0: mCertList = new nsNSSCertList(newList, locker); michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsNSSCertCache::CacheCertList(nsIX509CertList *list) michael@0: { michael@0: nsNSSShutDownPreventionLock locker; michael@0: if (isAlreadyShutDown()) michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: michael@0: { michael@0: MutexAutoLock lock(mutex); michael@0: mCertList = list; michael@0: //NS_ADDREF(mCertList); michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsNSSCertCache::GetX509CachedCerts(nsIX509CertList **list) michael@0: { michael@0: nsNSSShutDownPreventionLock locker; michael@0: if (isAlreadyShutDown()) michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: michael@0: { michael@0: MutexAutoLock lock(mutex); michael@0: if (!mCertList) { michael@0: return NS_ERROR_NOT_AVAILABLE; michael@0: } michael@0: *list = mCertList; michael@0: NS_ADDREF(*list); michael@0: } michael@0: michael@0: return NS_OK; michael@0: } michael@0: michael@0: michael@0: michael@0: void* nsNSSCertCache::GetCachedCerts() michael@0: { michael@0: if (isAlreadyShutDown()) michael@0: return nullptr; michael@0: michael@0: MutexAutoLock lock(mutex); michael@0: return mCertList->GetRawCertList(); michael@0: }