Source code

Revision control

Other Tools

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/. */
5
6
#ifndef mozilla_net_TLSServerSocket_h
7
#define mozilla_net_TLSServerSocket_h
8
9
#include "nsAutoPtr.h"
10
#include "nsITLSServerSocket.h"
11
#include "nsServerSocket.h"
12
#include "nsString.h"
13
#include "mozilla/Mutex.h"
14
#include "seccomon.h"
15
16
namespace mozilla {
17
namespace net {
18
19
class TLSServerSocket final : public nsServerSocket, public nsITLSServerSocket {
20
public:
21
NS_DECL_ISUPPORTS_INHERITED
22
NS_FORWARD_NSISERVERSOCKET(nsServerSocket::)
23
NS_DECL_NSITLSSERVERSOCKET
24
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;
30
31
TLSServerSocket();
32
33
private:
34
virtual ~TLSServerSocket() = default;
35
36
static SECStatus AuthCertificateHook(void* arg, PRFileDesc* fd,
37
PRBool checksig, PRBool isServer);
38
39
nsCOMPtr<nsIX509Cert> mServerCert;
40
};
41
42
class TLSServerConnectionInfo : public nsITLSServerConnectionInfo,
43
public nsITLSClientStatus {
44
friend class TLSServerSocket;
45
46
public:
47
NS_DECL_THREADSAFE_ISUPPORTS
48
NS_DECL_NSITLSSERVERCONNECTIONINFO
49
NS_DECL_NSITLSCLIENTSTATUS
50
51
TLSServerConnectionInfo();
52
53
private:
54
virtual ~TLSServerConnectionInfo();
55
56
static void HandshakeCallback(PRFileDesc* aFD, void* aArg);
57
nsresult HandshakeCallback(PRFileDesc* aFD);
58
59
RefPtr<TLSServerSocket> mServerSocket;
60
// Weak ref to the transport, to avoid cycles since the transport holds a
61
// reference to the TLSServerConnectionInfo object. This is not handed out to
62
// anyone, and is only used in HandshakeCallback to close the transport in
63
// case of an error. After this, it's set to nullptr.
64
nsISocketTransport* mTransport;
65
nsCOMPtr<nsIX509Cert> mPeerCert;
66
int16_t mTlsVersionUsed;
67
nsCString mCipherName;
68
uint32_t mKeyLength;
69
uint32_t mMacLength;
70
// lock protects access to mSecurityObserver
71
mozilla::Mutex mLock;
72
nsCOMPtr<nsITLSServerSecurityObserver> mSecurityObserver;
73
};
74
75
} // namespace net
76
} // namespace mozilla
77
78
#endif // mozilla_net_TLSServerSocket_h