live
TLSState.hh
Go to the documentation of this file.
1/**********
2This library is free software; you can redistribute it and/or modify it under
3the terms of the GNU Lesser General Public License as published by the
4Free Software Foundation; either version 3 of the License, or (at your
5option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6
7This library is distributed in the hope that it will be useful, but WITHOUT
8ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10more details.
11
12You should have received a copy of the GNU Lesser General Public License
13along with this library; if not, write to the Free Software Foundation, Inc.,
1451 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15**********/
16// "liveMedia"
17// Copyright (c) 1996-2025 Live Networks, Inc. All rights reserved.
18// State encapsulating a TLS connection
19// C++ header
20
21#ifndef _TLS_STATE_HH
22#define _TLS_STATE_HH
23
24#ifndef _NET_COMMON_H
25#include "NetCommon.h"
26#endif
27#ifndef _BOOLEAN_HH
28#include "Boolean.hh"
29#endif
30#ifndef _USAGE_ENVIRONMENT_HH
31#include "UsageEnvironment.hh"
32#endif
33#ifndef NO_OPENSSL
34#include <openssl/ssl.h>
35#endif
36
37class TLSState {
38public:
40
41 int write(const char* data, unsigned count);
42 int read(u_int8_t* buffer, unsigned bufferSize);
43
44 void nullify(); // clear the state so that the destructor will have no effect
45
46protected: // we're an abstract base class
48 virtual ~TLSState();
49
50#ifndef NO_OPENSSL
52 void reset();
53
54protected:
56 SSL_CTX* fCtx;
57 SSL* fCon;
58#endif
59};
60
61class ClientTLSState: public TLSState {
62public:
63 ClientTLSState(class RTSPClient& client);
64 virtual ~ClientTLSState();
65
66 int connect(int socketNum); // returns: <0 (error), 0 (pending), >0 (success)
67
68#ifndef NO_OPENSSL
69private:
70 Boolean setup(int socketNum);
71 Boolean setupContinue(int socketNum);// called to complete "setup()" (perhaps via a callback)
72#ifdef CLIENT_TLS_SETUP_EXTRA
73 // If you want to do some extra work during the client TLS setup (e.g., to check the server's
74 // certificate), then you would do so by defining CLIENT_TLS_SETUP_EXTRA during
75 // the compilation, and implementing this member function (which, if it succeeds, must
76 // eventually cause "setupContinue()" to be called:
77 Boolean setupExtra(int socketNum);
78#endif
79
80private:
82#endif
83};
84
85class ServerTLSState: public TLSState {
86public:
88 virtual ~ServerTLSState();
89
90 void setCertificateAndPrivateKeyFileNames(char const* certFileName, char const* privKeyFileName);
92
93 int accept(int socketNum); // returns: <0 (error), 0 (pending), >0 (success)
94
96
97#ifndef NO_OPENSSL
98private:
99 Boolean setup(int socketNum);
100
101private:
105#endif
106};
107
108#endif
unsigned char Boolean
Definition: Boolean.hh:25
Boolean setupContinue(int socketNum)
int connect(int socketNum)
class RTSPClient & fClient
Definition: TLSState.hh:81
virtual ~ClientTLSState()
ClientTLSState(class RTSPClient &client)
Boolean setup(int socketNum)
void assignStateFrom(ServerTLSState const &from)
char const * fPrivateKeyFileName
Definition: TLSState.hh:104
ServerTLSState(UsageEnvironment &env)
UsageEnvironment & fEnv
Definition: TLSState.hh:102
void setCertificateAndPrivateKeyFileNames(char const *certFileName, char const *privKeyFileName)
int accept(int socketNum)
Boolean setup(int socketNum)
virtual ~ServerTLSState()
Boolean tlsAcceptIsNeeded
Definition: TLSState.hh:95
char const * fCertificateFileName
Definition: TLSState.hh:103
SSL * fCon
Definition: TLSState.hh:57
Boolean isNeeded
Definition: TLSState.hh:39
void reset()
int write(const char *data, unsigned count)
virtual ~TLSState()
void nullify()
void initLibrary()
SSL_CTX * fCtx
Definition: TLSState.hh:56
Boolean fHasBeenSetup
Definition: TLSState.hh:55
int read(u_int8_t *buffer, unsigned bufferSize)