[DMAAP-BC] Consolidate bus controller repos
[dmaap/buscontroller.git] / dmaap-bc / src / main / java / org / onap / dmaap / dbcapi / server / CadiCertificateManager.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dmaap
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.dmaap.dbcapi.server;
21
22 import java.io.FileInputStream;
23 import java.io.IOException;
24 import java.util.Properties;
25
26 import org.onap.aaf.cadi.PropAccess;
27
28 public class CadiCertificateManager extends CertificateManager {
29         private PropAccess propAccess;  
30         
31         CadiCertificateManager( Properties properties )  {
32                 String cadiPropsFile = properties.getProperty("cadi.properties", "etc/org.onap.dmaa-bc.props");
33                 logger.info( "using cadi properties in ", cadiPropsFile);
34                 
35                 propAccess = new PropAccess();
36                 ready = true;
37                 try {
38                         propAccess.load( new FileInputStream( cadiPropsFile ));
39                 } catch ( IOException e ) {
40                         logger.error( "Failed to load props file: " + cadiPropsFile + "\n" +  e.getMessage());
41                         ready = false;
42                 }
43                 setKeyStoreType( "jks");
44                 setKeyStoreFile( propAccess.getProperty("cadi_keystore") );
45                 setKeyStorePassword( decryptPass( propAccess.getProperty("cadi_keystore_password_jks" ) ));
46
47                 setTrustStoreType( "jks");
48                 setTrustStoreFile( propAccess.getProperty("cadi_truststore" ) );
49                 setTrustStorePassword( decryptPass( propAccess.getProperty("cadi_truststore_password" ) ));
50         }
51
52         private String decryptPass( String password ) {
53                 String clear = null;
54                 try {
55                         clear = propAccess.decrypt(password, false );
56                 } catch (IOException e) {
57                         logger.error( "Failed to decrypt " + password + ": " + e.getMessage() );
58                 }
59                 return clear;
60         }
61 }