Skip to content

Commit e83b83f

Browse files
Selim GurunAndroid (Google) Code Review
authored andcommitted
Merge "Act on credential storage updates."
2 parents ada8c18 + fcd93b7 commit e83b83f

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;
@@ -1303,6 +1304,7 @@ protected WebView(Context context, AttributeSet attrs, int defStyle,
13031304
init();
13041305
setupPackageListener(context);
13051306
setupProxyListener(context);
1307+
setupTrustStorageListener(context);
13061308
updateMultiTouchSupport(context);
13071309

13081310
if (privateBrowsing) {
@@ -1312,6 +1314,41 @@ protected WebView(Context context, AttributeSet attrs, int defStyle,
13121314
mAutoFillData = new WebViewCore.AutoFillData();
13131315
}
13141316

1317+
private static class TrustStorageListener extends BroadcastReceiver {
1318+
@Override
1319+
public void onReceive(Context context, Intent intent) {
1320+
if (intent.getAction().equals(KeyChain.ACTION_STORAGE_CHANGED)) {
1321+
handleCertTrustChanged();
1322+
}
1323+
}
1324+
}
1325+
private static TrustStorageListener sTrustStorageListener;
1326+
1327+
/**
1328+
* Handles update to the trust storage.
1329+
*/
1330+
private static void handleCertTrustChanged() {
1331+
// send a message for indicating trust storage change
1332+
WebViewCore.sendStaticMessage(EventHub.TRUST_STORAGE_UPDATED, null);
1333+
}
1334+
1335+
/*
1336+
* @param context This method expects this to be a valid context.
1337+
*/
1338+
private static void setupTrustStorageListener(Context context) {
1339+
if (sTrustStorageListener != null ) {
1340+
return;
1341+
}
1342+
IntentFilter filter = new IntentFilter();
1343+
filter.addAction(KeyChain.ACTION_STORAGE_CHANGED);
1344+
sTrustStorageListener = new TrustStorageListener();
1345+
Intent current =
1346+
context.getApplicationContext().registerReceiver(sTrustStorageListener, filter);
1347+
if (current != null) {
1348+
handleCertTrustChanged();
1349+
}
1350+
}
1351+
13151352
private static class ProxyReceiver extends BroadcastReceiver {
13161353
@Override
13171354
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
};
@@ -1125,6 +1131,9 @@ public class EventHub {
11251131
static final int SELECT_WORD_AT = 214;
11261132
static final int SELECT_ALL = 215;
11271133

1134+
// for updating state on trust storage change
1135+
static final int TRUST_STORAGE_UPDATED = 220;
1136+
11281137
// Private handler for WebCore messages.
11291138
private Handler mHandler;
11301139
// Message queue for containing messages before the WebCore thread is
@@ -3077,4 +3086,6 @@ private native void nativeSelectText(int nativeClass,
30773086
private native void nativeClearTextSelection(int nativeClass);
30783087
private native void nativeSelectWordAt(int nativeClass, int x, int y);
30793088
private native void nativeSelectAll(int nativeClass);
3089+
3090+
private static native void nativeCertTrustChanged();
30803091
}

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)