Leave a comment at the end of this page or email contact@krishagni.com
How to implement DB encryption for MySQL?
Introduction
To ensure data privacy and minimize data vulnerability, OpenSpecimen provides an option to encrypt the MySQL database "at rest" and "in transit".
At Rest: Ensures the database files are in an encrypted format on the disk.
In Transit: Ensures the data passing through the network to the application is encrypted.
In both techniques, the malicious user won't be able to decrypt data.
Encrypting Data At Rest
In the database, all the patient data is stored in data files. There is a chance that an attacker can retrieve sensitive data if they get direct access to such files. To avoid this, one can encrypt the data files using the keyring plugin provided by MySQL.
The keyring file is the main file that stores key using which the tablespace (where all table data files are stored) is encrypted. The keyring plugin is used for this purpose.
Before encryption: Data is in a human-readable format.
After encryption: Data is encrypted.
Step 1: Enable the keyring plugin
Step 2: Verify if the plugin is enabled or not
Step 3: Encrypt database tables
Encrypting Data In Transit
In this step, we create self-signed SSL certificates for MySQL server to communicate using SSL. The certificate file is shared with the application so that it can store certificates in its TrustStore file and application can trust the MySQL server.
Step 1: Certificate creation
Step 2: Configure certificate in MySQL
In this step, we configure the SSL certificate files into the MySQL server. This will notify the MySQL about which certificate to use and enable security flags.
Each time when MySQL communicates with the application, the connection is secured using these certificate files.
Step 3: Add the certificate in the Java TrustStore.
A Java TrustStore file holds certificates that authenticate other applications; for example, MySQL server. Using this file, OpenSpecimen will trust MySQL as a legit partner.
The JVM (client), look up the certificates in its TrustStore. If the certificate or Certificate Authorities presented by the MySQL is not in our TrustStore then the application gives an SSLHandshakeException and connection won’t be set up successfully.
Step 4: Enable encryption in Tomcat.
The useSSL=true property is added to the JDBC URL to communicate with the database via SSL. This property can be added to only connect if the database server supports SSL.
Leave a comment at the end of this page or email contact@krishagni.com