Skip to content

Commit

Permalink
okhttp: enable legacy tls cipher suites
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalyster committed Apr 6, 2020
1 parent 1401aa4 commit 2a6638b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
26 changes: 25 additions & 1 deletion src/main/java/com/juick/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
import org.acra.annotation.AcraMailSender;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import okhttp3.CipherSuite;
import okhttp3.ConnectionSpec;
import okhttp3.Credentials;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
Expand Down Expand Up @@ -75,6 +80,8 @@ public static App getInstance() {

private ObjectMapper jsonMapper;

private ConnectionSpec okHttpLegacyTls;

public interface OnProgressListener {
void onProgress(long progressPercentage);
}
Expand Down Expand Up @@ -156,6 +163,7 @@ public Api getApi() {
return response;
})
.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.connectionSpecs(Arrays.asList(getOkHttpLegacyTls(), ConnectionSpec.CLEARTEXT))
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BuildConfig.API_ENDPOINT)
Expand All @@ -179,6 +187,7 @@ public void auth(String username, String password, Callback<SecureUser> callback
.header("Authorization", basicAuth)
.build();
})
.connectionSpecs(Arrays.asList(getOkHttpLegacyTls(), ConnectionSpec.CLEARTEXT))
.build();

Retrofit retrofit = new Retrofit.Builder()
Expand Down Expand Up @@ -225,7 +234,9 @@ public ObjectMapper getJsonMapper() {

public YouTube getYouTube() {
if (youTube == null) {
OkHttpClient client = new OkHttpClient.Builder().build();
OkHttpClient client = new OkHttpClient.Builder()
.connectionSpecs(Arrays.asList(getOkHttpLegacyTls(), ConnectionSpec.CLEARTEXT))
.build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://www.googleapis.com/youtube/v3/")
.client(client)
Expand All @@ -236,4 +247,17 @@ public YouTube getYouTube() {
}
return youTube;
}

public ConnectionSpec getOkHttpLegacyTls() {
if (okHttpLegacyTls == null) {
List<CipherSuite> cipherSuites = new ArrayList<>(ConnectionSpec.MODERN_TLS.cipherSuites());
cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA);
cipherSuites.add(CipherSuite.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA);

okHttpLegacyTls = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS)
.cipherSuites(cipherSuites.toArray(new CipherSuite[0]))
.build();
}
return okHttpLegacyTls;
}
}
4 changes: 0 additions & 4 deletions src/main/java/com/juick/android/JuickMessagesAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@
*/
package com.juick.android;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.URLSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -37,7 +34,6 @@
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat;

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/juick/api/JuickGlideModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,34 @@

package com.juick.api;

import android.content.Context;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.bumptech.glide.Registry;
import com.bumptech.glide.annotation.GlideModule;
import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.module.AppGlideModule;
import com.juick.App;

import java.io.InputStream;
import java.util.Arrays;

import okhttp3.ConnectionSpec;
import okhttp3.OkHttpClient;

/**
* Created by vt on 13/03/2018.
*/
@GlideModule
public class JuickGlideModule extends AppGlideModule {
@Override
public void registerComponents(@NonNull Context context, @NonNull Glide glide, @NonNull Registry registry) {
OkHttpClient client = new OkHttpClient.Builder()
.connectionSpecs(Arrays.asList(App.getInstance().getOkHttpLegacyTls(), ConnectionSpec.CLEARTEXT))
.build();
registry.replace(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(client));
}
}

0 comments on commit 2a6638b

Please sign in to comment.