KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > maverick > crypto > asn1 > x509 > X509CertificateStructure


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.maverick.crypto.asn1.x509;
21
22 import com.maverick.crypto.asn1.ASN1Sequence;
23 import com.maverick.crypto.asn1.ASN1TaggedObject;
24 import com.maverick.crypto.asn1.DERBitString;
25 import com.maverick.crypto.asn1.DEREncodable;
26 import com.maverick.crypto.asn1.DERInteger;
27 import com.maverick.crypto.asn1.DERObject;
28 import com.maverick.crypto.asn1.pkcs.PKCSObjectIdentifiers;
29
30 /**
31  * an X509Certificate structure.
32  * <pre>
33  * Certificate ::= SEQUENCE {
34  * tbsCertificate TBSCertificate,
35  * signatureAlgorithm AlgorithmIdentifier,
36  * signature BIT STRING
37  * }
38  * </pre>
39  */

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