{"id":933,"date":"2009-03-29T08:34:38","date_gmt":"2009-03-29T13:34:38","guid":{"rendered":"http:\/\/www.coresecuritypatterns.com\/blogs\/?p=933"},"modified":"2020-08-08T04:01:37","modified_gmt":"2020-08-08T04:01:37","slug":"demystifying-mysql-security-for-web-20-part-1","status":"publish","type":"post","link":"https:\/\/websecuritypatterns.com\/blogs\/2009\/03\/29\/demystifying-mysql-security-for-web-20-part-1\/","title":{"rendered":"Demystifying MySQL Security for Web 2.0: Part 1"},"content":{"rendered":"<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">Web 2.0 applications are proliferating and it has become widely popular for delivering dynamic user-generated content, information collaboration, data mashups, social networking and Web services. Building security for <a href=\"http:\/\/www.websecuritypatterns.com\/blogs\/?p=833\" target=\"_blank\" rel=\"noopener noreferrer\">Web 2.0 applications pose several&nbsp;daunting challenges<\/a> to Web 2.0 developers as&nbsp;these applications are&nbsp;publicly accessible and it blindly opens door to several intentional\/unintentional abuses and malicious practices including data interception and manipulation by cyber-criminals.<span style=\"yes\">&nbsp; <\/span>Unfortunately, Web 2.0 has no silver bullet&nbsp;or one-size fits all security solution ! Interestingly, the most common Web 2.0 security threats pertain to the inherent flaws with the application design, deployment architecture&nbsp;and its failure to proactively identify&nbsp;the potential application-level risks&nbsp; and mitigate them with appropriate countermeasures. <\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">Lately Web 2.0 application databases have become an easier target for cyber criminals &#8211; as it is transparent to user with rich-client applications and draws close proximity to the network perimeter ignoring the traditional logical-tiers of insulation considered with multi-tier architectures (such as Java EE). If we explore the existing Web 2.0 attack patterns and attempt to identify the potential security threats and exploits of Web 2.0 databases, we will find the most common vulnerabilities pertain to the following issues:<\/span><\/p>\n<p class=\"MsoNormal\" style=\"list 1.0in\"><span style=\"Symbol;\"><span style=\"Ignore\"><span style=\"small;\">\u00b7<\/span><span style=\"'Times New Roman';\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"small;\">Eavesdropping database connections<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"list 1.0in\"><span style=\"Symbol;\"><span style=\"Ignore\"><span style=\"small;\">\u00b7<\/span><span style=\"'Times New Roman';\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span style=\"small;\">Un-trusted application clients<\/span><\/p>\n<p class=\"MsoNormal\" style=\"list 1.0in\"><span style=\"Symbol;\"><span style=\"Ignore\"><span style=\"small;\">\u00b7<\/span><span style=\"'Times New Roman';\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span style=\"small;\"><span style=\"small;\">Insufficient authentication controls<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"list 1.0in\"><span style=\"Symbol;\"><span style=\"Ignore\"><span style=\"small;\">\u00b7<\/span><span style=\"'Times New Roman';\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span style=\"small;\">Insecure database access execution privileges<\/span><\/p>\n<p class=\"MsoNormal\" style=\"list 1.0in\"><span style=\"Symbol;\"><span style=\"Ignore\"><span style=\"small;\">\u00b7<\/span><span style=\"'Times New Roman';\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span style=\"small;\">Unauthorized disclosure of user account credentials<\/span><\/p>\n<p class=\"MsoNormal\" style=\"list 1.0in\"><span style=\"Symbol;\"><span style=\"Ignore\"><span style=\"small;\">\u00b7<\/span><span style=\"'Times New Roman';\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span style=\"small;\">Unauthorized access to application data tables<\/span><\/p>\n<p class=\"MsoNormal\" style=\"list 1.0in\"><span style=\"Symbol;\"><span style=\"Ignore\"><span style=\"small;\">\u00b7<\/span><span style=\"'Times New Roman';\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span style=\"small;\">SQL injection or Arbitrary code execution<\/span><\/p>\n<p class=\"MsoNormal\" style=\"list 1.0in\"><span style=\"Symbol;\"><span style=\"Ignore\"><span style=\"small;\">\u00b7<\/span><span style=\"'Times New Roman';\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><\/span><span style=\"small;\">Lack of auditing controls<\/span><\/p>\n<p class=\"MsoNormal\" style=\"list 1.0in\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">Thus it becomes extremely critical to proactively address the known database security issues by deploying appropriate countermeasures and ensuring confidentiality and integrity of the database including user accounts and stored data.<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft\" src=\"http:\/\/dev.mysql.com\/tech-resources\/articles\/sakila-security.png\" alt=\"\" width=\"130\" height=\"104\">MySQL is the most popular open-source database and widely popular in Web 2.0 application environments. <span style=\"yes\">&nbsp;<\/span>MySQL is certainly not my forte! Recently, I had my first experiences with MySQL on couple of projects so I ended up digging deeper into MySQL security and churned up <span style=\"yes\">&nbsp;<\/span>the features for use in Web 2.0 applications.<span style=\"yes\">&nbsp; <\/span>Here is my first installment of my hitchhiker\u2019s view on MySQL security and its relevance to Web 2.0 applications.<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<h2 class=\"MsoNormal\">Securing MySQL database connections<\/h2>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">Enforcing confidentiality and integrity of database communications&nbsp;is critical for thwarting eavesdropping and untrusted client connections.&nbsp;&nbsp;Enabling MySQL connections with SSL\/TLS protocol guarantees transport-layer security and assures that&nbsp;the database communciation&nbsp;is not accessible for unauthorized access and the data exchanged is not modified or altered during transit.<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">To secure communication between the client and the database server,<span style=\"yes\">&nbsp; <\/span>MySQL supports the use of SSL for ensuring transport-level security using encrypted communication.<span style=\"yes\">&nbsp; <\/span>Since MySQL 5.0.x, MySQL bundles yaSSL<span style=\"yes\">&nbsp; <\/span>(compatible with OpenSSL ) to support SSL and related cryptographic requirements.<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<h3 class=\"MsoNormal\"><span style=\"small;\">Configuring MySQL with SSL\/TLS communication<\/span><\/h3>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">If you are using binary versions of MySQL to verify the existence of <strong><em>yaSSL<\/em><\/strong> support, login to the mysql client and try the following:<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">mysql&gt; SHOW VARIABLES LIKE &#8216;have_ssl&#8217;;<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;-+<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">| Variable_name |&nbsp;Value&nbsp; <\/span><\/span><\/em><em><span style=\"Courier;\"><span style=\"small;\">|<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;-+<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">| have_ssl<span style=\"yes\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>| YES<span style=\"yes\">&nbsp;&nbsp; <\/span>|<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;-+<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">&nbsp;<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\"><span>Incase of using MySQL source distribution and if you want to choose OpenSSL<span style=\"yes\">&nbsp; <\/span>(I strongly recommend OpenSSL as it is FIPS-140 certified) as your SSL provider, you may choose to recompile your MySQL server using<span style=\"yes\">&nbsp;<strong><em> <\/em><\/strong><\/span><strong><em>\u2013with-openssl<\/em><\/strong><\/span><span style=\"Times New Roman;\"><span style=\"yes\">&nbsp;&nbsp; <\/span>as configure switches.<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt 0.5in\"><em><span style=\"Courier;\"><span style=\"small;\"># .\/configure &#8211;with-openssl<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">To verify the configuration with OpenSSL<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">mysql&gt; SHOW VARIABLES LIKE &#8216;have_openssl&#8217;;<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;-+<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">| Variable_name | Value |<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;-+<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">| have_openssl<span style=\"yes\">&nbsp; <\/span>| YES<span style=\"yes\">&nbsp;&nbsp; <\/span>|<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;-+<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">To establish an SSL communication, you must obtain the SSL certificates from a certificate authority (CA) (recommended) or alternatively you would able generate the certificates using<span style=\"yes\">&nbsp; <\/span><strong><em>Solaris Key Management Framework (pktool utility) or OpenSSL<\/em><\/strong> (refer my earlier post on <\/span><a href=\"http:\/\/www.coresecuritypatterns.com\/blogs\/?p=763\" target=\"_blank\" rel=\"noopener noreferrer\"><span style=\"small;\">OpenSSL as CA\/SSL Test Kit: Cheat Sheet<\/span><\/a><span style=\"small;\">) .<span style=\"yes\">&nbsp; <\/span>To enable SSL, MySQL requires the following three certificate files for both server and client (if required):<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"list .75in\"><span style=\"Times New Roman;\"><span style=\"Ignore\"><span style=\"small;\">a)<\/span><span style=\"'Times New Roman';\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"small;\">CA certificate<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"list .75in\"><span style=\"Times New Roman;\"><span style=\"Ignore\"><span style=\"small;\">b)<\/span><span style=\"'Times New Roman';\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"small;\">Server certificate<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"list .75in\"><span style=\"Times New Roman;\"><span style=\"Ignore\"><span style=\"small;\">c)<\/span><span style=\"'Times New Roman';\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"small;\">Client certificate<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"list .75in\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\"><span style=\"Times New Roman;\">You may append the location of these certificate files in the <\/span><em><span style=\"Courier;\">[mysqld]<\/span><\/em><span style=\"Times New Roman;\"> and <\/span><em><span style=\"Courier;\">[client]<\/span><\/em><span style=\"Times New Roman;\"> section of the MySQL server configuration file<span style=\"yes\">&nbsp; <\/span><\/span><em><span style=\"Courier;\"><strong>my.cnf<\/strong><\/span><\/em><span style=\"Times New Roman;\">.<span style=\"yes\">&nbsp; <\/span>For example:<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">\u2026<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">[client]<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt 0.5in\"><em><span style=\"Courier;\"><span style=\"small;\">ssl-ca=\/client-certs\/cacert.pem<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">ssl-cert=\/client-certs\/my-new-client-cert.pem<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">ssl-key=\/client-certs\/my-new-client-key.pem<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\"><span style=\"yes\">&nbsp;&nbsp;&nbsp;&nbsp; <\/span>[mysqld]<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt 0.5in\"><em><span style=\"Courier;\"><span style=\"small;\">ssl-ca=\/certs\/cacert.pem<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">ssl-cert=\/certs\/my-new-server-cert.pem<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">ssl-key=\/certs\/my-new-server-key.pem<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\"><span style=\"yes\">&nbsp;&nbsp;&nbsp;&nbsp; <\/span>\u2026<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"Times New Roman;\"><span style=\"small;\">Alternatively, you can specify each certificate as a command-line argument to mysqld (server) and mysql (client) environments.<span style=\"yes\">&nbsp; <\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">To start the MySQL server daemon with the SSL configuration:<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">mysqld <\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\"><span style=\"yes\">&nbsp;<\/span><span style=\"1\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"yes\">&nbsp;&nbsp; <\/span>&#8211;ssl-ca=cacert.pem <\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\"><span style=\"yes\">&nbsp;<\/span><span style=\"1\">&nbsp;&nbsp;&nbsp; <\/span><span style=\"yes\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8211;ssl-cert=my-new-server-cert.pem <\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\"><span style=\"yes\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>-ssl-key=my-new-server-key.pem<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">To start the MySQL client to use SSL, assuming the connecting user has no client certificate authentication requirements:<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">mysql &#8211;ssl-ca=cacert.pem <\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">To start the MySQL client, assuming the connecting user is required to provide a client certificate for SSL authentication:<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\">mysql <\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\"><span style=\"yes\">&nbsp;&nbsp; <\/span><span style=\"1\">&nbsp; <\/span><span style=\"yes\">&nbsp;<\/span>&#8211;ssl-ca=cacert.pem <\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\"><span style=\"yes\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>&#8211;ssl-cert=my-new-client-cert.pem <\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><em><span style=\"Courier;\"><span style=\"small;\"><span style=\"yes\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>-ssl-key=my-new-client-key.pem<\/span><\/span><\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\"><span style=\"Times New Roman;\">To verify configuration and to ensure that the MySQL server uses SSL connection, the status can be checked from the MySQL client using <\/span><em><span style=\"Courier;\"><strong>ssl_cipher<\/strong><\/span><\/em><span style=\"Times New Roman;\"> status variable.<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"Courier;\"><span style=\"small;\">&nbsp;<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"Courier;\"><span style=\"small;\">mysql&gt; SHOW STATUS LIKE &#8216;ssl_cipher&#8217;;<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"Courier;\"><span style=\"small;\">+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"Courier;\"><span style=\"small;\">| Variable_name | Value<span style=\"yes\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>|<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"Courier;\"><span style=\"small;\">+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"Courier;\"><span style=\"small;\">| Ssl_cipher<span style=\"yes\">&nbsp;&nbsp;&nbsp; <\/span>| DHE-RSA-AES256-SHA |<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"Courier;\"><span style=\"small;\">+&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<\/span><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;<\/span><\/p>\n<h3 class=\"MsoNormal\"><span style=\"small;\">Test-driving MySQL SSL&nbsp;connections using JDBC<\/span><\/h3>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">&nbsp;To test-drive SSL communication using JDBC, MySQL Connector\/J&nbsp; (MySQL JDBC driver) supports using SSL communication as long as the MySQL database server and Java client is configured with SSL certificates. To enable JDBC communication with SSL, it requires setting JDBC property <strong><em>requireSSL=true<\/em><\/strong> and <strong><em>useSSL=true<\/em><\/strong>.&nbsp; In case, if you want to validate the Server certificate you may choose to use <strong><em>verifyServerCertificate=true<\/em><\/strong>.<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">Here is the example code, I tried out :<\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\">&nbsp;<\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\"><em>import java.sql.*;<\/em><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\"><em>public class TestJDBCoverSSL&nbsp;&nbsp;&nbsp; {<\/em><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\"><em>public static void main(String args[])&nbsp;&nbsp; { <\/em><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Connection mySQLconnection = null;<\/em><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<\/em><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/Register the JDBC driver for MySQL.<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Class.forName(&#8220;com.mysql.jdbc.Driver&#8221;);<\/em><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String url =&nbsp; &#8220;jdbc:mysql:\/\/localhost:3306\/mysql?&amp;verifyServerCertificate=false&amp;useSSL=true&amp;requireSSL=true&#8221;;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mySQLconnection =&nbsp; DriverManager.getConnection(url,&nbsp; &#8220;jdbcuser&#8221;, &#8220;password&#8221;);<\/em><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/Print URL and connection information<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;URL: &#8221; + url);<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(&#8220;Connection: &#8221; + mySQLconnection);&nbsp;<\/em><\/span><\/p>\n<p><em><br \/>\n<\/em><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/\/ Close the connection<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mySQLconnection.close();<\/em><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\"><em>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; catch(Exception ex)&nbsp; {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ex.printStackTrace();<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; }<\/em><\/span><\/p>\n<p class=\"MsoNormal\" style=\"0in 0in 0pt\"><span style=\"small;\">More importantly, You need to import the SSL certificates in the Java keystore and then provide the Java keystore location&nbsp;properties where the SSL certificates are stored. You may provide these values as -D Java runtime options on the command line as follows: <\/span><\/p>\n<pre><em>-Djavax.net.ssl.keyStore=path_to_Java_keystore_file<\/em><\/pre>\n<pre><em>-Djavax.net.ssl.keyStorePassword=JavaKeyStore_password\n<\/em><\/pre>\n<pre><em>-Djavax.net.ssl.trustStore=path_to_Java_truststore_file<\/em><\/pre>\n<pre><em>-<\/em><em>Djavax.net.ssl.trustStorePassword=JavaTruststore_password<\/em><\/pre>\n<p>Alternatively, you may incorporate the Java keystore and truststore properties&nbsp;in the JDBC application:<\/p>\n<pre><em>System.setProperty(\"javax.net.ssl.keyStore\",\"path_to_Java_keystore_file\");\n<\/em><\/pre>\n<pre><em>System.setProperty(\"javax.net.ssl.keyStorePassword\",\"JavaKeyStore_password\");\n<\/em><\/pre>\n<pre><em>System.setProperty(\"javax.net.ssl.trustStore\",\"path_to_Java_truststore_file\");\n<\/em><\/pre>\n<pre><em>System.setProperty(\"javax.net.ssl.trustStorePassword\",\"JavaTruststore_password\");<\/em><\/pre>\n<p><span style=\"black;\"><span style=\"small;\">To summarize, enabling SSL\/TLS based MySQL connections ensure trusted communication between MySQL clients and the database server. It helps thwarting attacks related to&nbsp;eavesdropping MySQL communications, Man-in-the-Middle (MITM), Forged requests and so forth.&nbsp; In my next post, I will discuss how to secure user accounts and enable stronger authentication controls in MySQL.<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Web 2.0 applications are proliferating and it has become widely popular for delivering dynamic user-generated content, information collaboration, data mashups, social networking and Web services. Building security for Web 2.0 applications pose several&nbsp;daunting challenges to Web 2.0 developers as&nbsp;these applications are&nbsp;publicly accessible and it blindly opens door to several intentional\/unintentional abuses and malicious practices including data interception and manipulation by&#8230; <a href=\"https:\/\/websecuritypatterns.com\/blogs\/2009\/03\/29\/demystifying-mysql-security-for-web-20-part-1\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[17,20,6,9],"tags":[37,48,50,57,62,73],"class_list":["post-933","post","type-post","status-publish","format-standard","hentry","category-database-security","category-java-ee","category-main","category-security","tag-j2ee","tag-mysql","tag-openssl","tag-pki-main","tag-security","tag-web2-0"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/posts\/933","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/comments?post=933"}],"version-history":[{"count":1,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/posts\/933\/revisions"}],"predecessor-version":[{"id":2831,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/posts\/933\/revisions\/2831"}],"wp:attachment":[{"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/media?parent=933"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/categories?post=933"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/websecuritypatterns.com\/blogs\/wp-json\/wp\/v2\/tags?post=933"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}