1 /* vim:set ts=2 sw=2 et cindent: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_net_TLSServerSocket_h
7 #define mozilla_net_TLSServerSocket_h
9 #include "nsIInterfaceRequestor.h"
10 #include "nsITLSServerSocket.h"
11 #include "nsServerSocket.h"
13 #include "mozilla/Mutex.h"
19 class TLSServerSocket final
: public nsServerSocket
, public nsITLSServerSocket
{
21 NS_DECL_ISUPPORTS_INHERITED
22 NS_FORWARD_NSISERVERSOCKET(nsServerSocket::)
23 NS_DECL_NSITLSSERVERSOCKET
25 // Override methods from nsServerSocket
26 virtual void CreateClientTransport(PRFileDesc
* clientFD
,
27 const NetAddr
& clientAddr
) override
;
28 virtual nsresult
SetSocketDefaults() override
;
29 virtual nsresult
OnSocketListen() override
;
31 TLSServerSocket() = default;
34 virtual ~TLSServerSocket() = default;
36 static SECStatus
AuthCertificateHook(void* arg
, PRFileDesc
* fd
,
37 PRBool checksig
, PRBool isServer
);
39 nsCOMPtr
<nsIX509Cert
> mServerCert
;
42 class TLSServerConnectionInfo
: public nsITLSServerConnectionInfo
,
43 public nsITLSClientStatus
,
44 public nsIInterfaceRequestor
{
45 friend class TLSServerSocket
;
48 NS_DECL_THREADSAFE_ISUPPORTS
49 NS_DECL_NSITLSSERVERCONNECTIONINFO
50 NS_DECL_NSITLSCLIENTSTATUS
51 NS_DECL_NSIINTERFACEREQUESTOR
53 TLSServerConnectionInfo() = default;
56 virtual ~TLSServerConnectionInfo();
58 static void HandshakeCallback(PRFileDesc
* aFD
, void* aArg
);
59 nsresult
HandshakeCallback(PRFileDesc
* aFD
);
61 RefPtr
<TLSServerSocket
> mServerSocket
;
62 // Weak ref to the transport, to avoid cycles since the transport holds a
63 // reference to the TLSServerConnectionInfo object. This is not handed out to
64 // anyone, and is only used in HandshakeCallback to close the transport in
65 // case of an error. After this, it's set to nullptr.
66 nsISocketTransport
* mTransport
{nullptr};
67 nsCOMPtr
<nsIX509Cert
> mPeerCert
;
68 int16_t mTlsVersionUsed
{TLS_VERSION_UNKNOWN
};
69 nsCString mCipherName
;
70 uint32_t mKeyLength
{0};
71 uint32_t mMacLength
{0};
72 // lock protects access to mSecurityObserver
73 mozilla::Mutex mLock
{"TLSServerConnectionInfo.mLock"};
74 nsCOMPtr
<nsITLSServerSecurityObserver
> mSecurityObserver
75 MOZ_GUARDED_BY(mLock
);
79 } // namespace mozilla
81 #endif // mozilla_net_TLSServerSocket_h