|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef _nsNSSComponent_h_ |
|
8 #define _nsNSSComponent_h_ |
|
9 |
|
10 #include "mozilla/Mutex.h" |
|
11 #include "mozilla/RefPtr.h" |
|
12 #include "nsCOMPtr.h" |
|
13 #include "nsISignatureVerifier.h" |
|
14 #include "nsIEntropyCollector.h" |
|
15 #include "nsIStringBundle.h" |
|
16 #include "nsIObserver.h" |
|
17 #include "nsIObserverService.h" |
|
18 #ifndef MOZ_DISABLE_CRYPTOLEGACY |
|
19 #endif |
|
20 #include "nsINSSErrorsService.h" |
|
21 #include "nsNSSCallbacks.h" |
|
22 #include "ScopedNSSTypes.h" |
|
23 #include "SharedCertVerifier.h" |
|
24 #include "nsNSSHelper.h" |
|
25 #include "nsClientAuthRemember.h" |
|
26 #include "prerror.h" |
|
27 |
|
28 class nsIDOMWindow; |
|
29 class nsIPrompt; |
|
30 class SmartCardThreadList; |
|
31 |
|
32 namespace mozilla { namespace psm { |
|
33 |
|
34 MOZ_WARN_UNUSED_RESULT |
|
35 ::mozilla::TemporaryRef<mozilla::psm::SharedCertVerifier> |
|
36 GetDefaultCertVerifier(); |
|
37 |
|
38 } } // namespace mozilla::psm |
|
39 |
|
40 |
|
41 #define NS_NSSCOMPONENT_CID \ |
|
42 {0x4cb64dfd, 0xca98, 0x4e24, {0xbe, 0xfd, 0x0d, 0x92, 0x85, 0xa3, 0x3b, 0xcb}} |
|
43 |
|
44 #define PSM_COMPONENT_CONTRACTID "@mozilla.org/psm;1" |
|
45 |
|
46 //Define an interface that we can use to look up from the |
|
47 //callbacks passed to NSS. |
|
48 |
|
49 #define NS_INSSCOMPONENT_IID_STR "538c5093-7cfe-4f13-bc8e-e767766a2d4d" |
|
50 #define NS_INSSCOMPONENT_IID \ |
|
51 { 0x538c5093, 0x7cfe, 0x4f13, \ |
|
52 { 0xbc, 0x8e, 0xe7, 0x67, 0x76, 0x6a, 0x2d, 0x4d } } |
|
53 |
|
54 enum EnsureNSSOperator |
|
55 { |
|
56 nssLoadingComponent = 0, |
|
57 nssInitSucceeded = 1, |
|
58 nssInitFailed = 2, |
|
59 nssShutdown = 3, |
|
60 nssEnsure = 100, |
|
61 nssEnsureOnChromeOnly = 101 |
|
62 }; |
|
63 |
|
64 extern bool EnsureNSSInitialized(EnsureNSSOperator op); |
|
65 |
|
66 class nsNSSComponent; |
|
67 |
|
68 class NS_NO_VTABLE nsINSSComponent : public nsISupports { |
|
69 public: |
|
70 NS_DECLARE_STATIC_IID_ACCESSOR(NS_INSSCOMPONENT_IID) |
|
71 |
|
72 NS_IMETHOD ShowAlertFromStringBundle(const char* messageID) = 0; |
|
73 |
|
74 NS_IMETHOD GetPIPNSSBundleString(const char* name, |
|
75 nsAString& outString) = 0; |
|
76 NS_IMETHOD PIPBundleFormatStringFromName(const char* name, |
|
77 const char16_t** params, |
|
78 uint32_t numParams, |
|
79 nsAString& outString) = 0; |
|
80 |
|
81 NS_IMETHOD GetNSSBundleString(const char* name, |
|
82 nsAString& outString) = 0; |
|
83 NS_IMETHOD NSSBundleFormatStringFromName(const char* name, |
|
84 const char16_t** params, |
|
85 uint32_t numParams, |
|
86 nsAString& outString) = 0; |
|
87 |
|
88 NS_IMETHOD LogoutAuthenticatedPK11() = 0; |
|
89 |
|
90 #ifndef MOZ_DISABLE_CRYPTOLEGACY |
|
91 NS_IMETHOD LaunchSmartCardThread(SECMODModule* module) = 0; |
|
92 |
|
93 NS_IMETHOD ShutdownSmartCardThread(SECMODModule* module) = 0; |
|
94 |
|
95 NS_IMETHOD PostEvent(const nsAString& eventType, |
|
96 const nsAString& token) = 0; |
|
97 |
|
98 NS_IMETHOD DispatchEvent(const nsAString& eventType, |
|
99 const nsAString& token) = 0; |
|
100 #endif |
|
101 |
|
102 NS_IMETHOD IsNSSInitialized(bool* initialized) = 0; |
|
103 |
|
104 virtual ::mozilla::TemporaryRef<mozilla::psm::SharedCertVerifier> |
|
105 GetDefaultCertVerifier() = 0; |
|
106 }; |
|
107 |
|
108 NS_DEFINE_STATIC_IID_ACCESSOR(nsINSSComponent, NS_INSSCOMPONENT_IID) |
|
109 |
|
110 class nsNSSShutDownList; |
|
111 class nsCertVerificationThread; |
|
112 |
|
113 // Implementation of the PSM component interface. |
|
114 class nsNSSComponent : public nsISignatureVerifier, |
|
115 public nsIEntropyCollector, |
|
116 public nsINSSComponent, |
|
117 public nsIObserver, |
|
118 public nsSupportsWeakReference |
|
119 { |
|
120 typedef mozilla::Mutex Mutex; |
|
121 |
|
122 public: |
|
123 NS_DEFINE_STATIC_CID_ACCESSOR( NS_NSSCOMPONENT_CID ) |
|
124 |
|
125 nsNSSComponent(); |
|
126 virtual ~nsNSSComponent(); |
|
127 |
|
128 NS_DECL_THREADSAFE_ISUPPORTS |
|
129 NS_DECL_NSISIGNATUREVERIFIER |
|
130 NS_DECL_NSIENTROPYCOLLECTOR |
|
131 NS_DECL_NSIOBSERVER |
|
132 |
|
133 NS_METHOD Init(); |
|
134 |
|
135 static nsresult GetNewPrompter(nsIPrompt** result); |
|
136 static nsresult ShowAlertWithConstructedString(const nsString& message); |
|
137 NS_IMETHOD ShowAlertFromStringBundle(const char* messageID); |
|
138 |
|
139 NS_IMETHOD GetPIPNSSBundleString(const char* name, |
|
140 nsAString& outString); |
|
141 NS_IMETHOD PIPBundleFormatStringFromName(const char* name, |
|
142 const char16_t** params, |
|
143 uint32_t numParams, |
|
144 nsAString& outString); |
|
145 NS_IMETHOD GetNSSBundleString(const char* name, nsAString& outString); |
|
146 NS_IMETHOD NSSBundleFormatStringFromName(const char* name, |
|
147 const char16_t** params, |
|
148 uint32_t numParams, |
|
149 nsAString& outString); |
|
150 NS_IMETHOD LogoutAuthenticatedPK11(); |
|
151 |
|
152 #ifndef MOZ_DISABLE_CRYPTOLEGACY |
|
153 NS_IMETHOD LaunchSmartCardThread(SECMODModule* module); |
|
154 NS_IMETHOD ShutdownSmartCardThread(SECMODModule* module); |
|
155 NS_IMETHOD PostEvent(const nsAString& eventType, const nsAString& token); |
|
156 NS_IMETHOD DispatchEvent(const nsAString& eventType, const nsAString& token); |
|
157 void LaunchSmartCardThreads(); |
|
158 void ShutdownSmartCardThreads(); |
|
159 nsresult DispatchEventToWindow(nsIDOMWindow* domWin, |
|
160 const nsAString& eventType, |
|
161 const nsAString& token); |
|
162 #endif |
|
163 |
|
164 NS_IMETHOD IsNSSInitialized(bool* initialized); |
|
165 |
|
166 ::mozilla::TemporaryRef<mozilla::psm::SharedCertVerifier> |
|
167 GetDefaultCertVerifier() MOZ_OVERRIDE; |
|
168 |
|
169 private: |
|
170 nsresult InitializeNSS(); |
|
171 void ShutdownNSS(); |
|
172 |
|
173 void LoadLoadableRoots(); |
|
174 void UnloadLoadableRoots(); |
|
175 void setValidationOptions(bool isInitialSetting, |
|
176 const mozilla::MutexAutoLock& lock); |
|
177 nsresult setEnabledTLSVersions(); |
|
178 nsresult InitializePIPNSSBundle(); |
|
179 nsresult ConfigureInternalPKCS11Token(); |
|
180 nsresult RegisterObservers(); |
|
181 nsresult DeregisterObservers(); |
|
182 |
|
183 // Methods that we use to handle the profile change notifications (and to |
|
184 // synthesize a full profile change when we're just doing a profile startup): |
|
185 void DoProfileChangeNetTeardown(); |
|
186 void DoProfileChangeTeardown(nsISupports* aSubject); |
|
187 void DoProfileBeforeChange(nsISupports* aSubject); |
|
188 void DoProfileChangeNetRestore(); |
|
189 |
|
190 Mutex mutex; |
|
191 |
|
192 nsCOMPtr<nsIStringBundle> mPIPNSSBundle; |
|
193 nsCOMPtr<nsIStringBundle> mNSSErrorsBundle; |
|
194 bool mNSSInitialized; |
|
195 bool mObserversRegistered; |
|
196 static int mInstanceCount; |
|
197 nsNSSShutDownList* mShutdownObjectList; |
|
198 #ifndef MOZ_DISABLE_CRYPTOLEGACY |
|
199 SmartCardThreadList* mThreadList; |
|
200 #endif |
|
201 bool mIsNetworkDown; |
|
202 |
|
203 void deleteBackgroundThreads(); |
|
204 void createBackgroundThreads(); |
|
205 nsCertVerificationThread* mCertVerificationThread; |
|
206 |
|
207 nsNSSHttpInterface mHttpForNSS; |
|
208 mozilla::RefPtr<mozilla::psm::SharedCertVerifier> mDefaultCertVerifier; |
|
209 |
|
210 |
|
211 static PRStatus IdentityInfoInit(void); |
|
212 }; |
|
213 |
|
214 class nsNSSErrors |
|
215 { |
|
216 public: |
|
217 static const char* getDefaultErrorStringName(PRErrorCode err); |
|
218 static const char* getOverrideErrorStringName(PRErrorCode aErrorCode); |
|
219 static nsresult getErrorMessageFromCode(PRErrorCode err, |
|
220 nsINSSComponent* component, |
|
221 nsString& returnedMessage); |
|
222 }; |
|
223 |
|
224 class nsPSMInitPanic |
|
225 { |
|
226 private: |
|
227 static bool isPanic; |
|
228 public: |
|
229 static void SetPanic() {isPanic = true;} |
|
230 static bool GetPanic() {return isPanic;} |
|
231 }; |
|
232 |
|
233 #endif // _nsNSSComponent_h_ |