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.ASN1Encodable;
22 import org.apache.geronimo.util.asn1.ASN1EncodableVector;
23 import org.apache.geronimo.util.asn1.DERInteger;
24 import org.apache.geronimo.util.asn1.DERObjectIdentifier;
25 import org.apache.geronimo.util.asn1.DERSequence;
26 import org.apache.geronimo.util.asn1.DERGeneralizedTime;
27 import org.apache.geronimo.util.asn1.DERBitString;
28 import org.apache.geronimo.util.asn1.DERSet;
29
30 /**
31 * Generator for Version 2 AttributeCertificateInfo
32 * <pre>
33 * AttributeCertificateInfo ::= SEQUENCE {
34 * version AttCertVersion -- version is v2,
35 * holder Holder,
36 * issuer AttCertIssuer,
37 * signature AlgorithmIdentifier,
38 * serialNumber CertificateSerialNumber,
39 * attrCertValidityPeriod AttCertValidityPeriod,
40 * attributes SEQUENCE OF Attribute,
41 * issuerUniqueID UniqueIdentifier OPTIONAL,
42 * extensions Extensions OPTIONAL
43 * }
44 * </pre>
45 *
46 */
47 public class V2AttributeCertificateInfoGenerator
48 {
49 private DERInteger version;
50 private Holder holder;
51 private AttCertIssuer issuer;
52 private AlgorithmIdentifier signature;
53 private DERInteger serialNumber;
54 private AttCertValidityPeriod attrCertValidityPeriod;
55 private ASN1EncodableVector attributes;
56 private DERBitString issuerUniqueID;
57 private X509Extensions extensions;
58 private DERGeneralizedTime startDate, endDate;
59
60 public V2AttributeCertificateInfoGenerator()
61 {
62 this.version = new DERInteger(1);
63 attributes = new ASN1EncodableVector();
64 }
65
66 public void setHolder(Holder holder)
67 {
68 this.holder = holder;
69 }
70
71 public void addAttribute(String oid, ASN1Encodable value)
72 {
73 attributes.add(new Attribute(new DERObjectIdentifier(oid), new DERSet(value)));
74 }
75
76 /**
77 * @param attribute
78 */
79 public void addAttribute(Attribute attribute)
80 {
81 attributes.add(attribute);
82 }
83
84 public void setSerialNumber(
85 DERInteger serialNumber)
86 {
87 this.serialNumber = serialNumber;
88 }
89
90 public void setSignature(
91 AlgorithmIdentifier signature)
92 {
93 this.signature = signature;
94 }
95
96 public void setIssuer(
97 AttCertIssuer issuer)
98 {
99 this.issuer = issuer;
100 }
101
102 public void setStartDate(
103 DERGeneralizedTime startDate)
104 {
105 this.startDate = startDate;
106 }
107
108 public void setEndDate(
109 DERGeneralizedTime endDate)
110 {
111 this.endDate = endDate;
112 }
113
114 public void setIssuerUniqueID(
115 DERBitString issuerUniqueID)
116 {
117 this.issuerUniqueID = issuerUniqueID;
118 }
119
120 public void setExtensions(
121 X509Extensions extensions)
122 {
123 this.extensions = extensions;
124 }
125
126 public AttributeCertificateInfo generateAttributeCertificateInfo()
127 {
128 if ((serialNumber == null) || (signature == null)
129 || (issuer == null) || (startDate == null) || (endDate == null)
130 || (holder == null) || (attributes == null))
131 {
132 throw new IllegalStateException("not all mandatory fields set in V2 AttributeCertificateInfo generator");
133 }
134
135 ASN1EncodableVector v = new ASN1EncodableVector();
136
137 v.add(version);
138 v.add(holder);
139 v.add(issuer);
140 v.add(signature);
141 v.add(serialNumber);
142
143
144
145
146 AttCertValidityPeriod validity = new AttCertValidityPeriod(startDate, endDate);
147 v.add(validity);
148
149
150 v.add(new DERSequence(attributes));
151
152 if (issuerUniqueID != null)
153 {
154 v.add(issuerUniqueID);
155 }
156
157 if (extensions != null)
158 {
159 v.add(extensions);
160 }
161
162 return new AttributeCertificateInfo(new DERSequence(v));
163 }
164 }