Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encrypting db password in application.conf

Play framework [I'm using v1.2.3] does not support db password encryption stored in the application.conf. This is stored as a plain-text file. DBPlugin reads this property and creates a Connection pool.

The requirement is to encrypt this password - for e.g. using Jasypt. Some enterprises enforce this as a security measure.

Has anybody tried doing something like this?

Since DBPlugin loads on ApplicationStart, there is no way to hack it. That leaves to write a custom plugin and onConfigurationRead set a new value for the db.password of application.conf property.

Any suggestions?

like image 801
basav Avatar asked Feb 08 '12 19:02

basav


People also ask

How do I encrypt an Access database password?

On the File tab, click Info, and then click Encrypt with Password. The Set Database Password dialog box appears. Type your password in the Password box, type it again in the Verify box, and then click OK.

Are passwords encrypted in database?

Storing plain text passwords in the database is a sin. Encryption functions provide one-one mapping between input and output and they are always reversible. If the hacker gets the key, he will be able to decrypt the passwords. The better way would be to use a one way cryptographic hash function.

How does encryption work with passwords?

Password Encryption: How Do Password Encryption Methods Work? Encryption scrambles your password so it's unreadable and/or unusable by hackers. That simple step protects your password while it's sitting in a server, and it offers more protection as your password zooms across the internet.

What encryption does passwd use?

Passwords within the /etc/passwd file are encrypted using a randomly generated value or encryption key between 1 and 4,096 and a one-way hashing function. The key or salt is also stored with the encoded password.


2 Answers

Finally I fixed this by writing a Play Plugin. Writing a Play plugin is also very easy. Here is the sample code:

package plugin;

import java.util.Properties;

import org.jasypt.util.text.StrongTextEncryptor;

import play.Play;
import play.PlayPlugin;

public class DBPasswordInject extends PlayPlugin {

    @Override
    public void onConfigurationRead() {
        StrongTextEncryptor strongTextEncryptor = new StrongTextEncryptor();
        strongTextEncryptor.setPassword("$Look##$2");// this password has been used to encrypt

        String encryptedPassword = Play.configuration.getProperty("db.pass");
        String decrypted = strongTextEncryptor.decrypt(encryptedPassword);
        Play.configuration.setProperty("db.pass", decrypted); //override

        super.onConfigurationRead();
    }

}

The only downside is that I was not able to use org.jasypt.util.password.StrongPasswordEncryptor - because there is no decrypt method.

like image 90
basav Avatar answered Nov 12 '22 04:11

basav


Well the problem is which password should be used to encrypt the password? If you use a default password it's not safe too. If you put it into the configuration file you have a recursive problem. The only solution I see is to use your own plugin where the password is stored and change the values in the application properties. Then the password can be stored crytped with no problems. At least in Play1.x.

like image 29
niels Avatar answered Nov 12 '22 03:11

niels