Adds or updates Bouncy Castle as a security provider. A possible fix for alleviating issues with connections (issue #46 in particular).
This commit is contained in:
parent
b07151b707
commit
74e395834d
2 changed files with 38 additions and 0 deletions
|
@ -53,5 +53,6 @@ dependencies {
|
|||
compile('org.eclipse.paho:org.eclipse.paho.android.service:1.1.1') {
|
||||
exclude module: 'support-v4'
|
||||
}
|
||||
compile 'org.bouncycastle:bcprov-jdk15on:1.57'
|
||||
testCompile 'junit:junit:4.12'
|
||||
}
|
||||
|
|
|
@ -17,12 +17,20 @@ package com.keylesspalace.tusky;
|
|||
|
||||
import android.app.Application;
|
||||
import android.net.Uri;
|
||||
import android.util.Log;
|
||||
|
||||
import com.keylesspalace.tusky.util.OkHttpUtils;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.jakewharton.picasso.OkHttp3Downloader;
|
||||
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
|
||||
import java.security.Provider;
|
||||
import java.security.Security;
|
||||
|
||||
public class TuskyApplication extends Application {
|
||||
private static final String TAG = "TuskyApplication"; // logging tag
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
@ -47,5 +55,34 @@ public class TuskyApplication extends Application {
|
|||
if (BuildConfig.DEBUG) {
|
||||
Picasso.with(this).setLoggingEnabled(true);
|
||||
}
|
||||
|
||||
/* Install the new provider or, if there's a pre-existing older version, replace the
|
||||
* existing version of it. */
|
||||
final String providerName = "BC";
|
||||
Provider existingProvider = Security.getProvider(providerName);
|
||||
if (existingProvider == null) {
|
||||
try {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
} catch (SecurityException e) {
|
||||
Log.d(TAG, "Permission to replace the security provider was denied.");
|
||||
}
|
||||
} else {
|
||||
Provider replacement = new BouncyCastleProvider();
|
||||
if (existingProvider.getVersion() < replacement.getVersion()) {
|
||||
Provider[] providers = Security.getProviders();
|
||||
int priority = 1;
|
||||
for (int i = 0; i < providers.length; i++) {
|
||||
if (providers[i].getName().equals(providerName)) {
|
||||
priority = i + 1;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Security.removeProvider(providerName);
|
||||
Security.insertProviderAt(replacement, priority);
|
||||
} catch (SecurityException e) {
|
||||
Log.d(TAG, "Permission to replace the security provider was denied.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue