author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 57586 | f459f98aa30d |
permissions | -rw-r--r-- |
57538
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
1 |
/* |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
4 |
* |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
8 |
* |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
13 |
* accompanied this code). |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
14 |
* |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
18 |
* |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
21 |
* questions. |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
22 |
*/ |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
23 |
|
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
24 |
/* |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
25 |
* @test |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
26 |
* @bug 8180392 |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
27 |
* @summary Ensure SunJCE provider throws exception for unsupported modes |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
28 |
* and padding combinations |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
29 |
*/ |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
30 |
import java.security.*; |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
31 |
import java.security.spec.AlgorithmParameterSpec; |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
32 |
import javax.crypto.*; |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
33 |
|
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
34 |
public class TestNoPaddingModes { |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
35 |
|
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
36 |
// SunJCE only supports NoPadding with following modes |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
37 |
private static final String[] MODES = { |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
38 |
"CTR", "CTS", "GCM" |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
39 |
}; |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
40 |
private static final String[] PADDINGS = { |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
41 |
"PKCS5Padding", "ISO10126Padding" |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
42 |
}; |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
43 |
|
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
44 |
public static void main(String[] args) throws Exception { |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
45 |
Provider p = Security.getProvider("SunJCE"); |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
46 |
String transformation; |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
47 |
for (String mode : MODES) { |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
48 |
for (String padding : PADDINGS) { |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
49 |
transformation = "AES/" + mode + "/" + padding; |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
50 |
|
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
51 |
System.out.println("Test using " + transformation); |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
52 |
try { |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
53 |
Cipher c = Cipher.getInstance(transformation, "SunJCE"); |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
54 |
throw new RuntimeException("=> Fail, no exception thrown"); |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
55 |
} catch (NoSuchAlgorithmException | NoSuchPaddingException ex) { |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
56 |
System.out.println("=> Expected ex: " + ex); |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
57 |
} |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
58 |
try { |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
59 |
Cipher c = Cipher.getInstance(transformation, p); |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
60 |
throw new RuntimeException("=> Fail, no exception thrown"); |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
61 |
} catch (NoSuchAlgorithmException | NoSuchPaddingException ex) { |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
62 |
System.out.println("=> Expected ex: " + ex); |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
63 |
} |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
64 |
} |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
65 |
} |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
66 |
System.out.println("Test Passed"); |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
67 |
} |
445c32471dc6
8180392: SunJCE provider should throw exceptions for unsupported mode and padding combinations
valeriep
parents:
diff
changeset
|
68 |
} |