79 explicit Protocol(
const Profile & ,
const std::string & peer_certificate_name = {} ,
80 const std::string & peer_host_name = {} ) ;
117 Result
read(
char * buffer , std::size_t buffer_size_in , ssize_t & data_size_out ) ;
145 Result
write(
const char * buffer , std::size_t data_size_in , ssize_t & data_size_out ) ;
165 static std::string
str( Result result ) ;
173 std::string
cipher()
const ;
199 std::unique_ptr<ProtocolImpBase> m_imp ;
217 explicit Digester( std::unique_ptr<DigesterImpBase> ) ;
230 void add( std::string_view ) ;
233 std::string
state() ;
241 std::string
value() ;
245 std::shared_ptr<DigesterImpBase> m_imp ;
257 G_EXCEPTION( NoInstance ,
tx(
"no tls library object") )
258 G_EXCEPTION( BadProfileName ,
tx(
"invalid tls profile name") )
259 using LogFn = void (*)(int,
const std::string &) ;
261 explicit Library(
bool active =
true ,
const std::string & library_config = {} ,
276 static void log(
int level ,
const std::string & line ) ;
285 void addProfile(
const std::string & profile_name ,
bool is_server_profile ,
286 const std::string & key_file = {} ,
const std::string & cert_file = {} ,
287 const std::string & ca_path = {} ,
288 const std::string & default_peer_certificate_name = {} ,
289 const std::string & default_peer_host_name = {} ,
290 const std::string & profile_config = {} ) ;
322 bool hasProfile(
const std::string & profile_name )
const ;
325 const Profile &
profile(
const std::string & profile_name )
const ;
333 std::string
id()
const ;
343 static std::string
credit(
const std::string & prefix ,
const std::string & eol ,
const std::string & eot ) ;
346 static std::string
ids() ;
349 static bool enabledAs(
const std::string & profile_name ) ;
361 Digester digester(
const std::string & name ,
const std::string & state = {} ,
bool need_state = false )
const ;
373 static std::unique_ptr<LibraryImpBase> newLibraryImp(
G::StringArray & , Library::LogFn ,
bool ) ;
377 std::unique_ptr<LibraryImpBase> m_imp ;
390 virtual std::string
id()
const = 0 ;
393 virtual void addProfile(
const std::string & ,
bool ,
const std::string & ,
const std::string & ,
394 const std::string & ,
const std::string & ,
const std::string & ,
const std::string & ) = 0 ;
397 virtual bool hasProfile(
const std::string & profile_name )
const = 0 ;
424 virtual std::unique_ptr<ProtocolImpBase>
newProtocol(
const std::string & ,
const std::string & )
const = 0 ;
446 virtual Protocol::Result
read(
char * , std::size_t , ssize_t & ) = 0 ;
449 virtual Protocol::Result
write(
const char * , std::size_t , ssize_t & ) = 0 ;
477 virtual void add( std::string_view ) = 0 ;
A base interface for GSsl::Digester pimple classes.
virtual std::string state()=0
Implements Digester::state().
virtual std::size_t blocksize() const noexcept=0
Implements Digester::blocksize().
virtual std::size_t statesize() const noexcept=0
Implements Digester::statesize().
virtual std::size_t valuesize() const noexcept=0
Implements Digester::valuesize().
virtual ~DigesterImpBase()=default
Destructor.
virtual std::string value()=0
Implements Digester::value().
virtual void add(std::string_view)=0
Implements Digester::add().
A class for objects that can perform a cryptographic hash.
std::string value()
Returns the hash value.
std::size_t statesize() const noexcept
Returns the size of the state() string in bytes, or zero if state() is not implemented.
std::string state()
Returns the intermediate state.
void add(std::string_view)
Adds data of arbitrary size.
std::size_t blocksize() const noexcept
Returns the hash function's block size in bytes.
std::size_t valuesize() const noexcept
Returns the hash function's value size in bytes.
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().
static bool consume(G::StringArray &list, std::string_view item)
A convenience function that removes the item from the list and returns true iff is was removed.
virtual G::StringArray digesters(bool) const =0
Implements Library::digesters().
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 ...
bool hasProfile(const std::string &profile_name) const
Returns true if the named profile has been add()ed.
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.
Library(bool active=true, const std::string &library_config={}, LogFn=Library::log, bool verbose=true)
Constructor.
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={}, const std::string &cert_file={}, const std::string &ca_path={}, const std::string &default_peer_certificate_name={}, const std::string &default_peer_host_name={}, const std::string &profile_config={})
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.
Digester digester(const std::string &name, const std::string &state={}, bool need_state=false) const
Returns a digester object.
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,...
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.
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().
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.
Protocol(const Profile &, const std::string &peer_certificate_name={}, const std::string &peer_host_name={})
Constructor.
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.
constexpr const char * tx(const char *p) noexcept
A briefer alternative to G::gettext_noop().