Initial load
diff --git a/test/java/security/Provider/CaseSensitiveServices.java b/test/java/security/Provider/CaseSensitiveServices.java
new file mode 100644
index 0000000..7cfda1f
--- /dev/null
+++ b/test/java/security/Provider/CaseSensitiveServices.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 5097015
+ * @summary make sure we correctly treat Provider string entries as case insensitive
+ * @author Andreas Sterbenz
+ */
+
+import java.security.*;
+import java.security.Provider.*;
+
+public class CaseSensitiveServices extends Provider {
+ CaseSensitiveServices() {
+ super("Foo", 1.0d, null);
+ put("MessageDigest.Foo", "com.Foo");
+ put("mESSAGEdIGEST.fOO xYz", "aBc");
+ put("ALg.aliaS.MESSAGEdigest.Fu", "FoO");
+ put("messageDigest.Bar", "com.Bar");
+ put("MESSAGEDIGEST.BAZ", "com.Baz");
+ }
+
+ public static void main(String[] args) throws Exception {
+ Provider p = new CaseSensitiveServices();
+ System.out.println(p.getServices());
+ if (p.getServices().size() != 3) {
+ throw new Exception("services.size() should be 3");
+ }
+ Service s = testService(p, "MessageDigest", "fOO");
+ String val = s.getAttribute("Xyz");
+ if ("aBc".equals(val) == false) {
+ throw new Exception("Wrong value: " + val);
+ }
+ testService(p, "MessageDigest", "fU");
+ testService(p, "MessageDigest", "BAR");
+ testService(p, "MessageDigest", "baz");
+ System.out.println("OK");
+ }
+
+ private static Service testService(Provider p, String type, String alg) throws Exception {
+ System.out.println("Getting " + type + "." + alg + "...");
+ Service s = p.getService(type, alg);
+ System.out.println(s);
+ if (s == null) {
+ throw new Exception("Lookup failed for: " + type + "." + alg);
+ }
+ return s;
+ }
+
+}
diff --git a/test/java/security/Provider/CertStoreConstructorParam.java b/test/java/security/Provider/CertStoreConstructorParam.java
new file mode 100644
index 0000000..66da891
--- /dev/null
+++ b/test/java/security/Provider/CertStoreConstructorParam.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6219491
+ * @summary CertStore.getInstance(String,CertStoreParameters,String) throws NoSuchAlgorithmE
+ */
+
+import java.security.*;
+import java.security.cert.*;
+
+public class CertStoreConstructorParam {
+ public static void main(String[] args) throws Exception {
+ try {
+
+ // attempt with null constructor param
+ CertStore.getInstance("Collection", null, "SUN");
+
+ } catch (InvalidAlgorithmParameterException iape) {
+
+ // ok - thrown by SUN provider
+ System.out.println("test passed");
+
+ } catch (NoSuchAlgorithmException nsae) {
+
+ // bad - thrown by Provider.Service.newInstance
+ System.out.println("test failed");
+ throw nsae;
+ }
+ }
+}
diff --git a/test/java/security/Provider/ChangeProviders.java b/test/java/security/Provider/ChangeProviders.java
new file mode 100644
index 0000000..7826fad
--- /dev/null
+++ b/test/java/security/Provider/ChangeProviders.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4856968
+ * @summary make sure add/insert/removeProvider() work correctly
+ * @author Andreas Sterbenz
+ */
+
+import java.util.*;
+
+import java.security.*;
+
+public class ChangeProviders extends Provider {
+
+ private ChangeProviders() {
+ super("Foo", 47.23d, "none");
+ }
+
+ private static int plen() {
+ return Security.getProviders().length;
+ }
+
+ public static void main(String[] args) throws Exception {
+ long start = System.currentTimeMillis();
+ Provider p = new ChangeProviders();
+
+ int n = plen();
+ Security.addProvider(p);
+ if (plen() != n + 1) {
+ throw new Exception("Provider not added");
+ }
+ Security.addProvider(p);
+ if (plen() != n + 1) {
+ throw new Exception("Provider readded");
+ }
+ Security.insertProviderAt(p, 1);
+ if (plen() != n + 1) {
+ throw new Exception("Provider readded");
+ }
+ Security.removeProvider(p.getName());
+ if ((plen() != n) || (Security.getProvider(p.getName()) != null)) {
+ throw new Exception("Provider not removed");
+ }
+ Security.insertProviderAt(p, 1);
+ if (plen() != n + 1) {
+ throw new Exception("Provider not added");
+ }
+ if (Security.getProviders()[0] != p) {
+ throw new Exception("Provider not at pos 1");
+ }
+
+ System.out.println("All tests passed.");
+ }
+
+}
diff --git a/test/java/security/Provider/DefaultPKCS11.java b/test/java/security/Provider/DefaultPKCS11.java
new file mode 100644
index 0000000..e511f53
--- /dev/null
+++ b/test/java/security/Provider/DefaultPKCS11.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6260888
+ * @summary check SunPKCS11-Solaris is available on S10+ systems
+ * @author Andreas Sterbenz
+ */
+
+import java.util.*;
+
+import java.security.*;
+
+public class DefaultPKCS11 {
+
+ public static void main(String[] args) throws Exception {
+ String osName = System.getProperty("os.name", "(null)");
+ String osVersion = System.getProperty("os.version", "(null)");
+ System.out.println("Running on " + osName + " " + osVersion);
+ Provider[] ps = Security.getProviders();
+ System.out.println("Providers: " + Arrays.asList(ps));
+ System.out.println();
+
+ if (osName.equals("SunOS") == false) {
+ System.out.println("Test only applies to Solaris, skipping");
+ return;
+ }
+ String[] v = osVersion.split("\\.");
+ if (v.length < 2) {
+ throw new Exception("Failed to parse Solaris version: " + Arrays.asList(v));
+ }
+ if (Integer.parseInt(v[0]) != 5) {
+ throw new Exception("Unknown Solaris major version: " + v[0]);
+ }
+ if (Integer.parseInt(v[1]) < 10) {
+ System.out.println("Test only applies to Solaris 10 and later, skipping");
+ return;
+ }
+ if (ps[0].getName().equals("SunPKCS11-Solaris") == false) {
+ throw new Exception("SunPKCS11-Solaris provider not installed");
+ }
+ System.out.println("OK");
+ }
+
+}
diff --git a/test/java/security/Provider/Equals.java b/test/java/security/Provider/Equals.java
new file mode 100644
index 0000000..4b8232a
--- /dev/null
+++ b/test/java/security/Provider/Equals.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4918769
+ * @summary make sure Provider.equals() behaves as expected with the id attributes
+ * @author Andreas Sterbenz
+ */
+
+import java.security.*;
+
+public class Equals {
+
+ public static void main(String[] args) throws Exception {
+ Provider p1 = new P1("foo", 1.0d, "foo");
+ Provider p1b = new P1("foo", 1.0d, "foo");
+ Provider p2 = new P2("foo", 1.0d, "foo");
+ System.out.println(p1.entrySet());
+ if (p1.equals(p2)) {
+ throw new Exception("Objects are equal");
+ }
+ if (p1.equals(p1b) == false) {
+ throw new Exception("Objects not equal");
+ }
+ p1.clear();
+ if (p1.equals(p1b) == false) {
+ throw new Exception("Objects not equal");
+ }
+ p1.put("Provider.id name", "bar");
+ p1.remove("Provider.id version");
+ if (p1.equals(p1b) == false) {
+ throw new Exception("Objects not equal");
+ }
+ }
+
+ private static class P1 extends Provider {
+ P1(String name, double version, String info) {
+ super(name, version, info);
+ }
+ }
+
+ private static class P2 extends Provider {
+ P2(String name, double version, String info) {
+ super(name, version, info);
+ }
+ }
+
+}
diff --git a/test/java/security/Provider/GetInstance.java b/test/java/security/Provider/GetInstance.java
new file mode 100644
index 0000000..267982f
--- /dev/null
+++ b/test/java/security/Provider/GetInstance.java
@@ -0,0 +1,256 @@
+/*
+ * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4856968
+ * @summary make sure getInstance() works correctly, including failover
+ * and delayed provider selection for Signatures
+ * @author Andreas Sterbenz
+ */
+
+import java.util.*;
+
+import java.security.*;
+import java.security.cert.*;
+
+public class GetInstance {
+
+ private static void same(Provider p1, Provider p2) throws Exception {
+ if (p1 != p2) {
+ throw new Exception("Wrong provider");
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ long start = System.currentTimeMillis();
+
+ Provider foo = new FooProvider();
+ Provider bar = new BarProvider();
+ Provider baz = new BazProvider();
+
+ Security.addProvider(foo);
+ Security.addProvider(bar);
+ Security.addProvider(baz);
+
+ System.out.println("Testing MessageDigest.getInstance()...");
+ MessageDigest m;
+ m = MessageDigest.getInstance("foo");
+ m = MessageDigest.getInstance("foo", "foo");
+ m = MessageDigest.getInstance("foo", foo);
+
+ System.out.println("Testing Signature.getInstance() for SPI...");
+ Signature sig;
+ PrivateKey privateKey = new FooPrivateKey();
+ sig = Signature.getInstance("foo");
+ same(foo, sig.getProvider());
+ sig = Signature.getInstance("foo");
+ sig.initSign(privateKey);
+ same(foo, sig.getProvider());
+ sig = Signature.getInstance("foo", "foo");
+ sig.initSign(privateKey);
+ same(foo, sig.getProvider());
+ sig = Signature.getInstance("foo", foo);
+ sig.initSign(privateKey);
+ same(foo, sig.getProvider());
+
+ System.out.println("Testing Signature.getInstance() for Signature...");
+ sig = Signature.getInstance("fuu");
+ same(foo, sig.getProvider());
+ sig = Signature.getInstance("fuu");
+ sig.initSign(privateKey);
+ same(foo, sig.getProvider());
+ sig = Signature.getInstance("fuu", "foo");
+ sig.initSign(privateKey);
+ same(foo, sig.getProvider());
+ sig = Signature.getInstance("fuu", foo);
+ sig.initSign(privateKey);
+ same(foo, sig.getProvider());
+
+ System.out.println("Testing CertStore.getInstance()...");
+ CertStoreParameters params = new CollectionCertStoreParameters(Collections.EMPTY_LIST);
+ CertStore cs;
+ cs = CertStore.getInstance("foo", params);
+ cs = CertStore.getInstance("foo", params, "foo");
+ cs = CertStore.getInstance("foo", params, foo);
+
+ System.out.println("Testing failover...");
+ m = MessageDigest.getInstance("bar");
+ same(m.getProvider(), baz);
+ sig = Signature.getInstance("bar");
+ same(sig.getProvider(), baz);
+ cs = CertStore.getInstance("bar", params);
+ same(cs.getProvider(), baz);
+
+ System.out.println("Testing Signature delayed provider selection...");
+ sig = Signature.getInstance("baz");
+ sig.initVerify(new FooPublicKey());
+ same(sig.getProvider(), baz);
+
+ Provider.Service s = foo.getService("CertStore", "foo");
+ s.newInstance(null);
+ s.newInstance(params);
+ try {
+ s.newInstance(0);
+ throw new Exception("call should not succeed");
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ Throwable cause = e.getCause();
+ if (cause instanceof InvalidParameterException == false) {
+ throw new Exception("incorrect exception");
+ }
+ }
+
+ long stop = System.currentTimeMillis();
+ System.out.println("Done (" + (stop - start) + " ms).");
+ }
+
+ public static class FooProvider extends Provider {
+ FooProvider() {
+ super("foo", 1.0d, "none");
+ put("MessageDigest.foo", "GetInstance$FooDigest");
+ put("CertStore.foo", "GetInstance$FooStore");
+ put("Signature.foo", "GetInstance$FooSignatureSpi");
+
+ put("Signature.fuu", "GetInstance$BazSignature");
+
+ // throws InvalidKeyException, skipped in delayed provider selection
+ put("Signature.baz", "GetInstance$BazSignatureSpi");
+ }
+ }
+
+ public static class BarProvider extends Provider {
+ BarProvider() {
+ super("bar", 1.0d, "none");
+ // all entries invalid for failover
+ put("MessageDigest.bar", "GetInstance$FooKey");
+ put("Signature.bar", "GetInstance$FooKey");
+ put("Certstore.bar", "GetInstance$FooKey");
+
+ // not an SPI, skipped in delayed provider selection
+ put("Signature.baz", "GetInstance$BazSignature");
+ }
+ }
+
+ public static class BazProvider extends Provider {
+ BazProvider() {
+ super("baz", 1.0d, "none");
+ put("MessageDigest.bar", "GetInstance$FooDigest");
+ put("CertStore.bar", "GetInstance$FooStore");
+ put("Signature.bar", "GetInstance$FooSignatureSpi");
+
+ put("Signature.baz", "GetInstance$FooSignatureSpi");
+ }
+ }
+
+ public static class FooDigest extends MessageDigestSpi {
+ public byte[] engineDigest() { return new byte[0]; }
+ public void engineReset() {}
+ public void engineUpdate(byte input) {}
+ public void engineUpdate(byte[] b, int ofs, int len) {}
+ }
+
+ public static class FooStore extends CertStoreSpi {
+ public FooStore(CertStoreParameters params) throws InvalidAlgorithmParameterException { super(params); }
+ public Collection engineGetCertificates(CertSelector sel) { return Collections.EMPTY_LIST; }
+ public Collection engineGetCRLs(CRLSelector sel) { return Collections.EMPTY_LIST; }
+ }
+
+ public static class BaseSignatureSpi extends SignatureSpi {
+ protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
+ }
+ protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
+ }
+ protected void engineUpdate(byte b) throws SignatureException { }
+ protected void engineUpdate(byte[] b, int off, int len) throws SignatureException { }
+ protected byte[] engineSign() throws SignatureException {
+ return new byte[0];
+ }
+ protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
+ return false;
+ }
+ protected void engineSetParameter(String param, Object value) throws InvalidParameterException {
+ }
+ protected Object engineGetParameter(String param) throws InvalidParameterException {
+ return null;
+ }
+ }
+
+ public static class BaseSignature extends Signature {
+ BaseSignature(String s) {
+ super(s);
+ }
+ protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
+ //
+ }
+ protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException { }
+ protected void engineUpdate(byte b) throws SignatureException { }
+ protected void engineUpdate(byte[] b, int off, int len) throws SignatureException { }
+ protected byte[] engineSign() throws SignatureException {
+ return new byte[0];
+ }
+ protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
+ return false;
+ }
+ protected void engineSetParameter(String param, Object value) throws InvalidParameterException {
+ }
+ protected Object engineGetParameter(String param) throws InvalidParameterException {
+ return null;
+ }
+ }
+
+ public static abstract class FooKey implements Key {
+ public String getFormat() { return null; }
+ public byte[] getEncoded() { return null; }
+ public String getAlgorithm() { return "foo"; }
+ }
+
+ public static class FooPrivateKey extends FooKey implements PrivateKey { }
+
+ public static class FooPublicKey extends FooKey implements PublicKey { }
+
+ public static class FooSignatureSpi extends BaseSignatureSpi {
+ public FooSignatureSpi() {
+ super();
+ System.out.println("FooSignatureSpi constructor");
+ }
+ }
+
+ public static class BazSignatureSpi extends BaseSignatureSpi {
+ public BazSignatureSpi() {
+ super();
+ System.out.println("BazSignatureSpi constructor");
+ }
+ protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
+ throw new InvalidKeyException("verify not supported");
+ }
+ }
+
+ public static class BazSignature extends BaseSignature {
+ public BazSignature() {
+ super("baz");
+ System.out.println("BazSignature constructor");
+ }
+ }
+
+}
diff --git a/test/java/security/Provider/ProviderInfoCheck.java b/test/java/security/Provider/ProviderInfoCheck.java
new file mode 100644
index 0000000..60f4f7a
--- /dev/null
+++ b/test/java/security/Provider/ProviderInfoCheck.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6455351
+ * @summary Make sure the Provider.info entries have the correct values
+ * after going through serialization/deserialization.
+ * @author Valerie Peng
+ */
+
+import java.io.*;
+import java.security.*;
+import java.util.*;
+
+public class ProviderInfoCheck {
+
+ public static void main(String[] args) throws Exception {
+ Provider p = new SampleProvider();
+
+ // Serialize and deserialize the above Provider object
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(p);
+ oos.close();
+ ByteArrayInputStream bais =
+ new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ Provider p2 = (Provider) ois.readObject();
+ ois.close();
+
+ checkProviderInfoEntries(p2);
+ }
+
+ private static void checkProviderInfoEntries(Provider p)
+ throws Exception {
+ String value = (String) p.get("Provider.id name");
+ if (!SampleProvider.NAME.equalsIgnoreCase(value) ||
+ !p.getName().equalsIgnoreCase(value)) {
+ throw new Exception("Test Failed: incorrect name!");
+ }
+ value = (String) p.get("Provider.id info");
+ if (!SampleProvider.INFO.equalsIgnoreCase(value) ||
+ !p.getInfo().equalsIgnoreCase(value)) {
+ throw new Exception("Test Failed: incorrect info!");
+ }
+ value = (String) p.get("Provider.id className");
+ if (!p.getClass().getName().equalsIgnoreCase(value)) {
+ throw new Exception("Test Failed: incorrect className!");
+ }
+ double dvalue =
+ Double.parseDouble((String) p.get("Provider.id version"));
+ if ((SampleProvider.VERSION != dvalue) ||
+ p.getVersion() != dvalue) {
+ throw new Exception("Test Failed: incorrect version!");
+ }
+ System.out.println("Test Passed");
+ }
+
+ private static class SampleProvider extends Provider {
+ static String NAME = "Sample";
+ static double VERSION = 1.1d;
+ static String INFO = "Good for nothing";
+ SampleProvider() {
+ super(NAME, VERSION, INFO);
+ }
+ }
+}
diff --git a/test/java/security/Provider/RemoveProvider.java b/test/java/security/Provider/RemoveProvider.java
new file mode 100644
index 0000000..63c419e
--- /dev/null
+++ b/test/java/security/Provider/RemoveProvider.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright 1998 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4190873
+ * @summary Make sure provider instance can be removed from list of registered
+ * providers, and "entrySet", "keySet", and "values" methods don't loop
+ * indefinitely.
+ */
+import java.security.*;
+import java.util.*;
+
+public class RemoveProvider {
+
+ public static void main(String[] args) throws Exception {
+
+ // Add provider 1
+ Provider p1 = new MyProvider("name1",1,"");
+ Security.addProvider(p1);
+
+ // Add provider 2
+ Provider p2 = new MyProvider("name2",1,"");
+ Security.addProvider(p2);
+
+ // List all providers
+ System.out.println("// List all providers");
+ Provider[] provs = Security.getProviders();
+ for (int i=0; i<provs.length; i++)
+ System.out.println(provs[i].toString());
+
+ // Remove one provider and list all remaining providers
+ System.out.println("");
+ System.out.println("// Remove one provider");
+ Security.removeProvider("name1");
+ provs = Security.getProviders();
+ for (int i=0; i<provs.length; i++)
+ System.out.println(provs[i].toString());
+
+ // Iterate over the entrySet
+ System.out.println("");
+ System.out.println("// Iterate over entrySet");
+ Map.Entry me = null;
+ Set es = p1.entrySet();
+ Iterator i = es.iterator();
+ while (i.hasNext()) {
+ me = (Map.Entry)i.next();
+ System.out.println("Key: " + (String)me.getKey());
+ System.out.println("Value: " + (String)me.getValue());
+ }
+ // Try to modify the backing Map, and catch the expected exception
+ try {
+ me.setValue("name1.mac");
+ throw new Exception("Expected exception not thrown");
+ } catch (UnsupportedOperationException uoe) {
+ System.out.println("Expected exception caught");
+ }
+
+ // Iterate over the keySet, and try to remove one (should fail)
+ System.out.println("");
+ System.out.println("// Iterate over keySet");
+ Object o = null;
+ Set ks = p1.keySet();
+ i = ks.iterator();
+ while (i.hasNext()) {
+ o = i.next();
+ System.out.println((String)o);
+ }
+ try {
+ ks.remove(o);
+ throw new Exception("Expected exception not thrown");
+ } catch (UnsupportedOperationException uoe) {
+ }
+
+ // Iterate over the map values
+ System.out.println("");
+ System.out.println("// Iterate over values");
+ Collection c = p1.values();
+ i = c.iterator();
+ while (i.hasNext()) {
+ System.out.println((String)i.next());
+ }
+
+ // Modify provider and make sure changes are reflected in
+ // existing entrySet (i.e., make sure entrySet is "live").
+ // First, add entry to provider.
+ System.out.println("");
+ System.out.println("// Add 'Cipher' entry to provider");
+ p1.put("Cipher", "name1.des");
+ // entrySet
+ i = es.iterator();
+ boolean found = false;
+ while (i.hasNext()) {
+ me = (Map.Entry)i.next();
+ System.out.println("Key: " + (String)me.getKey());
+ System.out.println("Value: " + (String)me.getValue());
+ if (((String)me.getKey()).equals("Cipher"))
+ found = true;
+ }
+ if (!found)
+ throw new Exception("EntrySet not live");
+ // keySet
+ i = ks.iterator();
+ while (i.hasNext()) {
+ o = i.next();
+ System.out.println((String)o);
+ }
+ // collection
+ i = c.iterator();
+ while (i.hasNext()) {
+ System.out.println((String)i.next());
+ }
+
+ // Remove entry from provider
+ System.out.println("");
+ System.out.println("// Remove 'Digest' entry from provider");
+ p1.remove("Digest");
+ // entrySet
+ i = es.iterator();
+ while (i.hasNext()) {
+ me = (Map.Entry)i.next();
+ System.out.println("Key: " + (String)me.getKey());
+ System.out.println("Value: " + (String)me.getValue());
+ }
+ // keySet
+ i = ks.iterator();
+ while (i.hasNext()) {
+ o = i.next();
+ System.out.println((String)o);
+ }
+ // collection
+ i = c.iterator();
+ while (i.hasNext()) {
+ System.out.println((String)i.next());
+ }
+
+ // Retrieve new entrySet and make sure the backing Map cannot be
+ // mofified
+ es = p1.entrySet();
+ i = es.iterator();
+ while (i.hasNext()) {
+ me = (Map.Entry)i.next();
+ System.out.println("Key: " + (String)me.getKey());
+ System.out.println("Value: " + (String)me.getValue());
+ }
+ try {
+ me.setValue("name1.mac");
+ throw new Exception("Expected exception not thrown");
+ } catch (UnsupportedOperationException uoe) {
+ System.out.println("Expected exception caught");
+ }
+ }
+}
+
+class MyProvider extends Provider {
+ public MyProvider(String name, double version, String info) {
+ super(name, version, info);
+ put("Signature", name+".signature");
+ put("Digest", name+".digest");
+ }
+}
diff --git a/test/java/security/Provider/SupportsParameter.java b/test/java/security/Provider/SupportsParameter.java
new file mode 100644
index 0000000..b502a3c
--- /dev/null
+++ b/test/java/security/Provider/SupportsParameter.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 4911081
+ * @summary verify that Provider.Service.supportsParameter() works
+ * @author Andreas Sterbenz
+ */
+
+import java.security.*;
+import java.security.Provider.Service;
+
+import javax.crypto.*;
+import javax.crypto.spec.SecretKeySpec;
+
+public class SupportsParameter {
+
+ public static void main(String[] args) throws Exception {
+ KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA");
+ kpg.initialize(512);
+ KeyPair kp = kpg.generateKeyPair();
+ PublicKey dsaPublicKey = kp.getPublic();
+ PrivateKey dsaPrivateKey = kp.getPrivate();
+
+ PublicKey myPublicKey = new MyPublicKey();
+ PrivateKey myPrivateKey = new MyPrivateKey();
+ SecretKey mySecretKey = new MySecretKey();
+
+ Provider p = new MyProvider();
+ Service s;
+
+ // none specified, always true
+ s = p.getService("Signature", "DSA0");
+ checkSupports(s, null, true);
+ checkSupports(s, dsaPublicKey, true);
+ checkSupports(s, dsaPrivateKey, true);
+ checkSupports(s, myPublicKey, true);
+ checkSupports(s, myPrivateKey, true);
+ checkSupports(s, mySecretKey, true);
+
+ // DSAPublic/PrivateKey specified as classes
+ s = p.getService("Signature", "DSA");
+ checkSupports(s, dsaPublicKey, true);
+ checkSupports(s, dsaPrivateKey, true);
+ checkSupports(s, myPublicKey, false);
+ checkSupports(s, myPrivateKey, false);
+ checkSupports(s, mySecretKey, false);
+
+ // X.509/PKCS#8 specified as formats
+ s = p.getService("Signature", "DSA2");
+ checkSupports(s, dsaPublicKey, true);
+ checkSupports(s, dsaPrivateKey, true);
+ checkSupports(s, myPublicKey, false);
+ checkSupports(s, myPrivateKey, false);
+ checkSupports(s, mySecretKey, false);
+
+ // MyPublic/PrivateKey + DSAPublicKey specified as classes
+ s = p.getService("Signature", "DSA3");
+ checkSupports(s, dsaPublicKey, true);
+ checkSupports(s, dsaPrivateKey, false);
+ checkSupports(s, myPublicKey, true);
+ checkSupports(s, myPrivateKey, true);
+ checkSupports(s, mySecretKey, false);
+
+ // MyPublic/PrivateKey + DSAPublicKey specified as classes
+ s = p.getService("Cipher", "DES");
+ checkSupports(s, dsaPublicKey, false);
+ checkSupports(s, dsaPrivateKey, false);
+ checkSupports(s, myPublicKey, false);
+ checkSupports(s, myPrivateKey, false);
+ checkSupports(s, mySecretKey, true);
+ Key secretKeySpec = new SecretKeySpec(new byte[8], "DES");
+ checkSupports(s, secretKeySpec, true);
+
+ }
+
+ private static void checkSupports(Service s, Key key, boolean r) throws Exception {
+ if (s.supportsParameter(key) != r) {
+ throw new Exception("Result mismatch");
+ }
+ System.out.println("Passed");
+ }
+
+ private static class MyProvider extends Provider {
+ MyProvider() {
+ super("MyProvider", 1.0d, "MyProvider");
+
+ put("Signature.DSA0", "foo.DSA0");
+
+ put("Signature.DSA", "foo.DSA");
+ put("Signature.DSA SupportedKeyClasses",
+ "java.security.interfaces.DSAPublicKey" +
+ "|java.security.interfaces.DSAPrivateKey");
+
+ put("Signature.DSA2", "foo.DSA2");
+ put("Signature.DSA2 SupportedKeyFormats", "X.509|PKCS#8");
+
+ put("Signature.DSA3", "foo.DSA3");
+ put("Signature.DSA3 SupportedKeyClasses",
+ "SupportsParameter$MyPrivateKey" +
+ "|SupportsParameter$MyPublicKey" +
+ "|java.security.interfaces.DSAPublicKey");
+
+ put("Cipher.DES", "foo.DES");
+ put("Cipher.DES SupportedKeyFormats", "RAW");
+ put("Cipher.DES SupportedKeyClasses", "SupportsParameter$MySecretKey");
+ }
+ }
+
+ private static class MyKey implements Key {
+ public String getAlgorithm() { return "FOO"; }
+
+ public String getFormat() { return null; }
+
+ public byte[] getEncoded() { return null; }
+ }
+
+ private static class MyPrivateKey extends MyKey implements PrivateKey { }
+
+ private static class MyPublicKey extends MyKey implements PublicKey {}
+
+ private static class MySecretKey extends MyKey implements SecretKey {
+ public String getAlgorithm() { return "DES"; }
+ }
+
+}
diff --git a/test/java/security/Provider/Turkish.java b/test/java/security/Provider/Turkish.java
new file mode 100644
index 0000000..1934561
--- /dev/null
+++ b/test/java/security/Provider/Turkish.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/**
+ * @test
+ * @bug 6220064
+ * @summary make sure everything works ok in the Turkish local (dotted/dotless i problem)
+ * @author Andreas Sterbenz
+ */
+
+import java.util.*;
+
+import java.security.*;
+import java.security.Provider.Service;
+import javax.crypto.*;
+
+public class Turkish {
+
+ public static void main(String[] args) throws Exception {
+ Provider p1 = new TProvider("T1");
+ System.out.println(p1.getServices()); // trigger service parsing
+
+ Locale.setDefault(new Locale("tr", "TR"));
+
+ Provider p2 = new TProvider("T2");
+ System.out.println(p2.getServices()); // trigger service parsing
+
+ System.out.println(Signature.getInstance("MD5withRSA"));
+ System.out.println(Signature.getInstance("md5withrsa"));
+ System.out.println(Signature.getInstance("MD5WITHRSA"));
+ Service s1, s2;
+ s1 = p1.getService("Signature", "MD5withRSA");
+ check(s1, null);
+ check(s1, p1.getService("Signature", "md5withrsa"));
+ check(s1, p1.getService("Signature", "MD5WITHRSA"));
+ check(s1, p1.getService("Signature", "MD5RSA"));
+ check(s1, p1.getService("Signature", "md5rsa"));
+ check(s1, p1.getService("Signature", "MD5rsa"));
+
+ s1 = p1.getService("Signature", "SHAwithRSA");
+ check(s1, null);
+ check(s1, p1.getService("Signature", "shawithrsa"));
+ check(s1, p1.getService("Signature", "SHAWITHRSA"));
+ check(s1, p1.getService("Signature", "SHARSA"));
+ check(s1, p1.getService("Signature", "sharsa"));
+ check(s1, p1.getService("Signature", "SHArsa"));
+ check(s1, p1.getService("Signature", "SHA1RSA"));
+ check(s1, p1.getService("Signature", "sha1rsa"));
+ check(s1, p1.getService("Signature", "SHA1rsa"));
+
+ s1 = p2.getService("Signature", "MD5withRSA");
+ check(s1, null);
+ check(s1, p2.getService("Signature", "md5withrsa"));
+ check(s1, p2.getService("Signature", "MD5WITHRSA"));
+ check(s1, p2.getService("Signature", "MD5RSA"));
+ check(s1, p2.getService("Signature", "md5rsa"));
+ check(s1, p2.getService("Signature", "MD5rsa"));
+
+ s1 = p2.getService("Signature", "SHAwithRSA");
+ check(s1, null);
+ check(s1, p2.getService("Signature", "shawithrsa"));
+ check(s1, p2.getService("Signature", "SHAWITHRSA"));
+ check(s1, p2.getService("Signature", "SHARSA"));
+ check(s1, p2.getService("Signature", "sharsa"));
+ check(s1, p2.getService("Signature", "SHArsa"));
+ check(s1, p2.getService("Signature", "SHA1RSA"));
+ check(s1, p2.getService("Signature", "sha1rsa"));
+ check(s1, p2.getService("Signature", "SHA1rsa"));
+
+ System.out.println("OK");
+ }
+
+ private static void check(Service s1, Service s2) throws Exception {
+ System.out.println(s1);
+ if (s1 == null) {
+ throw new Exception("service is null");
+ }
+ if ((s2 != null) && (s1 != s2)) {
+ throw new Exception("service does not match");
+ }
+ }
+
+ private static class TProvider extends Provider {
+ TProvider(String name) {
+ super(name, 1.0d, null);
+ put("Signature.MD5withRSA", "com.foo.Sig");
+ put("Alg.Alias.Signature.MD5RSA", "MD5withRSA");
+ put("sIGNATURE.shaWITHrsa", "com.foo.Sig");
+ put("aLG.aLIAS.sIGNATURE.sharsa", "shaWITHrsa");
+ put("aLG.aLIAS.sIGNATURE.sha1rsa", "shawithrsa");
+ }
+ }
+
+}