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