test/jdk/sun/security/pkcs11/Secmod/AddPrivateKey.java
changeset 51460 97e361fe3433
parent 47216 71c04702a3d5
equal deleted inserted replaced
51459:7339b9e38182 51460:97e361fe3433
     1 /*
     1 /*
     2  * Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2006, 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.
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 6414980
    26  * @bug 6414980
    27  * @summary Test that the PKCS#11 KeyStore handles RSA, DSA, and EC keys
    27  * @summary Test that the PKCS#11 KeyStore handles RSA, DSA, and EC keys
    28  * @author Andreas Sterbenz
    28  * @author Andreas Sterbenz
    29  * @library ..
    29  * @library /test/lib ..
    30  * @modules jdk.crypto.cryptoki
    30  * @modules jdk.crypto.cryptoki
    31  * @run main/othervm AddPrivateKey
    31  * @run main/othervm AddPrivateKey
    32  * @run main/othervm AddPrivateKey sm policy
    32  * @run main/othervm AddPrivateKey sm policy
    33  */
    33  */
    34 
    34 
    61     private static final int MAX_LINE = 85;
    61     private static final int MAX_LINE = 85;
    62     private static final int DATA_LENGTH = 4096;
    62     private static final int DATA_LENGTH = 4096;
    63     private static final byte[] DATA = generateData(DATA_LENGTH);
    63     private static final byte[] DATA = generateData(DATA_LENGTH);
    64 
    64 
    65     public static void main(String[] args) throws Exception {
    65     public static void main(String[] args) throws Exception {
       
    66         if (args.length > 1 && "sm".equals(args[0])) {
       
    67             System.setProperty("java.security.policy",
       
    68                     BASE + File.separator + args[1]);
       
    69         }
       
    70 
    66         if (initSecmod() == false) {
    71         if (initSecmod() == false) {
    67             return;
    72             return;
    68         }
    73         }
    69 
    74 
    70         String configName = BASE + SEP + "nss.cfg";
    75         String configName = BASE + SEP + "nss.cfg";
    75         System.out.println(p);
    80         System.out.println(p);
    76         System.out.println();
    81         System.out.println();
    77         Security.addProvider(p);
    82         Security.addProvider(p);
    78 
    83 
    79         if (args.length > 1 && "sm".equals(args[0])) {
    84         if (args.length > 1 && "sm".equals(args[0])) {
    80             System.setProperty("java.security.policy",
       
    81                     BASE + File.separator + args[1]);
       
    82             System.setSecurityManager(new SecurityManager());
    85             System.setSecurityManager(new SecurityManager());
    83         }
    86         }
    84 
    87 
    85         KeyStore ks = KeyStore.getInstance(PKCS11, p);
    88         KeyStore ks = KeyStore.getInstance(PKCS11, p);
    86         ks.load(null, password);
    89         ks.load(null, password);