Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to protect a MySQL database from unauthorized access and securely connect to it from a Java application

Okay, I apologize in advance for this question, as it is quite broad.

Basically, I am developing a system involving:

  1. A website where users can register an account. This process will create a new database on the server for that account.
  2. A client side external application written in Java. This will access the data in the database in order to perform useful operations for the user.
  3. The databases themselves which are created in the first point.

My question is about what security measures should be implemented in order to keep the databases secure and how to transfer data securely.

My concerns are:

  1. How is a MySQL database actually secured? When I create the database at the point of account registration, do I need to set a password for that database? Does this encrypt the database? Is this enough to prevent someone from accessing the data?
  2. Java is pretty easy to decompile. Assuming I am to store the log in data for an account database in a master database, how do I secure that database and connect to it from my application in a way which doesn't require me to hard code the details for connecting to that database in the application. I believe this must be an issue in languages which are compiled to native code too, as someone could just perform a memory dump to get hold of such variables at run time of the application (I think).
  3. When sending and receiving data to the client from the server and vice versa, how do I prevent someone from network eavesdropping and getting hold of the data (whether this be log in credentials or other data from the database). I assume this is what SSL is for, but is that all I need to use?

A possible answer to these questions is to use a middle man service in between the Java client side application and the database, much the same way you would use PHP in between Javascript and a MySQL database (although the PHP is a necessity in this case). I assume this middle man service would contain the log in credentials for the master database etc. and would contain its own methods for preventing unauthorized access. If this is correct, how would I go about setting up such a service? Would it be possible to utilize a PHP script from a Java application to transfer data?

I hope my question makes sense and isn't too ambiguous. Thanks in advance for your time.

like image 286
Ben Guest Avatar asked Dec 06 '25 04:12

Ben Guest


2 Answers

How is a MySQL database actually secured? When I create the database at the point of account registration, do I need to set a password for that database? Does this encrypt the database? Is this enough to prevent someone from accessing the data?

  1. Using an account name and password, together with different access rights for particular databases "granted" to different users.

  2. The password is associated with the user account, not the database.

  3. MySQL databases are not encrypted.

  4. Yes ... though if untrusted people can gain admin control of the database itself, or the system that hosts the database, then all bets are off.

Java is pretty easy to decompile. Assuming I am to store the log in data for an account database in a master database, how do I secure that database and connect to it from my application in a way which doesn't require me to hard code the details for connecting to that database in the application.

A common approach is to put the connection details and/or account credentials into a Properties file that the application loads at startup time. However, I think your real issue is that you want to allow updates to the database by applications running on untrusted machines. A more sensible solution to that is to run a trusted service on a properly secured machine and have the untrusted machines talk to the trusted service and NOT directly to the database.

I believe this must be an issue in languages which are compiled to native code too, as someone could just perform a memory dump to get hold of such variables at run time of the application (I think).

That is correct.

When sending and receiving data to the client from the server and vice versa, how do I prevent someone from network eavesdropping and getting hold of the data (whether this be log in credentials or other data from the database). I assume this is what SSL is for, but is that all I need to use?

SSL is sufficient for securing data (or credentials) that are sent over the network.

The situation with man-in-the-middle attacks is murky, certainly when it comes to web browsers and whether trusted roots should really be trusted. But if I understood what I read correctly, there is a way to use SSL that should be immune to MITM. Basically you need to generate individual SSL certificates for all participants (clients, servers) and distribute them to all using an out-of-band distribution mechanism; i.e. NOT over the internet. Then you only accept SSL connections from parties with a known certificate. And make sure that you use TLS 1.1 or 1.2.

like image 158
Stephen C Avatar answered Dec 07 '25 17:12

Stephen C


I see some possibilities -

  1. Using jBoss SX framework
  2. Using EJBs is another thing, which provides the requried layers of abstraction.
  3. JCA components can be used on middle-man components

Finally SQL injections can also be accessed through some of the available tools like the sqlMAP.

like image 24
Larsen Avatar answered Dec 07 '25 17:12

Larsen