summaryrefslogtreecommitdiffstats
path: root/keystore/tests
diff options
context:
space:
mode:
authorNick Kralevich <nnk@google.com>2010-03-09 13:28:14 -0800
committerNick Kralevich <nnk@google.com>2010-03-10 11:25:53 -0800
commit34c47c855815d731e6deb55748ff690b0ec7b53f (patch)
tree3e6a6668f093bcf88bba3bb6c8e4438a212ceea8 /keystore/tests
parent15b3287994b92bb9bff10e65a56bc8a663d0e05d (diff)
downloadframeworks_base-34c47c855815d731e6deb55748ff690b0ec7b53f.zip
frameworks_base-34c47c855815d731e6deb55748ff690b0ec7b53f.tar.gz
frameworks_base-34c47c855815d731e6deb55748ff690b0ec7b53f.tar.bz2
Don't rely on the system locale for converting to/from bytes.
By default, when java converts Strings to bytes, it uses the default system locale. This can be specified by the -Dfile.encoding option. If no file encoding is specified, java uses ISO8859_1. Unfortunately, not all unicode characters can be mapped to ISO8859_1. Unmappable characters may be replaced by a byte within ISO8859_1, which may change the meaning of the String. This is especially problematic for password strings, and has been used to compromise the security of passwords in the past. Thankfully, Android uses UTF-8 by default, so this bug doesn't effect Android devices. However, it's recommended to explicitly list the character set when converting to/from bytes to avoid the potential ambiguity. Change-Id: Iec927e27ed3fc103696c439f6bd3e8779a37ade8
Diffstat (limited to 'keystore/tests')
-rwxr-xr-xkeystore/tests/src/android/security/KeyStoreTest.java11
1 files changed, 11 insertions, 0 deletions
diff --git a/keystore/tests/src/android/security/KeyStoreTest.java b/keystore/tests/src/android/security/KeyStoreTest.java
index 569d8da..6630a4f 100755
--- a/keystore/tests/src/android/security/KeyStoreTest.java
+++ b/keystore/tests/src/android/security/KeyStoreTest.java
@@ -39,6 +39,9 @@ public class KeyStoreTest extends ActivityUnitTestCase<Activity> {
private static final String TEST_KEYNAME2 = "testkey2";
private static final String TEST_KEYVALUE = "test value";
+ // "Hello, World" in Chinese
+ private static final String TEST_I18N = "\u4F60\u597D, \u4E16\u754C";
+
private KeyStore mKeyStore = null;
public KeyStoreTest() {
@@ -83,6 +86,14 @@ public class KeyStoreTest extends ActivityUnitTestCase<Activity> {
assertTrue(mKeyStore.put(TEST_KEYNAME, TEST_KEYVALUE));
}
+ public void testI18n() throws Exception {
+ assertFalse(mKeyStore.put(TEST_I18N, TEST_I18N));
+ assertFalse(mKeyStore.contains(TEST_I18N));
+ mKeyStore.password(TEST_I18N);
+ assertTrue(mKeyStore.put(TEST_I18N, TEST_I18N));
+ assertTrue(mKeyStore.contains(TEST_I18N));
+ }
+
public void testDelete() throws Exception {
assertTrue(mKeyStore.delete(TEST_KEYNAME));
mKeyStore.password(TEST_PASSWD);