2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ===================================================================
10 * Unless otherwise specified, all software contained herein is licensed
11 * under the Apache License, Version 2.0 (the "License");
12 * you may not use this software except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * Unless otherwise specified, all documentation contained herein is licensed
24 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 * you may not use this documentation except in compliance with the License.
26 * You may obtain a copy of the License at
28 * https://creativecommons.org/licenses/by/4.0/
30 * Unless required by applicable law or agreed to in writing, documentation
31 * distributed under the License is distributed on an "AS IS" BASIS,
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 * See the License for the specific language governing permissions and
34 * limitations under the License.
36 * ============LICENSE_END============================================
41 package org.onap.portalapp.portal.scheduler.client;
44 import java.text.SimpleDateFormat;
45 import java.util.Date;
47 import javax.net.ssl.HostnameVerifier;
48 import javax.net.ssl.HttpsURLConnection;
49 import javax.net.ssl.SSLContext;
50 import javax.net.ssl.SSLSession;
51 import javax.ws.rs.client.Client;
52 import javax.ws.rs.client.ClientBuilder;
54 import org.eclipse.jetty.util.security.Password;
55 import org.glassfish.jersey.client.ClientConfig;
56 import org.glassfish.jersey.client.ClientProperties;
57 import org.onap.portalapp.portal.scheduler.SchedulerProperties;
58 import org.onap.portalapp.portal.scheduler.util.CustomJacksonJaxBJsonProvider;
59 import org.onap.portalapp.util.DateUtil;
60 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
63 * General SSL client using the VID tomcat keystore. It doesn't use client certificates.
66 public class HttpsBasicClient{
69 static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HttpsBasicClient.class);
72 * Retrieve an SSL client.
74 * @return Client The SSL client
75 * @throws Exception the exception
77 public static Client getClient() throws Exception {
78 String methodName = "getClient";
79 ClientConfig config = new ClientConfig();
82 SSLContext ctx = null;
86 SimpleDateFormat dateFormat = DateUtil.getDateFormat();
87 config.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
89 String truststorePath = SchedulerProperties.getProperty(SchedulerProperties.VID_TRUSTSTORE_FILENAME);
90 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " " + methodName + " "
91 + "truststore_path=" +
93 String truststorePassword = SchedulerProperties.getProperty(SchedulerProperties.VID_TRUSTSTORE_PASSWD_X);
96 String decryptedTruststorePassword = Password.deobfuscate(truststorePassword);
97 //logger.debug(dateFormat.format(new Date()) + " " + methodName + " decrypted_truststore_password=" + decrypted_truststore_password);
99 File tr = new File (truststorePath);
100 logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + " " + methodName + " absolute "
101 + "truststore path=" + tr.getAbsolutePath());
103 //String keystore_path = certFilePath + AAIProperties.FILESEPARTOR + SystemProperties.getProperty(AAIProperties.AAI_KEYSTORE_FILENAME);
104 //String keystore_password = SystemProperties.getProperty(AAIProperties.AAI_KEYSTORE_PASSWD_X);
105 //String decrypted_keystore_password = EncryptedPropValue.decryptTriple(keystore_password);
107 System.setProperty("javax.net.ssl.trustStore", truststorePath);
108 System.setProperty("javax.net.ssl.trustStorePassword", decryptedTruststorePassword);
109 HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier(){
110 public boolean verify(String string,SSLSession ssls) {
115 //May need to make the algorithm a parameter. MSO requires TLSv1.1 or TLSv1.2
116 ctx = SSLContext.getInstance("TLSv1.2");
119 KeyManagerFactory kmf = null;
121 kmf = KeyManagerFactory.getInstance("SunX509");
122 FileInputStream fin = new FileInputStream(keystore_path);
123 KeyStore ks = KeyStore.getInstance("PKCS12");
124 char[] pwd = decrypted_keystore_password.toCharArray();
127 } catch (Exception e) {
128 System.out.println("Error setting up kmf: exiting");
133 ctx.init(kmf.getKeyManagers(), null, null);
135 ctx.init(null, null, null);
137 return ClientBuilder.newBuilder()
139 .hostnameVerifier(new HostnameVerifier() {
141 public boolean verify( String s, SSLSession sslSession ) {
144 }).withConfig(config)
146 .register(CustomJacksonJaxBJsonProvider.class);
148 } catch (Exception e) {
149 logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up config: exiting", e);