1 /*============LICENSE_START=======================================================
2 * oom-truststore-merger
3 * ================================================================================
4 * Copyright (C) 2020 Nokia. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
20 package org.onap.oom.truststoremerger.certification.file.provider;
22 import static org.onap.oom.truststoremerger.api.CertificateConstants.JKS_INSTANCE;
23 import static org.onap.oom.truststoremerger.api.CertificateConstants.PKCS12_INSTANCE;
26 import java.security.KeyStore;
27 import java.security.KeyStoreException;
28 import org.onap.oom.truststoremerger.certification.file.exception.KeystoreInstanceException;
29 import org.onap.oom.truststoremerger.certification.file.exception.LoadTruststoreException;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 public class CertificateStoreControllerFactory {
35 private static final Logger LOGGER = LoggerFactory.getLogger(CertificateStoreControllerFactory.class);
37 public JavaCertificateStoreController createLoadedJksCertificateStoreController(File certFile, String certPassword)
38 throws LoadTruststoreException, KeystoreInstanceException {
39 return createLoadedCertificateStoreController(certFile, certPassword, JKS_INSTANCE);
42 public JavaCertificateStoreController createLoadedPkcs12CertificateStoreController(File certFile, String certPassword)
43 throws KeystoreInstanceException, LoadTruststoreException {
44 return createLoadedCertificateStoreController(certFile, certPassword, PKCS12_INSTANCE);
47 private JavaCertificateStoreController createLoadedCertificateStoreController(File certFile, String certPassword,
49 throws LoadTruststoreException, KeystoreInstanceException {
51 JavaCertificateStoreController javaCertificateStoreController = new JavaCertificateStoreController(
52 KeyStore.getInstance(instanceType), certFile, certPassword);
53 javaCertificateStoreController.loadFile();
54 return javaCertificateStoreController;
55 } catch (KeyStoreException e) {
56 LOGGER.error("Cannot initialize Java Keystore instance");
57 throw new KeystoreInstanceException(e);