Assign image keyname and pubkey at vnf level
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / devicemanager / impl / src / main / java / org / opendaylight / mwtn / dcaeConnector / test / DcaePrivateTester.java
1 /**
2  *
3  */
4 package org.opendaylight.mwtn.dcaeConnector.test;
5
6 import java.io.BufferedReader;
7 import java.io.InputStreamReader;
8 import java.io.Reader;
9 import java.net.URL;
10 import java.net.URLConnection;
11 import java.security.cert.X509Certificate;
12
13 import javax.net.ssl.HostnameVerifier;
14 import javax.net.ssl.HttpsURLConnection;
15 import javax.net.ssl.SSLContext;
16 import javax.net.ssl.TrustManager;
17 import javax.net.ssl.X509TrustManager;
18
19 /**
20  * @author herbert
21  *
22  */
23 public class DcaePrivateTester {
24
25
26     public static void test(URL url, boolean readFromServer) throws Exception {
27         // Create a trust manager that does not validate certificate chains
28         TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
29             @Override
30             public java.security.cert.X509Certificate[] getAcceptedIssuers() {
31                 return null;
32             }
33             @Override
34             public void checkClientTrusted(X509Certificate[] certs, String authType) {
35             }
36             @Override
37             public void checkServerTrusted(X509Certificate[] certs, String authType) {
38             }
39         } };
40         // Install the all-trusting trust manager
41         final SSLContext sc = SSLContext.getInstance("TLS");
42         sc.init(null, trustAllCerts, new java.security.SecureRandom());
43         HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
44         // Create all-trusting host name verifier
45         HostnameVerifier allHostsValid = (hostname, session) -> true;
46
47         // Install the all-trusting host verifier
48         HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
49
50         //URL url = new URL("https://www.google.com");
51         URLConnection con = url.openConnection();
52         System.out.println("Connection background: "+con.getClass().getName()+" "+url.getHost());
53
54         if (readFromServer) {
55             final Reader reader = new InputStreamReader(con.getInputStream());
56             final BufferedReader br = new BufferedReader(reader);
57             String line = "";
58             while ((line = br.readLine()) != null) {
59                 System.out.println(line);
60             }
61             br.close();
62         } /**/
63     } // End of main
64
65
66
67 //    httpTestUrl=https://plan.fritz.box:9092/ux/#
68 //    keyStore=etc/clientkeystore
69 //    keyStorePassword=daylight2016
70     public static void main(String[] args) {
71
72         String urlString = "https://www.google.de";
73         //String urlString = "https://plan.fritz.box:9092/ux/#";
74         //String urlString = "http://plan.fritz.box:9091/ux/#";
75         //String urlString = "http://127.0.0.1:30000/eventListener/v3";
76
77         try {
78             test(new URL(urlString), true);
79         } catch (Exception e) {
80             System.out.println("(..something..) failed");
81             e.printStackTrace();
82         }
83         /*
84         System.out.println("Test HTTPS");
85
86         final HttpsClient httpTestClient;
87         httpTestClient = new HttpsClient();
88
89         httpTestClient.testIt(
90                 //"https://plan.fritz.box:9092/ux/#",
91                 "https://www.google.de",
92                 "/home/herbert/odl/distribution-karaf-0.5.1-Boron-SR1/etc/clientkeystore",
93                 "daylight2016"
94         );/**/
95
96     }
97
98 }