77 explicit Protocol(
const Profile & ,
const std::string & peer_certificate_name = std::string() ,
78 const std::string & peer_host_name = std::string() ) ;
115 Result
read(
char * buffer , std::size_t buffer_size_in , ssize_t & data_size_out ) ;
143 Result
write(
const char * buffer , std::size_t data_size_in , ssize_t & data_size_out ) ;
163 static std::string
str( Result result ) ;
171 std::string
cipher()
const ;
193 void operator=(
const Protocol & ) = delete ;
194 void operator=(
Protocol && ) = delete ;
197 std::unique_ptr<ProtocolImpBase> m_imp ;
215 explicit Digester( std::unique_ptr<DigesterImpBase> ) ;
228 void add(
const std::string & ) ;
231 std::string
state() ;
239 std::string
value() ;
243 std::shared_ptr<DigesterImpBase> m_imp ;
255 using LogFn = void (*)(int,
const std::string &) ;
257 explicit Library(
bool active =
true ,
const std::string & library_config = std::string() ,
272 static void log(
int level ,
const std::string & line ) ;
281 void addProfile(
const std::string & profile_name ,
bool is_server_profile ,
282 const std::string & key_file = std::string() ,
const std::string & cert_file = std::string() ,
283 const std::string & ca_path = std::string() ,
284 const std::string & default_peer_certificate_name = std::string() ,
285 const std::string & default_peer_host_name = std::string() ,
286 const std::string & profile_config = std::string() ) ;
318 bool hasProfile(
const std::string & profile_name )
const ;
321 const Profile &
profile(
const std::string & profile_name )
const ;
329 std::string
id()
const ;
335 std::string
generateKey(
const std::string & name )
const ;
348 static std::string
credit(
const std::string & prefix ,
const std::string & eol ,
const std::string & eot ) ;
351 static std::string
ids() ;
354 static bool enabledAs(
const std::string & profile_name ) ;
366 Digester digester(
const std::string & name ,
const std::string & state = std::string() ,
bool need_state =
false )
const ;
372 void operator=(
const Library & ) = delete ;
373 void operator=(
Library && ) = delete ;
378 static std::unique_ptr<LibraryImpBase> newLibraryImp(
G::StringArray & , Library::LogFn ,
bool ) ;
382 std::unique_ptr<LibraryImpBase> m_imp ;
395 virtual std::string
id()
const = 0 ;
398 virtual void addProfile(
const std::string & ,
bool ,
const std::string & ,
const std::string & ,
399 const std::string & ,
const std::string & ,
const std::string & ,
const std::string & ) = 0 ;
402 virtual bool hasProfile(
const std::string & profile_name )
const = 0 ;
417 virtual std::string
generateKey(
const std::string & )
const = 0 ;
435 virtual std::unique_ptr<ProtocolImpBase>
newProtocol(
const std::string & ,
const std::string & )
const = 0 ;
457 virtual Protocol::Result
read(
char * , std::size_t , ssize_t & ) = 0 ;
460 virtual Protocol::Result
write(
const char * , std::size_t , ssize_t & ) = 0 ;
488 virtual void add(
const std::string & ) = 0 ;
A base interface for GSsl::Digester pimple classes.
virtual std::string state()=0
Implements Digester::state().
virtual std::size_t blocksize() const =0
Implements Digester::blocksize().
virtual ~DigesterImpBase()=default
Destructor.
virtual std::size_t valuesize() const =0
Implements Digester::valuesize().
virtual std::string value()=0
Implements Digester::value().
virtual std::size_t statesize() const =0
Implements Digester::statesize().
virtual void add(const std::string &)=0
Implements Digester::add().
A class for objects that can perform a cryptographic hash.
std::size_t valuesize() const
Returns the hash function's value size in bytes.
std::size_t statesize() const
Returns the size of the state() string in bytes, or zero if state() is not implemented.
std::string value()
Returns the hash value.
void add(const std::string &)
Adds data of arbitrary size.
std::size_t blocksize() const
Returns the hash function's block size in bytes.
std::string state()
Returns the intermediate state.
Digester(std::unique_ptr< DigesterImpBase >)
Constructor, used by the Library class.
A base interface for GSsl::Library pimple classes.
virtual ~LibraryImpBase()=default
Destructor.
virtual bool hasProfile(const std::string &profile_name) const =0
Implements Library::hasProfile().
virtual const Profile & profile(const std::string &profile_name) const =0
Implements Library::profile().
virtual Digester digester(const std::string &, const std::string &, bool) const =0
Implements Library::digester().
virtual std::string id() const =0
Implements Library::id().
virtual G::StringArray digesters(bool) const =0
Implements Library::digesters().
virtual bool generateKeyAvailable() const =0
Implements Library::generateKeyAvailable().
static bool consume(G::StringArray &list, const std::string &item)
A convenience function that removes the item from the list and returns true iff is was removed.
virtual std::string generateKey(const std::string &) const =0
Implements Library::generateKey().
virtual void addProfile(const std::string &, bool, const std::string &, const std::string &, const std::string &, const std::string &, const std::string &, const std::string &)=0
Implements Library::addProfile().
A singleton class for initialising the underlying TLS library.
static bool enabledAs(const std::string &profile_name)
A static convenience function that returns true if there is an enabled() Library instance() that has ...
Digester digester(const std::string &name, const std::string &state=std::string(), bool need_state=false) const
Returns a digester object.
bool hasProfile(const std::string &profile_name) const
Returns true if the named profile has been add()ed.
Library(bool active=true, const std::string &library_config=std::string(), LogFn=Library::log, bool verbose=true)
Constructor.
bool generateKeyAvailable() const
Returns true if generateKey() is implemented.
static Library * instance()
Returns a pointer to a library object, if any.
std::string id() const
Returns the TLS library name and version.
static LibraryImpBase & impstance()
Returns a reference to the pimple object when enabled().
static std::string credit(const std::string &prefix, const std::string &eol, const std::string &eot)
Returns a multi-line library credit for all available TLS libraries.
static bool real()
Returns true if this is a real TLS library.
static std::string ids()
Returns a concatenation of all available TLS library names and versions.
void addProfile(const std::string &profile_name, bool is_server_profile, const std::string &key_file=std::string(), const std::string &cert_file=std::string(), const std::string &ca_path=std::string(), const std::string &default_peer_certificate_name=std::string(), const std::string &default_peer_host_name=std::string(), const std::string &profile_config=std::string())
Creates a named Profile object that can be retrieved by profile().
const Profile & profile(const std::string &profile_name) const
Returns an opaque reference to the named profile.
bool enabled() const
Returns true if this is a real TLS library and the constructor's active parameter was set.
static G::StringArray digesters(bool need_state=false)
Returns a list of hash function names (such as "MD5") that the TLS library can do,...
~Library()
Destructor. Cleans up the underlying TLS library.
static void log(int level, const std::string &line)
The default logging callback function, where the level is 1 for debug, 2 for info,...
std::string generateKey(const std::string &name) const
Generates a test certificate as a PEM string with embedded newlines, also containing the private-key.
A base interface for profile classes that work with concrete classes derived from GSsl::LibraryImpBas...
virtual std::unique_ptr< ProtocolImpBase > newProtocol(const std::string &, const std::string &) const =0
Factory method for a new Protocol object on the heap.
virtual ~Profile()=default
Destructor.
A base interface for GSsl::Protocol pimple classes.
virtual bool verified() const =0
Implements Protocol::verified().
virtual std::string peerCertificate() const =0
Implements Protocol::peerCertificate().
virtual Protocol::Result connect(G::ReadWrite &)=0
Implements Protocol::connect().
virtual std::string cipher() const =0
Implements Protocol::cipher().
virtual ~ProtocolImpBase()=default
Destructor.
virtual Protocol::Result write(const char *, std::size_t, ssize_t &)=0
Implements Protocol::write().
virtual std::string protocol() const =0
Implements Protocol::protocol().
virtual Protocol::Result read(char *, std::size_t, ssize_t &)=0
Implements Protocol::read().
virtual std::string peerCertificateChain() const =0
Implements Protocol::peerCertificateChain().
virtual Protocol::Result accept(G::ReadWrite &)=0
Implements Protocol::accept().
virtual Protocol::Result shutdown()=0
Implements Protocol::shutdown().
Protocol(const Profile &, const std::string &peer_certificate_name=std::string(), const std::string &peer_host_name=std::string())
Constructor.
Result shutdown()
Initiates the protocol shutdown by sending a "close notify shutdown alert" and does a socket shutdown...
Result read(char *buffer, std::size_t buffer_size_in, ssize_t &data_size_out)
Reads user data into the supplied buffer.
std::string cipher() const
Returns the cipher name, or the empty string if not yet available.
bool verified() const
Returns true if the peer certificate has been verified.
static std::string str(Result result)
Converts a result enumeration into a printable string.
std::string peerCertificateChain() const
Returns the peer certificate chain in PEM format, starting with the peer certificate and progressing ...
std::string protocol() const
Returns the protocol version like "TLSv1.2" or the empty string.
Result write(const char *buffer, std::size_t data_size_in, ssize_t &data_size_out)
Writes user data.
Result connect(G::ReadWrite &io)
Starts the protocol actively (as a client).
Result accept(G::ReadWrite &io)
Starts the protocol passively (as a server).
std::string peerCertificate() const
Returns the peer certificate in PEM format.
An abstract interface for reading and writing from a non-blocking i/o channel.
TLS/SSL transport layer security classes.
std::vector< std::string > StringArray
A std::vector of std::strings.