1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk feature sdnr wt
4 * ================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 ******************************************************************************/
21 package org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeConnector.test;
23 import java.io.BufferedReader;
24 import java.io.InputStreamReader;
25 import java.io.Reader;
27 import java.net.URLConnection;
28 import java.security.cert.X509Certificate;
29 import javax.net.ssl.HostnameVerifier;
30 import javax.net.ssl.HttpsURLConnection;
31 import javax.net.ssl.SSLContext;
32 import javax.net.ssl.TrustManager;
33 import javax.net.ssl.X509TrustManager;
35 public class DcaePrivateTester {
38 public static void test(URL url, boolean readFromServer) throws Exception {
39 // Create a trust manager that does not validate certificate chains
40 TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
42 public java.security.cert.X509Certificate[] getAcceptedIssuers() {
46 public void checkClientTrusted(X509Certificate[] certs, String authType) {
49 public void checkServerTrusted(X509Certificate[] certs, String authType) {
52 // Install the all-trusting trust manager
53 final SSLContext sc = SSLContext.getInstance("TLS");
54 sc.init(null, trustAllCerts, new java.security.SecureRandom());
55 HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
56 // Create all-trusting host name verifier
57 HostnameVerifier allHostsValid = (hostname, session) -> true;
59 // Install the all-trusting host verifier
60 HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
62 //URL url = new URL("https://www.google.com");
63 URLConnection con = url.openConnection();
64 System.out.println("Connection background: "+con.getClass().getName()+" "+url.getHost());
67 final Reader reader = new InputStreamReader(con.getInputStream());
68 final BufferedReader br = new BufferedReader(reader);
70 while ((line = br.readLine()) != null) {
71 System.out.println(line);
79 // httpTestUrl=https://plan.fritz.box:9092/ux/#
80 // keyStore=etc/clientkeystore
81 // keyStorePassword=daylight2016
82 public static void main(String[] args) {
84 String urlString = "https://www.google.de";
85 //String urlString = "https://plan.fritz.box:9092/ux/#";
86 //String urlString = "http://plan.fritz.box:9091/ux/#";
87 //String urlString = "http://127.0.0.1:30000/eventListener/v3";
90 test(new URL(urlString), true);
91 } catch (Exception e) {
92 System.out.println("(..something..) failed");
96 System.out.println("Test HTTPS");
98 final HttpsClient httpTestClient;
99 httpTestClient = new HttpsClient();
101 httpTestClient.testIt(
102 //"https://plan.fritz.box:9092/ux/#",
103 "https://www.google.de",
104 "/home/herbert/odl/distribution-karaf-0.5.1-Boron-SR1/etc/clientkeystore",