From 37a4c65e58728b321850b1e51d87eecfe9d1d805 Mon Sep 17 00:00:00 2001 From: Anthony Lee Date: Wed, 12 Feb 2014 15:50:02 -0800 Subject: [PATCH] Introduce an SSL handshake timeout value of 30 seconds. Motorola 0009-IKXREL1KK-5011 patch. Hanging on an SSL handshake is a real situation that needs to be handled. 30 seconds is more than enough of a timeout to abort on a potential hang. The coincidental thing is that there was a fix that was made a while back to email 1 that addressed the same issue in similar code. You can reference it here: b/7583420. Change-Id: I0533e57f8c5d45d241adb7f37d54ebe1f0ad9368 --- .../src/com/android/emailcommon/utility/SSLUtils.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/emailcommon/src/com/android/emailcommon/utility/SSLUtils.java b/emailcommon/src/com/android/emailcommon/utility/SSLUtils.java index 66afe146c..a620a284c 100644 --- a/emailcommon/src/com/android/emailcommon/utility/SSLUtils.java +++ b/emailcommon/src/com/android/emailcommon/utility/SSLUtils.java @@ -54,6 +54,9 @@ public class SSLUtils { private static final boolean LOG_ENABLED = false; private static final String TAG = "Email.Ssl"; + // A 30 second SSL handshake should be more than enough. + private static final int SSL_HANDSHAKE_TIMEOUT = 30000; + /** * A trust manager specific to a particular HostAuth. The first time a server certificate is * encountered for the HostAuth, its certificate is saved; subsequent checks determine whether @@ -144,7 +147,7 @@ public class SSLUtils { HostAuth hostAuth, boolean insecure) { if (insecure) { SSLCertificateSocketFactory insecureFactory = (SSLCertificateSocketFactory) - SSLCertificateSocketFactory.getInsecure(0, null); + SSLCertificateSocketFactory.getInsecure(SSL_HANDSHAKE_TIMEOUT, null); insecureFactory.setTrustManagers( new TrustManager[] { new SameCertificateCheckingTrustManager(context, hostAuth)}); @@ -152,7 +155,7 @@ public class SSLUtils { } else { if (sSecureFactory == null) { sSecureFactory = (SSLCertificateSocketFactory) - SSLCertificateSocketFactory.getDefault(0, null); + SSLCertificateSocketFactory.getDefault(SSL_HANDSHAKE_TIMEOUT, null); } return sSecureFactory; }