Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:26

0001 // @(#)root/net:$Id: TSSLSocket.h
0002 // Author: Alejandro Alvarez 16/09/2011
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2011, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TSSLSocket
0013 #define ROOT_TSSLSocket
0014 
0015 //////////////////////////////////////////////////////////////////////////
0016 //                                                                      //
0017 // TSSLSocket                                                           //
0018 //                                                                      //
0019 // A TSocket wrapped in by SSL.                                         //
0020 //                                                                      //
0021 //////////////////////////////////////////////////////////////////////////
0022 
0023 #include "TSocket.h"
0024 
0025 typedef struct ssl_st     SSL;
0026 typedef struct ssl_ctx_st SSL_CTX;
0027 
0028 class TSSLSocket : public TSocket {
0029 protected:
0030    TSSLSocket() : TSocket() {}
0031 
0032 private:
0033    // CA, client cert/key... are class properties
0034    static char fgSSLCAFile[];
0035    static char fgSSLCAPath[];
0036    static char fgSSLUCert[];
0037    static char fgSSLUKey[];
0038 
0039    // Object properties
0040    SSL_CTX *fSSLCtx;
0041    SSL     *fSSL;
0042 
0043    void WrapWithSSL();
0044 
0045 public:
0046    TSSLSocket(TInetAddress addr, const char *service, Int_t tcpwindowsize = -1);
0047    TSSLSocket(TInetAddress addr, Int_t port, Int_t tcpwindowsize = -1);
0048    TSSLSocket(const char *host, const char *service, Int_t tcpwindowsize = -1);
0049    TSSLSocket(const char *url, Int_t port, Int_t tcpwindowsize = -1);
0050    TSSLSocket(const char *sockpath);
0051    TSSLSocket(Int_t desc);
0052    TSSLSocket(Int_t desc, const char *sockpath);
0053    TSSLSocket(const TSSLSocket &s);
0054    virtual ~TSSLSocket();
0055 
0056    void Close(Option_t *option="") override;
0057 
0058    // Set up the SSL environment for the next instantiation
0059    static void SetUpSSL(const char *cafile, const char *capath,
0060                         const char *ucert,  const char *ukey);
0061 
0062    // The rest of the Send and Recv calls rely ultimately on these,
0063    // so it is enough to overload them
0064    Int_t Recv(TMessage *&mess) override;
0065    Int_t RecvRaw(void *buffer, Int_t length, ESendRecvOptions opt = kDefault) override;
0066    Int_t Send(const TMessage &mess) override;
0067    Int_t SendRaw(const void *buffer, Int_t length,
0068                  ESendRecvOptions opt = kDefault) override;
0069 
0070    // Issue with hidden method :(
0071    Int_t Send(Int_t kind) override                         { return TSocket::Send(kind); }
0072    Int_t Send(Int_t status, Int_t kind) override           { return TSocket::Send(status, kind); }
0073    Int_t Send(const char *mess, Int_t kind = kMESS_STRING) override { return TSocket::Send(mess, kind); }
0074    Int_t Recv(Int_t &status, Int_t &kind) override         { return TSocket::Recv(status, kind); }
0075    Int_t Recv(char *mess, Int_t max) override              { return TSocket::Recv(mess, max); }
0076    Int_t Recv(char *mess, Int_t max, Int_t &kind) override { return TSocket::Recv(mess, max, kind); }
0077 
0078    ClassDefOverride(TSSLSocket,0)  // SSL wrapped socket
0079 };
0080 
0081 #endif