Skip to content

Commit 6dc3294

Browse files
committed
Update to released plexus-cipher, adopt
1 parent 3c5f3cb commit 6dc3294

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<dependency>
4242
<groupId>org.codehaus.plexus</groupId>
4343
<artifactId>plexus-cipher</artifactId>
44-
<version>3.0.0-SNAPSHOT</version>
44+
<version>3.0.0</version>
4545
</dependency>
4646

4747
<dependency>

src/main/java/org/codehaus/plexus/components/secdispatcher/internal/DefaultSecDispatcher.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public String encrypt(String str, Map<String, String> attr) throws SecDispatcher
7171
if (attr == null || attr.get(DISPATCHER_NAME_ATTR) == null) {
7272
SettingsSecurity sec = getConfiguration(true);
7373
String master = getMasterPassword(sec, true);
74-
res = cipher.encrypt(str, master);
74+
res = cipher.encrypt(getMasterCipher(sec), str, master);
7575
} else {
7676
String type = attr.get(DISPATCHER_NAME_ATTR);
7777
Dispatcher dispatcher = dispatchers.get(type);
@@ -98,7 +98,7 @@ public String decrypt(String str) throws SecDispatcherException {
9898
if (attr == null || attr.get(DISPATCHER_NAME_ATTR) == null) {
9999
SettingsSecurity sec = getConfiguration(true);
100100
String master = getMasterPassword(sec, true);
101-
return cipher.decrypt(bare, master);
101+
return cipher.decrypt(getMasterCipher(sec), bare, master);
102102
} else {
103103
String type = attr.get(DISPATCHER_NAME_ATTR);
104104
Dispatcher dispatcher = dispatchers.get(type);
@@ -189,6 +189,11 @@ private String getMasterPassword(SettingsSecurity sec, boolean mandatory) throws
189189
}
190190
}
191191

192+
private String getMasterCipher(SettingsSecurity sec) throws SecDispatcherException {
193+
requireNonNull(sec, "configuration is null");
194+
return requireNonNull(sec.getMasterCipher(), "masterCipher is null");
195+
}
196+
192197
public String getConfigurationFile() {
193198
return configurationFile;
194199
}

src/main/mdo/settings-security.mdo

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@
4848
<description>The URI describing the source of the master password</description>
4949
</field>
5050

51+
<field>
52+
<name>masterCipher</name>
53+
<version>3.0.0+</version>
54+
<type>String</type>
55+
<description>The Cipher to be used</description>
56+
</field>
57+
5158
<field>
5259
<name>relocation</name>
5360
<version>1.0.0+</version>

src/test/java/org/codehaus/plexus/components/secdispatcher/internal/DefaultSecDispatcherTest.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Map;
2020
import java.util.Set;
2121

22+
import org.codehaus.plexus.components.cipher.internal.AESGCMNoPadding;
2223
import org.codehaus.plexus.components.cipher.internal.DefaultPlexusCipher;
2324
import org.codehaus.plexus.components.secdispatcher.SecDispatcher;
2425
import org.codehaus.plexus.components.secdispatcher.SecDispatcherException;
@@ -40,11 +41,11 @@
4041
public class DefaultSecDispatcherTest {
4142
String masterPassword = "masterPw";
4243
String password = "somePassword";
43-
String passwordEncrypted = "{TT2NQZ4iAdoHqsSfYUab3s6X2IHl5qaf4vx/F8DvtSI=}";
4444

4545
private void saveSec(String masterSource) throws Exception {
4646
SettingsSecurity sec = new SettingsSecurity();
4747
sec.setMasterSource(masterSource);
48+
sec.setMasterCipher(AESGCMNoPadding.CIPHER_ALG);
4849

4950
try (FileWriter fw = new FileWriter("./target/sec.xml")) {
5051
new SecurityConfigurationStaxWriter().write(fw, sec);
@@ -61,7 +62,7 @@ public void prepare() throws Exception {
6162
@Test
6263
void testEncrypt() throws Exception {
6364
DefaultSecDispatcher sd = new DefaultSecDispatcher(
64-
new DefaultPlexusCipher(),
65+
new DefaultPlexusCipher(Map.of(AESGCMNoPadding.CIPHER_ALG, new AESGCMNoPadding())),
6566
Map.of("static", new StaticMasterPasswordSource(masterPassword)),
6667
Map.of(),
6768
DefaultSecDispatcher.DEFAULT_CONFIGURATION);
@@ -74,11 +75,12 @@ void testEncrypt() throws Exception {
7475
@Test
7576
void testDecrypt() throws Exception {
7677
DefaultSecDispatcher sd = new DefaultSecDispatcher(
77-
new DefaultPlexusCipher(),
78+
new DefaultPlexusCipher(Map.of(AESGCMNoPadding.CIPHER_ALG, new AESGCMNoPadding())),
7879
Map.of("static", new StaticMasterPasswordSource(masterPassword)),
7980
Map.of(),
8081
DefaultSecDispatcher.DEFAULT_CONFIGURATION);
81-
String pass = sd.decrypt(passwordEncrypted);
82+
String encrypted = sd.encrypt(password, null);
83+
String pass = sd.decrypt(encrypted);
8284
assertNotNull(pass);
8385
assertEquals(password, pass);
8486
}
@@ -88,7 +90,7 @@ void testDecryptSystemProperty() throws Exception {
8890
System.setProperty("foobar", masterPassword);
8991
saveSec("prop:foobar");
9092
DefaultSecDispatcher sd = new DefaultSecDispatcher(
91-
new DefaultPlexusCipher(),
93+
new DefaultPlexusCipher(Map.of(AESGCMNoPadding.CIPHER_ALG, new AESGCMNoPadding())),
9294
Map.of(
9395
"prop",
9496
new SystemPropertyMasterPasswordSource(),
@@ -98,7 +100,8 @@ void testDecryptSystemProperty() throws Exception {
98100
new GpgAgentMasterPasswordSource()),
99101
Map.of(),
100102
DefaultSecDispatcher.DEFAULT_CONFIGURATION);
101-
String pass = sd.decrypt(passwordEncrypted);
103+
String encrypted = sd.encrypt(password, null);
104+
String pass = sd.decrypt(encrypted);
102105
assertNotNull(pass);
103106
assertEquals(password, pass);
104107
}
@@ -107,7 +110,7 @@ void testDecryptSystemProperty() throws Exception {
107110
void testDecryptEnv() throws Exception {
108111
saveSec("env:MASTER_PASSWORD");
109112
DefaultSecDispatcher sd = new DefaultSecDispatcher(
110-
new DefaultPlexusCipher(),
113+
new DefaultPlexusCipher(Map.of(AESGCMNoPadding.CIPHER_ALG, new AESGCMNoPadding())),
111114
Map.of(
112115
"prop",
113116
new SystemPropertyMasterPasswordSource(),
@@ -117,7 +120,8 @@ void testDecryptEnv() throws Exception {
117120
new GpgAgentMasterPasswordSource()),
118121
Map.of(),
119122
DefaultSecDispatcher.DEFAULT_CONFIGURATION);
120-
String pass = sd.decrypt(passwordEncrypted);
123+
String encrypted = sd.encrypt(password, null);
124+
String pass = sd.decrypt(encrypted);
121125
assertNotNull(pass);
122126
assertEquals(password, pass);
123127
}
@@ -127,7 +131,7 @@ void testDecryptEnv() throws Exception {
127131
void testDecryptGpg() throws Exception {
128132
saveSec("gpg-agent:/run/user/1000/gnupg/S.gpg-agent");
129133
DefaultSecDispatcher sd = new DefaultSecDispatcher(
130-
new DefaultPlexusCipher(),
134+
new DefaultPlexusCipher(Map.of(AESGCMNoPadding.CIPHER_ALG, new AESGCMNoPadding())),
131135
Map.of(
132136
"prop",
133137
new SystemPropertyMasterPasswordSource(),
@@ -137,15 +141,16 @@ void testDecryptGpg() throws Exception {
137141
new GpgAgentMasterPasswordSource()),
138142
Map.of(),
139143
DefaultSecDispatcher.DEFAULT_CONFIGURATION);
140-
String pass = sd.decrypt(passwordEncrypted);
144+
String encrypted = sd.encrypt(password, null);
145+
String pass = sd.decrypt(encrypted);
141146
assertNotNull(pass);
142147
assertEquals(password, pass);
143148
}
144149

145150
@Test
146151
void testEncryptWithDispatcher() throws Exception {
147152
DefaultSecDispatcher sd = new DefaultSecDispatcher(
148-
new DefaultPlexusCipher(),
153+
new DefaultPlexusCipher(Map.of(AESGCMNoPadding.CIPHER_ALG, new AESGCMNoPadding())),
149154
Map.of("static", new StaticMasterPasswordSource(masterPassword)),
150155
Map.of("magic", new StaticDispatcher("decrypted", "encrypted")),
151156
DefaultSecDispatcher.DEFAULT_CONFIGURATION);
@@ -162,7 +167,7 @@ void testEncryptWithDispatcher() throws Exception {
162167
@Test
163168
void testDecryptWithDispatcher() throws Exception {
164169
DefaultSecDispatcher sd = new DefaultSecDispatcher(
165-
new DefaultPlexusCipher(),
170+
new DefaultPlexusCipher(Map.of(AESGCMNoPadding.CIPHER_ALG, new AESGCMNoPadding())),
166171
Map.of("static", new StaticMasterPasswordSource(masterPassword)),
167172
Map.of("magic", new StaticDispatcher("decrypted", "encrypted")),
168173
DefaultSecDispatcher.DEFAULT_CONFIGURATION);
@@ -178,7 +183,7 @@ void testDecryptWithDispatcher() throws Exception {
178183
void testDecryptWithDispatcherConf() throws Exception {
179184
String bare = Base64.getEncoder().encodeToString("whatever".getBytes(StandardCharsets.UTF_8));
180185
DefaultSecDispatcher sd = new DefaultSecDispatcher(
181-
new DefaultPlexusCipher(),
186+
new DefaultPlexusCipher(Map.of(AESGCMNoPadding.CIPHER_ALG, new AESGCMNoPadding())),
182187
Map.of("static", new StaticMasterPasswordSource(masterPassword)),
183188
Map.of("magic", new Dispatcher() {
184189
@Override

src/test/resources/test-sec.xml

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)