jdk/test/sun/security/pkcs11/Secmod/AddTrustedCert.java
changeset 35379 1e8e336ef66b
parent 32635 d7e4ba3c2e0d
child 40975 680639c9b307
equal deleted inserted replaced
35378:7e19fa0e4e5b 35379:1e8e336ef66b
     1 /*
     1 /*
     2  * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2005, 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.
    26  * @bug 6298106
    26  * @bug 6298106
    27  * @summary make sure we can add a trusted cert to the NSS KeyStore module
    27  * @summary make sure we can add a trusted cert to the NSS KeyStore module
    28  * @author Andreas Sterbenz
    28  * @author Andreas Sterbenz
    29  * @library ..
    29  * @library ..
    30  * @run main/othervm AddTrustedCert
    30  * @run main/othervm AddTrustedCert
       
    31  * @run main/othervm AddTrustedCert sm policy
    31  */
    32  */
    32 
    33 
    33 import java.io.*;
    34 import java.io.File;
    34 import java.util.*;
    35 import java.io.FileInputStream;
    35 
    36 import java.io.InputStream;
    36 import java.security.*;
    37 import java.security.KeyStore;
    37 import java.security.KeyStore.*;
    38 import java.security.KeyStore.TrustedCertificateEntry;
    38 import java.security.cert.*;
    39 import java.security.Provider;
       
    40 import java.security.Security;
       
    41 import java.security.cert.CertificateFactory;
       
    42 import java.security.cert.X509Certificate;
       
    43 import java.util.Collection;
       
    44 import java.util.Collections;
       
    45 import java.util.TreeSet;
    39 
    46 
    40 public class AddTrustedCert extends SecmodTest {
    47 public class AddTrustedCert extends SecmodTest {
    41 
    48 
    42     public static void main(String[] args) throws Exception {
    49     public static void main(String[] args) throws Exception {
    43         if (initSecmod() == false) {
    50         if (initSecmod() == false) {
    54         String configName = BASE + SEP + "nss.cfg";
    61         String configName = BASE + SEP + "nss.cfg";
    55         Provider p = getSunPKCS11(configName);
    62         Provider p = getSunPKCS11(configName);
    56 
    63 
    57         System.out.println(p);
    64         System.out.println(p);
    58         Security.addProvider(p);
    65         Security.addProvider(p);
       
    66 
       
    67         if (args.length > 1 && "sm".equals(args[0])) {
       
    68             System.setProperty("java.security.policy",
       
    69                     BASE + File.separator + args[1]);
       
    70             System.setSecurityManager(new SecurityManager());
       
    71         }
       
    72 
    59         KeyStore ks = KeyStore.getInstance(PKCS11, p);
    73         KeyStore ks = KeyStore.getInstance(PKCS11, p);
    60         ks.load(null, password);
    74         ks.load(null, password);
    61         Collection<String> aliases = new TreeSet<>(Collections.list(
    75         Collection<String> aliases = new TreeSet<>(Collections.list(
    62                 ks.aliases()));
    76                 ks.aliases()));
    63         System.out.println("entries: " + aliases.size());
    77         System.out.println("entries: " + aliases.size());