88
99import java .io .FileNotFoundException ;
1010import java .io .IOException ;
11+ import java .security .KeyManagementException ;
12+ import java .security .NoSuchAlgorithmException ;
1113import java .util .HashMap ;
14+ import java .util .logging .Level ;
15+ import java .util .logging .Logger ;
16+ import javax .net .ssl .SSLContext ;
17+ import org .apache .http .conn .ssl .SSLConnectionSocketFactory ;
18+ import static org .apache .http .conn .ssl .SSLConnectionSocketFactory .BROWSER_COMPATIBLE_HOSTNAME_VERIFIER ;
19+ import org .apache .http .conn .ssl .SSLContexts ;
20+ import org .apache .http .impl .client .CloseableHttpClient ;
21+ import org .apache .http .impl .client .HttpClients ;
1222
1323/**
1424 * @author Iyanu Adelekan on 17/07/2016.
@@ -33,6 +43,29 @@ public ApiConnection(String url) {
3343 }
3444
3545 this .apiKey = keys .KEY_IN_USE ;
46+ this .enforceTlsV1point2 ();
47+ }
48+
49+ private void enforceTlsV1point2 () {
50+ try {
51+ SSLContext sslContext = SSLContexts .custom ()
52+ .useTLS ()
53+ .build ();
54+ SSLConnectionSocketFactory f = new SSLConnectionSocketFactory (
55+ sslContext ,
56+ new String []{"TLSv1.2" },
57+ null ,
58+ BROWSER_COMPATIBLE_HOSTNAME_VERIFIER );
59+ CloseableHttpClient httpClient = HttpClients .custom ()
60+ .setSSLSocketFactory (f )
61+ .build ();
62+ Unirest .setHttpClient (httpClient );
63+
64+ } catch (NoSuchAlgorithmException ex ) {
65+ Logger .getLogger (ApiConnection .class .getName ()).log (Level .SEVERE , null , ex );
66+ } catch (KeyManagementException ex ) {
67+ Logger .getLogger (ApiConnection .class .getName ()).log (Level .SEVERE , null , ex );
68+ }
3669 }
3770
3871 /**
0 commit comments