Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7897fdd6 authored by Steve Block's avatar Steve Block Committed by Android (Google) Code Review
Browse files

Merge "Fix BrowserFrame to construct SslError using the full URL, rather than the host"

parents 1d4a2555 fa03f9a3
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -163,10 +163,6 @@ public class SslError {
     * Gets the URL associated with this object.
     * @return The URL, non-null.
     */
    // TODO: When the WebView constructs an instance of this object, we
    // actually provide only the hostname, not the full URL. We should consider
    // deprecating this method, adding a new getHost() method and updating the
    // constructor arguments. See http://b/5410252.
    public String getUrl() {
        return mUrl;
    }
+1 −7
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ import junit.framework.Assert;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.Charsets;
import java.security.PrivateKey;
@@ -1171,12 +1170,7 @@ class BrowserFrame extends Handler {
        try {
            X509Certificate cert = new X509CertImpl(certDER);
            SslCertificate sslCert = new SslCertificate(cert);
            if (JniUtil.useChromiumHttpStack()) {
                sslError = SslError.SslErrorFromChromiumErrorCode(certError, sslCert,
                        new URL(url).getHost());
            } else {
                sslError = new SslError(certError, cert, url);
            }
            sslError = SslError.SslErrorFromChromiumErrorCode(certError, sslCert, url);
        } catch (IOException e) {
            // Can't get the certificate, not much to do.
            Log.e(LOGTAG, "Can't get the certificate from WebKit, canceling");
+23 −2
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ package android.webkit;
import android.os.Bundle;
import android.net.http.SslError;

import java.net.MalformedURLException;
import java.net.URL;

/**
 * Stores the user's decision of whether to allow or deny an invalid certificate.
 *
@@ -40,14 +43,32 @@ final class SslCertLookupTable {
    }

    public void setIsAllowed(SslError sslError, boolean allow) {
        table.putBoolean(sslError.toString(), allow);
        // TODO: We should key on just the host. See http://b/5409251.
        String errorString = sslErrorToString(sslError);
        if (errorString != null) {
            table.putBoolean(errorString, allow);
        }
    }

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

    public void clear() {
        table.clear();
    }

    private static String sslErrorToString(SslError error) {
        String host;
        try {
            host = new URL(error.getUrl()).getHost();
        } catch(MalformedURLException e) {
            return null;
        }
        return "primary error: " + error.getPrimaryError() +
                " certificate: " + error.getCertificate() +
                " on host: " + host;
    }
}