|
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 _MOZILLA_PSM_TRANSPORTSECURITYINFO_H |
|
8 #define _MOZILLA_PSM_TRANSPORTSECURITYINFO_H |
|
9 |
|
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" |
|
20 |
|
21 namespace mozilla { namespace psm { |
|
22 |
|
23 enum SSLErrorMessageType { |
|
24 OverridableCertErrorMessage = 1, // for *overridable* certificate errors |
|
25 PlainErrorMessage = 2 // all other errors (or "no error") |
|
26 }; |
|
27 |
|
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(); |
|
40 |
|
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 |
|
48 |
|
49 nsresult SetSecurityState(uint32_t aState); |
|
50 nsresult SetShortSecurityDescription(const char16_t *aText); |
|
51 |
|
52 const nsACString & GetHostName() const { return mHostName; } |
|
53 const char * GetHostNameRaw() const { return mHostName.get(); } |
|
54 |
|
55 nsresult GetHostName(char **aHostName); |
|
56 nsresult SetHostName(const char *aHostName); |
|
57 |
|
58 int32_t GetPort() const { return mPort; } |
|
59 nsresult GetPort(int32_t *aPort); |
|
60 nsresult SetPort(int32_t aPort); |
|
61 |
|
62 PRErrorCode GetErrorCode() const; |
|
63 |
|
64 void GetErrorLogMessage(PRErrorCode errorCode, |
|
65 ::mozilla::psm::SSLErrorMessageType errorMessageType, |
|
66 nsString &result); |
|
67 |
|
68 void SetCanceled(PRErrorCode errorCode, |
|
69 ::mozilla::psm::SSLErrorMessageType errorMessageType); |
|
70 |
|
71 /* Set SSL Status values */ |
|
72 nsresult SetSSLStatus(nsSSLStatus *aSSLStatus); |
|
73 nsSSLStatus* SSLStatus() { return mSSLStatus; } |
|
74 void SetStatusErrorBits(nsIX509Cert & cert, uint32_t collected_errors); |
|
75 |
|
76 private: |
|
77 mutable ::mozilla::Mutex mMutex; |
|
78 |
|
79 protected: |
|
80 nsCOMPtr<nsIInterfaceRequestor> mCallbacks; |
|
81 |
|
82 private: |
|
83 uint32_t mSecurityState; |
|
84 int32_t mSubRequestsBrokenSecurity; |
|
85 int32_t mSubRequestsNoSecurity; |
|
86 |
|
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); |
|
95 |
|
96 int32_t mPort; |
|
97 nsXPIDLCString mHostName; |
|
98 |
|
99 /* SSL Status */ |
|
100 mozilla::RefPtr<nsSSLStatus> mSSLStatus; |
|
101 |
|
102 virtual void virtualDestroyNSSReference(); |
|
103 void destructorSafeDestroyNSSReference(); |
|
104 }; |
|
105 |
|
106 class RememberCertErrorsTable |
|
107 { |
|
108 private: |
|
109 RememberCertErrorsTable(); |
|
110 |
|
111 struct CertStateBits |
|
112 { |
|
113 bool mIsDomainMismatch; |
|
114 bool mIsNotValidAtThisTime; |
|
115 bool mIsUntrusted; |
|
116 }; |
|
117 nsDataHashtable<nsCStringHashKey, CertStateBits> mErrorHosts; |
|
118 |
|
119 public: |
|
120 void RememberCertHasError(TransportSecurityInfo * infoobject, |
|
121 nsSSLStatus * status, |
|
122 SECStatus certVerificationResult); |
|
123 void LookupCertErrorBits(TransportSecurityInfo * infoObject, |
|
124 nsSSLStatus* status); |
|
125 |
|
126 static nsresult Init() |
|
127 { |
|
128 sInstance = new RememberCertErrorsTable(); |
|
129 return NS_OK; |
|
130 } |
|
131 |
|
132 static RememberCertErrorsTable & GetInstance() |
|
133 { |
|
134 MOZ_ASSERT(sInstance); |
|
135 return *sInstance; |
|
136 } |
|
137 |
|
138 static void Cleanup() |
|
139 { |
|
140 delete sInstance; |
|
141 sInstance = nullptr; |
|
142 } |
|
143 private: |
|
144 Mutex mMutex; |
|
145 |
|
146 static RememberCertErrorsTable * sInstance; |
|
147 }; |
|
148 |
|
149 } } // namespace mozilla::psm |
|
150 |
|
151 // 16786594-0296-4471-8096-8f84497ca428 |
|
152 #define TRANSPORTSECURITYINFO_CID \ |
|
153 { 0x16786594, 0x0296, 0x4471, \ |
|
154 { 0x80, 0x96, 0x8f, 0x84, 0x49, 0x7c, 0xa4, 0x28 } } |
|
155 |
|
156 #endif /* _MOZILLA_PSM_TRANSPORTSECURITYINFO_H */ |