XRootD
XrdTlsSocket.hh
Go to the documentation of this file.
1 #ifndef __XRD_TLS_SOCKET_HH__
2 #define __XRD_TLS_SOCKET_HH__
3 //------------------------------------------------------------------------------
4 // Copyright (c) 2011-2018 by European Organization for Nuclear Research (CERN)
5 // Author: Michal Simon <simonm@cern.ch>
6 //------------------------------------------------------------------------------
7 // XRootD is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // XRootD is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19 //------------------------------------------------------------------------------
20 
21 #include <string>
22 
23 #include "XrdTls/XrdTls.hh"
24 
25 //----------------------------------------------------------------------------
26 // Forward declarations
27 //----------------------------------------------------------------------------
28 
29 class XrdNetAddrInfo;
30 class XrdSysError;
31 class XrdTlsContext;
32 class XrdTlsPeerCerts;
33 struct XrdTlsSocketImpl;
34 
35 //----------------------------------------------------------------------------
37 //----------------------------------------------------------------------------
38 
40 {
41 public:
42 
43 enum RW_Mode
44 {
49 };
50 
51 enum HS_Mode
52 {
53  TLS_HS_BLOCK = true,
54  TLS_HS_NOBLK = false,
55 };
56 
57 //------------------------------------------------------------------------
76 //------------------------------------------------------------------------
77 
78  XrdTlsSocket( XrdTlsContext &ctx, int sfd, RW_Mode rwm, HS_Mode hsm,
79  bool isClient, bool serial=true );
80 
81 //------------------------------------------------------------------------
84 //------------------------------------------------------------------------
85 
86  XrdTlsSocket();
87 
88 //------------------------------------------------------------------------
90 //------------------------------------------------------------------------
91 
92  ~XrdTlsSocket();
93 
94 //------------------------------------------------------------------------
100 //------------------------------------------------------------------------
101 
102  XrdTls::RC Accept(std::string *eMsg=0);
103 
104 //------------------------------------------------------------------------
114 //------------------------------------------------------------------------
115 
116  XrdTls::RC Connect(const char *thehost=0, std::string *eWhy=0);
117 
118 //------------------------------------------------------------------------
122 //------------------------------------------------------------------------
123 
125 
126 //------------------------------------------------------------------------
135 //------------------------------------------------------------------------
136 
137 XrdTlsPeerCerts *getCerts(bool ver=true);
138 
139 //------------------------------------------------------------------------
163 //------------------------------------------------------------------------
164 
165  const char *Init( XrdTlsContext &ctx, int sfd, RW_Mode rwm, HS_Mode hsm,
166  bool isClient, bool serial=true, const char *tid="" );
167 
168 //------------------------------------------------------------------------
177 //------------------------------------------------------------------------
178 
179  XrdTls::RC Peek( char *buffer, size_t size, int &bytesPeek );
180 
181 //------------------------------------------------------------------------
191 //------------------------------------------------------------------------
192 
193  int Pending(bool any=true);
194 
195 //------------------------------------------------------------------------
197 //
204 //------------------------------------------------------------------------
205 
206  XrdTls::RC Read( char *buffer, size_t size, int &bytesRead );
207 
208 //------------------------------------------------------------------------
212 //------------------------------------------------------------------------
213 
214  void SetTraceID(const char *tid);
215 
216 //------------------------------------------------------------------------
223 //------------------------------------------------------------------------
224 
225  enum SDType {sdForce = 1, sdImmed = 2, sdWait = 3};
226 
227  void Shutdown(SDType=sdImmed);
228 
229 //------------------------------------------------------------------------
238 //------------------------------------------------------------------------
239 
240  XrdTls::RC Write( const char *buffer, size_t size, int &bytesOut );
241 
242 //------------------------------------------------------------------------
245 //------------------------------------------------------------------------
246 
247  bool NeedHandShake();
248 
249 //------------------------------------------------------------------------
251 //------------------------------------------------------------------------
252 
253  const char *Version();
254 
255 private:
256 
257 void AcceptEMsg(std::string *eWhy, const char *reason);
258 int Diagnose(const char *what, int sslrc, int tcode);
259 std::string Err2Text(int sslerr);
260 bool NeedHS();
261 bool Wait4OK(bool wantRead);
262 
263 XrdTlsSocketImpl *pImpl;
264 };
265 #endif // __XRD_TLS_IO_HH__
#define eMsg(x)
Socket wrapper for TLS I/O.
Definition: XrdTlsSocket.hh:40
@ TLS_HS_BLOCK
Always block during handshake.
Definition: XrdTlsSocket.hh:53
@ TLS_HS_NOBLK
Do not block during handshake.
Definition: XrdTlsSocket.hh:54
XrdTlsContext * Context()
XrdTls::RC Accept(std::string *eMsg=0)
void Shutdown(SDType=sdImmed)
~XrdTlsSocket()
Destructor.
@ TLS_RNB_WBL
Non-blocking read blocking write.
Definition: XrdTlsSocket.hh:46
@ TLS_RBL_WNB
blocking read non-blocking write
Definition: XrdTlsSocket.hh:47
@ TLS_RBL_WBL
blocking read blocking write
Definition: XrdTlsSocket.hh:48
@ TLS_RNB_WNB
Non-blocking read non-blocking write.
Definition: XrdTlsSocket.hh:45
bool NeedHandShake()
XrdTls::RC Write(const char *buffer, size_t size, int &bytesOut)
const char * Version()
XrdTls::RC Read(char *buffer, size_t size, int &bytesRead)
Read from the TLS connection. If necessary, a handshake will be done.
const char * Init(XrdTlsContext &ctx, int sfd, RW_Mode rwm, HS_Mode hsm, bool isClient, bool serial=true, const char *tid="")
XrdTls::RC Connect(const char *thehost=0, std::string *eWhy=0)
void SetTraceID(const char *tid)
int Pending(bool any=true)
XrdTls::RC Peek(char *buffer, size_t size, int &bytesPeek)
XrdTlsPeerCerts * getCerts(bool ver=true)