21 #ifndef G_SSL_MBEDTLS__H
22 #define G_SSL_MBEDTLS__H
26 #include <mbedtls/ssl.h>
27 #include <mbedtls/ssl_ciphersuites.h>
28 #include <mbedtls/entropy.h>
29 #if GCONFIG_HAVE_MBEDTLS_NET_H
30 #include <mbedtls/net.h>
32 #include <mbedtls/net_sockets.h>
34 #include <mbedtls/ctr_drbg.h>
35 #include <mbedtls/certs.h>
36 #include <mbedtls/error.h>
37 #include <mbedtls/version.h>
38 #include <mbedtls/pem.h>
39 #include <mbedtls/base64.h>
40 #include <mbedtls/debug.h>
41 #include <mbedtls/md5.h>
42 #include <mbedtls/sha1.h>
43 #include <mbedtls/sha256.h>
44 #include <mbedtls/sha512.h>
74 void load(
const std::string & file ) ;
76 mbedtls_x509_crt * ptr() ;
77 mbedtls_x509_crt * ptr()
const ;
96 mbedtls_ctr_drbg_context * ptr() ;
97 mbedtls_ctr_drbg_context * ptr()
const ;
101 void operator=(
const Rng & ) ;
104 mbedtls_ctr_drbg_context x ;
105 mbedtls_entropy_context entropy ;
116 void load(
const std::string & file ) ;
117 mbedtls_pk_context * ptr() ;
118 mbedtls_pk_context * ptr()
const ;
122 void operator=(
const Key & ) ;
125 mbedtls_pk_context x ;
134 explicit Context(
const mbedtls_ssl_config * ) ;
136 mbedtls_ssl_context * ptr() ;
137 mbedtls_ssl_context * ptr()
const ;
141 void operator=(
const Context & ) ;
144 mbedtls_ssl_context x ;
153 explicit Error(
const std::string & ) ;
154 Error(
const std::string & ,
int rc ,
const std::string & more = std::string() ) ;
155 virtual ~
Error() g__noexcept ;
156 virtual const char * what()
const g__noexcept override ;
169 SecureFile(
const std::string & path ,
bool with_nul ) ;
171 const char * p()
const ;
172 const unsigned char * pu()
const ;
173 unsigned char * pu() ;
174 size_t size()
const ;
182 std::vector<char> m_buffer ;
194 bool noverify()
const ;
215 virtual void addProfile(
const std::string & profile_name ,
bool is_server_profile ,
216 const std::string & key_file ,
const std::string & cert_file ,
const std::string & ca_file ,
217 const std::string & default_peer_certificate_name ,
const std::string & default_peer_host_name ,
218 const std::string & profile_config )
override ;
219 virtual bool hasProfile(
const std::string & profile_name )
const override ;
220 virtual const Profile &
profile(
const std::string & profile_name )
const override ;
221 virtual std::string
id()
const override ;
223 virtual Digester digester(
const std::string & ,
const std::string & )
const override ;
224 const Rng & rng()
const ;
225 Library::LogFn log()
const ;
227 static std::string credit(
const std::string & ,
const std::string & ,
const std::string & ) ;
228 static std::string sid() ;
237 typedef std::map<std::string,shared_ptr<ProfileImp> > Map ;
238 Library::LogFn m_log_fn ;
256 const std::string & cert_file ,
const std::string & ca_file ,
257 const std::string & default_peer_certificate_name ,
const std::string & default_peer_host_name ,
258 const std::string & profile_config ) ;
261 const mbedtls_ssl_config * config()
const ;
262 mbedtls_x509_crl * crl()
const ;
263 void logAt(
int level_out , std::string )
const ;
264 const std::string & defaultPeerCertificateName()
const ;
265 const std::string & defaultPeerHostName()
const ;
270 static void onDebug(
void * ,
int ,
const char * ,
int ,
const char * ) ;
271 void doDebug(
int ,
const char * ,
int ,
const char * ) ;
275 const std::string m_default_peer_certificate_name ;
276 const std::string m_default_peer_host_name ;
277 mbedtls_ssl_config m_config ;
279 Certificate m_certificate ;
280 Certificate m_ca_list ;
289 typedef Protocol::Result Result ;
298 virtual Result
read(
char * buffer ,
size_t buffer_size_in , ssize_t & data_size_out )
override ;
299 virtual Result
write(
const char * buffer ,
size_t data_size_in , ssize_t & data_size_out )
override ;
300 virtual Result
stop()
override ;
303 virtual bool verified()
const override ;
305 static int doSend(
void * ,
const unsigned char * ,
size_t ) ;
306 static int doRecv(
void * ,
unsigned char * ,
size_t ) ;
307 static int doRecvTimeout(
void * ,
unsigned char * ,
size_t , uint32_t ) ;
308 std::string protocol()
const ;
309 std::string cipher()
const ;
310 const Profile & profile()
const ;
315 Result convert(
const char * ,
int ,
bool more =
false ) ;
317 std::string getPeerCertificate() ;
318 std::string verifyResultString(
int ) ;
324 std::string m_peer_certificate ;
325 std::string m_peer_certificate_chain ;
335 DigesterImp(
const std::string & ,
const std::string & ) ;
337 virtual void add(
const std::string & )
override ;
338 virtual std::string
value()
override ;
339 virtual std::string
state()
override ;
340 virtual size_t blocksize()
const override ;
341 virtual size_t valuesize()
const override ;
342 virtual size_t statesize()
const override ;
349 std::string m_hash_type ;
350 mbedtls_md5_context m_md5 ;
351 mbedtls_sha1_context m_sha1 ;
352 mbedtls_sha256_context m_sha256 ;
A base interface for profile classes that work with concrete classes derived from GSsl::LibraryImpBas...
An interface to an underlying TLS library.
An abstract interface for reading and writing from a non-blocking i/o channel.
A base interface for GSsl::Protocol pimple classes.
virtual std::string id() const override
Implements Library::id().
Holds protocol version information, etc.
Holds a mbedtls_ssl_context structure.
An implementation of the GSsl::LibraryImpBase interface for mbedtls.
An exception class for GSsl::MbedTls classes.
virtual ProtocolImpBase * newProtocol(const std::string &, const std::string &) const override
Factory method for a new Protocol object on the heap.
std::vector< std::string > StringArray
A std::vector of std::strings.
virtual const Profile & profile(const std::string &profile_name) const override
Implements Library::profile().
virtual size_t blocksize() const override
Implements Digester::blocksize().
virtual Result connect(G::ReadWrite &) override
Implements Protocol::connect().
Holds a mbedtls_ctr_drbg_context structure.
virtual void add(const std::string &) override
Implements Digester::add().
An implementation of the GSsl::DigesterImpBase interface for MbedTls.
A base interface for GSsl::Digester pimple classes.
An implementation of the GSsl::ProtocolImpBase interface for mbedtls.
virtual Result read(char *buffer, size_t buffer_size_in, ssize_t &data_size_out) override
Implements Protocol::read().
Holds a mbedtls_pk_context structure.
virtual bool verified() const override
Implements Protocol::verified().
virtual bool hasProfile(const std::string &profile_name) const override
Implements Library::hasProfile().
Returns an object that can perform a cryptographic hash.
virtual std::string peerCertificate() const override
Implements Protocol::peerCertificate().
An implementation of the GSsl::Profile interface for mbedtls.
A base interface for GSsl::Library pimple classes.
virtual Result accept(G::ReadWrite &) override
Implements Protocol::accept().
virtual size_t statesize() const override
Implements Digester::statesize().
virtual Result write(const char *buffer, size_t data_size_in, ssize_t &data_size_out) override
Implements Protocol::write().
virtual std::string state() override
Implements Digester::state().
virtual std::string peerCertificateChain() const override
Implements Protocol::peerCertificateChain().
virtual std::string value() override
Implements Digester::value().
virtual Result stop() override
Implements Protocol::stop().
virtual size_t valuesize() const override
Implements Digester::valuesize().
TLS/SSL transport layer security classes.
virtual G::StringArray digesters(bool) const override
Implements Library::digesters().
Holds a mbedtls_x509_crt structure.
virtual Digester digester(const std::string &, const std::string &) const override
Implements Library::digester().
An interface for reading a sensitive file and then overwriting its contents in memory.
virtual void addProfile(const std::string &profile_name, bool is_server_profile, const std::string &key_file, const std::string &cert_file, const std::string &ca_file, const std::string &default_peer_certificate_name, const std::string &default_peer_host_name, const std::string &profile_config) override
Implements Library::addProfile().