CPPMyth
Library to interoperate with MythTV server
Loading...
Searching...
No Matches
securesocket.h
1/*
2 * Copyright (C) 2016 Jean-Luc Barriere
3 *
4 * This library is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; either version 3, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library; see the file COPYING. If not, write to
16 * the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
17 * MA 02110-1301 USA
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 */
21
22#ifndef SECURESOCKET_H
23#define SECURESOCKET_H
24
25#include "socket.h"
26
27#include <string>
28
29namespace NSROOT
30{
31 class SecureSocket;
32
33 class SSLSessionFactory
34 {
35 public:
36 static SSLSessionFactory& Instance();
37 static void Destroy();
38 bool IsEnabled() const { return m_enabled; }
39
46
47 private:
48 SSLSessionFactory();
49 ~SSLSessionFactory();
50 SSLSessionFactory(const SSLSessionFactory&);
51 SSLSessionFactory& operator=(const SSLSessionFactory&);
52
53 static SSLSessionFactory* m_instance;
55 bool m_enabled;
56 };
57
58 class SSLServerContext
59 {
60 public:
61 SSLServerContext() : m_server_ctx(nullptr) { }
62 ~SSLServerContext();
63
71 bool InitContext(const std::string& certfile, const std::string& pkeyfile);
72
79
93 static TcpServerSocket::AcceptStatus SSLHandshake(SecureSocket& socket);
94
95 private:
96 SSLServerContext(const SSLServerContext& other);
97 SSLServerContext& operator=(const SSLServerContext& other);
98
100 };
101
102 class SecureSocket : public TcpSocket
103 {
104 friend class SSLSessionFactory;
105 friend class SSLServerContext;
106 public:
107 virtual ~SecureSocket();
108
109 // Overrides TcpSocket
110 bool Connect(const char *server, unsigned port, int rcvbuf);
111 bool SendData(const char* buf, size_t size);
112 size_t ReceiveData(void* buf, size_t n);
113 size_t BlockingRead(void* buf, size_t n);
114 void Disconnect();
115
116 bool IsCertificateValid(std::string& info);
117
118 const char* GetSSLError();
119
120 private:
121 SecureSocket(void* ssl);
122
123 void* m_ssl;
124 void* m_cert;
127 char* m_errmsg;
128 };
129
130}
131
132#endif /* SECURESOCKET_H */
133
134
SecureSocket * NewServerSocket()
void * m_server_ctx
SSL server context.
bool InitContext(const std::string &certfile, const std::string &pkeyfile)
static TcpServerSocket::AcceptStatus SSLHandshake(SecureSocket &socket)
SecureSocket * NewClientSocket()
bool m_enabled
SSL feature status.
void * m_client_ctx
SSL default client context.
void * m_ssl
SSL handle.
bool m_connected
SSL session state.
int m_ssl_error
SSL error code.
size_t ReceiveData(void *buf, size_t n)
bool SendData(const char *buf, size_t size)
void * m_cert
X509 certificate.
size_t BlockingRead(void *buf, size_t n)
char * m_errmsg
error message buffer
bool Connect(const char *server, unsigned port, int rcvbuf)