Skip to content

Commit

Permalink
fix(android): remove HTTPClient addKeyManager() and addTrustManager()…
Browse files Browse the repository at this point in the history
… methods

marked removed in our docs since 3.4.0, but were never actually removed
  • Loading branch information
sgtcoolguy committed Apr 15, 2021
1 parent 9bc150e commit 50225e1
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2009-2016 by Appcelerator, Inc. All Rights Reserved.
* Copyright (c) 2009-2021 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
package ti.modules.titanium.network;

import java.io.UnsupportedEncodingException;

import javax.net.ssl.X509KeyManager;
import javax.net.ssl.X509TrustManager;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;
Expand Down Expand Up @@ -289,36 +286,6 @@ public String getDomain()
return null;
}

// This uses Apache
/*
@Kroll.method
public void addAuthFactory(String scheme, Object factory)
{
//Sanity Checks
if ( (scheme == null) || (scheme.length() == 0) || (! (factory instanceof AuthSchemeFactory) )) {
return;
}
client.addAuthFactory(scheme, (AuthSchemeFactory)factory);
}
*/

@Kroll.method
public void addTrustManager(Object manager)
{
if (manager instanceof X509TrustManager) {
client.addTrustManager((X509TrustManager) manager);
}
}

@Kroll.method
public void addKeyManager(Object manager)
{
if (manager instanceof X509KeyManager) {
client.addKeyManager((X509KeyManager) manager);
}
}

@Kroll.setProperty
public void setTlsVersion(int tlsVersion)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509KeyManager;
import javax.net.ssl.X509TrustManager;

import android.util.Base64;
import org.appcelerator.kroll.KrollDict;
Expand Down Expand Up @@ -128,8 +126,6 @@ public class TiHTTPClient
private URL mURL;
private String redirectedLocation;
private final ArrayList<File> tmpFiles = new ArrayList<>();
private final ArrayList<X509TrustManager> trustManagers = new ArrayList<>();
private final ArrayList<X509KeyManager> keyManagers = new ArrayList<>();
protected SecurityManagerProtocol securityManager;
private int tlsVersion = NetworkModule.TLS_DEFAULT;

Expand Down Expand Up @@ -1059,27 +1055,7 @@ private void setUpSSL(boolean validating, HttpsURLConnection securedConnection)
}
}
if (sslSocketFactory == null) {
if (trustManagers.size() > 0 || keyManagers.size() > 0) {
TrustManager[] trustManagerArray = null;
KeyManager[] keyManagerArray = null;

if (trustManagers.size() > 0) {
trustManagerArray = new X509TrustManager[trustManagers.size()];
trustManagerArray = trustManagers.toArray(trustManagerArray);
}

if (keyManagers.size() > 0) {
keyManagerArray = new X509KeyManager[keyManagers.size()];
keyManagerArray = keyManagers.toArray(keyManagerArray);
}

try {
sslSocketFactory = new TiSocketFactory(keyManagerArray, trustManagerArray, tlsVersion);
} catch (Exception e) {
Log.e(TAG, "Error creating SSLSocketFactory: " + e.getMessage());
sslSocketFactory = null;
}
} else if (!validating) {
if (!validating) {
TrustManager[] trustManagerArray = new TrustManager[] { new NonValidatingTrustManager() };
try {
sslSocketFactory = new TiSocketFactory(null, trustManagerArray, tlsVersion);
Expand Down Expand Up @@ -1627,28 +1603,6 @@ protected boolean getAutoRedirect()
return autoRedirect;
}

protected void addKeyManager(X509KeyManager manager)
{
if (Log.isDebugModeEnabled()) {
String message
= "addKeyManager() method is deprecated. "
+ "Use the securityManager property on the HttpClient to define custom SSL Contexts.";
Log.d(TAG, message, Log.DEBUG_MODE);
}
keyManagers.add(manager);
}

protected void addTrustManager(X509TrustManager manager)
{
if (Log.isDebugModeEnabled()) {
String message
= "addTrustManager() method is deprecated. "
+ "Use the securityManager property on the HttpClient to define custom SSL Contexts.";
Log.d(TAG, message, Log.DEBUG_MODE);
}
trustManagers.add(manager);
}

protected void setTlsVersion(int value)
{
this.proxy.setProperty(TiC.PROPERTY_TLS_VERSION, value);
Expand Down

0 comments on commit 50225e1

Please sign in to comment.