00001 //------------------------------------------------------------------------------ 00002 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN) 00003 // Author: Lukasz Janyst <ljanyst@cern.ch> 00004 //------------------------------------------------------------------------------ 00005 // This file is part of the XRootD software suite. 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 // In applying this licence, CERN does not waive the privileges and immunities 00021 // granted to it by virtue of its status as an Intergovernmental Organization 00022 // or submit itself to any jurisdiction. 00023 //------------------------------------------------------------------------------ 00024 00025 #ifndef __XRD_CL_XROOTD_TRANSPORT_HH__ 00026 #define __XRD_CL_XROOTD_TRANSPORT_HH__ 00027 00028 #include "XrdCl/XrdClPostMaster.hh" 00029 #include "XProtocol/XProtocol.hh" 00030 #include "XrdSec/XrdSecInterface.hh" 00031 #include "XrdOuc/XrdOucEnv.hh" 00032 00033 class XrdSysPlugin; 00034 class XrdSecProtect; 00035 00036 namespace XrdCl 00037 { 00038 class Tls; 00039 class Socket; 00040 struct XRootDChannelInfo; 00041 struct PluginUnloadHandler; 00042 00043 //---------------------------------------------------------------------------- 00045 //---------------------------------------------------------------------------- 00046 struct XRootDQuery 00047 { 00048 static const uint16_t ServerFlags = 1002; 00049 static const uint16_t ProtocolVersion = 1003; 00050 }; 00051 00052 //---------------------------------------------------------------------------- 00054 //---------------------------------------------------------------------------- 00055 class XRootDTransport: public TransportHandler 00056 { 00057 public: 00058 //------------------------------------------------------------------------ 00060 //------------------------------------------------------------------------ 00061 XRootDTransport(); 00062 00063 //------------------------------------------------------------------------ 00065 //------------------------------------------------------------------------ 00066 ~XRootDTransport(); 00067 00068 //------------------------------------------------------------------------ 00079 //------------------------------------------------------------------------ 00080 virtual Status GetHeader( Message *message, Socket *socket ); 00081 00082 //------------------------------------------------------------------------ 00091 //------------------------------------------------------------------------ 00092 virtual Status GetBody( Message *message, Socket *socket ); 00093 00094 //------------------------------------------------------------------------ 00096 //------------------------------------------------------------------------ 00097 virtual void InitializeChannel( const URL &url, 00098 AnyObject &channelData ); 00099 00100 //------------------------------------------------------------------------ 00102 //------------------------------------------------------------------------ 00103 virtual void FinalizeChannel( AnyObject &channelData ); 00104 00105 //------------------------------------------------------------------------ 00107 //------------------------------------------------------------------------ 00108 virtual Status HandShake( HandShakeData *handShakeData, 00109 AnyObject &channelData ); 00110 00111 //------------------------------------------------------------------------ 00112 // @return true if handshake has been done and stream is connected, 00113 // false otherwise 00114 //------------------------------------------------------------------------ 00115 virtual bool HandShakeDone( HandShakeData *handShakeData, 00116 AnyObject &channelData ); 00117 00118 //------------------------------------------------------------------------ 00120 //------------------------------------------------------------------------ 00121 virtual bool IsStreamTTLElapsed( time_t time, 00122 AnyObject &channelData ); 00123 00124 //------------------------------------------------------------------------ 00127 //------------------------------------------------------------------------ 00128 virtual Status IsStreamBroken( time_t inactiveTime, 00129 AnyObject &channelData ); 00130 00131 //------------------------------------------------------------------------ 00137 //------------------------------------------------------------------------ 00138 virtual PathID Multiplex( Message *msg, 00139 AnyObject &channelData, 00140 PathID *hint = 0 ); 00141 00142 //------------------------------------------------------------------------ 00148 //------------------------------------------------------------------------ 00149 virtual PathID MultiplexSubStream( Message *msg, 00150 AnyObject &channelData, 00151 PathID *hint = 0 ); 00152 00153 //------------------------------------------------------------------------ 00155 //------------------------------------------------------------------------ 00156 virtual uint16_t SubStreamNumber( AnyObject &channelData ); 00157 00158 //------------------------------------------------------------------------ 00161 //------------------------------------------------------------------------ 00162 virtual bool NeedControlConnection() 00163 { 00164 return true; 00165 } 00166 00167 //------------------------------------------------------------------------ 00169 //------------------------------------------------------------------------ 00170 static Status MarshallRequest( Message *msg ); 00171 00172 //------------------------------------------------------------------------ 00175 //------------------------------------------------------------------------ 00176 static Status UnMarshallRequest( Message *msg ); 00177 00178 //------------------------------------------------------------------------ 00180 //------------------------------------------------------------------------ 00181 static Status UnMarshallBody( Message *msg, uint16_t reqType ); 00182 00183 //------------------------------------------------------------------------ 00185 //------------------------------------------------------------------------ 00186 static void UnMarshallHeader( Message *msg ); 00187 00188 //------------------------------------------------------------------------ 00190 //------------------------------------------------------------------------ 00191 static void LogErrorResponse( const Message &msg ); 00192 00193 //------------------------------------------------------------------------ 00195 //------------------------------------------------------------------------ 00196 static uint16_t NbConnectedStrm( AnyObject &channelData ); 00197 00198 //------------------------------------------------------------------------ 00200 //------------------------------------------------------------------------ 00201 virtual void Disconnect( AnyObject &channelData, 00202 uint16_t subStreamId ); 00203 00204 //------------------------------------------------------------------------ 00206 //------------------------------------------------------------------------ 00207 virtual Status Query( uint16_t query, 00208 AnyObject &result, 00209 AnyObject &channelData ); 00210 00211 //------------------------------------------------------------------------ 00213 //------------------------------------------------------------------------ 00214 static void SetDescription( Message *msg ); 00215 00216 //------------------------------------------------------------------------ 00218 //------------------------------------------------------------------------ 00219 virtual uint32_t MessageReceived( Message *msg, 00220 uint16_t subStream, 00221 AnyObject &channelData ); 00222 00223 //------------------------------------------------------------------------ 00225 //------------------------------------------------------------------------ 00226 virtual void MessageSent( Message *msg, 00227 uint16_t subStream, 00228 uint32_t bytesSent, 00229 AnyObject &channelData ); 00230 00231 //------------------------------------------------------------------------ 00233 //------------------------------------------------------------------------ 00234 virtual Status GetSignature( Message *toSign, Message *&sign, 00235 AnyObject &channelData ); 00236 00237 //------------------------------------------------------------------------ 00239 //------------------------------------------------------------------------ 00240 virtual Status GetSignature( Message *toSign, Message *&sign, 00241 XRootDChannelInfo *info ); 00242 00243 //------------------------------------------------------------------------ 00245 //------------------------------------------------------------------------ 00246 virtual void WaitBeforeExit(); 00247 00248 //------------------------------------------------------------------------ 00250 //------------------------------------------------------------------------ 00251 virtual bool NeedEncryption( HandShakeData *handShakeData, 00252 AnyObject &channelData ); 00253 00254 private: 00255 00256 //------------------------------------------------------------------------ 00257 // Hand shake the main stream 00258 //------------------------------------------------------------------------ 00259 Status HandShakeMain( HandShakeData *handShakeData, 00260 AnyObject &channelData ); 00261 00262 //------------------------------------------------------------------------ 00263 // Hand shake a parallel stream 00264 //------------------------------------------------------------------------ 00265 Status HandShakeParallel( HandShakeData *handShakeData, 00266 AnyObject &channelData ); 00267 00268 //------------------------------------------------------------------------ 00269 // Generate the message to be sent as an initial handshake 00270 // (handshake + kXR_protocol) 00271 //------------------------------------------------------------------------ 00272 Message *GenerateInitialHSProtocol( HandShakeData *hsData, 00273 XRootDChannelInfo *info, 00274 kXR_char expect ); 00275 00276 //------------------------------------------------------------------------ 00277 // Process the server initial handshake response 00278 //------------------------------------------------------------------------ 00279 Status ProcessServerHS( HandShakeData *hsData, 00280 XRootDChannelInfo *info ); 00281 00282 //----------------------------------------------------------------------- 00283 // Process the protocol response 00284 //------------------------------------------------------------------------ 00285 Status ProcessProtocolResp( HandShakeData *hsData, 00286 XRootDChannelInfo *info ); 00287 00288 //------------------------------------------------------------------------ 00289 // Generate the bind message 00290 //------------------------------------------------------------------------ 00291 Message *GenerateBind( HandShakeData *hsData, 00292 XRootDChannelInfo *info ); 00293 00294 //------------------------------------------------------------------------ 00295 // Generate the bind message 00296 //------------------------------------------------------------------------ 00297 Status ProcessBindResp( HandShakeData *hsData, 00298 XRootDChannelInfo *info ); 00299 00300 //------------------------------------------------------------------------ 00301 // Generate the login message 00302 //------------------------------------------------------------------------ 00303 Message *GenerateLogIn( HandShakeData *hsData, 00304 XRootDChannelInfo *info ); 00305 00306 //------------------------------------------------------------------------ 00307 // Process the login response 00308 //------------------------------------------------------------------------ 00309 Status ProcessLogInResp( HandShakeData *hsData, 00310 XRootDChannelInfo *info ); 00311 00312 //------------------------------------------------------------------------ 00313 // Do the authentication 00314 //------------------------------------------------------------------------ 00315 Status DoAuthentication( HandShakeData *hsData, 00316 XRootDChannelInfo *info ); 00317 00318 //------------------------------------------------------------------------ 00319 // Get the initial credentials using one of the protocols 00320 //------------------------------------------------------------------------ 00321 Status GetCredentials( XrdSecCredentials *&credentials, 00322 HandShakeData *hsData, 00323 XRootDChannelInfo *info ); 00324 00325 //------------------------------------------------------------------------ 00326 // Clean up the data structures created for the authentication process 00327 //------------------------------------------------------------------------ 00328 Status CleanUpAuthentication( XRootDChannelInfo *info ); 00329 00330 //------------------------------------------------------------------------ 00331 // Clean up the data structures created for the protection purposes 00332 //------------------------------------------------------------------------ 00333 Status CleanUpProtection( XRootDChannelInfo *info ); 00334 00335 //------------------------------------------------------------------------ 00336 // Get the authentication function handle 00337 //------------------------------------------------------------------------ 00338 XrdSecGetProt_t GetAuthHandler(); 00339 00340 //------------------------------------------------------------------------ 00341 // Generate the end session message 00342 //------------------------------------------------------------------------ 00343 Message *GenerateEndSession( HandShakeData *hsData, 00344 XRootDChannelInfo *info ); 00345 00346 //------------------------------------------------------------------------ 00347 // Process the end session response 00348 //------------------------------------------------------------------------ 00349 Status ProcessEndSessionResp( HandShakeData *hsData, 00350 XRootDChannelInfo *info ); 00351 00352 //------------------------------------------------------------------------ 00353 // Get a string representation of the server flags 00354 //------------------------------------------------------------------------ 00355 static std::string ServerFlagsToStr( uint32_t flags ); 00356 00357 //------------------------------------------------------------------------ 00358 // Get a string representation of file handle 00359 //------------------------------------------------------------------------ 00360 static std::string FileHandleToStr( const unsigned char handle[4] ); 00361 00362 friend struct PluginUnloadHandler; 00363 PluginUnloadHandler *pSecUnloadHandler; 00364 }; 00365 } 00366 00367 #endif // __XRD_CL_XROOTD_TRANSPORT_HANDLER_HH__