jdk/test/sun/security/pkcs11/Secmod/LoadKeystore.java
changeset 35379 1e8e336ef66b
parent 32635 d7e4ba3c2e0d
child 40975 680639c9b307
equal deleted inserted replaced
35378:7e19fa0e4e5b 35379:1e8e336ef66b
     1 /*
     1 /*
     2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
     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.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    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
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
       
    24 import java.io.File;
    24 import java.io.IOException;
    25 import java.io.IOException;
    25 import java.security.KeyStore;
    26 import java.security.KeyStore;
    26 import java.security.KeyStoreException;
    27 import java.security.KeyStoreException;
    27 import java.security.Provider;
    28 import java.security.Provider;
    28 import java.security.Security;
    29 import java.security.Security;
    33  * @test
    34  * @test
    34  * @bug 8048622 8134232
    35  * @bug 8048622 8134232
    35  * @summary Checks that PKCS#11 keystore can't be loaded with wrong password
    36  * @summary Checks that PKCS#11 keystore can't be loaded with wrong password
    36  * @library ../
    37  * @library ../
    37  * @run main/othervm LoadKeystore
    38  * @run main/othervm LoadKeystore
       
    39  * @run main/othervm LoadKeystore sm policy
    38  */
    40  */
    39 public class LoadKeystore extends SecmodTest {
    41 public class LoadKeystore extends SecmodTest {
    40 
    42 
    41     public static void main(String[] args) throws Exception {
    43     public static void main(String[] args) throws Exception {
    42         if (!initSecmod()) {
    44         if (!initSecmod()) {
    47         Provider p = getSunPKCS11(configName);
    49         Provider p = getSunPKCS11(configName);
    48 
    50 
    49         System.out.println("Add provider " + p);
    51         System.out.println("Add provider " + p);
    50         System.out.println();
    52         System.out.println();
    51         Security.addProvider(p);
    53         Security.addProvider(p);
       
    54 
       
    55         if (args.length > 1 && "sm".equals(args[0])) {
       
    56             System.setProperty("java.security.policy",
       
    57                     BASE + File.separator + args[1]);
       
    58             System.setSecurityManager(new SecurityManager());
       
    59         }
    52 
    60 
    53         try {
    61         try {
    54             System.out.println("Load keystore with wrong type");
    62             System.out.println("Load keystore with wrong type");
    55             KeyStore.getInstance("unknown", p);
    63             KeyStore.getInstance("unknown", p);
    56             throw new RuntimeException("Expected exception not thrown");
    64             throw new RuntimeException("Expected exception not thrown");