PeerConnector(aServerConn, aCallback, alp, timeout), icapService(service) {}
/* PeerConnector API */
- virtual Security::SessionPtr initializeSsl();
+ virtual bool initializeTls(Security::SessionPointer &);
virtual void noteNegotiationDone(ErrorState *error);
virtual Security::ContextPtr getSslContext() {return icapService->sslContext;}
}
#if USE_OPENSSL
-Security::SessionPtr
-Ssl::IcapPeerConnector::initializeSsl()
+bool
+Ssl::IcapPeerConnector::initializeTls(Security::SessionPointer &serverSession)
{
- auto ssl = Ssl::PeerConnector::initializeSsl();
- if (!ssl)
- return nullptr;
+ if (!Ssl::PeerConnector::initializeTls(serverSession))
+ return false;
assert(!icapService->cfg().secure.sslDomain.isEmpty());
SBuf *host = new SBuf(icapService->cfg().secure.sslDomain);
- SSL_set_ex_data(ssl, ssl_ex_index_server, host);
+ SSL_set_ex_data(serverSession.get(), ssl_ex_index_server, host);
- ACLFilledChecklist *check = (ACLFilledChecklist *)SSL_get_ex_data(ssl, ssl_ex_index_cert_error_check);
+ ACLFilledChecklist *check = static_cast<ACLFilledChecklist *>(SSL_get_ex_data(serverSession.get(), ssl_ex_index_cert_error_check));
if (check)
check->dst_peer_name = *host;
- Security::GetSessionResumeData(Security::SessionPointer(ssl), icapService->sslSession);
-
- return ssl;
+ Security::GetSessionResumeData(serverSession, icapService->sslSession);
+ return true;
}
void
{
public:
/// a helper label to simplify this objects API definitions below
- typedef LockingPointer<T, UnLocker, lockId> SelfType;
+ typedef Security::LockingPointer<T, UnLocker, lockId> SelfType;
/**
* Construct directly from a raw pointer.
~LockingPointer() { unlock(); }
// copy semantics are okay only when adding a lock reference
- explicit LockingPointer(const SelfType &o) : raw(nullptr) { resetAndLock(o.get()); }
- SelfType &operator =(const SelfType & o) {
+ explicit LockingPointer(const SelfType &o) : raw(nullptr) {
+ resetAndLock(o.get());
+ }
+ const SelfType &operator =(const SelfType &o) {
resetAndLock(o.get());
return *this;
}
return ::Config.ssl_client.sslContext;
}
-Security::SessionPtr
-Ssl::BlindPeerConnector::initializeSsl()
+bool
+Ssl::BlindPeerConnector::initializeTls(Security::SessionPointer &serverSession)
{
- auto ssl = Ssl::PeerConnector::initializeSsl();
- if (!ssl)
- return nullptr;
+ if (!Ssl::PeerConnector::initializeTls(serverSession))
+ return false;
if (const CachePeer *peer = serverConnection()->getPeer()) {
assert(peer);
// const loss is okay here, ssl_ex_index_server is only read and not assigned a destructor
SBuf *host = new SBuf(peer->secure.sslDomain);
- SSL_set_ex_data(ssl, ssl_ex_index_server, host);
+ SSL_set_ex_data(serverSession.get(), ssl_ex_index_server, host);
- Security::SetSessionResumeData(ssl, peer->sslSession);
+ Security::SetSessionResumeData(serverSession.get(), peer->sslSession);
} else {
SBuf *hostName = new SBuf(request->url.host());
- SSL_set_ex_data(ssl, ssl_ex_index_server, (void*)hostName);
+ SSL_set_ex_data(serverSession.get(), ssl_ex_index_server, (void*)hostName);
}
- return ssl;
+ return true;
}
void
/* PeerConnector API */
- /// Calls parent initializeSSL, configure the created SSL object to try reuse SSL session
- /// and sets the hostname to use for certificates validation
- virtual Security::SessionPtr initializeSsl();
+ /// Calls parent initializeTls(), configure the created TLS session object to
+ /// try reuse TLS session and sets the hostname to use for certificates validation
+ /// \returns true on successful initialization
+ virtual bool initializeTls(Security::SessionPointer &);
/// Return the configured Security::ContextPtr object
virtual Security::ContextPtr getSslContext();
return ::Config.ssl_client.sslContext;
}
-Security::SessionPtr
-Ssl::PeekingPeerConnector::initializeSsl()
+bool
+Ssl::PeekingPeerConnector::initializeTls(Security::SessionPointer &serverSession)
{
- auto ssl = Ssl::PeerConnector::initializeSsl();
- if (!ssl)
- return nullptr;
+ if (!Ssl::PeerConnector::initializeTls(serverSession))
+ return false;
if (ConnStateData *csd = request->clientConnectionManager.valid()) {
assert(clientConn != NULL);
SBuf *hostName = NULL;
- //Enable Status_request tls extension, required to bump some clients
- SSL_set_tlsext_status_type(ssl, TLSEXT_STATUSTYPE_ocsp);
+ //Enable Status_request TLS extension, required to bump some clients
+ SSL_set_tlsext_status_type(serverSession.get(), TLSEXT_STATUSTYPE_ocsp);
const Security::TlsDetails::Pointer details = csd->tlsParser.details;
if (details && !details->serverName.isEmpty())
}
if (hostName)
- SSL_set_ex_data(ssl, ssl_ex_index_server, (void*)hostName);
+ SSL_set_ex_data(serverSession.get(), ssl_ex_index_server, (void*)hostName);
Must(!csd->serverBump() || csd->serverBump()->step <= Ssl::bumpStep2);
if (csd->sslBumpMode == Ssl::bumpPeek || csd->sslBumpMode == Ssl::bumpStare) {
- auto clientSsl = fd_table[clientConn->fd].ssl.get();
- Must(clientSsl);
- BIO *bc = SSL_get_rbio(clientSsl);
+ auto clientSession = fd_table[clientConn->fd].ssl.get();
+ Must(clientSession);
+ BIO *bc = SSL_get_rbio(clientSession);
Ssl::ClientBio *cltBio = static_cast<Ssl::ClientBio *>(bc->ptr);
Must(cltBio);
if (details && details->tlsVersion.protocol != AnyP::PROTO_NONE) {
- applyTlsDetailsToSSL(ssl, details, csd->sslBumpMode);
+ applyTlsDetailsToSSL(serverSession.get(), details, csd->sslBumpMode);
// Should we allow it for all protocols?
if (details->tlsVersion.protocol == AnyP::PROTO_TLS || details->tlsVersion == AnyP::ProtocolVersion(AnyP::PROTO_SSL, 3, 0)) {
- BIO *b = SSL_get_rbio(ssl);
+ BIO *b = SSL_get_rbio(serverSession.get());
Ssl::ServerBio *srvBio = static_cast<Ssl::ServerBio *>(b->ptr);
// Inherite client features, like SSL version, SNI and other
srvBio->setClientFeatures(details, cltBio->rBufData());
}
} else {
// Set client SSL options
- SSL_set_options(ssl, ::Security::ProxyOutgoingConfig.parsedOptions);
+ SSL_set_options(serverSession.get(), ::Security::ProxyOutgoingConfig.parsedOptions);
// Use SNI TLS extension only when we connect directly
// to the origin server and we know the server host name.
sniServer = hostName->c_str();
if (sniServer)
- Ssl::setClientSNI(ssl, sniServer);
+ Ssl::setClientSNI(serverSession.get(), sniServer);
}
if (Ssl::ServerBump *serverBump = csd->serverBump()) {
- serverBump->attachServerSSL(ssl);
+ serverBump->attachServerSSL(serverSession.get());
// store peeked cert to check SQUID_X509_V_ERR_CERT_CHANGE
if (X509 *peeked_cert = serverBump->serverCert.get()) {
CRYPTO_add(&(peeked_cert->references),1,CRYPTO_LOCK_X509);
- SSL_set_ex_data(ssl, ssl_ex_index_ssl_peeked_cert, peeked_cert);
+ SSL_set_ex_data(serverSession.get(), ssl_ex_index_ssl_peeked_cert, peeked_cert);
}
}
}
- return ssl;
+ return true;
}
void
}
/* PeerConnector API */
- virtual Security::SessionPtr initializeSsl();
+ virtual bool initializeTls(Security::SessionPointer &);
virtual Security::ContextPtr getSslContext();
virtual void noteWantWrite();
virtual void noteSslNegotiationError(const int result, const int ssl_error, const int ssl_lib_error);
{
AsyncJob::start();
- if (prepareSocket() && initializeSsl())
+ Security::SessionPointer tmp;
+ if (prepareSocket() && initializeTls(tmp))
negotiateSsl();
}
return true;
}
-Security::SessionPtr
-Ssl::PeerConnector::initializeSsl()
+bool
+Ssl::PeerConnector::initializeTls(Security::SessionPointer &serverSession)
{
Security::ContextPtr sslContext(getSslContext());
assert(sslContext);
noteNegotiationDone(anErr);
bail(anErr);
- return nullptr;
+ return false;
}
// A TLS/SSL session has now been created for the connection and stored in fd_table
- auto &tlsSession = fd_table[serverConnection()->fd].ssl;
+ serverSession = fd_table[serverConnection()->fd].ssl;
// If CertValidation Helper used do not lookup checklist for errors,
// but keep a list of errors to send it to CertValidator
ACLFilledChecklist *check = new ACLFilledChecklist(acl, request.getRaw(), dash_str);
check->al = al;
// check->fd(fd); XXX: need client FD here
- SSL_set_ex_data(tlsSession.get(), ssl_ex_index_cert_error_check, check);
+ SSL_set_ex_data(serverSession.get(), ssl_ex_index_cert_error_check, check);
}
}
- return tlsSession.get();
+ return true;
}
void
#include "base/AsyncJob.h"
#include "CommCalls.h"
#include "security/EncryptorAnswer.h"
+#include "security/forward.h"
#include "ssl/support.h"
#include <iosfwd>
/// silent server
void setReadTimeout();
- virtual Security::SessionPtr initializeSsl(); ///< Initializes SSL state
+ /// \returns true on successful TLS session initialization
+ virtual bool initializeTls(Security::SessionPointer &);
/// Performs a single secure connection negotiation step.
/// It is called multiple times untill the negotiation finish or aborted.