BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
SSLFacility.h
1 #pragma once
2 
3 #include <string>
4 #include <set>
5 
6 #include <Poco/File.h>
7 #include <Poco/Mutex.h>
8 #include <Poco/Net/Context.h>
9 
10 #include "util/Loggable.h"
11 
12 namespace Poco {
13 
14 class Logger;
15 
16 }
17 
18 namespace BeeeOn {
19 
41 public:
42  PrivateKeyPassphraseProvider(const std::string &passphrase);
43  PrivateKeyPassphraseProvider(const std::string &passphrase,
44  Poco::Mutex &lock);
46 
47  void onRequest(const void *sender, std::string &passphrase);
48 
49 private:
50  void init();
51 
52 private:
53  const std::string m_passphrase;
54  Poco::Mutex &m_lock;
55  static Poco::Mutex defaultLock;
56 };
57 
77 class SSLFacility : public Loggable {
78 public:
79  SSLFacility();
80  virtual ~SSLFacility();
81 
82  void setCALocation(const std::string &caLocation);
83  void setLoadDefaultCA(const std::string &enable);
84  void setPrivateKey(const std::string &file);
85  void setPassphrase(const std::string &passphrase);
86  void setCertificate(const std::string &file);
87  void setVerificationMode(const std::string &mode);
88  void setVerificationDepth(int depth);
89  void setCipherList(const std::string &list);
90  void setSessionCache(const std::string &enable);
91  void setDisabledProtocols(const std::string &protocols);
92  void setExtendedCertificateVerification(bool enable);
93 
94  Poco::File caLocation() const;
95  Poco::File privateKey() const;
96  std::string passphrase() const;
97  Poco::File certificate() const;
98  Poco::Net::Context::VerificationMode verificationMode() const;
99  std::set<std::string> disabledProtocols() const;
100  std::string cipherList() const;
101 
102  Poco::Net::Context::Ptr context();
103  void initContext();
104 
105 protected:
106  virtual Poco::Net::Context::Ptr createContext() = 0;
107 
108 protected:
109  using VerificationMode =
110  typename Poco::Net::Context::VerificationMode;
111 
112  Poco::Mutex m_lock;
113  Poco::Net::Context::Ptr m_context;
114  std::string m_caLocation;
115  bool m_loadDefaultCA;
116  std::string m_privateKey;
117  std::string m_passphrase;
118  std::string m_certificate;
119  VerificationMode m_verificationMode;
120  int m_verificationDepth;
121  std::string m_cipherList;
122  bool m_sessionCache;
123  unsigned int m_disabledProtocols;
124  bool m_extendedCertificateVerification;
125 };
126 
127 }
Definition: SSLFacility.h:77
Definition: Loggable.h:19
Definition: SSLFacility.h:40