Skip to content

Commit cfb753a

Browse files
Steve BlockAndroid (Google) Code Review
authored andcommitted
Merge "Fix SslCertLookupTable to correctly determine whether we have a valid cached decision"
2 parents 63d8b0c + f219f23 commit cfb753a

File tree

1 file changed

+16
-19
lines changed

1 file changed

+16
-19
lines changed

core/java/android/webkit/SslCertLookupTable.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*/
3131
final class SslCertLookupTable {
3232
private static SslCertLookupTable sTable;
33+
// We store the most severe error we're willing to allow for each host.
3334
private final Bundle table;
3435

3536
public static SslCertLookupTable getInstance() {
@@ -44,32 +45,28 @@ private SslCertLookupTable() {
4445
}
4546

4647
public void setIsAllowed(SslError sslError) {
47-
// TODO: We should key on just the host. See http://b/5409251.
48-
String errorString = sslErrorToString(sslError);
49-
if (errorString != null) {
50-
table.putBoolean(errorString, true);
48+
String host;
49+
try {
50+
host = new URL(sslError.getUrl()).getHost();
51+
} catch(MalformedURLException e) {
52+
return;
5153
}
54+
table.putInt(host, sslError.getPrimaryError());
5255
}
5356

57+
// We allow the decision to be re-used if it's for the same host and is for
58+
// an error of equal or greater severity than this error.
5459
public boolean isAllowed(SslError sslError) {
55-
// TODO: We should key on just the host. See http://b/5409251.
56-
String errorString = sslErrorToString(sslError);
57-
return errorString == null ? false : table.getBoolean(errorString);
58-
}
59-
60-
public void clear() {
61-
table.clear();
62-
}
63-
64-
private static String sslErrorToString(SslError error) {
6560
String host;
6661
try {
67-
host = new URL(error.getUrl()).getHost();
62+
host = new URL(sslError.getUrl()).getHost();
6863
} catch(MalformedURLException e) {
69-
return null;
64+
return false;
7065
}
71-
return "primary error: " + error.getPrimaryError() +
72-
" certificate: " + error.getCertificate() +
73-
" on host: " + host;
66+
return table.containsKey(host) && sslError.getPrimaryError() <= table.getInt(host);
67+
}
68+
69+
public void clear() {
70+
table.clear();
7471
}
7572
}

0 commit comments

Comments
 (0)