summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2014-09-04 21:23:43 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-09-04 21:23:43 +0000
commit41bb5d1676e94fe9aa261d7b7f76e7cbd83e6004 (patch)
tree6e3298a6aea7cbf10fc71ae5a1c3fdafb0defc96
parent8129648fee0b8e24c359d1495fb6c2fc98aecd89 (diff)
parenta556465b9bbfcd89e446a89d4d9b91da5b68897e (diff)
am 04164b5a: Merge "Protect phonenumbers with Log.pii" into lmp-dev
* commit '04164b5adbb3f9baee5623fbe023b7062b86fe0d': Protect phonenumbers with Log.pii
-rw-r--r--InCallUI/src/com/android/incallui/ContactInfoCache.java2
-rw-r--r--InCallUI/src/com/android/incallui/Log.java72
2 files changed, 73 insertions, 1 deletions
diff --git a/InCallUI/src/com/android/incallui/ContactInfoCache.java b/InCallUI/src/com/android/incallui/ContactInfoCache.java
index fec319854..d0d093940 100644
--- a/InCallUI/src/com/android/incallui/ContactInfoCache.java
+++ b/InCallUI/src/com/android/incallui/ContactInfoCache.java
@@ -420,7 +420,7 @@ public class ContactInfoCache implements ContactsAsyncHelper.OnImageLoadComplete
}
Log.d(TAG, " ==> no name; falling back to number:"
- + " displayNumber '" + displayNumber
+ + " displayNumber '" + Log.pii(displayNumber)
+ "', displayLocation '" + displayLocation + "'");
}
} else {
diff --git a/InCallUI/src/com/android/incallui/Log.java b/InCallUI/src/com/android/incallui/Log.java
index 6bf993a49..a834919c5 100644
--- a/InCallUI/src/com/android/incallui/Log.java
+++ b/InCallUI/src/com/android/incallui/Log.java
@@ -16,6 +16,12 @@
package com.android.incallui;
+import android.net.Uri;
+import android.telephony.PhoneNumberUtils;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
/**
* Manages logging for the entire class.
*/
@@ -91,6 +97,72 @@ public class Log {
android.util.Log.wtf(TAG, getPrefix(obj) + msg);
}
+ public static String piiHandle(Object pii) {
+ if (pii == null || VERBOSE) {
+ return String.valueOf(pii);
+ }
+
+ if (pii instanceof Uri) {
+ Uri uri = (Uri) pii;
+
+ // All Uri's which are not "tel" go through normal pii() method.
+ if (!"tel".equals(uri.getScheme())) {
+ return pii(pii);
+ } else {
+ pii = uri.getSchemeSpecificPart();
+ }
+ }
+
+ String originalString = String.valueOf(pii);
+ StringBuilder stringBuilder = new StringBuilder(originalString.length());
+ for (char c : originalString.toCharArray()) {
+ if (PhoneNumberUtils.isDialable(c)) {
+ stringBuilder.append('*');
+ } else {
+ stringBuilder.append(c);
+ }
+ }
+ return stringBuilder.toString();
+ }
+
+ /**
+ * Redact personally identifiable information for production users.
+ * If we are running in verbose mode, return the original string, otherwise
+ * return a SHA-1 hash of the input string.
+ */
+ public static String pii(Object pii) {
+ if (pii == null || VERBOSE) {
+ return String.valueOf(pii);
+ }
+ return "[" + secureHash(String.valueOf(pii).getBytes()) + "]";
+ }
+
+ private static String secureHash(byte[] input) {
+ MessageDigest messageDigest;
+ try {
+ messageDigest = MessageDigest.getInstance("SHA-1");
+ } catch (NoSuchAlgorithmException e) {
+ return null;
+ }
+ messageDigest.update(input);
+ byte[] result = messageDigest.digest();
+ return encodeHex(result);
+ }
+
+ private static String encodeHex(byte[] bytes) {
+ StringBuffer hex = new StringBuffer(bytes.length * 2);
+
+ for (int i = 0; i < bytes.length; i++) {
+ int byteIntValue = bytes[i] & 0xff;
+ if (byteIntValue < 0x10) {
+ hex.append("0");
+ }
+ hex.append(Integer.toString(byteIntValue, 16));
+ }
+
+ return hex.toString();
+ }
+
private static String getPrefix(Object obj) {
return (obj == null ? "" : (obj.getClass().getSimpleName() + TAG_DELIMETER));
}