test/jdk/sun/security/pkcs11/Secmod/GetPrivateKey.java
changeset 51460 97e361fe3433
parent 47216 71c04702a3d5
equal deleted inserted replaced
51459:7339b9e38182 51460:97e361fe3433
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 2018, 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.
    25  * @test
    25  * @test
    26  * @bug 6273877 6322208 6275523
    26  * @bug 6273877 6322208 6275523
    27  * @summary make sure we can access the NSS softtoken KeyStore
    27  * @summary make sure we can access the NSS softtoken KeyStore
    28  *          and use a private key
    28  *          and use a private key
    29  * @author Andreas Sterbenz
    29  * @author Andreas Sterbenz
    30  * @library ..
    30  * @library /test/lib ..
    31  * @modules jdk.crypto.cryptoki
    31  * @modules jdk.crypto.cryptoki
    32  * @run main/othervm GetPrivateKey
    32  * @run main/othervm GetPrivateKey
    33  * @run main/othervm GetPrivateKey sm policy
    33  * @run main/othervm GetPrivateKey sm policy
    34  */
    34  */
    35 
    35 
    45 import java.util.TreeSet;
    45 import java.util.TreeSet;
    46 
    46 
    47 public class GetPrivateKey extends SecmodTest {
    47 public class GetPrivateKey extends SecmodTest {
    48 
    48 
    49     public static void main(String[] args) throws Exception {
    49     public static void main(String[] args) throws Exception {
       
    50         if (args.length > 1 && "sm".equals(args[0])) {
       
    51             System.setProperty("java.security.policy",
       
    52                     BASE + File.separator + args[1]);
       
    53         }
       
    54 
    50         if (initSecmod() == false) {
    55         if (initSecmod() == false) {
    51             return;
    56             return;
    52         }
    57         }
    53 
    58 
    54         String configName = BASE + SEP + "nss.cfg";
    59         String configName = BASE + SEP + "nss.cfg";
    56 
    61 
    57         System.out.println(p);
    62         System.out.println(p);
    58         Security.addProvider(p);
    63         Security.addProvider(p);
    59 
    64 
    60         if (args.length > 1 && "sm".equals(args[0])) {
    65         if (args.length > 1 && "sm".equals(args[0])) {
    61             System.setProperty("java.security.policy",
       
    62                     BASE + File.separator + args[1]);
       
    63             System.setSecurityManager(new SecurityManager());
    66             System.setSecurityManager(new SecurityManager());
    64         }
    67         }
    65 
    68 
    66         KeyStore ks = KeyStore.getInstance(PKCS11, p);
    69         KeyStore ks = KeyStore.getInstance(PKCS11, p);
    67         ks.load(null, password);
    70         ks.load(null, password);