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

Commit b6aa97e0 authored by Selim Gurun's avatar Selim Gurun
Browse files

Add ClientCert support

Bug: 12983007

This is to add APIs for client certificates. Keep the APIs hidden
until finalizing the design.

Change-Id: I8a1e755e2c509cf821dff7c7df0ddd5270a5f79b
parent 10459a54
Loading
Loading
Loading
Loading
+80 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.webkit;

import java.security.Principal;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;

/**
 * ClientCertRequest: The user receives an instance of this class as
 * a parameter of {@link WebViewClient#onReceivedClientCertRequest}.
 * The request includes the parameters to choose the client certificate,
 * such as the host name and the port number requesting the cert, the acceptable
 * key types and the principals.
 *
 * The user should call one of the interface methods to indicate how to deal
 * with the client certificate request. All methods should be called on
 * UI thread.
 *
 * WebView caches the {@link #proceed} and {@link #cancel} responses in memory
 * and uses them to handle future client certificate requests for the same
 * host/port pair. The user can clear the cached data using
 * {@link WebView#clearClientCertPreferences}.
 *
 * TODO(sgurun) unhide
 * @hide
 */
public interface ClientCertRequest {
    /**
     * Returns the acceptable types of asymmetric keys (can be null).
     */
    public String[] getKeyTypes();

    /**
     * Returns the acceptable certificate issuers for the certificate
     *            matching the private key (can be null).
     */
    public Principal[] getPrincipals();

    /**
     * Returns the host name of the server requesting the certificate.
     */
    public String getHost();

    /**
     * Returns the port number of the server requesting the certificate.
     */
    public int getPort();

    /**
     * Proceed with the specified private key and client certificate chain.
     * Remember the user's positive choice and use it for future requests.
     */
    public void proceed(PrivateKey privateKey, X509Certificate[] chain);

    /**
     * Ignore the request for now. Do not remember user's choice.
     */
    public void ignore();

    /**
     * Cancel this request. Remember the user's choice and use it for
     * future requests.
     */
    public void cancel();
}
+18 −1
Original line number Original line Diff line number Diff line
@@ -1475,6 +1475,23 @@ public class WebView extends AbsoluteLayout
        mProvider.clearSslPreferences();
        mProvider.clearSslPreferences();
    }
    }


    /**
     * Clears the client certificate preferences table stored in response
     * to proceeding/cancelling client cert requests. Note that webview
     * automatically clears these preferences when it receives a
     * {@link KeyChain.ACTION_STORAGE_CHANGED}
     *
     * @param resultCallback A callback to be invoked when client certs are cleared.
     *
     * TODO(sgurun) unhide
     * @hide
     */
    public void clearClientCertPreferences(ValueCallback<Void> resultCallback) {
        checkThread();
        if (DebugFlags.TRACE_API) Log.d(LOGTAG, "clearClientCertPreferences");
        mProvider.clearClientCertPreferences(resultCallback);
    }

    /**
    /**
     * Gets the WebBackForwardList for this WebView. This contains the
     * Gets the WebBackForwardList for this WebView. This contains the
     * back/forward list for use in querying each item in the history stack.
     * back/forward list for use in querying each item in the history stack.
+26 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,8 @@ import android.os.Message;
import android.view.KeyEvent;
import android.view.KeyEvent;
import android.view.ViewRootImpl;
import android.view.ViewRootImpl;


import java.security.Principal;

public class WebViewClient {
public class WebViewClient {


    /**
    /**
@@ -204,6 +206,30 @@ public class WebViewClient {
        handler.cancel();
        handler.cancel();
    }
    }


    /**
     * Notify the host application to handle a SSL client certificate
     * request. The host application is responsible for showing the UI
     * if desired and providing the keys. There are three ways to
     * respond: proceed(), cancel() or ignore(). Webview remembers the
     * response if proceed() or cancel() is called and does not
     * call onReceivedClientCertRequest() again for the same host and port
     * pair. Webview does not remember the response if ignore() is called.
     *
     * This method is called on the UI thread. During the callback, the
     * connection is suspended.
     *
     * The default behavior is to cancel, returning no client certificate.
     *
     * @param view The WebView that is initiating the callback
     * @param request An instance of a {@link ClientCertRequest}
     *
     * TODO(sgurun) unhide
     * @hide
     */
    public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) {
        request.cancel();
    }

    /**
    /**
     * Notifies the host application that the WebView received an HTTP
     * Notifies the host application that the WebView received an HTTP
     * authentication request. The host application can use the supplied
     * authentication request. The host application can use the supplied
+2 −0
Original line number Original line Diff line number Diff line
@@ -198,6 +198,8 @@ public interface WebViewProvider {


    public void clearSslPreferences();
    public void clearSslPreferences();


    public void clearClientCertPreferences(ValueCallback<Void> resultCallback);

    public WebBackForwardList copyBackForwardList();
    public WebBackForwardList copyBackForwardList();


    public void setFindListener(WebView.FindListener listener);
    public void setFindListener(WebView.FindListener listener);