mariadb ssl problem: ERROR 2026 (HY000): TLS/SSL error: Validation of SSL server certificate failed

this will be extremely detailed as I can’t solve this problem. I have a website developed with java servlet and jdbc, whose connection method is:

private static synchronized Connection createDBConnection() throws SQLException {
        Connection newConnection = null;
        String ip = "localhost";
        String port = "3306";
        String db = "bookscape";
        String username = "root";
        String password = "password";
        String truststorePath = "/opt/jdk-21.0.3/lib/security/cacerts";
        String truststorePassword = "changeit";

        System.setProperty("javax.net.ssl.trustStore", truststorePath);
        System.setProperty("javax.net.ssl.trustStorePassword", truststorePassword);

        newConnection = DriverManager.getConnection(
            "jdbc:mysql://" + ip + ":" + port + "/" + db +
            "?     useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Europe/Rome&useSSL=true&verifyServerCertificate=true&enabledTLSProtocols=TLSv1.2&requireSSL=true",
            username, password
        );

        newConnection.setAutoCommit(true);

        // verify if ssl is used
        try (Statement stmt = newConnection.createStatement();
                ResultSet rs = stmt.executeQuery("SHOW SESSION STATUS LIKE 'Ssl_cipher'")){
            if (rs.next()) {
                String sslCipher = rs.getString("Value");
                if (sslCipher != null && !sslCipher.isEmpty()) {
                    System.out.println("SSL è attivo. Cifrario SSL utilizzato: " + sslCipher);
                } else {
                    System.out.println("SSL non è attivo.");
                }
            }
        } catch (SQLException e) {
            System.err.println("Errore durante la verifica dell'SSL: " + e.getMessage());
        }

        return newConnection;
    }

I configured the mysql server 50-server.cnf configuration file with:

ssl-ca = /etc/mysql/certs/ca-cert.pem
ssl-cert = /etc/mysql/certs/server-cert.pem
ssl-key = /etc/mysql/certs/server-key.pem
require-secure-transport = on

ssl-cipher=TLSv1.2`

and 50-client.cnf con:

[client]
ssl-ca = /etc/mysql/certs/ca-cert.pem
ssl-cert = /etc/mysql/certs/client-cert.pem
ssl-key  = /etc/mysql/certs/client-key.pem
ssl-verify-server-cert = on

the certificates are all in mysql/certs, I also added them to the default java truststore (cacerts). Now, if I start tomcat, the site works and if I look in catalina.out, I see from the logs that the encryption is happening (console.log in the java code). So everything’s fine, right? ssl configured well and in use, no problems. If instead I try to access mysql from the terminal I get: ERROR 2026 (HY000): TLS/SSL error: Validation of SSL server certificate failed. Why? what’s the reason?

further context, in ~/.bashrc I added:
export CATALINA_HOME=/opt/apache-tomcat-9.0.91
export PATH=$PATH:$CATALINA_HOME/bin
export JAVA_HOME=/opt/jdk-21.0.3
export PATH=$PATH:$JAVA_HOME/bin
export JAVA_OPTS="$JAVA_OPTS -Djava.library.path=/usr/local/apr/lib"
export JAVA_OPTS="$JAVA_OPTS -Djavax.net.ssl.trustStore=/opt/jdk-21.0.3/lib/security/cacerts 
                  -Djavax.net.ssl.trustStorePassword=changeit"

also, the tomcat server and mariadb are running on the same machine (raspberry pi 4)

I tried to check the certificates, everything was ok (on the other hand the connection from Java works as expected), I tried to change permissions, but there was nothing to do there either, I checked in the truststore and the certificates are all there.

New contributor

Marco Renella is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật