KickJava   Java API By Example, From Geeks To Geeks.

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


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.ASN1Encodable;
21 import org.apache.geronimo.util.asn1.ASN1Sequence;
22 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
23 import org.apache.geronimo.util.asn1.DERBitString;
24 import org.apache.geronimo.util.asn1.DERInteger;
25 import org.apache.geronimo.util.asn1.DERObject;
26 import org.apache.geronimo.util.asn1.pkcs.PKCSObjectIdentifiers;
27
28 /**
29  * an X509Certificate structure.
30  * <pre>
31  * Certificate ::= SEQUENCE {
32  * tbsCertificate TBSCertificate,
33  * signatureAlgorithm AlgorithmIdentifier,
34  * signature BIT STRING
35  * }
36  * </pre>
37  */

38 public class X509CertificateStructure
39     extends ASN1Encodable
40     implements X509ObjectIdentifiers, PKCSObjectIdentifiers
41 {
42     ASN1Sequence seq;
43     TBSCertificateStructure tbsCert;
44     AlgorithmIdentifier sigAlgId;
45     DERBitString sig;
46
47     public static X509CertificateStructure getInstance(
48         ASN1TaggedObject obj,
49         boolean explicit)
50     {
51         return getInstance(ASN1Sequence.getInstance(obj, explicit));
52     }
53
54     public static X509CertificateStructure getInstance(
55         Object JavaDoc obj)
56     {
57         if (obj instanceof X509CertificateStructure)
58         {
59             return (X509CertificateStructure)obj;
60         }
61         else if (obj instanceof ASN1Sequence)
62         {
63             return new X509CertificateStructure((ASN1Sequence)obj);
64         }
65
66         throw new IllegalArgumentException JavaDoc("unknown object in factory");
67     }
68
69     public X509CertificateStructure(
70         ASN1Sequence seq)
71     {
72         this.seq = seq;
73
74         //
75
// correct x509 certficate
76
//
77
if (seq.size() == 3)
78         {
79             tbsCert = TBSCertificateStructure.getInstance(seq.getObjectAt(0));
80             sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
81
82             sig = (DERBitString)seq.getObjectAt(2);
83         }
84         else
85         {
86             throw new IllegalArgumentException JavaDoc("sequence wrong size for a certificate");
87         }
88     }
89
90     public TBSCertificateStructure getTBSCertificate()
91     {
92         return tbsCert;
93     }
94
95     public int getVersion()
96     {
97         return tbsCert.getVersion();
98     }
99
100     public DERInteger getSerialNumber()
101     {
102         return tbsCert.getSerialNumber();
103     }
104
105     public X509Name getIssuer()
106     {
107         return tbsCert.getIssuer();
108     }
109
110     public Time getStartDate()
111     {
112         return tbsCert.getStartDate();
113     }
114
115     public Time getEndDate()
116     {
117         return tbsCert.getEndDate();
118     }
119
120     public X509Name getSubject()
121     {
122         return tbsCert.getSubject();
123     }
124
125     public SubjectPublicKeyInfo getSubjectPublicKeyInfo()
126     {
127         return tbsCert.getSubjectPublicKeyInfo();
128     }
129
130     public AlgorithmIdentifier getSignatureAlgorithm()
131     {
132         return sigAlgId;
133     }
134
135     public DERBitString getSignature()
136     {
137         return sig;
138     }
139
140     public DERObject toASN1Object()
141     {
142         return seq;
143     }
144 }
145
Popular Tags