TDME2  1.9.200
SecureTCPSocket.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <openssl/types.h>
4 #include <openssl/x509.h>
5 
6 #include <string>
7 #include <vector>
8 
9 #include <tdme/tdme.h>
13 
14 using std::string;
15 using std::vector;
16 
19 
20 /**
21  * Class representing a secure TCP socket
22  * @author Andreas Drewke
23  */
25  public:
26  // forbid class copy
28 
29  /**
30  * Public Constructor
31  */
33 
34  /**
35  * Public destructor
36  */
37  virtual ~SecureTCPSocket();
38 
39  /**
40  * Connects a socket to given remote IP and port
41  * @param hostname hostname
42  * @param port port
43  * @throws tdme::os::network::NetworkSocketException
44  */
45  void connect(const string& hostname, const unsigned int port);
46 
47  /**
48  * Reads up to "bytes" bytes from socket
49  * @param buf buffer to write to
50  * @param bytes bytes to receive
51  * @throws tdme::os::network::NetworkIOException
52  * @return bytes read
53  */
54  size_t read(void* buf, const size_t bytes);
55 
56  /**
57  * Writes up to "bytes" bytes to socket
58  * @param buf buffer to read from
59  * @param bytes bytes to send
60  * @throws tdme::os::network::NetworkIOException
61  * @return bytes written
62  */
63  size_t write(void* buf, const size_t bytes);
64 
65  /**
66  * shuts socket down for reading and writing
67  */
68  virtual void shutdown();
69 
70  /**
71  * Closes the socket
72  */
73  virtual void close();
74 
75  private:
76  /**
77  * OpenSSL verify callback
78  * @param preverify preverify
79  * @param x509_ctx x509_ctx
80  */
81  static int openSSLVerifyCallback(int preverify, X509_STORE_CTX* x509_ctx);
82 
83  /**
84  * @return OpenSSL get errors
85  */
86  const string openSSLGetErrors();
87 
88  //
89  SSL* ssl = nullptr;
90  SSL_CTX* ctx = nullptr;
91  BIO* bio = nullptr, *out = nullptr;
92 };
93 
Class representing a secure TCP socket.
static int openSSLVerifyCallback(int preverify, X509_STORE_CTX *x509_ctx)
OpenSSL verify callback.
size_t read(void *buf, const size_t bytes)
Reads up to "bytes" bytes from socket.
size_t write(void *buf, const size_t bytes)
Writes up to "bytes" bytes to socket.
virtual void close()
Closes the socket.
virtual void shutdown()
shuts socket down for reading and writing
void connect(const string &hostname, const unsigned int port)
Connects a socket to given remote IP and port.
virtual ~SecureTCPSocket()
Public destructor.
Class representing a TCP socket.
Definition: TCPSocket.h:15
Mutex implementation.
Definition: Mutex.h:19
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6