summaryrefslogtreecommitdiffstats
path: root/support/src/test/java
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2010-11-18 09:27:38 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2010-11-18 09:27:38 -0800
commit9d615f25f7576314ec6473b143b13d00ce52e805 (patch)
tree391f556a2d04c1989ff3b0c5e8689de1ad6a06d5 /support/src/test/java
parent8c22baab6e43ced1ac2f28379fbdabcfe402ad36 (diff)
parent57f2cc03ff2cf5d2f6413c5410680b4908d7301d (diff)
downloadlibcore-9d615f25f7576314ec6473b143b13d00ce52e805.zip
libcore-9d615f25f7576314ec6473b143b13d00ce52e805.tar.gz
libcore-9d615f25f7576314ec6473b143b13d00ce52e805.tar.bz2
am 57f2cc03: Test updates for Elliptic Curve
* commit '57f2cc03ff2cf5d2f6413c5410680b4908d7301d': Test updates for Elliptic Curve
Diffstat (limited to 'support/src/test/java')
-rw-r--r--support/src/test/java/libcore/java/security/StandardNames.java45
-rw-r--r--support/src/test/java/tests/security/SignatureTest.java146
2 files changed, 45 insertions, 146 deletions
diff --git a/support/src/test/java/libcore/java/security/StandardNames.java b/support/src/test/java/libcore/java/security/StandardNames.java
index 21456af..8742650 100644
--- a/support/src/test/java/libcore/java/security/StandardNames.java
+++ b/support/src/test/java/libcore/java/security/StandardNames.java
@@ -16,6 +16,7 @@
package libcore.java.security;
+import java.security.Security;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -44,6 +45,11 @@ import junit.framework.Assert;
* <a href="http://java.sun.com/javase/6/docs/technotes/guides/security/StandardNames.html">
* Java &trade; Cryptography Architecture Standard Algorithm Name Documentation
* </a>.
+ *
+ * Further updates based on the
+ * <a href=http://java.sun.com/javase/6/docs/technotes/guides/security/p11guide.html">
+ * Java &trade; PKCS#11 Reference Guide
+ * </a>.
*/
public final class StandardNames extends Assert {
@@ -219,6 +225,34 @@ public final class StandardNames extends Assert {
provide("TrustManagerFactory", "SunX509");
}
+ // Only available with the SunPKCS11-NSS provider,
+ // which seems to be enabled in OpenJDK 6 but not Oracle Java 6
+ if (Security.getProvider("SunPKCS11-NSS") != null) {
+ provide("AlgorithmParameters", "EC");
+ provide("Cipher", "AES/CBC/NOPADDING");
+ provide("Cipher", "DES/CBC/NOPADDING");
+ provide("Cipher", "DESEDE/CBC/NOPADDING");
+ provide("Cipher", "RSA/ECB/PKCS1PADDING");
+ provide("KeyAgreement", "DH");
+ provide("KeyAgreement", "ECDH");
+ provide("KeyFactory", "DH");
+ provide("KeyFactory", "EC");
+ provide("KeyPairGenerator", "DH");
+ provide("KeyPairGenerator", "EC");
+ provide("KeyStore", "PKCS11");
+ provide("MessageDigest", "SHA1");
+ provide("SecretKeyFactory", "AES");
+ provide("SecretKeyFactory", "ARCFOUR");
+ provide("SecureRandom", "PKCS11");
+ provide("Signature", "DSA");
+ provide("Signature", "NONEWITHECDSA");
+ provide("Signature", "RAWDSA");
+ provide("Signature", "SHA1WITHECDSA");
+ provide("Signature", "SHA256WITHECDSA");
+ provide("Signature", "SHA384WITHECDSA");
+ provide("Signature", "SHA512WITHECDSA");
+ }
+
// Fixups for dalvik
if (!IS_RI) {
@@ -371,6 +405,17 @@ public final class StandardNames extends Assert {
// TODO add to JDKAlgorithmParameters perhaps as wrapper on PBES2Parameters
// For now, can use AlgorithmParametersSpec javax.crypto.spec.PBEParameterSpec instead
unprovide("AlgorithmParameters", "PBEWithMD5AndDES"); // 1.2.840.113549.1.5.3
+
+ // EC support
+ // provide("AlgorithmParameters", "EC");
+ provide("KeyAgreement", "ECDH");
+ provide("KeyFactory", "EC");
+ provide("KeyPairGenerator", "EC");
+ provide("Signature", "NONEWITHECDSA");
+ provide("Signature", "ECDSA"); // as opposed to SHA1WITHECDSA
+ provide("Signature", "SHA256WITHECDSA");
+ provide("Signature", "SHA384WITHECDSA");
+ provide("Signature", "SHA512WITHECDSA");
}
}
diff --git a/support/src/test/java/tests/security/SignatureTest.java b/support/src/test/java/tests/security/SignatureTest.java
deleted file mode 100644
index c23d7ca..0000000
--- a/support/src/test/java/tests/security/SignatureTest.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package tests.security;
-
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargets;
-
-import junit.framework.TestCase;
-
-import java.security.InvalidKeyException;
-import java.security.KeyPair;
-import java.security.KeyPairGenerator;
-import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.Signature;
-import java.security.SignatureException;
-public abstract class SignatureTest extends TestCase {
-
- private final String algorithmName;
- private final String keyAlgorithmName;
- private static final String signData = "some data to sign an"; //d verify";
- KeyPairGenerator generator;
- KeyPair keyPair;
-
- public SignatureTest(String algorithmName, String keyAlgorithmName) {
- this.algorithmName = algorithmName;
- this.keyAlgorithmName = keyAlgorithmName;
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- generator = getGenerator();
- keyPair = getKeyPair();
- }
-
- private KeyPair getKeyPair() {
- return generator.generateKeyPair();
- }
-
- private KeyPairGenerator getGenerator() {
- try {
- return KeyPairGenerator.getInstance(keyAlgorithmName);
- } catch (NoSuchAlgorithmException e) {
- fail(e.getMessage());
- }
- return null;
- }
-
- @TestTargets({
- @TestTargetNew(
- level = TestLevel.ADDITIONAL,
- method = "getInstance",
- args = {String.class}
- ),
- @TestTargetNew(
- level = TestLevel.ADDITIONAL,
- method = "initSign",
- args = {PrivateKey.class}
- ),
- @TestTargetNew(
- level = TestLevel.ADDITIONAL,
- method = "update",
- args = {byte[].class}
- ),
- @TestTargetNew(
- level = TestLevel.ADDITIONAL,
- method = "sign",
- args = {}
- ),
- @TestTargetNew(
- level = TestLevel.ADDITIONAL,
- method = "initVerify",
- args = {PublicKey.class}
- ),
- @TestTargetNew(
- level = TestLevel.ADDITIONAL,
- method = "verify",
- args = {byte[].class}
- ),
- @TestTargetNew(
- level = TestLevel.COMPLETE,
- method = "method",
- args = {}
- )
- })
- public void testSignature() {
- Signature signature = null;
- try {
- signature = Signature.getInstance(algorithmName);
- } catch (NoSuchAlgorithmException e) {
- fail(e.getMessage());
- }
-
- try {
- signature.initSign(keyPair.getPrivate());
- } catch (InvalidKeyException e) {
- fail(e.getMessage());
- }
-
- try {
- signature.update(signData.getBytes());
- } catch (SignatureException e) {
- fail(e.getMessage());
- }
-
- byte[] sign = null;
- try {
- sign = signature.sign();
- } catch (SignatureException e) {
- fail(e.getMessage());
- }
-
- try {
- signature.initVerify(keyPair.getPublic());
- } catch (InvalidKeyException e) {
- fail(e.getMessage());
- }
-
- try {
- signature.update(signData.getBytes());
- } catch (SignatureException e) {
- fail(e.getMessage());
- }
-
- try {
- assertTrue(signature.verify(sign));
- } catch (SignatureException e) {
- fail(e.getMessage());
- }
- }
-}