Logo ROOT   6.16/01
Reference Guide
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
25typedef struct ssl_st SSL;
26typedef struct ssl_ctx_st SSL_CTX;
27
28class TSSLSocket : public TSocket {
29protected:
31
32private:
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
42
43 void WrapWithSSL();
44
45public:
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,
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
@ kMESS_STRING
Definition: MessageTypes.h:34
int Int_t
Definition: RtypesCore.h:41
const char Option_t
Definition: RtypesCore.h:62
#define ClassDef(name, id)
Definition: Rtypes.h:324
ESendRecvOptions
Definition: TSocket.h:50
@ kDefault
Definition: TSocket.h:51
struct ssl_ctx_st SSL_CTX
Definition: civetweb.c:1762
struct ssl_st SSL
Definition: civetweb.c:1760
This class represents an Internet Protocol (IP) address.
Definition: TInetAddress.h:36
Int_t Recv(Int_t &status, Int_t &kind)
Receives a status and a message type.
Definition: TSSLSocket.h:74
Int_t Recv(char *mess, Int_t max)
Receive a character string message of maximum max length.
Definition: TSSLSocket.h:75
Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition: TSSLSocket.cxx:189
SSL * fSSL
Definition: TSSLSocket.h:41
SSL_CTX * fSSLCtx
Definition: TSSLSocket.h:40
static char fgSSLUKey[]
Definition: TSSLSocket.h:37
static char fgSSLCAPath[]
Definition: TSSLSocket.h:35
void WrapWithSSL()
Wraps the socket with OpenSSL.
Definition: TSSLSocket.cxx:35
static char fgSSLCAFile[]
Definition: TSSLSocket.h:34
Int_t Send(const TMessage &mess)
Send a TMessage object.
Definition: TSSLSocket.cxx:254
Int_t Send(Int_t kind)
Send a single message opcode.
Definition: TSSLSocket.h:71
Int_t Send(Int_t status, Int_t kind)
Send a status and a single message opcode.
Definition: TSSLSocket.h:72
static char fgSSLUCert[]
Definition: TSSLSocket.h:36
Int_t SendRaw(const void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Send a raw buffer of specified length.
Definition: TSSLSocket.cxx:263
void Close(Option_t *option="")
Close the SSL connection.
Definition: TSSLSocket.cxx:164
virtual ~TSSLSocket()
Close gracefully the connection, and free SSL structures.
Definition: TSSLSocket.cxx:152
Int_t Send(const char *mess, Int_t kind=kMESS_STRING)
Send a character string buffer.
Definition: TSSLSocket.h:73
static void SetUpSSL(const char *cafile, const char *capath, const char *ucert, const char *ukey)
Set up the static configuration variables.
Definition: TSSLSocket.cxx:174
Int_t Recv(char *mess, Int_t max, Int_t &kind)
Receive a character string message of maximum max length.
Definition: TSSLSocket.h:76
Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt=kDefault)
Receive a raw buffer of specified length bytes.
Definition: TSSLSocket.cxx:198
virtual Int_t Recv(TMessage *&mess)
Receive a TMessage object.
Definition: TSocket.cxx:817
virtual Int_t Send(const TMessage &mess)
Send a TMessage object.
Definition: TSocket.cxx:522
static constexpr double s