Skip to content

Commit fa03f9a

Browse files
author
Steve Block
committed
Fix BrowserFrame to construct SslError using the full URL, rather than the host
https://android-git.corp.google.com/g/#/c/133348 changed BrowserFrame to construct the SslError using only the host. This was done so that we match on just the host component of the URL when re-using previous decisions in case of an SSL error. It also means that the browser displays only the host when it shows the SSL error dialog. This change fixes BrowserFrame to pass the full URL to SslError. We modify SslCertLookupTable to keep the existing behaviour regarding matching on only the host component. There's no need to change Browser to continue displaying only the host as I think this change was an unintentional side-effect. Also remove dead code-path in BrowserFrame.reportSslCertError(). This method is used only with the Chromium HTTP stack. This code was added in https://android-git.corp.google.com/g/#/c/121023. No functional change. Bug: 5410252 Change-Id: Ief2dbf4558095fb6fa7ab0caac7d37fa4f640b66
1 parent ea54b17 commit fa03f9a

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

core/java/android/net/http/SslError.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,6 @@ public SslCertificate getCertificate() {
163163
* Gets the URL associated with this object.
164164
* @return The URL, non-null.
165165
*/
166-
// TODO: When the WebView constructs an instance of this object, we
167-
// actually provide only the hostname, not the full URL. We should consider
168-
// deprecating this method, adding a new getHost() method and updating the
169-
// constructor arguments. See http://b/5410252.
170166
public String getUrl() {
171167
return mUrl;
172168
}

core/java/android/webkit/BrowserFrame.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import java.io.IOException;
4444
import java.io.InputStream;
4545
import java.lang.ref.WeakReference;
46-
import java.net.URL;
4746
import java.net.URLEncoder;
4847
import java.nio.charset.Charsets;
4948
import java.security.PrivateKey;
@@ -1171,12 +1170,7 @@ private void reportSslCertError(final int handle, final int certError, byte cert
11711170
try {
11721171
X509Certificate cert = new X509CertImpl(certDER);
11731172
SslCertificate sslCert = new SslCertificate(cert);
1174-
if (JniUtil.useChromiumHttpStack()) {
1175-
sslError = SslError.SslErrorFromChromiumErrorCode(certError, sslCert,
1176-
new URL(url).getHost());
1177-
} else {
1178-
sslError = new SslError(certError, cert, url);
1179-
}
1173+
sslError = SslError.SslErrorFromChromiumErrorCode(certError, sslCert, url);
11801174
} catch (IOException e) {
11811175
// Can't get the certificate, not much to do.
11821176
Log.e(LOGTAG, "Can't get the certificate from WebKit, canceling");

core/java/android/webkit/SslCertLookupTable.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import android.os.Bundle;
2020
import android.net.http.SslError;
2121

22+
import java.net.MalformedURLException;
23+
import java.net.URL;
24+
2225
/**
2326
* Stores the user's decision of whether to allow or deny an invalid certificate.
2427
*
@@ -40,14 +43,32 @@ private SslCertLookupTable() {
4043
}
4144

4245
public void setIsAllowed(SslError sslError, boolean allow) {
43-
table.putBoolean(sslError.toString(), allow);
46+
// TODO: We should key on just the host. See http://b/5409251.
47+
String errorString = sslErrorToString(sslError);
48+
if (errorString != null) {
49+
table.putBoolean(errorString, allow);
50+
}
4451
}
4552

4653
public boolean isAllowed(SslError sslError) {
47-
return table.getBoolean(sslError.toString());
54+
// TODO: We should key on just the host. See http://b/5409251.
55+
String errorString = sslErrorToString(sslError);
56+
return errorString == null ? false : table.getBoolean(errorString);
4857
}
4958

5059
public void clear() {
5160
table.clear();
5261
}
62+
63+
private static String sslErrorToString(SslError error) {
64+
String host;
65+
try {
66+
host = new URL(error.getUrl()).getHost();
67+
} catch(MalformedURLException e) {
68+
return null;
69+
}
70+
return "primary error: " + error.getPrimaryError() +
71+
" certificate: " + error.getCertificate() +
72+
" on host: " + host;
73+
}
5374
}

0 commit comments

Comments
 (0)