]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Mimic Key Usage and Basic Constraints
authorChristos Tsantilas <chtsanti@users.sourceforge.net>
Fri, 1 Feb 2013 04:47:04 +0000 (21:47 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 1 Feb 2013 04:47:04 +0000 (21:47 -0700)
There are cases where the generated certificates do not mimic enough
properties
and secure connection with the client fails. For example, Squid does not
mimic
Key Usage extensions. Clients using GnuTLS (or similar libraries that
validate
server certificate using those extensions) fail to secure the connection
with
Squid.

This patch add mimicking for the following extensions, which are
considered
as safe to mimic:
    * X509v3 Key Usage
    * X509v3 Extended Key Usage,
    * X509v3 Basic Constraints CA.

We would be happy to add more "safe to mimic" extensions if users
request (and
vouch for) them.

This is a Measurement Factory project

src/ssl/gadgets.cc

index ac94bc165ce918db349ca5ece50d8fc5eb419d02..9a891871001e43cce20f12e0c587d74ca845db3a 100644 (file)
@@ -249,6 +249,31 @@ std::string & Ssl::CertificateProperties::dbKey() const
     return certKey;
 }
 
+// Copy certificate extensions from cert to mimicCert.
+// Currently only extensions which are reported by the users that required are
+// mimicked. More safe to mimic extensions would be added here if users request
+// them.
+static void
+mimicExtensions(Ssl::X509_Pointer & cert, Ssl::X509_Pointer const & mimicCert)
+{
+    static int extensions[]= {
+        NID_key_usage,
+        NID_ext_key_usage,
+        NID_basic_constraints,
+        0
+    };
+
+    int nid;
+    for (int i = 0; (nid = extensions[i]) != 0; ++i) {
+        const int pos = X509_get_ext_by_NID(mimicCert.get(), nid, -1);
+        if (X509_EXTENSION *ext = X509_get_ext(mimicCert.get(), pos))
+            X509_add_ext(cert.get(), ext, -1);
+    }
+
+    // We could also restrict mimicking of the CA extension to CA:FALSE
+    // because Squid does not generate valid fake CA certificates.
+}
+
 static bool buildCertificate(Ssl::X509_Pointer & cert, Ssl::CertificateProperties const &properties)
 {
     // not an Ssl::X509_NAME_Pointer because X509_REQ_get_subject_name()
@@ -320,6 +345,8 @@ static bool buildCertificate(Ssl::X509_Pointer & cert, Ssl::CertificatePropertie
                 X509_set_version(cert.get(), 2);
             }
         }
+
+        mimicExtensions(cert, properties.mimicCert);
     }
 
     return true;