diff options
-rw-r--r-- | core/java/android/app/backup/BackupAgent.java | 2 | ||||
-rw-r--r-- | core/java/com/android/internal/widget/LockPatternUtils.java | 37 | ||||
-rw-r--r-- | media/mca/filterfw/Android.mk | 6 | ||||
-rw-r--r-- | media/mca/filterfw/jni/Android.mk | 7 | ||||
-rw-r--r-- | media/mca/filterpacks/Android.mk | 2 | ||||
-rw-r--r-- | rs/java/android/renderscript/RenderScript.java | 2 | ||||
-rw-r--r-- | services/core/java/com/android/server/MountService.java | 15 |
7 files changed, 28 insertions, 43 deletions
diff --git a/core/java/android/app/backup/BackupAgent.java b/core/java/android/app/backup/BackupAgent.java index 87d785a..1b1e600 100644 --- a/core/java/android/app/backup/BackupAgent.java +++ b/core/java/android/app/backup/BackupAgent.java @@ -105,7 +105,7 @@ import java.util.concurrent.CountDownLatch; */ public abstract class BackupAgent extends ContextWrapper { private static final String TAG = "BackupAgent"; - private static final boolean DEBUG = true; + private static final boolean DEBUG = false; /** @hide */ public static final int TYPE_EOF = 0; diff --git a/core/java/com/android/internal/widget/LockPatternUtils.java b/core/java/com/android/internal/widget/LockPatternUtils.java index d6885da..3326e42 100644 --- a/core/java/com/android/internal/widget/LockPatternUtils.java +++ b/core/java/com/android/internal/widget/LockPatternUtils.java @@ -48,6 +48,9 @@ import android.widget.Button; import com.android.internal.R; import com.google.android.collect.Lists; +import java.io.ByteArrayOutputStream; +import java.nio.charset.StandardCharsets; +import libcore.util.HexEncoding; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -359,7 +362,7 @@ public class LockPatternUtils { */ public boolean checkPasswordHistory(String password) { String passwordHashString = new String( - passwordToHash(password, getCurrentOrCallingUserId())); + passwordToHash(password, getCurrentOrCallingUserId()), StandardCharsets.UTF_8); String passwordHistory = getString(PASSWORD_HISTORY_KEY); if (passwordHistory == null) { return false; @@ -860,7 +863,7 @@ public class LockPatternUtils { passwordHistory = ""; } else { byte[] hash = passwordToHash(password, userHandle); - passwordHistory = new String(hash) + "," + passwordHistory; + passwordHistory = new String(hash, StandardCharsets.UTF_8) + "," + passwordHistory; // Cut it to contain passwordHistoryLength hashes // and passwordHistoryLength -1 commas. passwordHistory = passwordHistory.substring(0, Math.min(hash.length @@ -1040,34 +1043,30 @@ public class LockPatternUtils { * Generate a hash for the given password. To avoid brute force attacks, we use a salted hash. * Not the most secure, but it is at least a second level of protection. First level is that * the file is in a location only readable by the system process. + * * @param password the gesture pattern. + * * @return the hash of the pattern in a byte array. */ public byte[] passwordToHash(String password, int userId) { if (password == null) { return null; } - String algo = null; - byte[] hashed = null; + try { byte[] saltedPassword = (password + getSalt(userId)).getBytes(); - byte[] sha1 = MessageDigest.getInstance(algo = "SHA-1").digest(saltedPassword); - byte[] md5 = MessageDigest.getInstance(algo = "MD5").digest(saltedPassword); - hashed = (toHex(sha1) + toHex(md5)).getBytes(); - } catch (NoSuchAlgorithmException e) { - Log.w(TAG, "Failed to encode string because of missing algorithm: " + algo); - } - return hashed; - } + byte[] sha1 = MessageDigest.getInstance("SHA-1").digest(saltedPassword); + byte[] md5 = MessageDigest.getInstance("MD5").digest(saltedPassword); - private static String toHex(byte[] ary) { - final String hex = "0123456789ABCDEF"; - String ret = ""; - for (int i = 0; i < ary.length; i++) { - ret += hex.charAt((ary[i] >> 4) & 0xf); - ret += hex.charAt(ary[i] & 0xf); + byte[] combined = new byte[sha1.length + md5.length]; + System.arraycopy(sha1, 0, combined, 0, sha1.length); + System.arraycopy(md5, 0, combined, sha1.length, md5.length); + + final char[] hexEncoded = HexEncoding.encode(combined); + return new String(hexEncoded).getBytes(StandardCharsets.UTF_8); + } catch (NoSuchAlgorithmException e) { + throw new AssertionError("Missing digest algorithm: ", e); } - return ret; } /** diff --git a/media/mca/filterfw/Android.mk b/media/mca/filterfw/Android.mk index a63d635..334f4e2 100644 --- a/media/mca/filterfw/Android.mk +++ b/media/mca/filterfw/Android.mk @@ -43,10 +43,4 @@ LOCAL_SHARED_LIBRARIES := \ libjnigraphics \ libmedia -# Don't prelink this library. For more efficient code, you may want -# to add this library to the prelink map and set this to true. However, -# it's difficult to do this for applications that are not supplied as -# part of a system image. -LOCAL_PRELINK_MODULE := false - include $(BUILD_SHARED_LIBRARY) diff --git a/media/mca/filterfw/jni/Android.mk b/media/mca/filterfw/jni/Android.mk index 4ae32ac..cba4e7e 100644 --- a/media/mca/filterfw/jni/Android.mk +++ b/media/mca/filterfw/jni/Android.mk @@ -41,13 +41,6 @@ LOCAL_C_INCLUDES += \ $(JNI_H_INCLUDE) \ $(LOCAL_PATH)/.. -# Don't prelink this library. For more efficient code, you may want -# to add this library to the prelink map and set this to true. However, -# it's difficult to do this for applications that are not supplied as -# part of a system image. -LOCAL_PRELINK_MODULE := false - LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code -Wno-unused-parameter include $(BUILD_STATIC_LIBRARY) - diff --git a/media/mca/filterpacks/Android.mk b/media/mca/filterpacks/Android.mk index 7e8661f..0ff7658 100644 --- a/media/mca/filterpacks/Android.mk +++ b/media/mca/filterpacks/Android.mk @@ -48,8 +48,6 @@ LOCAL_SRC_FILES += native/imageproc/brightness.c \ LOCAL_SHARED_LIBRARIES := liblog libutils libfilterfw -LOCAL_PRELINK_MODULE := false - LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code include $(BUILD_SHARED_LIBRARY) diff --git a/rs/java/android/renderscript/RenderScript.java b/rs/java/android/renderscript/RenderScript.java index f11c408..114042d 100644 --- a/rs/java/android/renderscript/RenderScript.java +++ b/rs/java/android/renderscript/RenderScript.java @@ -1147,7 +1147,7 @@ public class RenderScript { } mRWLock = new ReentrantReadWriteLock(); try { - registerNativeAllocation.invoke(sRuntime, 4 * 1024 * 1024 * 1024); // 4MB for GC sake + registerNativeAllocation.invoke(sRuntime, 4 * 1024 * 1024); // 4MB for GC sake } catch (Exception e) { Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e); throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e); diff --git a/services/core/java/com/android/server/MountService.java b/services/core/java/com/android/server/MountService.java index 24d81a0..743db16 100644 --- a/services/core/java/com/android/server/MountService.java +++ b/services/core/java/com/android/server/MountService.java @@ -76,9 +76,8 @@ import com.android.server.pm.PackageManagerService; import com.android.server.pm.UserManagerService; import com.google.android.collect.Lists; import com.google.android.collect.Maps; +import libcore.util.HexEncoding; -import org.apache.commons.codec.binary.Hex; -import org.apache.commons.codec.DecoderException; import org.xmlpull.v1.XmlPullParserException; import java.io.File; @@ -2158,10 +2157,10 @@ class MountService extends IMountService.Stub private String toHex(String password) { if (password == null) { - return new String(); + return ""; } byte[] bytes = password.getBytes(StandardCharsets.UTF_8); - return new String(Hex.encodeHex(bytes)); + return new String(HexEncoding.encode(bytes)); } private String fromHex(String hexPassword) { @@ -2169,12 +2168,14 @@ class MountService extends IMountService.Stub return null; } + final byte[] bytes; try { - byte[] bytes = Hex.decodeHex(hexPassword.toCharArray()); - return new String(bytes, StandardCharsets.UTF_8); - } catch (DecoderException e) { + bytes = HexEncoding.decode(hexPassword.toCharArray(), false); + } catch (IllegalArgumentException e) { return null; } + + return new String(bytes, StandardCharsets.UTF_8); } @Override |