Skip to content

Commit

Permalink
Add implementation of ProviderInstallerImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
voidstarstar committed Oct 9, 2018
1 parent 1e444dc commit 0e54f62
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions play-services-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ dependencies {
implementation project(':vtm-extras')
implementation project(':vtm-jts')
implementation project(':vtm-microg-theme')

compile 'org.conscrypt:conscrypt-android:1.2.0'
}

def execResult(...args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,40 @@

import android.content.Context;
import android.util.Log;
import org.conscrypt.OpenSSLProvider;
import java.lang.reflect.Field;
import java.security.Security;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocketFactory;

public class ProviderInstallerImpl {
public static void insertProvider(Context context) {
Log.d("ProviderInstallerImpl", "yep, i should do something with Security here...");
int insertProviderAt = Security.insertProviderAt(new OpenSSLProvider("GmsCore_OpenSSL"), 1);
try {
if (insertProviderAt == 1) {
SSLContext instance = SSLContext.getInstance("Default");
Field declaredField = SSLSocketFactory.class.getDeclaredField("defaultSocketFactory");
declaredField.setAccessible(true);
declaredField.set(null, instance.getSocketFactory());
declaredField = SSLServerSocketFactory.class.getDeclaredField("defaultServerSocketFactory");
declaredField.setAccessible(true);
declaredField.set(null, instance.getServerSocketFactory());
Security.setProperty("ssl.SocketFactory.provider", "org.conscrypt.OpenSSLSocketFactoryImpl");
Security.setProperty("ssl.ServerSocketFactory.provider", "org.conscrypt.OpenSSLServerSocketFactoryImpl");
instance = SSLContext.getInstance("Default");
SSLContext.setDefault(instance);
HttpsURLConnection.setDefaultSSLSocketFactory(instance.getSocketFactory());
//HttpsURLConnection.setDefaultHostnameVerifier(new oat());
//TODO: Set the default HostnameVerifier
Log.i("ProviderInstaller", "Installed default security provider GmsCore_OpenSSL");
} else {
Log.e("ProviderInstaller", "Failed to install security provider GmsCore_OpenSSL, result: " + insertProviderAt);
throw new SecurityException();
}
} catch (Exception e) {
Log.d("ProviderInstaller", "Failed to insert provider");
}
}
}

0 comments on commit 0e54f62

Please sign in to comment.