Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-1198

If you use the System Truststore for tls connection, all certificates are accepted

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Not a Bug
    • None
    • N/A
    • SSL
    • None

    Description

      If you setup a Mariadb with the following tls configuration:

      /etc/mysql/conf.d/tls.cnf

      [mariadb]
      ssl_ca=/tls/ca-cert.pem
      ssl_cert=/tls/server-cert.pem
      ssl_key=/tls/server-key.pem
      require_secure_transport=ON
      

      And you want to use a custom (Java) System trust-store like:

              //System.setProperty("javax.net.ssl.trustStore", "./truststore.jks");
              //System.setProperty("javax.net.ssl.trustStorePassword", "jkspw");
       
              Properties connConfig = new Properties();
              connConfig.setProperty("user", "root");
              connConfig.setProperty("password", "rootpw");
              connConfig.setProperty("sslMode", "verify-full");
       
       
       
              try (Connection conn = DriverManager.getConnection("jdbc:mariadb://192.168.28.164:3306", connConfig)) {
                  try (Statement stmt = conn.createStatement()) {
                      try (ResultSet rs = stmt.executeQuery("SHOW VARIABLES LIKE 'have_ssl';")) {
                          rs.first();
                          System.out.println(rs.getString(2)); 
                      }
                  }
              }
      

      The connection is successful, even if we do not trust the ca. During my debug session I found out that if we "fall back" to the System Truststore, the X509Trustmanager will be wrapped inside a "MariaDbX509EphemeralTrustingManager", that basically accept all Certificates.

      Basically, this leads to the same behavior as "sslMode=trust", so the Db server just needs to provided any certificate.

      Test with the j-Connector 3.4.1

      Attachments

        1. ca-cert.pem
          1 kB
          Herbert2
        2. server-cert.pem
          1 kB
          Herbert2
        3. server-key.pem
          2 kB
          Herbert2

        Activity

          People

            diego dupin Diego Dupin
            Jürgens2 Herbert2
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.