LCOV - code coverage report
Current view: top level - security/manager/ssl - TransportSecurityInfo.h (source / functions) Hit Total Coverage
Test: output.info Lines: 3 16 18.8 %
Date: 2017-07-14 16:53:18 Functions: 1 8 12.5 %
Legend: Lines: hit not hit

          Line data    Source code
       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 TransportSecurityInfo_h
       8             : #define TransportSecurityInfo_h
       9             : 
      10             : #include "ScopedNSSTypes.h"
      11             : #include "certt.h"
      12             : #include "mozilla/Assertions.h"
      13             : #include "mozilla/BasePrincipal.h"
      14             : #include "mozilla/Mutex.h"
      15             : #include "mozilla/RefPtr.h"
      16             : #include "nsDataHashtable.h"
      17             : #include "nsIAssociatedContentSecurity.h"
      18             : #include "nsIInterfaceRequestor.h"
      19             : #include "nsISSLStatusProvider.h"
      20             : #include "nsITransportSecurityInfo.h"
      21             : #include "nsNSSShutDown.h"
      22             : #include "nsSSLStatus.h"
      23             : #include "nsString.h"
      24             : #include "pkix/pkixtypes.h"
      25             : 
      26             : namespace mozilla { namespace psm {
      27             : 
      28             : enum class SSLErrorMessageType {
      29             :   OverridableCert = 1, // for *overridable* certificate errors
      30             :   Plain = 2,           // all other errors (or "no error")
      31             : };
      32             : 
      33             : class TransportSecurityInfo : public nsITransportSecurityInfo,
      34             :                               public nsIInterfaceRequestor,
      35             :                               public nsISSLStatusProvider,
      36             :                               public nsIAssociatedContentSecurity,
      37             :                               public nsISerializable,
      38             :                               public nsIClassInfo,
      39             :                               public nsNSSShutDownObject,
      40             :                               public nsOnPK11LogoutCancelObject
      41             : {
      42             : protected:
      43             :   virtual ~TransportSecurityInfo();
      44             : public:
      45             :   TransportSecurityInfo();
      46             : 
      47             :   NS_DECL_THREADSAFE_ISUPPORTS
      48             :   NS_DECL_NSITRANSPORTSECURITYINFO
      49             :   NS_DECL_NSIINTERFACEREQUESTOR
      50             :   NS_DECL_NSISSLSTATUSPROVIDER
      51             :   NS_DECL_NSIASSOCIATEDCONTENTSECURITY
      52             :   NS_DECL_NSISERIALIZABLE
      53             :   NS_DECL_NSICLASSINFO
      54             : 
      55             :   void SetSecurityState(uint32_t aState);
      56             : 
      57           0 :   const nsACString & GetHostName() const { return mHostName; }
      58             : 
      59             :   void SetHostName(const char* host);
      60             : 
      61           0 :   int32_t GetPort() const { return mPort; }
      62             :   void SetPort(int32_t aPort);
      63             : 
      64           0 :   const OriginAttributes& GetOriginAttributes() const {
      65           0 :     return mOriginAttributes;
      66             :   }
      67             :   void SetOriginAttributes(const OriginAttributes& aOriginAttributes);
      68             : 
      69             :   PRErrorCode GetErrorCode() const;
      70             : 
      71             :   void GetErrorLogMessage(PRErrorCode errorCode,
      72             :                           ::mozilla::psm::SSLErrorMessageType errorMessageType,
      73             :                           nsString &result);
      74             : 
      75             :   void SetCanceled(PRErrorCode errorCode,
      76             :                    ::mozilla::psm::SSLErrorMessageType errorMessageType);
      77             : 
      78             :   /* Set SSL Status values */
      79             :   void SetSSLStatus(nsSSLStatus* aSSLStatus);
      80           0 :   nsSSLStatus* SSLStatus() { return mSSLStatus; }
      81             :   void SetStatusErrorBits(nsNSSCertificate* cert, uint32_t collected_errors);
      82             : 
      83             :   nsresult SetFailedCertChain(UniqueCERTCertList certList);
      84             : 
      85             : private:
      86             :   mutable ::mozilla::Mutex mMutex;
      87             : 
      88             : protected:
      89             :   nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
      90             : 
      91             : private:
      92             :   uint32_t mSecurityState;
      93             :   int32_t mSubRequestsBrokenSecurity;
      94             :   int32_t mSubRequestsNoSecurity;
      95             : 
      96             :   PRErrorCode mErrorCode;
      97             :   ::mozilla::psm::SSLErrorMessageType mErrorMessageType;
      98             :   nsString mErrorMessageCached;
      99             :   nsresult formatErrorMessage(::mozilla::MutexAutoLock const & proofOfLock,
     100             :                               PRErrorCode errorCode,
     101             :                               ::mozilla::psm::SSLErrorMessageType errorMessageType,
     102             :                               bool wantsHtml, bool suppressPort443,
     103             :                               nsString &result);
     104             : 
     105             :   int32_t mPort;
     106             :   nsCString mHostName;
     107             :   OriginAttributes mOriginAttributes;
     108             : 
     109             :   /* SSL Status */
     110             :   RefPtr<nsSSLStatus> mSSLStatus;
     111             : 
     112             :   /* Peer cert chain for failed connections (for error reporting) */
     113             :   nsCOMPtr<nsIX509CertList> mFailedCertChain;
     114             : 
     115             :   virtual void virtualDestroyNSSReference() override;
     116             :   void destructorSafeDestroyNSSReference();
     117             : };
     118             : 
     119           0 : class RememberCertErrorsTable
     120             : {
     121             : private:
     122             :   RememberCertErrorsTable();
     123             : 
     124             :   struct CertStateBits
     125             :   {
     126             :     bool mIsDomainMismatch;
     127             :     bool mIsNotValidAtThisTime;
     128             :     bool mIsUntrusted;
     129             :   };
     130             :   nsDataHashtable<nsCStringHashKey, CertStateBits> mErrorHosts;
     131             : 
     132             : public:
     133             :   void RememberCertHasError(TransportSecurityInfo * infoobject,
     134             :                             nsSSLStatus * status,
     135             :                             SECStatus certVerificationResult);
     136             :   void LookupCertErrorBits(TransportSecurityInfo * infoObject,
     137             :                            nsSSLStatus* status);
     138             : 
     139           1 :   static void Init()
     140             :   {
     141           1 :     sInstance = new RememberCertErrorsTable();
     142           1 :   }
     143             : 
     144           0 :   static RememberCertErrorsTable & GetInstance()
     145             :   {
     146           0 :     MOZ_ASSERT(sInstance);
     147           0 :     return *sInstance;
     148             :   }
     149             : 
     150           0 :   static void Cleanup()
     151             :   {
     152           0 :     delete sInstance;
     153           0 :     sInstance = nullptr;
     154           0 :   }
     155             : private:
     156             :   Mutex mMutex;
     157             : 
     158             :   static RememberCertErrorsTable * sInstance;
     159             : };
     160             : 
     161             : } } // namespace mozilla::psm
     162             : 
     163             : // 16786594-0296-4471-8096-8f84497ca428
     164             : #define TRANSPORTSECURITYINFO_CID \
     165             : { 0x16786594, 0x0296, 0x4471, \
     166             :     { 0x80, 0x96, 0x8f, 0x84, 0x49, 0x7c, 0xa4, 0x28 } }
     167             : 
     168             : #endif // TransportSecurityInfo_h

Generated by: LCOV version 1.13