Skip to content

Commit d494c8a

Browse files
authored
Merge pull request android-async-http#1261 from BahadirBulduk/android-async-http#1260-TrustManager
Fixing a security issue which is banned by google play.
2 parents f53deef + 26d135c commit d494c8a

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ sudo: false
33
jdk: openjdk7
44
android:
55
components:
6-
- build-tools-23.0.1
7-
- extra-android-support
8-
- extra-android-m2repository
6+
- platform-tools
7+
- tools
8+
- build-tools-23.0.3
99
- android-23
10+
- extra-android-m2repository
11+
- extra-google-m2repository
12+
1013
licenses:
1114
- '.+'
1215
script:

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ apply plugin: 'com.android.library'
22

33
android {
44
compileSdkVersion 23
5-
buildToolsVersion '23.0.1'
5+
buildToolsVersion '23.0.3'
66

77
defaultConfig {
8-
minSdkVersion 3
8+
minSdkVersion 9
99
targetSdkVersion 23
1010
consumerProguardFiles 'proguard.txt'
1111
}

library/src/main/java/com/loopj/android/http/MySSLSocketFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,19 @@ public MySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException,
7272

7373
X509TrustManager tm = new X509TrustManager() {
7474
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
75+
try {
76+
chain[0].checkValidity();
77+
} catch (Exception e) {
78+
throw new CertificateException("Certificate not valid or trusted.");
79+
}
7580
}
7681

7782
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
83+
try {
84+
chain[0].checkValidity();
85+
} catch (Exception e) {
86+
throw new CertificateException("Certificate not valid or trusted.");
87+
}
7888
}
7989

8090
public X509Certificate[] getAcceptedIssuers() {

library/src/main/java/com/loopj/android/http/PersistentCookieStore.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void addCookie(Cookie cookie) {
9797
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
9898
prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
9999
prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
100-
prefsWriter.commit();
100+
prefsWriter.apply();
101101
}
102102

103103
@Override
@@ -108,7 +108,7 @@ public void clear() {
108108
prefsWriter.remove(COOKIE_NAME_PREFIX + name);
109109
}
110110
prefsWriter.remove(COOKIE_NAME_STORE);
111-
prefsWriter.commit();
111+
prefsWriter.apply();
112112

113113
// Clear cookies from local store
114114
cookies.clear();
@@ -138,7 +138,7 @@ public boolean clearExpired(Date date) {
138138
if (clearedAny) {
139139
prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
140140
}
141-
prefsWriter.commit();
141+
prefsWriter.apply();
142142

143143
return clearedAny;
144144
}
@@ -168,7 +168,7 @@ public void deleteCookie(Cookie cookie) {
168168
cookies.remove(name);
169169
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
170170
prefsWriter.remove(COOKIE_NAME_PREFIX + name);
171-
prefsWriter.commit();
171+
prefsWriter.apply();
172172
}
173173

174174
/**

sample/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ repositories {
99

1010
android {
1111
compileSdkVersion 23
12-
buildToolsVersion '23.0.1'
12+
buildToolsVersion '23.0.3'
1313

1414
defaultConfig {
15-
minSdkVersion 3
15+
minSdkVersion 9
1616
targetSdkVersion 23
1717
}
1818

1919
productFlavors {
2020
standard {
2121
}
2222
withLeakCanary {
23-
minSdkVersion 8
23+
minSdkVersion 9
2424
targetSdkVersion 23
2525
}
2626
}

0 commit comments

Comments
 (0)