1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements. See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 package org.apache.geronimo.util.asn1.x509;
20
21 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
22 import org.apache.geronimo.util.asn1.DERInteger;
23 import org.apache.geronimo.util.asn1.DERSequence;
24 import org.apache.geronimo.util.asn1.DERTaggedObject;
25 import org.apache.geronimo.util.asn1.DERUTCTime;
26
27 /**
28 * Generator for Version 1 TBSCertificateStructures.
29 * <pre>
30 * TBSCertificate ::= SEQUENCE {
31 * version [ 0 ] Version DEFAULT v1(0),
32 * serialNumber CertificateSerialNumber,
33 * signature AlgorithmIdentifier,
34 * issuer Name,
35 * validity Validity,
36 * subject Name,
37 * subjectPublicKeyInfo SubjectPublicKeyInfo,
38 * }
39 * </pre>
40 *
41 */
42 public class V1TBSCertificateGenerator
43 {
44 DERTaggedObject version = new DERTaggedObject(0, new DERInteger(0));
45
46 DERInteger serialNumber;
47 AlgorithmIdentifier signature;
48 X509Name issuer;
49 Time startDate, endDate;
50 X509Name subject;
51 SubjectPublicKeyInfo subjectPublicKeyInfo;
52
53 public V1TBSCertificateGenerator()
54 {
55 }
56
57 public void setSerialNumber(
58 DERInteger serialNumber)
59 {
60 this.serialNumber = serialNumber;
61 }
62
63 public void setSignature(
64 AlgorithmIdentifier signature)
65 {
66 this.signature = signature;
67 }
68
69 public void setIssuer(
70 X509Name issuer)
71 {
72 this.issuer = issuer;
73 }
74
75 public void setStartDate(
76 Time startDate)
77 {
78 this.startDate = startDate;
79 }
80
81 public void setStartDate(
82 DERUTCTime startDate)
83 {
84 this.startDate = new Time(startDate);
85 }
86
87 public void setEndDate(
88 Time endDate)
89 {
90 this.endDate = endDate;
91 }
92
93 public void setEndDate(
94 DERUTCTime endDate)
95 {
96 this.endDate = new Time(endDate);
97 }
98
99 public void setSubject(
100 X509Name subject)
101 {
102 this.subject = subject;
103 }
104
105 public void setSubjectPublicKeyInfo(
106 SubjectPublicKeyInfo pubKeyInfo)
107 {
108 this.subjectPublicKeyInfo = pubKeyInfo;
109 }
110
111 public TBSCertificateStructure generateTBSCertificate()
112 {
113 if ((serialNumber == null) || (signature == null)
114 || (issuer == null) || (startDate == null) || (endDate == null)
115 || (subject == null) || (subjectPublicKeyInfo == null))
116 {
117 throw new IllegalStateException("not all mandatory fields set in V1 TBScertificate generator");
118 }
119
120 ASN1EncodableVector seq = new ASN1EncodableVector();
121
122
123 seq.add(serialNumber);
124 seq.add(signature);
125 seq.add(issuer);
126
127
128
129
130 ASN1EncodableVector validity = new ASN1EncodableVector();
131
132 validity.add(startDate);
133 validity.add(endDate);
134
135 seq.add(new DERSequence(validity));
136
137 seq.add(subject);
138
139 seq.add(subjectPublicKeyInfo);
140
141 return new TBSCertificateStructure(new DERSequence(seq));
142 }
143 }