diff options
author | Vijay Venkatesh Kumar <vv770d@att.com> | 2019-12-11 20:54:46 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-12-11 20:54:46 +0000 |
commit | a1f590d75dc29759d2abaa14915c70838abdc9c2 (patch) | |
tree | 7b485df413bf6c71745cefcd463a65adcf24522c /mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/SSLUtils.java | |
parent | 89ff166e60908fc9fbc2b6075edf9d6676d1b974 (diff) | |
parent | cc9d389bf197c1a365e669b407ea781f2bc87fd4 (diff) |
Merge "Add mod/runtimeapi"
Diffstat (limited to 'mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/SSLUtils.java')
-rw-r--r-- | mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/SSLUtils.java | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/SSLUtils.java b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/SSLUtils.java new file mode 100644 index 0000000..16501af --- /dev/null +++ b/mod/runtimeapi/runtime-web/src/main/java/org/onap/dcae/runtime/web/service/SSLUtils.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 AT&T Intellectual Property. 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.dcae.runtime.web.service; + +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.X509Certificate; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +public final class SSLUtils { + + static { + // for localhost testing only + javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(new javax.net.ssl.HostnameVerifier() { + public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) { + return true; + } + }); + } + + private static final TrustManager[] UNQUESTIONING_TRUST_MANAGER = new TrustManager[] { new X509TrustManager() { + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return null; + } + + public void checkClientTrusted(X509Certificate[] certs, String authType) { + } + + public void checkServerTrusted(X509Certificate[] certs, String authType) { + } + } }; + + public static void turnOffSslChecking() throws NoSuchAlgorithmException, KeyManagementException { + // Install the all-trusting trust manager + final SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, UNQUESTIONING_TRUST_MANAGER, null); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + } + + public static void turnOnSslChecking() throws KeyManagementException, NoSuchAlgorithmException { + // Return it to the initial state (discovered by reflection, now hardcoded) + SSLContext.getInstance("SSL").init(null, null, null); + } + + private SSLUtils() { + throw new UnsupportedOperationException("Do not instantiate libraries."); + } +}
\ No newline at end of file |