1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/manager/ssl/src/nsNSSComponent.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,233 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef _nsNSSComponent_h_ 1.11 +#define _nsNSSComponent_h_ 1.12 + 1.13 +#include "mozilla/Mutex.h" 1.14 +#include "mozilla/RefPtr.h" 1.15 +#include "nsCOMPtr.h" 1.16 +#include "nsISignatureVerifier.h" 1.17 +#include "nsIEntropyCollector.h" 1.18 +#include "nsIStringBundle.h" 1.19 +#include "nsIObserver.h" 1.20 +#include "nsIObserverService.h" 1.21 +#ifndef MOZ_DISABLE_CRYPTOLEGACY 1.22 +#endif 1.23 +#include "nsINSSErrorsService.h" 1.24 +#include "nsNSSCallbacks.h" 1.25 +#include "ScopedNSSTypes.h" 1.26 +#include "SharedCertVerifier.h" 1.27 +#include "nsNSSHelper.h" 1.28 +#include "nsClientAuthRemember.h" 1.29 +#include "prerror.h" 1.30 + 1.31 +class nsIDOMWindow; 1.32 +class nsIPrompt; 1.33 +class SmartCardThreadList; 1.34 + 1.35 +namespace mozilla { namespace psm { 1.36 + 1.37 +MOZ_WARN_UNUSED_RESULT 1.38 + ::mozilla::TemporaryRef<mozilla::psm::SharedCertVerifier> 1.39 + GetDefaultCertVerifier(); 1.40 + 1.41 +} } // namespace mozilla::psm 1.42 + 1.43 + 1.44 +#define NS_NSSCOMPONENT_CID \ 1.45 +{0x4cb64dfd, 0xca98, 0x4e24, {0xbe, 0xfd, 0x0d, 0x92, 0x85, 0xa3, 0x3b, 0xcb}} 1.46 + 1.47 +#define PSM_COMPONENT_CONTRACTID "@mozilla.org/psm;1" 1.48 + 1.49 +//Define an interface that we can use to look up from the 1.50 +//callbacks passed to NSS. 1.51 + 1.52 +#define NS_INSSCOMPONENT_IID_STR "538c5093-7cfe-4f13-bc8e-e767766a2d4d" 1.53 +#define NS_INSSCOMPONENT_IID \ 1.54 + { 0x538c5093, 0x7cfe, 0x4f13, \ 1.55 + { 0xbc, 0x8e, 0xe7, 0x67, 0x76, 0x6a, 0x2d, 0x4d } } 1.56 + 1.57 +enum EnsureNSSOperator 1.58 +{ 1.59 + nssLoadingComponent = 0, 1.60 + nssInitSucceeded = 1, 1.61 + nssInitFailed = 2, 1.62 + nssShutdown = 3, 1.63 + nssEnsure = 100, 1.64 + nssEnsureOnChromeOnly = 101 1.65 +}; 1.66 + 1.67 +extern bool EnsureNSSInitialized(EnsureNSSOperator op); 1.68 + 1.69 +class nsNSSComponent; 1.70 + 1.71 +class NS_NO_VTABLE nsINSSComponent : public nsISupports { 1.72 + public: 1.73 + NS_DECLARE_STATIC_IID_ACCESSOR(NS_INSSCOMPONENT_IID) 1.74 + 1.75 + NS_IMETHOD ShowAlertFromStringBundle(const char* messageID) = 0; 1.76 + 1.77 + NS_IMETHOD GetPIPNSSBundleString(const char* name, 1.78 + nsAString& outString) = 0; 1.79 + NS_IMETHOD PIPBundleFormatStringFromName(const char* name, 1.80 + const char16_t** params, 1.81 + uint32_t numParams, 1.82 + nsAString& outString) = 0; 1.83 + 1.84 + NS_IMETHOD GetNSSBundleString(const char* name, 1.85 + nsAString& outString) = 0; 1.86 + NS_IMETHOD NSSBundleFormatStringFromName(const char* name, 1.87 + const char16_t** params, 1.88 + uint32_t numParams, 1.89 + nsAString& outString) = 0; 1.90 + 1.91 + NS_IMETHOD LogoutAuthenticatedPK11() = 0; 1.92 + 1.93 +#ifndef MOZ_DISABLE_CRYPTOLEGACY 1.94 + NS_IMETHOD LaunchSmartCardThread(SECMODModule* module) = 0; 1.95 + 1.96 + NS_IMETHOD ShutdownSmartCardThread(SECMODModule* module) = 0; 1.97 + 1.98 + NS_IMETHOD PostEvent(const nsAString& eventType, 1.99 + const nsAString& token) = 0; 1.100 + 1.101 + NS_IMETHOD DispatchEvent(const nsAString& eventType, 1.102 + const nsAString& token) = 0; 1.103 +#endif 1.104 + 1.105 + NS_IMETHOD IsNSSInitialized(bool* initialized) = 0; 1.106 + 1.107 + virtual ::mozilla::TemporaryRef<mozilla::psm::SharedCertVerifier> 1.108 + GetDefaultCertVerifier() = 0; 1.109 +}; 1.110 + 1.111 +NS_DEFINE_STATIC_IID_ACCESSOR(nsINSSComponent, NS_INSSCOMPONENT_IID) 1.112 + 1.113 +class nsNSSShutDownList; 1.114 +class nsCertVerificationThread; 1.115 + 1.116 +// Implementation of the PSM component interface. 1.117 +class nsNSSComponent : public nsISignatureVerifier, 1.118 + public nsIEntropyCollector, 1.119 + public nsINSSComponent, 1.120 + public nsIObserver, 1.121 + public nsSupportsWeakReference 1.122 +{ 1.123 + typedef mozilla::Mutex Mutex; 1.124 + 1.125 +public: 1.126 + NS_DEFINE_STATIC_CID_ACCESSOR( NS_NSSCOMPONENT_CID ) 1.127 + 1.128 + nsNSSComponent(); 1.129 + virtual ~nsNSSComponent(); 1.130 + 1.131 + NS_DECL_THREADSAFE_ISUPPORTS 1.132 + NS_DECL_NSISIGNATUREVERIFIER 1.133 + NS_DECL_NSIENTROPYCOLLECTOR 1.134 + NS_DECL_NSIOBSERVER 1.135 + 1.136 + NS_METHOD Init(); 1.137 + 1.138 + static nsresult GetNewPrompter(nsIPrompt** result); 1.139 + static nsresult ShowAlertWithConstructedString(const nsString& message); 1.140 + NS_IMETHOD ShowAlertFromStringBundle(const char* messageID); 1.141 + 1.142 + NS_IMETHOD GetPIPNSSBundleString(const char* name, 1.143 + nsAString& outString); 1.144 + NS_IMETHOD PIPBundleFormatStringFromName(const char* name, 1.145 + const char16_t** params, 1.146 + uint32_t numParams, 1.147 + nsAString& outString); 1.148 + NS_IMETHOD GetNSSBundleString(const char* name, nsAString& outString); 1.149 + NS_IMETHOD NSSBundleFormatStringFromName(const char* name, 1.150 + const char16_t** params, 1.151 + uint32_t numParams, 1.152 + nsAString& outString); 1.153 + NS_IMETHOD LogoutAuthenticatedPK11(); 1.154 + 1.155 +#ifndef MOZ_DISABLE_CRYPTOLEGACY 1.156 + NS_IMETHOD LaunchSmartCardThread(SECMODModule* module); 1.157 + NS_IMETHOD ShutdownSmartCardThread(SECMODModule* module); 1.158 + NS_IMETHOD PostEvent(const nsAString& eventType, const nsAString& token); 1.159 + NS_IMETHOD DispatchEvent(const nsAString& eventType, const nsAString& token); 1.160 + void LaunchSmartCardThreads(); 1.161 + void ShutdownSmartCardThreads(); 1.162 + nsresult DispatchEventToWindow(nsIDOMWindow* domWin, 1.163 + const nsAString& eventType, 1.164 + const nsAString& token); 1.165 +#endif 1.166 + 1.167 + NS_IMETHOD IsNSSInitialized(bool* initialized); 1.168 + 1.169 + ::mozilla::TemporaryRef<mozilla::psm::SharedCertVerifier> 1.170 + GetDefaultCertVerifier() MOZ_OVERRIDE; 1.171 + 1.172 +private: 1.173 + nsresult InitializeNSS(); 1.174 + void ShutdownNSS(); 1.175 + 1.176 + void LoadLoadableRoots(); 1.177 + void UnloadLoadableRoots(); 1.178 + void setValidationOptions(bool isInitialSetting, 1.179 + const mozilla::MutexAutoLock& lock); 1.180 + nsresult setEnabledTLSVersions(); 1.181 + nsresult InitializePIPNSSBundle(); 1.182 + nsresult ConfigureInternalPKCS11Token(); 1.183 + nsresult RegisterObservers(); 1.184 + nsresult DeregisterObservers(); 1.185 + 1.186 + // Methods that we use to handle the profile change notifications (and to 1.187 + // synthesize a full profile change when we're just doing a profile startup): 1.188 + void DoProfileChangeNetTeardown(); 1.189 + void DoProfileChangeTeardown(nsISupports* aSubject); 1.190 + void DoProfileBeforeChange(nsISupports* aSubject); 1.191 + void DoProfileChangeNetRestore(); 1.192 + 1.193 + Mutex mutex; 1.194 + 1.195 + nsCOMPtr<nsIStringBundle> mPIPNSSBundle; 1.196 + nsCOMPtr<nsIStringBundle> mNSSErrorsBundle; 1.197 + bool mNSSInitialized; 1.198 + bool mObserversRegistered; 1.199 + static int mInstanceCount; 1.200 + nsNSSShutDownList* mShutdownObjectList; 1.201 +#ifndef MOZ_DISABLE_CRYPTOLEGACY 1.202 + SmartCardThreadList* mThreadList; 1.203 +#endif 1.204 + bool mIsNetworkDown; 1.205 + 1.206 + void deleteBackgroundThreads(); 1.207 + void createBackgroundThreads(); 1.208 + nsCertVerificationThread* mCertVerificationThread; 1.209 + 1.210 + nsNSSHttpInterface mHttpForNSS; 1.211 + mozilla::RefPtr<mozilla::psm::SharedCertVerifier> mDefaultCertVerifier; 1.212 + 1.213 + 1.214 + static PRStatus IdentityInfoInit(void); 1.215 +}; 1.216 + 1.217 +class nsNSSErrors 1.218 +{ 1.219 +public: 1.220 + static const char* getDefaultErrorStringName(PRErrorCode err); 1.221 + static const char* getOverrideErrorStringName(PRErrorCode aErrorCode); 1.222 + static nsresult getErrorMessageFromCode(PRErrorCode err, 1.223 + nsINSSComponent* component, 1.224 + nsString& returnedMessage); 1.225 +}; 1.226 + 1.227 +class nsPSMInitPanic 1.228 +{ 1.229 +private: 1.230 + static bool isPanic; 1.231 +public: 1.232 + static void SetPanic() {isPanic = true;} 1.233 + static bool GetPanic() {return isPanic;} 1.234 +}; 1.235 + 1.236 +#endif // _nsNSSComponent_h_