KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > util > asn1 > x509 > TBSCertificateStructure


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.util.asn1.x509;
19
20 import org.apache.geronimo.util.asn1.ASN1Encodable;
21 import org.apache.geronimo.util.asn1.ASN1Sequence;
22 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
23 import org.apache.geronimo.util.asn1.DERBitString;
24 import org.apache.geronimo.util.asn1.DERInteger;
25 import org.apache.geronimo.util.asn1.DERObject;
26 import org.apache.geronimo.util.asn1.DERTaggedObject;
27 import org.apache.geronimo.util.asn1.pkcs.PKCSObjectIdentifiers;
28
29 /**
30  * The TBSCertificate object.
31  * <pre>
32  * TBSCertificate ::= SEQUENCE {
33  * version [ 0 ] Version DEFAULT v1(0),
34  * serialNumber CertificateSerialNumber,
35  * signature AlgorithmIdentifier,
36  * issuer Name,
37  * validity Validity,
38  * subject Name,
39  * subjectPublicKeyInfo SubjectPublicKeyInfo,
40  * issuerUniqueID [ 1 ] IMPLICIT UniqueIdentifier OPTIONAL,
41  * subjectUniqueID [ 2 ] IMPLICIT UniqueIdentifier OPTIONAL,
42  * extensions [ 3 ] Extensions OPTIONAL
43  * }
44  * </pre>
45  * <p>
46  * Note: issuerUniqueID and subjectUniqueID are both deprecated by the IETF. This class
47  * will parse them, but you really shouldn't be creating new ones.
48  */

49 public class TBSCertificateStructure
50     extends ASN1Encodable
51     implements X509ObjectIdentifiers, PKCSObjectIdentifiers
52 {
53     ASN1Sequence seq;
54
55     DERInteger version;
56     DERInteger serialNumber;
57     AlgorithmIdentifier signature;
58     X509Name issuer;
59     Time startDate, endDate;
60     X509Name subject;
61     SubjectPublicKeyInfo subjectPublicKeyInfo;
62     DERBitString issuerUniqueId;
63     DERBitString subjectUniqueId;
64     X509Extensions extensions;
65
66     public static TBSCertificateStructure getInstance(
67         ASN1TaggedObject obj,
68         boolean explicit)
69     {
70         return getInstance(ASN1Sequence.getInstance(obj, explicit));
71     }
72
73     public static TBSCertificateStructure getInstance(
74         Object JavaDoc obj)
75     {
76         if (obj instanceof TBSCertificateStructure)
77         {
78             return (TBSCertificateStructure)obj;
79         }
80         else if (obj instanceof ASN1Sequence)
81         {
82             return new TBSCertificateStructure((ASN1Sequence)obj);
83         }
84
85         throw new IllegalArgumentException JavaDoc("unknown object in factory");
86     }
87
88     public TBSCertificateStructure(
89         ASN1Sequence seq)
90     {
91         int seqStart = 0;
92
93         this.seq = seq;
94
95         //
96
// some certficates don't include a version number - we assume v1
97
//
98
if (seq.getObjectAt(0) instanceof DERTaggedObject)
99         {
100             version = DERInteger.getInstance(seq.getObjectAt(0));
101         }
102         else
103         {
104             seqStart = -1; // field 0 is missing!
105
version = new DERInteger(0);
106         }
107
108         serialNumber = DERInteger.getInstance(seq.getObjectAt(seqStart + 1));
109
110         signature = AlgorithmIdentifier.getInstance(seq.getObjectAt(seqStart + 2));
111         issuer = X509Name.getInstance(seq.getObjectAt(seqStart + 3));
112
113         //
114
// before and after dates
115
//
116
ASN1Sequence dates = (ASN1Sequence)seq.getObjectAt(seqStart + 4);
117
118         startDate = Time.getInstance(dates.getObjectAt(0));
119         endDate = Time.getInstance(dates.getObjectAt(1));
120
121         subject = X509Name.getInstance(seq.getObjectAt(seqStart + 5));
122
123         //
124
// public key info.
125
//
126
subjectPublicKeyInfo = SubjectPublicKeyInfo.getInstance(seq.getObjectAt(seqStart + 6));
127
128         for (int extras = seq.size() - (seqStart + 6) - 1; extras > 0; extras--)
129         {
130             DERTaggedObject extra = (DERTaggedObject)seq.getObjectAt(seqStart + 6 + extras);
131
132             switch (extra.getTagNo())
133             {
134             case 1:
135                 issuerUniqueId = DERBitString.getInstance(extra, false);
136                 break;
137             case 2:
138                 subjectUniqueId = DERBitString.getInstance(extra, false);
139                 break;
140             case 3:
141                 extensions = X509Extensions.getInstance(extra);
142             }
143         }
144     }
145
146     public int getVersion()
147     {
148         return version.getValue().intValue() + 1;
149     }
150
151     public DERInteger getVersionNumber()
152     {
153         return version;
154     }
155
156     public DERInteger getSerialNumber()
157     {
158         return serialNumber;
159     }
160
161     public AlgorithmIdentifier getSignature()
162     {
163         return signature;
164     }
165
166     public X509Name getIssuer()
167     {
168         return issuer;
169     }
170
171     public Time getStartDate()
172     {
173         return startDate;
174     }
175
176     public Time getEndDate()
177     {
178         return endDate;
179     }
180
181     public X509Name getSubject()
182     {
183         return subject;
184     }
185
186     public SubjectPublicKeyInfo getSubjectPublicKeyInfo()
187     {
188         return subjectPublicKeyInfo;
189     }
190
191     public DERBitString getIssuerUniqueId()
192     {
193         return issuerUniqueId;
194     }
195
196     public DERBitString getSubjectUniqueId()
197     {
198         return subjectUniqueId;
199     }
200
201     public X509Extensions getExtensions()
202     {
203         return extensions;
204     }
205
206     public DERObject toASN1Object()
207     {
208         return seq;
209     }
210 }
211
Popular Tags