Browse Source

SONAR-12841 Support AES 256 Settings Encryption

tags/8.5.0.37579
Duarte Meneses 3 years ago
parent
commit
4cd0180440

+ 2
- 1
server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/EncryptActionTest.java View File

package org.sonar.server.setting.ws; package org.sonar.server.setting.ws;


import java.io.File; import java.io.File;
import java.nio.charset.StandardCharsets;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.junit.Before; import org.junit.Before;
logInAsSystemAdministrator(); logInAsSystemAdministrator();


File secretKeyFile = folder.newFile(); File secretKeyFile = folder.newFile();
FileUtils.writeStringToFile(secretKeyFile, "fCVFf/JHRi8Qwu5KLNva7g==");
FileUtils.writeStringToFile(secretKeyFile, "fCVFf/JHRi8Qwu5KLNva7g==", StandardCharsets.UTF_8);


encryption.setPathToSecretKey(secretKeyFile.getAbsolutePath()); encryption.setPathToSecretKey(secretKeyFile.getAbsolutePath());
} }

+ 2
- 1
server/sonar-webserver-webapi/src/test/java/org/sonar/server/setting/ws/GenerateSecretKeyActionTest.java View File



import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;


String secretKey = result.getSecretKey(); String secretKey = result.getSecretKey();
File file = temporaryFolder.newFile(); File file = temporaryFolder.newFile();
FileUtils.writeStringToFile(file, secretKey);
FileUtils.writeStringToFile(file, secretKey, StandardCharsets.UTF_8);
encryption.setPathToSecretKey(file.getAbsolutePath()); encryption.setPathToSecretKey(file.getAbsolutePath());
String encryptedValue = encryption.encrypt("my value"); String encryptedValue = encryption.encrypt("my value");
String decryptedValue = encryption.decrypt(encryptedValue); String decryptedValue = encryption.decrypt(encryptedValue);

+ 1
- 5
sonar-plugin-api-impl/src/main/java/org/sonar/api/config/internal/AesCipher.java View File

import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;


final class AesCipher implements Cipher { final class AesCipher implements Cipher {

// Can't be increased because of Java 6 policy files :
// https://confluence.terena.org/display/~visser/No+256+bit+ciphers+for+Java+apps
// http://java.sun.com/javase/6/webnotes/install/jre/README
static final int KEY_SIZE_IN_BITS = 128;
static final int KEY_SIZE_IN_BITS = 256;


private static final String CRYPTO_KEY = "AES"; private static final String CRYPTO_KEY = "AES";



Loading…
Cancel
Save