jdk/test/sun/security/provider/SeedGenerator/SeedGeneratorChoice.java
author ssahoo
Fri, 20 May 2016 09:57:01 -0700
changeset 38447 435b76ccc9e3
parent 38423 5d6ff7d76bf4
child 45028 b0ea3c0bfb81
permissions -rw-r--r--
8157417: Some of SecureRandom test might get timed out in linux Reviewed-by: weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7546
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
     1
/*
38423
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
     2
 * Copyright (c) 2010, 2011, 2016, Oracle and/or its affiliates. All rights
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
     3
 * reserved.
8168
fd0dd3dc997d 7016897: Copyright header correction : test/sun/security/provider/SeedGenerator/SeedGeneratorChoice.java
coffeys
parents: 7546
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7546
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
     5
 *
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
     8
 * published by the Free Software Foundation.
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
     9
 *
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    14
 * accompanied this code).
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    15
 *
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    19
 *
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    22
 * questions.
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    23
 */
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    24
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    25
/*
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    26
 * @test
38423
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
    27
 * @bug 6998583 8141039
7546
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    28
 * @summary NativeSeedGenerator is making 8192 byte read requests from
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    29
 *             entropy pool on each init.
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    30
 * @run main/othervm -Djava.security.egd=file:/dev/random SeedGeneratorChoice
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    31
 * @run main/othervm -Djava.security.egd=file:filename  SeedGeneratorChoice
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    32
 */
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    33
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    34
/*
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    35
 * Side testcase introduced to ensure changes for 6998583 will always
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    36
 * succeed in falling back to ThreadedSeedGenerator if issues are found
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    37
 * with the native OS generator request. We should never see an exception
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    38
 * causing exit.
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    39
 * We should always fall back to the ThreadedSeedGenerator if exceptions
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    40
 * are encountered with user defined source of entropy.
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    41
 */
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    42
import java.security.SecureRandom;
38423
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
    43
import java.security.Security;
7546
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    44
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    45
public class SeedGeneratorChoice {
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    46
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    47
    public static void main(String... arguments) throws Exception {
38423
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
    48
        for (String mech : new String[]{"SHA1PRNG", "Hash_DRBG", "HMAC_DRBG",
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
    49
            "CTR_DRBG"}) {
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
    50
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
    51
            SecureRandom prng = null;
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
    52
            if (!mech.contains("_DRBG")) {
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
    53
                prng = SecureRandom.getInstance(mech);
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
    54
            } else {
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
    55
                Security.setProperty("securerandom.drbg.config", mech);
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
    56
                prng = SecureRandom.getInstance("DRBG");
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
    57
            }
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
    58
            prng.generateSeed(1);
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
    59
        }
7546
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    60
    }
38423
5d6ff7d76bf4 8141039: Test Task: Develop new tests for JEP 273: DRBG-Based SecureRandom Implementations
ssahoo
parents: 8168
diff changeset
    61
7546
c1915029b924 6998583: NativeSeedGenerator is making 8192 byte read requests from entropy pool on each init.
coffeys
parents:
diff changeset
    62
}