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