live
TLSState.hh
Go to the documentation of this file.
1 /**********
2 This library is free software; you can redistribute it and/or modify it under
3 the terms of the GNU Lesser General Public License as published by the
4 Free Software Foundation; either version 3 of the License, or (at your
5 option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
6 
7 This library is distributed in the hope that it will be useful, but WITHOUT
8 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
9 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
10 more details.
11 
12 You should have received a copy of the GNU Lesser General Public License
13 along with this library; if not, write to the Free Software Foundation, Inc.,
14 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 **********/
16 // "liveMedia"
17 // Copyright (c) 1996-2022 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 
37 class TLSState {
38 public:
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 
46 protected: // we're an abstract base class
48  virtual ~TLSState();
49 
50 #ifndef NO_OPENSSL
51  void initLibrary();
52  void reset();
53 
54 protected:
56  SSL_CTX* fCtx;
57  SSL* fCon;
58 #endif
59 };
60 
61 class ClientTLSState: public TLSState {
62 public:
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
69 private:
70  Boolean setup(int socketNum);
71 
72 private:
74 #endif
75 };
76 
77 class ServerTLSState: public TLSState {
78 public:
80  virtual ~ServerTLSState();
81 
82  void setCertificateAndPrivateKeyFileNames(char const* certFileName, char const* privKeyFileName);
83  void assignStateFrom(ServerTLSState const& from);
84 
85  int accept(int socketNum); // returns: <0 (error), 0 (pending), >0 (success)
86 
88 
89 #ifndef NO_OPENSSL
90 private:
91  Boolean setup(int socketNum);
92 
93 private:
95  char const* fCertificateFileName;
96  char const* fPrivateKeyFileName;
97 #endif
98 };
99 
100 #endif
unsigned char Boolean
Definition: Boolean.hh:25
int connect(int socketNum)
class RTSPClient & fClient
Definition: TLSState.hh:73
virtual ~ClientTLSState()
ClientTLSState(class RTSPClient &client)
Boolean setup(int socketNum)
void assignStateFrom(ServerTLSState const &from)
char const * fPrivateKeyFileName
Definition: TLSState.hh:96
ServerTLSState(UsageEnvironment &env)
UsageEnvironment & fEnv
Definition: TLSState.hh:94
void setCertificateAndPrivateKeyFileNames(char const *certFileName, char const *privKeyFileName)
int accept(int socketNum)
Boolean setup(int socketNum)
virtual ~ServerTLSState()
Boolean tlsAcceptIsNeeded
Definition: TLSState.hh:87
char const * fCertificateFileName
Definition: TLSState.hh:95
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)