2014-08-22 20:08:44 +00:00
|
|
|
/*
|
2017-06-12 22:30:41 +00:00
|
|
|
* Copyright (C) 2013-2017 microG Project Team
|
2014-08-22 20:08:44 +00:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
2015-02-01 22:27:46 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-08-22 20:08:44 +00:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.google.android.gms.common.security;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2019-05-25 13:54:32 +00:00
|
|
|
import android.os.Process;
|
2014-08-22 20:08:44 +00:00
|
|
|
import android.util.Log;
|
2019-05-25 13:54:32 +00:00
|
|
|
|
2018-10-09 02:09:06 +00:00
|
|
|
import org.conscrypt.OpenSSLProvider;
|
2019-05-25 13:54:32 +00:00
|
|
|
import org.microg.gms.common.PackageUtils;
|
|
|
|
|
2018-10-09 02:09:06 +00:00
|
|
|
import java.security.Security;
|
2019-05-25 13:54:32 +00:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
|
|
import javax.net.ssl.SSLContext;
|
2014-08-22 20:08:44 +00:00
|
|
|
|
|
|
|
public class ProviderInstallerImpl {
|
2019-05-25 13:54:32 +00:00
|
|
|
private static final String TAG = "GmsProviderInstaller";
|
|
|
|
private static final List<String> DISABLED = Collections.singletonList("com.discord");
|
|
|
|
|
2014-08-22 20:08:44 +00:00
|
|
|
public static void insertProvider(Context context) {
|
2019-05-25 13:54:32 +00:00
|
|
|
try {
|
|
|
|
String packageName = PackageUtils.packageFromProcessId(context, Process.myPid());
|
|
|
|
Log.d(TAG, "Provider installer invoked for " + packageName);
|
|
|
|
if (DISABLED.contains(packageName)) {
|
|
|
|
Log.d(TAG, "Package is excluded from usage of provider installer");
|
|
|
|
} else if (Security.insertProviderAt(new OpenSSLProvider("GmsCore_OpenSSL"), 1) == 1) {
|
|
|
|
Security.setProperty("ssl.SocketFactory.provider", "org.conscrypt.OpenSSLSocketFactoryImpl");
|
|
|
|
Security.setProperty("ssl.ServerSocketFactory.provider", "org.conscrypt.OpenSSLServerSocketFactoryImpl");
|
|
|
|
|
|
|
|
SSLContext.setDefault(SSLContext.getInstance("Default"));
|
|
|
|
HttpsURLConnection.setDefaultSSLSocketFactory(SSLContext.getDefault().getSocketFactory());
|
|
|
|
Log.d(TAG, "SSL provider installed");
|
|
|
|
} else {
|
|
|
|
Log.w(TAG, "Did not insert the new SSL provider");
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.w(TAG, e);
|
|
|
|
}
|
2014-08-22 20:08:44 +00:00
|
|
|
}
|
|
|
|
}
|