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: */package org.apache.geronimo.crypto.asn1.x509;
017:
018: import org.apache.geronimo.crypto.asn1.ASN1Encodable;
019: import org.apache.geronimo.crypto.asn1.ASN1Sequence;
020: import org.apache.geronimo.crypto.asn1.ASN1TaggedObject;
021: import org.apache.geronimo.crypto.asn1.DERBitString;
022: import org.apache.geronimo.crypto.asn1.DERInteger;
023: import org.apache.geronimo.crypto.asn1.DERObject;
024: import org.apache.geronimo.crypto.asn1.pkcs.PKCSObjectIdentifiers;
025:
026: /**
027: * an X509Certificate structure.
028: * <pre>
029: * Certificate ::= SEQUENCE {
030: * tbsCertificate TBSCertificate,
031: * signatureAlgorithm AlgorithmIdentifier,
032: * signature BIT STRING
033: * }
034: * </pre>
035: */
036: public class X509CertificateStructure extends ASN1Encodable implements
037: X509ObjectIdentifiers, PKCSObjectIdentifiers {
038: ASN1Sequence seq;
039: TBSCertificateStructure tbsCert;
040: AlgorithmIdentifier sigAlgId;
041: DERBitString sig;
042:
043: public static X509CertificateStructure getInstance(
044: ASN1TaggedObject obj, boolean explicit) {
045: return getInstance(ASN1Sequence.getInstance(obj, explicit));
046: }
047:
048: public static X509CertificateStructure getInstance(Object obj) {
049: if (obj instanceof X509CertificateStructure) {
050: return (X509CertificateStructure) obj;
051: } else if (obj instanceof ASN1Sequence) {
052: return new X509CertificateStructure((ASN1Sequence) obj);
053: }
054:
055: throw new IllegalArgumentException("unknown object in factory");
056: }
057:
058: public X509CertificateStructure(ASN1Sequence seq) {
059: this .seq = seq;
060:
061: //
062: // correct x509 certficate
063: //
064: if (seq.size() == 3) {
065: tbsCert = TBSCertificateStructure.getInstance(seq
066: .getObjectAt(0));
067: sigAlgId = AlgorithmIdentifier.getInstance(seq
068: .getObjectAt(1));
069:
070: sig = (DERBitString) seq.getObjectAt(2);
071: } else {
072: throw new IllegalArgumentException(
073: "sequence wrong size for a certificate");
074: }
075: }
076:
077: public TBSCertificateStructure getTBSCertificate() {
078: return tbsCert;
079: }
080:
081: public int getVersion() {
082: return tbsCert.getVersion();
083: }
084:
085: public DERInteger getSerialNumber() {
086: return tbsCert.getSerialNumber();
087: }
088:
089: public X509Name getIssuer() {
090: return tbsCert.getIssuer();
091: }
092:
093: public Time getStartDate() {
094: return tbsCert.getStartDate();
095: }
096:
097: public Time getEndDate() {
098: return tbsCert.getEndDate();
099: }
100:
101: public X509Name getSubject() {
102: return tbsCert.getSubject();
103: }
104:
105: public SubjectPublicKeyInfo getSubjectPublicKeyInfo() {
106: return tbsCert.getSubjectPublicKeyInfo();
107: }
108:
109: public AlgorithmIdentifier getSignatureAlgorithm() {
110: return sigAlgId;
111: }
112:
113: public DERBitString getSignature() {
114: return sig;
115: }
116:
117: public DERObject toASN1Object() {
118: return seq;
119: }
120: }
|