Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TSSLSocket.h
Go to the documentation of this file.
1 // @(#)root/net:$Id: TSSLSocket.h
2 // Author: Alejandro Alvarez 16/09/2011
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2011, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TSSLSocket
13 #define ROOT_TSSLSocket
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TSSLSocket //
18 // //
19 // A TSocket wrapped in by SSL. //
20 // //
21 //////////////////////////////////////////////////////////////////////////
22 
23 #include "TSocket.h"
24 
25 typedef struct ssl_st SSL;
26 typedef struct ssl_ctx_st SSL_CTX;
27 
28 class TSSLSocket : public TSocket {
29 protected:
30  TSSLSocket() : TSocket() {}
31 
32 private:
33  // CA, client cert/key... are class properties
34  static char fgSSLCAFile[];
35  static char fgSSLCAPath[];
36  static char fgSSLUCert[];
37  static char fgSSLUKey[];
38 
39  // Object properties
40  SSL_CTX *fSSLCtx;
41  SSL *fSSL;
42 
43  void WrapWithSSL();
44 
45 public:
46  TSSLSocket(TInetAddress addr, const char *service, Int_t tcpwindowsize = -1);
47  TSSLSocket(TInetAddress addr, Int_t port, Int_t tcpwindowsize = -1);
48  TSSLSocket(const char *host, const char *service, Int_t tcpwindowsize = -1);
49  TSSLSocket(const char *url, Int_t port, Int_t tcpwindowsize = -1);
50  TSSLSocket(const char *sockpath);
51  TSSLSocket(Int_t desc);
52  TSSLSocket(Int_t desc, const char *sockpath);
53  TSSLSocket(const TSSLSocket &s);
54  virtual ~TSSLSocket();
55 
56  void Close(Option_t *option="");
57 
58  // Set up the SSL environment for the next instantiation
59  static void SetUpSSL(const char *cafile, const char *capath,
60  const char *ucert, const char *ukey);
61 
62  // The rest of the Send and Recv calls rely ultimately on these,
63  // so it is enough to overload them
64  Int_t Recv(TMessage *&mess);
65  Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt = kDefault);
66  Int_t Send(const TMessage &mess);
67  Int_t SendRaw(const void *buffer, Int_t length,
68  ESendRecvOptions opt = kDefault);
69 
70  // Issue with hidden method :(
71  Int_t Send(Int_t kind) { return TSocket::Send(kind); }
72  Int_t Send(Int_t status, Int_t kind) { return TSocket::Send(status, kind); }
73  Int_t Send(const char *mess, Int_t kind = kMESS_STRING) { return TSocket::Send(mess, kind); }
74  Int_t Recv(Int_t &status, Int_t &kind) { return TSocket::Recv(status, kind); }
75  Int_t Recv(char *mess, Int_t max) { return TSocket::Recv(mess, max); }
76  Int_t Recv(char *mess, Int_t max, Int_t &kind) { return TSocket::Recv(mess, max, kind); }
77 
78  ClassDef(TSSLSocket,0) // SSL wrapped socket
79 };
80 
81 #endif