security/manager/ssl/src/nsNSSComponent.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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/. */
     7 #ifndef _nsNSSComponent_h_
     8 #define _nsNSSComponent_h_
    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"
    28 class nsIDOMWindow;
    29 class nsIPrompt;
    30 class SmartCardThreadList;
    32 namespace mozilla { namespace psm {
    34 MOZ_WARN_UNUSED_RESULT
    35   ::mozilla::TemporaryRef<mozilla::psm::SharedCertVerifier>
    36   GetDefaultCertVerifier();
    38 } } // namespace mozilla::psm
    41 #define NS_NSSCOMPONENT_CID \
    42 {0x4cb64dfd, 0xca98, 0x4e24, {0xbe, 0xfd, 0x0d, 0x92, 0x85, 0xa3, 0x3b, 0xcb}}
    44 #define PSM_COMPONENT_CONTRACTID "@mozilla.org/psm;1"
    46 //Define an interface that we can use to look up from the
    47 //callbacks passed to NSS.
    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 } }
    54 enum EnsureNSSOperator
    55 {
    56   nssLoadingComponent = 0,
    57   nssInitSucceeded = 1,
    58   nssInitFailed = 2,
    59   nssShutdown = 3,
    60   nssEnsure = 100,
    61   nssEnsureOnChromeOnly = 101
    62 };
    64 extern bool EnsureNSSInitialized(EnsureNSSOperator op);
    66 class nsNSSComponent;
    68 class NS_NO_VTABLE nsINSSComponent : public nsISupports {
    69  public:
    70   NS_DECLARE_STATIC_IID_ACCESSOR(NS_INSSCOMPONENT_IID)
    72   NS_IMETHOD ShowAlertFromStringBundle(const char* messageID) = 0;
    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;
    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;
    88   NS_IMETHOD LogoutAuthenticatedPK11() = 0;
    90 #ifndef MOZ_DISABLE_CRYPTOLEGACY
    91   NS_IMETHOD LaunchSmartCardThread(SECMODModule* module) = 0;
    93   NS_IMETHOD ShutdownSmartCardThread(SECMODModule* module) = 0;
    95   NS_IMETHOD PostEvent(const nsAString& eventType,
    96                        const nsAString& token) = 0;
    98   NS_IMETHOD DispatchEvent(const nsAString& eventType,
    99                            const nsAString& token) = 0;
   100 #endif
   102   NS_IMETHOD IsNSSInitialized(bool* initialized) = 0;
   104   virtual ::mozilla::TemporaryRef<mozilla::psm::SharedCertVerifier>
   105     GetDefaultCertVerifier() = 0;
   106 };
   108 NS_DEFINE_STATIC_IID_ACCESSOR(nsINSSComponent, NS_INSSCOMPONENT_IID)
   110 class nsNSSShutDownList;
   111 class nsCertVerificationThread;
   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;
   122 public:
   123   NS_DEFINE_STATIC_CID_ACCESSOR( NS_NSSCOMPONENT_CID )
   125   nsNSSComponent();
   126   virtual ~nsNSSComponent();
   128   NS_DECL_THREADSAFE_ISUPPORTS
   129   NS_DECL_NSISIGNATUREVERIFIER
   130   NS_DECL_NSIENTROPYCOLLECTOR
   131   NS_DECL_NSIOBSERVER
   133   NS_METHOD Init();
   135   static nsresult GetNewPrompter(nsIPrompt** result);
   136   static nsresult ShowAlertWithConstructedString(const nsString& message);
   137   NS_IMETHOD ShowAlertFromStringBundle(const char* messageID);
   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();
   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
   164   NS_IMETHOD IsNSSInitialized(bool* initialized);
   166   ::mozilla::TemporaryRef<mozilla::psm::SharedCertVerifier>
   167     GetDefaultCertVerifier() MOZ_OVERRIDE;
   169 private:
   170   nsresult InitializeNSS();
   171   void ShutdownNSS();
   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();
   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();
   190   Mutex mutex;
   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;
   203   void deleteBackgroundThreads();
   204   void createBackgroundThreads();
   205   nsCertVerificationThread* mCertVerificationThread;
   207   nsNSSHttpInterface mHttpForNSS;
   208   mozilla::RefPtr<mozilla::psm::SharedCertVerifier> mDefaultCertVerifier;
   211   static PRStatus IdentityInfoInit(void);
   212 };
   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 };
   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 };
   233 #endif // _nsNSSComponent_h_

mercurial