dodo
0.0.1
A C++ library to create containerized Linux services
|
Go to the documentation of this file.
36 BaseSocket( socket ), tlscontext_(tlscontext), peer_name_(peer_name) {
44 BaseSocket( blocking, params ), tlscontext_(tlscontext), peer_name_(peer_name) {
45 ssl_ = SSL_new( tlscontext .getContext() );
49 SSL_ctrl(
ssl_, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name, (
void*)
peer_name_.
san_name.c_str());
62 auto ssl_error_code = SSL_get_error(
ssl_, rc );
65 rc = SSL_connect(
ssl_ );
67 auto ssl_error_code = SSL_get_error(
ssl_, rc );
68 switch ( ssl_error_code ) {
89 auto rc = SSL_accept(
ssl_ );
91 auto ssl_error_code = SSL_get_error(
ssl_, rc );
102 return SSL_get_peer_certificate(
ssl_);
106 auto rc = SSL_write(
ssl_, buf, (
int)len );
108 switch ( SSL_get_error(
ssl_, rc ) ) {
125 auto rc = SSL_read(
ssl_, buf, (
int)request );
127 auto sge = SSL_get_error(
ssl_, (
int)rc );
140 }
else received = rc;
SSL * ssl_
The SSL object.
@ ecSSL_ERROR_WANT_WRITE
10005 SSL_ERROR_WANT_WRITE
X509Common::SAN peer_name_
The peer name connected to, for TLS CN and SubjectAltName matching.
virtual common::SystemError connect(const Address &address)
Connect to the address.
@ ecSSL_ERROR_WANT_READ
10004 SSL_ERROR_WANT_READ
@ ecSSL_ERROR_PEERVERIFICATION
10013 When peer verification failed
bool isSNIEnabled() const
Return true when SNI (server Name Information) is to be enabled by TLSSocket objects using this TLSCo...
@ ecSSL_ERROR_WANT_CONNECT
10006 SSL_ERROR_WANT_CONNECT
static bool verifySAN(const X509 *cert, const SAN &san, bool wildcards=false)
Verify a peer name against this certificate's CN and SubjectAltnames.
Generic network Address, supporting ipv4 and ipv6 transparently.
virtual common::SystemError send(const void *buf, ssize_t len, bool more=false)
Send data.
@ stDNS
A DNS name such as myhost.mydomain.org.
TLSContext & tlscontext_
The TLSContext.
virtual common::SystemError connect(const Address &address)
Connect to the Address.
@ ecSSL_ERROR_WANT_ACCEPT
10007 SSL_ERROR_WANT_ACCEPT
@ ecSSL_ERROR_ZERO_RETURN
10003 SSL_ERROR_ZERO_RETURN
virtual common::SystemError receive(void *buf, ssize_t request, ssize_t &received)
Receive data.
Socket for TLS encrypted traffic between trusted endpoints.
#define log_Error(what)
Macro to log Error.
Socket parameters - the family (domain), socket type and protocol triplet.
int socket_
The socket file decsriptor.
PeerVerification getPeerVerification() const
Return the getPeerVerification mode.
@ ecSSL_ERROR_SYSCALL
10012 SSL_ERROR_SYSCALL
@ pvVerifyFQDN
As pvVerifyPeer, but the remote DNS name must match either the peer cert commonname or match one of t...
#define throw_Exception(what)
Throws an Exception, passes FILE and LINE to constructor.
@ ecOK
0 Not an error, success
Interface for network communication.
TLSSocket(int socket, TLSContext &tlscontext, const X509Common::SAN &peer_name)
Construct from existing socket file descriptor.
std::string getSSLErrors(char terminator)
Get all OpenSSL errors as a single string, and clear their error state.
virtual ~TLSSocket()
Destructor.
virtual TLSSocket * accept()
Accept a connection.
std::string san_name
The name.
Linux system error primitive to provide a consistent interface to Linux error codes.
@ ecSSL_ERROR_NONE
10003 SSL_ERROR_NONE
@ ecSSL_ERROR_WANT_X509_LOOKUP
10008 SSL_ERROR_WANT_X509_LOOKUP
X509 * getPeerCertificate() const
Get the peer's certificate.
bool isAllowSANWildcards() const
If true, TLS will allow SAN wildcard matching.
Interface to and common implementation of concrete sockets (Socket, TLSSocket).