Skip to content

Commit 7897fdd

Browse files
Steve BlockAndroid (Google) Code Review
authored andcommitted
Merge "Fix BrowserFrame to construct SslError using the full URL, rather than the host"
2 parents 1d4a255 + fa03f9a commit 7897fdd

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)