]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3816: SSL_get_certificate call inside Ssl::verifySslCertificate crashes squi
authorChristos Tsantilas <chtsanti@users.sourceforge.net>
Tue, 23 Apr 2013 15:03:31 +0000 (18:03 +0300)
committerChristos Tsantilas <chtsanti@users.sourceforge.net>
Tue, 23 Apr 2013 15:03:31 +0000 (18:03 +0300)
d

The SSL_get_certificate implementation in OpenSSL 1.0.1d and 1.0.1e releases,
will crash if called before the certificate sent to the client.
This patch add a hack when one of the problematic OpenSSL versions used to
retrieve the certificate directly from SSL_CTX object, instead of creating
a temporary SSL object, and call SSL_get_certificate.

src/ssl/support.cc

index c701bd6bda2b02b5f3da53db3d5c501096cbbbed..883d5ef4a841e63a793a82be883a687889df43d6 100644 (file)
@@ -1452,9 +1452,18 @@ Ssl::generateSslContext(CertificateProperties const &properties, AnyP::PortCfg &
 
 bool Ssl::verifySslCertificate(SSL_CTX * sslContext, CertificateProperties const &properties)
 {
+    // SSL_get_certificate is buggy in openssl versions 1.0.1d and 1.0.1e
+    // Try to retrieve certificate directly from SSL_CTX object
+#if OPENSSL_VERSION_NUMBER == 0x1000105fL || OPENSSL_VERSION_NUMBER == 0x1000104fL
+    X509 ***pCert = (X509 ***)sslContext->cert;
+    X509 * cert = pCert && *pCert ? **pCert : NULL;
+#else
     // Temporary ssl for getting X509 certificate from SSL_CTX.
     Ssl::SSL_Pointer ssl(SSL_new(sslContext));
     X509 * cert = SSL_get_certificate(ssl.get());
+#endif
+    if (!cert)
+        return false;
     ASN1_TIME * time_notBefore = X509_get_notBefore(cert);
     ASN1_TIME * time_notAfter = X509_get_notAfter(cert);
     bool ret = (X509_cmp_current_time(time_notBefore) < 0 && X509_cmp_current_time(time_notAfter) > 0);