|
1 /* |
|
2 * Copyright (c) 2013, 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 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 7171982 |
|
27 * @summary Test that SunJCE.getInstance() is retrieving a provider when |
|
28 * SunJCE has been removed from the provider list. |
|
29 */ |
|
30 |
|
31 import java.security.Security; |
|
32 import javax.crypto.Cipher; |
|
33 import javax.crypto.spec.SecretKeySpec; |
|
34 |
|
35 |
|
36 public class SunJCEGetInstance { |
|
37 public static void main(String[] args) throws Exception { |
|
38 Cipher jce; |
|
39 |
|
40 try{ |
|
41 // Remove SunJCE from Provider list |
|
42 Security.removeProvider("SunJCE"); |
|
43 |
|
44 // Create our own instance of SunJCE provider. Purposefully not |
|
45 // using SunJCE.getInstance() so we can have our own instance |
|
46 // for the test. |
|
47 jce = Cipher.getInstance("AES/CBC/PKCS5Padding", |
|
48 new com.sun.crypto.provider.SunJCE()); |
|
49 |
|
50 jce.init(Cipher.ENCRYPT_MODE, |
|
51 new SecretKeySpec("1234567890abcedf".getBytes(), "AES")); |
|
52 jce.doFinal("PlainText".getBytes()); |
|
53 } catch (Exception e) { |
|
54 System.err.println("Setup failure: "); |
|
55 throw e; |
|
56 } |
|
57 |
|
58 // Get parameters which will call SunJCE.getInstance(). Failure |
|
59 // would occur on this line. |
|
60 try { |
|
61 jce.getParameters().getEncoded(); |
|
62 |
|
63 } catch (Exception e) { |
|
64 System.err.println("Test Failure"); |
|
65 throw e; |
|
66 } |
|
67 System.out.println("Passed"); |
|
68 } |
|
69 } |