ROOT logo
// @(#)root/net:$Id: TSSLSocket.h
// Author: Alejandro Alvarez 16/09/2011

/*************************************************************************
 * Copyright (C) 1995-2011, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TSSLSocket
#define ROOT_TSSLSocket

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TSSLSocket                                                           //
//                                                                      //
// A TSocket wrapped in by SSL.                                         //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TSocket
#include "TSocket.h"
#endif

typedef struct ssl_st     SSL;
typedef struct ssl_ctx_st SSL_CTX;

class TSSLSocket : public TSocket {
protected:
   TSSLSocket() : TSocket() {}

private:
   // CA, client cert/key... are class properties
   static char fgSSLCAFile[];
   static char fgSSLCAPath[];
   static char fgSSLUCert[];
   static char fgSSLUKey[];

   // Object properties
   SSL_CTX *fSSLCtx;
   SSL     *fSSL;

   void WrapWithSSL();

public:
   TSSLSocket(TInetAddress addr, const char *service, Int_t tcpwindowsize = -1);
   TSSLSocket(TInetAddress addr, Int_t port, Int_t tcpwindowsize = -1);
   TSSLSocket(const char *host, const char *service, Int_t tcpwindowsize = -1);
   TSSLSocket(const char *url, Int_t port, Int_t tcpwindowsize = -1);
   TSSLSocket(const char *sockpath);
   TSSLSocket(Int_t desc);
   TSSLSocket(Int_t desc, const char *sockpath);
   TSSLSocket(const TSSLSocket &s);
   virtual ~TSSLSocket();

   void  Close(Option_t *option="");

   // Set up the SSL environment for the next instantiation
   static void SetUpSSL(const char *cafile, const char *capath,
                        const char *ucert,  const char *ukey);

   // The rest of the Send and Recv calls rely ultimately on these,
   // so it is enough to overload them
   Int_t Recv(TMessage *&mess);
   Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt = kDefault);
   Int_t Send(const TMessage &mess);
   Int_t SendRaw(const void *buffer, Int_t length,
                 ESendRecvOptions opt = kDefault);

   // Issue with hidden method :(
   Int_t Send(Int_t kind)                                  { return TSocket::Send(kind); }
   Int_t Send(Int_t status, Int_t kind)                    { return TSocket::Send(status, kind); }
   Int_t Send(const char *mess, Int_t kind = kMESS_STRING) { return TSocket::Send(mess, kind); }
   Int_t Recv(Int_t &status, Int_t &kind)                  { return TSocket::Recv(status, kind); }
   Int_t Recv(char *mess, Int_t max)                       { return TSocket::Recv(mess, max); }
   Int_t Recv(char *mess, Int_t max, Int_t &kind)          { return TSocket::Recv(mess, max, kind); }

   ClassDef(TSSLSocket,0)  // SSL wrapped socket
};

#endif
 TSSLSocket.h:1
 TSSLSocket.h:2
 TSSLSocket.h:3
 TSSLSocket.h:4
 TSSLSocket.h:5
 TSSLSocket.h:6
 TSSLSocket.h:7
 TSSLSocket.h:8
 TSSLSocket.h:9
 TSSLSocket.h:10
 TSSLSocket.h:11
 TSSLSocket.h:12
 TSSLSocket.h:13
 TSSLSocket.h:14
 TSSLSocket.h:15
 TSSLSocket.h:16
 TSSLSocket.h:17
 TSSLSocket.h:18
 TSSLSocket.h:19
 TSSLSocket.h:20
 TSSLSocket.h:21
 TSSLSocket.h:22
 TSSLSocket.h:23
 TSSLSocket.h:24
 TSSLSocket.h:25
 TSSLSocket.h:26
 TSSLSocket.h:27
 TSSLSocket.h:28
 TSSLSocket.h:29
 TSSLSocket.h:30
 TSSLSocket.h:31
 TSSLSocket.h:32
 TSSLSocket.h:33
 TSSLSocket.h:34
 TSSLSocket.h:35
 TSSLSocket.h:36
 TSSLSocket.h:37
 TSSLSocket.h:38
 TSSLSocket.h:39
 TSSLSocket.h:40
 TSSLSocket.h:41
 TSSLSocket.h:42
 TSSLSocket.h:43
 TSSLSocket.h:44
 TSSLSocket.h:45
 TSSLSocket.h:46
 TSSLSocket.h:47
 TSSLSocket.h:48
 TSSLSocket.h:49
 TSSLSocket.h:50
 TSSLSocket.h:51
 TSSLSocket.h:52
 TSSLSocket.h:53
 TSSLSocket.h:54
 TSSLSocket.h:55
 TSSLSocket.h:56
 TSSLSocket.h:57
 TSSLSocket.h:58
 TSSLSocket.h:59
 TSSLSocket.h:60
 TSSLSocket.h:61
 TSSLSocket.h:62
 TSSLSocket.h:63
 TSSLSocket.h:64
 TSSLSocket.h:65
 TSSLSocket.h:66
 TSSLSocket.h:67
 TSSLSocket.h:68
 TSSLSocket.h:69
 TSSLSocket.h:70
 TSSLSocket.h:71
 TSSLSocket.h:72
 TSSLSocket.h:73
 TSSLSocket.h:74
 TSSLSocket.h:75
 TSSLSocket.h:76
 TSSLSocket.h:77
 TSSLSocket.h:78
 TSSLSocket.h:79
 TSSLSocket.h:80
 TSSLSocket.h:81
 TSSLSocket.h:82
 TSSLSocket.h:83