|
5 | 5 |
|
6 | 6 | package org.opensearch.dataprepper.plugins.geoip.extension.databasedownload; |
7 | 7 |
|
8 | | -import javax.net.ssl.HostnameVerifier; |
9 | | -import javax.net.ssl.HttpsURLConnection; |
10 | | -import javax.net.ssl.SSLContext; |
11 | | -import javax.net.ssl.SSLSession; |
12 | | -import javax.net.ssl.TrustManager; |
13 | | -import javax.net.ssl.X509TrustManager; |
14 | | -import java.security.KeyManagementException; |
15 | | -import java.security.NoSuchAlgorithmException; |
16 | | -import java.security.SecureRandom; |
17 | | -import java.security.cert.CertificateException; |
18 | | -import java.security.cert.X509Certificate; |
19 | | - |
20 | 8 | public interface DBSource { |
21 | 9 | String MAXMIND_DATABASE_EXTENSION = ".mmdb"; |
22 | 10 | void initiateDownload() throws Exception; |
23 | | - |
24 | | - /** |
25 | | - * initiateSSL |
26 | | - * @throws NoSuchAlgorithmException NoSuchAlgorithmException |
27 | | - * @throws KeyManagementException KeyManagementException |
28 | | - */ |
29 | | - default void initiateSSL() throws NoSuchAlgorithmException, KeyManagementException { |
30 | | - final TrustManager[] trustAllCerts = new TrustManager[]{ |
31 | | - new X509TrustManager() { |
32 | | - public X509Certificate[] getAcceptedIssuers() { |
33 | | - return null; |
34 | | - } |
35 | | - public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException { |
36 | | - return; |
37 | | - } |
38 | | - public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException { |
39 | | - return; |
40 | | - } |
41 | | - } |
42 | | - }; |
43 | | - |
44 | | - final SSLContext sc = SSLContext.getInstance("TLS"); |
45 | | - sc.init(null, trustAllCerts, new SecureRandom()); |
46 | | - HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); |
47 | | - final HostnameVerifier hostnameVerifier = new HostnameVerifier() { |
48 | | - public boolean verify(String urlHostName, SSLSession session) { |
49 | | - return true; |
50 | | - } |
51 | | - }; |
52 | | - HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); |
53 | | - } |
54 | 11 | } |
0 commit comments