}
}
- secure.updateTlsVersionLimits();
- secure.staticContext.reset(sslCreateServerContext(*this));
-
+ secure.staticContext.reset(secure.createStaticServerContext(*this));
if (!secure.staticContext) {
char buf[128];
fatalf("%s_port %s initialization error", AnyP::ProtocolType_str[transport.protocol], s.toUrl(buf, sizeof(buf)));
}
#else
- fatal("Failed to allocate TLS client context: No TLS library\n");
+ debugs(83, 1, "WARNING: Failed to allocate TLS client context: No TLS library");
#endif
Security::ContextPtr
Security::PeerOptions::createClientContext(bool setOptions)
{
- Security::ContextPtr t = nullptr;
-
updateTlsVersionLimits();
+ Security::ContextPtr t = createBlankContext();
+ if (t) {
#if USE_OPENSSL
- // XXX: temporary performance regression. c_str() data copies and prevents this being a const method
- t = sslCreateClientContext(*this, (setOptions ? parsedOptions : 0), parsedFlags);
-
-#elif USE_GNUTLS && WHEN_READY_FOR_GNUTLS
- t = createBlankContext();
-
+ // XXX: temporary performance regression. c_str() data copies and prevents this being a const method
+ Ssl::InitClientContext(t, *this, (setOptions ? parsedOptions : 0), parsedFlags);
#endif
-
- if (t) {
updateContextNpn(t);
updateContextCa(t);
updateContextCrl(t);
return t;
}
+Security::ContextPtr
+Security::ServerOptions::createStaticServerContext(AnyP::PortCfg &port)
+{
+ updateTlsVersionLimits();
+
+ Security::ContextPtr t = createBlankContext();
+ if (t) {
+#if USE_OPENSSL
+ Ssl::InitServerContext(t, port);
+#endif
+ }
+
+ return t;
+}
+
void
Security::ServerOptions::loadDhParams()
{
#ifndef SQUID_SRC_SECURITY_SERVEROPTIONS_H
#define SQUID_SRC_SECURITY_SERVEROPTIONS_H
+#include "anyp/forward.h"
#include "security/PeerOptions.h"
namespace Security
virtual Security::ContextPtr createBlankContext() const;
virtual void dumpCfg(Packable *, const char *pfx) const;
+ /// generate a security server-context from these configured options
+ Security::ContextPtr createStaticServerContext(AnyP::PortCfg &);
+
/// update the context with DH, EDH, EECDH settings
void updateContextEecdh(Security::ContextPtr &);
return true;
}
-Security::ContextPtr
-sslCreateServerContext(AnyP::PortCfg &port)
+bool
+Ssl::InitServerContext(Security::ContextPtr &sslContext, AnyP::PortCfg &port)
{
- Security::ContextPtr sslContext(port.secure.createBlankContext());
if (!sslContext)
- return nullptr;
+ return false;
if (!SSL_CTX_use_certificate(sslContext, port.signingCert.get())) {
const int ssl_error = ERR_get_error();
const auto &keys = port.secure.certs.front();
debugs(83, DBG_CRITICAL, "ERROR: Failed to acquire TLS certificate '" << keys.certFile << "': " << ERR_error_string(ssl_error, NULL));
SSL_CTX_free(sslContext);
- return NULL;
+ return false;
}
if (!SSL_CTX_use_PrivateKey(sslContext, port.signPkey.get())) {
const auto &keys = port.secure.certs.front();
debugs(83, DBG_CRITICAL, "ERROR: Failed to acquire TLS private key '" << keys.privateKeyFile << "': " << ERR_error_string(ssl_error, NULL));
SSL_CTX_free(sslContext);
- return NULL;
+ return false;
}
Ssl::addChainToSslContext(sslContext, port.certsToChain.get());
ssl_error = ERR_get_error();
debugs(83, DBG_CRITICAL, "ERROR: Failed to acquire SSL certificate '" << certfile << "': " << ERR_error_string(ssl_error, NULL));
SSL_CTX_free(sslContext);
- return NULL;
+ return false;
}
debugs(83, DBG_IMPORTANT, "Using private key in " << keyfile);
ssl_error = ERR_get_error();
debugs(83, DBG_CRITICAL, "ERROR: Failed to acquire SSL private key '" << keyfile << "': " << ERR_error_string(ssl_error, NULL));
SSL_CTX_free(sslContext);
- return NULL;
+ return false;
}
debugs(83, 5, "Comparing private and public SSL keys.");
debugs(83, DBG_CRITICAL, "ERROR: SSL private key '" << certfile << "' does not match public key '" <<
keyfile << "': " << ERR_error_string(ssl_error, NULL));
SSL_CTX_free(sslContext);
- return NULL;
+ return false;
}
*/
if (!configureSslContext(sslContext, port)) {
debugs(83, DBG_CRITICAL, "ERROR: Configuring static SSL context");
SSL_CTX_free(sslContext);
- return NULL;
+ return false;
}
- return sslContext;
+ return true;
}
-Security::ContextPtr
-sslCreateClientContext(Security::PeerOptions &peer, long options, long fl)
+bool
+Ssl::InitClientContext(Security::ContextPtr &sslContext, Security::PeerOptions &peer, long options, long fl)
{
- Security::ContextPtr sslContext(peer.createBlankContext());
if (!sslContext)
- return nullptr;
+ return false;
SSL_CTX_set_options(sslContext, options);
SSL_CTX_set_verify(sslContext, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, ssl_verify_cb);
}
- return sslContext;
+ return true;
}
/// \ingroup ServerProtocolSSLInternal
extern Ipc::MemMap *SessionCache;
extern const char *SessionCacheName;
-} //namespace Ssl
+/// initialize a TLS server context with OpenSSL specific settings
+bool InitServerContext(Security::ContextPtr &, AnyP::PortCfg &);
-/// \ingroup ServerProtocolSSLAPI
-Security::ContextPtr sslCreateServerContext(AnyP::PortCfg &port);
+/// initialize a TLS client context with OpenSSL specific settings
+bool InitClientContext(Security::ContextPtr &, Security::PeerOptions &, long options, long flags);
-/// \ingroup ServerProtocolSSLAPI
-Security::ContextPtr sslCreateClientContext(Security::PeerOptions &, long options, long flags);
+} //namespace Ssl
/// \ingroup ServerProtocolSSLAPI
int ssl_read_method(int, char *, int);
CertError & CertError::operator = (const CertError &old) STUB_RETVAL(*this)
bool CertError::operator == (const CertError &ce) const STUB_RETVAL(false)
bool CertError::operator != (const CertError &ce) const STUB_RETVAL(false)
+bool InitServerContext(Security::ContextPtr &, AnyP::PortCfg &) STUB_RETVAL(false)
+bool InitClientContext(Security::ContextPtr &, Security::PeerOptions &, long, const char *) STUB_RETVAL(false)
} // namespace Ssl
-Security::ContextPtr sslCreateServerContext(AnyP::PortCfg &port) STUB_RETVAL(NULL)
-Security::ContextPtr sslCreateClientContext(Security::PeerOptions &, long, const char *) STUB_RETVAL(nullptr)
int ssl_read_method(int, char *, int) STUB_RETVAL(0)
int ssl_write_method(int, const char *, int) STUB_RETVAL(0)
void ssl_shutdown_method(SSL *ssl) STUB