jdk/test/sun/security/pkcs11/rsa/TestCACerts.java
changeset 35379 1e8e336ef66b
parent 32138 23830562d3d1
child 40975 680639c9b307
equal deleted inserted replaced
35378:7e19fa0e4e5b 35379:1e8e336ef66b
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 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 4856966
    26  * @bug 4856966
    27  * @summary Test the new RSA provider can verify all the RSA certs in the cacerts file
    27  * @summary Test the new RSA provider can verify all the RSA certs in the cacerts file
    28  * @author Andreas Sterbenz
    28  * @author Andreas Sterbenz
    29  * @library ..
    29  * @library ..
    30  * @library ../../../../java/security/testlibrary
    30  * @library ../../../../java/security/testlibrary
       
    31  * @run main/othervm TestCACerts
       
    32  * @run main/othervm TestCACerts sm TestCACerts.policy
    31  */
    33  */
    32 
    34 
    33 // this test serves as our known answer test
    35 // this test serves as our known answer test
    34 
    36 
    35 import java.io.*;
    37 import java.io.FileInputStream;
    36 import java.util.*;
    38 import java.io.InputStream;
    37 
    39 import java.security.KeyStore;
    38 import java.security.*;
    40 import java.security.Provider;
    39 import java.security.cert.*;
    41 import java.security.PublicKey;
       
    42 import java.security.Security;
       
    43 import java.security.cert.X509Certificate;
       
    44 import java.util.Enumeration;
    40 
    45 
    41 public class TestCACerts extends PKCS11Test {
    46 public class TestCACerts extends PKCS11Test {
    42 
    47 
    43     private final static char SEP = File.separatorChar;
       
    44 
       
    45     public static void main(String[] args) throws Exception {
    48     public static void main(String[] args) throws Exception {
    46         main(new TestCACerts());
    49         main(new TestCACerts(), args);
    47     }
    50     }
    48 
    51 
       
    52     @Override
    49     public void main(Provider p) throws Exception {
    53     public void main(Provider p) throws Exception {
    50 
    54 
    51         /*
    55         /*
    52          * Use Solaris SPARC 11.2 or later to avoid an intermittent failure
    56          * Use Solaris SPARC 11.2 or later to avoid an intermittent failure
    53          * when running SunPKCS11-Solaris (8044554)
    57          * when running SunPKCS11-Solaris (8044554)
    54          */
    58          */
    55         if (p.getName().equals("SunPKCS11-Solaris") &&
    59         if (p.getName().equals("SunPKCS11-Solaris") &&
    56             System.getProperty("os.name").equals("SunOS") &&
    60             props.getProperty("os.name").equals("SunOS") &&
    57             System.getProperty("os.arch").equals("sparcv9") &&
    61             props.getProperty("os.arch").equals("sparcv9") &&
    58             System.getProperty("os.version").compareTo("5.11") <= 0 &&
    62             props.getProperty("os.version").compareTo("5.11") <= 0 &&
    59             getDistro().compareTo("11.2") < 0) {
    63             getDistro().compareTo("11.2") < 0) {
    60 
    64 
    61             System.out.println("SunPKCS11-Solaris provider requires " +
    65             System.out.println("SunPKCS11-Solaris provider requires " +
    62                 "Solaris SPARC 11.2 or later, skipping");
    66                 "Solaris SPARC 11.2 or later, skipping");
    63             return;
    67             return;
    65 
    69 
    66         long start = System.currentTimeMillis();
    70         long start = System.currentTimeMillis();
    67         Providers.setAt(p, 1);
    71         Providers.setAt(p, 1);
    68         try {
    72         try {
    69             String PROVIDER = p.getName();
    73             String PROVIDER = p.getName();
    70             String javaHome = System.getProperty("java.home");
    74             String javaHome = props.getProperty("java.home");
    71             String caCerts = javaHome + SEP + "lib" + SEP + "security" + SEP + "cacerts";
    75             String caCerts = javaHome + SEP + "lib" + SEP + "security" + SEP + "cacerts";
    72             InputStream in = new FileInputStream(caCerts);
    76             KeyStore ks;
    73             KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
    77             try (InputStream in = new FileInputStream(caCerts)) {
    74             ks.load(in, null);
    78                 ks = KeyStore.getInstance(KeyStore.getDefaultType());
    75             in.close();
    79                 ks.load(in, null);
       
    80             }
    76             for (Enumeration e = ks.aliases(); e.hasMoreElements(); ) {
    81             for (Enumeration e = ks.aliases(); e.hasMoreElements(); ) {
    77                 String alias = (String)e.nextElement();
    82                 String alias = (String)e.nextElement();
    78                 if (ks.isCertificateEntry(alias)) {
    83                 if (ks.isCertificateEntry(alias)) {
    79                     System.out.println("* Testing " + alias + "...");
    84                     System.out.println("* Testing " + alias + "...");
    80                     X509Certificate cert = (X509Certificate)ks.getCertificate(alias);
    85                     X509Certificate cert = (X509Certificate)ks.getCertificate(alias);