001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.geronimo.crypto.asn1.x509;
017:
018: import org.apache.geronimo.crypto.asn1.ASN1EncodableVector;
019: import org.apache.geronimo.crypto.asn1.DERInteger;
020: import org.apache.geronimo.crypto.asn1.DERSequence;
021: import org.apache.geronimo.crypto.asn1.DERTaggedObject;
022: import org.apache.geronimo.crypto.asn1.DERUTCTime;
023:
024: /**
025: * Generator for Version 3 TBSCertificateStructures.
026: * <pre>
027: * TBSCertificate ::= SEQUENCE {
028: * version [ 0 ] Version DEFAULT v1(0),
029: * serialNumber CertificateSerialNumber,
030: * signature AlgorithmIdentifier,
031: * issuer Name,
032: * validity Validity,
033: * subject Name,
034: * subjectPublicKeyInfo SubjectPublicKeyInfo,
035: * issuerUniqueID [ 1 ] IMPLICIT UniqueIdentifier OPTIONAL,
036: * subjectUniqueID [ 2 ] IMPLICIT UniqueIdentifier OPTIONAL,
037: * extensions [ 3 ] Extensions OPTIONAL
038: * }
039: * </pre>
040: *
041: */
042: public class V3TBSCertificateGenerator {
043: DERTaggedObject version = new DERTaggedObject(0, new DERInteger(2));
044:
045: DERInteger serialNumber;
046: AlgorithmIdentifier signature;
047: X509Name issuer;
048: Time startDate, endDate;
049: X509Name subject;
050: SubjectPublicKeyInfo subjectPublicKeyInfo;
051: X509Extensions extensions;
052:
053: public V3TBSCertificateGenerator() {
054: }
055:
056: public void setSerialNumber(DERInteger serialNumber) {
057: this .serialNumber = serialNumber;
058: }
059:
060: public void setSignature(AlgorithmIdentifier signature) {
061: this .signature = signature;
062: }
063:
064: public void setIssuer(X509Name issuer) {
065: this .issuer = issuer;
066: }
067:
068: public void setStartDate(DERUTCTime startDate) {
069: this .startDate = new Time(startDate);
070: }
071:
072: public void setStartDate(Time startDate) {
073: this .startDate = startDate;
074: }
075:
076: public void setEndDate(DERUTCTime endDate) {
077: this .endDate = new Time(endDate);
078: }
079:
080: public void setEndDate(Time endDate) {
081: this .endDate = endDate;
082: }
083:
084: public void setSubject(X509Name subject) {
085: this .subject = subject;
086: }
087:
088: public void setSubjectPublicKeyInfo(SubjectPublicKeyInfo pubKeyInfo) {
089: this .subjectPublicKeyInfo = pubKeyInfo;
090: }
091:
092: public void setExtensions(X509Extensions extensions) {
093: this .extensions = extensions;
094: }
095:
096: public TBSCertificateStructure generateTBSCertificate() {
097: if ((serialNumber == null) || (signature == null)
098: || (issuer == null) || (startDate == null)
099: || (endDate == null) || (subject == null)
100: || (subjectPublicKeyInfo == null)) {
101: throw new IllegalStateException(
102: "not all mandatory fields set in V3 TBScertificate generator");
103: }
104:
105: ASN1EncodableVector v = new ASN1EncodableVector();
106:
107: v.add(version);
108: v.add(serialNumber);
109: v.add(signature);
110: v.add(issuer);
111:
112: //
113: // before and after dates
114: //
115: ASN1EncodableVector validity = new ASN1EncodableVector();
116:
117: validity.add(startDate);
118: validity.add(endDate);
119:
120: v.add(new DERSequence(validity));
121:
122: v.add(subject);
123:
124: v.add(subjectPublicKeyInfo);
125:
126: if (extensions != null) {
127: v.add(new DERTaggedObject(3, extensions));
128: }
129:
130: return new TBSCertificateStructure(new DERSequence(v));
131: }
132: }
|