Skip to content

Commit fcd93b7

Browse files
author
Selim Gurun
committed
Act on credential storage updates.
Bug: 6009802 Listen to credential storage updates and clean state when necessary. Change-Id: I48f2e7d6e036882c2b4a29fbd357ca018fd4e4c7
1 parent b17932f commit fcd93b7

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
lines changed

core/java/android/net/http/CertificateChainValidator.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@
2525
import javax.net.ssl.SSLHandshakeException;
2626
import javax.net.ssl.SSLSession;
2727
import javax.net.ssl.SSLSocket;
28+
import javax.net.ssl.X509TrustManager;
2829
import org.apache.harmony.security.provider.cert.X509CertImpl;
2930
import org.apache.harmony.xnet.provider.jsse.SSLParametersImpl;
31+
import org.apache.harmony.xnet.provider.jsse.TrustManagerImpl;
3032

3133
/**
3234
* Class responsible for all server certificate validation functionality
3335
*
3436
* {@hide}
3537
*/
36-
class CertificateChainValidator {
38+
public class CertificateChainValidator {
3739

3840
/**
3941
* The singleton instance of the certificate chain validator
@@ -121,6 +123,18 @@ public static SslError verifyServerCertificates(
121123
return verifyServerDomainAndCertificates(serverCertificates, domain, authType);
122124
}
123125

126+
/**
127+
* Handles updates to credential storage.
128+
*/
129+
public static void handleTrustStorageUpdate() {
130+
131+
X509TrustManager x509TrustManager = SSLParametersImpl.getDefaultTrustManager();
132+
if( x509TrustManager instanceof TrustManagerImpl ) {
133+
TrustManagerImpl trustManager = (TrustManagerImpl) x509TrustManager;
134+
trustManager.handleTrustStorageUpdate();
135+
}
136+
}
137+
124138
/**
125139
* Common code of doHandshakeAndValidateServerCertificates and verifyServerCertificates.
126140
* Calls DomainNamevalidator to verify the domain, and TrustManager to verify the certs.

core/java/android/webkit/WebView.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import android.os.StrictMode;
6060
import android.os.SystemClock;
6161
import android.provider.Settings;
62+
import android.security.KeyChain;
6263
import android.speech.tts.TextToSpeech;
6364
import android.text.Editable;
6465
import android.text.InputType;
@@ -1261,6 +1262,7 @@ protected WebView(Context context, AttributeSet attrs, int defStyle,
12611262
init();
12621263
setupPackageListener(context);
12631264
setupProxyListener(context);
1265+
setupTrustStorageListener(context);
12641266
updateMultiTouchSupport(context);
12651267

12661268
if (privateBrowsing) {
@@ -1270,6 +1272,41 @@ protected WebView(Context context, AttributeSet attrs, int defStyle,
12701272
mAutoFillData = new WebViewCore.AutoFillData();
12711273
}
12721274

1275+
private static class TrustStorageListener extends BroadcastReceiver {
1276+
@Override
1277+
public void onReceive(Context context, Intent intent) {
1278+
if (intent.getAction().equals(KeyChain.ACTION_STORAGE_CHANGED)) {
1279+
handleCertTrustChanged();
1280+
}
1281+
}
1282+
}
1283+
private static TrustStorageListener sTrustStorageListener;
1284+
1285+
/**
1286+
* Handles update to the trust storage.
1287+
*/
1288+
private static void handleCertTrustChanged() {
1289+
// send a message for indicating trust storage change
1290+
WebViewCore.sendStaticMessage(EventHub.TRUST_STORAGE_UPDATED, null);
1291+
}
1292+
1293+
/*
1294+
* @param context This method expects this to be a valid context.
1295+
*/
1296+
private static void setupTrustStorageListener(Context context) {
1297+
if (sTrustStorageListener != null ) {
1298+
return;
1299+
}
1300+
IntentFilter filter = new IntentFilter();
1301+
filter.addAction(KeyChain.ACTION_STORAGE_CHANGED);
1302+
sTrustStorageListener = new TrustStorageListener();
1303+
Intent current =
1304+
context.getApplicationContext().registerReceiver(sTrustStorageListener, filter);
1305+
if (current != null) {
1306+
handleCertTrustChanged();
1307+
}
1308+
}
1309+
12731310
private static class ProxyReceiver extends BroadcastReceiver {
12741311
@Override
12751312
public void onReceive(Context context, Intent intent) {

core/java/android/webkit/WebViewCore.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import android.media.MediaFile;
2727
import android.net.ProxyProperties;
2828
import android.net.Uri;
29+
import android.net.http.CertificateChainValidator;
2930
import android.os.Bundle;
3031
import android.os.Handler;
3132
import android.os.Looper;
@@ -767,6 +768,11 @@ public void handleMessage(Message msg) {
767768
Message m = (Message)msg.obj;
768769
m.sendToTarget();
769770
break;
771+
case EventHub.TRUST_STORAGE_UPDATED:
772+
// post a task to network thread for updating trust manager
773+
nativeCertTrustChanged();
774+
CertificateChainValidator.handleTrustStorageUpdate();
775+
break;
770776
}
771777
}
772778
};
@@ -1124,6 +1130,9 @@ public class EventHub {
11241130
static final int SELECT_WORD_AT = 214;
11251131
static final int SELECT_ALL = 215;
11261132

1133+
// for updating state on trust storage change
1134+
static final int TRUST_STORAGE_UPDATED = 220;
1135+
11271136
// Private handler for WebCore messages.
11281137
private Handler mHandler;
11291138
// Message queue for containing messages before the WebCore thread is
@@ -3054,4 +3063,6 @@ private native void nativeSelectText(int nativeClass,
30543063
private native void nativeClearTextSelection(int nativeClass);
30553064
private native void nativeSelectWordAt(int nativeClass, int x, int y);
30563065
private native void nativeSelectAll(int nativeClass);
3066+
3067+
private static native void nativeCertTrustChanged();
30573068
}

keystore/java/android/security/KeyChain.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public final class KeyChain {
124124
public static final String EXTRA_SENDER = "sender";
125125

126126
/**
127-
* Action to bring up the CertInstaller
127+
* Action to bring up the CertInstaller.
128128
*/
129129
private static final String ACTION_INSTALL = "android.credentials.INSTALL";
130130

@@ -167,6 +167,22 @@ public final class KeyChain {
167167
// Compatible with old android.security.Credentials.PKCS12
168168
public static final String EXTRA_PKCS12 = "PKCS12";
169169

170+
171+
/**
172+
* @hide TODO This is temporary and will be removed
173+
* Broadcast Action: Indicates the trusted storage has changed. Sent when
174+
* one of this happens:
175+
*
176+
* <ul>
177+
* <li>a new CA is added,
178+
* <li>an existing CA is removed or disabled,
179+
* <li>a disabled CA is enabled,
180+
* <li>trusted storage is reset (all user certs are cleared),
181+
* <li>when permission to access a private key is changed.
182+
* </ul>
183+
*/
184+
public static final String ACTION_STORAGE_CHANGED = "android.security.STORAGE_CHANGED";
185+
170186
/**
171187
* Returns an {@code Intent} that can be used for credential
172188
* installation. The intent may be used without any extras, in

0 commit comments

Comments
 (0)