Skip to content

Commit cdce116

Browse files
committed
LIBbb11121: Fixing a security issue
1 parent e0379c3 commit cdce116

7 files changed

Lines changed: 40 additions & 9 deletions

File tree

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ sudo: false
1717
jdk: oraclejdk8
1818
android:
1919
components:
20+
- platform-tools
21+
- tools
2022
- build-tools-27.0.1
21-
- extra-android-support
22-
- extra-android-m2repository
2323
- android-27
24+
- extra-android-m2repository
25+
- extra-google-m2repository
2426
licenses:
2527
- '.+'
2628
script:

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ allprojects {
2929
google()
3030
jcenter()
3131
}
32+
tasks.withType(JavaCompile) {
33+
options.encoding = "UTF-8"
34+
options.compilerArgs << "-Xlint:unchecked"
35+
}
3236
}
3337

3438
task clean(type: Delete) {

library/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ apply plugin: 'com.android.library'
1919
android {
2020
compileSdkVersion 27
2121
buildToolsVersion '27.0.1'
22-
//useLibrary 'cz.msebera.android:httpclient'
2322
defaultConfig {
2423
minSdkVersion 9
2524
targetSdkVersion 27

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

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

7171
X509TrustManager tm = new X509TrustManager() {
7272
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
73+
try {
74+
chain[0].checkValidity();
75+
} catch (Exception e) {
76+
throw new CertificateException("Certificate not valid or trusted.");
77+
}
7378
}
7479

7580
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
81+
try {
82+
chain[0].checkValidity();
83+
} catch (Exception e) {
84+
throw new CertificateException("Certificate not valid or trusted.");
85+
}
7686
}
7787

7888
public X509Certificate[] getAcceptedIssuers() {

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.Date;
3030
import java.util.List;
3131
import java.util.Locale;
32+
import java.util.Map;
3233
import java.util.concurrent.ConcurrentHashMap;
3334

3435
import cz.msebera.android.httpclient.client.CookieStore;
@@ -93,7 +94,10 @@ public void addCookie(Cookie cookie) {
9394

9495
// Save cookie into persistent store
9596
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
96-
prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
97+
98+
// This prevents map.keySet to compile to a Java 8+ KeySetView return type
99+
Map<String, Cookie> map = cookies;
100+
prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", map.keySet()));
97101
prefsWriter.putString(COOKIE_NAME_PREFIX + name, encodeCookie(new SerializableCookie(cookie)));
98102
prefsWriter.apply();
99103
}
@@ -102,7 +106,9 @@ public void addCookie(Cookie cookie) {
102106
public void clear() {
103107
// Clear cookies from persistent store
104108
SharedPreferences.Editor prefsWriter = cookiePrefs.edit();
105-
for (String name : cookies.keySet()) {
109+
// This prevents map.keySet to compile to a Java 8+ KeySetView return type
110+
Map<String, Cookie> map = cookies;
111+
for (String name : map.keySet()) {
106112
prefsWriter.remove(COOKIE_NAME_PREFIX + name);
107113
}
108114
prefsWriter.remove(COOKIE_NAME_STORE);
@@ -132,9 +138,11 @@ public boolean clearExpired(Date date) {
132138
}
133139
}
134140

141+
// This prevents map.keySet to compile to a Java 8+ KeySetView return type
142+
Map<String, Cookie> map = cookies;
135143
// Update names in persistent store
136144
if (clearedAny) {
137-
prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
145+
prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", map.keySet()));
138146
}
139147
prefsWriter.apply();
140148

sample/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ android {
9696
dependencies {
9797
implementation 'com.android.support:multidex:1.0.2'
9898
implementation 'com.android.support:support-annotations:27.0.1'
99-
implementation 'com.fasterxml.jackson.core:jackson-databind:2.5.3'
99+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.2'
100100
implementation project(':library')
101101
debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
102102
releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'

sample/proguard-rules.pro

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,13 @@
1717

1818
# Add any project specific keep options here:
1919

20-
-dontwarn com.fasterxml.jackson.**
21-
-dontwarn com.vorlonsoft.android.http.**
20+
# Proguard configuration for Jackson 2.x (fasterxml package)
21+
-keep class com.fasterxml.jackson.databind.ObjectMapper {
22+
public <methods>;
23+
protected <methods>;
24+
}
25+
-keep class com.fasterxml.jackson.databind.ObjectWriter {
26+
public ** writeValueAsString(**);
27+
}
28+
-keepnames class com.fasterxml.jackson.** { *; }
29+
-dontwarn com.fasterxml.jackson.databind.**

0 commit comments

Comments
 (0)