1 17 18 package org.apache.geronimo.util.asn1.x509; 19 20 import org.apache.geronimo.util.asn1.ASN1EncodableVector; 21 import org.apache.geronimo.util.asn1.DERInteger; 22 import org.apache.geronimo.util.asn1.DERSequence; 23 import org.apache.geronimo.util.asn1.DERTaggedObject; 24 import org.apache.geronimo.util.asn1.DERUTCTime; 25 26 44 public class V3TBSCertificateGenerator 45 { 46 DERTaggedObject version = new DERTaggedObject(0, new DERInteger(2)); 47 48 DERInteger serialNumber; 49 AlgorithmIdentifier signature; 50 X509Name issuer; 51 Time startDate, endDate; 52 X509Name subject; 53 SubjectPublicKeyInfo subjectPublicKeyInfo; 54 X509Extensions extensions; 55 56 public V3TBSCertificateGenerator() 57 { 58 } 59 60 public void setSerialNumber( 61 DERInteger serialNumber) 62 { 63 this.serialNumber = serialNumber; 64 } 65 66 public void setSignature( 67 AlgorithmIdentifier signature) 68 { 69 this.signature = signature; 70 } 71 72 public void setIssuer( 73 X509Name issuer) 74 { 75 this.issuer = issuer; 76 } 77 78 public void setStartDate( 79 DERUTCTime startDate) 80 { 81 this.startDate = new Time(startDate); 82 } 83 84 public void setStartDate( 85 Time startDate) 86 { 87 this.startDate = startDate; 88 } 89 90 public void setEndDate( 91 DERUTCTime endDate) 92 { 93 this.endDate = new Time(endDate); 94 } 95 96 public void setEndDate( 97 Time endDate) 98 { 99 this.endDate = endDate; 100 } 101 102 public void setSubject( 103 X509Name subject) 104 { 105 this.subject = subject; 106 } 107 108 public void setSubjectPublicKeyInfo( 109 SubjectPublicKeyInfo pubKeyInfo) 110 { 111 this.subjectPublicKeyInfo = pubKeyInfo; 112 } 113 114 public void setExtensions( 115 X509Extensions extensions) 116 { 117 this.extensions = extensions; 118 } 119 120 public TBSCertificateStructure generateTBSCertificate() 121 { 122 if ((serialNumber == null) || (signature == null) 123 || (issuer == null) || (startDate == null) || (endDate == null) 124 || (subject == null) || (subjectPublicKeyInfo == null)) 125 { 126 throw new IllegalStateException ("not all mandatory fields set in V3 TBScertificate generator"); 127 } 128 129 ASN1EncodableVector v = new ASN1EncodableVector(); 130 131 v.add(version); 132 v.add(serialNumber); 133 v.add(signature); 134 v.add(issuer); 135 136 ASN1EncodableVector validity = new ASN1EncodableVector(); 140 141 validity.add(startDate); 142 validity.add(endDate); 143 144 v.add(new DERSequence(validity)); 145 146 v.add(subject); 147 148 v.add(subjectPublicKeyInfo); 149 150 if (extensions != null) 151 { 152 v.add(new DERTaggedObject(3, extensions)); 153 } 154 155 return new TBSCertificateStructure(new DERSequence(v)); 156 } 157 } 158 | Popular Tags |