author | stefank |
Mon, 04 Apr 2016 09:15:01 +0200 | |
changeset 37241 | b9961c99c356 |
parent 35379 | 1e8e336ef66b |
child 40975 | 680639c9b307 |
permissions | -rw-r--r-- |
21848
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
1 |
/* |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
32138
diff
changeset
|
2 |
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. |
21848
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
4 |
* |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
8 |
* |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
13 |
* accompanied this code). |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
14 |
* |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
18 |
* |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
21 |
* questions. |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
22 |
*/ |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
32138
diff
changeset
|
23 |
|
21848
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
24 |
/* |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
25 |
* @test |
21962
fb94f324e7f3
8029158: sun/security/pkcs11/Signature/TestDSAKeyLength.java does not compile (or run)
valeriep
parents:
21848
diff
changeset
|
26 |
* @bug 7200306 8029158 |
21848
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
27 |
* @summary verify that P11Signature impl will error out when initialized |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
28 |
* with unsupported key sizes |
21962
fb94f324e7f3
8029158: sun/security/pkcs11/Signature/TestDSAKeyLength.java does not compile (or run)
valeriep
parents:
21848
diff
changeset
|
29 |
* @library .. |
30046 | 30 |
* @key randomness |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
32138
diff
changeset
|
31 |
* @run main/othervm TestDSAKeyLength |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
32138
diff
changeset
|
32 |
* @run main/othervm TestDSAKeyLength sm |
21848
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
33 |
*/ |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
34 |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
32138
diff
changeset
|
35 |
import java.security.InvalidKeyException; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
32138
diff
changeset
|
36 |
import java.security.KeyPair; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
32138
diff
changeset
|
37 |
import java.security.KeyPairGenerator; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
32138
diff
changeset
|
38 |
import java.security.Provider; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
32138
diff
changeset
|
39 |
import java.security.SecureRandom; |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
32138
diff
changeset
|
40 |
import java.security.Signature; |
21848
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
41 |
|
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
42 |
public class TestDSAKeyLength extends PKCS11Test { |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
43 |
|
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
44 |
public static void main(String[] args) throws Exception { |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
32138
diff
changeset
|
45 |
main(new TestDSAKeyLength(), args); |
21848
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
46 |
} |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
47 |
|
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
32138
diff
changeset
|
48 |
@Override |
21848
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
49 |
public void main(Provider provider) throws Exception { |
21962
fb94f324e7f3
8029158: sun/security/pkcs11/Signature/TestDSAKeyLength.java does not compile (or run)
valeriep
parents:
21848
diff
changeset
|
50 |
if (isNSS(provider) && getNSSVersion() >= 3.14) { |
fb94f324e7f3
8029158: sun/security/pkcs11/Signature/TestDSAKeyLength.java does not compile (or run)
valeriep
parents:
21848
diff
changeset
|
51 |
System.out.println("Skip testing NSS " + getNSSVersion()); |
fb94f324e7f3
8029158: sun/security/pkcs11/Signature/TestDSAKeyLength.java does not compile (or run)
valeriep
parents:
21848
diff
changeset
|
52 |
return; |
fb94f324e7f3
8029158: sun/security/pkcs11/Signature/TestDSAKeyLength.java does not compile (or run)
valeriep
parents:
21848
diff
changeset
|
53 |
} |
fb94f324e7f3
8029158: sun/security/pkcs11/Signature/TestDSAKeyLength.java does not compile (or run)
valeriep
parents:
21848
diff
changeset
|
54 |
|
32138
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
30046
diff
changeset
|
55 |
/* |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
30046
diff
changeset
|
56 |
* Use Solaris SPARC 11.2 or later to avoid an intermittent failure |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
30046
diff
changeset
|
57 |
* when running SunPKCS11-Solaris (8044554) |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
30046
diff
changeset
|
58 |
*/ |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
30046
diff
changeset
|
59 |
if (provider.getName().equals("SunPKCS11-Solaris") && |
35379
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
32138
diff
changeset
|
60 |
props.getProperty("os.name").equals("SunOS") && |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
32138
diff
changeset
|
61 |
props.getProperty("os.arch").equals("sparcv9") && |
1e8e336ef66b
8144539: Update PKCS11 tests to run with security manager
asmotrak
parents:
32138
diff
changeset
|
62 |
props.getProperty("os.version").compareTo("5.11") <= 0 && |
32138
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
30046
diff
changeset
|
63 |
getDistro().compareTo("11.2") < 0) { |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
30046
diff
changeset
|
64 |
|
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
30046
diff
changeset
|
65 |
System.out.println("SunPKCS11-Solaris provider requires " + |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
30046
diff
changeset
|
66 |
"Solaris SPARC 11.2 or later, skipping"); |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
30046
diff
changeset
|
67 |
return; |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
30046
diff
changeset
|
68 |
} |
23830562d3d1
8133318: Exclude intermittent failing PKCS11 tests on Solaris SPARC 11.1 and earlier
vinnie
parents:
30046
diff
changeset
|
69 |
|
21848
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
70 |
KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA", "SUN"); |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
71 |
kpg.initialize(2048, new SecureRandom()); |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
72 |
KeyPair pair = kpg.generateKeyPair(); |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
73 |
|
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
74 |
boolean status = true; |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
75 |
Signature sig = Signature.getInstance("SHA1withDSA", provider); |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
76 |
try { |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
77 |
sig.initSign(pair.getPrivate()); |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
78 |
status = false; |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
79 |
} catch (InvalidKeyException ike) { |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
80 |
System.out.println("Expected IKE thrown for initSign()"); |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
81 |
} |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
82 |
try { |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
83 |
sig.initVerify(pair.getPublic()); |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
84 |
status = false; |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
85 |
} catch (InvalidKeyException ike) { |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
86 |
System.out.println("Expected IKE thrown for initVerify()"); |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
87 |
} |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
88 |
if (status) { |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
89 |
System.out.println("Test Passed"); |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
90 |
} else { |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
91 |
throw new Exception("Test Failed - expected IKE not thrown"); |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
92 |
} |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
93 |
} |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
94 |
} |