1 /*
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
90 public static void invalidAlg(String value) throws NoSuchPaddingException {
91 String[] arrays = value.split(":");
92
93 try {
94 Security.setProperty(SEC_PREF_PROP, value);
95 Cipher.getInstance(arrays[0]);
96 } catch (NoSuchAlgorithmException e) {
97 System.out.println(
98 "Test Pass:Got NoSuchAlgorithmException as expired");
99 return;
100 }
101 throw new RuntimeException(
102 "Test Failed:Expected NoSuchAlgorithmException was not thrown");
103 }
104
105 public static void main(String[] args)
106 throws NoSuchAlgorithmException, NoSuchPaddingException {
107
108 String expected;
109 String value = args[1];
110 // If OS is solaris, expect OracleUcrypto, otherwise SunJCE
111 if (System.getProperty("os.name").toLowerCase().contains("sun")) {
112 expected = "OracleUcrypto";
113 } else {
114 expected = "SunJCE";
115 }
116
117 if (args.length >= 2) {
118 switch (args[0]) {
119 case "preSet":
120 boolean negativeProvider = Boolean.valueOf(args[2]);
121 if (!args[1].contains(":")) {
122 value += ":" + expected;
123 }
124 PreferredProviderNegativeTest.preJCESet(
125 value, negativeProvider);
126 break;
127 case "afterSet":
128 PreferredProviderNegativeTest.afterJCESet(args[1],
129 expected);
130 break;
131 case "invalidAlg":
132 PreferredProviderNegativeTest.invalidAlg(args[1]);
133 break;
134 }
135 } else {
|
1 /*
2 * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
90 public static void invalidAlg(String value) throws NoSuchPaddingException {
91 String[] arrays = value.split(":");
92
93 try {
94 Security.setProperty(SEC_PREF_PROP, value);
95 Cipher.getInstance(arrays[0]);
96 } catch (NoSuchAlgorithmException e) {
97 System.out.println(
98 "Test Pass:Got NoSuchAlgorithmException as expired");
99 return;
100 }
101 throw new RuntimeException(
102 "Test Failed:Expected NoSuchAlgorithmException was not thrown");
103 }
104
105 public static void main(String[] args)
106 throws NoSuchAlgorithmException, NoSuchPaddingException {
107
108 String expected;
109 String value = args[1];
110 expected = "SunJCE";
111
112 if (args.length >= 2) {
113 switch (args[0]) {
114 case "preSet":
115 boolean negativeProvider = Boolean.valueOf(args[2]);
116 if (!args[1].contains(":")) {
117 value += ":" + expected;
118 }
119 PreferredProviderNegativeTest.preJCESet(
120 value, negativeProvider);
121 break;
122 case "afterSet":
123 PreferredProviderNegativeTest.afterJCESet(args[1],
124 expected);
125 break;
126 case "invalidAlg":
127 PreferredProviderNegativeTest.invalidAlg(args[1]);
128 break;
129 }
130 } else {
|