E-MailRelay
gssl_none.cpp
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2024 Graeme Walker <graeme_walker@users.sourceforge.net>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file gssl_none.cpp
19///
20
21#include "gdef.h"
22#include "gssl.h"
23#include "gexception.h"
24#include <memory>
25#include <utility>
26
27GSsl::Library * GSsl::Library::m_this = nullptr ;
28
29GSsl::Library::Library( const bool , const std::string & , LogFn , bool )
30{
31 if( m_this == nullptr )
32 m_this = this ;
33}
34
36{
37 if( this == m_this )
38 m_this = nullptr ;
39}
40
41void GSsl::Library::log( int , const std::string & )
42{
43}
44
46{
47 return false ;
48}
49
50std::string GSsl::Library::id() const
51{
52 return ids() ;
53}
54
56{
57 return m_this ;
58}
59
60void GSsl::Library::addProfile( const std::string & , bool , const std::string & , const std::string & ,
61 const std::string & , const std::string & , const std::string & , const std::string & )
62{
63}
64
65bool GSsl::Library::hasProfile( const std::string & ) const
66{
67 return false ;
68}
69
70const GSsl::Profile & GSsl::Library::profile( const std::string & ) const
71{
72 throw G::Exception( "invalid profile name: no tls library built in" ) ;
73}
74
75bool GSsl::Library::enabled() const
76{
77 return false ;
78}
79
80bool GSsl::Library::enabledAs( const std::string & )
81{
82 return false ;
83}
84
85std::string GSsl::Library::credit( const std::string & , const std::string & , const std::string & )
86{
87 return {} ;
88}
89
90std::string GSsl::Library::ids()
91{
92 return "none" ;
93}
94
96{
97 return {} ;
98}
99
100GSsl::Digester GSsl::Library::digester( const std::string & , const std::string & , bool ) const
101{
102 throw G::Exception( "internal error" ) ;
103 //return Digester( nullptr ) ; // never gets here
104}
105
106// ==
107
108GSsl::Protocol::Protocol( const Profile & , const std::string & , const std::string & )
109{
110}
111
113= default;
114
115GSsl::Protocol::Result GSsl::Protocol::connect( G::ReadWrite & )
116{
117 return Result::error ;
118}
119
120GSsl::Protocol::Result GSsl::Protocol::accept( G::ReadWrite & )
121{
122 return Result::error ;
123}
124
125GSsl::Protocol::Result GSsl::Protocol::shutdown()
126{
127 return Result::error ;
128}
129
130GSsl::Protocol::Result GSsl::Protocol::read( char * , std::size_t , ssize_t & )
131{
132 return Result::error ;
133}
134
135GSsl::Protocol::Result GSsl::Protocol::write( const char * , std::size_t , ssize_t & )
136{
137 return Result::error ;
138}
139
140std::string GSsl::Protocol::str( Protocol::Result )
141{
142 return {} ;
143}
144
145std::string GSsl::Protocol::peerCertificate() const
146{
147 return {} ;
148}
149
150std::string GSsl::Protocol::peerCertificateChain() const
151{
152 return {} ;
153}
154
155std::string GSsl::Protocol::protocol() const
156{
157 return {} ;
158}
159
160std::string GSsl::Protocol::cipher() const
161{
162 return {} ;
163}
164
165bool GSsl::Protocol::verified() const
166{
167 return false ;
168}
169
170// ==
171
172GSsl::Digester::Digester( std::unique_ptr<DigesterImpBase> p ) :
173 m_imp(p.release())
174{
175}
176
177void GSsl::Digester::add( std::string_view )
178{
179}
180
181std::string GSsl::Digester::value()
182{
183 return {} ;
184}
185
186std::string GSsl::Digester::state()
187{
188 return {} ;
189}
190
191std::size_t GSsl::Digester::blocksize() const noexcept
192{
193 return 1U ;
194}
195
196std::size_t GSsl::Digester::valuesize() const noexcept
197{
198 return 1U ;
199}
200
201std::size_t GSsl::Digester::statesize() const noexcept
202{
203 return 0U ;
204}
205
A class for objects that can perform a cryptographic hash.
Definition: gssl.h:215
std::string value()
Returns the hash value.
Definition: gssl.cpp:228
std::size_t statesize() const noexcept
Returns the size of the state() string in bytes, or zero if state() is not implemented.
Definition: gssl.cpp:248
std::string state()
Returns the intermediate state.
Definition: gssl.cpp:233
void add(std::string_view)
Adds data of arbitrary size.
Definition: gssl.cpp:223
std::size_t blocksize() const noexcept
Returns the hash function's block size in bytes.
Definition: gssl.cpp:238
std::size_t valuesize() const noexcept
Returns the hash function's value size in bytes.
Definition: gssl.cpp:243
Digester(std::unique_ptr< DigesterImpBase >)
Constructor, used by the Library class.
Definition: gssl.cpp:218
A singleton class for initialising the underlying TLS library.
Definition: gssl.h:255
static bool enabledAs(const std::string &profile_name)
A static convenience function that returns true if there is an enabled() Library instance() that has ...
Definition: gssl.cpp:97
bool hasProfile(const std::string &profile_name) const
Returns true if the named profile has been add()ed.
Definition: gssl.cpp:85
static Library * instance()
Returns a pointer to a library object, if any.
Definition: gssl.cpp:58
std::string id() const
Returns the TLS library name and version.
Definition: gssl.cpp:69
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.
Definition: gssl_none.cpp:85
static bool real()
Returns true if this is a real TLS library.
Definition: gssl.cpp:52
Library(bool active=true, const std::string &library_config={}, LogFn=Library::log, bool verbose=true)
Constructor.
Definition: gssl.cpp:30
static std::string ids()
Returns a concatenation of all available TLS library names and versions.
Definition: gssl_none.cpp:90
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().
Definition: gssl.cpp:75
const Profile & profile(const std::string &profile_name) const
Returns an opaque reference to the named profile.
Definition: gssl.cpp:90
bool enabled() const
Returns true if this is a real TLS library and the constructor's active parameter was set.
Definition: gssl.cpp:63
Digester digester(const std::string &name, const std::string &state={}, bool need_state=false) const
Returns a digester object.
Definition: gssl.cpp:138
static G::StringArray digesters(bool need_state=false)
Returns a list of hash function names (such as "MD5") that the TLS library can do,...
Definition: gssl.cpp:133
~Library()
Destructor. Cleans up the underlying TLS library.
Definition: gssl.cpp:45
static void log(int level, const std::string &line)
The default logging callback function, where the level is 1 for debug, 2 for info,...
Definition: gssl.cpp:123
A base interface for profile classes that work with concrete classes derived from GSsl::LibraryImpBas...
Definition: gssl.h:419
~Protocol()
Destructor.
Result shutdown()
Initiates the protocol shutdown by sending a "close notify shutdown alert" and does a socket shutdown...
Definition: gssl.cpp:211
Result read(char *buffer, std::size_t buffer_size_in, ssize_t &data_size_out)
Reads user data into the supplied buffer.
Definition: gssl.cpp:201
Protocol(const Profile &, const std::string &peer_certificate_name={}, const std::string &peer_host_name={})
Constructor.
Definition: gssl.cpp:145
std::string cipher() const
Returns the cipher name, or the empty string if not yet available.
Definition: gssl.cpp:170
bool verified() const
Returns true if the peer certificate has been verified.
Definition: gssl.cpp:176
static std::string str(Result result)
Converts a result enumeration into a printable string.
Definition: gssl.cpp:182
std::string peerCertificateChain() const
Returns the peer certificate chain in PEM format, starting with the peer certificate and progressing ...
Definition: gssl.cpp:159
std::string protocol() const
Returns the protocol version like "TLSv1.2" or the empty string.
Definition: gssl.cpp:165
Result write(const char *buffer, std::size_t data_size_in, ssize_t &data_size_out)
Writes user data.
Definition: gssl.cpp:206
Result connect(G::ReadWrite &io)
Starts the protocol actively (as a client).
Definition: gssl.cpp:191
Result accept(G::ReadWrite &io)
Starts the protocol passively (as a server).
Definition: gssl.cpp:196
std::string peerCertificate() const
Returns the peer certificate in PEM format.
Definition: gssl.cpp:153
A general-purpose exception class derived from std::exception and containing an error message.
Definition: gexception.h:64
An abstract interface for reading and writing from a non-blocking i/o channel.
Definition: greadwrite.h:50
An interface to an underlying TLS library.
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstringarray.h:30