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