Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS will be completely phased out by mid-2025. To see alternatives please check here

Skip to content
Snippets Groups Projects
Commit 1f71bbd2 authored by Joze RIHTARSIC's avatar Joze RIHTARSIC
Browse files

Fix build - keystore absolute path

parent 7cbb20d0
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,8 @@ public enum SMPPropertyEnum {
ENCRYPTION_FILENAME("encryption.key.filename","encryptionPrivateKey.private","Path to the folder containing all the configuration files (keystore and sig0 key)"),
KEYSTORE_PASSWORD_DECRYPTED("smp.keystore.password.decrypted","","Only for backup purposes. This password was automatically created. Store password somewhere save and delete this entry!"),
SML_KEYSTORE_PASSWORD("bdmsl.integration.keystore.password","","Deprecated "),
SML_KEYSTORE_PATH("bdmsl.integration.keystore.path","","Deprecated "),
SIGNATURE_KEYSTORE_PASSWORD("xmldsig.keystore.password","","Deprecated "),
......
......@@ -40,7 +40,7 @@ public class UIKeystoreService {
@Value("${encryption.key.filename}")
private String encryptionFilename;
private String smpKeyStorePasswordDecripted;
private String smpKeyStorePasswordDecrypted;
private Map<String, Key> keystoreKeys;
private Map<String, X509Certificate> keystoreCertificates;
......@@ -60,7 +60,7 @@ public class UIKeystoreService {
LOG.info("initialize from configuration folder:"+configurationDir
+", enc file: "+encryptionFilename+", keystore " + smpKeyStoreFilename);
if (configurationDir==null || encryptionFilename==null){
LOG.info("Configuration folder and/or encryption filename are not set in database!");
LOG.warn("Configuration folder and/or encryption filename are not set in database!");
return;
}
......@@ -68,15 +68,21 @@ public class UIKeystoreService {
File file = new File(configurationDir + File.separator + encryptionFilename);
File keystoreFilePath = new File(configurationDir + File.separator + smpKeyStoreFilename );
if (!file.exists()){
LOG.error("Encryption key file '{}' does not exists!", file.getAbsolutePath());
return;
}
smpKeyStorePasswordDecripted = SecurityUtils.decrypt(file,smpKeyStorePasswordEncrypted);
if (!keystoreFilePath.exists()){
LOG.error("Keystore file '{}' does not exists!", keystoreFilePath.getAbsolutePath());
return;
}
smpKeyStorePasswordDecrypted = SecurityUtils.decrypt(file,smpKeyStorePasswordEncrypted);
// Load the KeyStore and get the signing key and certificate.
try (InputStream keystoreInputStream = new FileInputStream(keystoreFilePath)) {
KeyStore keyStore = KeyStore.getInstance("JKS");
keyStore.load(keystoreInputStream, smpKeyStorePasswordDecripted.toCharArray());
keyStore.load(keystoreInputStream, smpKeyStorePasswordDecrypted.toCharArray());
for (String alias : list(keyStore.aliases())) {
......@@ -88,7 +94,7 @@ public class UIKeystoreService {
}
private void loadKeyAndCert(KeyStore keyStore, String alias) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
Key key = keyStore.getKey(alias, smpKeyStorePasswordDecripted.toCharArray());
Key key = keyStore.getKey(alias, smpKeyStorePasswordDecrypted.toCharArray());
Certificate certificate = keyStore.getCertificate(alias);
if (key == null || certificate == null || !(certificate instanceof X509Certificate)) {
throw new IllegalStateException("Wrong entry type found in keystore, only certificates with keypair are accepted, entry alias: " + alias);
......
......@@ -2,7 +2,7 @@ package eu.europa.ec.edelivery.smp.utils;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.util.StringUtils;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
......@@ -16,10 +16,6 @@ import static org.junit.Assert.*;
public class SecurityUtilsTest {
@Test
public void mergeKeystores() {
}
@Test
public void generatePrivateSymmetricKey() throws IOException {
......@@ -41,7 +37,7 @@ public class SecurityUtilsTest {
}
@Test
public void encrypt() {
public void encrypt() throws IOException {
// given
File f = generateRandomPrivateKey();
String password = "TEST11002password1@!."+System.currentTimeMillis();
......@@ -53,9 +49,9 @@ public class SecurityUtilsTest {
assertNotEquals(password, encPassword);
}
@Test
public void encryptt() {
public void encryptWithSetupKey() {
// given
File f = new File("/cef/code/smp/smp-server-library/src/test/resources/keystores/encryptionKey.key");
File f = new File("src/test/resources/keystores/encryptionKey.key");
String password = "test123";
// when
......@@ -67,7 +63,7 @@ public class SecurityUtilsTest {
@Test
public void decrypt() {
public void decrypt() throws IOException {
// given
File f = generateRandomPrivateKey();
String password = "TEST11002password1@!." + System.currentTimeMillis();
......@@ -81,11 +77,11 @@ public class SecurityUtilsTest {
}
private File generateRandomPrivateKey(){
String tempPrivateKey = "enckey_"+ System.currentTimeMillis() + ".private";
Path resourceDirectory = Paths.get("target", tempPrivateKey);
File resource = resourceDirectory.toFile();
SecurityUtils.generatePrivateSymmetricKey(resourceDirectory.toFile());
private File generateRandomPrivateKey() throws IOException{
File resource = File.createTempFile( "test-key", ".key");
resource.deleteOnExit();
SecurityUtils.generatePrivateSymmetricKey(resource);
return resource;
}
......
......@@ -44,6 +44,11 @@ import static eu.europa.ec.edelivery.smp.utils.SecurityUtils.*;
/**
* Created by Flavio Santos
* Class read properties from configuration file if exists. Than it use datasource (default by JNDI
* if not defined in property file jdbc/smpDatasource) to read application properties. Because this class is
* invoked before datasource is initialiyzed by default - it creates it's own database connection.
* Also it uses hibernate to handle dates for Configuration table.
*
*/
@Configuration
@ComponentScan(basePackages = {
......@@ -158,6 +163,8 @@ public class PropertiesConfig {
storeDBEntry(em, SMPPropertyEnum.CONFIGURATION_DIR, settingsFolder.getPath());
initProperties.setProperty(SMPPropertyEnum.CONFIGURATION_DIR.getProperty(), settingsFolder.getPath());
String newKeyPassword = RandomStringUtils.random(8, true, true);
storeDBEntry(em, SMPPropertyEnum.KEYSTORE_PASSWORD_DECRYPTED, newKeyPassword);
// store encryption filename
File fEncryption = new File(settingsFolder, SMPPropertyEnum.ENCRYPTION_FILENAME.getDefValue());
......
......@@ -34,7 +34,7 @@ public class PropertiesTestConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
Path resourceDirectory = Paths.get("src", "test", "resources", "keystores");
String path = resourceDirectory.toString();
String path = resourceDirectory.toFile().getAbsolutePath();
PropertySourcesPlaceholderConfigurer propertiesConfig = new PropertySourcesPlaceholderConfigurer();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment