X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dashboard%2Fwebapp-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Futil%2FHttpsURLConnectionUtils.java;h=f687483d87d7e1174fc647221fcb6269be2eb76c;hb=a2ad32a98e7a3f32214d3ecd7ca9730e3602d11f;hp=32646de43cf7c90ffb74a7380e5ed49a2abfe58d;hpb=06b7efdf86bf7b22a7dceee2de722c3f5c84c692;p=nonrtric.git diff --git a/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/util/HttpsURLConnectionUtils.java b/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/util/HttpsURLConnectionUtils.java index 32646de4..f687483d 100644 --- a/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/util/HttpsURLConnectionUtils.java +++ b/dashboard/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/util/HttpsURLConnectionUtils.java @@ -3,6 +3,7 @@ * O-RAN-SC * %% * Copyright (C) 2019 AT&T Intellectual Property + * Modifications Copyright (C) 2020 Nordix Foundation * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,13 +23,13 @@ package org.oransc.ric.portal.dashboard.util; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; -import java.security.cert.X509Certificate; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; + +import org.apache.axis2.java.security.TrustAllTrustManager; /** * Disables and enables certificate and host-name checking in @@ -44,28 +45,12 @@ public final class HttpsURLConnectionUtils { private static final HostnameVerifier trivialHostnameVerifier = (hostname, sslSession) -> hostname.equalsIgnoreCase(sslSession.getPeerHost()); - private static final TrustManager[] UNQUESTIONING_TRUST_MANAGER = new TrustManager[] {new X509TrustManager() { - @SuppressWarnings("squid:S1168") // Must return null to get wanted behaviour. - @Override - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return null; - } - - @Override - public void checkClientTrusted(X509Certificate[] certs, String authType) { - // Do nothing. - } - - @Override - public void checkServerTrusted(X509Certificate[] certs, String authType) { - // Do nothing. - } - }}; + private static final TrustManager[] UNQUESTIONING_TRUST_MANAGER = new TrustManager[] {new TrustAllTrustManager()}; public static void turnOffSslChecking() throws NoSuchAlgorithmException, KeyManagementException { HttpsURLConnection.setDefaultHostnameVerifier(trivialHostnameVerifier); // Install the all-trusting trust manager - SSLContext sc = SSLContext.getInstance("SSL"); + SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, UNQUESTIONING_TRUST_MANAGER, null); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); } @@ -73,7 +58,7 @@ public final class HttpsURLConnectionUtils { public static void turnOnSslChecking() throws KeyManagementException, NoSuchAlgorithmException { HttpsURLConnection.setDefaultHostnameVerifier(jvmHostnameVerifier); // Return it to the initial state (discovered by reflection, now hardcoded) - SSLContext sc = SSLContext.getInstance("SSL"); + SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, null, null); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); }