1
10package org.jstk.pki;
11
12import java.io.*;
13
14import org.jstk.asn1.*;
15import org.jstk.pem.*;
16import org.jstk.JSTKOptions;
17
18
24public class CertificateList extends ASN1Seq{
25 private TBSCertList tbsCertList = new TBSCertList();
26 private AlgorithmIdentifier algorithm = new AlgorithmIdentifier();
27 private ASN1BitString signatureBytes = new ASN1BitString();
28
29 public CertificateList(){
30 super();
31 add(tbsCertList);
32 add(algorithm);
33 add(signatureBytes);
34 }
35
36 public TBSCertList getTBSCertList(){
37 return tbsCertList;
38 }
39
40 public AlgorithmIdentifier getAlgorithm(){
41 return algorithm;
42 }
43
44 public ASN1BitString getSignatureBytes(){
45 return signatureBytes;
46 }
47
48 public String toString(){
49 StringBuffer sb = new StringBuffer();
50 sb.append("CertificateList-SEQ(" + tbsCertList.toString() + ", ");
51 sb.append(algorithm.toString() + ", " + signatureBytes.toString() + ")");
52 return sb.toString();
53 }
54 public static void main(String[] args) throws Exception {
55 if (args.length < 1){
56 System.out.println("Usage::java org.jstk.pki.CertificateList <file> [-encode <outfile>]");
57 return;
58 }
59 String file = args[0];
60 InputStream is = PEMData.getDERInputStream(file);
61
62 ASN1PullParser parser = DefASN1PullParser.getInstance(is);
63 parser.setInput(is);
64
65 CertificateList certList = new CertificateList();
66 certList.decode(parser);
67 System.out.println(certList.toString());
68
69 JSTKOptions opts = new JSTKOptions();
70 opts.parse(args, 1);
71 String outfile = opts.get("encode");
72 if (outfile != null){
73 System.out.println("Writing the data in DER format to file: " + outfile);
74 FileOutputStream fos = new FileOutputStream(outfile);
75 byte[] encoded = certList.encode();
76 fos.write(encoded);
77 fos.close();
78 }
79 }
80}
81
82