Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // -- keystore
- KeyStore ks = KeyStore.getInstance("PKCS12");
- ks.load(new FileInputStream(KEYSTORE), KEYSTORE_PASS.toCharArray());
- KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
- kmf.init(ks, KEYSTORE_PASS.toCharArray());
- // -- trustore
- KeyStore ts = KeyStore.getInstance("JKS");
- ts.load(new FileInputStream(TRUSTORE), TRUSTORE_PASS.toCharArray());
- TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
- tmf.init(ts);
- // -- kontext
- SSLContext sslContext = SSLContext.getInstance("TLSv1");
- sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), new java.security.SecureRandom());
- // -- factory
- SSLSocketFactory factory = sslContext.getSocketFactory();
- SSLSocket sslSocket = (SSLSocket) factory.createSocket(HOST, PORT);
- sslSocket.startHandshake();
- // -- connection
- HttpsURLConnection connection = (HttpsURLConnection) new URL(ENDPOINT).openConnection();
- connection.setRequestMethod("GET");
- connection.setRequestProperty("Content-Type", "application/xml");
- connection.setRequestProperty("Content-Language", "en-US");
- connection.setSSLSocketFactory(factory);
- // -- processing request/response
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- String line;
- StringBuilder lines = new StringBuilder();
- while ((line = bufferedReader.readLine()) != null) {
- lines.append(line).append(LINE_BREAKER);
- }
- System.out.println("response from " + HOST + ":" + LINE_BREAKER + lines);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement