Revert stopgaps related to beta server cert issue (#3396)

* Revert stopgaps related to beta server cert issue

The upstream issue with Commons beta server has been
fixed now[1]. So, there's no point in stopgapping
the issue anymore. So, revert the related changes.

This reverts fa87eb5661
and df426f7c42 which
correspond to PRs #3350 and #3349 respectively.

[1]: https://phabricator.wikimedia.org/T243881#5861983

* Test-fix: fix the failing CI test
This commit is contained in:
Kaartic Sivaraam 2020-03-13 20:28:43 +05:30 committed by GitHub
parent 4bd7a5b1e2
commit a78e167676
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 293 deletions

View file

@ -18,8 +18,6 @@ import java.util.concurrent.TimeUnit;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import dagger.Module;
import dagger.Provides;
@ -33,7 +31,6 @@ import fr.free.nrw.commons.mwapi.OkHttpJsonApiClient;
import fr.free.nrw.commons.mwapi.UserInterface;
import fr.free.nrw.commons.review.ReviewInterface;
import fr.free.nrw.commons.upload.UploadInterface;
import fr.free.nrw.commons.utils.ConfigUtils;
import fr.free.nrw.commons.wikidata.WikidataInterface;
import okhttp3.Cache;
import okhttp3.HttpUrl;
@ -61,20 +58,14 @@ public class NetworkingModule {
public OkHttpClient provideOkHttpClient(Context context,
HttpLoggingInterceptor httpLoggingInterceptor) {
File dir = new File(context.getCacheDir(), "okHttpCache");
OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
return new OkHttpClient.Builder().connectTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.addInterceptor(httpLoggingInterceptor)
.readTimeout(60, TimeUnit.SECONDS)
.cache(new Cache(dir, OK_HTTP_CACHE_SIZE));
if(ConfigUtils.isBetaFlavour()){
builder.sslSocketFactory(SslUtils.INSTANCE.getTrustAllHostsSSLSocketFactory());
}
return builder.build();
.readTimeout(60, TimeUnit.SECONDS)
.cache(new Cache(dir, OK_HTTP_CACHE_SIZE))
.build();
}
@Provides
@Singleton
public HttpLoggingInterceptor provideHttpLoggingInterceptor() {

View file

@ -1,47 +0,0 @@
package fr.free.nrw.commons.di
import java.security.KeyManagementException
import java.security.NoSuchAlgorithmException
import java.security.cert.CertificateException
import java.security.cert.X509Certificate
import javax.net.ssl.SSLContext
import javax.net.ssl.SSLSocketFactory
import javax.net.ssl.TrustManager
import javax.net.ssl.X509TrustManager
object SslUtils {
fun getTrustAllHostsSSLSocketFactory(): SSLSocketFactory? {
try {
// Create a trust manager that does not validate certificate chains
val trustAllCerts = arrayOf<TrustManager>(object : X509TrustManager {
override fun getAcceptedIssuers(): Array<X509Certificate> {
return arrayOf()
}
@Throws(CertificateException::class)
override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {
}
@Throws(CertificateException::class)
override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {
}
})
// Install the all-trusting trust manager
val sslContext = SSLContext.getInstance("SSL")
sslContext.init(null, trustAllCerts, java.security.SecureRandom())
// Create an ssl socket factory with our all-trusting manager
return sslContext.socketFactory
} catch (e: KeyManagementException) {
e.printStackTrace()
return null
} catch (e: NoSuchAlgorithmException) {
e.printStackTrace()
return null
}
}
}