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