author | valeriep |
Tue, 03 Dec 2013 17:23:58 -0800 | |
changeset 21962 | fb94f324e7f3 |
parent 21848 | 3902d25a64b1 |
child 30046 | cf2c86e1819e |
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 |
/* |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
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 |
*/ |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
23 |
/* |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
24 |
* @test |
21962
fb94f324e7f3
8029158: sun/security/pkcs11/Signature/TestDSAKeyLength.java does not compile (or run)
valeriep
parents:
21848
diff
changeset
|
25 |
* @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
|
26 |
* @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
|
27 |
* with unsupported key sizes |
21962
fb94f324e7f3
8029158: sun/security/pkcs11/Signature/TestDSAKeyLength.java does not compile (or run)
valeriep
parents:
21848
diff
changeset
|
28 |
* @library .. |
21848
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
29 |
*/ |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
30 |
|
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
31 |
|
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
32 |
import java.security.*; |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
33 |
import java.security.spec.*; |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
34 |
import java.security.interfaces.*; |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
35 |
|
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
36 |
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
|
37 |
|
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
38 |
public static void main(String[] args) throws Exception { |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
39 |
main(new TestDSAKeyLength()); |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
40 |
} |
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 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
|
43 |
if (isNSS(provider) && getNSSVersion() >= 3.14) { |
fb94f324e7f3
8029158: sun/security/pkcs11/Signature/TestDSAKeyLength.java does not compile (or run)
valeriep
parents:
21848
diff
changeset
|
44 |
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
|
45 |
return; |
fb94f324e7f3
8029158: sun/security/pkcs11/Signature/TestDSAKeyLength.java does not compile (or run)
valeriep
parents:
21848
diff
changeset
|
46 |
} |
fb94f324e7f3
8029158: sun/security/pkcs11/Signature/TestDSAKeyLength.java does not compile (or run)
valeriep
parents:
21848
diff
changeset
|
47 |
|
21848
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
|
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
52 |
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
|
53 |
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
|
54 |
try { |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
55 |
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
|
56 |
status = false; |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
57 |
} 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
|
58 |
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
|
59 |
} |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
60 |
try { |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
61 |
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
|
62 |
status = false; |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
63 |
} 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
|
64 |
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
|
65 |
} |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
66 |
if (status) { |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
67 |
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
|
68 |
} else { |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
69 |
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
|
70 |
} |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
71 |
} |
3902d25a64b1
7200306: SunPKCS11 provider delays the check of DSA key size for SHA1withDSA to sign() instead of init()
valeriep
parents:
diff
changeset
|
72 |
} |