1package org.bouncycastle.asn1.x509; 2 3import org.bouncycastle.asn1.ASN1Encodable; 4import org.bouncycastle.asn1.ASN1Sequence; 5import org.bouncycastle.asn1.ASN1TaggedObject; 6import org.bouncycastle.asn1.DERBitString; 7import org.bouncycastle.asn1.DERInteger; 8import org.bouncycastle.asn1.DERObject; 9import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers; 10 11/** 12 * an X509Certificate structure. 13 * <pre> 14 * Certificate ::= SEQUENCE { 15 * tbsCertificate TBSCertificate, 16 * signatureAlgorithm AlgorithmIdentifier, 17 * signature BIT STRING 18 * } 19 * </pre> 20 */ 21public class X509CertificateStructure 22 extends ASN1Encodable 23 implements X509ObjectIdentifiers, PKCSObjectIdentifiers 24{ 25 ASN1Sequence seq; 26 TBSCertificateStructure tbsCert; 27 AlgorithmIdentifier sigAlgId; 28 DERBitString sig; 29 30 public static X509CertificateStructure getInstance( 31 ASN1TaggedObject obj, 32 boolean explicit) 33 { 34 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 35 } 36 37 public static X509CertificateStructure getInstance( 38 Object obj) 39 { 40 if (obj instanceof X509CertificateStructure) 41 { 42 return (X509CertificateStructure)obj; 43 } 44 else if (obj != null) 45 { 46 return new X509CertificateStructure(ASN1Sequence.getInstance(obj)); 47 } 48 49 return null; 50 } 51 52 public X509CertificateStructure( 53 ASN1Sequence seq) 54 { 55 this.seq = seq; 56 57 // 58 // correct x509 certficate 59 // 60 if (seq.size() == 3) 61 { 62 tbsCert = TBSCertificateStructure.getInstance(seq.getObjectAt(0)); 63 sigAlgId = AlgorithmIdentifier.getInstance(seq.getObjectAt(1)); 64 65 sig = DERBitString.getInstance(seq.getObjectAt(2)); 66 } 67 else 68 { 69 throw new IllegalArgumentException("sequence wrong size for a certificate"); 70 } 71 } 72 73 public TBSCertificateStructure getTBSCertificate() 74 { 75 return tbsCert; 76 } 77 78 public int getVersion() 79 { 80 return tbsCert.getVersion(); 81 } 82 83 public DERInteger getSerialNumber() 84 { 85 return tbsCert.getSerialNumber(); 86 } 87 88 public X509Name getIssuer() 89 { 90 return tbsCert.getIssuer(); 91 } 92 93 public Time getStartDate() 94 { 95 return tbsCert.getStartDate(); 96 } 97 98 public Time getEndDate() 99 { 100 return tbsCert.getEndDate(); 101 } 102 103 public X509Name getSubject() 104 { 105 return tbsCert.getSubject(); 106 } 107 108 public SubjectPublicKeyInfo getSubjectPublicKeyInfo() 109 { 110 return tbsCert.getSubjectPublicKeyInfo(); 111 } 112 113 public AlgorithmIdentifier getSignatureAlgorithm() 114 { 115 return sigAlgId; 116 } 117 118 public DERBitString getSignature() 119 { 120 return sig; 121 } 122 123 public DERObject toASN1Object() 124 { 125 return seq; 126 } 127} 128