19
19
import java .util .Map ;
20
20
import java .util .Set ;
21
21
22
+ import org .codehaus .plexus .components .cipher .internal .AESGCMNoPadding ;
22
23
import org .codehaus .plexus .components .cipher .internal .DefaultPlexusCipher ;
23
24
import org .codehaus .plexus .components .secdispatcher .SecDispatcher ;
24
25
import org .codehaus .plexus .components .secdispatcher .SecDispatcherException ;
40
41
public class DefaultSecDispatcherTest {
41
42
String masterPassword = "masterPw" ;
42
43
String password = "somePassword" ;
43
- String passwordEncrypted = "{TT2NQZ4iAdoHqsSfYUab3s6X2IHl5qaf4vx/F8DvtSI=}" ;
44
44
45
45
private void saveSec (String masterSource ) throws Exception {
46
46
SettingsSecurity sec = new SettingsSecurity ();
47
47
sec .setMasterSource (masterSource );
48
+ sec .setMasterCipher (AESGCMNoPadding .CIPHER_ALG );
48
49
49
50
try (FileWriter fw = new FileWriter ("./target/sec.xml" )) {
50
51
new SecurityConfigurationStaxWriter ().write (fw , sec );
@@ -61,7 +62,7 @@ public void prepare() throws Exception {
61
62
@ Test
62
63
void testEncrypt () throws Exception {
63
64
DefaultSecDispatcher sd = new DefaultSecDispatcher (
64
- new DefaultPlexusCipher (),
65
+ new DefaultPlexusCipher (Map . of ( AESGCMNoPadding . CIPHER_ALG , new AESGCMNoPadding ()) ),
65
66
Map .of ("static" , new StaticMasterPasswordSource (masterPassword )),
66
67
Map .of (),
67
68
DefaultSecDispatcher .DEFAULT_CONFIGURATION );
@@ -74,11 +75,12 @@ void testEncrypt() throws Exception {
74
75
@ Test
75
76
void testDecrypt () throws Exception {
76
77
DefaultSecDispatcher sd = new DefaultSecDispatcher (
77
- new DefaultPlexusCipher (),
78
+ new DefaultPlexusCipher (Map . of ( AESGCMNoPadding . CIPHER_ALG , new AESGCMNoPadding ()) ),
78
79
Map .of ("static" , new StaticMasterPasswordSource (masterPassword )),
79
80
Map .of (),
80
81
DefaultSecDispatcher .DEFAULT_CONFIGURATION );
81
- String pass = sd .decrypt (passwordEncrypted );
82
+ String encrypted = sd .encrypt (password , null );
83
+ String pass = sd .decrypt (encrypted );
82
84
assertNotNull (pass );
83
85
assertEquals (password , pass );
84
86
}
@@ -88,7 +90,7 @@ void testDecryptSystemProperty() throws Exception {
88
90
System .setProperty ("foobar" , masterPassword );
89
91
saveSec ("prop:foobar" );
90
92
DefaultSecDispatcher sd = new DefaultSecDispatcher (
91
- new DefaultPlexusCipher (),
93
+ new DefaultPlexusCipher (Map . of ( AESGCMNoPadding . CIPHER_ALG , new AESGCMNoPadding ()) ),
92
94
Map .of (
93
95
"prop" ,
94
96
new SystemPropertyMasterPasswordSource (),
@@ -98,7 +100,8 @@ void testDecryptSystemProperty() throws Exception {
98
100
new GpgAgentMasterPasswordSource ()),
99
101
Map .of (),
100
102
DefaultSecDispatcher .DEFAULT_CONFIGURATION );
101
- String pass = sd .decrypt (passwordEncrypted );
103
+ String encrypted = sd .encrypt (password , null );
104
+ String pass = sd .decrypt (encrypted );
102
105
assertNotNull (pass );
103
106
assertEquals (password , pass );
104
107
}
@@ -107,7 +110,7 @@ void testDecryptSystemProperty() throws Exception {
107
110
void testDecryptEnv () throws Exception {
108
111
saveSec ("env:MASTER_PASSWORD" );
109
112
DefaultSecDispatcher sd = new DefaultSecDispatcher (
110
- new DefaultPlexusCipher (),
113
+ new DefaultPlexusCipher (Map . of ( AESGCMNoPadding . CIPHER_ALG , new AESGCMNoPadding ()) ),
111
114
Map .of (
112
115
"prop" ,
113
116
new SystemPropertyMasterPasswordSource (),
@@ -117,7 +120,8 @@ void testDecryptEnv() throws Exception {
117
120
new GpgAgentMasterPasswordSource ()),
118
121
Map .of (),
119
122
DefaultSecDispatcher .DEFAULT_CONFIGURATION );
120
- String pass = sd .decrypt (passwordEncrypted );
123
+ String encrypted = sd .encrypt (password , null );
124
+ String pass = sd .decrypt (encrypted );
121
125
assertNotNull (pass );
122
126
assertEquals (password , pass );
123
127
}
@@ -127,7 +131,7 @@ void testDecryptEnv() throws Exception {
127
131
void testDecryptGpg () throws Exception {
128
132
saveSec ("gpg-agent:/run/user/1000/gnupg/S.gpg-agent" );
129
133
DefaultSecDispatcher sd = new DefaultSecDispatcher (
130
- new DefaultPlexusCipher (),
134
+ new DefaultPlexusCipher (Map . of ( AESGCMNoPadding . CIPHER_ALG , new AESGCMNoPadding ()) ),
131
135
Map .of (
132
136
"prop" ,
133
137
new SystemPropertyMasterPasswordSource (),
@@ -137,15 +141,16 @@ void testDecryptGpg() throws Exception {
137
141
new GpgAgentMasterPasswordSource ()),
138
142
Map .of (),
139
143
DefaultSecDispatcher .DEFAULT_CONFIGURATION );
140
- String pass = sd .decrypt (passwordEncrypted );
144
+ String encrypted = sd .encrypt (password , null );
145
+ String pass = sd .decrypt (encrypted );
141
146
assertNotNull (pass );
142
147
assertEquals (password , pass );
143
148
}
144
149
145
150
@ Test
146
151
void testEncryptWithDispatcher () throws Exception {
147
152
DefaultSecDispatcher sd = new DefaultSecDispatcher (
148
- new DefaultPlexusCipher (),
153
+ new DefaultPlexusCipher (Map . of ( AESGCMNoPadding . CIPHER_ALG , new AESGCMNoPadding ()) ),
149
154
Map .of ("static" , new StaticMasterPasswordSource (masterPassword )),
150
155
Map .of ("magic" , new StaticDispatcher ("decrypted" , "encrypted" )),
151
156
DefaultSecDispatcher .DEFAULT_CONFIGURATION );
@@ -162,7 +167,7 @@ void testEncryptWithDispatcher() throws Exception {
162
167
@ Test
163
168
void testDecryptWithDispatcher () throws Exception {
164
169
DefaultSecDispatcher sd = new DefaultSecDispatcher (
165
- new DefaultPlexusCipher (),
170
+ new DefaultPlexusCipher (Map . of ( AESGCMNoPadding . CIPHER_ALG , new AESGCMNoPadding ()) ),
166
171
Map .of ("static" , new StaticMasterPasswordSource (masterPassword )),
167
172
Map .of ("magic" , new StaticDispatcher ("decrypted" , "encrypted" )),
168
173
DefaultSecDispatcher .DEFAULT_CONFIGURATION );
@@ -178,7 +183,7 @@ void testDecryptWithDispatcher() throws Exception {
178
183
void testDecryptWithDispatcherConf () throws Exception {
179
184
String bare = Base64 .getEncoder ().encodeToString ("whatever" .getBytes (StandardCharsets .UTF_8 ));
180
185
DefaultSecDispatcher sd = new DefaultSecDispatcher (
181
- new DefaultPlexusCipher (),
186
+ new DefaultPlexusCipher (Map . of ( AESGCMNoPadding . CIPHER_ALG , new AESGCMNoPadding ()) ),
182
187
Map .of ("static" , new StaticMasterPasswordSource (masterPassword )),
183
188
Map .of ("magic" , new Dispatcher () {
184
189
@ Override
0 commit comments