ulisesbocchio / jasypt-spring-boot

Jasypt integration for Spring boot
MIT License
2.88k stars 514 forks source link

Can't decrypt value on a different machine #59

Closed mryhmln closed 7 years ago

mryhmln commented 7 years ago

So I'm using integration/configuration method #1 (adding the starter jar dependency to my project). I added the dependency to my project, downloaded the latest jasypt (1.9.2) for Windows, encrypted an application property using the jasypt encrypt command line utility (with just the input and password parameters... everything else was defaults) and then put the encrypted value into my application.properties file using the standard "ENC(encrypted_value)" jasypt syntax, then I built my JAR locally and then ran it using the JAVA_OPTS setting "-Djasypt.encryptor.password="password-i-used-to-encrypt-the-value", and everything worked fine. Then another developer on the team downloaded the code base to his machine (also Windows) and tried running it with the password and it did not work. It was unable to decrypt the value, giving the following set of errors:

2017-09-05 16:54:40.606  INFO 8440 --- [ost-startStop-1] EncryptablePropertyResolverConfiguration : String Encryptor custom Bean not found with name 'jasyptStringEncryptor'. Initializing String Encryptor based on properties with name 'jasyptStringEncryptor'
2017-09-05 16:54:40.667  INFO 8440 --- [ost-startStop-1] c.u.j.encryptor.DefaultLazyEncryptor     : Encryptor config not found for property jasypt.encryptor.algorithm, using default value: PBEWithMD5AndDES
2017-09-05 16:54:40.667  INFO 8440 --- [ost-startStop-1] c.u.j.encryptor.DefaultLazyEncryptor     : Encryptor config not found for property jasypt.encryptor.keyObtentionIterations, using default value: 1000
2017-09-05 16:54:40.668  INFO 8440 --- [ost-startStop-1] c.u.j.encryptor.DefaultLazyEncryptor     : Encryptor config not found for property jasypt.encryptor.poolSize, using default value: 1
2017-09-05 16:54:40.668  INFO 8440 --- [ost-startStop-1] c.u.j.encryptor.DefaultLazyEncryptor     : Encryptor config not found for property jasypt.encryptor.providerName, using default value: null
2017-09-05 16:54:40.668  INFO 8440 --- [ost-startStop-1] c.u.j.encryptor.DefaultLazyEncryptor     : Encryptor config not found for property jasypt.encryptor.saltGeneratorClassname, using default value: org.jasypt.salt.RandomSaltGenerator
2017-09-05 16:54:40.669  INFO 8440 --- [ost-startStop-1] c.u.j.encryptor.DefaultLazyEncryptor     : Encryptor config not found for property jasypt.encryptor.stringOutputType, using default value: base64

Note that he also downloaded jasypt version 1.9.2 and WAS able to decrypt the value using the password. But for some reason it's not working comparably from within the app. Any thoughts on what could be going wrong?

ulisesbocchio commented 7 years ago

Hi @mryhmln none of the logs you show are errors. Just INFO logs telling you some default values were used. My bet would be either be on:

mryhmln commented 7 years ago

I wish it were that straight forward. But unfortunately I sent him the exact same parameters I was using to launch the JAR (which worked for me) and he cut and pasted them directly into his terminal and got the error. Also, from the logs it looks like it's defaulting to PBEWithMD5AndDES encryption. I confirmed in the jasypt command line utility that I was able to decrypt the password with that algorithm, and so was my friend.

Also, sorry I didn't send over the actual error. Here is the complete log file up to and including the error (I commented out the app name but other than that it's verbatim):

