Skip to content

Commit b86370c

Browse files
committed
Fix different line endings causing failure and bump version
1 parent 5a4c762 commit b86370c

6 files changed

Lines changed: 57 additions & 2 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>net.wedjaa.ansible.vault</groupId>
88
<artifactId>vault-utilities</artifactId>
9-
<version>1.2.2</version>
9+
<version>1.2.3</version>
1010
<build>
1111
<plugins>
1212
<plugin>

src/main/java/net/wedjaa/ansible/vault/crypto/VaultHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public static void encrypt(InputStream clearText, OutputStream cipherText, Strin
6666
public static void decrypt(InputStream encryptedVault, OutputStream decryptedVault, String password) throws IOException
6767
{
6868
String encryptedValue = IOUtils.toString(encryptedVault, CHAR_ENCODING);
69-
decryptedVault.write(decrypt(encryptedValue.getBytes(), password));
69+
String cleanedValue = Util.cleanupInput(encryptedValue);
70+
decryptedVault.write(decrypt(cleanedValue.getBytes(), password));
7071
}
7172

7273
public static byte[] decrypt(byte[] encrypted, String password) throws IOException

src/main/java/net/wedjaa/ansible/vault/crypto/data/Util.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ public static VaultInfo getVaultInfo(byte [] vaultData)
8080
return getVaultInfo(new String(vaultData));
8181
}
8282

83+
public static String cleanupInput(String input)
84+
{
85+
String val = input;
86+
val = val.replaceAll("\\r\\n", "\n");
87+
val = val.replaceAll("\\r", "\n");
88+
val = val.replaceAll("\\n", System.lineSeparator());
89+
return val;
90+
}
91+
8392
public static String cleanupData(String vaultData)
8493
{
8594
return vaultData.substring(vaultData.indexOf(System.lineSeparator()));

src/test/java/net/wedjaa/ansible/vault/crypto/VaultHandlerTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,36 @@ public void testStreamInvalidVault()
111111
}
112112
}
113113

114+
@Test
115+
public void testStreamValidVaultLF()
116+
{
117+
logger.info("Testing decoding vault Stream with lf - Valid password ");
118+
try
119+
{
120+
ByteArrayOutputStream decodedStream = new ByteArrayOutputStream();
121+
InputStream encodedStream = getClass().getClassLoader().getResourceAsStream("test-vault-lf.yml");
122+
VaultHandler.decrypt(encodedStream, decodedStream, TEST_PASSWORD);
123+
String decoded = new String(decodedStream.toByteArray());
124+
assertEquals(DECODED_VAULT, decoded);
125+
} catch(Exception ex) {
126+
fail("Failed to decode the test vault from stream: " + ex.getMessage());
127+
}
128+
}
129+
130+
@Test
131+
public void testStreamValidVaultCR()
132+
{
133+
logger.info("Testing decoding vault Stream with cr - Valid password ");
134+
try
135+
{
136+
ByteArrayOutputStream decodedStream = new ByteArrayOutputStream();
137+
InputStream encodedStream = getClass().getClassLoader().getResourceAsStream("test-vault-cr.yml");
138+
VaultHandler.decrypt(encodedStream, decodedStream, TEST_PASSWORD);
139+
String decoded = new String(decodedStream.toByteArray());
140+
assertEquals(DECODED_VAULT, decoded);
141+
} catch(Exception ex) {
142+
fail("Failed to decode the test vault from stream: " + ex.getMessage());
143+
}
144+
}
145+
114146
}

src/test/resources/test-vault-cr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$ANSIBLE_VAULT;1.1;AES256336431353561373531333730353765643162396335623634306366653731333761316333646333663561306635333832356137313239643335303631323662330a303464373738373932333564353634316536663063373566653437366431366562643535346431396263336536303332353064303938323231643966373262650a653664663237616138303932313663643939393539343734366662343365633765656431653865383261383966323335663562663335386363353961323161613135383961376662303266353765663637316430376362353833366566646638656234393430373531313566303066616130346130303063663636306537613334663661616361636235666361613462373066363565346436656630306363333132376138616266653264623132393535323135353032646463616137343133376234363831636436363265386135613533633335666230373263396233613334356339643239353065393238666334396232653034613263346566343639333163656633626436636364313932313436663431643964396366633264306633
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
$ANSIBLE_VAULT;1.1;AES256
2+
33643135356137353133373035376564316239633562363430636665373133376131633364633366
3+
3561306635333832356137313239643335303631323662330a303464373738373932333564353634
4+
31653666306337356665343736643136656264353534643139626333653630333235306430393832
5+
3231643966373262650a653664663237616138303932313663643939393539343734366662343365
6+
63376565643165386538326138396632333566356266333538636335396132316161313538396137
7+
66623032663537656636373164303763623538333665666466386562343934303735313135663030
8+
66616130346130303063663636306537613334663661616361636235666361613462373066363565
9+
34643665663030636333313237613861626665326462313239353532313535303264646361613734
10+
31333762343638316364363632653861356135336333356662303732633962336133343563396432
11+
39353065393238666334396232653034613263346566343639333163656633626436636364313932
12+
313436663431643964396366633264306633

0 commit comments

Comments
 (0)