test/jdk/lib/security/CheckBlacklistedCerts.java
changeset 52075 40aa2d50d116
parent 51994 7577686cc9bd
equal deleted inserted replaced
52074:755b367c2134 52075:40aa2d50d116
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 8011402
    26  * @bug 8011402 8211969
    27  * @summary Move blacklisting certificate logic from hard code to data
    27  * @summary Move blacklisting certificate logic from hard code to data
    28  * @modules java.base/sun.security.util
    28  * @modules java.base/sun.security.util
    29  */
    29  */
    30 
    30 
    31 import sun.security.util.UntrustedCertificates;
    31 import sun.security.util.UntrustedCertificates;
    58 
    58 
    59         // All certs in the pem files
    59         // All certs in the pem files
    60         Set<Certificate> blacklisted = new HashSet<>();
    60         Set<Certificate> blacklisted = new HashSet<>();
    61 
    61 
    62         // Assumes the full src is available
    62         // Assumes the full src is available
    63         File[] blacklists = {
    63         File blacklist = new File(System.getProperty("test.src"),
    64             new File(System.getProperty("test.src"),
    64                 "../../../../make/data/blacklistedcertsconverter/blacklisted.certs.pem");
    65                 "../../../make/data/blacklistedcertsconverter/blacklisted.certs.pem"),
       
    66             new File(System.getProperty("test.src"),
       
    67                 "../../../make/closed/data/blacklistedcertsconverter/blacklisted.certs.pem")
       
    68         };
       
    69 
       
    70         // Is this an OPENJDK build?
       
    71         String prop = System.getProperty("java.runtime.name");
       
    72         if (prop != null && prop.startsWith("OpenJDK")) {
       
    73             System.out.println("This is a OpenJDK build.");
       
    74             blacklists = Arrays.copyOf(blacklists, 1);
       
    75         }
       
    76 
    65 
    77         CertificateFactory cf = CertificateFactory.getInstance("X.509");
    66         CertificateFactory cf = CertificateFactory.getInstance("X.509");
    78         for (File blacklist: blacklists) {
    67         try (FileInputStream fis = new FileInputStream(blacklist)) {
    79             System.out.print("Check for " + blacklist + ": ");
    68             Collection<? extends Certificate> certs
    80             if (!blacklist.exists()) {
    69                     = cf.generateCertificates(fis);
    81                 System.out.println("does not exist");
    70             System.out.println(certs.size());
    82             } else {
    71             for (Certificate c: certs) {
    83                 try (FileInputStream fis = new FileInputStream(blacklist)) {
    72                 blacklisted.add(c);
    84                     Collection<? extends Certificate> certs
    73                 X509Certificate cert = ((X509Certificate)c);
    85                             = cf.generateCertificates(fis);
    74                 if (!UntrustedCertificates.isUntrusted(cert)) {
    86                     System.out.println(certs.size());
    75                     System.out.println(cert.getSubjectDN() + " is trusted");
    87                     for (Certificate c: certs) {
    76                     failed = true;
    88                         blacklisted.add(c);
       
    89                         X509Certificate cert = ((X509Certificate)c);
       
    90                         if (!UntrustedCertificates.isUntrusted(cert)) {
       
    91                             System.out.println(cert.getSubjectDN() + " is trusted");
       
    92                             failed = true;
       
    93                         }
       
    94                     }
       
    95                 }
    77                 }
    96             }
    78             }
    97         }
    79         }
    98 
    80 
    99         // Check the blacklisted.certs file itself
    81         // Check the blacklisted.certs file itself