Skip to content

Commit 2479d47

Browse files
author
Luigi R. Viggiano
committed
fixed bug: decryption not working when used in combination with variable substitution
1 parent 3cfeeb5 commit 2479d47

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

owner/src/main/java/org/aeonbits/owner/PropertiesInvocationHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ private Object resolveProperty(Method method, Object... args) {
8585
}
8686
if (value == null)
8787
return null;
88-
// Before processing the value, we decrypt it if necessary.
89-
// It is a security hole store the decrypted value, so every time we need it it should be decrypted.
90-
value = this.propertiesManager.decryptIfNecessary(method, value);
9188
value = preProcess(method, value);
92-
Object result = convert(method, method.getReturnType(), format(method, expandVariables(method, value), args));
89+
Object result = convert(method, method.getReturnType(),
90+
format(method, propertiesManager
91+
.decryptIfNecessary(method, expandVariables(method, value)),
92+
args));
9393
if (result == NULL) return null;
9494
return result;
9595
}

owner/src/test/java/org/aeonbits/owner/crypto/CryptoConfigTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ public interface SampleConfig extends Config {
5050
@Separator(",")
5151
@DefaultValue("Pfzoiet5E5zN2/7tfgrGLQ==")
5252
List<String> cryptoList();
53+
54+
@Key("encryptedValue")
55+
@DefaultValue("tzH7IKLCVc0AC72fh5DiZA==")
56+
String encryptedValue();
57+
58+
@Key("password.variable.expanded")
59+
@EncryptedValue
60+
@DefaultValue("${encryptedValue}")
61+
String passwordVariableExpanded();
5362
}
5463

5564

@@ -93,6 +102,17 @@ public void salutationNotDecryptedTest() {
93102
assertEquals( "Salutation value is not expected", SALUTATION_EXPECTED, salutation );
94103
}
95104

105+
/**
106+
* This test checks that the decrypted value is not cached.
107+
* So we recover it twice.
108+
*/
109+
@Test
110+
public void passwordDecryptedWhenVariableSubstitutionIsSet() {
111+
SampleConfig config = ConfigFactory.create( SampleConfig.class );
112+
String decryptedPassword = config.passwordVariableExpanded();
113+
assertEquals( "May be property password was decrypted twice.", PASSWORD_EXPECTED, decryptedPassword );
114+
}
115+
96116
public static class Decryptor1 extends SampleDecryptor {
97117
public Decryptor1() {
98118
super( "AES", SECRET_KEY );

0 commit comments

Comments
 (0)