]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3816: SSL_get_certificate call inside Ssl::verifySslCertificate crashes
authorChristos Tsantilas <chtsanti@users.sourceforge.net>
Wed, 24 Apr 2013 15:46:24 +0000 (09:46 -0600)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 24 Apr 2013 15:46:24 +0000 (09:46 -0600)
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 e5b361cd415ad12b6bfa5ae110bae9dbd6580b07..a2c48d6a72513888718a8f17fe96175323fce5ce 100644 (file)
@@ -1411,9 +1411,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);