Skip to content

Commit

Permalink
Implement a workable solution for issue jonan#345
Browse files Browse the repository at this point in the history
Also tackle legacy device support, downgrade minSdkVersion to 18 from 19
unless someone can tell me that there is a reason the code base must be
on API 19.  Note: I've been working at this to be able to continue to
maintain at least one Github client working with BB10 (Blackberry OS10),
which has ForkHub as its sole Github client in the app store
BlackberryWorld (also in Amazon store), however this app stopped working
about a year or so back, and this should provide a fix.  Work with
upstream maintainers to sort out cleanest fix as this only takes into
account a build specific to the legacy devices.
  • Loading branch information
truedat101 committed Nov 9, 2018
1 parent cfcd0ab commit 6744ab1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {

defaultConfig {
applicationId 'jp.forkhub'
minSdkVersion 19
minSdkVersion 18
targetSdkVersion 27
versionCode 1020900
versionName '1.2.9'
Expand Down Expand Up @@ -55,4 +55,5 @@ dependencies {

//Self compiled .aar version of wishlist
compile(name: 'lib', ext: 'aar')
implementation 'com.android.support:appcompat-v7:27.1.0'
}
39 changes: 36 additions & 3 deletions app/src/main/java/com/github/mobile/DefaultClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import okhttp3.OkHttpClient;
import okhttp3.OkUrlFactory;
Expand Down Expand Up @@ -50,8 +57,34 @@ public DefaultClient() {
*/
@Override
protected HttpURLConnection createConnection(String uri) throws IOException {
OkUrlFactory factory = new OkUrlFactory(new OkHttpClient());
URL url = new URL(createUri(uri));
return factory.open(url);
// OkUrlFactory factory = new OkUrlFactory(new OkHttpClient());
//
// TODO: Look through code base to explore how project handles exceptions
// generally, and what to do about the fact this connection has several
// new ways it can throw an exception, instead of burrying the fault of KeyManagementException or
// NoSuchAlgorithmException
try {
// NOTE: The deprecated signature below for sslSocketFactory()
// final OkHttpClient client = new OkHttpClient.Builder().sslSocketFactory(new TLSSocketFactory()).build();

// public OkHttpClient.Builder sslSocketFactory(SSLSocketFactory sslSocketFactory,
// X509TrustManager trustManager)
TrustManager[] trustManagers = new TrustManager[] { new TrustManagerManipulator() };

SSLContext context = SSLContext.getInstance("TLS");
context.init(null, trustManagers, new SecureRandom());
final OkHttpClient client2 = new OkHttpClient.Builder().sslSocketFactory(new TLSSocketFactory(context.getSocketFactory()), (X509TrustManager) trustManagers[0]).build();
URL url = new URL(createUri(uri));
OkUrlFactory factory = new OkUrlFactory(client2);
return factory.open(url);
} catch (KeyManagementException e) {
e.printStackTrace();
throw new IOException(e.getMessage());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
throw new IOException(e.getMessage());
}
// URL url = new URL(createUri(uri));
// return factory.open(url);
}
}

4 comments on commit 6744ab1

@truedat101
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few things to note on this commit:

  • Tested on a few earlier devices, and the above code can work, and works on at least one device
  • it's not working on my 4.3 device, but I need to get that device hooked up to a debugger to test further as to what's still wrong
  • This commit doesn't take into account that we might want to keep the original code in there for API level greater than "legacy device", and use this for the devices currently broken
  • I also don't like that the error that bubbles up is "invalid verification code" or whatever, should be a bit more detailed if in fact this is an exception related to certificates, TLS support, reflection. I would like for these sorts of errors to bubble up instead of being made to this this is just failure to authenticate.

@truedat101
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another part of the "problem" is that the existing original code is using some deprecated methods. Need to get off of those, not because the signatures are going away soon, but this seems to have some impact on the behavior in having problems with reflection and how the SSLContext gets loaded. https://square.github.io/okhttp/3.x/okhttp/okhttp3/OkHttpClient.Builder.html

@truedat101
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My BB10 device still fails but my Nexus works with the above code. BB10 needs to go onto the debugger. I have to figure out how to set that up.

@truedat101
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So a few more details on the BB10 android 4.3 issue:

To setup a dev environment:

  • Download BB10 Command Line tools for Android (requires a 4.3 SDK for Android)
  • Setup the developer mode on the target BB10 device
  • Check your BB10 target device's IP address on wifi. Let's assume it's something 192.168.1.10 or whatever
  • Set the password to something for BB10
  • Run the bat file: blackberry-adbproxy --gui
  • When the UI pops up, add a new device by ip address
  • It will prompt for a password.
  • If a CSR is needed to be installed on the device, do so, and you'll need to login with a blackberry ID and download that CSR
  • When selecting the CSR in the GUI, it will get installed.
  • At that point, connect up, and the ADB bridge starts and gets running on some port. note the port.
  • From adb, connect to: adb connect 192.168.1.10 (or whatever IP)

A lot of steps ...

Here is the failure on the device:

D/LoginActivity(12329215): Exception requesting authenticated user
D/LoginActivity(12329215): javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=11554678: Failure in SSL library, usually a protocol error
D/LoginActivity(12329215): error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version (external/openssl/ssl/s23_clnt.c:749 78cd128f:0x00000000)
D/LoginActivity(12329215):      at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:440)
D/LoginActivity(12329215):      at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:299)
D/LoginActivity(12329215):      at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:268)
D/LoginActivity(12329215):      at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:160)
D/LoginActivity(12329215):      at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:256)
D/LoginActivity(12329215):      at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134)
D/LoginActivity(12329215):      at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113)
D/LoginActivity(12329215):      at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
D/LoginActivity(12329215):      at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
D/LoginActivity(12329215):      at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
D/LoginActivity(12329215):      at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
D/LoginActivity(12329215):      at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
D/LoginActivity(12329215):      at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
D/LoginActivity(12329215):      at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
D/LoginActivity(12329215):      at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
D/LoginActivity(12329215):      at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
D/LoginActivity(12329215):      at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
D/LoginActivity(12329215):      at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
D/LoginActivity(12329215):      at okhttp3.internal.huc.OkHttpURLConnection$UnexpectedException$1.intercept(OkHttpURLConnection.java:564)
D/LoginActivity(12329215):      at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
D/LoginActivity(12329215):      at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
D/LoginActivity(12329215):      at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
D/LoginActivity(12329215):      at okhttp3.RealCall.execute(RealCall.java:77)
D/LoginActivity(12329215):      at okhttp3.internal.huc.OkHttpURLConnection.getResponse(OkHttpURLConnection.java:436)
D/LoginActivity(12329215):      at okhttp3.internal.huc.OkHttpURLConnection.getResponseCode(OkHttpURLConnection.java:473)
D/LoginActivity(12329215):      at okhttp3.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:106)
D/LoginActivity(12329215):      at okhttp3.internal.huc.OkHttpsURLConnection.getResponseCode(OkHttpsURLConnection.java:26)
D/LoginActivity(12329215):      at com.github.mobile.accounts.TwoFactorAuthClient.get(TwoFactorAuthClient.java:81)
D/LoginActivity(12329215):      at org.eclipse.egit.github.core.service.UserService.getUser(UserService.java:95)
D/LoginActivity(12329215):      at com.github.mobile.accounts.LoginActivity$5.call(LoginActivity.java:298)
D/LoginActivity(12329215):      at com.github.mobile.accounts.LoginActivity$5.call(LoginActivity.java:289)
D/LoginActivity(12329215):      at roboguice.util.SafeAsyncTask$Task.doCall(SafeAsyncTask.java:204)
D/LoginActivity(12329215):      at roboguice.util.SafeAsyncTask$Task.call(SafeAsyncTask.java:170)
D/LoginActivity(12329215):      at roboguice.util.SafeAsyncTask$Task.call(SafeAsyncTask.java:158)
D/LoginActivity(12329215):      at java.util.concurrent.FutureTask.run(FutureTask.java:234)

