Skip to content

Commit

Permalink
trying to fix https self signed cert issue
Browse files Browse the repository at this point in the history
  • Loading branch information
tmszdmsk committed Nov 13, 2013
1 parent 1588b9c commit 9e8ccc5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="14" android:versionName="1.3.0-SNAPSHOT" package="com.tadamski.arij">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="15" android:versionName="1.3.1-SNAPSHOT" package="com.tadamski.arij">

<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:name=".Application">
<activity android:name=".account.activity.AccountSelectorActivity_" android:theme="@style/Theme.Sherlock.Light">
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tadamski</groupId>
<artifactId>arij</artifactId>
<version>1.3.0-SNAPSHOT</version>
<version>1.3.1-SNAPSHOT</version>
<packaging>apk</packaging>
<name>arij</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,6 @@ void setLoginButtonState(boolean enabled) {
loginButton.setEnabled(enabled);
}

private CheckResult checkServer(LoginInfo loginInfo) {
try {
Response response = loginService.checkCredentials(loginInfo);
return new CheckResult(response.getStatus(), response.toString());
} catch (RetrofitError retrofitError) {
if (retrofitError.isNetworkError()) {
return new CheckResult(0, retrofitError.getCause().toString());
} else {
return new CheckResult(retrofitError.getResponse().getStatus(), retrofitError.toString());
}
}
}

@Background
void checkCredentials(String protocol, String url, String login, String password) {
try {
Expand All @@ -139,6 +126,7 @@ void checkCredentials(String protocol, String url, String login, String password
if (retrofitError.getCause() instanceof SSLHandshakeException && secureHttps) {
ifSelfSignedCert();
} else if (retrofitError.isNetworkError()) {
Tracker.sendEvent("AddNewAccountActivity", "login_network_error", "secureHttps="+secureHttps, null);
ifCommunicationException("Network error: \n" + retrofitError.toString());
} else {
int httpCode = retrofitError.getResponse().getStatus();
Expand All @@ -158,6 +146,7 @@ void checkCredentials(String protocol, String url, String login, String password

@UiThread
void ifSelfSignedCert() {
Tracker.sendEvent("AddNewAccountActivity", "login_failed_self_signed_certificate", null, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Untrusted SSL Certificate");
builder.setMessage("It seems like the server you want to connect to is secured with untrusted (self signed?) SSL certificate. Be careful.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.googlecode.androidannotations.annotations.EBean;
import com.tadamski.arij.util.retrofit.RestAdapterProvider;

import retrofit.RestAdapter;
import retrofit.client.Response;
Expand All @@ -20,7 +21,11 @@ public class LoginService {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();

public Response checkCredentials(LoginInfo loginInfo) {
RestAdapter restAdapter = new RestAdapter.Builder().setServer(loginInfo.getBaseURL()).setConverter(new GsonConverter(gson)).build();
RestAdapter restAdapter = new RestAdapter.Builder()
.setServer(loginInfo.getBaseURL())
.setConverter(new GsonConverter(gson))
.setClient(new RestAdapterProvider.UrlConnectionClient(loginInfo.isSecureHttps()))
.build();
LoginResource loginResource = restAdapter.create(LoginResource.class);
Response response = loginResource.checkCredentials(loginInfo);
return response;
Expand Down

0 comments on commit 9e8ccc5

Please # to comment.