KickJava   Java API By Example, From Geeks To Geeks.

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


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 1 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  * }
38  * </pre>
39  *
40  */

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