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 1 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: * }
036: * </pre>
037: *
038: */
039: public class V1TBSCertificateGenerator {
040: DERTaggedObject version = new DERTaggedObject(0, new DERInteger(0));
041:
042: DERInteger serialNumber;
043: AlgorithmIdentifier signature;
044: X509Name issuer;
045: Time startDate, endDate;
046: X509Name subject;
047: SubjectPublicKeyInfo subjectPublicKeyInfo;
048:
049: public V1TBSCertificateGenerator() {
050: }
051:
052: public void setSerialNumber(DERInteger serialNumber) {
053: this .serialNumber = serialNumber;
054: }
055:
056: public void setSignature(AlgorithmIdentifier signature) {
057: this .signature = signature;
058: }
059:
060: public void setIssuer(X509Name issuer) {
061: this .issuer = issuer;
062: }
063:
064: public void setStartDate(Time startDate) {
065: this .startDate = startDate;
066: }
067:
068: public void setStartDate(DERUTCTime startDate) {
069: this .startDate = new Time(startDate);
070: }
071:
072: public void setEndDate(Time endDate) {
073: this .endDate = endDate;
074: }
075:
076: public void setEndDate(DERUTCTime endDate) {
077: this .endDate = new Time(endDate);
078: }
079:
080: public void setSubject(X509Name subject) {
081: this .subject = subject;
082: }
083:
084: public void setSubjectPublicKeyInfo(SubjectPublicKeyInfo pubKeyInfo) {
085: this .subjectPublicKeyInfo = pubKeyInfo;
086: }
087:
088: public TBSCertificateStructure generateTBSCertificate() {
089: if ((serialNumber == null) || (signature == null)
090: || (issuer == null) || (startDate == null)
091: || (endDate == null) || (subject == null)
092: || (subjectPublicKeyInfo == null)) {
093: throw new IllegalStateException(
094: "not all mandatory fields set in V1 TBScertificate generator");
095: }
096:
097: ASN1EncodableVector seq = new ASN1EncodableVector();
098:
099: // seq.add(version); - not required as default value.
100: seq.add(serialNumber);
101: seq.add(signature);
102: seq.add(issuer);
103:
104: //
105: // before and after dates
106: //
107: ASN1EncodableVector validity = new ASN1EncodableVector();
108:
109: validity.add(startDate);
110: validity.add(endDate);
111:
112: seq.add(new DERSequence(validity));
113:
114: seq.add(subject);
115:
116: seq.add(subjectPublicKeyInfo);
117:
118: return new TBSCertificateStructure(new DERSequence(seq));
119: }
120: }
|