2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
18 package org.onap.dcae.runtime.web.service;
20 import java.security.KeyManagementException;
21 import java.security.NoSuchAlgorithmException;
22 import java.security.cert.X509Certificate;
24 import javax.net.ssl.HttpsURLConnection;
25 import javax.net.ssl.SSLContext;
26 import javax.net.ssl.TrustManager;
27 import javax.net.ssl.X509TrustManager;
29 public final class SSLUtils {
32 // for localhost testing only
33 javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier() {
34 public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
40 private static final TrustManager[] UNQUESTIONING_TRUST_MANAGER = new TrustManager[] { new X509TrustManager() {
41 public java.security.cert.X509Certificate[] getAcceptedIssuers() {
45 public void checkClientTrusted(X509Certificate[] certs, String authType) {
48 public void checkServerTrusted(X509Certificate[] certs, String authType) {
52 public static void turnOffSslChecking() throws NoSuchAlgorithmException, KeyManagementException {
53 // Install the all-trusting trust manager
54 final SSLContext sc = SSLContext.getInstance("SSL");
55 sc.init(null, UNQUESTIONING_TRUST_MANAGER, null);
56 HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
59 public static void turnOnSslChecking() throws KeyManagementException, NoSuchAlgorithmException {
60 // Return it to the initial state (discovered by reflection, now hardcoded)
61 SSLContext.getInstance("SSL").init(null, null, null);
65 throw new UnsupportedOperationException("Do not instantiate libraries.");