aboutsummaryrefslogtreecommitdiffstats
path: root/trustStoreMerger/src/main
diff options
context:
space:
mode:
authorRemigiusz Janeczek <remigiusz.janeczek@nokia.com>2020-08-10 11:39:43 +0200
committerRemigiusz Janeczek <remigiusz.janeczek@nokia.com>2020-08-11 09:00:48 +0200
commiteddd3bd7b3d7fbb7cc052eebf3059589f1715233 (patch)
tree62a77b8043f8ad9f0e41c442d9993a3b62dd09c9 /trustStoreMerger/src/main
parentdea7453051ff7c1e9c8d1dea26f42a318ca9fc2c (diff)
Add TruststoreFile provider
Move certification.file classes to certification.path package Issue-ID: DCAEGEN2-2253 Signed-off-by: Remigiusz Janeczek <remigiusz.janeczek@nokia.com> Change-Id: I3098ac443b940031506732216f2bedffa3143adb
Diffstat (limited to 'trustStoreMerger/src/main')
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/TrustStoreMerger.java24
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java4
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/JksTruststore.java37
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/P12Truststore.java38
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/PemTruststore.java37
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoreFile.java38
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoreFileWithPassword.java35
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/FileManager.java39
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/PasswordReader.java36
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/PasswordReaderException.java29
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFileFactory.java84
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFileFactoryException.java30
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFilesListProvider.java50
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/path/EnvProvider.java (renamed from trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/EnvProvider.java)2
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/path/PathValidator.java (renamed from trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/PathValidator.java)2
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/path/TruststoresPathsProvider.java (renamed from trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoresPathsProvider.java)2
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/path/TruststoresPathsProviderException.java (renamed from trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoresPathsProviderException.java)2
-rw-r--r--trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationFactory.java4
18 files changed, 483 insertions, 10 deletions
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/TrustStoreMerger.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/TrustStoreMerger.java
index 3a3b9b6e..98c67ba8 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/TrustStoreMerger.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/TrustStoreMerger.java
@@ -21,11 +21,18 @@ package org.onap.oom.truststoremerger;
import org.onap.oom.truststoremerger.api.ExitStatus;
import org.onap.oom.truststoremerger.api.ExitableException;
-import org.onap.oom.truststoremerger.certification.file.EnvProvider;
-import org.onap.oom.truststoremerger.certification.file.TruststoresPathsProvider;
+import org.onap.oom.truststoremerger.certification.file.TruststoreFile;
+import org.onap.oom.truststoremerger.certification.file.provider.FileManager;
+import org.onap.oom.truststoremerger.certification.file.provider.PasswordReader;
+import org.onap.oom.truststoremerger.certification.file.provider.TruststoreFileFactory;
+import org.onap.oom.truststoremerger.certification.file.provider.TruststoreFilesListProvider;
+import org.onap.oom.truststoremerger.certification.path.EnvProvider;
+import org.onap.oom.truststoremerger.certification.path.TruststoresPathsProvider;
import org.onap.oom.truststoremerger.configuration.MergerConfiguration;
import org.onap.oom.truststoremerger.configuration.MergerConfigurationFactory;
-import org.onap.oom.truststoremerger.certification.file.PathValidator;
+import org.onap.oom.truststoremerger.certification.path.PathValidator;
+
+import java.util.List;
class TrustStoreMerger {
@@ -46,6 +53,7 @@ class TrustStoreMerger {
private void mergeTruststores() throws ExitableException {
MergerConfiguration configuration = loadConfiguration();
+ List<TruststoreFile> truststoreFilesList = getTruststoreFilesList(configuration);
}
private MergerConfiguration loadConfiguration() throws ExitableException {
@@ -53,4 +61,14 @@ class TrustStoreMerger {
MergerConfigurationFactory factory = new MergerConfigurationFactory(truststoresPathsProvider);
return factory.createConfiguration();
}
+
+ private List<TruststoreFile> getTruststoreFilesList(MergerConfiguration configuration) throws ExitableException {
+ TruststoreFileFactory truststoreFileFactory = new TruststoreFileFactory(new FileManager(), new PasswordReader());
+ TruststoreFilesListProvider truststoreFilesListProvider = new TruststoreFilesListProvider(truststoreFileFactory);
+ return truststoreFilesListProvider
+ .getTruststoreFilesList(
+ configuration.getTruststoreFilePaths(),
+ configuration.getTruststoreFilePasswordPaths()
+ );
+ }
}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java
index ae145f7e..d0c3b2f0 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/api/ExitStatus.java
@@ -23,7 +23,9 @@ public enum ExitStatus {
SUCCESS(0, "Success"),
TRUSTSTORES_PATHS_PROVIDER_EXCEPTION(1, "Invalid paths in environment variables"),
- MERGER_CONFIGURATION_EXCEPTION(2, "Invalid merger configuration");
+ MERGER_CONFIGURATION_EXCEPTION(2, "Invalid merger configuration"),
+ TRUSTSTORE_FILE_FACTORY_EXCEPTION(3, "Invalid truststore file-password pair"),
+ PASSWORD_READER_EXCEPTION(4, "Cannot read password from file");
private final int value;
private final String message;
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/JksTruststore.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/JksTruststore.java
new file mode 100644
index 00000000..b977daee
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/JksTruststore.java
@@ -0,0 +1,37 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.certification.file;
+
+import java.io.File;
+import java.security.cert.Certificate;
+import java.util.Collections;
+import java.util.List;
+
+public class JksTruststore extends TruststoreFileWithPassword {
+
+ public JksTruststore(File truststoreFile, String password) {
+ super(truststoreFile, password);
+ }
+
+ @Override
+ public List<Certificate> getCertificates() {
+ return Collections.emptyList();
+ }
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/P12Truststore.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/P12Truststore.java
new file mode 100644
index 00000000..8527cce5
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/P12Truststore.java
@@ -0,0 +1,38 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.certification.file;
+
+import java.io.File;
+import java.security.cert.Certificate;
+import java.util.Collections;
+import java.util.List;
+
+public class P12Truststore extends TruststoreFileWithPassword {
+
+ public P12Truststore(File truststoreFile, String password) {
+ super(truststoreFile, password);
+ }
+
+ @Override
+ public List<Certificate> getCertificates() {
+ return Collections.emptyList();
+ }
+
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/PemTruststore.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/PemTruststore.java
new file mode 100644
index 00000000..ca2ac85d
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/PemTruststore.java
@@ -0,0 +1,37 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.certification.file;
+
+import java.io.File;
+import java.security.cert.Certificate;
+import java.util.Collections;
+import java.util.List;
+
+public class PemTruststore extends TruststoreFile {
+
+ public PemTruststore(File truststoreFile) {
+ super(truststoreFile);
+ }
+
+ @Override
+ public List<Certificate> getCertificates() {
+ return Collections.emptyList();
+ }
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoreFile.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoreFile.java
new file mode 100644
index 00000000..88b1b5a8
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoreFile.java
@@ -0,0 +1,38 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.certification.file;
+
+import java.io.File;
+import java.security.cert.Certificate;
+import java.util.List;
+
+public abstract class TruststoreFile {
+ private File truststoreFile;
+
+ TruststoreFile(File truststoreFile) {
+ this.truststoreFile = truststoreFile;
+ }
+
+ public abstract List<Certificate> getCertificates();
+
+ public File getTruststoreFile() {
+ return truststoreFile;
+ };
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoreFileWithPassword.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoreFileWithPassword.java
new file mode 100644
index 00000000..484f2d4f
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoreFileWithPassword.java
@@ -0,0 +1,35 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.certification.file;
+
+import java.io.File;
+
+public abstract class TruststoreFileWithPassword extends TruststoreFile {
+ private String password;
+
+ TruststoreFileWithPassword(File truststoreFile, String password) {
+ super(truststoreFile);
+ this.password = password;
+ }
+
+ public String getPassword(){
+ return password;
+ };
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/FileManager.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/FileManager.java
new file mode 100644
index 00000000..901c13ab
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/FileManager.java
@@ -0,0 +1,39 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.certification.file.provider;
+
+import java.io.File;
+
+public class FileManager {
+ private static final int NOT_FOUND_INDEX=-1;
+
+ String getExtension(File file) {
+ int extStartIndex = file.getName().lastIndexOf(".");
+ if (extStartIndex == NOT_FOUND_INDEX) {
+ return "";
+ }
+ return file.getName().substring(extStartIndex);
+ }
+
+ boolean checkIfFileExists(File file){
+ return file.exists();
+ }
+
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/PasswordReader.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/PasswordReader.java
new file mode 100644
index 00000000..db42f3bd
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/PasswordReader.java
@@ -0,0 +1,36 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.certification.file.provider;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+
+public class PasswordReader {
+ private static final String COULD_NOT_READ_PASSWORD_FROM_FILE_MSG_TEMPLATE = "Could not read password from file: %s";
+
+ String readPassword(File file) throws PasswordReaderException {
+ try {
+ return Files.readString(file.toPath());
+ } catch (IOException e) {
+ throw new PasswordReaderException(String.format(COULD_NOT_READ_PASSWORD_FROM_FILE_MSG_TEMPLATE, file));
+ }
+ }
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/PasswordReaderException.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/PasswordReaderException.java
new file mode 100644
index 00000000..2928f0c5
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/PasswordReaderException.java
@@ -0,0 +1,29 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.certification.file.provider;
+
+import org.onap.oom.truststoremerger.api.ExitStatus;
+import org.onap.oom.truststoremerger.api.ExitableException;
+
+class PasswordReaderException extends ExitableException {
+ PasswordReaderException(String message) {
+ super(message, ExitStatus.PASSWORD_READER_EXCEPTION);
+ }
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFileFactory.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFileFactory.java
new file mode 100644
index 00000000..e63e7c33
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFileFactory.java
@@ -0,0 +1,84 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.certification.file.provider;
+
+import org.onap.oom.truststoremerger.certification.file.JksTruststore;
+import org.onap.oom.truststoremerger.certification.file.P12Truststore;
+import org.onap.oom.truststoremerger.certification.file.PemTruststore;
+import org.onap.oom.truststoremerger.certification.file.TruststoreFile;
+
+import java.io.File;
+
+public class TruststoreFileFactory {
+
+ private static final String JKS_EXTENSION = ".jks";
+ private static final String P12_EXTENSION = ".p12";
+ private static final String PEM_EXTENSION = ".pem";
+ private static final String FILE_DOES_NOT_EXIST_MSG_TEMPLATE = "File: %s does not exist";
+ private static final String UNKNOWN_TRUSTSTORE_TYPE_MSG_TEMPLATE = "Unknown truststore extension type: %s";
+
+ private final FileManager fileManager;
+ private final PasswordReader passwordReader;
+
+ public TruststoreFileFactory(FileManager fileManager, PasswordReader passwordReader) {
+ this.fileManager = fileManager;
+ this.passwordReader = passwordReader;
+ }
+
+ TruststoreFile create(String truststoreFilePath, String truststorePasswordPath)
+ throws TruststoreFileFactoryException, PasswordReaderException {
+ File truststoreFile = new File(truststoreFilePath);
+ if (!fileManager.checkIfFileExists(truststoreFile)) {
+ throw new TruststoreFileFactoryException(String.format(FILE_DOES_NOT_EXIST_MSG_TEMPLATE, truststoreFile));
+ }
+ return createTypedTruststore(truststoreFile, truststorePasswordPath);
+ }
+
+ private TruststoreFile createTypedTruststore(File truststoreFile, String truststorePasswordPath)
+ throws PasswordReaderException, TruststoreFileFactoryException {
+ String extension = fileManager.getExtension(truststoreFile);
+ switch (extension) {
+ case JKS_EXTENSION:
+ return createJksTruststore(truststoreFile, truststorePasswordPath);
+ case P12_EXTENSION:
+ return createP12Truststore(truststoreFile, truststorePasswordPath);
+ case PEM_EXTENSION:
+ return createPemTruststore(truststoreFile);
+ default:
+ throw new TruststoreFileFactoryException(String.format(UNKNOWN_TRUSTSTORE_TYPE_MSG_TEMPLATE, extension));
+ }
+ }
+
+ private JksTruststore createJksTruststore(File truststoreFile, String truststorePasswordPath)
+ throws PasswordReaderException {
+ String password = passwordReader.readPassword(new File(truststorePasswordPath));
+ return new JksTruststore(truststoreFile, password);
+ }
+
+ private P12Truststore createP12Truststore(File truststoreFile, String truststorePasswordPath)
+ throws PasswordReaderException {
+ String password = passwordReader.readPassword(new File(truststorePasswordPath));
+ return new P12Truststore(truststoreFile, password);
+ }
+
+ private PemTruststore createPemTruststore(File truststoreFile) {
+ return new PemTruststore(truststoreFile);
+ }
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFileFactoryException.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFileFactoryException.java
new file mode 100644
index 00000000..43342c83
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFileFactoryException.java
@@ -0,0 +1,30 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.certification.file.provider;
+
+import org.onap.oom.truststoremerger.api.ExitStatus;
+import org.onap.oom.truststoremerger.api.ExitableException;
+
+class TruststoreFileFactoryException extends ExitableException {
+ TruststoreFileFactoryException(String message) {
+ super(message, ExitStatus.TRUSTSTORE_FILE_FACTORY_EXCEPTION);
+ }
+
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFilesListProvider.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFilesListProvider.java
new file mode 100644
index 00000000..2f5356d5
--- /dev/null
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/provider/TruststoreFilesListProvider.java
@@ -0,0 +1,50 @@
+/*============LICENSE_START=======================================================
+ * oom-truststore-merger
+ * ================================================================================
+ * Copyright (C) 2020 Nokia. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.oom.truststoremerger.certification.file.provider;
+
+import org.onap.oom.truststoremerger.certification.file.TruststoreFile;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class TruststoreFilesListProvider {
+
+ private final TruststoreFileFactory truststoreFileFactory;
+
+ public TruststoreFilesListProvider(TruststoreFileFactory truststoreFileFactory) {
+ this.truststoreFileFactory = truststoreFileFactory;
+ }
+
+ public List<TruststoreFile> getTruststoreFilesList(List<String> truststoreFilePaths,
+ List<String> truststoreFilePasswordPaths)
+ throws PasswordReaderException, TruststoreFileFactoryException {
+ List<TruststoreFile> truststoreFilesList = new ArrayList<>();
+ for (int i = 0; i < truststoreFilePaths.size(); i++) {
+ String truststorePath = truststoreFilePaths.get(i);
+ String passwordPath = truststoreFilePasswordPaths.get(i);
+
+ TruststoreFile truststoreFile = truststoreFileFactory.create(truststorePath, passwordPath);
+ truststoreFilesList.add(truststoreFile);
+ }
+
+ return truststoreFilesList;
+ }
+}
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/EnvProvider.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/path/EnvProvider.java
index f64edc89..4bb763da 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/EnvProvider.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/path/EnvProvider.java
@@ -17,7 +17,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.oom.truststoremerger.certification.file;
+package org.onap.oom.truststoremerger.certification.path;
import java.util.Optional;
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/PathValidator.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/path/PathValidator.java
index 05b80f14..256da490 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/PathValidator.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/path/PathValidator.java
@@ -17,7 +17,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.oom.truststoremerger.certification.file;
+package org.onap.oom.truststoremerger.certification.path;
public class PathValidator {
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoresPathsProvider.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/path/TruststoresPathsProvider.java
index e23a1add..f8e85d49 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoresPathsProvider.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/path/TruststoresPathsProvider.java
@@ -17,7 +17,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.oom.truststoremerger.certification.file;
+package org.onap.oom.truststoremerger.certification.path;
import static org.onap.oom.truststoremerger.api.ConfigurationEnvs.TRUSTSTORES_ENV;
import static org.onap.oom.truststoremerger.api.ConfigurationEnvs.TRUSTSTORES_PASSWORDS_ENV;
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoresPathsProviderException.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/path/TruststoresPathsProviderException.java
index 5f491c36..1f69fe20 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/file/TruststoresPathsProviderException.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/certification/path/TruststoresPathsProviderException.java
@@ -17,7 +17,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.oom.truststoremerger.certification.file;
+package org.onap.oom.truststoremerger.certification.path;
import org.onap.oom.truststoremerger.api.ExitStatus;
import org.onap.oom.truststoremerger.api.ExitableException;
diff --git a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationFactory.java b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationFactory.java
index fa0b8cde..7a2fdc10 100644
--- a/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationFactory.java
+++ b/trustStoreMerger/src/main/java/org/onap/oom/truststoremerger/configuration/MergerConfigurationFactory.java
@@ -19,8 +19,8 @@
package org.onap.oom.truststoremerger.configuration;
-import org.onap.oom.truststoremerger.certification.file.TruststoresPathsProvider;
-import org.onap.oom.truststoremerger.certification.file.TruststoresPathsProviderException;
+import org.onap.oom.truststoremerger.certification.path.TruststoresPathsProvider;
+import org.onap.oom.truststoremerger.certification.path.TruststoresPathsProviderException;
import static org.onap.oom.truststoremerger.api.ConfigurationEnvs.TRUSTSTORES_ENV;
import static org.onap.oom.truststoremerger.api.ConfigurationEnvs.TRUSTSTORES_PASSWORDS_ENV;