author | weijun |
Thu, 13 Jun 2019 23:53:21 +0800 | |
changeset 55380 | 22b3b7983ada |
permissions | -rw-r--r-- |
55380
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
1 |
/* |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
4 |
* |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
8 |
* |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
13 |
* accompanied this code). |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
14 |
* |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
18 |
* |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
21 |
* questions. |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
22 |
*/ |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
23 |
|
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
24 |
import java.security.InvalidKeyException; |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
25 |
import java.security.PublicKey; |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
26 |
import java.security.Signature; |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
27 |
import java.util.List; |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
28 |
|
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
29 |
/** |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
30 |
* @test |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
31 |
* @bug 8225180 |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
32 |
* @requires os.family == "windows" |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
33 |
* @summary SunMSCAPI Signature should throw InvalidKeyException when |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
34 |
* initialized with a null key |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
35 |
*/ |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
36 |
|
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
37 |
public class NullKey { |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
38 |
public static void main(String[] args) throws Exception { |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
39 |
for (String alg : List.of( |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
40 |
"SHA256withRSA", "SHA256withECDSA", "RSASSA-PSS")) { |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
41 |
Signature sig = Signature.getInstance(alg, "SunMSCAPI"); |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
42 |
try { |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
43 |
sig.initSign(null); |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
44 |
} catch (InvalidKeyException e) { |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
45 |
// Expected |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
46 |
} |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
47 |
try { |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
48 |
sig.initVerify((PublicKey)null); |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
49 |
} catch (InvalidKeyException e) { |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
50 |
// Expected |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
51 |
} |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
52 |
} |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
53 |
} |
22b3b7983ada
8225180: SignedObject with invalid Key not throwing the InvalidKeyException in Windows
weijun
parents:
diff
changeset
|
54 |
} |