KickJava   Java API By Example, From Geeks To Geeks.

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


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.ASN1EncodableVector;
21 import org.apache.geronimo.util.asn1.DERInteger;
22 import org.apache.geronimo.util.asn1.DERSequence;
23 import org.apache.geronimo.util.asn1.DERTaggedObject;
24 import org.apache.geronimo.util.asn1.DERUTCTime;
25
26 /**
27  * Generator for Version 3 TBSCertificateStructures.
28  * <pre>
29  * TBSCertificate ::= SEQUENCE {
30  * version [ 0 ] Version DEFAULT v1(0),
31  * serialNumber CertificateSerialNumber,
32  * signature AlgorithmIdentifier,
33  * issuer Name,
34  * validity Validity,
35  * subject Name,
36  * subjectPublicKeyInfo SubjectPublicKeyInfo,
37  * issuerUniqueID [ 1 ] IMPLICIT UniqueIdentifier OPTIONAL,
38  * subjectUniqueID [ 2 ] IMPLICIT UniqueIdentifier OPTIONAL,
39  * extensions [ 3 ] Extensions OPTIONAL
40  * }
41  * </pre>
42  *
43  */

44 public class V3TBSCertificateGenerator
45 {
46     DERTaggedObject version = new DERTaggedObject(0, new DERInteger(2));
47
48     DERInteger serialNumber;
49     AlgorithmIdentifier signature;
50     X509Name issuer;
51     Time startDate, endDate;
52     X509Name subject;
53     SubjectPublicKeyInfo subjectPublicKeyInfo;
54     X509Extensions extensions;
55
56     public V3TBSCertificateGenerator()
57     {
58     }
59
60     public void setSerialNumber(
61         DERInteger serialNumber)
62     {
63         this.serialNumber = serialNumber;
64     }
65
66     public void setSignature(
67         AlgorithmIdentifier signature)
68     {
69         this.signature = signature;
70     }
71
72     public void setIssuer(
73         X509Name issuer)
74     {
75         this.issuer = issuer;
76     }
77
78     public void setStartDate(
79         DERUTCTime startDate)
80     {
81         this.startDate = new Time(startDate);
82     }
83
84     public void setStartDate(
85         Time startDate)
86     {
87         this.startDate = startDate;
88     }
89
90     public void setEndDate(
91         DERUTCTime endDate)
92     {
93         this.endDate = new Time(endDate);
94     }
95
96     public void setEndDate(
97         Time endDate)
98     {
99         this.endDate = endDate;
100     }
101
102     public void setSubject(
103         X509Name subject)
104     {
105         this.subject = subject;
106     }
107
108     public void setSubjectPublicKeyInfo(
109         SubjectPublicKeyInfo pubKeyInfo)
110     {
111         this.subjectPublicKeyInfo = pubKeyInfo;
112     }
113
114     public void setExtensions(
115         X509Extensions extensions)
116     {
117         this.extensions = extensions;
118     }
119
120     public TBSCertificateStructure generateTBSCertificate()
121     {
122         if ((serialNumber == null) || (signature == null)
123             || (issuer == null) || (startDate == null) || (endDate == null)
124             || (subject == null) || (subjectPublicKeyInfo == null))
125         {
126             throw new IllegalStateException JavaDoc("not all mandatory fields set in V3 TBScertificate generator");
127         }
128
129         ASN1EncodableVector v = new ASN1EncodableVector();
130
131         v.add(version);
132         v.add(serialNumber);
133         v.add(signature);
134         v.add(issuer);
135
136         //
137
// before and after dates
138
//
139
ASN1EncodableVector validity = new ASN1EncodableVector();
140
141         validity.add(startDate);
142         validity.add(endDate);
143
144         v.add(new DERSequence(validity));
145
146         v.add(subject);
147
148         v.add(subjectPublicKeyInfo);
149
150         if (extensions != null)
151         {
152             v.add(new DERTaggedObject(3, extensions));
153         }
154
155         return new TBSCertificateStructure(new DERSequence(v));
156     }
157 }
158
Popular Tags