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 _MOZILLA_PSM_TRANSPORTSECURITYINFO_H michael@0: #define _MOZILLA_PSM_TRANSPORTSECURITYINFO_H michael@0: michael@0: #include "certt.h" michael@0: #include "mozilla/Mutex.h" michael@0: #include "mozilla/RefPtr.h" michael@0: #include "nsIInterfaceRequestor.h" michael@0: #include "nsITransportSecurityInfo.h" michael@0: #include "nsSSLStatus.h" michael@0: #include "nsISSLStatusProvider.h" michael@0: #include "nsIAssociatedContentSecurity.h" michael@0: #include "nsNSSShutDown.h" michael@0: #include "nsDataHashtable.h" michael@0: michael@0: namespace mozilla { namespace psm { michael@0: michael@0: enum SSLErrorMessageType { michael@0: OverridableCertErrorMessage = 1, // for *overridable* certificate errors michael@0: PlainErrorMessage = 2 // all other errors (or "no error") michael@0: }; michael@0: michael@0: class TransportSecurityInfo : public nsITransportSecurityInfo, michael@0: public nsIInterfaceRequestor, michael@0: public nsISSLStatusProvider, michael@0: public nsIAssociatedContentSecurity, michael@0: public nsISerializable, michael@0: public nsIClassInfo, michael@0: public nsNSSShutDownObject, michael@0: public nsOnPK11LogoutCancelObject michael@0: { michael@0: public: michael@0: TransportSecurityInfo(); michael@0: virtual ~TransportSecurityInfo(); michael@0: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSITRANSPORTSECURITYINFO michael@0: NS_DECL_NSIINTERFACEREQUESTOR michael@0: NS_DECL_NSISSLSTATUSPROVIDER michael@0: NS_DECL_NSIASSOCIATEDCONTENTSECURITY michael@0: NS_DECL_NSISERIALIZABLE michael@0: NS_DECL_NSICLASSINFO michael@0: michael@0: nsresult SetSecurityState(uint32_t aState); michael@0: nsresult SetShortSecurityDescription(const char16_t *aText); michael@0: michael@0: const nsACString & GetHostName() const { return mHostName; } michael@0: const char * GetHostNameRaw() const { return mHostName.get(); } michael@0: michael@0: nsresult GetHostName(char **aHostName); michael@0: nsresult SetHostName(const char *aHostName); michael@0: michael@0: int32_t GetPort() const { return mPort; } michael@0: nsresult GetPort(int32_t *aPort); michael@0: nsresult SetPort(int32_t aPort); michael@0: michael@0: PRErrorCode GetErrorCode() const; michael@0: michael@0: void GetErrorLogMessage(PRErrorCode errorCode, michael@0: ::mozilla::psm::SSLErrorMessageType errorMessageType, michael@0: nsString &result); michael@0: michael@0: void SetCanceled(PRErrorCode errorCode, michael@0: ::mozilla::psm::SSLErrorMessageType errorMessageType); michael@0: michael@0: /* Set SSL Status values */ michael@0: nsresult SetSSLStatus(nsSSLStatus *aSSLStatus); michael@0: nsSSLStatus* SSLStatus() { return mSSLStatus; } michael@0: void SetStatusErrorBits(nsIX509Cert & cert, uint32_t collected_errors); michael@0: michael@0: private: michael@0: mutable ::mozilla::Mutex mMutex; michael@0: michael@0: protected: michael@0: nsCOMPtr mCallbacks; michael@0: michael@0: private: michael@0: uint32_t mSecurityState; michael@0: int32_t mSubRequestsBrokenSecurity; michael@0: int32_t mSubRequestsNoSecurity; michael@0: michael@0: PRErrorCode mErrorCode; michael@0: ::mozilla::psm::SSLErrorMessageType mErrorMessageType; michael@0: nsString mErrorMessageCached; michael@0: nsresult formatErrorMessage(::mozilla::MutexAutoLock const & proofOfLock, michael@0: PRErrorCode errorCode, michael@0: ::mozilla::psm::SSLErrorMessageType errorMessageType, michael@0: bool wantsHtml, bool suppressPort443, michael@0: nsString &result); michael@0: michael@0: int32_t mPort; michael@0: nsXPIDLCString mHostName; michael@0: michael@0: /* SSL Status */ michael@0: mozilla::RefPtr mSSLStatus; michael@0: michael@0: virtual void virtualDestroyNSSReference(); michael@0: void destructorSafeDestroyNSSReference(); michael@0: }; michael@0: michael@0: class RememberCertErrorsTable michael@0: { michael@0: private: michael@0: RememberCertErrorsTable(); michael@0: michael@0: struct CertStateBits michael@0: { michael@0: bool mIsDomainMismatch; michael@0: bool mIsNotValidAtThisTime; michael@0: bool mIsUntrusted; michael@0: }; michael@0: nsDataHashtable mErrorHosts; michael@0: michael@0: public: michael@0: void RememberCertHasError(TransportSecurityInfo * infoobject, michael@0: nsSSLStatus * status, michael@0: SECStatus certVerificationResult); michael@0: void LookupCertErrorBits(TransportSecurityInfo * infoObject, michael@0: nsSSLStatus* status); michael@0: michael@0: static nsresult Init() michael@0: { michael@0: sInstance = new RememberCertErrorsTable(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: static RememberCertErrorsTable & GetInstance() michael@0: { michael@0: MOZ_ASSERT(sInstance); michael@0: return *sInstance; michael@0: } michael@0: michael@0: static void Cleanup() michael@0: { michael@0: delete sInstance; michael@0: sInstance = nullptr; michael@0: } michael@0: private: michael@0: Mutex mMutex; michael@0: michael@0: static RememberCertErrorsTable * sInstance; michael@0: }; michael@0: michael@0: } } // namespace mozilla::psm michael@0: michael@0: // 16786594-0296-4471-8096-8f84497ca428 michael@0: #define TRANSPORTSECURITYINFO_CID \ michael@0: { 0x16786594, 0x0296, 0x4471, \ michael@0: { 0x80, 0x96, 0x8f, 0x84, 0x49, 0x7c, 0xa4, 0x28 } } michael@0: michael@0: #endif /* _MOZILLA_PSM_TRANSPORTSECURITYINFO_H */