Initial load
diff --git a/test/java/security/Signature/ByteBuffers.java b/test/java/security/Signature/ByteBuffers.java
new file mode 100644
index 0000000..c7c33be
--- /dev/null
+++ b/test/java/security/Signature/ByteBuffers.java
@@ -0,0 +1,95 @@
+/*
+ * 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 4844847
+ * @summary Test the Signature.update(ByteBuffer) method
+ * @author Andreas Sterbenz
+ */
+
+import java.util.*;
+import java.nio.*;
+
+import java.security.*;
+
+public class ByteBuffers {
+
+ public static void main(String[] args) throws Exception {
+ Provider p = Security.getProvider("SUN");
+ Random random = new Random();
+ int n = 10 * 1024;
+ byte[] t = new byte[n];
+ random.nextBytes(t);
+
+ KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA", p);
+ kpg.initialize(512);
+ KeyPair kp = kpg.generateKeyPair();
+
+ Signature sig = Signature.getInstance("DSA", p);
+ sig.initSign(kp.getPrivate());
+ sig.update(t);
+ byte[] signature = sig.sign();
+
+ sig.initVerify(kp.getPublic());
+
+ // test 1: ByteBuffer with an accessible backing array
+ ByteBuffer b1 = ByteBuffer.allocate(n + 256);
+ b1.position(random.nextInt(256));
+ b1.limit(b1.position() + n);
+ ByteBuffer b2 = b1.slice();
+ b2.put(t);
+ b2.clear();
+ verify(sig, signature, b2, random);
+
+ // test 2: direct ByteBuffer
+ ByteBuffer b3 = ByteBuffer.allocateDirect(t.length);
+ b3.put(t);
+ b3.clear();
+ verify(sig, signature, b3, random);
+
+ // test 3: ByteBuffer without an accessible backing array
+ b2.clear();
+ ByteBuffer b4 = b2.asReadOnlyBuffer();
+ verify(sig, signature, b4, random);
+
+ System.out.println("All tests passed");
+ }
+
+ private static void verify(Signature sig, byte[] signature, ByteBuffer b, Random random) throws Exception {
+ int lim = b.limit();
+ b.limit(random.nextInt(lim));
+ sig.update(b);
+ if (b.hasRemaining()) {
+ throw new Exception("Buffer not consumed");
+ }
+ b.limit(lim);
+ sig.update(b);
+ if (b.hasRemaining()) {
+ throw new Exception("Buffer not consumed");
+ }
+ if (sig.verify(signature) == false) {
+ throw new Exception("Signature did not verify");
+ }
+ }
+}
diff --git a/test/java/security/Signature/NONEwithRSA.java b/test/java/security/Signature/NONEwithRSA.java
new file mode 100644
index 0000000..26566f9
--- /dev/null
+++ b/test/java/security/Signature/NONEwithRSA.java
@@ -0,0 +1,90 @@
+/*
+ * 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 4955844
+ * @summary ensure that the NONEwithRSA adapter works correctly
+ * @author Andreas Sterbenz
+ */
+
+import java.util.*;
+
+import java.security.*;
+
+import javax.crypto.*;
+
+public class NONEwithRSA {
+
+ public static void main(String[] args) throws Exception {
+// showProvider(Security.getProvider("SUN"));
+ Random random = new Random();
+ byte[] b = new byte[16];
+ random.nextBytes(b);
+
+ KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
+ kpg.initialize(512);
+ KeyPair kp = kpg.generateKeyPair();
+
+ Signature sig = Signature.getInstance("NONEwithRSA");
+ sig.initSign(kp.getPrivate());
+ System.out.println("Provider: " + sig.getProvider());
+ sig.update(b);
+ byte[] sb = sig.sign();
+
+ sig.initVerify(kp.getPublic());
+ sig.update(b);
+ if (sig.verify(sb) == false) {
+ throw new Exception("verification failed");
+ }
+
+ Cipher c = Cipher.getInstance("RSA/ECB/PKCS1Padding");
+ c.init(Cipher.DECRYPT_MODE, kp.getPublic());
+ byte[] dec = c.doFinal(sb);
+ if (Arrays.equals(dec, b) == false) {
+ throw new Exception("decryption failed");
+ }
+
+ sig = Signature.getInstance("NONEwithRSA", "SunJCE");
+ sig.initSign(kp.getPrivate());
+ sig = Signature.getInstance("NONEwithRSA", Security.getProvider("SunJCE"));
+ sig.initSign(kp.getPrivate());
+
+ try {
+ Signature.getInstance("NONEwithRSA", "SUN");
+ throw new Exception("call succeeded");
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ }
+
+ System.out.println("OK");
+ }
+
+ private static void showProvider(Provider p) {
+ System.out.println(p);
+ for (Iterator t = p.getServices().iterator(); t.hasNext(); ) {
+ System.out.println(t.next());
+ }
+ }
+
+}
diff --git a/test/java/security/Signature/SignWithOutputBuffer.java b/test/java/security/Signature/SignWithOutputBuffer.java
new file mode 100644
index 0000000..3c393f3
--- /dev/null
+++ b/test/java/security/Signature/SignWithOutputBuffer.java
@@ -0,0 +1,66 @@
+/*
+ * 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 4114896
+ * @summary Signature should support a sign() method that places the signature
+ * in an already existing array.
+ */
+
+import java.security.*;
+
+public class SignWithOutputBuffer {
+
+ public static void main(String[] args) throws Exception {
+
+ int numBytes;
+
+ KeyPairGenerator kpGen = KeyPairGenerator.getInstance("DSA");
+ kpGen.initialize(512);
+ KeyPair kp = kpGen.genKeyPair();
+
+ Signature sig = Signature.getInstance("DSS");
+ sig.initSign(kp.getPrivate());
+ sig.update((byte)0xff);
+
+ // Allocate buffer for signature. According to BSAFE, the size of the
+ // signature may be as many as 48 bytes.
+ // First, let's allocate a buffer that's too short.
+ byte[] out = new byte[10];
+ try {
+ numBytes = sig.sign(out, 0, out.length);
+ } catch (SignatureException e) {
+ System.out.println(e);
+ }
+
+ // Now repeat the same with a buffer that's big enough
+ sig = Signature.getInstance("DSS");
+ sig.initSign(kp.getPrivate());
+ sig.update((byte)0xff);
+ out = new byte[48];
+ numBytes = sig.sign(out, 0, out.length);
+
+ System.out.println("Signature len="+numBytes);
+ }
+}
diff --git a/test/java/security/Signature/TestInitSignWithMyOwnRandom.java b/test/java/security/Signature/TestInitSignWithMyOwnRandom.java
new file mode 100644
index 0000000..5363b34
--- /dev/null
+++ b/test/java/security/Signature/TestInitSignWithMyOwnRandom.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2002-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 4716321
+ * @summary Ensure the random source supplied in
+ * Signature.initSign(PrivateKey, SecureRandom) is used.
+ */
+import java.security.*;
+
+public class TestInitSignWithMyOwnRandom {
+
+ public static void main(String[] argv) throws Exception {
+ // any signature implementation will do as long as
+ // it needs a random source
+ Provider p = Security.getProvider("SUN");
+ KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA", p);
+ kpg.initialize(512);
+ KeyPair kp = kpg.generateKeyPair();
+ TestRandomSource rand = new TestRandomSource();
+ Signature sig = Signature.getInstance("DSA", p);
+ sig.initSign(kp.getPrivate(), rand);
+ sig.update(new byte[20]);
+ sig.sign();
+ if (rand.isUsed()) {
+ System.out.println("Custom random source is used.");
+ } else {
+ throw new Exception("Custom random source is not used");
+ }
+ }
+}
+
+class TestRandomSource extends SecureRandom {
+
+ int count = 0;
+
+ public int nextInt() {
+ count++;
+ return 0;
+ }
+
+ public boolean isUsed() {
+ return (count != 0);
+ }
+}