2017-09-05 16:54:30.329  INFO 8440 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@6d21714c: startup date [Tue Sep 05 16:54:30 EDT 2017]; root of context hierarchy
2017-09-05 16:54:33.671  WARN 8440 --- [           main] o.s.c.a.ConfigurationClassPostProcessor  : Cannot enhance @Configuration bean definition 'beanNamePlaceholderRegistryPostProcessor' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.
2017-09-05 16:54:34.112  INFO 8440 --- [           main] ptablePropertiesBeanFactoryPostProcessor : Post-processing PropertySource instances
2017-09-05 16:54:34.175  INFO 8440 --- [           main] ptablePropertiesBeanFactoryPostProcessor : Converting PropertySource servletConfigInitParams [org.springframework.core.env.PropertySource$StubPropertySource] to EncryptablePropertySourceWrapper
2017-09-05 16:54:34.180  INFO 8440 --- [           main] ptablePropertiesBeanFactoryPostProcessor : Converting PropertySource servletContextInitParams [org.springframework.core.env.PropertySource$StubPropertySource] to EncryptablePropertySourceWrapper
2017-09-05 16:54:34.181  INFO 8440 --- [           main] ptablePropertiesBeanFactoryPostProcessor : Converting PropertySource systemProperties [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
2017-09-05 16:54:34.181  INFO 8440 --- [           main] ptablePropertiesBeanFactoryPostProcessor : Converting PropertySource systemEnvironment [org.springframework.core.env.SystemEnvironmentPropertySource] to EncryptableMapPropertySourceWrapper
2017-09-05 16:54:34.181  INFO 8440 --- [           main] ptablePropertiesBeanFactoryPostProcessor : Converting PropertySource random [org.springframework.boot.context.config.RandomValuePropertySource] to EncryptablePropertySourceWrapper
2017-09-05 16:54:34.181  INFO 8440 --- [           main] ptablePropertiesBeanFactoryPostProcessor : Converting PropertySource applicationConfig: [classpath:/application-dev.properties] [org.springframework.core.env.PropertiesPropertySource] to EncryptableMapPropertySourceWrapper
2017-09-05 16:54:34.182  INFO 8440 --- [           main] ptablePropertiesBeanFactoryPostProcessor : Converting PropertySource applicationConfig: [classpath:/application.properties] [org.springframework.core.env.PropertiesPropertySource] to EncryptableMapPropertySourceWrapper
2017-09-05 16:54:40.092  INFO 8440 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-09-05 16:54:40.122  INFO 8440 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2017-09-05 16:54:40.124  INFO 8440 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.15
2017-09-05 16:54:40.335  INFO 8440 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-09-05 16:54:40.336  INFO 8440 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 10011 ms
2017-09-05 16:54:40.606  INFO 8440 --- [ost-startStop-1] EncryptablePropertyResolverConfiguration : String Encryptor custom Bean not found with name 'jasyptStringEncryptor'. Initializing String Encryptor based on properties with name 'jasyptStringEncryptor'
2017-09-05 16:54:40.667  INFO 8440 --- [ost-startStop-1] c.u.j.encryptor.DefaultLazyEncryptor     : Encryptor config not found for property jasypt.encryptor.algorithm, using default value: PBEWithMD5AndDES
2017-09-05 16:54:40.667  INFO 8440 --- [ost-startStop-1] c.u.j.encryptor.DefaultLazyEncryptor     : Encryptor config not found for property jasypt.encryptor.keyObtentionIterations, using default value: 1000
2017-09-05 16:54:40.668  INFO 8440 --- [ost-startStop-1] c.u.j.encryptor.DefaultLazyEncryptor     : Encryptor config not found for property jasypt.encryptor.poolSize, using default value: 1
2017-09-05 16:54:40.668  INFO 8440 --- [ost-startStop-1] c.u.j.encryptor.DefaultLazyEncryptor     : Encryptor config not found for property jasypt.encryptor.providerName, using default value: null
2017-09-05 16:54:40.668  INFO 8440 --- [ost-startStop-1] c.u.j.encryptor.DefaultLazyEncryptor     : Encryptor config not found for property jasypt.encryptor.saltGeneratorClassname, using default value: org.jasypt.salt.RandomSaltGenerator
2017-09-05 16:54:40.669  INFO 8440 --- [ost-startStop-1] c.u.j.encryptor.DefaultLazyEncryptor     : Encryptor config not found for property jasypt.encryptor.stringOutputType, using default value: base64
2017-09-05 16:54:40.784 ERROR 8440 --- [ost-startStop-1] o.s.b.c.embedded.tomcat.TomcatStarter    : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'samlSecurityConfiguration' defined in URL [jar:file:/C:/Git/xxxx-service-release-1.0.jar!/BOOT-INF/classes!/com/xxx/config/security/saml/SamlSecurityConfiguration.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'samlConfigurationProperties': Injection of autowired dependencies failed; nested exception is com.ulisesbocchio.jasyptspringboot.exception.DecryptionException: Decryption of Properties failed,  make sure encryption/decryption passwords match
2017-09-05 16:54:40.857  WARN 8440 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat

Any ideas now? It's quite the mystery!

ulisesbocchio commented 7 years ago

Interesting, yeah, it looks like a mismatch either on the algorithm or the password. Can you paste your own log? Just to see if they're any differences in the defaults selected.

mryhmln commented 7 years ago

Well, apparently it was a red herring. At this point I'm not sure what I did to get it to work on my machine. But when I went back to rerun it to regenerate the log files so that I could show them to you, it then started failing for me as well. Which I think is definitely better than it working for me but not for him! Because at least it was consistent.

Anyway, I then went back to investigate the issue and it popped out at me that when I supplied the value for -Djasypt.encryptor.password, I was surrounding the password in quotes. And I noticed that you were NOT surrounding yours in quotes. And my other JAVA_OPTS variable value wasn't in quotes either. So I removed the quotes and voila! It started working. Sorry to waste your time. Apparently it was a case of user error. In this case I believe mostly a function of being primarily a Windows developer... I'm used to putting parameter values in quotes.

Thanks for the help! And feel free to close this issue.

ulisesbocchio commented 7 years ago

alright, great, no poblem :). Glad you could figure it out.