D/LoginActivity(12329215):      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
D/LoginActivity(12329215):      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
D/LoginActivity(12329215):      at java.lang.Thread.run(Thread.java:841)
D/LoginActivity(12329215):      at dalvik.system.VMStack.getThreadStackTrace(Native Method)

D/LoginActivity(12329215):      at java.lang.Thread.getStackTrace(Thread.java:579)
D/LoginActivity(12329215):      at roboguice.util.SafeAsyncTask.execute(SafeAsyncTask.java:90)
D/LoginActivity(12329215):      at com.github.mobile.accounts.LoginActivity.handleLogin(LoginActivity.java:339)
D/LoginActivity(12329215):      at com.github.mobile.accounts.LoginActivity$3.onEditorAction(LoginActivity.java:219)
D/LoginActivity(12329215):      at android.widget.TextView.onEditorAction(TextView.java:4203)
D/LoginActivity(12329215):      at com.android.internal.widget.EditableInputConnection.performEditorAction(EditableInputConnection.java:138)
D/LoginActivity(12329215):      at com.android.internal.view.IInputConnectionWrappe
W/InputMethodManagerService(12136481): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@2a22db68 attribute=null, token = android.os.BinderProxy@2a0978a8
D/dalvikvm(14659836): GC_CONCURRENT freed 463K, 4% free 17809K/18408K, paused 8ms+2ms, total 62ms

Please sign in to comment.