1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/manager/ssl/src/TransportSecurityInfo.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,156 @@ 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 _MOZILLA_PSM_TRANSPORTSECURITYINFO_H 1.11 +#define _MOZILLA_PSM_TRANSPORTSECURITYINFO_H 1.12 + 1.13 +#include "certt.h" 1.14 +#include "mozilla/Mutex.h" 1.15 +#include "mozilla/RefPtr.h" 1.16 +#include "nsIInterfaceRequestor.h" 1.17 +#include "nsITransportSecurityInfo.h" 1.18 +#include "nsSSLStatus.h" 1.19 +#include "nsISSLStatusProvider.h" 1.20 +#include "nsIAssociatedContentSecurity.h" 1.21 +#include "nsNSSShutDown.h" 1.22 +#include "nsDataHashtable.h" 1.23 + 1.24 +namespace mozilla { namespace psm { 1.25 + 1.26 +enum SSLErrorMessageType { 1.27 + OverridableCertErrorMessage = 1, // for *overridable* certificate errors 1.28 + PlainErrorMessage = 2 // all other errors (or "no error") 1.29 +}; 1.30 + 1.31 +class TransportSecurityInfo : public nsITransportSecurityInfo, 1.32 + public nsIInterfaceRequestor, 1.33 + public nsISSLStatusProvider, 1.34 + public nsIAssociatedContentSecurity, 1.35 + public nsISerializable, 1.36 + public nsIClassInfo, 1.37 + public nsNSSShutDownObject, 1.38 + public nsOnPK11LogoutCancelObject 1.39 +{ 1.40 +public: 1.41 + TransportSecurityInfo(); 1.42 + virtual ~TransportSecurityInfo(); 1.43 + 1.44 + NS_DECL_THREADSAFE_ISUPPORTS 1.45 + NS_DECL_NSITRANSPORTSECURITYINFO 1.46 + NS_DECL_NSIINTERFACEREQUESTOR 1.47 + NS_DECL_NSISSLSTATUSPROVIDER 1.48 + NS_DECL_NSIASSOCIATEDCONTENTSECURITY 1.49 + NS_DECL_NSISERIALIZABLE 1.50 + NS_DECL_NSICLASSINFO 1.51 + 1.52 + nsresult SetSecurityState(uint32_t aState); 1.53 + nsresult SetShortSecurityDescription(const char16_t *aText); 1.54 + 1.55 + const nsACString & GetHostName() const { return mHostName; } 1.56 + const char * GetHostNameRaw() const { return mHostName.get(); } 1.57 + 1.58 + nsresult GetHostName(char **aHostName); 1.59 + nsresult SetHostName(const char *aHostName); 1.60 + 1.61 + int32_t GetPort() const { return mPort; } 1.62 + nsresult GetPort(int32_t *aPort); 1.63 + nsresult SetPort(int32_t aPort); 1.64 + 1.65 + PRErrorCode GetErrorCode() const; 1.66 + 1.67 + void GetErrorLogMessage(PRErrorCode errorCode, 1.68 + ::mozilla::psm::SSLErrorMessageType errorMessageType, 1.69 + nsString &result); 1.70 + 1.71 + void SetCanceled(PRErrorCode errorCode, 1.72 + ::mozilla::psm::SSLErrorMessageType errorMessageType); 1.73 + 1.74 + /* Set SSL Status values */ 1.75 + nsresult SetSSLStatus(nsSSLStatus *aSSLStatus); 1.76 + nsSSLStatus* SSLStatus() { return mSSLStatus; } 1.77 + void SetStatusErrorBits(nsIX509Cert & cert, uint32_t collected_errors); 1.78 + 1.79 +private: 1.80 + mutable ::mozilla::Mutex mMutex; 1.81 + 1.82 +protected: 1.83 + nsCOMPtr<nsIInterfaceRequestor> mCallbacks; 1.84 + 1.85 +private: 1.86 + uint32_t mSecurityState; 1.87 + int32_t mSubRequestsBrokenSecurity; 1.88 + int32_t mSubRequestsNoSecurity; 1.89 + 1.90 + PRErrorCode mErrorCode; 1.91 + ::mozilla::psm::SSLErrorMessageType mErrorMessageType; 1.92 + nsString mErrorMessageCached; 1.93 + nsresult formatErrorMessage(::mozilla::MutexAutoLock const & proofOfLock, 1.94 + PRErrorCode errorCode, 1.95 + ::mozilla::psm::SSLErrorMessageType errorMessageType, 1.96 + bool wantsHtml, bool suppressPort443, 1.97 + nsString &result); 1.98 + 1.99 + int32_t mPort; 1.100 + nsXPIDLCString mHostName; 1.101 + 1.102 + /* SSL Status */ 1.103 + mozilla::RefPtr<nsSSLStatus> mSSLStatus; 1.104 + 1.105 + virtual void virtualDestroyNSSReference(); 1.106 + void destructorSafeDestroyNSSReference(); 1.107 +}; 1.108 + 1.109 +class RememberCertErrorsTable 1.110 +{ 1.111 +private: 1.112 + RememberCertErrorsTable(); 1.113 + 1.114 + struct CertStateBits 1.115 + { 1.116 + bool mIsDomainMismatch; 1.117 + bool mIsNotValidAtThisTime; 1.118 + bool mIsUntrusted; 1.119 + }; 1.120 + nsDataHashtable<nsCStringHashKey, CertStateBits> mErrorHosts; 1.121 + 1.122 +public: 1.123 + void RememberCertHasError(TransportSecurityInfo * infoobject, 1.124 + nsSSLStatus * status, 1.125 + SECStatus certVerificationResult); 1.126 + void LookupCertErrorBits(TransportSecurityInfo * infoObject, 1.127 + nsSSLStatus* status); 1.128 + 1.129 + static nsresult Init() 1.130 + { 1.131 + sInstance = new RememberCertErrorsTable(); 1.132 + return NS_OK; 1.133 + } 1.134 + 1.135 + static RememberCertErrorsTable & GetInstance() 1.136 + { 1.137 + MOZ_ASSERT(sInstance); 1.138 + return *sInstance; 1.139 + } 1.140 + 1.141 + static void Cleanup() 1.142 + { 1.143 + delete sInstance; 1.144 + sInstance = nullptr; 1.145 + } 1.146 +private: 1.147 + Mutex mMutex; 1.148 + 1.149 + static RememberCertErrorsTable * sInstance; 1.150 +}; 1.151 + 1.152 +} } // namespace mozilla::psm 1.153 + 1.154 +// 16786594-0296-4471-8096-8f84497ca428 1.155 +#define TRANSPORTSECURITYINFO_CID \ 1.156 +{ 0x16786594, 0x0296, 0x4471, \ 1.157 + { 0x80, 0x96, 0x8f, 0x84, 0x49, 0x7c, 0xa4, 0x28 } } 1.158 + 1.159 +#endif /* _MOZILLA_PSM_TRANSPORTSECURITYINFO_H */