1 17 18 package org.apache.geronimo.util.asn1.x509; 19 20 import java.io.IOException ; 21 import java.util.Enumeration ; 22 import java.util.Vector ; 23 24 import org.apache.geronimo.util.asn1.ASN1EncodableVector; 25 import org.apache.geronimo.util.asn1.ASN1Sequence; 26 import org.apache.geronimo.util.asn1.DERGeneralizedTime; 27 import org.apache.geronimo.util.asn1.DERInteger; 28 import org.apache.geronimo.util.asn1.DEROctetString; 29 import org.apache.geronimo.util.asn1.DERSequence; 30 import org.apache.geronimo.util.asn1.DERTaggedObject; 31 import org.apache.geronimo.util.asn1.DERUTCTime; 32 33 56 public class V2TBSCertListGenerator 57 { 58 DERInteger version = new DERInteger(1); 59 60 AlgorithmIdentifier signature; 61 X509Name issuer; 62 Time thisUpdate, nextUpdate=null; 63 X509Extensions extensions=null; 64 private Vector crlentries=null; 65 66 public V2TBSCertListGenerator() 67 { 68 } 69 70 71 public void setSignature( 72 AlgorithmIdentifier signature) 73 { 74 this.signature = signature; 75 } 76 77 public void setIssuer( 78 X509Name issuer) 79 { 80 this.issuer = issuer; 81 } 82 83 public void setThisUpdate( 84 DERUTCTime thisUpdate) 85 { 86 this.thisUpdate = new Time(thisUpdate); 87 } 88 89 public void setNextUpdate( 90 DERUTCTime nextUpdate) 91 { 92 this.nextUpdate = new Time(nextUpdate); 93 } 94 95 public void setThisUpdate( 96 Time thisUpdate) 97 { 98 this.thisUpdate = thisUpdate; 99 } 100 101 public void setNextUpdate( 102 Time nextUpdate) 103 { 104 this.nextUpdate = nextUpdate; 105 } 106 107 public void addCRLEntry( 108 ASN1Sequence crlEntry) 109 { 110 if (crlentries == null) 111 crlentries = new Vector (); 112 crlentries.addElement(crlEntry); 113 } 114 115 public void addCRLEntry(DERInteger userCertificate, DERUTCTime revocationDate, int reason) 116 { 117 addCRLEntry(userCertificate, new Time(revocationDate), reason); 118 } 119 120 public void addCRLEntry(DERInteger userCertificate, Time revocationDate, int reason) 121 { 122 addCRLEntry(userCertificate, revocationDate, reason, null); 123 } 124 125 public void addCRLEntry(DERInteger userCertificate, Time revocationDate, int reason, DERGeneralizedTime invalidityDate) 126 { 127 ASN1EncodableVector v = new ASN1EncodableVector(); 128 129 v.add(userCertificate); 130 v.add(revocationDate); 131 132 Vector extOids = new Vector (); 133 Vector extValues = new Vector (); 134 135 if (reason != 0) 136 { 137 CRLReason crlReason = new CRLReason(reason); 138 139 try 140 { 141 extOids.addElement(X509Extensions.ReasonCode); 142 extValues.addElement(new X509Extension(false, new DEROctetString(crlReason.getEncoded()))); 143 } 144 catch (IOException e) 145 { 146 throw new IllegalArgumentException ("error encoding reason: " + e); 147 } 148 } 149 150 if (invalidityDate != null) 151 { 152 try 153 { 154 extOids.addElement(X509Extensions.InvalidityDate); 155 extValues.addElement(new X509Extension(false, new DEROctetString(invalidityDate.getEncoded()))); 156 } 157 catch (IOException e) 158 { 159 throw new IllegalArgumentException ("error encoding invalidityDate: " + e); 160 } 161 } 162 163 if (extOids.size() != 0) 164 { 165 X509Extensions ex = new X509Extensions(extOids, extValues); 166 v.add(ex); 167 } 168 169 if (crlentries == null) 170 { 171 crlentries = new Vector (); 172 } 173 174 crlentries.addElement(new DERSequence(v)); 175 } 176 177 public void setExtensions( 178 X509Extensions extensions) 179 { 180 this.extensions = extensions; 181 } 182 183 public TBSCertList generateTBSCertList() 184 { 185 if ((signature == null) || (issuer == null) || (thisUpdate == null)) 186 { 187 throw new IllegalStateException ("Not all mandatory fields set in V2 TBSCertList generator."); 188 } 189 190 ASN1EncodableVector v = new ASN1EncodableVector(); 191 192 v.add(version); 193 v.add(signature); 194 v.add(issuer); 195 196 v.add(thisUpdate); 197 if (nextUpdate != null) 198 { 199 v.add(nextUpdate); 200 } 201 202 if (crlentries != null) 204 { 205 ASN1EncodableVector certs = new ASN1EncodableVector(); 206 Enumeration it = crlentries.elements(); 207 while( it.hasMoreElements() ) 208 { 209 certs.add((ASN1Sequence)it.nextElement()); 210 } 211 v.add(new DERSequence(certs)); 212 } 213 214 if (extensions != null) 215 { 216 v.add(new DERTaggedObject(0, extensions)); 217 } 218 219 return new TBSCertList(new DERSequence(v)); 220 } 221 } 222 | Popular Tags |