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