Wed, 31 Dec 2014 06:09:35 +0100
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 _MOZILLA_PSM_TRANSPORTSECURITYINFO_H
8 #define _MOZILLA_PSM_TRANSPORTSECURITYINFO_H
10 #include "certt.h"
11 #include "mozilla/Mutex.h"
12 #include "mozilla/RefPtr.h"
13 #include "nsIInterfaceRequestor.h"
14 #include "nsITransportSecurityInfo.h"
15 #include "nsSSLStatus.h"
16 #include "nsISSLStatusProvider.h"
17 #include "nsIAssociatedContentSecurity.h"
18 #include "nsNSSShutDown.h"
19 #include "nsDataHashtable.h"
21 namespace mozilla { namespace psm {
23 enum SSLErrorMessageType {
24 OverridableCertErrorMessage = 1, // for *overridable* certificate errors
25 PlainErrorMessage = 2 // all other errors (or "no error")
26 };
28 class TransportSecurityInfo : public nsITransportSecurityInfo,
29 public nsIInterfaceRequestor,
30 public nsISSLStatusProvider,
31 public nsIAssociatedContentSecurity,
32 public nsISerializable,
33 public nsIClassInfo,
34 public nsNSSShutDownObject,
35 public nsOnPK11LogoutCancelObject
36 {
37 public:
38 TransportSecurityInfo();
39 virtual ~TransportSecurityInfo();
41 NS_DECL_THREADSAFE_ISUPPORTS
42 NS_DECL_NSITRANSPORTSECURITYINFO
43 NS_DECL_NSIINTERFACEREQUESTOR
44 NS_DECL_NSISSLSTATUSPROVIDER
45 NS_DECL_NSIASSOCIATEDCONTENTSECURITY
46 NS_DECL_NSISERIALIZABLE
47 NS_DECL_NSICLASSINFO
49 nsresult SetSecurityState(uint32_t aState);
50 nsresult SetShortSecurityDescription(const char16_t *aText);
52 const nsACString & GetHostName() const { return mHostName; }
53 const char * GetHostNameRaw() const { return mHostName.get(); }
55 nsresult GetHostName(char **aHostName);
56 nsresult SetHostName(const char *aHostName);
58 int32_t GetPort() const { return mPort; }
59 nsresult GetPort(int32_t *aPort);
60 nsresult SetPort(int32_t aPort);
62 PRErrorCode GetErrorCode() const;
64 void GetErrorLogMessage(PRErrorCode errorCode,
65 ::mozilla::psm::SSLErrorMessageType errorMessageType,
66 nsString &result);
68 void SetCanceled(PRErrorCode errorCode,
69 ::mozilla::psm::SSLErrorMessageType errorMessageType);
71 /* Set SSL Status values */
72 nsresult SetSSLStatus(nsSSLStatus *aSSLStatus);
73 nsSSLStatus* SSLStatus() { return mSSLStatus; }
74 void SetStatusErrorBits(nsIX509Cert & cert, uint32_t collected_errors);
76 private:
77 mutable ::mozilla::Mutex mMutex;
79 protected:
80 nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
82 private:
83 uint32_t mSecurityState;
84 int32_t mSubRequestsBrokenSecurity;
85 int32_t mSubRequestsNoSecurity;
87 PRErrorCode mErrorCode;
88 ::mozilla::psm::SSLErrorMessageType mErrorMessageType;
89 nsString mErrorMessageCached;
90 nsresult formatErrorMessage(::mozilla::MutexAutoLock const & proofOfLock,
91 PRErrorCode errorCode,
92 ::mozilla::psm::SSLErrorMessageType errorMessageType,
93 bool wantsHtml, bool suppressPort443,
94 nsString &result);
96 int32_t mPort;
97 nsXPIDLCString mHostName;
99 /* SSL Status */
100 mozilla::RefPtr<nsSSLStatus> mSSLStatus;
102 virtual void virtualDestroyNSSReference();
103 void destructorSafeDestroyNSSReference();
104 };
106 class RememberCertErrorsTable
107 {
108 private:
109 RememberCertErrorsTable();
111 struct CertStateBits
112 {
113 bool mIsDomainMismatch;
114 bool mIsNotValidAtThisTime;
115 bool mIsUntrusted;
116 };
117 nsDataHashtable<nsCStringHashKey, CertStateBits> mErrorHosts;
119 public:
120 void RememberCertHasError(TransportSecurityInfo * infoobject,
121 nsSSLStatus * status,
122 SECStatus certVerificationResult);
123 void LookupCertErrorBits(TransportSecurityInfo * infoObject,
124 nsSSLStatus* status);
126 static nsresult Init()
127 {
128 sInstance = new RememberCertErrorsTable();
129 return NS_OK;
130 }
132 static RememberCertErrorsTable & GetInstance()
133 {
134 MOZ_ASSERT(sInstance);
135 return *sInstance;
136 }
138 static void Cleanup()
139 {
140 delete sInstance;
141 sInstance = nullptr;
142 }
143 private:
144 Mutex mMutex;
146 static RememberCertErrorsTable * sInstance;
147 };
149 } } // namespace mozilla::psm
151 // 16786594-0296-4471-8096-8f84497ca428
152 #define TRANSPORTSECURITYINFO_CID \
153 { 0x16786594, 0x0296, 0x4471, \
154 { 0x80, 0x96, 0x8f, 0x84, 0x49, 0x7c, 0xa4, 0x28 } }
156 #endif /* _MOZILLA_PSM_TRANSPORTSECURITYINFO_H */