001: package org.bouncycastle.asn1.x509;
002:
003: import org.bouncycastle.asn1.ASN1EncodableVector;
004: import org.bouncycastle.asn1.DERInteger;
005: import org.bouncycastle.asn1.DERSequence;
006: import org.bouncycastle.asn1.DERTaggedObject;
007: import org.bouncycastle.asn1.DERUTCTime;
008:
009: /**
010: * Generator for Version 1 TBSCertificateStructures.
011: * <pre>
012: * TBSCertificate ::= SEQUENCE {
013: * version [ 0 ] Version DEFAULT v1(0),
014: * serialNumber CertificateSerialNumber,
015: * signature AlgorithmIdentifier,
016: * issuer Name,
017: * validity Validity,
018: * subject Name,
019: * subjectPublicKeyInfo SubjectPublicKeyInfo,
020: * }
021: * </pre>
022: *
023: */
024: public class V1TBSCertificateGenerator {
025: DERTaggedObject version = new DERTaggedObject(0, new DERInteger(0));
026:
027: DERInteger serialNumber;
028: AlgorithmIdentifier signature;
029: X509Name issuer;
030: Time startDate, endDate;
031: X509Name subject;
032: SubjectPublicKeyInfo subjectPublicKeyInfo;
033:
034: public V1TBSCertificateGenerator() {
035: }
036:
037: public void setSerialNumber(DERInteger serialNumber) {
038: this .serialNumber = serialNumber;
039: }
040:
041: public void setSignature(AlgorithmIdentifier signature) {
042: this .signature = signature;
043: }
044:
045: public void setIssuer(X509Name issuer) {
046: this .issuer = issuer;
047: }
048:
049: public void setStartDate(Time startDate) {
050: this .startDate = startDate;
051: }
052:
053: public void setStartDate(DERUTCTime startDate) {
054: this .startDate = new Time(startDate);
055: }
056:
057: public void setEndDate(Time endDate) {
058: this .endDate = endDate;
059: }
060:
061: public void setEndDate(DERUTCTime endDate) {
062: this .endDate = new Time(endDate);
063: }
064:
065: public void setSubject(X509Name subject) {
066: this .subject = subject;
067: }
068:
069: public void setSubjectPublicKeyInfo(SubjectPublicKeyInfo pubKeyInfo) {
070: this .subjectPublicKeyInfo = pubKeyInfo;
071: }
072:
073: public TBSCertificateStructure generateTBSCertificate() {
074: if ((serialNumber == null) || (signature == null)
075: || (issuer == null) || (startDate == null)
076: || (endDate == null) || (subject == null)
077: || (subjectPublicKeyInfo == null)) {
078: throw new IllegalStateException(
079: "not all mandatory fields set in V1 TBScertificate generator");
080: }
081:
082: ASN1EncodableVector seq = new ASN1EncodableVector();
083:
084: // seq.add(version); - not required as default value.
085: seq.add(serialNumber);
086: seq.add(signature);
087: seq.add(issuer);
088:
089: //
090: // before and after dates
091: //
092: ASN1EncodableVector validity = new ASN1EncodableVector();
093:
094: validity.add(startDate);
095: validity.add(endDate);
096:
097: seq.add(new DERSequence(validity));
098:
099: seq.add(subject);
100:
101: seq.add(subjectPublicKeyInfo);
102:
103: return new TBSCertificateStructure(new DERSequence(seq));
104: }
105: }
|