Cuberite
A lightweight, fast and extensible game server for Minecraft
SslContext.h
Go to the documentation of this file.
1 
2 // SslContext.h
3 
4 // Declares the cSslContext class that holds everything a single SSL context needs to function
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "mbedtls/ssl.h"
13 #include "../ByteBuffer.h"
14 
15 
16 
17 
18 
19 // fwd:
20 class cCtrDrbgContext;
21 class cSslConfig;
22 
23 
24 
25 
26 
35 class cSslContext abstract
36 {
37 public:
39  cSslContext(void);
40 
41  virtual ~cSslContext();
42 
46  int Initialize(std::shared_ptr<const cSslConfig> a_Config);
47 
49  int Initialize(bool a_IsClient);
50 
52  bool IsValid(void) const { return m_IsValid; }
53 
57  void SetExpectedPeerName(const AString & a_ExpectedPeerName);
58 
65  int WritePlain(const void * a_Data, size_t a_NumBytes);
66 
73  int ReadPlain(void * a_Data, size_t a_MaxBytes);
74 
80  int Handshake(void);
81 
83  bool HasHandshaken(void) const { return m_HasHandshaken; }
84 
87  int NotifyClose(void);
88 
89 protected:
90 
92  std::shared_ptr<const cSslConfig> m_Config;
93 
95  mbedtls_ssl_context m_Ssl;
96 
98  bool m_IsValid;
99 
101  bool m_HasHandshaken;
102 
104  static int ReceiveEncrypted(void * a_This, unsigned char * a_Buffer, size_t a_NumBytes)
105  {
106  return (static_cast<cSslContext *>(a_This))->ReceiveEncrypted(a_Buffer, a_NumBytes);
107  }
108 
110  static int SendEncrypted(void * a_This, const unsigned char * a_Buffer, size_t a_NumBytes)
111  {
112  return (static_cast<cSslContext *>(a_This))->SendEncrypted(a_Buffer, a_NumBytes);
113  }
114 
116  virtual int ReceiveEncrypted(unsigned char * a_Buffer, size_t a_NumBytes) = 0;
117 
119  virtual int SendEncrypted(const unsigned char * a_Buffer, size_t a_NumBytes) = 0;
120 } ;
121 
122 
123 
124 
std::string AString
Definition: StringUtils.h:13