33 if( m_this ==
nullptr )
43 G_WARNING(
"GSsl::Library::ctor: tls-config: numeric tls configuration flags are deprecated" ) ;
45 if( (flags&(~3U)) == 0U )
47 if( (flags&3U) == 2U )
48 config.push_back(
"sslv23" ) ;
49 else if( (flags&3U) == 3U )
50 config.push_back(
"sslv3" ) ;
53 m_imp = newLibraryImp( config , log_fn , verbose ) ;
56 G_WARNING(
"GSsl::Library::Library: tls-config: tls configuration items ignored: [" <<
G::Str::join(
",",config) <<
"]" ) ;
63 if( m_this ==
nullptr )
79 return m_imp != nullptr ;
88 const std::string & key_file ,
const std::string & cert_file ,
const std::string & ca_file ,
89 const std::string & default_peer_certificate_name ,
const std::string & default_peer_host_name ,
90 const std::string & profile_config )
92 if( m_imp !=
nullptr )
93 m_imp->addProfile( profile_name , is_server_profile , key_file , cert_file , ca_file ,
94 default_peer_certificate_name , default_peer_host_name , profile_config ) ;
99 return m_imp->hasProfile( profile_name ) ;
104 if( !
imp().hasProfile(profile_name) )
105 throw G::Exception(
"invalid tls profile name [" + profile_name +
"]" ) ;
106 return imp().profile( profile_name ) ;
111 return instance() !=
nullptr && instance()->enabled() && instance()->hasProfile( profile_name ) ;
116 if( instance() ==
nullptr )
118 return instance()->imp() ;
123 if( m_imp ==
nullptr )
130 if( m_imp ==
nullptr )
138 G_DEBUG(
"GSsl::Library::log: tls: " << log_line ) ;
139 else if( level == 2 )
140 G_LOG(
"GSsl::Library::log: tls: " << log_line ) ;
142 G_WARNING(
"GSsl::Library::log: tls: " << log_line ) ;
147 return instance() ==
nullptr || instance()->m_imp ==
nullptr ?
G::StringArray() : impstance().digesters(require_state) ;
152 return impstance().digester( hash_function , state ) ;
158 m_imp( profile.newProtocol(peer_certificate_name,peer_host_name) )
169 return m_imp->peerCertificate() ;
174 return m_imp->peerCertificateChain() ;
179 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 ) ;
203 return m_imp->read( buffer , buffer_size_in , data_size_out ) ;
208 return m_imp->write( buffer , data_size_in , data_size_out ) ;
213 return m_imp->stop() ;
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() ;
261 G::StringArray::iterator p = std::find( list.begin() , list.end() , key ) ;
262 if( p != list.end() )
A base interface for profile classes that work with concrete classes derived from GSsl::LibraryImpBas...
static Library * instance()
Returns a pointer to a library object, if any.
std::string peerCertificateChain() const
Returns the peer certificate chain in PEM format, starting with the peer certificate and progressing ...
An interface to an underlying TLS library.
Digester digester(const std::string &name, const std::string &state=std::string()) const
Returns a digester object.
An abstract interface for reading and writing from a non-blocking i/o channel.
virtual ~LibraryImpBase()
Destructor.
std::string state()
Returns the intermediate state.
static G::StringArray digesters(bool require_state=false)
Returns a list of hash function names (such as "MD5") that the TLS library can do, ordered roughly from strongest to weakest.
bool hasProfile(const std::string &profile_name) const
Returns true if the named profile has been add()ed.
std::vector< std::string > StringArray
A std::vector of std::strings.
static bool enabledAs(const std::string &profile_name)
A static convenience function that returns true if there is an enabled() Library instance() that has ...
static void splitIntoTokens(const std::string &in, StringArray &out, const std::string &ws)
Splits the string into 'ws'-delimited tokens.
static std::string str(Result result)
Converts a result enumeration into a printable string.
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().
virtual ~Profile()
Destructor.
~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, 3 for warnings, and 4 for errors.
A base interface for GSsl::Digester pimple classes.
static LibraryImpBase & impstance()
Returns a reference to the pimple object when enabled().
Protocol(const Profile &, const std::string &peer_certificate_name=std::string(), const std::string &peer_host_name=std::string())
Constructor.
static unsigned int toUInt(const std::string &s)
Converts string 's' to an unsigned int.
Result stop()
Initiates the protocol shutdown.
Returns an object that can perform a cryptographic hash.
Result read(char *buffer, size_t buffer_size_in, ssize_t &data_size_out)
Reads user data into the supplied buffer.
Result accept(G::ReadWrite &io)
Starts the protocol passively (as a server).
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...
A base interface for GSsl::Library pimple classes.
std::string value()
Returns the hash value.
Result connect(G::ReadWrite &io)
Starts the protocol actively (as a client).
Digester(DigesterImpBase *)
Constructor, used by the Library class.
const Profile & profile(const std::string &profile_name) const
Returns an opaque reference to the named profile.
std::string peerCertificate() const
Returns the peer certificate in PEM format.
size_t valuesize() const
Returns the hash function's value size in bytes.
Library(bool active=true, const std::string &library_config=std::string(), LogFn=Library::log, bool verbose=true)
Constructor.
void add(const std::string &)
Adds data of arbitrary size.
Result write(const char *buffer, size_t data_size_in, ssize_t &data_size_out)
Writes user data.
A general-purpose exception class derived from std::exception and containing a std::string.
A singleton class for initialising the underlying TLS library.
static std::string join(const std::string &sep, const StringArray &strings)
Concatenates an array of strings with separators.
static bool real()
Returns true if this is a real TLS library.
size_t statesize() const
Returns the size of the state() string in bytes, or zero if state() is not implemented.
virtual ~DigesterImpBase()
Destructor.
bool enabled() const
Returns true if this is a real TLS library and the constructor's active parameter was set...
static bool isUInt(const std::string &s)
Returns true if the string can be converted into an unsigned integer without throwing an exception...
size_t blocksize() const
Returns the hash function's block size in bytes.
bool verified() const
Returns true if the peer certificate has been verified.
std::string id() const
Returns the TLS library name and version.
virtual ~ProtocolImpBase()
Destructor.