CPPMyth
Library to interoperate with MythTV server
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 
29 namespace NSROOT
30 {
31  class SecureSocket;
32 
34  {
35  public:
36  static SSLSessionFactory& Instance();
37  static void Destroy();
38  bool isEnabled() const { return m_enabled; }
39  SecureSocket* NewSocket();
40 
41  private:
45  SSLSessionFactory& operator=(const SSLSessionFactory&);
46 
47  static SSLSessionFactory* m_instance;
48  bool m_enabled;
49  void* m_ctx;
50  };
51 
52  class SecureSocket : public TcpSocket
53  {
54  friend class SSLSessionFactory;
55  public:
56  virtual ~SecureSocket();
57 
58  // Overrides TcpSocket
59  bool Connect(const char *server, unsigned port, int rcvbuf);
60  bool SendData(const char* buf, size_t size);
61  size_t ReceiveData(void* buf, size_t n);
62  void Disconnect();
63  bool IsValid() const;
64 
65  bool IsCertificateValid(std::string& info);
66 
67  private:
68  SecureSocket(void* ssl);
69 
70  void* m_ssl;
71  void* m_cert;
72  bool m_connected;
74  };
75 }
76 
77 #endif /* SECURESOCKET_H */
78 
79 
void * m_ctx
SSL default context for the application.
Definition: securesocket.h:49
int m_ssl_error
SSL error code.
Definition: securesocket.h:73
bool m_enabled
SSL feature status.
Definition: securesocket.h:48
void * m_cert
X509 certificate.
Definition: securesocket.h:71
bool m_connected
SSL session state.
Definition: securesocket.h:72
void * m_ssl
SSL handle.
Definition: securesocket.h:70