michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _nsNSSComponent_h_ michael@0: #define _nsNSSComponent_h_ michael@0: michael@0: #include "mozilla/Mutex.h" michael@0: #include "mozilla/RefPtr.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsISignatureVerifier.h" michael@0: #include "nsIEntropyCollector.h" michael@0: #include "nsIStringBundle.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsIObserverService.h" michael@0: #ifndef MOZ_DISABLE_CRYPTOLEGACY michael@0: #endif michael@0: #include "nsINSSErrorsService.h" michael@0: #include "nsNSSCallbacks.h" michael@0: #include "ScopedNSSTypes.h" michael@0: #include "SharedCertVerifier.h" michael@0: #include "nsNSSHelper.h" michael@0: #include "nsClientAuthRemember.h" michael@0: #include "prerror.h" michael@0: michael@0: class nsIDOMWindow; michael@0: class nsIPrompt; michael@0: class SmartCardThreadList; michael@0: michael@0: namespace mozilla { namespace psm { michael@0: michael@0: MOZ_WARN_UNUSED_RESULT michael@0: ::mozilla::TemporaryRef michael@0: GetDefaultCertVerifier(); michael@0: michael@0: } } // namespace mozilla::psm michael@0: michael@0: michael@0: #define NS_NSSCOMPONENT_CID \ michael@0: {0x4cb64dfd, 0xca98, 0x4e24, {0xbe, 0xfd, 0x0d, 0x92, 0x85, 0xa3, 0x3b, 0xcb}} michael@0: michael@0: #define PSM_COMPONENT_CONTRACTID "@mozilla.org/psm;1" michael@0: michael@0: //Define an interface that we can use to look up from the michael@0: //callbacks passed to NSS. michael@0: michael@0: #define NS_INSSCOMPONENT_IID_STR "538c5093-7cfe-4f13-bc8e-e767766a2d4d" michael@0: #define NS_INSSCOMPONENT_IID \ michael@0: { 0x538c5093, 0x7cfe, 0x4f13, \ michael@0: { 0xbc, 0x8e, 0xe7, 0x67, 0x76, 0x6a, 0x2d, 0x4d } } michael@0: michael@0: enum EnsureNSSOperator michael@0: { michael@0: nssLoadingComponent = 0, michael@0: nssInitSucceeded = 1, michael@0: nssInitFailed = 2, michael@0: nssShutdown = 3, michael@0: nssEnsure = 100, michael@0: nssEnsureOnChromeOnly = 101 michael@0: }; michael@0: michael@0: extern bool EnsureNSSInitialized(EnsureNSSOperator op); michael@0: michael@0: class nsNSSComponent; michael@0: michael@0: class NS_NO_VTABLE nsINSSComponent : public nsISupports { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_INSSCOMPONENT_IID) michael@0: michael@0: NS_IMETHOD ShowAlertFromStringBundle(const char* messageID) = 0; michael@0: michael@0: NS_IMETHOD GetPIPNSSBundleString(const char* name, michael@0: nsAString& outString) = 0; michael@0: NS_IMETHOD PIPBundleFormatStringFromName(const char* name, michael@0: const char16_t** params, michael@0: uint32_t numParams, michael@0: nsAString& outString) = 0; michael@0: michael@0: NS_IMETHOD GetNSSBundleString(const char* name, michael@0: nsAString& outString) = 0; michael@0: NS_IMETHOD NSSBundleFormatStringFromName(const char* name, michael@0: const char16_t** params, michael@0: uint32_t numParams, michael@0: nsAString& outString) = 0; michael@0: michael@0: NS_IMETHOD LogoutAuthenticatedPK11() = 0; michael@0: michael@0: #ifndef MOZ_DISABLE_CRYPTOLEGACY michael@0: NS_IMETHOD LaunchSmartCardThread(SECMODModule* module) = 0; michael@0: michael@0: NS_IMETHOD ShutdownSmartCardThread(SECMODModule* module) = 0; michael@0: michael@0: NS_IMETHOD PostEvent(const nsAString& eventType, michael@0: const nsAString& token) = 0; michael@0: michael@0: NS_IMETHOD DispatchEvent(const nsAString& eventType, michael@0: const nsAString& token) = 0; michael@0: #endif michael@0: michael@0: NS_IMETHOD IsNSSInitialized(bool* initialized) = 0; michael@0: michael@0: virtual ::mozilla::TemporaryRef michael@0: GetDefaultCertVerifier() = 0; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsINSSComponent, NS_INSSCOMPONENT_IID) michael@0: michael@0: class nsNSSShutDownList; michael@0: class nsCertVerificationThread; michael@0: michael@0: // Implementation of the PSM component interface. michael@0: class nsNSSComponent : public nsISignatureVerifier, michael@0: public nsIEntropyCollector, michael@0: public nsINSSComponent, michael@0: public nsIObserver, michael@0: public nsSupportsWeakReference michael@0: { michael@0: typedef mozilla::Mutex Mutex; michael@0: michael@0: public: michael@0: NS_DEFINE_STATIC_CID_ACCESSOR( NS_NSSCOMPONENT_CID ) michael@0: michael@0: nsNSSComponent(); michael@0: virtual ~nsNSSComponent(); michael@0: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSISIGNATUREVERIFIER michael@0: NS_DECL_NSIENTROPYCOLLECTOR michael@0: NS_DECL_NSIOBSERVER michael@0: michael@0: NS_METHOD Init(); michael@0: michael@0: static nsresult GetNewPrompter(nsIPrompt** result); michael@0: static nsresult ShowAlertWithConstructedString(const nsString& message); michael@0: NS_IMETHOD ShowAlertFromStringBundle(const char* messageID); michael@0: michael@0: NS_IMETHOD GetPIPNSSBundleString(const char* name, michael@0: nsAString& outString); michael@0: NS_IMETHOD PIPBundleFormatStringFromName(const char* name, michael@0: const char16_t** params, michael@0: uint32_t numParams, michael@0: nsAString& outString); michael@0: NS_IMETHOD GetNSSBundleString(const char* name, nsAString& outString); michael@0: NS_IMETHOD NSSBundleFormatStringFromName(const char* name, michael@0: const char16_t** params, michael@0: uint32_t numParams, michael@0: nsAString& outString); michael@0: NS_IMETHOD LogoutAuthenticatedPK11(); michael@0: michael@0: #ifndef MOZ_DISABLE_CRYPTOLEGACY michael@0: NS_IMETHOD LaunchSmartCardThread(SECMODModule* module); michael@0: NS_IMETHOD ShutdownSmartCardThread(SECMODModule* module); michael@0: NS_IMETHOD PostEvent(const nsAString& eventType, const nsAString& token); michael@0: NS_IMETHOD DispatchEvent(const nsAString& eventType, const nsAString& token); michael@0: void LaunchSmartCardThreads(); michael@0: void ShutdownSmartCardThreads(); michael@0: nsresult DispatchEventToWindow(nsIDOMWindow* domWin, michael@0: const nsAString& eventType, michael@0: const nsAString& token); michael@0: #endif michael@0: michael@0: NS_IMETHOD IsNSSInitialized(bool* initialized); michael@0: michael@0: ::mozilla::TemporaryRef michael@0: GetDefaultCertVerifier() MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: nsresult InitializeNSS(); michael@0: void ShutdownNSS(); michael@0: michael@0: void LoadLoadableRoots(); michael@0: void UnloadLoadableRoots(); michael@0: void setValidationOptions(bool isInitialSetting, michael@0: const mozilla::MutexAutoLock& lock); michael@0: nsresult setEnabledTLSVersions(); michael@0: nsresult InitializePIPNSSBundle(); michael@0: nsresult ConfigureInternalPKCS11Token(); michael@0: nsresult RegisterObservers(); michael@0: nsresult DeregisterObservers(); michael@0: michael@0: // Methods that we use to handle the profile change notifications (and to michael@0: // synthesize a full profile change when we're just doing a profile startup): michael@0: void DoProfileChangeNetTeardown(); michael@0: void DoProfileChangeTeardown(nsISupports* aSubject); michael@0: void DoProfileBeforeChange(nsISupports* aSubject); michael@0: void DoProfileChangeNetRestore(); michael@0: michael@0: Mutex mutex; michael@0: michael@0: nsCOMPtr mPIPNSSBundle; michael@0: nsCOMPtr mNSSErrorsBundle; michael@0: bool mNSSInitialized; michael@0: bool mObserversRegistered; michael@0: static int mInstanceCount; michael@0: nsNSSShutDownList* mShutdownObjectList; michael@0: #ifndef MOZ_DISABLE_CRYPTOLEGACY michael@0: SmartCardThreadList* mThreadList; michael@0: #endif michael@0: bool mIsNetworkDown; michael@0: michael@0: void deleteBackgroundThreads(); michael@0: void createBackgroundThreads(); michael@0: nsCertVerificationThread* mCertVerificationThread; michael@0: michael@0: nsNSSHttpInterface mHttpForNSS; michael@0: mozilla::RefPtr mDefaultCertVerifier; michael@0: michael@0: michael@0: static PRStatus IdentityInfoInit(void); michael@0: }; michael@0: michael@0: class nsNSSErrors michael@0: { michael@0: public: michael@0: static const char* getDefaultErrorStringName(PRErrorCode err); michael@0: static const char* getOverrideErrorStringName(PRErrorCode aErrorCode); michael@0: static nsresult getErrorMessageFromCode(PRErrorCode err, michael@0: nsINSSComponent* component, michael@0: nsString& returnedMessage); michael@0: }; michael@0: michael@0: class nsPSMInitPanic michael@0: { michael@0: private: michael@0: static bool isPanic; michael@0: public: michael@0: static void SetPanic() {isPanic = true;} michael@0: static bool GetPanic() {return isPanic;} michael@0: }; michael@0: michael@0: #endif // _nsNSSComponent_h_