views:

166

answers:

3

I just realized that there is no best way to hide MySQL string connection password in my executable file, especially in JAR file. Even encrypting it in EXE would only slow down the process (although I'm not sure how much time would it take to get an encrypted password from an EXE file).

So, from my understanding, I need something in the middle that would do the add, edit, delete etc to the database. Seems like a job for REST API or maybe SOAP services.

My question is, which one should I use? Or should I use something else? I was thinking Zend Framework to create those REST APIs. Then, I would use Qt to create a desktop application to call those APIs. But if I proceed with REST, my application would be a 3 tier application. Wouldn't it be better if I just create a web application? Maybe I should just stick to desktop application call those APIs since the application is already finished and I just need to change from connecting directly to MySQL to calling those APIs to perform tasks rather than changing the whole application to a web.

Any advice would be very helpful. Thanks in advance.

UPDATE:

I'm looking for a security that would protect my MySQL password connection.

Obfuscator would only obfuscate the code, it won't hide my string database information which In my opinion can be easily found using grep after decompiling the JAR using tools like JAD.

About my application:

  1. Using a centralized MySQL database
  2. Thousands of user
  3. Contains sensitive information
  4. My client uses Linux and Windows
  5. My server uses Linux
  6. All access are done in LAN, no outside connection (from Internet etc)

My current solutions (comments please):

  1. Using REST APIs (safer since MySQL password is in the server)
  2. Using Qt with encryption to the password
+2  A: 

It depends on what kind of security are you looking for. Is this to protect the application from the user? To protect the user's data from other users? To protect multiple users' data from one another? To protect the user's data from an attacker?

In a lot of applications there's nothing wrong with storing the database login credentials in plain text. In other cases, you might try:

  1. encrypting a user-chosen database password using a reasonably strong algorithm, e.g. Blowfish, using a hard-coded key;
  2. having the user provide the password and "log in" to the program each time;
  3. storing the database password in plain-text, but encrypt the data using a hard-coded key;
  4. same as the above, but encrypt each user's data using their own provided password;
  5. same as 2 but store each user's data in their own database with their login info as the database credentials;
  6. storing the data on a secure remote database that users have to log into to access via a SOAP API;
  7. using the native filesystem permissions to protect the configuration file holding the login credentials;
  8. same as #1 but rolling your own really elaborate key-generation system: e.g. run the machine SID or a hardware id through MD5 using a randomly-generated salt, and then using the result to encrypt the login credentials.

Remember, there's no such thing as perfect security, so whatever you settle on doesn't need to be unbreakable. It just needs to be tough enough to break to make the hassle of circumventing the security mechanism exceed the value of the data. So, for example, if the data is a list of the top scores in Minesweeper, then ROT13 would probably be enough.

Edit: I just want to add that, even if you can't get around having to hard-code an encryption key in your application, there are obfuscators for Java, .NET, and most other popular languages/frameworks. One of the key uses of these tools is to hide sensitive hard-coded strings like encryption keys.

Edit 2: Given the additional details about the app in question, only 1, 6 and 8 would apply in this case. And a SOAP API is more appropriate for #6 as George rightly pointed out.

I also want to mention that there are Java resource obfuscators that encrypt string literals. This is just one example.

Lèse majesté
I'm going to disagree about there's nothing wrong storing the database login credentials in plain text. Someone could easily connect to the server directly without my permission.1) This doesn't protect my MySQL password.2) Same as above (although I did enforce a login for my users).3) As I've mentioned, this would only slow down the process (4) If the attacker gains my MySQL password, it can delete all of my data which would make data encryption pointless.5) I got thousands of users.6) I'm considering this one.7) I don't think this method can be implemented in Windows.8) Same as #1
aurorius
I guess I should have made it more clear that by "user-chosen password" I mean let the user specify the DB password. And while it's not appropriate in _all_ circumstances, plain-text login credentials are permissible in some circumstances--e.g. when the database does not contain critical/sensitive data.
Lèse majesté
Thanks for the clarification. But giving a user (in my case, thousands of them) a user-chosen db password would not be very helpful. For an example, User A has to be given an access to read, update, and delete to a certain table. If the user's DB password was compromised, the attacker can use it to connect to my MySQL and delete the row one by one.
aurorius
@cekpo I don't believe that a REST API would be appropriate here at all. REST is all about being 'stateless.' In other words, it's an approach that avoids storing state data between requests, each request being atomic and containing all information needed for that request. Another way to put it, using sessions on a webserver pretty much goes against the REST approach of HTTP. Take a look at this *cringe* wikipedia article: http://en.wikipedia.org/wiki/Representational_State_Transfer
George Marian
+1  A: 

It pretty much depends in what environment your app runs

a) db and client local
b) db and client in a local network
c) db is in the internet

my two cents:

a) I would create a single db user and wouldn't use a password but restrict acces to localhost
b) direct connect to the database is fine but I would each user have to login with his own password and grant only the permissions he needs.
c) It's a bad idea to allow mysql connections to a public server. In this case webservices would be a good solution.

Anyway if your case is b or c I would stick with a login dialog for the user.

Maybe you should have a look at this http://www.greensql.net/ tool. It is like a firewall but for mysql/postresql
So you can deny anything and only allow queries you want to.

SchlaWiener
My application is in category (b) ...a) I can't since my users are everywhere, they need to be able to access the data remotely.b) I don't think MySQL can limit the user to which rows it can delete and which one it can read unless I did it programatically.
aurorius
You can achieve some kind of row level security by using triggers and views. But if you really need that kind of security you should consider using web services or building a web app.
SchlaWiener
As you mentioned in another post you are worried about someone with a password deleting all your data. With greensql (the link I provided) you can setup a rule preventing someone to execute a delete command without a where clause containing the id column. That would at least prevent someone to delete more than one row. And you have a total control about which queries are allowed. If someone tries to execute a statement you don't explicitly whitelisted before it it blocked.
SchlaWiener
GreenSQL is a good stuff, but it won't protect my MySQL password in my executable. Besides, the attacker can use 'DELETE FROM table1 LIMIT 1' multiple times just to screw up my database. That's why I need a way to prevent my database password getting read by anyone. REST API is one of solutions I have in my mind. I was hoping someone would comment on that.
aurorius
+1  A: 

If you are using Java for implementing your database desktop application, I would recommend to use Java DB as the database. There is a few ways of securing it, and there are alternatives to having a password in the connection string. I would recommend to read Java DB Security - Security Features in Java DB Release 10.4

It is easy to deploy your application with Java DB, since you can have much of it embedded in the same jar file. I have used it in a Point of Sale application implemented in Java.

Jonas
Thanks, it's definitely a good read. But I've given up hope on Java Desktop Application since it can be easily be decompiled using tools like JAD. Whatever put there can be read by the attacker. I might as well use Qt to develop my app, at least it will take longer for the attacker to have my MySQL password.
aurorius