DSL
gnutls.h
1 //@AUTOHEADER@BEGIN@
2 /***********************************************************************\
3 | Drift Standard Libraries v1.01 |
4 | Copyright 2010-2023 Drift Solutions / Indy Sams |
5 | Docs and more information available at https://www.driftsolutions.dev |
6 | This file released under the 3-clause BSD license, |
7 | see included DSL.LICENSE.TXT file for details. |
8 \***********************************************************************/
9 //@AUTOHEADER@END@
10 
11 #ifndef __DRIFT_GNUTLS_H__
12 #define __DRIFT_GNUTLS_H__
13 
14 #include <drift/sockets3.h>
15 
16 #if defined(DSL_DLL) && defined(WIN32)
17  #if defined(DSL_GNUTLS_EXPORTS)
18  #define DSL_GNUTLS_API extern "C" __declspec(dllexport)
19  #define DSL_GNUTLS_API_CLASS __declspec(dllexport)
20  #else
21  #define DSL_GNUTLS_API extern "C" __declspec(dllimport)
22  #define DSL_GNUTLS_API_CLASS __declspec(dllimport)
23  #endif
24 #else
25  #define DSL_GNUTLS_API DSL_API_VIS
26  #define DSL_GNUTLS_API_CLASS DSL_API_VIS
27 #endif
28 
29 class DSL_GNUTLS_API_CLASS DSL_SOCKET_GNUTLS: public DSL_SOCKET {
30 public:
31  gnutls_session_t gtls = NULL;
32  bool ssl_is_client = false;
33 };
34 
35 class DSL_GNUTLS_API_CLASS DSL_Sockets3_GnuTLS: public DSL_Sockets3_SSL {
36  protected:
37  virtual DSL_SOCKET * pAllocSocket();
38  virtual int pRecv(DSL_SOCKET * sock, char * buf, uint32 bufsize);
39  virtual int pPeek(DSL_SOCKET * sock, char * buf, uint32 bufsize);
40  virtual int pSend(DSL_SOCKET * sock, const char * buf, uint32 bufsize);
41  virtual int pSelect_Read(DSL_SOCKET * sock, timeval * timeo);
42  virtual void pCloseSSL(DSL_SOCKET * sock);
43  private:
44  gnutls_session_t ctx = NULL;
45  gnutls_certificate_credentials_t gnutls_cred;
46  public:
48  virtual ~DSL_Sockets3_GnuTLS();
49 
50  virtual bool EnableSSL(const char * cert_fn, DS3_SSL_METHOD method);
51  virtual bool SwitchToSSL_Server(DSL_SOCKET * sock);
52  virtual bool SwitchToSSL_Client(DSL_SOCKET * sock);
53 
54  virtual gnutls_session_t GetSSL_CTX();
55 };
56 
57 #endif // __DRIFT_GNUTLS_H__
DS3_SSL_METHOD
Definition: sockets3.h:67