Skip to content

Commit 65fc88f

Browse files
authored
Escape backslashes so that they won't be removed when loading the properties (#774)
1 parent e329b88 commit 65fc88f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Diff for: build-info-extractor/src/main/java/org/jfrog/build/extractor/clientConfiguration/util/encryption/PropertyEncryptor.java

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public static Properties decryptPropertiesFromFile(String filePath, EncryptionKe
4949
private static Properties decryptProperties(byte[] encryptedData, EncryptionKeyPair keyPair) throws IOException, InvalidAlgorithmParameterException, IllegalBlockSizeException, NoSuchPaddingException, BadPaddingException, NoSuchAlgorithmException, InvalidKeyException {
5050
byte[] decryptedBytes = decrypt(encryptedData, keyPair);
5151
String decryptedString = new String(decryptedBytes, StandardCharsets.UTF_8);
52+
// Escape backslashes so that they won't be removed when loading the properties.
53+
decryptedString = decryptedString.replace("\\", "\\\\");
5254
return stringToProperties(decryptedString);
5355
}
5456

Diff for: build-info-extractor/src/test/java/org/jfrog/build/extractor/clientConfiguration/ArtifactoryClientConfigurationTest.java

+24
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,30 @@ public void testReadEncryptedPropertyFile() throws IOException, InvalidAlgorithm
7575
}
7676
}
7777

78+
@Test(description = "Test read encrypted property file")
79+
public void testReadEncryptedWindowsPath() throws IOException, InvalidAlgorithmParameterException, IllegalBlockSizeException, NoSuchPaddingException, BadPaddingException, NoSuchAlgorithmException, InvalidKeyException {
80+
// Create property with windows path
81+
String key = "path";
82+
String value = "C:\\user\\home";
83+
ArtifactoryClientConfiguration client = new ArtifactoryClientConfiguration(new NullLog());
84+
Properties clientProps = new Properties();
85+
clientProps.put(key, value);
86+
client.fillFromProperties(clientProps);
87+
88+
// Save property into the file
89+
tempFile = Files.createTempFile("BuildInfoExtractorUtilsTest", "").toAbsolutePath();
90+
client.root.props.put(BuildInfoConfigProperties.PROP_PROPS_FILE, tempFile.toString());
91+
92+
try (FileOutputStream fileOutputStream = new FileOutputStream(tempFile.toFile())) {
93+
// Save encrypted file.
94+
EncryptionKeyPair keyPair = client.persistToEncryptedPropertiesFile(fileOutputStream);
95+
// Assert decrypted successfully.
96+
Properties props = decryptPropertiesFromFile(tempFile.toString(), keyPair);
97+
assertNotNull(props);
98+
assertEquals(props.getProperty(key), value);
99+
}
100+
}
101+
78102
private ArtifactoryClientConfiguration createProxyClient() {
79103
ArtifactoryClientConfiguration client = new ArtifactoryClientConfiguration(new NullLog());
80104
Properties props = new Properties();

0 commit comments

Comments
 (0)