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 //------------------------------------------------------------------------
73 //------------------------------------------------------------------------
74 
75  XrdTlsSocket( XrdTlsContext &ctx, int sfd, RW_Mode rwm,
76  HS_Mode hsm, bool isClient );
77 
78 //------------------------------------------------------------------------
81 //------------------------------------------------------------------------
82 
83  XrdTlsSocket();
84 
85 //------------------------------------------------------------------------
87 //------------------------------------------------------------------------
88 
89  ~XrdTlsSocket();
90 
91 //------------------------------------------------------------------------
97 //------------------------------------------------------------------------
98 
99  XrdTls::RC Accept(std::string *eMsg=0);
100 
101 //------------------------------------------------------------------------
111 //------------------------------------------------------------------------
112 
113  XrdTls::RC Connect(const char *thehost=0, std::string *eWhy=0);
114 
115 //------------------------------------------------------------------------
119 //------------------------------------------------------------------------
120 
122 
123 //------------------------------------------------------------------------
132 //------------------------------------------------------------------------
133 
134 XrdTlsPeerCerts *getCerts(bool ver=true);
135 
136 //------------------------------------------------------------------------
157 //------------------------------------------------------------------------
158 
159  const char *Init( XrdTlsContext &ctx, int sfd, RW_Mode rwm, HS_Mode hsm,
160  bool isClient, const char *tid="" );
161 
162 //------------------------------------------------------------------------
171 //------------------------------------------------------------------------
172 
173  XrdTls::RC Peek( char *buffer, size_t size, int &bytesPeek );
174 
175 //------------------------------------------------------------------------
185 //------------------------------------------------------------------------
186 
187  int Pending(bool any=true);
188 
189 //------------------------------------------------------------------------
191 //
198 //------------------------------------------------------------------------
199 
200  XrdTls::RC Read( char *buffer, size_t size, int &bytesRead );
201 
202 //------------------------------------------------------------------------
206 //------------------------------------------------------------------------
207 
208  void SetTraceID(const char *tid);
209 
210 //------------------------------------------------------------------------
217 //------------------------------------------------------------------------
218 
219  enum SDType {sdForce = 1, sdImmed = 2, sdWait = 3};
220 
221  void Shutdown(SDType=sdImmed);
222 
223 //------------------------------------------------------------------------
232 //------------------------------------------------------------------------
233 
234  XrdTls::RC Write( const char *buffer, size_t size, int &bytesOut );
235 
236 //------------------------------------------------------------------------
239 //------------------------------------------------------------------------
240 
241  bool NeedHandShake();
242 
243 //------------------------------------------------------------------------
245 //------------------------------------------------------------------------
246 
247  const char *Version();
248 
249 private:
250 
251 void AcceptEMsg(std::string *eWhy, const char *reason);
252 int Diagnose(const char *what, int sslrc, int tcode);
253 std::string Err2Text(int sslerr);
254 bool Wait4OK(bool wantRead);
255 
256 XrdTlsSocketImpl *pImpl;
257 };
258 #endif // __XRD_TLS_IO_HH__
XrdTls::RC Accept(std::string *eMsg=0)
void SetTraceID(const char *tid)
Definition: XrdTlsSocket.hh:219
Always block during handshake.
Definition: XrdTlsSocket.hh:53
Definition: XrdTlsSocket.hh:219
int Diagnose(const char *what, int sslrc, int tcode)
const char * Init(XrdTlsContext &ctx, int sfd, RW_Mode rwm, HS_Mode hsm, bool isClient, const char *tid="")
XrdTls::RC Connect(const char *thehost=0, std::string *eWhy=0)
XrdTls::RC Read(char *buffer, size_t size, int &bytesRead)
Read from the TLS connection. If necessary, a handshake will be done.
bool Wait4OK(bool wantRead)
Socket wrapper for TLS I/O.
Definition: XrdTlsSocket.hh:39
Definition: XrdSysError.hh:89
int Pending(bool any=true)
SDType
Definition: XrdTlsSocket.hh:219
HS_Mode
Definition: XrdTlsSocket.hh:51
RC
Definition: XrdTls.hh:40
blocking read non-blocking write
Definition: XrdTlsSocket.hh:47
~XrdTlsSocket()
Destructor.
RW_Mode
Definition: XrdTlsSocket.hh:43
void AcceptEMsg(std::string *eWhy, const char *reason)
bool NeedHandShake()
std::string Err2Text(int sslerr)
XrdTlsPeerCerts * getCerts(bool ver=true)
blocking read blocking write
Definition: XrdTlsSocket.hh:48
void Shutdown(SDType=sdImmed)
Definition: XrdNetAddrInfo.hh:53
XrdTls::RC Write(const char *buffer, size_t size, int &bytesOut)
Definition: XrdTlsSocket.hh:219
XrdTlsSocketImpl * pImpl
Definition: XrdTlsSocket.hh:256
Definition: XrdTlsContext.hh:36
XrdTlsContext * Context()
XrdTls::RC Peek(char *buffer, size_t size, int &bytesPeek)
Non-blocking read non-blocking write.
Definition: XrdTlsSocket.hh:45
Do not block during handshake.
Definition: XrdTlsSocket.hh:54
Definition: XrdTlsPeerCerts.hh:34
Non-blocking read blocking write.
Definition: XrdTlsSocket.hh:46
const char * Version()