1 /*
2  * @(#) $Id: ShowCRL.java,v 1.2 2003/07/08 08:13:52 pankaj Exp $
3  *
4  * Copyright (c) 2002-03 by Pankaj Kumar (http://www.pankaj-k.net). 
5  * All rights reserved.
6  *
7  * The license governing the use of this file can be found in the 
8  * root directory of the containing software.
9  */
10import java.util.Iterator;
11import java.util.Set;
12import java.security.cert.X509CRL;
13import java.security.cert.X509CRLEntry;
14import java.security.cert.CertificateFactory;
15import java.io.FileInputStream;
16
17public class ShowCRL {
18    private static void display(String str){
19        System.out.println(str);
20    }
21    public static void printX509CRL(X509CRL crl){
22        display("CRL:");
23        display("  Version: " + crl.getVersion());
24        display("  Signature Algorithm: " + crl.getSigAlgName());
25        display("  Issuer: " + crl.getIssuerX500Principal());
26        display("  This Update: " + crl.getThisUpdate());
27        display("  Next Update: " + crl.getNextUpdate());
28
29        Set revokedCerts = crl.getRevokedCertificates();
30        if (revokedCerts == null)
31            return;
32        Iterator itr = revokedCerts.iterator();
33        int index = 0;
34        while (itr.hasNext()){
35            printX509CRLEntry((X509CRLEntry)itr.next(), index);
36            ++index;
37        }
38    }
39
40    public static void printX509CRLEntry(X509CRLEntry crlEntry, int index){
41        display("  CRLEntry[" + index + "]:");
42        display("    Serial Number: " + crlEntry.getSerialNumber());
43        display("    Revocation Date: " + crlEntry.getRevocationDate());
44    }
45
46    public static void main(String[] args) throws Exception{
47        if (args.length < 1){
48            System.out.println("Usage:: java ShowCRL <crlfile>");
49            return;
50        }
51        String crlfile = args[0];
52
53        CertificateFactory cf = CertificateFactory.getInstance("X.509");
54        FileInputStream fis = new FileInputStream(crlfile);
55        X509CRL crl = (X509CRL)cf.generateCRL(fis);
56        printX509CRL(crl);
57    }
58}