harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mloe...@apache.org
Subject svn commit: r393206 [2/2] - in /incubator/harmony/enhanced/classlib/trunk/modules/security: make/common/ src/main/java/common/java/security/ src/test/java/common/tests/api/java/security/ src/test/java/common/tests/api/java/security/spec/
Date Tue, 11 Apr 2006 12:48:35 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/KeyStoreTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/KeyStoreTest.java?rev=393206&r1=393205&r2=393206&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/KeyStoreTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/KeyStoreTest.java Tue Apr 11 05:48:33 2006
@@ -17,22 +17,16 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
 import java.io.InputStream;
 import java.security.KeyPair;
 import java.security.KeyPairGenerator;
 import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
 import java.security.PrivateKey;
 import java.security.Provider;
 import java.security.PublicKey;
 import java.security.SecureRandom;
 import java.security.Security;
 import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateException;
 import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
 import java.util.Arrays;
@@ -110,41 +104,29 @@
 	ByteArrayInputStream certArray3 = new ByteArrayInputStream(certificate3
 			.getBytes());
 
-	private byte[] creatCertificate() {
+	private byte[] creatCertificate() throws Exception {
 		ByteArrayOutputStream out = null;
-		try {
-			CertificateFactory cf = CertificateFactory.getInstance("X.509");
-			X509Certificate cert[] = new X509Certificate[2];
-			cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-			cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-			KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			keyTest.load(null, null);
-			// alias 1
-			PublicKey pub = cert[0].getPublicKey();
-			keyTest.setCertificateEntry("alias1", cert[0]);
-
-			// alias 2
-			keyTest.setCertificateEntry("alias2", cert[0]);
-			keyTest.setKeyEntry("alias2", pub, pssWord, cert);
-
-			// alias 3
-			keyTest.setCertificateEntry("alias3", cert[1]);
-
-			out = new ByteArrayOutputStream();
-			keyTest.store(out, pssWord);
-			out.close();
-
-		} catch (CertificateException e) {
-			fail("creating a certificate failed : " + e);
-		} catch (KeyStoreException e) {
-			fail("problem setting keyEntry and CertificateEntry : " + e);
-		} catch (FileNotFoundException e) {
-			fail("file not found for writing : " + e);
-		} catch (IOException e) {
-			fail("An IO problem was found when writing the keystore: " + e);
-		} catch (NoSuchAlgorithmException e) {
-			fail("The data integrity algorithm for the keystore cannot be found");
-		}
+
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+		// alias 1
+		PublicKey pub = cert[0].getPublicKey();
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		// alias 2
+		keyTest.setCertificateEntry("alias2", cert[0]);
+		keyTest.setKeyEntry("alias2", pub, pssWord, cert);
+
+		// alias 3
+		keyTest.setCertificateEntry("alias3", cert[1]);
+
+		out = new ByteArrayOutputStream();
+		keyTest.store(out, pssWord);
+		out.close();
 
 		return out.toByteArray();
 	}
@@ -152,635 +134,468 @@
 	/**
 	 * @tests java.security.KeyStore#aliases()
 	 */
-	public void test_aliases() {
+	public void test_aliases() throws Exception {
 		// Test for method java.util.Enumeration
 		// java.security.KeyStore.aliases()
 		// NOT COMPATIBLE WITH PCS#12
-		try {
-			CertificateFactory cf = CertificateFactory.getInstance("X.509");
-			X509Certificate cert[] = new X509Certificate[2];
-			cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-			cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-			KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			keyTest.load(null, null);
-
-			// KeyStore keyTest =
-			// KeyStore.getInstance(KeyStore.getDefaultType());
-			// alias 1
-			keyTest.setCertificateEntry("alias1", cert[0]);
-
-			// alias 2
-			keyTest.setCertificateEntry("alias2", cert[0]);
-
-			// alias 3
-			keyTest.setCertificateEntry("alias3", cert[0]);
-
-			// obtaining the aliase
-			Enumeration aliase = keyTest.aliases();
-			Set alia = new HashSet();
-			int i = 0;
-			while (aliase.hasMoreElements()) {
-				alia.add(aliase.nextElement());
-				i++;
-			}
-			assertTrue("the alias names were returned wrong", i == 3
-					&& alia.contains("alias1") && alia.contains("alias2")
-					&& alia.contains("alias3"));
-		} catch (CertificateException e) {
-			fail("creating a certificate failed : " + e);
-		} catch (KeyStoreException e) {
-			fail("problem with setting keyEntry and CertificateEntry : " + e);
-		} catch (IOException e) {
-			fail("IOException occurred : " + e);
-		} catch (NoSuchAlgorithmException e) {
-			fail("NoSuchAlgorithmException occurred");
-		}
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+
+		// KeyStore keyTest =
+		// KeyStore.getInstance(KeyStore.getDefaultType());
+		// alias 1
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		// alias 2
+		keyTest.setCertificateEntry("alias2", cert[0]);
+
+		// alias 3
+		keyTest.setCertificateEntry("alias3", cert[0]);
+
+		// obtaining the aliase
+		Enumeration aliase = keyTest.aliases();
+		Set alia = new HashSet();
+		int i = 0;
+		while (aliase.hasMoreElements()) {
+			alia.add(aliase.nextElement());
+			i++;
+		}
+		assertTrue("the alias names were returned wrong", i == 3
+				&& alia.contains("alias1") && alia.contains("alias2")
+				&& alia.contains("alias3"));
 	}
 
 	/**
 	 * @tests java.security.KeyStore#containsAlias(java.lang.String)
 	 */
-	public void test_containsAliasLjava_lang_String() {
+	public void test_containsAliasLjava_lang_String() throws Exception {
 		// Test for method boolean
 		// java.security.KeyStore.containsAlias(java.lang.String)
-		try {
-			CertificateFactory cf = CertificateFactory.getInstance("X.509");
-			X509Certificate cert[] = new X509Certificate[2];
-			cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-			cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-			KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			keyTest.load(null, null);
-
-			// alias 1
-			keyTest.setCertificateEntry("alias1", cert[0]);
-
-			// alias 2
-			keyTest.setCertificateEntry("alias2", cert[0]);
-
-			assertTrue("alias1 does not exist", keyTest.containsAlias("alias1"));
-			assertTrue("alias2 does not exist", keyTest.containsAlias("alias2"));
-			assertFalse("alias3 exists", keyTest.containsAlias("alias3"));
-		} catch (CertificateException e) {
-			fail("creating a certificate failed : " + e);
-		} catch (KeyStoreException e) {
-			fail("problem with setting keyEntry and CertificateEntry : " + e);
-		} catch (IOException e) {
-			fail("IOException occurred : " + e);
-		} catch (NoSuchAlgorithmException e) {
-			fail("NoSuchAlgorithmException occurred : " + e);
-		}
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+
+		// alias 1
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		// alias 2
+		keyTest.setCertificateEntry("alias2", cert[0]);
+
+		assertTrue("alias1 does not exist", keyTest.containsAlias("alias1"));
+		assertTrue("alias2 does not exist", keyTest.containsAlias("alias2"));
+		assertFalse("alias3 exists", keyTest.containsAlias("alias3"));
 	}
 
 	/**
 	 * @tests java.security.KeyStore#getCertificate(java.lang.String)
 	 */
-	public void test_getCertificateLjava_lang_String() {
+	public void test_getCertificateLjava_lang_String() throws Exception {
 		// Test for method java.security.cert.Certificate
 		// java.security.KeyStore.getCertificate(java.lang.String)
-		try {
-			CertificateFactory cf = CertificateFactory.getInstance("X.509");
-			X509Certificate cert[] = new X509Certificate[2];
-			cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-			cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-			KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			keyTest.load(null, null);
-
-			// alias 1
-			PublicKey pub = cert[0].getPublicKey();
-			keyTest.setCertificateEntry("alias1", cert[0]);
-
-			java.security.cert.Certificate certRes = keyTest
-					.getCertificate("alias1");
-			assertTrue(
-					"the public key of the certificate from getCertificate() "
-							+ "did not equal the original certificate", certRes
-							.getPublicKey() == pub);
-
-			// alias 2
-			keyTest.setCertificateEntry("alias2", cert[0]);
-
-			// testing for a certificate chain
-			java.security.cert.Certificate cert2 = keyTest
-					.getCertificate("alias2");
-			assertTrue("the certificate for alias2 is supposed to exist",
-					cert2 != null && cert2.equals(cert[0]));
-
-		} catch (KeyStoreException e) {
-			fail("keyStore is not initialized : " + e);
-		} catch (CertificateException e) {
-			fail("the certificate is not generated correctly : " + e);
-		} catch (IOException e) {
-			fail("IOException occurred : " + e);
-		} catch (NoSuchAlgorithmException e) {
-			fail("NoSuchAlgorithmException occurred " + e);
-		}
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+
+		// alias 1
+		PublicKey pub = cert[0].getPublicKey();
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		java.security.cert.Certificate certRes = keyTest
+				.getCertificate("alias1");
+		assertTrue("the public key of the certificate from getCertificate() "
+				+ "did not equal the original certificate", certRes
+				.getPublicKey() == pub);
+
+		// alias 2
+		keyTest.setCertificateEntry("alias2", cert[0]);
+
+		// testing for a certificate chain
+		java.security.cert.Certificate cert2 = keyTest.getCertificate("alias2");
+		assertTrue("the certificate for alias2 is supposed to exist",
+				cert2 != null && cert2.equals(cert[0]));
+
 	}
 
 	/**
 	 * @tests java.security.KeyStore#getCertificateAlias(java.security.cert.Certificate)
 	 */
-	public void test_getCertificateAliasLjava_security_cert_Certificate() {
+	public void test_getCertificateAliasLjava_security_cert_Certificate()
+			throws Exception {
 		// Test for method java.lang.String
 		// java.security.KeyStore.getCertificateAlias(java.security.cert.Certificate)
-		try {
-			CertificateFactory cf = CertificateFactory.getInstance("X.509");
-			X509Certificate cert[] = new X509Certificate[2];
-			cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-			cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-			KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			keyTest.load(null, null);
-
-			// certificate entry
-			keyTest.setCertificateEntry("alias1", cert[1]);
-			String alias = keyTest.getCertificateAlias(cert[1]);
-			assertTrue("certificate entry - the alias returned for this "
-					+ "certificate was wrong", alias.equals("alias1"));
-
-			// key entry
-			PublicKey pub = cert[0].getPublicKey();
-
-			// If next line throws a NPE check that a full math implementation
-			// is being used.
-			keyTest.setKeyEntry("alias2", pub, pssWord, cert);
-			alias = keyTest.getCertificateAlias(cert[0]);
-			assertTrue("key entry - the alias returned for this "
-					+ "certificate was wrong", alias.equals("alias2"));
-
-			// testing case with a nonexistant certificate
-			X509Certificate cert2 = (X509Certificate) cf
-					.generateCertificate(certArray3);
-			String aliasNull = keyTest.getCertificateAlias(cert2);
-			assertNull("the alias returned for the nonexist certificate "
-					+ "was NOT null", aliasNull);
-		} catch (KeyStoreException e) {
-			fail("unexpected keyStore exception : " + e);
-		} catch (CertificateException e) {
-			fail("the certificate is not generated correctly : " + e);
-		} catch (IOException e) {
-			fail("IOException occurred : " + e);
-		} catch (NoSuchAlgorithmException e) {
-			fail("NoSuchAlgorithmException occurred : " + e);
-		}
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+
+		// certificate entry
+		keyTest.setCertificateEntry("alias1", cert[1]);
+		String alias = keyTest.getCertificateAlias(cert[1]);
+		assertTrue("certificate entry - the alias returned for this "
+				+ "certificate was wrong", alias.equals("alias1"));
+
+		// key entry
+		PublicKey pub = cert[0].getPublicKey();
+
+		// If next line throws a NPE check that a full math implementation
+		// is being used.
+		keyTest.setKeyEntry("alias2", pub, pssWord, cert);
+		alias = keyTest.getCertificateAlias(cert[0]);
+		assertTrue("key entry - the alias returned for this "
+				+ "certificate was wrong", alias.equals("alias2"));
+
+		// testing case with a nonexistant certificate
+		X509Certificate cert2 = (X509Certificate) cf
+				.generateCertificate(certArray3);
+		String aliasNull = keyTest.getCertificateAlias(cert2);
+		assertNull("the alias returned for the nonexist certificate "
+				+ "was NOT null", aliasNull);
 	}
 
 	/**
 	 * @tests java.security.KeyStore#getCertificateChain(java.lang.String)
 	 */
-	public void test_getCertificateChainLjava_lang_String() {
+	public void test_getCertificateChainLjava_lang_String() throws Exception {
 		// Test for method java.security.cert.Certificate []
 		// java.security.KeyStore.getCertificateChain(java.lang.String)
-		try {
-			// creatCertificate();
-			CertificateFactory cf = CertificateFactory.getInstance("X.509");
-			X509Certificate cert[] = new X509Certificate[2];
-			cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-			cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-			KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			keyTest.load(null, null);
-
-			// alias 1
-			PublicKey pub = cert[0].getPublicKey();
-			keyTest.setCertificateEntry("alias1", cert[0]);
-
-			// alias 2
-			keyTest.setCertificateEntry("alias2", cert[0]);
-			keyTest.setKeyEntry("alias2", pub, pssWord, cert);
-
-			java.security.cert.Certificate[] certRes = keyTest
-					.getCertificateChain("alias2");
-			assertTrue("there are more than two certificate returned "
-					+ "from getCertificateChain", certRes.length == 2);
-			assertTrue("the certificates returned from getCertificateChain "
-					+ "is not correct", cert[0].getPublicKey() == certRes[0]
-					.getPublicKey()
-					&& cert[1].getPublicKey() == certRes[1].getPublicKey());
-			java.security.cert.Certificate[] certResNull = keyTest
-					.getCertificateChain("alias1");
-			assertTrue("the certificate chain returned from "
-					+ "getCertificateChain is NOT null", certResNull == null);
-		} catch (KeyStoreException e) {
-			fail("keyStore is not initialized : " + e);
-		} catch (CertificateException e) {
-			fail("the certificate is not generated correctly : " + e);
-		} catch (IOException e) {
-			fail("IOException occurred : " + e);
-		} catch (NoSuchAlgorithmException e) {
-			fail("NoSuchAlgorithmException occurred : " + e);
-		}
+		// creatCertificate();
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+
+		// alias 1
+		PublicKey pub = cert[0].getPublicKey();
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		// alias 2
+		keyTest.setCertificateEntry("alias2", cert[0]);
+		keyTest.setKeyEntry("alias2", pub, pssWord, cert);
+
+		java.security.cert.Certificate[] certRes = keyTest
+				.getCertificateChain("alias2");
+		assertTrue("there are more than two certificate returned "
+				+ "from getCertificateChain", certRes.length == 2);
+		assertTrue("the certificates returned from getCertificateChain "
+				+ "is not correct", cert[0].getPublicKey() == certRes[0]
+				.getPublicKey()
+				&& cert[1].getPublicKey() == certRes[1].getPublicKey());
+		java.security.cert.Certificate[] certResNull = keyTest
+				.getCertificateChain("alias1");
+		assertTrue("the certificate chain returned from "
+				+ "getCertificateChain is NOT null", certResNull == null);
 	}
 
 	/**
 	 * @tests java.security.KeyStore#getInstance(java.lang.String)
 	 */
-	public void test_getInstanceLjava_lang_String() {
+	public void test_getInstanceLjava_lang_String() throws Exception {
 		// Test for method java.security.KeyStore
 		// java.security.KeyStore.getInstance(java.lang.String)
-		try {
-			KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			assertTrue("the method getInstance did not obtain "
-					+ "the correct type", keyTest.getType().equals(
-					KeyStore.getDefaultType()));
-		} catch (KeyStoreException e) {
-			fail("keyStore is not loaded : " + e);
-		}
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		assertTrue("the method getInstance did not obtain "
+				+ "the correct type", keyTest.getType().equals(
+				KeyStore.getDefaultType()));
 	}
 
 	/**
 	 * @tests java.security.KeyStore#getInstance(java.lang.String,
 	 *        java.lang.String)
 	 */
-	public void test_getInstanceLjava_lang_StringLjava_lang_String() {
+	public void test_getInstanceLjava_lang_StringLjava_lang_String()
+			throws Exception {
 		// Test for method java.security.KeyStore
 		// java.security.KeyStore.getInstance(java.lang.String,
 		// java.lang.String)
-		try {
-			KeyStore keyTest = KeyStore.getInstance("PKCS#12/Netscape",
-					"TestProvider");
-			assertTrue("the method getInstance did not obtain the "
-					+ "correct provider and type", keyTest.getProvider()
-					.getName().equals("TestProvider")
-					&& keyTest.getType().equals("PKCS#12/Netscape"));
-		} catch (KeyStoreException e) {
-			fail("keyStore is not loaded : " + e);
-		} catch (NoSuchProviderException e) {
-			fail("no such provider : " + e);
-		}
+		KeyStore keyTest = KeyStore.getInstance("PKCS#12/Netscape",
+				"TestProvider");
+		assertTrue("the method getInstance did not obtain the "
+				+ "correct provider and type", keyTest.getProvider().getName()
+				.equals("TestProvider")
+				&& keyTest.getType().equals("PKCS#12/Netscape"));
 	}
 
 	/**
 	 * @tests java.security.KeyStore#getKey(java.lang.String, char[])
 	 */
-	public void test_getKeyLjava_lang_String$C() {
-
-		fail("Test hangs - requires a full math implementation ??");
+	public void test_getKeyLjava_lang_String$C() throws Exception {
 
 		// Test for method java.security.Key
 		// java.security.KeyStore.getKey(java.lang.String, char [])
+		// creatCertificate();
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+		KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DSA");
+		SecureRandom secureRandom = new SecureRandom();
+		keyPairGenerator.initialize(1024, secureRandom);
+		KeyPair keyPair = keyPairGenerator.genKeyPair();
+		PrivateKey privateKey = keyPair.getPrivate();
+		keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
+		PrivateKey returnedKey = (PrivateKey) keyTest.getKey("alias2", pssWord);
+		byte[] retB = returnedKey.getEncoded();
+		byte[] priB = privateKey.getEncoded();
+		boolean equality = Arrays.equals(retB, priB);
+		equality &= returnedKey.getAlgorithm()
+				.equals(privateKey.getAlgorithm());
+		equality &= returnedKey.getFormat().equals(privateKey.getFormat());
+		assertTrue("the private key returned from getKey for a "
+				+ "key entry did not equal the original key", equality);
+
 		try {
-			// creatCertificate();
-			CertificateFactory cf = CertificateFactory.getInstance("X.509");
-			X509Certificate cert[] = new X509Certificate[2];
-			cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-			cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-			KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			keyTest.load(null, null);
-			KeyPairGenerator keyPairGenerator = KeyPairGenerator
-					.getInstance("DSA");
-			SecureRandom secureRandom = new SecureRandom();
-			keyPairGenerator.initialize(1024, secureRandom);
-			KeyPair keyPair = keyPairGenerator.genKeyPair();
-			PrivateKey privateKey = keyPair.getPrivate();
-			keyTest.setKeyEntry("alias2", privateKey, pssWord, cert);
-			PrivateKey returnedKey = (PrivateKey) keyTest.getKey("alias2",
-					pssWord);
-			byte[] retB = returnedKey.getEncoded();
-			byte[] priB = privateKey.getEncoded();
-			boolean equality = Arrays.equals(retB, priB);
-			equality &= returnedKey.getAlgorithm().equals(
-					privateKey.getAlgorithm());
-			equality &= returnedKey.getFormat().equals(privateKey.getFormat());
-			assertTrue("the private key returned from getKey for a "
-					+ "key entry did not equal the original key", equality);
-
-			try {
-				keyTest.getKey("alias2", "wrong".toCharArray());
-				fail("Should have thrown UnrecoverableKeyException");
-			} catch (UnrecoverableKeyException e) {
-				// expected
-			}
-
-			keyTest.setCertificateEntry("alias1", cert[1]);
-			assertNull("the private key returned from getKey for "
-					+ "a certificate entry is not null", keyTest.getKey(
-					"alias1", pssWord));
-
-		} catch (KeyStoreException e) {
-			fail("type is not found : " + e);
-		} catch (NoSuchAlgorithmException e) {
-			fail("algorithm to recover the key cannot be found " + e);
+			keyTest.getKey("alias2", "wrong".toCharArray());
+			fail("Should have thrown UnrecoverableKeyException");
 		} catch (UnrecoverableKeyException e) {
-			fail("the key can't be recovered : " + e);
-		} catch (CertificateException e) {
-			fail("the certificate is not generated correctly : " + e);
-		} catch (IOException e) {
-			fail("IOException occurred : " + e);
+			// expected
 		}
+
+		keyTest.setCertificateEntry("alias1", cert[1]);
+		assertNull("the private key returned from getKey for "
+				+ "a certificate entry is not null", keyTest.getKey("alias1",
+				pssWord));
 	}
 
 	/**
 	 * @tests java.security.KeyStore#getProvider()
 	 */
-	public void test_getProvider() {
+	public void test_getProvider() throws Exception {
 		// Test for method java.security.Provider
 		// java.security.KeyStore.getProvider()
-		try {
-			KeyStore keyTest = KeyStore.getInstance("PKCS#12/Netscape",
-					"TestProvider");
-			Provider provKeyStore = keyTest.getProvider();
-			assertEquals("the provider should be TestProvider", "TestProvider",
-					provKeyStore.getName());
-		} catch (KeyStoreException e) {
-			fail("type is not found : " + e);
-		} catch (NoSuchProviderException e) {
-			fail("no such provider : " + e);
-		}
+		KeyStore keyTest = KeyStore.getInstance("PKCS#12/Netscape",
+				"TestProvider");
+		Provider provKeyStore = keyTest.getProvider();
+		assertEquals("the provider should be TestProvider", "TestProvider",
+				provKeyStore.getName());
 	}
 
 	/**
 	 * @tests java.security.KeyStore#getType()
 	 */
-	public void test_getType() {
+	public void test_getType() throws Exception {
 		// Test for method java.lang.String java.security.KeyStore.getType()
-		try {
-			KeyStore keyTest = KeyStore.getInstance("PKCS#12/Netscape",
-					"TestProvider");
-			assertEquals(
-					"type should be PKCS#12/Netscape for provider TestProvider",
-					"PKCS#12/Netscape", keyTest.getType());
-		} catch (KeyStoreException e) {
-			fail("type is not found : " + e);
-		} catch (NoSuchProviderException e) {
-			fail("no such provider : " + e);
-		}
+		KeyStore keyTest = KeyStore.getInstance("PKCS#12/Netscape",
+				"TestProvider");
+		assertEquals(
+				"type should be PKCS#12/Netscape for provider TestProvider",
+				"PKCS#12/Netscape", keyTest.getType());
 	}
 
 	/**
 	 * @tests java.security.KeyStore#isCertificateEntry(java.lang.String)
 	 */
-	public void test_isCertificateEntryLjava_lang_String() {
+	public void test_isCertificateEntryLjava_lang_String() throws Exception {
 		// Test for method boolean
 		// java.security.KeyStore.isCertificateEntry(java.lang.String)
-		try {
-			CertificateFactory cf = CertificateFactory.getInstance("X.509");
-			X509Certificate cert[] = new X509Certificate[2];
-			cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-			cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-			KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			keyTest.load(null, null);
-			// alias 1
-			PublicKey pub = cert[0].getPublicKey();
-			keyTest.setCertificateEntry("alias1", cert[0]);
-
-			// alias 2
-			keyTest.setCertificateEntry("alias2", cert[0]);
-			keyTest.setKeyEntry("alias2", pub, pssWord, cert);
-
-			assertTrue(
-					"isCertificateEntry method returns false for a certificate",
-					keyTest.isCertificateEntry("alias1") == true);
-			assertTrue(
-					"isCertificateEntry method returns true for noncertificate",
-					keyTest.isCertificateEntry("alias2") == false);
-		} catch (KeyStoreException e) {
-			fail("alias already exists for an untrusted certificate : " + e);
-		} catch (CertificateException e) {
-			fail("creating a certificate failed : " + e);
-		} catch (IOException e) {
-			fail("IOException occurred : " + e);
-		} catch (NoSuchAlgorithmException e) {
-			fail("NoSuchAlgorithmException occurred : " + e);
-		}
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+		// alias 1
+		PublicKey pub = cert[0].getPublicKey();
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		// alias 2
+		keyTest.setCertificateEntry("alias2", cert[0]);
+		keyTest.setKeyEntry("alias2", pub, pssWord, cert);
+
+		assertTrue("isCertificateEntry method returns false for a certificate",
+				keyTest.isCertificateEntry("alias1") == true);
+		assertTrue("isCertificateEntry method returns true for noncertificate",
+				keyTest.isCertificateEntry("alias2") == false);
 	}
 
 	/**
 	 * @tests java.security.KeyStore#isKeyEntry(java.lang.String)
 	 */
-	public void test_isKeyEntryLjava_lang_String() {
+	public void test_isKeyEntryLjava_lang_String() throws Exception {
 		// Test for method boolean
 		// java.security.KeyStore.isKeyEntry(java.lang.String)
-		try {
-			CertificateFactory cf = CertificateFactory.getInstance("X.509");
-			X509Certificate cert[] = new X509Certificate[2];
-			cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-			cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-			KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			keyTest.load(null, null);
-			// alias 1
-			PublicKey pub = cert[0].getPublicKey();
-			keyTest.setCertificateEntry("alias1", cert[0]);
-
-			// alias 2
-			keyTest.setCertificateEntry("alias2", cert[0]);
-			keyTest.setKeyEntry("alias2", pub, pssWord, cert);
-
-			assertTrue("isKeyEntry method returns false for a certificate",
-					keyTest.isKeyEntry("alias2") == true);
-			assertTrue("isKeyEntry method returns true for noncertificate",
-					keyTest.isKeyEntry("alias1") == false);
-		} catch (KeyStoreException e) {
-			fail("alias already exists for an untrusted certificate : " + e);
-		} catch (CertificateException e) {
-			fail("creating a certificate failed : " + e);
-		} catch (IOException e) {
-			fail("IOException occurred : " + e);
-		} catch (NoSuchAlgorithmException e) {
-			fail("NoSuchAlgorithmException occurred : " + e);
-		}
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+		// alias 1
+		PublicKey pub = cert[0].getPublicKey();
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		// alias 2
+		keyTest.setCertificateEntry("alias2", cert[0]);
+		keyTest.setKeyEntry("alias2", pub, pssWord, cert);
+
+		assertTrue("isKeyEntry method returns false for a certificate", keyTest
+				.isKeyEntry("alias2") == true);
+		assertTrue("isKeyEntry method returns true for noncertificate", keyTest
+				.isKeyEntry("alias1") == false);
 	}
 
 	/**
 	 * @tests java.security.KeyStore#load(java.io.InputStream, char[])
 	 */
-	public void test_loadLjava_io_InputStream$C() {
+	public void test_loadLjava_io_InputStream$C() throws Exception {
 		// Test for method void java.security.KeyStore.load(java.io.InputStream,
 		// char [])
-		try {
-			byte[] keyStore = creatCertificate();
-			KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			InputStream in = new ByteArrayInputStream(keyStore);
-			keyTest.load(in, pssWord);
-			in.close();
-			assertTrue("alias1 is not a certificate", keyTest
-					.isCertificateEntry("alias1") == true);
-			assertTrue("alias2 is not a keyEntry",
-					keyTest.isKeyEntry("alias2") == true);
-			assertTrue("alias3 is not a certificate", keyTest
-					.isCertificateEntry("alias3") == true);
-
-			// test with null password
-			keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			in = new ByteArrayInputStream(keyStore);
-			keyTest.load(in, null);
-			in.close();
-			assertTrue("alias1 is not a certificate", keyTest
-					.isCertificateEntry("alias1") == true);
-			assertTrue("alias2 is not a keyEntry",
-					keyTest.isKeyEntry("alias2") == true);
-			assertTrue("alias3 is not a certificate", keyTest
-					.isCertificateEntry("alias3") == true);
-
-			keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			InputStream v1in = Support_Resources.getStream("hyts_ks.bks");
-			char[] pass = "abcdef".toCharArray();
-			keyTest.load(v1in, pass);
-			v1in.close();
-			keyTest.getKey("mykey", pass);
-		} catch (UnrecoverableKeyException e) {
-			fail("Caught an UnrecoverableKeyException : " + e);
-		} catch (KeyStoreException e) {
-			fail("alias already exists for an untrusted certificate : " + e);
-		} catch (CertificateException e) {
-			fail("creating a certificate failed : " + e);
-		} catch (IOException e) {
-			e.printStackTrace();
-			fail("An IO problem was found when reading the keystore : " + e);
-		} catch (NoSuchAlgorithmException e) {
-			fail("The data integrity algorithm for the keystore "
-					+ "cannot be found : " + e);
-		}
+		byte[] keyStore = creatCertificate();
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		InputStream in = new ByteArrayInputStream(keyStore);
+		keyTest.load(in, pssWord);
+		in.close();
+		assertTrue("alias1 is not a certificate", keyTest
+				.isCertificateEntry("alias1") == true);
+		assertTrue("alias2 is not a keyEntry",
+				keyTest.isKeyEntry("alias2") == true);
+		assertTrue("alias3 is not a certificate", keyTest
+				.isCertificateEntry("alias3") == true);
+
+		// test with null password
+		keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		in = new ByteArrayInputStream(keyStore);
+		keyTest.load(in, null);
+		in.close();
+		assertTrue("alias1 is not a certificate", keyTest
+				.isCertificateEntry("alias1") == true);
+		assertTrue("alias2 is not a keyEntry",
+				keyTest.isKeyEntry("alias2") == true);
+		assertTrue("alias3 is not a certificate", keyTest
+				.isCertificateEntry("alias3") == true);
+
+		keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		InputStream v1in = Support_Resources.getStream("hyts_ks.bks");
+		char[] pass = "abcdef".toCharArray();
+		keyTest.load(v1in, pass);
+		v1in.close();
+		keyTest.getKey("mykey", pass);
 	}
 
 	/**
 	 * @tests java.security.KeyStore#setCertificateEntry(java.lang.String,
 	 *        java.security.cert.Certificate)
 	 */
-	public void test_setCertificateEntryLjava_lang_StringLjava_security_cert_Certificate() {
+	public void test_setCertificateEntryLjava_lang_StringLjava_security_cert_Certificate()
+			throws Exception {
 		// Test for method void
 		// java.security.KeyStore.setCertificateEntry(java.lang.String,
 		// java.security.cert.Certificate)
-		try {
-			CertificateFactory cf = CertificateFactory.getInstance("X.509");
-			X509Certificate cert = (X509Certificate) cf
-					.generateCertificate(certArray);
-			KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			keyTest.load(null, null);
-
-			PublicKey pub = cert.getPublicKey();
-			keyTest.setCertificateEntry("alias1", cert);
-			assertTrue(
-					"the entry specified by the alias alias1 is not a certificate",
-					keyTest.isCertificateEntry("alias1") == true);
-			java.security.cert.Certificate resultCert = keyTest
-					.getCertificate("alias1");
-			assertTrue(
-					"the public key of the certificate from getCertificate() did not equal the original certificate",
-					resultCert.getPublicKey() == pub);
-		} catch (KeyStoreException e) {
-			fail("alias already exists for an untrusted certificate : " + e);
-		} catch (CertificateException e) {
-			fail("creating a certificate failed : " + e);
-		} catch (IOException e) {
-			fail("IOException occurred : " + e);
-		} catch (NoSuchAlgorithmException e) {
-			fail("NoSuchAlgorithmException occurred : " + e);
-		}
-
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert = (X509Certificate) cf
+				.generateCertificate(certArray);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+
+		PublicKey pub = cert.getPublicKey();
+		keyTest.setCertificateEntry("alias1", cert);
+		assertTrue(
+				"the entry specified by the alias alias1 is not a certificate",
+				keyTest.isCertificateEntry("alias1") == true);
+		java.security.cert.Certificate resultCert = keyTest
+				.getCertificate("alias1");
+		assertTrue(
+				"the public key of the certificate from getCertificate() did not equal the original certificate",
+				resultCert.getPublicKey() == pub);
 	}
 
 	/**
 	 * @tests java.security.KeyStore#setKeyEntry(java.lang.String, byte[],
 	 *        java.security.cert.Certificate[])
 	 */
-	public void test_setKeyEntryLjava_lang_String$B$Ljava_security_cert_Certificate() {
+	public void test_setKeyEntryLjava_lang_String$B$Ljava_security_cert_Certificate()
+			throws Exception {
 
 		fail("Test hangs - requires a full math implementation ??");
 
 		// Test for method void
 		// java.security.KeyStore.setKeyEntry(java.lang.String, byte [],
 		// java.security.cert.Certificate [])
-		try {
-			CertificateFactory cf = CertificateFactory.getInstance("X.509");
-			X509Certificate cert[] = new X509Certificate[2];
-			cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-			cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-			KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			keyTest.load(null, null);
-			// generator
-			KeyPairGenerator keyPairGenerator = KeyPairGenerator
-					.getInstance("DSA");
-			SecureRandom secureRandom = new SecureRandom();
-			keyPairGenerator.initialize(1024, secureRandom);
-			KeyPair keyPair = keyPairGenerator.genKeyPair();
-			// set the same alias as keyEntry
-			keyTest.setKeyEntry("alias2", keyPair.getPrivate().getEncoded(),
-					cert);
-			assertTrue(
-					"the entry specified by the alias alias2 is not a keyEntry",
-					keyTest.isKeyEntry("alias2"));
-		} catch (KeyStoreException e) {
-			fail("Setting keyEntry for the alias failed : " + e);
-		} catch (CertificateException e) {
-			fail("creating a certificate failed : " + e);
-		} catch (IOException e) {
-			fail("IOException occurred : " + e);
-		} catch (NoSuchAlgorithmException e) {
-			fail("NoSuchAlgorithmException occurred : " + e);
-		}
+
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+		// generator
+		KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DSA");
+		SecureRandom secureRandom = new SecureRandom();
+		keyPairGenerator.initialize(1024, secureRandom);
+		KeyPair keyPair = keyPairGenerator.genKeyPair();
+		// set the same alias as keyEntry
+		keyTest.setKeyEntry("alias2", keyPair.getPrivate().getEncoded(), cert);
+		assertTrue("the entry specified by the alias alias2 is not a keyEntry",
+				keyTest.isKeyEntry("alias2"));
 	}
 
 	/**
 	 * @tests java.security.KeyStore#setKeyEntry(java.lang.String,
 	 *        java.security.Key, char[], java.security.cert.Certificate[])
 	 */
-	public void test_setKeyEntryLjava_lang_StringLjava_security_Key$C$Ljava_security_cert_Certificate() {
-
-		fail("Test hangs - requires a full math implementation ??");
+	public void test_setKeyEntryLjava_lang_StringLjava_security_Key$C$Ljava_security_cert_Certificate()
+			throws Exception {
 
 		// Test for method void
 		// java.security.KeyStore.setKeyEntry(java.lang.String,
 		// java.security.Key, char [], java.security.cert.Certificate [])
-		try {
-			CertificateFactory cf = CertificateFactory.getInstance("X.509");
-			X509Certificate cert[] = new X509Certificate[2];
-			cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-			cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-			KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			keyTest.load(null, null);
-			// generator
-			KeyPairGenerator keyPairGenerator = KeyPairGenerator
-					.getInstance("DSA");
-			SecureRandom secureRandom = new SecureRandom();
-			keyPairGenerator.initialize(1024, secureRandom);
-			KeyPair keyPair = keyPairGenerator.genKeyPair();
-			PrivateKey privateKey = keyPair.getPrivate();
-			keyTest.setKeyEntry("alias3", privateKey, pssWord, cert);
-			assertTrue(
-					"the entry specified by the alias alias3 is not a keyEntry",
-					keyTest.isKeyEntry("alias3"));
-		} catch (KeyStoreException e) {
-			fail("Setting keyEntry for the alias failed : " + e);
-		} catch (CertificateException e) {
-			fail("creating a certificate failed : " + e);
-		} catch (IOException e) {
-			fail("IOException occurred : " + e);
-		} catch (NoSuchAlgorithmException e) {
-			fail("NoSuchAlgorithmException occurred : " + e);
-		}
+
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+		// generator
+		KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DSA");
+		SecureRandom secureRandom = new SecureRandom();
+		keyPairGenerator.initialize(1024, secureRandom);
+		KeyPair keyPair = keyPairGenerator.genKeyPair();
+		PrivateKey privateKey = keyPair.getPrivate();
+		keyTest.setKeyEntry("alias3", privateKey, pssWord, cert);
+		assertTrue("the entry specified by the alias alias3 is not a keyEntry",
+				keyTest.isKeyEntry("alias3"));
 	}
 
 	/**
 	 * @tests java.security.KeyStore#size()
 	 */
-	public void test_size() {
+	public void test_size() throws Exception {
 		// Test for method int java.security.KeyStore.size()
-		try {
-			CertificateFactory cf = CertificateFactory.getInstance("X.509");
-			X509Certificate cert[] = new X509Certificate[2];
-			cert[0] = (X509Certificate) cf.generateCertificate(certArray);
-			cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
-			KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
-			keyTest.load(null, null);
-			// alias 1
-			PublicKey pub = cert[0].getPublicKey();
-			keyTest.setCertificateEntry("alias1", cert[0]);
-
-			// alias 2
-			keyTest.setCertificateEntry("alias2", cert[0]);
-			keyTest.setKeyEntry("alias2", pub, pssWord, cert);
-
-			// alias 3
-			keyTest.setCertificateEntry("alias3", cert[1]);
-
-			assertTrue("the size of the keyStore is not 3", keyTest.size() == 3);
-		} catch (KeyStoreException e) {
-			fail("alias already exists for an untrusted certificate : " + e);
-		} catch (CertificateException e) {
-			fail("creating a certificate failed : " + e);
-		} catch (IOException e) {
-			fail("IOException occurred : " + e);
-		} catch (NoSuchAlgorithmException e) {
-			fail("NoSuchAlgorithmException occurred : " + e);
-		}
+
+		CertificateFactory cf = CertificateFactory.getInstance("X.509");
+		X509Certificate cert[] = new X509Certificate[2];
+		cert[0] = (X509Certificate) cf.generateCertificate(certArray);
+		cert[1] = (X509Certificate) cf.generateCertificate(certArray2);
+		KeyStore keyTest = KeyStore.getInstance(KeyStore.getDefaultType());
+		keyTest.load(null, null);
+		// alias 1
+		PublicKey pub = cert[0].getPublicKey();
+		keyTest.setCertificateEntry("alias1", cert[0]);
+
+		// alias 2
+		keyTest.setCertificateEntry("alias2", cert[0]);
+		keyTest.setKeyEntry("alias2", pub, pssWord, cert);
+
+		// alias 3
+		keyTest.setCertificateEntry("alias3", cert[1]);
+
+		assertTrue("the size of the keyStore is not 3", keyTest.size() == 3);
 	}
 
 	/**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SecureRandomTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SecureRandomTest.java?rev=393206&r1=393205&r2=393206&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SecureRandomTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SecureRandomTest.java Tue Apr 11 05:48:33 2006
@@ -103,16 +103,6 @@
 	}
 
 	/**
-	 * @tests java.security.SecureRandom#getProvider()
-	 */
-	public void test_getProvider() {
-		// Test for method java.security.Provider
-		// java.security.SecureRandom.getProvider()
-		Provider p = new SecureRandom().getProvider();
-		assertNotNull("SecureRandom provider is null", p);
-	}
-
-	/**
 	 * @tests java.security.SecureRandom#getSeed(int)
 	 */
 	public void test_getSeedI() {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SignatureTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SignatureTest.java?rev=393206&r1=393205&r2=393206&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SignatureTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SignatureTest.java Tue Apr 11 05:48:33 2006
@@ -16,17 +16,13 @@
 package tests.api.java.security;
 
 import java.math.BigInteger;
-import java.security.InvalidKeyException;
 import java.security.InvalidParameterException;
 import java.security.KeyPair;
 import java.security.KeyPairGenerator;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
 import java.security.Provider;
 import java.security.SecureRandom;
 import java.security.Security;
 import java.security.Signature;
-import java.security.SignatureException;
 import java.security.spec.DSAParameterSpec;
 
 public class SignatureTest extends junit.framework.TestCase {
@@ -36,170 +32,101 @@
 	/**
 	 * @tests java.security.Signature#clone()
 	 */
-	public void test_clone() {
-		try {
-			Signature s = Signature.getInstance("DSA");
-			try {
-				s.clone();
-				fail("A Signature may not be cloneable");
-			} catch (CloneNotSupportedException e) {
-				// Expected - a Signature may not be cloneable
-			}
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm");
-		}
+	public void test_clone() throws Exception {
+       		Signature s = Signature.getInstance("DSA");
+       		try {
+       			s.clone();
+       			fail("A Signature may not be cloneable");
+       		} catch (CloneNotSupportedException e) {
+       			// Expected - a Signature may not be cloneable
+       		}
 	}
 
 	/**
 	 * @tests java.security.Signature#getAlgorithm()
 	 */
-	public void test_getAlgorithm() {
-		try {
-			String alg = Signature.getInstance("DSA").getAlgorithm();
-			assertTrue("getAlgorithm did not get DSA (" + alg + ")", alg
-					.indexOf("DSA") != -1);
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm");
-		}
+	public void test_getAlgorithm() throws Exception {
+       		String alg = Signature.getInstance("DSA").getAlgorithm();
+       		assertTrue("getAlgorithm did not get DSA (" + alg + ")", alg
+       				.indexOf("DSA") != -1);
 	}
 
 	/**
 	 * @tests java.security.Signature#getInstance(java.lang.String)
 	 */
-	public void test_getInstanceLjava_lang_String() {
-		try {
-			Signature.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm");
-		}
+	public void test_getInstanceLjava_lang_String() throws Exception {
+		Signature.getInstance("DSA");
 	}
 
 	/**
 	 * @tests java.security.Signature#getInstance(java.lang.String,
 	 *        java.lang.String)
 	 */
-	public void test_getInstanceLjava_lang_StringLjava_lang_String() {
-		try {
-			Provider[] providers = Security.getProviders("Signature.DSA");
-			assertNotNull("No providers support Signature.DSA", providers);
-			for (int i = 0; i < providers.length; i++) {
-				Signature.getInstance("DSA", providers[i].getName());
-			}// end for
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		} catch (NoSuchProviderException e) {
-			fail("getInstance did not find named provider : " + e);
-		}
+	public void test_getInstanceLjava_lang_StringLjava_lang_String() throws Exception {
+       		Provider[] providers = Security.getProviders("Signature.DSA");
+
+       		for (int i = 0; i < providers.length; i++) {
+       			Signature.getInstance("DSA", providers[i].getName());
+       		}// end for
 	}
 
 	/**
 	 * @tests java.security.Signature#getParameter(java.lang.String)
 	 */
-	public void test_getParameterLjava_lang_String() {
-		Signature sig = null;
-		try {
-			sig = Signature.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
+	public void test_getParameterLjava_lang_String() throws Exception {
+		Signature sig = Signature.getInstance("DSA");
 
-		boolean passed = false;
 		try {
 			sig.getParameter("r");
 			sig.getParameter("s");
-			passed = true;
 		} catch (UnsupportedOperationException e) {
-			passed = true;
-		} catch (Exception e) {
-			passed = false;
 		}
-		assertTrue("getParameter did not pass or threw incorrect exception",
-				passed);
 	}
 
 	/**
 	 * @tests java.security.Signature#getProvider()
 	 */
-	public void test_getProvider() {
-		try {
-			Provider p = Signature.getInstance("DSA").getProvider();
-			assertNotNull("provider is null", p);
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
+	public void test_getProvider() throws Exception {
+       		Provider p = Signature.getInstance("DSA").getProvider();
+       		assertNotNull("provider is null", p);
 	}
 
 	/**
 	 * @tests java.security.Signature#initSign(java.security.PrivateKey)
 	 */
-	public void test_initSignLjava_security_PrivateKey() {
+	public void test_initSignLjava_security_PrivateKey() throws Exception {
 
-		fail("Test hangs - dependent on full math implementation ??");
+		Signature sig = Signature.getInstance("DSA");
 
-		Signature sig = null;
-		try {
-			sig = Signature.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
+		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
 
-		KeyPairGenerator keyGen = null;
-		try {
-			keyGen = KeyPairGenerator.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
 		SecureRandom random = new SecureRandom();
 		keyGen.initialize(1024, random);
 		KeyPair keys = keyGen.generateKeyPair();
-		try {
-			sig.initSign(keys.getPrivate());
-		} catch (InvalidKeyException e) {
-			fail("Invalid key : " + e);
-		}
+
+		sig.initSign(keys.getPrivate());
 	}
 
 	/**
 	 * @tests java.security.Signature#initVerify(java.security.PublicKey)
 	 */
-	public void test_initVerifyLjava_security_PublicKey() {
-
-		fail("Test hangs - dependent on full math implementation ??");
+	public void test_initVerifyLjava_security_PublicKey() throws Exception {
 
-		Signature sig = null;
-		try {
-			sig = Signature.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
+		Signature sig = Signature.getInstance("DSA");
 
-		KeyPairGenerator keyGen = null;
-		try {
-			keyGen = KeyPairGenerator.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
+		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
 		SecureRandom random = new SecureRandom();
 		keyGen.initialize(1024, random);
 		KeyPair keys = keyGen.generateKeyPair();
-		try {
-			sig.initVerify(keys.getPublic());
-		} catch (InvalidKeyException e) {
-			fail("Invalid key : " + e);
-		}
+		sig.initVerify(keys.getPublic());
 	}
 
 	/**
 	 * @tests java.security.Signature#setParameter(java.lang.String,
 	 *        java.lang.Object)
 	 */
-	public void test_setParameterLjava_lang_StringLjava_lang_Object() {
-		Signature sig = null;
-		try {
-			sig = Signature.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
+	public void test_setParameterLjava_lang_StringLjava_lang_Object() throws Exception {
+		Signature sig = Signature.getInstance("DSA");
 
 		try {
 			sig.setParameter("r", BigInteger.ONE);
@@ -208,22 +135,15 @@
 			// Could be that it's an invalid param for the found algorithm
 		} catch (UnsupportedOperationException e) {
 			// Could be that the operation is not supported
-		} catch (Exception e) {
-			fail("test_setParameterLjava_lang_StringLjava_lang_Object "
-					+ "threw incorrect exception : " + e);
 		}
 	}
 
 	/**
 	 * @tests java.security.Signature#setParameter(java.security.spec.AlgorithmParameterSpec)
 	 */
-	public void test_setParameterLjava_security_spec_AlgorithmParameterSpec() {
-		Signature sig = null;
-		try {
-			sig = Signature.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
+	public void test_setParameterLjava_security_spec_AlgorithmParameterSpec() throws Exception {
+		Signature sig = Signature.getInstance("DSA");
+
 		try {
 			DSAParameterSpec spec = new DSAParameterSpec(BigInteger.ONE,
 					BigInteger.ONE, BigInteger.ONE);
@@ -232,228 +152,111 @@
 			// Could be that it's an invalid param for the found algorithm
 		} catch (UnsupportedOperationException e) {
 			// Could be that the operation is not supported
-		} catch (Exception e) {
-			fail("test_setParameterLjava_security_spec_AlgorithmParameterSpec "
-					+ "threw incorrect exception : " + e);
 		}
 	}
 
 	/**
 	 * @tests java.security.Signature#sign()
 	 */
-	public void test_sign() {
+	public void test_sign() throws Exception {
 
-		fail("Test hangs - dependent on full math implementation ??");
+		Signature sig = Signature.getInstance("DSA");
 
-		Signature sig = null;
-		try {
-			sig = Signature.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
+		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
 
-		KeyPairGenerator keyGen = null;
-		try {
-			keyGen = KeyPairGenerator.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
 		SecureRandom random = new SecureRandom();
 		keyGen.initialize(1024, random);
 		KeyPair keys = keyGen.generateKeyPair();
-		try {
-			sig.initSign(keys.getPrivate());
-		} catch (InvalidKeyException e) {
-			fail("Invalid key : " + e);
-		}
-		try {
-			sig.update(MESSAGE.getBytes());
-		} catch (SignatureException e) {
-			fail("Problem updating Signature bytes : " + e);
-		}
-		try {
-			sig.sign();
-		} catch (SignatureException e) {
-			fail("Signature problem signing bytes : " + e);
-		}
+
+		sig.initSign(keys.getPrivate());
+		sig.update(MESSAGE.getBytes());
+		sig.sign();
 	}
 
 	/**
 	 * @tests java.security.Signature#toString()
 	 */
-	public void test_toString() {
-		try {
-			String str = Signature.getInstance("DSA").toString();
-			assertNotNull("toString is null", str);
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
+	public void test_toString() throws Exception {
+		String str = Signature.getInstance("DSA").toString();
+		assertNotNull("toString is null", str);
 	}
 
 	/**
 	 * @tests java.security.Signature#update(byte[])
 	 */
-	public void test_update$B() {
+	public void test_update$B() throws Exception {
 
-		fail("Test hangs - dependent on full math implementation ??");
+		Signature sig = Signature.getInstance("DSA");
 
-		Signature sig = null;
-		try {
-			sig = Signature.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
+		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
 
-		KeyPairGenerator keyGen = null;
-		try {
-			keyGen = KeyPairGenerator.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
 		SecureRandom random = new SecureRandom();
 		keyGen.initialize(1024, random);
 		KeyPair keys = keyGen.generateKeyPair();
-		try {
-			sig.initSign(keys.getPrivate());
-		} catch (InvalidKeyException e) {
-			fail("Invalid key : " + e);
-		}
-		try {
-			byte[] bytes = MESSAGE.getBytes();
-			sig.update(bytes);
-		} catch (SignatureException e) {
-			fail("Problem updating Signature bytes : " + e);
-		}
+
+		sig.initSign(keys.getPrivate());
+
+		byte[] bytes = MESSAGE.getBytes();
+		sig.update(bytes);
 	}
 
 	/**
 	 * @tests java.security.Signature#update(byte[], int, int)
 	 */
-	public void test_update$BII() {
+	public void test_update$BII() throws Exception {
 
-		fail("Test hangs - dependent on full math implementation ??");
+		Signature sig = Signature.getInstance("DSA");
 
-		Signature sig = null;
-		try {
-			sig = Signature.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
+		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
 
-		KeyPairGenerator keyGen = null;
-		try {
-			keyGen = KeyPairGenerator.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
 		SecureRandom random = new SecureRandom();
 		keyGen.initialize(1024, random);
 		KeyPair keys = keyGen.generateKeyPair();
-		try {
-			sig.initSign(keys.getPrivate());
-		} catch (InvalidKeyException e) {
-			fail("Invalid key : " + e);
-		}
-		try {
-			byte[] bytes = MESSAGE.getBytes();
-			sig.update(bytes, 0, bytes.length);
-		} catch (SignatureException e) {
-			fail("Signature problem updating bytes : " + e);
-		}
+
+		sig.initSign(keys.getPrivate());
+
+		byte[] bytes = MESSAGE.getBytes();
+		sig.update(bytes, 0, bytes.length);
 	}
 
 	/**
 	 * @tests java.security.Signature#update(byte)
 	 */
-	public void test_updateB() {
+	public void test_updateB() throws Exception {
 
-		fail("Test hangs - dependent on full math implementation ??");
+		Signature sig = Signature.getInstance("DSA");
 
-		Signature sig = null;
-		try {
-			sig = Signature.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
+		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
 
-		KeyPairGenerator keyGen = null;
-		try {
-			keyGen = KeyPairGenerator.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
 		SecureRandom random = new SecureRandom();
 		keyGen.initialize(1024, random);
 		KeyPair keys = keyGen.generateKeyPair();
-		try {
-			sig.initSign(keys.getPrivate());
-		} catch (InvalidKeyException e) {
-			fail("Invalid key : " + e);
-		}
-		try {
-			sig.update(MESSAGE.getBytes()[0]);
-		} catch (SignatureException e) {
-			fail("Problem updating Signature bytes : " + e);
-		}
+
+		sig.initSign(keys.getPrivate());
+
+		sig.update(MESSAGE.getBytes()[0]);
 	}
 
 	/**
 	 * @tests java.security.Signature#verify(byte[])
 	 */
-	public void test_verify$B() {
+	public void test_verify$B() throws Exception {
 
-		fail("Test hangs - dependent on full math implementation ??");
+		Signature sig = Signature.getInstance("DSA");
 
-		Signature sig = null;
-		try {
-			sig = Signature.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
+		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
 
-		KeyPairGenerator keyGen = null;
-		try {
-			keyGen = KeyPairGenerator.getInstance("DSA");
-		} catch (NoSuchAlgorithmException e) {
-			fail("getInstance did not find algorithm : " + e);
-		}
 		SecureRandom random = new SecureRandom();
 		keyGen.initialize(1024, random);
 		KeyPair keys = keyGen.generateKeyPair();
-		try {
-			sig.initSign(keys.getPrivate());
-		} catch (InvalidKeyException e) {
-			fail("Invalid key : " + e);
-		}
-		try {
-			sig.update(MESSAGE.getBytes());
-		} catch (SignatureException e) {
-			fail("Problem updating Signature bytes : " + e);
-		}
-		byte[] signature = null;
-		try {
-			signature = sig.sign();
-		} catch (SignatureException e) {
-			fail("Signature problem signing bytes : " + e);
-		}
 
-		try {
-			sig.initVerify(keys.getPublic());
-		} catch (InvalidKeyException e) {
-			fail("Invalid key : " + e);
-		}
-		try {
-			sig.update(MESSAGE.getBytes());
-		} catch (SignatureException e) {
-			fail("Problem updating Signature bytes : " + e);
-		}
-		boolean ok = false;
-		try {
-			ok = sig.verify(signature);
-		} catch (SignatureException e) {
-			fail("Signature problem verifying bytes : " + e);
-		}
+		sig.initSign(keys.getPrivate());
+		sig.update(MESSAGE.getBytes());
+		byte[] signature = sig.sign();
+
 
-		assertTrue("Sign/Verify does not pass", ok);
+		sig.initVerify(keys.getPublic());
+		sig.update(MESSAGE.getBytes());
+		assertTrue("Sign/Verify does not pass", sig.verify(signature));
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SignerTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SignerTest.java?rev=393206&r1=393205&r2=393206&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SignerTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/SignerTest.java Tue Apr 11 05:48:33 2006
@@ -44,64 +44,41 @@
 	 * @tests java.security.Signer#Signer()
 	 */
 	public void test_Constructor() {
-		try {
-			new SignerImpl();
-		} catch (Exception e) {
-			fail("Caught exception : " + e);
-		}
+		new SignerImpl();
 	}
 
 	/**
 	 * @tests java.security.Signer#Signer(java.lang.String)
 	 */
 	public void test_ConstructorLjava_lang_String() {
-		try {
-			new SignerImpl("test");
-		} catch (Exception e) {
-			fail("Caught exception : " + e);
-		}
+		new SignerImpl("test");
 	}
 
 	/**
 	 * @tests java.security.Signer#Signer(java.lang.String,
 	 *        java.security.IdentityScope)
 	 */
-	public void test_ConstructorLjava_lang_StringLjava_security_IdentityScope() {
-		try {
-			new SignerImpl("test", new IdentityScopeSubclass());
-		} catch (Exception e) {
-			fail("Caught exception : " + e);
-		}
+	public void test_ConstructorLjava_lang_StringLjava_security_IdentityScope() throws Exception {
+		new SignerImpl("test", new IdentityScopeSubclass());
 	}
 
 	/**
 	 * @tests java.security.Signer#getPrivateKey()
 	 */
-	public void test_getPrivateKey() {
-
-		fail("Test hangs - could be dependent on reall math implementation ??");
-
-		try {
-			SignerImpl signer = new SignerImpl("test");
-			KeyPairGenerator gen = KeyPairGenerator.getInstance("DSA");
-			KeyPair pair = gen.genKeyPair();
-			signer.setKeyPair(pair);
-			signer.getPrivateKey();
-		} catch (Exception e) {
-			fail("Caught exception : " + e);
-		}
+	public void test_getPrivateKey() throws Exception {
+		SignerImpl signer = new SignerImpl("test");
+		KeyPairGenerator gen = KeyPairGenerator.getInstance("DSA");
+		KeyPair pair = gen.genKeyPair();
+		signer.setKeyPair(pair);
+		signer.getPrivateKey();
 	}
 
 	/**
 	 * @tests java.security.Signer#toString()
 	 */
 	public void test_toString() {
-		try {
-			SignerImpl signer = new SignerImpl("test");
-			assertEquals("Unexpected return from toString method",
-					"[Signer]test", signer.toString());
-		} catch (Exception e) {
-			fail("Caught exception : " + e);
-		}
+		SignerImpl signer = new SignerImpl("test");
+		assertEquals("Unexpected return from toString method",
+				"[Signer]test", signer.toString());
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/spec/EncodedKeySpecTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/spec/EncodedKeySpecTest.java?rev=393206&r1=393205&r2=393206&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/spec/EncodedKeySpecTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/security/src/test/java/common/tests/api/java/security/spec/EncodedKeySpecTest.java Tue Apr 11 05:48:33 2006
@@ -19,139 +19,46 @@
 import java.security.KeyFactory;
 import java.security.KeyPair;
 import java.security.KeyPairGenerator;
-import java.security.NoSuchAlgorithmException;
-import java.security.NoSuchProviderException;
-import java.security.Provider;
-import java.security.SecureRandom;
-import java.security.Security;
 import java.security.interfaces.DSAPrivateKey;
 import java.security.interfaces.DSAPublicKey;
-import java.security.interfaces.RSAPrivateCrtKey;
-import java.security.interfaces.RSAPublicKey;
-import java.security.spec.InvalidKeySpecException;
 import java.security.spec.PKCS8EncodedKeySpec;
 import java.security.spec.X509EncodedKeySpec;
-import java.util.Enumeration;
-import java.util.Vector;
 
 import junit.framework.TestCase;
 
 public class EncodedKeySpecTest extends TestCase {
 
-	private static final String KEYFACTORY_ID = "KeyFactory.";
-
 	/**
 	 * @tests java.security.spec.EncodedKeySpec#getEncoded()
 	 */
-	public void test_getEncoded() {
-		
-		fail("Takes ages. Problem with SecureRandom and stub math ?");
+	public void test_getEncoded() throws Exception {
 		
-		Provider[] providers = Security.getProviders();
-		if (providers == null) {
-			fail("No providers found");
-		}
+       		KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
 
-		boolean atLeastOneProviderFound = false;
-		
-		// Loop through each of the providers that support KeyFactory algorithms
-		for (int j = 0; j < providers.length; j++) {
-			String providerName = providers[j].getName();
-			String[] keyfactAlgs = getKeyFactoryAlgorithms(providerName);
-			
-			// Loop through each of the KeyFactory algorithms supported by 
-			// the current provider
-			for (int i = 0; i < keyfactAlgs.length; i++) {
-				// If we reach here then at least one of the installed providers
-				// must support one of the KeyFactory algorithms
-				atLeastOneProviderFound = true;
-				try {
-					KeyFactory fact = KeyFactory.getInstance(keyfactAlgs[i],
-							providerName);
-					KeyPairGenerator keyGen = KeyPairGenerator
-							.getInstance(keyfactAlgs[i]);
-					// We don't use getInstance
-					SecureRandom random = new SecureRandom();
-					keyGen.initialize(1024, random);
-					KeyPair keys = keyGen.generateKeyPair();
-
-					// check public key encoding
-					byte[] encoded = keys.getPublic().getEncoded();
-					Key key = fact.generatePublic(new X509EncodedKeySpec(
-							encoded));
-					assertTrue(
-							"public key encodings were different for algorithm "
-									+ keyfactAlgs[i], isEqual(key, keys
-									.getPublic()));
-
-					// check private key encoding
-					encoded = keys.getPrivate().getEncoded();
-					key = fact
-							.generatePrivate(new PKCS8EncodedKeySpec(encoded));
-					assertTrue(
-							"private key encodings were different for algorithm "
-									+ keyfactAlgs[i], isEqual(key, keys
-									.getPrivate()));
-				} catch (NoSuchAlgorithmException e) {
-					fail("getInstance did not find expected algorithm "
-							+ keyfactAlgs[i]);
-				} catch (NoSuchProviderException e) {
-					fail("getInstance did not find provider " + providerName);
-				} catch (InvalidKeySpecException e) {
-					fail("invalid key spec for algorithm " + keyfactAlgs[i]);
-				}
-			}// end for
-		}// end for each provider supporting KeyFactory algorithms
-		
-		if (!atLeastOneProviderFound) {
-			fail("No providers supported KeyFactory algorithms");
-		}
-	}
+       		keyGen.initialize(1024);
+       		KeyPair keys = keyGen.generateKeyPair();
 
-	/*
-	 * Returns the key algorithms that the given provider supports.
-	 */
-	private String[] getKeyFactoryAlgorithms(String providerName) {
-		Vector algs = new Vector();
 
-		Provider provider = Security.getProvider(providerName);
-		if (provider == null)
-			return new String[0];
-		Enumeration e = provider.keys();
-		while (e.hasMoreElements()) {
-			String algorithm = (String) e.nextElement();
-			if (algorithm.startsWith(KEYFACTORY_ID)) {
-				algs.addElement(algorithm.substring(KEYFACTORY_ID.length()));
-			}
-		}
-		return (String[]) algs.toArray(new String[algs.size()]);
+       		KeyFactory fact = KeyFactory.getInstance("DSA");
+
+
+       		// check public key encoding
+       		byte[] encoded = keys.getPublic().getEncoded();
+       		Key key = fact.generatePublic(new X509EncodedKeySpec(encoded));
+
+       		assertTrue("public key encodings were different", 
+       					isEqual(key, keys.getPublic()));
+
+       		// check private key encoding
+       		encoded = keys.getPrivate().getEncoded();
+       		key = fact.generatePrivate(new PKCS8EncodedKeySpec(encoded));
+
+       		assertTrue("private key encodings were different",
+       					isEqual(key, keys.getPrivate()));
 	}
 
 	private boolean isEqual(Key key1, Key key2) {
-		if (key1 instanceof RSAPublicKey && key2 instanceof RSAPublicKey) {
-			RSAPublicKey rsa1 = ((RSAPublicKey) key1);
-			RSAPublicKey rsa2 = ((RSAPublicKey) key2);
-			return rsa1.getModulus().equals(rsa2.getModulus())
-					&& rsa1.getPublicExponent()
-							.equals(rsa2.getPublicExponent());
-		} else if (key1 instanceof RSAPrivateCrtKey
-				&& key2 instanceof RSAPrivateCrtKey) {
-			RSAPrivateCrtKey rsa1 = ((RSAPrivateCrtKey) key1);
-			RSAPrivateCrtKey rsa2 = ((RSAPrivateCrtKey) key2);
-			return rsa1.getModulus().equals(rsa2.getModulus())
-					&& rsa1.getPublicExponent()
-							.equals(rsa2.getPublicExponent())
-					&& rsa1.getPrivateExponent().equals(
-							rsa2.getPrivateExponent())
-					&& rsa1.getPrimeP().equals(rsa2.getPrimeP())
-					&& rsa1.getPrimeQ().equals(rsa2.getPrimeQ())
-					&& rsa1.getPrimeExponentP()
-							.equals(rsa2.getPrimeExponentP())
-					&& rsa1.getPrimeExponentQ()
-							.equals(rsa2.getPrimeExponentQ())
-					&& rsa1.getCrtCoefficient()
-							.equals(rsa2.getCrtCoefficient());
-		} else if (key1 instanceof DSAPublicKey && key2 instanceof DSAPublicKey) {
+		if (key1 instanceof DSAPublicKey && key2 instanceof DSAPublicKey) {
 			DSAPublicKey dsa1 = ((DSAPublicKey) key1);
 			DSAPublicKey dsa2 = ((DSAPublicKey) key2);
 			return dsa1.getY().equals(dsa2.getY())



Mime
View raw message