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.ASN1Sequence;
24 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
25 import org.apache.geronimo.util.asn1.DERBitString;
26 import org.apache.geronimo.util.asn1.DERInteger;
27 import org.apache.geronimo.util.asn1.DERObject;
28 import org.apache.geronimo.util.asn1.DERSequence;
29
30 public class AttributeCertificateInfo
31 extends ASN1Encodable
32 {
33 private DERInteger version;
34 private Holder holder;
35 private AttCertIssuer issuer;
36 private AlgorithmIdentifier signature;
37 private DERInteger serialNumber;
38 private AttCertValidityPeriod attrCertValidityPeriod;
39 private ASN1Sequence attributes;
40 private DERBitString issuerUniqueID;
41 private X509Extensions extensions;
42
43 public static AttributeCertificateInfo getInstance(
44 ASN1TaggedObject obj,
45 boolean explicit)
46 {
47 return getInstance(ASN1Sequence.getInstance(obj, explicit));
48 }
49
50 public static AttributeCertificateInfo getInstance(
51 Object obj)
52 {
53 if (obj instanceof AttributeCertificateInfo)
54 {
55 return (AttributeCertificateInfo)obj;
56 }
57 else if (obj instanceof ASN1Sequence)
58 {
59 return new AttributeCertificateInfo((ASN1Sequence)obj);
60 }
61
62 throw new IllegalArgumentException("unknown object in factory");
63 }
64
65 public AttributeCertificateInfo(
66 ASN1Sequence seq)
67 {
68 this.version = DERInteger.getInstance(seq.getObjectAt(0));
69 this.holder = Holder.getInstance(seq.getObjectAt(1));
70 this.issuer = AttCertIssuer.getInstance(seq.getObjectAt(2));
71 this.signature = AlgorithmIdentifier.getInstance(seq.getObjectAt(3));
72 this.serialNumber = DERInteger.getInstance(seq.getObjectAt(4));
73 this.attrCertValidityPeriod = AttCertValidityPeriod.getInstance(seq.getObjectAt(5));
74 this.attributes = ASN1Sequence.getInstance(seq.getObjectAt(6));
75
76 for (int i = 7; i < seq.size(); i++)
77 {
78 ASN1Encodable obj = (ASN1Encodable)seq.getObjectAt(i);
79
80 if (obj instanceof DERBitString)
81 {
82 this.issuerUniqueID = DERBitString.getInstance(seq.getObjectAt(i));
83 }
84 else if (obj instanceof ASN1Sequence || obj instanceof X509Extensions)
85 {
86 this.extensions = X509Extensions.getInstance(seq.getObjectAt(i));
87 }
88 }
89 }
90
91 public DERInteger getVersion()
92 {
93 return version;
94 }
95
96 public Holder getHolder()
97 {
98 return holder;
99 }
100
101 public AttCertIssuer getIssuer()
102 {
103 return issuer;
104 }
105
106 public AlgorithmIdentifier getSignature()
107 {
108 return signature;
109 }
110
111 public DERInteger getSerialNumber()
112 {
113 return serialNumber;
114 }
115
116 public AttCertValidityPeriod getAttrCertValidityPeriod()
117 {
118 return attrCertValidityPeriod;
119 }
120
121 public ASN1Sequence getAttributes()
122 {
123 return attributes;
124 }
125
126 public DERBitString getIssuerUniqueID()
127 {
128 return issuerUniqueID;
129 }
130
131 public X509Extensions getExtensions()
132 {
133 return extensions;
134 }
135
136 /**
137 * Produce an object suitable for an ASN1OutputStream.
138 * <pre>
139 * AttributeCertificateInfo ::= SEQUENCE {
140 * version AttCertVersion -- version is v2,
141 * holder Holder,
142 * issuer AttCertIssuer,
143 * signature AlgorithmIdentifier,
144 * serialNumber CertificateSerialNumber,
145 * attrCertValidityPeriod AttCertValidityPeriod,
146 * attributes SEQUENCE OF Attribute,
147 * issuerUniqueID UniqueIdentifier OPTIONAL,
148 * extensions Extensions OPTIONAL
149 * }
150 *
151 * AttCertVersion ::= INTEGER { v2(1) }
152 * </pre>
153 */
154 public DERObject toASN1Object()
155 {
156 ASN1EncodableVector v = new ASN1EncodableVector();
157
158 v.add(version);
159 v.add(holder);
160 v.add(issuer);
161 v.add(signature);
162 v.add(serialNumber);
163 v.add(attrCertValidityPeriod);
164 v.add(attributes);
165
166 if (issuerUniqueID != null)
167 {
168 v.add(issuerUniqueID);
169 }
170
171 if (extensions != null)
172 {
173 v.add(extensions);
174 }
175
176 return new DERSequence(v);
177 }
178 }