1 /*
2  * @(#) $Id: TBSCertList.java,v 1.2 2003/07/08 08:13:53 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  */
10package org.jstk.pki;
11
12import java.io.*;
13
14import org.jstk.asn1.*;
15import org.jstk.pem.*;
16import java.math.BigInteger;
17
18/*
19 * TBSCertList ::= SEQUENCE {
20 *   version                    Version OPTIONAL, -- if present, shall be v2
21 *   signature                  AlgorithmIdentifier,
22 *   issuer                     Name,
23 *   thisUpdate                 Time,
24 *   nextUpdate                 Time OPTIONAL,
25 *   revokedCertificates        SEQUENCE OF SEQUENCE {
26 *      userCertificate             CertificateSerialNumber,
27 *      revocationDate              Time,
28 *      crlEntryExtensions          Extensions OPTIONAL,
29 *      } OPTIONAL,
30 *   crlExtensions          [0] EXPLICIT Extensions OPTIONAL
31 * }
32 */
33public class TBSCertList extends ASN1Seq{
34    public static class RevokedCert extends ASN1Seq {
35        public ASN1Integer userCertificate = new ASN1Integer();
36        public ASN1UTCTime revocationDate = new ASN1UTCTime();
37        public ASN1Seq crlEntryExtensions = new ASN1Seq();
38
39        public RevokedCert(){
40            super();
41            crlEntryExtensions.setOptional(true);
42
43            add(userCertificate);
44            add(revocationDate);
45            add(crlEntryExtensions);
46        }
47        public ASN1Integer getUserCertificate(){
48            return userCertificate;
49        }
50
51        public ASN1UTCTime getRevocationDate(){
52            return revocationDate;
53        }
54
55        public ASN1Seq getCRLEntryExtensions(){
56            return crlEntryExtensions;
57        }
58    }
59
60    public static class RevokedCerts extends ASN1Seq {
61        public RevokedCerts(){
62            super();
63        }
64    }
65
66    private ASN1Integer version = new ASN1Integer();
67    private AlgorithmIdentifier algorithm = new AlgorithmIdentifier();
68    private Name issuer = new Name();
69    private ASN1UTCTime thisUpdate = new ASN1UTCTime();
70    private ASN1UTCTime nextUpdate = new ASN1UTCTime();
71    private RevokedCerts revokedCerts = new RevokedCerts();
72    private ASN1Explicit crlExtensions = new ASN1Explicit(CONTEXT, EXPLICIT, 0);
73
74    public TBSCertList(){
75        super();
76        version.setOptional(true);
77        nextUpdate.setOptional(true);
78        revokedCerts.setOptional(true);
79        crlExtensions.setOptional(true);
80
81        add(version);
82        add(algorithm);
83        add(issuer);
84        add(thisUpdate);
85        add(nextUpdate);
86        add(revokedCerts);
87        add(crlExtensions);
88    }
89
90    public ASN1Integer getVersion(){
91        return version;
92    }
93
94    public AlgorithmIdentifier getAlgorithm(){
95        return algorithm;
96    }
97
98    public Name getIssuer(){
99        return issuer;
00    }
01
02    public ASN1UTCTime getThisUpdate(){
03        return thisUpdate;
04    }
05
06    public ASN1UTCTime getNextUpdate(){
07        return nextUpdate;
08    }
09
10    public RevokedCerts getRevokedCerts(){
11        return revokedCerts;
12    }
13
14    public ASN1Explicit getCRLExtensions(){
15        return crlExtensions;
16    }
17
18    public String toString(){
19        StringBuffer sb = new StringBuffer();
20        sb.append("TBSCertList-SEQ(" + version.toString() + ", ");
21        sb.append(algorithm.toString());
22        sb.append(", " + issuer.toString() + ", " + thisUpdate.toString());
23        sb.append(", " + nextUpdate.toString() + ", " + revokedCerts.toString() +
24            crlExtensions.toString() + ")");
25        return sb.toString();
26    }
27}
28
29