import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yang.gen.v1.config.aaa.authn.encrypt.service.config.rev160915.AaaEncryptServiceConfigBuilder;
String after = impl.decrypt(encrypt);
assertEquals(before, after);
}
+
+ @Test
+ public void testNetconfEncodedPasswordWithoutPadding() {
+ changePadding();
+ String password = "bmV0Y29uZgo=";
+ String unencrypted = impl.decrypt(password);
+ assertEquals(password, unencrypted);
+ }
+
+ @Test
+ public void testNetconfEncodedPasswordWithPadding() {
+ String password = "bmV0Y29uZgo=";
+ String unencrypted = impl.decrypt(password);
+ assertEquals(password, unencrypted);
+ }
+
+ @Test
+ public void testNetconfPasswordWithoutPadding() {
+ changePadding();
+ String password = "netconf";
+ String encodedPassword = Base64.getEncoder().encodeToString(password.getBytes(StandardCharsets.UTF_8));
+ String unencrypted = impl.decrypt(encodedPassword);
+ assertEquals(encodedPassword, unencrypted);
+ }
+
+ @Test
+ public void testNetconfPasswordWithPadding() {
+ String password = "netconf";
+ String encodedPassword = Base64.getEncoder().encodeToString(password.getBytes(StandardCharsets.UTF_8));
+ String unencrypted = impl.decrypt(encodedPassword);
+ assertEquals(encodedPassword, unencrypted);
+ }
+
+ @Test
+ public void testAdminEncodedPasswordWithoutPadding() {
+ changePadding();
+ String password = "YWRtaW4K";
+ String unencrypted = impl.decrypt(password);
+ assertEquals(password, unencrypted);
+ }
+
+ @Test
+ public void testAdminEncodedPasswordWithPadding() {
+ String password = "YWRtaW4K";
+ String unencrypted = impl.decrypt(password);
+ assertEquals(password, unencrypted);
+ }
+
+ @Test
+ public void testAdminPasswordWithoutPadding() {
+ changePadding();
+ String password = "admin";
+ String encodedPassword = Base64.getEncoder().encodeToString(password.getBytes(StandardCharsets.UTF_8));
+ String unencrypted = impl.decrypt(encodedPassword);
+ assertEquals(encodedPassword, unencrypted);
+ }
+
+ @Test
+ public void testAdminPasswordWithPadding() {
+ String password = "admin";
+ String encodedPassword = Base64.getEncoder().encodeToString(password.getBytes(StandardCharsets.UTF_8));
+ String unencrypted = impl.decrypt(encodedPassword);
+ assertEquals(encodedPassword, unencrypted);
+ }
+
+ private void changePadding() {
+ impl = new AAAEncryptionServiceImpl(new EncryptServiceConfigImpl(
+ OSGiEncryptionServiceConfigurator.generateConfig(new AaaEncryptServiceConfigBuilder()
+ .setCipherTransforms("AES/CBC/NoPadding")
+ .setEncryptIterationCount(32768)
+ .setEncryptKey("")
+ .setEncryptKeyLength(128)
+ .setEncryptMethod("PBKDF2WithHmacSHA1")
+ .setEncryptSalt("")
+ .setEncryptType("AES")
+ .setPasswordLength(12)
+ .build())));
+ }
}