Skip to content

Commit 239c1b1

Browse files
authored
Jasypt documentation corrected. (#381)
1 parent 7d9e327 commit 239c1b1

File tree

1 file changed

+24
-50
lines changed

1 file changed

+24
-50
lines changed

documentation/guide-configuration.asciidoc

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,13 @@ We recommend the following base layout for the hierarchical business configurati
152152

153153
`component.[subcomponent].[subcomponent].propertyname`
154154

155+
155156
== Security
156157
Often you need to have passwords (for databases, third-party services, etc.) as part of your configuration. These are typically environment specific (see above). However, with DevOps and continuous-deployment you might be tempted to commit such configurations into your version-control (e.g. `git`). Doing that with plain text passwords is a severe problem especially for production systems. Never do that! Instead we offer some suggestions how to deal with sensible configurations:
157158

158159
=== Password Encryption
159160
A simple but reasonable approach is to configure the passwords encrypted with a master-password. The master-password should be a strong secret that is specific for each environment. It must never be committed to version-control.
160-
In order to support encrypted passwords in spring-boot `application.properties` all you need to do is to add https://github.com/ulisesbocchio/jasypt-spring-boot#jasypt-spring-boot[jasypt-spring-boot] as dependency in your `pom.xml`(please check for recent version link:https://mvnrepository.com/artifact/com.github.ulisesbocchio/jasypt-spring-boot-starter[here]):
161+
In order to support encrypted passwords in spring-boot `application.properties` all you need to do is to add https://github.com/ulisesbocchio/jasypt-spring-boot#jasypt-spring-boot[jasypt-spring-boot] as dependency in your `pom.xml` (please check for recent version link:https://mvnrepository.com/artifact/com.github.ulisesbocchio/jasypt-spring-boot-starter[here]):
161162
[source, xml]
162163
----
163164
<dependency>
@@ -166,83 +167,56 @@ In order to support encrypted passwords in spring-boot `application.properties`
166167
<version>3.0.3</version>
167168
</dependency>
168169
----
169-
This will smoothly integrate http://jasypt.org/[jasypt] into your https://projects.spring.io/spring-boot/[spring-boot] application. Read this https://apereo.atlassian.net/wiki/spaces/CASUM/pages/103261428/HOWTO+Use+Jasypt+to+encrypt+passwords+in+configuration+files[HOWTO] to learn how to encrypt and decrypt passwords using jasypt. Here is a simple example output of an encrypted password (of course you have to use strong passwords instead of `secret` and `postgres` - this is only an example):
170+
This will smoothly integrate http://jasypt.org/[jasypt] into your https://projects.spring.io/spring-boot/[spring-boot] application. Read this https://apereo.atlassian.net/wiki/spaces/CASUM/pages/103261428/HOWTO+Use+Jasypt+to+encrypt+passwords+in+configuration+files[HOWTO] to learn how to encrypt and decrypt passwords using jasypt.
170171

172+
Here we give a simple example how to encypt and configure a secret value. Different algorithms can be used if perferred (e.g. `PBEWITHMD5ANDTRIPLEDES`). However, the default in jasypt is `PBEWITHHMACSHA512ANDAES_256` that provides strong encryption.
171173
----
172-
jasypt-1.9.3\bin>java -cp ${M2_REPO}/org/jasypt/jasypt/1.9.3/jasypt-1.9.3.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI password=secret algorithm=PBEWITHHMACSHA512ANDAES_256 input=postgres ivGeneratorClassName=org.jasypt.iv.RandomIvGenerator
174+
java -cp ${M2_REPO}/org/jasypt/jasypt/1.9.3/jasypt-1.9.3.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI password=masterpassword algorithm=PBEWITHHMACSHA512ANDAES_256 input=secret ivGeneratorClassName=org.jasypt.iv.RandomIvGenerator
173175
174176
----ENVIRONMENT-----------------
175177
176-
Runtime: Oracle Corporation OpenJDK 64-Bit Server VM 12+33
178+
Runtime: AdoptOpenJDK OpenJDK 64-Bit Server VM 11.0.5+10
179+
180+
177181
178182
----ARGUMENTS-------------------
179183
180-
input: postgres
181-
password: secret
184+
input: secret
185+
password: masterpassword
182186
ivGeneratorClassName: org.jasypt.iv.RandomIvGenerator
183187
algorithm: PBEWITHHMACSHA512ANDAES_256
184188
189+
190+
185191
----OUTPUT----------------------
186192
187-
vRZkKth6WKCtzUAGdx/+NUPjhzYvBZXjXQDPillqUrWB1I59bdFM66UQ6SYmJrE4
193+
PoUxkNjY2juQMCyPu6ic5KJy1XfK+bX9vu2/mPj3pmcO4iydG6mhgZRZSw50z/oC
188194
189195
----
196+
Of course the master-password (`masterpassword`) and the actual password to encrypt (`secret`) are just examples.
197+
Please replace them with reasonable strong passwords for your environment.
198+
There entire line after the `OUTPUT` block is your encrypted secret.
199+
It even contains some random salt so that multiple encryption invocations with the same parameters (`ARGUMENTS`) will produce a different `OUTPUT`.
190200

191201
The master-password can be configured on your target environment via the property `jasypt.encryptor.password`. As system properties given on the command-line are visible in the process list, we recommend to use an `config/application.yml` file only for this purpose (as we recommended to use `application.properties` for regular configs):
192202
```
193203
jasypt:
194204
encryptor:
195-
password: «secret»
205+
password: masterpassword
196206
```
197-
(of course you will replace `«secret»` with a strong password). In case you happen to have multiple apps on the same machine, you can symlink the `application.yml` from a central place.
198-
Now you are able to put encrypted passwords into your `application.properties`
207+
Again `masterpassword` is just an example that your replace with your actual master password.
208+
Now you are able to put encrypted passwords into your `application.properties` and specify the algorithm.
199209
```
200-
spring.datasource.password=ENC(vRZkKth6WKCtzUAGdx/+NUPjhzYvBZXjXQDPillqUrWB1I59bdFM66UQ6SYmJrE4)
210+
spring.datasource.password=ENC(PoUxkNjY2juQMCyPu6ic5KJy1XfK+bX9vu2/mPj3pmcO4iydG6mhgZRZSw50z/oC)
211+
jasypt.encryptor.algorithm=PBEWITHHMACSHA512ANDAES_256
201212
```
213+
This `application.properties` file can be version controlled (git-opts) and without knowing the masterpassword nobody is able to decrypt this to get the actual secret back.
202214

203-
To prevent jasypt to throw an exception in dev or test scenarios simply put this in your local config (`src/main/config/application.properties` and same for `test`, see above for details):
215+
To prevent jasypt to throw an exception in dev or test scenarios you can simply put this in your local config (`src/main/config/application.properties` and same for `test`, see above for details):
204216
```
205217
jasypt.encryptor.password=none
206218
```
207219

208-
==== Configure Algorithm
209-
Algorithm can be configured for stronger encryption. Jasypt uses PBEWITHHMACSHA512ANDAES_256 as the Default encryption algorithm.
210-
Algorithm can be configured through System, properties file, command line argumments, environment variable etc.
211-
212-
Here is an example on how to use different algorithm for encryption and decryption.
213-
214-
Use the below command to encrypt, specify the algorithm PBEWITHMD5ANDTRIPLEDES with master password "secret" and the string to be encrypted as "postgres"
215-
----
216-
jasypt-1.9.3\bin>java -cp ${M2_REPO}/org/jasypt/jasypt/1.9.3/jasypt-1.9.3.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI password=secret algorithm=PBEWITHMD5ANDTRIPLEDES input=postgres ivGeneratorClassName=org.jasypt.iv.RandomIvGenerator
217-
218-
----ENVIRONMENT-----------------
219-
220-
Runtime: Oracle Corporation OpenJDK 64-Bit Server VM 12+33
221-
222-
----ARGUMENTS-------------------
223-
224-
input: postgres
225-
password: secret
226-
ivGeneratorClassName: org.jasypt.iv.RandomIvGenerator
227-
algorithm: PBEWITHMD5ANDTRIPLEDES
228-
229-
----OUTPUT----------------------
230-
231-
vCfZDp9Ru3+GsGy39rpE6gWJ8LJexaz6KeFSm+KQnyI=
232-
----
233-
234-
For decryption, specify the algorithm in the "applicaiton.properties" file as shown here. Keep the master password in config/application.yaml as described above.
235-
236-
----
237-
spring.datasource.password=ENC(vCfZDp9Ru3+GsGy39rpE6gWJ8LJexaz6KeFSm+KQnyI=)
238-
jasypt.encryptor.algorithm=PBEWITHMD5ANDTRIPLEDES
239-
----
240-
241-
242-
Other configurable properties can be found https://github.com/ulisesbocchio/jasypt-spring-boot#password-based-encryption-configuration[here]
243-
244-
AES is considered secure in available encryption algorithms, PBEWITHHMACSHA512ANDAES_256 as highest level, which is the default algorithm as on Jasypt version 1.9.3. Our recommendation is to use the default (PBEWITHHMACSHA512ANDAES_256), which means algorithm need not be specified.
245-
246220
==== Is this Security by Obscurity?
247221

248222
* Yes, from the point of view to protect the passwords on the target environment this is nothing but security by obscurity. If an attacker somehow got full access to the machine this will only cause him to spend some more time.

0 commit comments

Comments
 (0)