From 056ad753c9c766a2441f66f181624c79227541a3 Mon Sep 17 00:00:00 2001 From: Aurelien <100427063+aurelien-poscia-sonarsource@users.noreply.github.com> Date: Thu, 11 Aug 2022 12:05:44 +0200 Subject: [PATCH] SONAR-17150 fix SSF-39 --- .../java/org/sonar/api/config/internal/Encryption.java | 2 +- .../org/sonar/api/config/internal/EncryptionTest.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sonar-plugin-api-impl/src/main/java/org/sonar/api/config/internal/Encryption.java b/sonar-plugin-api-impl/src/main/java/org/sonar/api/config/internal/Encryption.java index e3b2366621e..7802d757a67 100644 --- a/sonar-plugin-api-impl/src/main/java/org/sonar/api/config/internal/Encryption.java +++ b/sonar-plugin-api-impl/src/main/java/org/sonar/api/config/internal/Encryption.java @@ -30,6 +30,7 @@ import javax.annotation.Nullable; * @since 3.0 */ public final class Encryption { + private static final Pattern ENCRYPTED_PATTERN = Pattern.compile("^\\{([^{^}]*)}(.*)$"); private static final String BASE64_ALGORITHM = "b64"; private static final String AES_ECB_ALGORITHM = "aes"; @@ -39,7 +40,6 @@ public final class Encryption { private final AesGCMCipher aesGCMCipher; private final Map ciphers; - private static final Pattern ENCRYPTED_PATTERN = Pattern.compile("\\{(.*?)\\}(.*)"); public Encryption(@Nullable String pathToSecretKey) { aesECBCipher = new AesECBCipher(pathToSecretKey); diff --git a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/EncryptionTest.java b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/EncryptionTest.java index 6a3fe819617..1f8651a9b1d 100644 --- a/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/EncryptionTest.java +++ b/sonar-plugin-api-impl/src/test/java/org/sonar/api/config/internal/EncryptionTest.java @@ -91,6 +91,16 @@ public class EncryptionTest { assertThat(encryption.decrypt("foo")).isEqualTo("foo"); } + @Test + public void should_notDecryptText_whenBadBraceSyntax(){ + Encryption encryption = new Encryption(null); + assertThat(encryption.decrypt("}xxx{Zm9v")).isEqualTo("}xxx{Zm9v"); + assertThat(encryption.decrypt("}dcd}59LK")).isEqualTo("}dcd}59LK"); + assertThat(encryption.decrypt("}rrrRg6")).isEqualTo("}rrrRg6"); + assertThat(encryption.decrypt("{closedjdk")).isEqualTo("{closedjdk"); + + } + private String pathToSecretKey() throws Exception { URL resource = getClass().getResource("/org/sonar/api/config/internal/AesCipherTest/aes_secret_key.txt"); return new File(resource.toURI()).getCanonicalPath(); -- 2.39.5