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.pkcs;
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.ASN1Set;
25 import org.apache.geronimo.util.asn1.DERInteger;
26 import org.apache.geronimo.util.asn1.DERObject;
27 import org.apache.geronimo.util.asn1.DERSequence;
28 import org.apache.geronimo.util.asn1.DERTaggedObject;
29 import org.apache.geronimo.util.asn1.x509.SubjectPublicKeyInfo;
30 import org.apache.geronimo.util.asn1.x509.X509Name;
31
32 /**
33 * PKCS10 CertificationRequestInfo object.
34 * <pre>
35 * CertificationRequestInfo ::= SEQUENCE {
36 * version INTEGER { v1(0) } (v1,...),
37 * subject Name,
38 * subjectPKInfo SubjectPublicKeyInfo{{ PKInfoAlgorithms }},
39 * attributes [0] Attributes{{ CRIAttributes }}
40 * }
41 *
42 * Attributes { ATTRIBUTE:IOSet } ::= SET OF Attribute{{ IOSet }}
43 *
44 * Attribute { ATTRIBUTE:IOSet } ::= SEQUENCE {
45 * type ATTRIBUTE.&id({IOSet}),
46 * values SET SIZE(1..MAX) OF ATTRIBUTE.&Type({IOSet}{\@type})
47 * }
48 * </pre>
49 */
50 public class CertificationRequestInfo
51 extends ASN1Encodable
52 {
53 DERInteger version = new DERInteger(0);
54 X509Name subject;
55 SubjectPublicKeyInfo subjectPKInfo;
56 ASN1Set attributes = null;
57
58 public static CertificationRequestInfo getInstance(
59 Object obj)
60 {
61 if (obj instanceof CertificationRequestInfo)
62 {
63 return (CertificationRequestInfo)obj;
64 }
65 else if (obj instanceof ASN1Sequence)
66 {
67 return new CertificationRequestInfo((ASN1Sequence)obj);
68 }
69
70 throw new IllegalArgumentException("unknown object in factory");
71 }
72
73 public CertificationRequestInfo(
74 X509Name subject,
75 SubjectPublicKeyInfo pkInfo,
76 ASN1Set attributes)
77 {
78 this.subject = subject;
79 this.subjectPKInfo = pkInfo;
80 this.attributes = attributes;
81
82 if ((subject == null) || (version == null) || (subjectPKInfo == null))
83 {
84 throw new IllegalArgumentException("Not all mandatory fields set in CertificationRequestInfo generator.");
85 }
86 }
87
88 public CertificationRequestInfo(
89 ASN1Sequence seq)
90 {
91 version = (DERInteger)seq.getObjectAt(0);
92
93 subject = X509Name.getInstance(seq.getObjectAt(1));
94 subjectPKInfo = SubjectPublicKeyInfo.getInstance(seq.getObjectAt(2));
95
96
97
98
99
100 if (seq.size() > 3)
101 {
102 DERTaggedObject tagobj = (DERTaggedObject)seq.getObjectAt(3);
103 attributes = ASN1Set.getInstance(tagobj, false);
104 }
105
106 if ((subject == null) || (version == null) || (subjectPKInfo == null))
107 {
108 throw new IllegalArgumentException("Not all mandatory fields set in CertificationRequestInfo generator.");
109 }
110 }
111
112 public DERInteger getVersion()
113 {
114 return version;
115 }
116
117 public X509Name getSubject()
118 {
119 return subject;
120 }
121
122 public SubjectPublicKeyInfo getSubjectPublicKeyInfo()
123 {
124 return subjectPKInfo;
125 }
126
127 public ASN1Set getAttributes()
128 {
129 return attributes;
130 }
131
132 public DERObject toASN1Object()
133 {
134 ASN1EncodableVector v = new ASN1EncodableVector();
135
136 v.add(version);
137 v.add(subject);
138 v.add(subjectPKInfo);
139
140 if (attributes != null)
141 {
142 v.add(new DERTaggedObject(false, 0, attributes));
143 }
144
145 return new DERSequence(v);
146 }
147 }