@@ -20,7 +20,6 @@ import org.threeten.bp.OffsetDateTime;
2020import org.threeten.bp.format.DateTimeFormatter;
2121{ {/threetenbp} }
2222
23- import javax.net.ssl.*;
2423import java.io.File;
2524import java.io.IOException;
2625import java.io.InputStream;
@@ -29,11 +28,6 @@ import java.lang.reflect.Type;
2928import java.net.URLConnection;
3029import java.net.URLEncoder;
3130import java.security.GeneralSecurityException;
32- import java.security.KeyStore;
33- import java.security.SecureRandom;
34- import java.security.cert.Certificate;
35- import java.security.cert.CertificateFactory;
36- import java.security.cert.X509Certificate;
3731import java.text.DateFormat;
3832{ {#java8} }
3933import java.time.LocalDate;
@@ -62,10 +56,6 @@ public class ApiClient {
6256 private boolean lenientDatetimeFormat;
6357 private int dateLength;
6458
65- private InputStream sslCaCert;
66- private boolean verifyingSsl;
67- private KeyManager[] keyManagers;
68-
6959 private OkHttpClient httpClient;
7060 private JSON json;
7161
@@ -101,8 +91,6 @@ public class ApiClient {
10191 httpClient.interceptors().add(new GzipRequestInterceptor());
10292 { {/useGzipFeature} }
10393
104- verifyingSsl = true;
105-
10694 json = new JSON();
10795
10896 // Set default User-Agent.
@@ -162,68 +150,6 @@ public class ApiClient {
162150 return this;
163151 }
164152
165- /**
166- * True if isVerifyingSsl flag is on
167- *
168- * @return True if isVerifySsl flag is on
169- */
170- public boolean isVerifyingSsl() {
171- return verifyingSsl;
172- }
173-
174- /**
175- * Configure whether to verify certificate and hostname when making https requests.
176- * Default to true.
177- * NOTE: Do NOT set to false in production code, otherwise you would face multiple types of cryptographic attacks.
178- *
179- * @param verifyingSsl True to verify TLS/SSL connection
180- * @return ApiClient
181- */
182- public ApiClient setVerifyingSsl(boolean verifyingSsl) {
183- this.verifyingSsl = verifyingSsl;
184- applySslSettings();
185- return this;
186- }
187-
188- /**
189- * Get SSL CA cert.
190- *
191- * @return Input stream to the SSL CA cert
192- */
193- public InputStream getSslCaCert() {
194- return sslCaCert;
195- }
196-
197- /**
198- * Configure the CA certificate to be trusted when making https requests.
199- * Use null to reset to default.
200- *
201- * @param sslCaCert input stream for SSL CA cert
202- * @return ApiClient
203- */
204- public ApiClient setSslCaCert(InputStream sslCaCert) {
205- this.sslCaCert = sslCaCert;
206- applySslSettings();
207- return this;
208- }
209-
210- public KeyManager[] getKeyManagers() {
211- return keyManagers;
212- }
213-
214- /**
215- * Configure client keys to use for authorization in an SSL session.
216- * Use null to reset to default.
217- *
218- * @param managers The KeyManagers to use
219- * @return ApiClient
220- */
221- public ApiClient setKeyManagers(KeyManager[] managers) {
222- this.keyManagers = managers;
223- applySslSettings();
224- return this;
225- }
226-
227153 public DateFormat getDateFormat() {
228154 return dateFormat;
229155 }
@@ -1036,70 +962,6 @@ public class ApiClient {
1036962 }
1037963 }
1038964
1039- /**
1040- * Apply SSL related settings to httpClient according to the current values of
1041- * verifyingSsl and sslCaCert.
1042- */
1043- private void applySslSettings() {
1044- try {
1045- TrustManager[] trustManagers = null;
1046- HostnameVerifier hostnameVerifier = null;
1047- if (! verifyingSsl) {
1048- TrustManager trustAll = new X509TrustManager() {
1049- @Override
1050- public void checkClientTrusted(X509Certificate[] chain, String authType) {}
1051- @Override
1052- public void checkServerTrusted(X509Certificate[] chain, String authType) { }
1053- @Override
1054- public X509Certificate[] getAcceptedIssuers() { return null; }
1055- };
1056- SSLContext sslContext = SSLContext.getInstance("TLS");
1057- trustManagers = new TrustManager[]{ trustAll } ;
1058- hostnameVerifier = new HostnameVerifier() {
1059- @Override
1060- public boolean verify(String hostname, SSLSession session) { return true ; }
1061- };
1062- } else if (sslCaCert != null) {
1063- char[] password = null; // Any password will work.
1064- CertificateFactory certificateFactory = CertificateFactory.getInstance(" X.509" );
1065- Collection< ? extends Certificate> certificates = certificateFactory.generateCertificates(sslCaCert);
1066- if (certificates.isEmpty()) {
1067- throw new IllegalArgumentException(" expected non-empty set of trusted certificates" );
1068- }
1069- KeyStore caKeyStore = newEmptyKeyStore(password);
1070- int index = 0;
1071- for (Certificate certificate : certificates) {
1072- String certificateAlias = " ca" + index++;
1073- caKeyStore.setCertificateEntry(certificateAlias, certificate);
1074- }
1075- TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
1076- trustManagerFactory.init(caKeyStore);
1077- trustManagers = trustManagerFactory.getTrustManagers();
1078- }
1079-
1080- if (keyManagers != null || trustManagers != null) {
1081- SSLContext sslContext = SSLContext.getInstance(" TLS" );
1082- sslContext.init(keyManagers, trustManagers, new SecureRandom());
1083- httpClient.setSslSocketFactory(sslContext.getSocketFactory());
1084- } else {
1085- httpClient.setSslSocketFactory(null);
1086- }
1087- httpClient.setHostnameVerifier(hostnameVerifier);
1088- } catch (GeneralSecurityException e) {
1089- throw new RuntimeException(e);
1090- }
1091- }
1092-
1093- private KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityException {
1094- try {
1095- KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
1096- keyStore.load(null, password);
1097- return keyStore;
1098- } catch (IOException e) {
1099- throw new AssertionError(e);
1100- }
1101- }
1102-
1103965 /**
1104966 * Request OAuth token
1105967 *
0 commit comments