1919import java .util .Map ;
2020import java .util .Set ;
2121
22+ import org .codehaus .plexus .components .cipher .internal .AESGCMNoPadding ;
2223import org .codehaus .plexus .components .cipher .internal .DefaultPlexusCipher ;
2324import org .codehaus .plexus .components .secdispatcher .SecDispatcher ;
2425import org .codehaus .plexus .components .secdispatcher .SecDispatcherException ;
4041public 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
0 commit comments