diff options
author | Ye Wen <ywen@google.com> | 2015-02-19 16:08:16 -0800 |
---|---|---|
committer | The Android Automerger <android-build@google.com> | 2015-03-11 19:35:38 -0700 |
commit | 1e146022ae0b2ba055685d517c216fd39fada7fb (patch) | |
tree | ac2b5784a0d2475e9c0784aae7d6d9b58b90d9cd | |
parent | ea675e088d4cbc4bd896dcc6178639767ad48368 (diff) | |
download | Mms-1e146022ae0b2ba055685d517c216fd39fada7fb.tar.gz |
Redact MMS message URL loggingandroid-cts-5.1_r9android-cts-5.1_r8android-cts-5.1_r7android-cts-5.1_r6android-cts-5.1_r5android-cts-5.1_r4android-cts-5.1_r3android-cts-5.1_r28android-cts-5.1_r27android-cts-5.1_r26android-cts-5.1_r25android-cts-5.1_r24android-cts-5.1_r23android-cts-5.1_r22android-cts-5.1_r21android-cts-5.1_r20android-cts-5.1_r2android-cts-5.1_r19android-cts-5.1_r18android-cts-5.1_r17android-cts-5.1_r16android-cts-5.1_r15android-cts-5.1_r14android-cts-5.1_r13android-cts-5.1_r10android-cts-5.1_r1android-5.1.1_r9android-5.1.1_r6android-5.1.1_r4android-5.1.1_r38android-5.1.1_r37android-5.1.1_r36android-5.1.1_r35android-5.1.1_r34android-5.1.1_r33android-5.1.1_r30android-5.1.1_r3android-5.1.1_r26android-5.1.1_r25android-5.1.1_r24android-5.1.1_r20android-5.1.1_r2android-5.1.1_r19android-5.1.1_r16android-5.1.1_r15android-5.1.1_r14android-5.1.1_r10android-5.1.1_r1android-5.1.0_r5lollipop-mr1-releaselollipop-mr1-cts-release
Sprint embeds phone number into message URL.
b/19444241
Change-Id: I19505816d6b0639e2bd66bcfe12b53a6531db766
-rw-r--r-- | src/com/android/mms/service/MmsHttpClient.java | 43 | ||||
-rw-r--r-- | src/com/android/mms/service/MmsService.java | 3 | ||||
-rw-r--r-- | src/com/android/mms/service/PhoneUtils.java | 4 |
3 files changed, 41 insertions, 9 deletions
diff --git a/src/com/android/mms/service/MmsHttpClient.java b/src/com/android/mms/service/MmsHttpClient.java index 281d9b6..1099b64 100644 --- a/src/com/android/mms/service/MmsHttpClient.java +++ b/src/com/android/mms/service/MmsHttpClient.java @@ -105,7 +105,7 @@ public class MmsHttpClient { public byte[] execute(String urlString, byte[] pdu, String method, boolean isProxySet, String proxyHost, int proxyPort, MmsConfig.Overridden mmsConfig) throws MmsHttpException { - Log.d(MmsService.TAG, "HTTP: " + method + " " + urlString + Log.d(MmsService.TAG, "HTTP: " + method + " " + redactUrlForNonVerbose(urlString) + (isProxySet ? (", proxy=" + proxyHost + ":" + proxyPort) : "") + ", PDU size=" + (pdu != null ? pdu.length : 0)); checkMethod(method); @@ -193,11 +193,13 @@ public class MmsHttpClient { + (responseBody != null ? responseBody.length : 0)); return responseBody; } catch (MalformedURLException e) { - Log.e(MmsService.TAG, "HTTP: invalid URL " + urlString, e); - throw new MmsHttpException(0/*statusCode*/, "Invalid URL " + urlString, e); + final String redactedUrl = redactUrlForNonVerbose(urlString); + Log.e(MmsService.TAG, "HTTP: invalid URL " + redactedUrl, e); + throw new MmsHttpException(0/*statusCode*/, "Invalid URL " + redactedUrl, e); } catch (ProtocolException e) { - Log.e(MmsService.TAG, "HTTP: invalid URL protocol " + urlString, e); - throw new MmsHttpException(0/*statusCode*/, "Invalid URL protocol " + urlString, e); + final String redactedUrl = redactUrlForNonVerbose(urlString); + Log.e(MmsService.TAG, "HTTP: invalid URL protocol " + redactedUrl, e); + throw new MmsHttpException(0/*statusCode*/, "Invalid URL protocol " + redactedUrl, e); } catch (IOException e) { Log.e(MmsService.TAG, "HTTP: IO failure", e); throw new MmsHttpException(0/*statusCode*/, e); @@ -380,4 +382,35 @@ public class MmsHttpClient { } } } + + /** + * Redact the URL for non-VERBOSE logging. Replace url with only the host part and the length + * of the input URL string. + * + * @param urlString + * @return + */ + public static String redactUrlForNonVerbose(String urlString) { + if (Log.isLoggable(MmsService.TAG, Log.VERBOSE)) { + // Don't redact for VERBOSE level logging + return urlString; + } + if (TextUtils.isEmpty(urlString)) { + return urlString; + } + String protocol = "http"; + String host = ""; + try { + final URL url = new URL(urlString); + protocol = url.getProtocol(); + host = url.getHost(); + } catch (MalformedURLException e) { + // Ignore + } + // Print "http://host[length]" + final StringBuilder sb = new StringBuilder(); + sb.append(protocol).append("://").append(host) + .append("[").append(urlString.length()).append("]"); + return sb.toString(); + } } diff --git a/src/com/android/mms/service/MmsService.java b/src/com/android/mms/service/MmsService.java index 09a86a9..8c31e71 100644 --- a/src/com/android/mms/service/MmsService.java +++ b/src/com/android/mms/service/MmsService.java @@ -64,7 +64,6 @@ import java.util.Arrays; import java.util.List; import java.util.Queue; import java.util.concurrent.Callable; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -204,7 +203,7 @@ public class MmsService extends Service implements MmsRequest.RequestManager { public void downloadMessage(int subId, String callingPkg, String locationUrl, Uri contentUri, Bundle configOverrides, PendingIntent downloadedIntent) throws RemoteException { - Log.d(TAG, "downloadMessage: " + locationUrl); + Log.d(TAG, "downloadMessage: " + MmsHttpClient.redactUrlForNonVerbose(locationUrl)); enforceSystemUid(); // Make sure the subId is correct subId = checkSubId(subId); diff --git a/src/com/android/mms/service/PhoneUtils.java b/src/com/android/mms/service/PhoneUtils.java index fc1ff4b..8de881a 100644 --- a/src/com/android/mms/service/PhoneUtils.java +++ b/src/com/android/mms/service/PhoneUtils.java @@ -60,12 +60,12 @@ public class PhoneUtils { if (phoneNumberUtil.isValidNumber(phoneNumber)) { return phoneNumber; } else { - Log.e(MmsService.TAG, "getParsedNumber: not a valid phone number " + phoneText + Log.e(MmsService.TAG, "getParsedNumber: not a valid phone number" + " for country " + country); return null; } } catch (final NumberParseException e) { - Log.e(MmsService.TAG, "getParsedNumber: Not able to parse phone number " + phoneText); + Log.e(MmsService.TAG, "getParsedNumber: Not able to parse phone number"); return null; } } |