32 if( m_this ==
nullptr )
38 m_imp = newLibraryImp( config , log_fn , verbose ) ;
40 if( !config.empty() && !ignore_extra )
41 G_WARNING(
"GSsl::Library::Library: tls-config: tls configuration items ignored: [" <<
G::Str::join(
",",config) <<
"]" ) ;
65 return m_imp != nullptr ;
76 const std::string & key_file ,
const std::string & cert_file ,
const std::string & ca_file ,
77 const std::string & default_peer_certificate_name ,
const std::string & default_peer_host_name ,
78 const std::string & profile_config )
80 if( m_imp !=
nullptr )
81 m_imp->addProfile( profile_name , is_server_profile , key_file , cert_file , ca_file ,
82 default_peer_certificate_name , default_peer_host_name , profile_config ) ;
87 return m_imp->hasProfile( profile_name ) ;
92 if( !imp().hasProfile(profile_name) )
93 throw BadProfileName( profile_name ) ;
94 return imp().profile( profile_name ) ;
99 return instance() !=
nullptr && instance()->enabled() && instance()->hasProfile( profile_name ) ;
104 if( instance() ==
nullptr )
106 return instance()->imp() ;
111 if( m_imp ==
nullptr )
118 if( m_imp ==
nullptr )
126 G_DEBUG(
"GSsl::Library::log: tls: " << log_line ) ;
127 else if( level == 2 )
128 G_LOG(
"GSsl::Library::log: tls: " << log_line ) ;
130 G_WARNING(
"GSsl::Library::log: tls: " << log_line ) ;
135 return instance() ==
nullptr || instance()->m_imp ==
nullptr ?
G::StringArray() : impstance().digesters(require_state) ;
140 return impstance().digester( hash_function , state , need_state ) ;
146 m_imp( profile.newProtocol(peer_certificate_name,peer_host_name) )
155 return m_imp->peerCertificate() ;
161 return m_imp->peerCertificateChain() ;
167 return m_imp->protocol() ;
172 return m_imp->cipher() ;
178 return m_imp->verified() ;
184 if( result == Result::ok )
return "Result_ok" ;
185 if( result == Result::read )
return "Result_read" ;
186 if( result == Result::write )
return "Result_write" ;
187 if( result == Result::error )
return "Result_error" ;
188 return "Result_undefined" ;
193 return m_imp->connect( io ) ;
198 return m_imp->accept( io ) ;
201GSsl::Protocol::Result
GSsl::Protocol::read(
char * buffer , std::size_t buffer_size_in , ssize_t & data_size_out )
203 return m_imp->read( buffer , buffer_size_in , data_size_out ) ;
206GSsl::Protocol::Result
GSsl::Protocol::write(
const char * buffer , std::size_t data_size_in , ssize_t & data_size_out)
208 return m_imp->write( buffer , data_size_in , data_size_out ) ;
213 return m_imp->shutdown() ;
230 return m_imp->value() ;
235 return m_imp->state() ;
240 return m_imp->blocksize() ;
245 return m_imp->valuesize() ;
250 return m_imp->statesize() ;
257 auto p = std::find( list.begin() , list.end() , G::sv_to_string(key) ) ;
258 if( p != list.end() )
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.
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.
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 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.
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...
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.
static void splitIntoTokens(const std::string &in, StringArray &out, std::string_view ws, char esc='\0')
Splits the string into 'ws'-delimited tokens.
static std::string join(std::string_view sep, const StringArray &strings)
Concatenates an array of strings with separators.
An interface to an underlying TLS library.
std::vector< std::string > StringArray
A std::vector of std::strings.