E-MailRelay
gssl_none.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2018 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 // gssl_none.cpp
19 //
20 
21 #include "gdef.h"
22 #include "gssl.h"
23 #include "gexception.h"
24 #include <utility>
25 
26 GSsl::Library * GSsl::Library::m_this = nullptr ;
27 
28 GSsl::Library::Library( const bool , const std::string & , LogFn , bool )
29 {
30  if( m_this == nullptr )
31  m_this = this ;
32 }
33 
35 {
36  if( this == m_this )
37  m_this = nullptr ;
38 }
39 
40 void GSsl::Library::log( int , const std::string & )
41 {
42 }
43 
45 {
46  return false ;
47 }
48 
49 std::string GSsl::Library::id() const
50 {
51  return ids() ;
52 }
53 
55 {
56  return m_this ;
57 }
58 
59 void GSsl::Library::addProfile( const std::string & , bool , const std::string & , const std::string & ,
60  const std::string & , const std::string & , const std::string & , const std::string & )
61 {
62 }
63 
64 bool GSsl::Library::hasProfile( const std::string & ) const
65 {
66  return false ;
67 }
68 
69 const GSsl::Profile & GSsl::Library::profile( const std::string & ) const
70 {
71  throw G::Exception( "internal error" ) ;
72 }
73 
74 bool GSsl::Library::enabled() const
75 {
76  return false ;
77 }
78 
79 bool GSsl::Library::enabledAs( const std::string & )
80 {
81  return false ;
82 }
83 
84 std::string GSsl::Library::credit( const std::string & , const std::string & , const std::string & )
85 {
86  return std::string() ;
87 }
88 
89 std::string GSsl::Library::ids()
90 {
91  return "none" ;
92 }
93 
94 G::StringArray GSsl::Library::digesters( bool require_state )
95 {
96  return G::StringArray() ;
97 }
98 
99 GSsl::Digester GSsl::Library::digester( const std::string & name , const std::string & state ) const
100 {
101  throw G::Exception( "internal error" ) ;
102  //return Digester( nullptr ) ; // never gets here
103 }
104 
105 // ==
106 
107 GSsl::Protocol::Protocol( const Profile & , const std::string & , const std::string & )
108 {
109 }
110 
112 {
113 }
114 
115 GSsl::Protocol::Result GSsl::Protocol::connect( G::ReadWrite & )
116 {
117  return Result_error ;
118 }
119 
120 GSsl::Protocol::Result GSsl::Protocol::accept( G::ReadWrite & )
121 {
122  return Result_error ;
123 }
124 
125 GSsl::Protocol::Result GSsl::Protocol::stop()
126 {
127  return Result_error ;
128 }
129 
130 GSsl::Protocol::Result GSsl::Protocol::read( char * , size_t , ssize_t & )
131 {
132  return Result_error ;
133 }
134 
135 GSsl::Protocol::Result GSsl::Protocol::write( const char * , size_t , ssize_t & )
136 {
137  return Result_error ;
138 }
139 
140 std::string GSsl::Protocol::str( Protocol::Result )
141 {
142  return std::string() ;
143 }
144 
145 std::string GSsl::Protocol::peerCertificate() const
146 {
147  return std::string() ;
148 }
149 
150 std::string GSsl::Protocol::peerCertificateChain() const
151 {
152  return std::string() ;
153 }
154 
155 bool GSsl::Protocol::verified() const
156 {
157  return false ;
158 }
159 
160 // ==
161 
162 GSsl::Digester::Digester( DigesterImpBase * p ) :
163  m_imp(p)
164 {
165 }
166 
167 void GSsl::Digester::add( const std::string & )
168 {
169 }
170 
171 std::string GSsl::Digester::value()
172 {
173  return std::string() ;
174 }
175 
176 std::string GSsl::Digester::state()
177 {
178  return std::string() ;
179 }
180 
181 size_t GSsl::Digester::blocksize() const
182 {
183  return 1U ;
184 }
185 
186 size_t GSsl::Digester::valuesize() const
187 {
188  return 1U ;
189 }
190 
191 size_t GSsl::Digester::statesize() const
192 {
193  return 0U ;
194 }
195 
196 /// \file gssl_none.cpp
A base interface for profile classes that work with concrete classes derived from GSsl::LibraryImpBas...
Definition: gssl.h:392
static Library * instance()
Returns a pointer to a library object, if any.
Definition: gssl.cpp:72
std::string peerCertificateChain() const
Returns the peer certificate chain in PEM format, starting with the peer certificate and progressing ...
Definition: gssl.cpp:172
An interface to an underlying TLS library.
Digester digester(const std::string &name, const std::string &state=std::string()) const
Returns a digester object.
Definition: gssl.cpp:150
An abstract interface for reading and writing from a non-blocking i/o channel.
Definition: greadwrite.h:49
std::string state()
Returns the intermediate state.
Definition: gssl.cpp:233
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.
Definition: gssl.cpp:145
bool hasProfile(const std::string &profile_name) const
Returns true if the named profile has been add()ed.
Definition: gssl.cpp:97
std::vector< std::string > StringArray
A std::vector of std::strings.
Definition: gstrings.h:33
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:109
static std::string str(Result result)
Converts a result enumeration into a printable string.
Definition: gssl.cpp:182
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().
Definition: gssl.cpp:87
~Library()
Destructor. Cleans up the underlying TLS library.
Definition: gssl.cpp:60
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.
Definition: gssl.cpp:135
Protocol(const Profile &, const std::string &peer_certificate_name=std::string(), const std::string &peer_host_name=std::string())
Constructor.
Definition: gssl.cpp:157
Result stop()
Initiates the protocol shutdown.
Definition: gssl.cpp:211
Returns an object that can perform a cryptographic hash.
Definition: gssl.h:194
Result read(char *buffer, size_t buffer_size_in, ssize_t &data_size_out)
Reads user data into the supplied buffer.
Definition: gssl.cpp:201
Result accept(G::ReadWrite &io)
Starts the protocol passively (as a server).
Definition: gssl.cpp:196
std::string value()
Returns the hash value.
Definition: gssl.cpp:228
Result connect(G::ReadWrite &io)
Starts the protocol actively (as a client).
Definition: gssl.cpp:191
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:84
Digester(DigesterImpBase *)
Constructor, used by the Library class.
Definition: gssl.cpp:218
const Profile & profile(const std::string &profile_name) const
Returns an opaque reference to the named profile.
Definition: gssl.cpp:102
std::string peerCertificate() const
Returns the peer certificate in PEM format.
Definition: gssl.cpp:167
size_t valuesize() const
Returns the hash function's value size in bytes.
Definition: gssl.cpp:243
Library(bool active=true, const std::string &library_config=std::string(), LogFn=Library::log, bool verbose=true)
Constructor.
Definition: gssl.cpp:30
void add(const std::string &)
Adds data of arbitrary size.
Definition: gssl.cpp:223
static std::string ids()
Returns a concatenation of all available TLS library names and versions.
Definition: gssl_none.cpp:89
Result write(const char *buffer, size_t data_size_in, ssize_t &data_size_out)
Writes user data.
Definition: gssl.cpp:206
A general-purpose exception class derived from std::exception and containing a std::string.
Definition: gexception.h:43
A singleton class for initialising the underlying TLS library.
Definition: gssl.h:234
static bool real()
Returns true if this is a real TLS library.
Definition: gssl.cpp:67
~Protocol()
Destructor.
Definition: gssl.cpp:162
size_t statesize() const
Returns the size of the state() string in bytes, or zero if state() is not implemented.
Definition: gssl.cpp:248
bool enabled() const
Returns true if this is a real TLS library and the constructor's active parameter was set...
Definition: gssl.cpp:77
size_t blocksize() const
Returns the hash function's block size in bytes.
Definition: gssl.cpp:238
bool verified() const
Returns true if the peer certificate has been verified.
Definition: gssl.cpp:177
std::string id() const
Returns the TLS library name and version.
Definition: gssl.cpp:82