7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8141039
27 * @library /lib/testlibrary
28 * @summary When random number is generated through the a SecureRandom instance
29 * as well from it's serialized instance in the same time then the
30 * generated random numbers should be different when one or both are
31 * reseeded.
32 * @run main/othervm -Djava.security.egd=file:/dev/urandom SerializedSeedTest
33 */
34 import java.io.ByteArrayOutputStream;
35 import java.io.IOException;
36 import java.io.ObjectInputStream;
37 import java.io.ObjectOutputStream;
38 import java.io.ByteArrayInputStream;
39 import java.security.NoSuchAlgorithmException;
40 import java.security.SecureRandom;
41 import java.security.Security;
42 import jdk.testlibrary.Asserts;
43
44 public class SerializedSeedTest {
45
46 private static final byte[] SEED = "seed".getBytes();
47 private static final String DRBG_CONFIG = "securerandom.drbg.config";
48 private static final String DRBG_CONFIG_VALUE
49 = Security.getProperty(DRBG_CONFIG);
50
51 public static void main(String[] args) {
52 boolean success = true;
53
54 for (String mech : new String[]{
55 "SHA1PRNG", "Hash_DRBG", "HMAC_DRBG", "CTR_DRBG"}) {
56 System.out.printf(
57 "%nRunning test for SecureRandom mechanism: '%s'", mech);
58 try {
59 // Serialize without seed and compare generated random numbers
60 // produced through original and serialized instances.
61 SecureRandom orig = getSRInstance(mech);
62 SecureRandom copy = deserializedCopy(orig);
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8141039
27 * @library /test/lib
28 * @summary When random number is generated through the a SecureRandom instance
29 * as well from it's serialized instance in the same time then the
30 * generated random numbers should be different when one or both are
31 * reseeded.
32 * @run main/othervm -Djava.security.egd=file:/dev/urandom SerializedSeedTest
33 */
34 import java.io.ByteArrayOutputStream;
35 import java.io.IOException;
36 import java.io.ObjectInputStream;
37 import java.io.ObjectOutputStream;
38 import java.io.ByteArrayInputStream;
39 import java.security.NoSuchAlgorithmException;
40 import java.security.SecureRandom;
41 import java.security.Security;
42 import jdk.test.lib.Asserts;
43
44 public class SerializedSeedTest {
45
46 private static final byte[] SEED = "seed".getBytes();
47 private static final String DRBG_CONFIG = "securerandom.drbg.config";
48 private static final String DRBG_CONFIG_VALUE
49 = Security.getProperty(DRBG_CONFIG);
50
51 public static void main(String[] args) {
52 boolean success = true;
53
54 for (String mech : new String[]{
55 "SHA1PRNG", "Hash_DRBG", "HMAC_DRBG", "CTR_DRBG"}) {
56 System.out.printf(
57 "%nRunning test for SecureRandom mechanism: '%s'", mech);
58 try {
59 // Serialize without seed and compare generated random numbers
60 // produced through original and serialized instances.
61 SecureRandom orig = getSRInstance(mech);
62 SecureRandom copy = deserializedCopy(orig);
|