1 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.DERTaggedObject; 29 import com.maverick.crypto.asn1.pkcs.PKCSObjectIdentifiers; 30 31 51 public class TBSCertificateStructure 52 implements DEREncodable, X509ObjectIdentifiers, PKCSObjectIdentifiers 53 { 54 ASN1Sequence seq; 55 56 DERInteger version; 57 DERInteger serialNumber; 58 AlgorithmIdentifier signature; 59 X509Name issuer; 60 Time startDate, endDate; 61 X509Name subject; 62 SubjectPublicKeyInfo subjectPublicKeyInfo; 63 DERBitString issuerUniqueId; 64 DERBitString subjectUniqueId; 65 X509Extensions extensions; 66 67 public static TBSCertificateStructure getInstance( 68 ASN1TaggedObject obj, 69 boolean explicit) 70 { 71 return getInstance(ASN1Sequence.getInstance(obj, explicit)); 72 } 73 74 public static TBSCertificateStructure getInstance( 75 Object obj) 76 { 77 if (obj instanceof TBSCertificateStructure) 78 { 79 return (TBSCertificateStructure)obj; 80 } 81 else if (obj instanceof ASN1Sequence) 82 { 83 return new TBSCertificateStructure((ASN1Sequence)obj); 84 } 85 86 throw new IllegalArgumentException ("unknown object in factory"); 87 } 88 89 public TBSCertificateStructure( 90 ASN1Sequence seq) 91 { 92 int seqStart = 0; 93 94 this.seq = seq; 95 96 if (seq.getObjectAt(0) instanceof DERTaggedObject) 100 { 101 version = DERInteger.getInstance(seq.getObjectAt(0)); 102 } 103 else 104 { 105 seqStart = -1; version = new DERInteger(0); 107 } 108 109 serialNumber = DERInteger.getInstance(seq.getObjectAt(seqStart + 1)); 110 111 signature = AlgorithmIdentifier.getInstance(seq.getObjectAt(seqStart + 2)); 112 issuer = X509Name.getInstance(seq.getObjectAt(seqStart + 3)); 113 114 ASN1Sequence dates = (ASN1Sequence)seq.getObjectAt(seqStart + 4); 118 119 startDate = Time.getInstance(dates.getObjectAt(0)); 120 endDate = Time.getInstance(dates.getObjectAt(1)); 121 122 subject = X509Name.getInstance(seq.getObjectAt(seqStart + 5)); 123 124 subjectPublicKeyInfo = SubjectPublicKeyInfo.getInstance(seq.getObjectAt(seqStart + 6)); 128 129 for (int extras = seq.size() - (seqStart + 6) - 1; extras > 0; extras--) 130 { 131 DERTaggedObject extra = (DERTaggedObject)seq.getObjectAt(seqStart + 6 + extras); 132 133 switch (extra.getTagNo()) 134 { 135 case 1: 136 issuerUniqueId = DERBitString.getInstance(extra); 137 break; 138 case 2: 139 subjectUniqueId = DERBitString.getInstance(extra); 140 break; 141 case 3: 142 extensions = X509Extensions.getInstance(extra); 143 } 144 } 145 } 146 147 public int getVersion() 148 { 149 return version.getValue().intValue() + 1; 150 } 151 152 public DERInteger getVersionNumber() 153 { 154 return version; 155 } 156 157 public DERInteger getSerialNumber() 158 { 159 return serialNumber; 160 } 161 162 public AlgorithmIdentifier getSignature() 163 { 164 return signature; 165 } 166 167 public X509Name getIssuer() 168 { 169 return issuer; 170 } 171 172 public Time getStartDate() 173 { 174 return startDate; 175 } 176 177 public Time getEndDate() 178 { 179 return endDate; 180 } 181 182 public X509Name getSubject() 183 { 184 return subject; 185 } 186 187 public SubjectPublicKeyInfo getSubjectPublicKeyInfo() 188 { 189 return subjectPublicKeyInfo; 190 } 191 192 public DERBitString getIssuerUniqueId() 193 { 194 return issuerUniqueId; 195 } 196 197 public DERBitString getSubjectUniqueId() 198 { 199 return subjectUniqueId; 200 } 201 202 public X509Extensions getExtensions() 203 { 204 return extensions; 205 } 206 207 public DERObject getDERObject() 208 { 209 return seq; 210 } 211 } 212 | Popular Tags |