Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | #include "nsNSSCertCache.h" |
michael@0 | 6 | #include "nsNSSCertificate.h" |
michael@0 | 7 | #include "cert.h" |
michael@0 | 8 | #include "nsCOMPtr.h" |
michael@0 | 9 | #include "nsIInterfaceRequestor.h" |
michael@0 | 10 | #include "nsNSSHelper.h" |
michael@0 | 11 | |
michael@0 | 12 | using namespace mozilla; |
michael@0 | 13 | |
michael@0 | 14 | NS_IMPL_ISUPPORTS(nsNSSCertCache, nsINSSCertCache) |
michael@0 | 15 | |
michael@0 | 16 | nsNSSCertCache::nsNSSCertCache() |
michael@0 | 17 | :mutex("nsNSSCertCache.mutex"), mCertList(nullptr) |
michael@0 | 18 | { |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | nsNSSCertCache::~nsNSSCertCache() |
michael@0 | 22 | { |
michael@0 | 23 | nsNSSShutDownPreventionLock locker; |
michael@0 | 24 | if (isAlreadyShutDown()) { |
michael@0 | 25 | return; |
michael@0 | 26 | } |
michael@0 | 27 | destructorSafeDestroyNSSReference(); |
michael@0 | 28 | shutdown(calledFromObject); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | void nsNSSCertCache::virtualDestroyNSSReference() |
michael@0 | 32 | { |
michael@0 | 33 | destructorSafeDestroyNSSReference(); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | void nsNSSCertCache::destructorSafeDestroyNSSReference() |
michael@0 | 37 | { |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | NS_IMETHODIMP |
michael@0 | 41 | nsNSSCertCache::CacheAllCerts() |
michael@0 | 42 | { |
michael@0 | 43 | nsNSSShutDownPreventionLock locker; |
michael@0 | 44 | if (isAlreadyShutDown()) |
michael@0 | 45 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 46 | |
michael@0 | 47 | nsCOMPtr<nsIInterfaceRequestor> cxt = new PipUIContext(); |
michael@0 | 48 | |
michael@0 | 49 | mozilla::pkix::ScopedCERTCertList newList( |
michael@0 | 50 | PK11_ListCerts(PK11CertListUnique, cxt)); |
michael@0 | 51 | |
michael@0 | 52 | if (newList) { |
michael@0 | 53 | MutexAutoLock lock(mutex); |
michael@0 | 54 | mCertList = new nsNSSCertList(newList, locker); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | return NS_OK; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | NS_IMETHODIMP |
michael@0 | 61 | nsNSSCertCache::CacheCertList(nsIX509CertList *list) |
michael@0 | 62 | { |
michael@0 | 63 | nsNSSShutDownPreventionLock locker; |
michael@0 | 64 | if (isAlreadyShutDown()) |
michael@0 | 65 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 66 | |
michael@0 | 67 | { |
michael@0 | 68 | MutexAutoLock lock(mutex); |
michael@0 | 69 | mCertList = list; |
michael@0 | 70 | //NS_ADDREF(mCertList); |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | return NS_OK; |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | NS_IMETHODIMP |
michael@0 | 77 | nsNSSCertCache::GetX509CachedCerts(nsIX509CertList **list) |
michael@0 | 78 | { |
michael@0 | 79 | nsNSSShutDownPreventionLock locker; |
michael@0 | 80 | if (isAlreadyShutDown()) |
michael@0 | 81 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 82 | |
michael@0 | 83 | { |
michael@0 | 84 | MutexAutoLock lock(mutex); |
michael@0 | 85 | if (!mCertList) { |
michael@0 | 86 | return NS_ERROR_NOT_AVAILABLE; |
michael@0 | 87 | } |
michael@0 | 88 | *list = mCertList; |
michael@0 | 89 | NS_ADDREF(*list); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | return NS_OK; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | |
michael@0 | 96 | |
michael@0 | 97 | void* nsNSSCertCache::GetCachedCerts() |
michael@0 | 98 | { |
michael@0 | 99 | if (isAlreadyShutDown()) |
michael@0 | 100 | return nullptr; |
michael@0 | 101 | |
michael@0 | 102 | MutexAutoLock lock(mutex); |
michael@0 | 103 | return mCertList->GetRawCertList(); |
michael@0 | 104 | } |