forked from ravinet/mahimahi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecure_socket.hh
57 lines (39 loc) · 1.1 KB
/
secure_socket.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* -*-mode:c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* run: sudo apt-get install libssl-dev */
#ifndef SECURE_SOCKET_HH
#define SECURE_SOCKET_HH
#include <openssl/ssl.h>
#include <openssl/err.h>
#include "socket.hh"
enum SSL_MODE { CLIENT, SERVER };
class SecureSocket : public Socket
{
friend class SSLContext;
private:
SSL *ssl_;
SecureSocket( Socket && sock, SSL *ssl );
public:
~SecureSocket();
void connect( void );
void accept( void );
/* forbid copying or assignment */
SecureSocket( const SecureSocket & ) = delete;
SecureSocket & operator=( const SecureSocket & ) = delete;
/* allow moving */
SecureSocket( SecureSocket && other );
std::string read( void );
void write( const std::string & message );
};
class SSLContext
{
private:
SSL_CTX *ctx_;
public:
SSLContext( const SSL_MODE type );
~SSLContext();
SecureSocket new_secure_socket( Socket && sock );
/* forbid copying or assignment */
SSLContext( const SSLContext & ) = delete;
SSLContext & operator=( const SSLContext & ) = delete;
};
#endif