00001 #ifndef __XRD_TLS_SOCKET_HH__ 00002 #define __XRD_TLS_SOCKET_HH__ 00003 //------------------------------------------------------------------------------ 00004 // Copyright (c) 2011-2018 by European Organization for Nuclear Research (CERN) 00005 // Author: Michal Simon <simonm@cern.ch> 00006 //------------------------------------------------------------------------------ 00007 // XRootD is free software: you can redistribute it and/or modify 00008 // it under the terms of the GNU Lesser General Public License as published by 00009 // the Free Software Foundation, either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // XRootD is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU Lesser General Public License 00018 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 00019 //------------------------------------------------------------------------------ 00020 00021 #include <string> 00022 00023 #include "XrdTls/XrdTls.hh" 00024 00025 //---------------------------------------------------------------------------- 00026 // Forward declarations 00027 //---------------------------------------------------------------------------- 00028 00029 class XrdNetAddrInfo; 00030 class XrdSysError; 00031 class XrdTlsContext; 00032 class XrdTlsPeerCerts; 00033 struct XrdTlsSocketImpl; 00034 00035 //---------------------------------------------------------------------------- 00037 //---------------------------------------------------------------------------- 00038 00039 class XrdTlsSocket 00040 { 00041 public: 00042 00043 enum RW_Mode 00044 { 00045 TLS_RNB_WNB, 00046 TLS_RNB_WBL, 00047 TLS_RBL_WNB, 00048 TLS_RBL_WBL 00049 }; 00050 00051 enum HS_Mode 00052 { 00053 TLS_HS_BLOCK = true, 00054 TLS_HS_NOBLK = false, 00055 }; 00056 00057 //------------------------------------------------------------------------ 00073 //------------------------------------------------------------------------ 00074 00075 XrdTlsSocket( XrdTlsContext &ctx, int sfd, RW_Mode rwm, 00076 HS_Mode hsm, bool isClient ); 00077 00078 //------------------------------------------------------------------------ 00081 //------------------------------------------------------------------------ 00082 00083 XrdTlsSocket(); 00084 00085 //------------------------------------------------------------------------ 00087 //------------------------------------------------------------------------ 00088 00089 ~XrdTlsSocket(); 00090 00091 //------------------------------------------------------------------------ 00097 //------------------------------------------------------------------------ 00098 00099 XrdTls::RC Accept(std::string *eMsg=0); 00100 00101 //------------------------------------------------------------------------ 00111 //------------------------------------------------------------------------ 00112 00113 XrdTls::RC Connect(const char *thehost=0, std::string *eWhy=0); 00114 00115 //------------------------------------------------------------------------ 00119 //------------------------------------------------------------------------ 00120 00121 XrdTlsContext *Context(); 00122 00123 //------------------------------------------------------------------------ 00132 //------------------------------------------------------------------------ 00133 00134 XrdTlsPeerCerts *getCerts(bool ver=true); 00135 00136 //------------------------------------------------------------------------ 00157 //------------------------------------------------------------------------ 00158 00159 const char *Init( XrdTlsContext &ctx, int sfd, RW_Mode rwm, HS_Mode hsm, 00160 bool isClient, const char *tid="" ); 00161 00162 //------------------------------------------------------------------------ 00171 //------------------------------------------------------------------------ 00172 00173 XrdTls::RC Peek( char *buffer, size_t size, int &bytesPeek ); 00174 00175 //------------------------------------------------------------------------ 00185 //------------------------------------------------------------------------ 00186 00187 int Pending(bool any=true); 00188 00189 //------------------------------------------------------------------------ 00191 // 00198 //------------------------------------------------------------------------ 00199 00200 XrdTls::RC Read( char *buffer, size_t size, int &bytesRead ); 00201 00202 //------------------------------------------------------------------------ 00206 //------------------------------------------------------------------------ 00207 00208 void SetTraceID(const char *tid); 00209 00210 //------------------------------------------------------------------------ 00217 //------------------------------------------------------------------------ 00218 00219 enum SDType {sdForce = 1, sdImmed = 2, sdWait = 3}; 00220 00221 void Shutdown(SDType=sdImmed); 00222 00223 //------------------------------------------------------------------------ 00232 //------------------------------------------------------------------------ 00233 00234 XrdTls::RC Write( const char *buffer, size_t size, int &bytesOut ); 00235 00236 //------------------------------------------------------------------------ 00239 //------------------------------------------------------------------------ 00240 00241 bool NeedHandShake(); 00242 00243 //------------------------------------------------------------------------ 00245 //------------------------------------------------------------------------ 00246 00247 const char *Version(); 00248 00249 private: 00250 00251 void AcceptEMsg(std::string *eWhy, const char *reason); 00252 int Diagnose(const char *what, int sslrc, int tcode); 00253 std::string Err2Text(int sslerr); 00254 bool Wait4OK(bool wantRead); 00255 00256 XrdTlsSocketImpl *pImpl; 00257 }; 00258 #endif // __XRD_TLS_IO_HH__