summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2016-04-28 18:14:32 +0100
committerNarayan Kamath <narayan@google.com>2016-04-29 14:01:22 +0100
commite76cbc0654d177b4102780953c353149e249c005 (patch)
treec7fed7a8c556f9c28d0de0aea18bf606276e5149
parent04b40329b2a1e393c741c86bfa5c4a96a0d21917 (diff)
downloadcts-e76cbc0654d177b4102780953c353149e249c005.tar.gz
KeyPairGeneratorTest: Add test for bug 28384942
We should be able to generate key pairs when the default locale is set to farsi (or any other locale with non arabic digits). bug: 28384942 (cherry picked from commit 5690417e9c072a1344aaf7a35d88b555e092c8db) Change-Id: Ice3484f31978e2c5aa53b9d76b61a25dd56b10e7
-rw-r--r--tests/tests/keystore/src/android/keystore/cts/KeyPairGeneratorTest.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/tests/keystore/src/android/keystore/cts/KeyPairGeneratorTest.java b/tests/tests/keystore/src/android/keystore/cts/KeyPairGeneratorTest.java
index 4c59652a93e..9dbf3f36de4 100644
--- a/tests/tests/keystore/src/android/keystore/cts/KeyPairGeneratorTest.java
+++ b/tests/tests/keystore/src/android/keystore/cts/KeyPairGeneratorTest.java
@@ -61,6 +61,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
+import java.text.DecimalFormatSymbols;
import javax.net.ssl.KeyManager;
import javax.net.ssl.SSLContext;
@@ -1138,6 +1139,32 @@ public class KeyPairGeneratorTest extends AndroidTestCase {
.build());
}
+ // http://b/28384942
+ public void testGenerateWithFarsiLocale() throws Exception {
+ Locale defaultLocale = Locale.getDefault();
+ // Note that we use farsi here because its number formatter doesn't use
+ // arabic digits.
+ Locale fa_IR = Locale.forLanguageTag("fa-IR");
+ DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(fa_IR);
+ assertFalse('0' == dfs.getZeroDigit());
+
+ Locale.setDefault(fa_IR);
+ try {
+ KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance(
+ KeyProperties.KEY_ALGORITHM_RSA, "AndroidKeyStore");
+
+ keyGenerator.initialize(new KeyGenParameterSpec.Builder(
+ TEST_ALIAS_1, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
+ .setBlockModes(KeyProperties.BLOCK_MODE_ECB)
+ .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_RSA_PKCS1)
+ .build());
+
+ keyGenerator.generateKeyPair();
+ } finally {
+ Locale.setDefault(defaultLocale);
+ }
+ }
+
private void assertKeyGenInitSucceeds(String algorithm, AlgorithmParameterSpec params)
throws Exception {
KeyPairGenerator generator = getGenerator(algorithm);