001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.geronimo.util.asn1.x509;
019
020 import org.apache.geronimo.util.asn1.ASN1Encodable;
021 import org.apache.geronimo.util.asn1.ASN1Sequence;
022 import org.apache.geronimo.util.asn1.ASN1TaggedObject;
023 import org.apache.geronimo.util.asn1.DERBitString;
024 import org.apache.geronimo.util.asn1.DERInteger;
025 import org.apache.geronimo.util.asn1.DERObject;
026 import org.apache.geronimo.util.asn1.pkcs.PKCSObjectIdentifiers;
027
028 /**
029 * an X509Certificate structure.
030 * <pre>
031 * Certificate ::= SEQUENCE {
032 * tbsCertificate TBSCertificate,
033 * signatureAlgorithm AlgorithmIdentifier,
034 * signature BIT STRING
035 * }
036 * </pre>
037 */
038 public class X509CertificateStructure
039 extends ASN1Encodable
040 implements X509ObjectIdentifiers, PKCSObjectIdentifiers
041 {
042 ASN1Sequence seq;
043 TBSCertificateStructure tbsCert;
044 AlgorithmIdentifier sigAlgId;
045 DERBitString sig;
046
047 public static X509CertificateStructure getInstance(
048 ASN1TaggedObject obj,
049 boolean explicit)
050 {
051 return getInstance(ASN1Sequence.getInstance(obj, explicit));
052 }
053
054 public static X509CertificateStructure getInstance(
055 Object obj)
056 {
057 if (obj instanceof X509CertificateStructure)
058 {
059 return (X509CertificateStructure)obj;
060 }
061 else if (obj instanceof ASN1Sequence)
062 {
063 return new X509CertificateStructure((ASN1Sequence)obj);
064 }
065
066 throw new IllegalArgumentException("unknown object in factory");
067 }
068
069 public X509CertificateStructure(
070 ASN1Sequence seq)
071 {
072 this.seq = seq;
073
074 //
075 // correct x509 certficate
076 //
077 if (seq.size() == 3)
078 {
079 tbsCert = TBSCertificateStructure.getInstance(seq.getObjectAt(0));
080 sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1));
081
082 sig = (DERBitString)seq.getObjectAt(2);
083 }
084 else
085 {
086 throw new IllegalArgumentException("sequence wrong size for a certificate");
087 }
088 }
089
090 public TBSCertificateStructure getTBSCertificate()
091 {
092 return tbsCert;
093 }
094
095 public int getVersion()
096 {
097 return tbsCert.getVersion();
098 }
099
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 }