Skip to content

Add encryption support for PropertyPlaceholderConfigurer [SPR-10666] #15294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Jun 19, 2013 · 13 comments
Labels
status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jun 19, 2013

Michael Isvy opened SPR-10666 and commented

At this stage, Spring does not provide support for encrypted property values.

For instance, if I externalize my values in a properties file using a property-placeholder, I can only have the following inside my properties file:

jdbc.username=admin
jdbc.password=secret

I would like to be able to use the following instead:

jdbc.username=admin
jdbc.password={md5}bface9aa8e675d3a1757f143893793db

(syntax is just a draft, you might find something more appropriate)

We could have a new class that inherits from PropertyPlaceholderConfigurer and adds the encryption features.

And we could add a property to the namespace as follows:

<context:property-placeholder useEncryption="true" location="classpath:spring/data-access.properties"/>

( 'useEncryption' could default to true or false depending on what you find more appropriate).


Issue Links:

2 votes, 11 watchers

@spring-projects-issues
Copy link
Collaborator Author

Phil Webb commented

One problem with this type of encryption is that we need to decrypt the property values before they can be used. This means we would need some way to configure a master key. We also would also need to use a symmetric encryption algorithm (such as DES). Your example above shows an MD5 hash being used as the value, this can work in challenge-response scenarios, but I don't think it will work for property values as we will have no way of getting back the original value.

Another inherent weakness with this type of scheme is that the properties file and application are usually co-located, meaning that an attacker would effectively have access to key by unpacking the jar (and possibly decompiling some .class file).

@spring-projects-issues
Copy link
Collaborator Author

Michael Isvy commented

Hi Phil,
I was just thinking we can do something similar to what we have already in place in Spring Security (which is why I used that syntax).
Unless you see any issue there?

@spring-projects-issues
Copy link
Collaborator Author

Phil Webb commented

I am not familiar with that, can you point me at an example?

@spring-projects-issues
Copy link
Collaborator Author

Michael Isvy commented

Sure!
You can check here for instance:
http://www.mkyong.com/spring-security/spring-security-password-hashing-example/

I thought that Spring Security was using a prefix such as {MD5} but that's not needed.

@spring-projects-issues
Copy link
Collaborator Author

Phil Webb commented

robwinch can probably chime in here but I assume this is only possible in Spring Security because this is testing against user entered input.

e.g:

  • User types 'password'
  • A SHA1 of 'password' is created
  • The SHA1 can be compared to the value in the configuration

The problem is that there is no way to get back to 'password' if you only have the SHA1.

@spring-projects-issues
Copy link
Collaborator Author

Michael Isvy commented

Actually, Jasypt seems to offer exactly that :).
www.jasypt.org/api/jasypt/1.8/org/jasypt/spring/properties/EncryptablePropertyPlaceholderConfigurer.html

(adding Daniel who is the creator of Jasypt)
Daniel Fernández

@spring-projects-issues
Copy link
Collaborator Author

Daniel Fernández commented

Yup, Jasypt can do that.

In fact, in version 1.9 I even added a Spring namespace so that these encrypting structures can be declared like:

<encryption:encryptable-property-placeholder encryptor="stringEnc" location="classpath:application.properties"/>

...or even directly an encrypted .properties file (equivalent to "util:properties") like:

<encryption:encryptable-properties encryptor="stringEnc" location="classpath:application.properties"/>

Of course in both cases you will have to first declare and configure that "stringEnc" bean, which is the encryptor object in charge of encrypting/decrypting properties in those files.

See more info here: http://www.jasypt.org/spring31.html

@spring-projects-issues
Copy link
Collaborator Author

Rob Winch commented

Encryption can be done (as is done in Jasypt), but one way hashes such as SHA1 cannot be done in this case for the reasons Phil mentioned. In the past when such use cases needed to be addressed I have always recommended Jasypt as IMHO it is an exceptional library.

If Daniel is interested, perhaps we can collaborate to see if/how we could get first class support in Spring Security.

@spring-projects-issues
Copy link
Collaborator Author

Phil Webb commented

Recommending the use of Jasypt or possibly adding first class support to Spring Security seems like the best option here. The core framework classes are flexible enough to support the feature and I think it would be best not to add too much more to the core.

I will leave this as "Contributions Welcome" and see how many votes we get.

@spring-projects-issues
Copy link
Collaborator Author

Daniel Fernández commented

Well... if you have any specific ideas regarding jasypt integration in the future, I'll be happy to discuss them with you :-)

@spring-projects-issues
Copy link
Collaborator Author

Rob Winch commented

I think at this point this issue is a duplicate of SEC-3123.

@spring-projects-issues
Copy link
Collaborator Author

Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: bulk-closed An outdated, unresolved issue that's closed in bulk as part of a cleaning process
Projects
None yet
Development

No branches or pull requests

2 participants