diff options
Diffstat (limited to 'pki/base/util/src/com/netscape/cmsutil/ocsp')
19 files changed, 1520 insertions, 1276 deletions
diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/BasicOCSPResponse.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/BasicOCSPResponse.java index bdb9188e..f6306b78 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/BasicOCSPResponse.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/BasicOCSPResponse.java @@ -35,7 +35,7 @@ import org.mozilla.jss.pkix.primitive.AlgorithmIdentifier; /** * RFC 2560: - * + * * <pre> * BasicOCSPResponse ::= SEQUENCE { * tbsResponseData ResponseData, @@ -43,10 +43,11 @@ import org.mozilla.jss.pkix.primitive.AlgorithmIdentifier; * signature BIT STRING, * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class BasicOCSPResponse implements Response { +public class BasicOCSPResponse implements Response +{ private byte mData[] = null; private ResponseData _rd = null; private AlgorithmIdentifier _signAlg = null; @@ -54,43 +55,47 @@ public class BasicOCSPResponse implements Response { private Certificate _certs[] = null; public BasicOCSPResponse(ResponseData rd, AlgorithmIdentifier signAlg, - BIT_STRING signature, Certificate certs[]) { + BIT_STRING signature, Certificate certs[]) + { _rd = rd; _signAlg = signAlg; _signature = signature; _certs = certs; } - public BasicOCSPResponse(OCTET_STRING os) { + public BasicOCSPResponse(OCTET_STRING os) + { this(os.toByteArray()); } - public BasicOCSPResponse(byte data[]) { + public BasicOCSPResponse(byte data[]) + { mData = data; // extract _rd, _signAlg, _signature and _certs try { - BasicOCSPResponse resp = (BasicOCSPResponse) getTemplate().decode( - new ByteArrayInputStream(data)); + BasicOCSPResponse resp = (BasicOCSPResponse) getTemplate().decode(new ByteArrayInputStream(data)); _rd = resp.getResponseData(); _signAlg = resp.getSignatureAlgorithm(); _signature = resp.getSignature(); _certs = resp.getCerts(); - } catch (Exception e) { + } catch (Exception e) { // exception in decoding byte data - } + } } private static final Tag TAG = SEQUENCE.TAG; - public Tag getTag() { + public Tag getTag() + { return TAG; } - public void encode(Tag t, OutputStream os) throws IOException { - if (mData != null) { - os.write(mData); - } else { + public void encode(Tag t, OutputStream os) throws IOException + { + if (mData != null) { + os.write(mData); + } else { SEQUENCE seq = new SEQUENCE(); seq.addElement(_rd); seq.addElement(_signAlg); @@ -100,42 +105,50 @@ public class BasicOCSPResponse implements Response { for (Certificate c : _certs) { certsSeq.addElement(c); } - EXPLICIT certsExplicit = new EXPLICIT(new Tag(0), certsSeq); + EXPLICIT certsExplicit = new EXPLICIT(new Tag(0),certsSeq); seq.addElement(certsExplicit); } - seq.encode(t, os); - } + seq.encode(t,os); + } } - public void encode(OutputStream os) throws IOException { + public void encode(OutputStream os) throws IOException + { encode(TAG, os); } - public OCTET_STRING getBytes() { + public OCTET_STRING getBytes() + { return null; } - public ResponseData getResponseData() { + public ResponseData getResponseData() + { return _rd; } - public AlgorithmIdentifier getSignatureAlgorithm() { + public AlgorithmIdentifier getSignatureAlgorithm() + { return _signAlg; } - public BIT_STRING getSignature() { + public BIT_STRING getSignature() + { return _signature; } - public int getCertsCount() { + public int getCertsCount() + { return (_certs != null) ? _certs.length : 0; } - public Certificate[] getCerts() { - return _certs; + public Certificate[] getCerts() + { + return _certs; } - public Certificate getCertificateAt(int pos) { + public Certificate getCertificateAt(int pos) + { return (_certs != null) ? _certs[pos] : null; } @@ -148,48 +161,54 @@ public class BasicOCSPResponse implements Response { /** * A Template for decoding <code>ResponseBytes</code>. */ - public static class Template implements ASN1Template { + public static class Template implements ASN1Template + { private SEQUENCE.Template seqt; - public Template() { - seqt = new SEQUENCE.Template(); - seqt.addElement(ResponseData.getTemplate()); - seqt.addElement(AlgorithmIdentifier.getTemplate()); - seqt.addElement(BIT_STRING.getTemplate()); - seqt.addOptionalElement(new EXPLICIT.Template(new Tag(0), - new SEQUENCE.OF_Template(Certificate.getTemplate()))); - } - - public boolean tagMatch(Tag tag) { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - - ResponseData rd = (ResponseData) seq.elementAt(0); - AlgorithmIdentifier alg = (AlgorithmIdentifier) seq.elementAt(1); - BIT_STRING bs = (BIT_STRING) seq.elementAt(2); - Certificate[] certs = null; - if (seq.size() == 4) { - // optional certificates are present - EXPLICIT certSeqExplicit = (EXPLICIT) seq.elementAt(3); - SEQUENCE certSeq = (SEQUENCE) certSeqExplicit.getContent(); - if (certSeq != null) { - certs = new Certificate[certSeq.size()]; - for (int x = 0; x < certSeq.size(); x++) { - certs[x] = (Certificate) certSeq.elementAt(x); - } - } - } - - return new BasicOCSPResponse(rd, alg, bs, certs); - } + public Template() + { + seqt = new SEQUENCE.Template(); + seqt.addElement( ResponseData.getTemplate() ); + seqt.addElement( AlgorithmIdentifier.getTemplate() ); + seqt.addElement( BIT_STRING.getTemplate() ); + seqt.addOptionalElement( new EXPLICIT.Template( + new Tag(0), new SEQUENCE.OF_Template( + Certificate.getTemplate())) ); + } + + public boolean tagMatch(Tag tag) + { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException + { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException + { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); + + ResponseData rd = (ResponseData)seq.elementAt(0); + AlgorithmIdentifier alg = (AlgorithmIdentifier)seq.elementAt(1); + BIT_STRING bs = (BIT_STRING)seq.elementAt(2); + Certificate[] certs = null; + if (seq.size() == 4) { + // optional certificates are present + EXPLICIT certSeqExplicit = (EXPLICIT) seq.elementAt(3); + SEQUENCE certSeq = (SEQUENCE) certSeqExplicit.getContent(); + if (certSeq != null) { + certs = new Certificate[certSeq.size()]; + for (int x = 0; x < certSeq.size(); x++) { + certs[x] = (Certificate) certSeq.elementAt(x); + } + } + } + + return new BasicOCSPResponse(rd, alg, bs, certs); + } } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/CertID.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/CertID.java index 816cc81c..29fbc4e8 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/CertID.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/CertID.java @@ -32,7 +32,7 @@ import org.mozilla.jss.pkix.primitive.AlgorithmIdentifier; /** * RFC 2560: - * + * * <pre> * CertID ::= SEQUENCE { * hashAlgorithm AlgorithmIdentifier, @@ -40,116 +40,131 @@ import org.mozilla.jss.pkix.primitive.AlgorithmIdentifier; * issuerKeyHash OCTET STRING, -- Hash of Issuers public key * serialNumber CertificateSerialNumber } * </pre> - * + * * @version $Revision$ $Date$ */ -public class CertID implements ASN1Value { - // ///////////////////////////////////////////////////////////////////// - // Members and member access - // ///////////////////////////////////////////////////////////////////// - private AlgorithmIdentifier hashAlgorithm; - private OCTET_STRING issuerNameHash; - private OCTET_STRING issuerKeyHash; - private INTEGER serialNumber; - private SEQUENCE sequence; - - public AlgorithmIdentifier getHashAlgorithm() { - return hashAlgorithm; - } - - public OCTET_STRING getIssuerNameHash() { - return issuerNameHash; - } - - public OCTET_STRING getIssuerKeyHash() { - return issuerKeyHash; - } - - public INTEGER getSerialNumber() { - return serialNumber; - } - - // ///////////////////////////////////////////////////////////////////// - // Constructors - // ///////////////////////////////////////////////////////////////////// - private CertID() { - } - - public CertID(AlgorithmIdentifier hashAlgorithm, - OCTET_STRING issuerNameHash, OCTET_STRING issuerKeyHash, - INTEGER serialNumber) { - sequence = new SEQUENCE(); - - this.hashAlgorithm = hashAlgorithm; - sequence.addElement(hashAlgorithm); - - this.issuerNameHash = issuerNameHash; - sequence.addElement(issuerNameHash); - - this.issuerKeyHash = issuerKeyHash; - sequence.addElement(issuerKeyHash); - - this.serialNumber = serialNumber; - sequence.addElement(serialNumber); - } - - // ///////////////////////////////////////////////////////////////////// - // encoding/decoding - // ///////////////////////////////////////////////////////////////////// - - private static final Tag TAG = SEQUENCE.TAG; - - public Tag getTag() { - return TAG; - } - - public void encode(OutputStream ostream) throws IOException { - encode(TAG, ostream); - } - - public void encode(Tag implicitTag, OutputStream ostream) - throws IOException { - sequence.encode(implicitTag, ostream); - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; - } - - /** - * A Template for decoding a <code>CertID</code>. - */ - public static class Template implements ASN1Template { - - private SEQUENCE.Template seqt; - - public Template() { - seqt = new SEQUENCE.Template(); - seqt.addElement(AlgorithmIdentifier.getTemplate()); - seqt.addElement(OCTET_STRING.getTemplate()); - seqt.addElement(OCTET_STRING.getTemplate()); - seqt.addElement(INTEGER.getTemplate()); - } - - public boolean tagMatch(Tag tag) { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - - return new CertID((AlgorithmIdentifier) seq.elementAt(0), - (OCTET_STRING) seq.elementAt(1), - (OCTET_STRING) seq.elementAt(2), (INTEGER) seq.elementAt(3)); - } - } +public class CertID implements ASN1Value +{ + /////////////////////////////////////////////////////////////////////// + // Members and member access + /////////////////////////////////////////////////////////////////////// + private AlgorithmIdentifier hashAlgorithm; + private OCTET_STRING issuerNameHash; + private OCTET_STRING issuerKeyHash; + private INTEGER serialNumber; + private SEQUENCE sequence; + + public AlgorithmIdentifier getHashAlgorithm() + { + return hashAlgorithm; + } + + public OCTET_STRING getIssuerNameHash() + { + return issuerNameHash; + } + + public OCTET_STRING getIssuerKeyHash() + { + return issuerKeyHash; + } + + public INTEGER getSerialNumber() + { + return serialNumber; + } + + /////////////////////////////////////////////////////////////////////// + // Constructors + /////////////////////////////////////////////////////////////////////// + private CertID() { } + + public CertID(AlgorithmIdentifier hashAlgorithm, + OCTET_STRING issuerNameHash, OCTET_STRING issuerKeyHash, + INTEGER serialNumber) + { + sequence = new SEQUENCE(); + + this.hashAlgorithm = hashAlgorithm; + sequence.addElement(hashAlgorithm); + + this.issuerNameHash = issuerNameHash; + sequence.addElement(issuerNameHash); + + this.issuerKeyHash = issuerKeyHash; + sequence.addElement(issuerKeyHash); + + this.serialNumber = serialNumber; + sequence.addElement(serialNumber); + } + + /////////////////////////////////////////////////////////////////////// + // encoding/decoding + /////////////////////////////////////////////////////////////////////// + + private static final Tag TAG = SEQUENCE.TAG; + + public Tag getTag() + { + return TAG; + } + + public void encode(OutputStream ostream) throws IOException + { + encode(TAG, ostream); + } + + public void encode(Tag implicitTag, OutputStream ostream) + throws IOException + { + sequence.encode(implicitTag, ostream); + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } + + /** + * A Template for decoding a <code>CertID</code>. + */ + public static class Template implements ASN1Template + { + + private SEQUENCE.Template seqt; + + public Template() + { + seqt = new SEQUENCE.Template(); + seqt.addElement( AlgorithmIdentifier.getTemplate() ); + seqt.addElement( OCTET_STRING.getTemplate() ); + seqt.addElement( OCTET_STRING.getTemplate() ); + seqt.addElement( INTEGER.getTemplate() ); + } + + public boolean tagMatch(Tag tag) + { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException + { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException + { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); + + return new CertID( + (AlgorithmIdentifier) seq.elementAt(0), + (OCTET_STRING) seq.elementAt(1), + (OCTET_STRING) seq.elementAt(2), + (INTEGER) seq.elementAt(3)); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/CertStatus.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/CertStatus.java index a90eb215..c6fe4b51 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/CertStatus.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/CertStatus.java @@ -21,15 +21,16 @@ import org.mozilla.jss.asn1.ASN1Value; /** * RFC 2560: - * + * * <pre> * CertStatus ::= CHOICE { * good [0] IMPLICIT NULL, * revoked [1] IMPLICIT RevokedInfo, * unknown [2] IMPLICIT UnknownInfo } * </pre> - * + * * @version $Revision$ $Date$ */ -public interface CertStatus extends ASN1Value { +public interface CertStatus extends ASN1Value +{ } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/GoodInfo.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/GoodInfo.java index fe777214..c0b5015d 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/GoodInfo.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/GoodInfo.java @@ -30,69 +30,79 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * CertStatus ::= CHOICE { * good [0] IMPLICIT NULL, * revoked [1] IMPLICIT RevokedInfo, * unknown [2] IMPLICIT UnknownInfo } * </pre> - * + * * @version $Revision$ $Date$ */ -public class GoodInfo implements CertStatus { - private static final Tag TAG = SEQUENCE.TAG; +public class GoodInfo implements CertStatus +{ + private static final Tag TAG = SEQUENCE.TAG; - public GoodInfo() { - } + public GoodInfo() + { + } - public Tag getTag() { - return Tag.get(0); - } + public Tag getTag() + { + return Tag.get(0); + } - public void encode(Tag t, OutputStream os) throws IOException { - NULL.getInstance().encode(getTag(), os); - } + public void encode(Tag t, OutputStream os) throws IOException + { + NULL.getInstance().encode(getTag(), os); + } - public void encode(OutputStream os) throws IOException { - encode(getTag(), os); - } + public void encode(OutputStream os) throws IOException + { + encode(getTag(), os); + } - private static final Template templateInstance = new Template(); + private static final Template templateInstance = new Template(); - public static Template getTemplate() { - return templateInstance; - } + public static Template getTemplate() { + return templateInstance; + } - /** - * A Template for decoding <code>ResponseBytes</code>. - */ - public static class Template implements ASN1Template { + /** + * A Template for decoding <code>ResponseBytes</code>. + */ + public static class Template implements ASN1Template + { - private SEQUENCE.Template seqt; + private SEQUENCE.Template seqt; - public Template() { - seqt = new SEQUENCE.Template(); - seqt.addElement(new NULL.Template()); + public Template() + { + seqt = new SEQUENCE.Template(); + seqt.addElement(new NULL.Template() ); - } + } - public boolean tagMatch(Tag tag) { - return TAG.equals(tag); - } + public boolean tagMatch(Tag tag) + { + return TAG.equals(tag); + } - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { - return decode(TAG, istream); - } + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException + { + return decode(TAG, istream); + } - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { - // SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, - // istream); + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException + { + // SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, + // istream); - return new GoodInfo(); + return new GoodInfo(); + } } - } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/KeyHashID.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/KeyHashID.java index 4e2454b3..96a3e44f 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/KeyHashID.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/KeyHashID.java @@ -30,75 +30,87 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * ResponderID ::= CHOICE { * byName [1] EXPLICIT Name, * byKey [2] EXPLICIT KeyHash } * </pre> - * + * * @version $Revision$ $Date$ */ -public class KeyHashID implements ResponderID { - private OCTET_STRING _hash = null; - private static final Tag TAG = SEQUENCE.TAG; - - public KeyHashID(OCTET_STRING hash) { - _hash = hash; - } - - public Tag getTag() { - return Tag.get(2); - } - - public void encode(Tag tag, OutputStream os) throws IOException { - _hash.encode(os); - } - - public void encode(OutputStream os) throws IOException { - _hash.encode(os); - } - - public OCTET_STRING getHash() { - return _hash; - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; - } - - /** - * A Template for decoding <code>ResponseBytes</code>. - */ - public static class Template implements ASN1Template { - - private SEQUENCE.Template seqt; - - public Template() { - seqt = new SEQUENCE.Template(); - // seqt.addElement(new EXPLICIT.Template( - // new Tag (2), new OCTET_STRING.Template()) ); - seqt.addElement(new OCTET_STRING.Template()); - - } - - public boolean tagMatch(Tag tag) { - return TAG.equals(tag); +public class KeyHashID implements ResponderID +{ + private OCTET_STRING _hash = null; + private static final Tag TAG = SEQUENCE.TAG; + + public KeyHashID(OCTET_STRING hash) + { + _hash = hash; + } + + public Tag getTag() + { + return Tag.get(2); + } + + public void encode(Tag tag, OutputStream os) throws IOException + { + _hash.encode(os); + } + + public void encode(OutputStream os) throws IOException + { + _hash.encode(os); + } + + public OCTET_STRING getHash() + { + return _hash; + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; } - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - - OCTET_STRING o = (OCTET_STRING) seq.elementAt(0); - return new KeyHashID(o); - } - } + /** + * A Template for decoding <code>ResponseBytes</code>. + */ + public static class Template implements ASN1Template + { + + private SEQUENCE.Template seqt; + + public Template() + { + seqt = new SEQUENCE.Template(); +// seqt.addElement(new EXPLICIT.Template( + // new Tag (2), new OCTET_STRING.Template()) ); + seqt.addElement(new OCTET_STRING.Template() ); + + } + + public boolean tagMatch(Tag tag) + { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException + { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException + { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, + istream); + + OCTET_STRING o = (OCTET_STRING)seq.elementAt(0); + return new KeyHashID(o); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/NameID.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/NameID.java index 016c058d..aa6ef1b5 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/NameID.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/NameID.java @@ -30,76 +30,88 @@ import org.mozilla.jss.pkix.primitive.Name; /** * RFC 2560: - * + * * <pre> * ResponderID ::= CHOICE { * byName [1] EXPLICIT Name, * byKey [2] EXPLICIT KeyHash } * </pre> - * + * * @version $Revision$ $Date$ */ -public class NameID implements ResponderID { - private Name _name = null; - private static final Tag TAG = SEQUENCE.TAG; - - public NameID(Name n) { - _name = n; - } - - public Tag getTag() { - return Tag.get(1); - } - - public void encode(Tag tag, OutputStream os) throws IOException { - _name.encode(os); - } - - public void encode(OutputStream os) throws IOException { - _name.encode(os); - } - - public Name getName() { - return _name; - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; - } - - /** - * A Template for decoding <code>ResponseBytes</code>. - */ - public static class Template implements ASN1Template { - - private SEQUENCE.Template seqt; - - public Template() { - seqt = new SEQUENCE.Template(); - // seqt.addElement(new EXPLICIT.Template( - // new Tag (1), new Name.Template()) ); - seqt.addElement(new Name.Template()); - - } - - public boolean tagMatch(Tag tag) { - return TAG.equals(tag); +public class NameID implements ResponderID +{ + private Name _name = null; + private static final Tag TAG = SEQUENCE.TAG; + + public NameID(Name n) + { + _name = n; + } + + public Tag getTag() + { + return Tag.get(1); + } + + public void encode(Tag tag, OutputStream os) throws IOException + { + _name.encode(os); + } + + public void encode(OutputStream os) throws IOException + { + _name.encode(os); + } + + public Name getName() + { + return _name; + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; } - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - - // EXPLICIT e_name = (EXPLICIT) seq.elementAt(0); - Name name = (Name) seq.elementAt(0); - return new NameID(name); - } - } + /** + * A Template for decoding <code>ResponseBytes</code>. + */ + public static class Template implements ASN1Template + { + + private SEQUENCE.Template seqt; + + public Template() + { + seqt = new SEQUENCE.Template(); + // seqt.addElement(new EXPLICIT.Template( + // new Tag (1), new Name.Template()) ); + seqt.addElement(new Name.Template()); + + } + + public boolean tagMatch(Tag tag) + { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException + { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException + { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, + istream); + + // EXPLICIT e_name = (EXPLICIT) seq.elementAt(0); + Name name = (Name)seq.elementAt(0); + return new NameID(name); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPRequest.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPRequest.java index 5476f322..98f50e7e 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPRequest.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPRequest.java @@ -30,119 +30,129 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * OCSPRequest ::= SEQUENCE { * tbsRequest TBSRequest, * optionalSignature [0] EXPLICIT Signature OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class OCSPRequest implements ASN1Value { - - // ///////////////////////////////////////////////////////////////////// - // Members and member access - // ///////////////////////////////////////////////////////////////////// - private TBSRequest tbsRequest; - private Signature optionalSignature; - private SEQUENCE sequence; - - /** - * Returns the <code>TBSRequest</code> field. - */ - public TBSRequest getTBSRequest() { - return tbsRequest; - } - - /** - * Returns the <code>Signature</code> field. - */ - public Signature getSignature() { - return optionalSignature; - } - - // ///////////////////////////////////////////////////////////////////// - // Constructors - // ///////////////////////////////////////////////////////////////////// - private OCSPRequest() { - } - - /* - * THIS code is probably broken. It does not properly encode the explicit - * element - */ - - public OCSPRequest(TBSRequest tbsRequest, Signature optionalSignature) { - sequence = new SEQUENCE(); - - this.tbsRequest = tbsRequest; - sequence.addElement(tbsRequest); - - this.optionalSignature = optionalSignature; - if (optionalSignature != null) { - sequence.addElement(optionalSignature); - } - } - - // ///////////////////////////////////////////////////////////////////// - // encoding/decoding - // ///////////////////////////////////////////////////////////////////// - private static final Tag TAG = SEQUENCE.TAG; - - public Tag getTag() { - return TAG; - } - - public void encode(OutputStream ostream) throws IOException { - encode(TAG, ostream); - } - - public void encode(Tag implicitTag, OutputStream ostream) - throws IOException { - sequence.encode(implicitTag, ostream); - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; - } - - /** - * A Template for decoding OCSPRequest. - */ - public static class Template implements ASN1Template { - - private SEQUENCE.Template seqt; - - public Template() { - seqt = new SEQUENCE.Template(); - seqt.addElement(TBSRequest.getTemplate()); - seqt.addOptionalElement(new EXPLICIT.Template(new Tag(0), - new Signature.Template())); - } - - public boolean tagMatch(Tag tag) { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { - SEQUENCE seq = (SEQUENCE) seqt.decode(istream); - Signature signature = null; - if (seq.elementAt(1) != null) { - signature = (Signature) ((EXPLICIT) seq.elementAt(1)) - .getContent(); - } - - return new OCSPRequest((TBSRequest) seq.elementAt(0), signature); - } - } +public class OCSPRequest implements ASN1Value +{ + + /////////////////////////////////////////////////////////////////////// + // Members and member access + /////////////////////////////////////////////////////////////////////// + private TBSRequest tbsRequest; + private Signature optionalSignature; + private SEQUENCE sequence; + + /** + * Returns the <code>TBSRequest</code> field. + */ + public TBSRequest getTBSRequest() + { + return tbsRequest; + } + + /** + * Returns the <code>Signature</code> field. + */ + public Signature getSignature() + { + return optionalSignature; + } + + /////////////////////////////////////////////////////////////////////// + // Constructors + /////////////////////////////////////////////////////////////////////// + private OCSPRequest() { } + + /* THIS code is probably broken. It does not properly encode the explicit element */ + + public OCSPRequest(TBSRequest tbsRequest, Signature optionalSignature) + { + sequence = new SEQUENCE(); + + this.tbsRequest = tbsRequest; + sequence.addElement(tbsRequest); + + this.optionalSignature = optionalSignature; + if (optionalSignature != null) { + sequence.addElement(optionalSignature); + } + } + + /////////////////////////////////////////////////////////////////////// + // encoding/decoding + /////////////////////////////////////////////////////////////////////// + private static final Tag TAG = SEQUENCE.TAG; + + public Tag getTag() + { + return TAG; + } + + public void encode(OutputStream ostream) throws IOException + { + encode(TAG, ostream); + } + + public void encode(Tag implicitTag, OutputStream ostream) + throws IOException + { + sequence.encode(implicitTag, ostream); + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() + { + return templateInstance; + } + + /** + * A Template for decoding OCSPRequest. + */ + public static class Template implements ASN1Template + { + + private SEQUENCE.Template seqt; + + public Template() + { + seqt = new SEQUENCE.Template(); + seqt.addElement(TBSRequest.getTemplate()); + seqt.addOptionalElement( new EXPLICIT.Template( new Tag(0), + new Signature.Template()) ); + } + + public boolean tagMatch(Tag tag) + { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException + { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException + { + SEQUENCE seq = (SEQUENCE) seqt.decode(istream); + Signature signature = null; + if (seq.elementAt(1) != null) { + signature = (Signature)((EXPLICIT)seq.elementAt(1)).getContent(); + } + + return new OCSPRequest( + (TBSRequest) seq.elementAt(0), + signature); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponse.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponse.java index eaa30268..67f6242c 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponse.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponse.java @@ -30,111 +30,123 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * OCSPResponse ::= SEQUENCE { * responseStatus OCSPResponseStatus, * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class OCSPResponse implements ASN1Value { - // ///////////////////////////////////////////////////////////////////// - // Members and member access - // ///////////////////////////////////////////////////////////////////// - private OCSPResponseStatus responseStatus = null; - private ResponseBytes responseBytes = null; - private SEQUENCE sequence; - - public OCSPResponseStatus getResponseStatus() { - return responseStatus; - } - - public ResponseBytes getResponseBytes() { - return responseBytes; - } - - // ///////////////////////////////////////////////////////////////////// - // Constructors - // ///////////////////////////////////////////////////////////////////// - private OCSPResponse() { - } - - public OCSPResponse(OCSPResponseStatus responseStatus, - ResponseBytes responseBytes) { - sequence = new SEQUENCE(); - - this.responseStatus = responseStatus; - sequence.addElement(responseStatus); - - this.responseBytes = responseBytes; - sequence.addElement(new EXPLICIT(Tag.get(0), responseBytes)); - } - - // ///////////////////////////////////////////////////////////////////// - // encoding/decoding - // ///////////////////////////////////////////////////////////////////// - - private static final Tag TAG = SEQUENCE.TAG; - - public Tag getTag() { - return TAG; - } - - public void encode(OutputStream ostream) throws IOException { - encode(TAG, ostream); - } - - public void encode(Tag implicitTag, OutputStream ostream) - throws IOException { - sequence.encode(implicitTag, ostream); - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; - } - - /** - * A Template for decoding an <code>OCSPResponse</code>. - */ - public static class Template implements ASN1Template { - - private SEQUENCE.Template seqt; - - public Template() { - seqt = new SEQUENCE.Template(); - seqt.addElement(OCSPResponseStatus.getTemplate()); - seqt.addOptionalElement(new EXPLICIT.Template(new Tag(0), - new ResponseBytes.Template())); - - } - - public boolean tagMatch(Tag tag) { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - - OCSPResponseStatus rs = (OCSPResponseStatus) seq.elementAt(0); - ResponseBytes rb = null; - ASN1Value val = seq.elementAt(1); - if (val instanceof EXPLICIT) { - EXPLICIT exp = (EXPLICIT) val; - rb = (ResponseBytes) exp.getContent(); - } else { - rb = (ResponseBytes) val; - } - return new OCSPResponse(rs, rb); - } - } +public class OCSPResponse implements ASN1Value +{ + /////////////////////////////////////////////////////////////////////// + // Members and member access + /////////////////////////////////////////////////////////////////////// + private OCSPResponseStatus responseStatus = null; + private ResponseBytes responseBytes = null; + private SEQUENCE sequence; + + public OCSPResponseStatus getResponseStatus() + { + return responseStatus; + } + + public ResponseBytes getResponseBytes() + { + return responseBytes; + } + + /////////////////////////////////////////////////////////////////////// + // Constructors + /////////////////////////////////////////////////////////////////////// + private OCSPResponse() { } + + public OCSPResponse(OCSPResponseStatus responseStatus, + ResponseBytes responseBytes) + { + sequence = new SEQUENCE(); + + this.responseStatus = responseStatus; + sequence.addElement(responseStatus); + + this.responseBytes = responseBytes; + sequence.addElement(new EXPLICIT(Tag.get(0), responseBytes)); + } + + /////////////////////////////////////////////////////////////////////// + // encoding/decoding + /////////////////////////////////////////////////////////////////////// + + private static final Tag TAG = SEQUENCE.TAG; + + public Tag getTag() + { + return TAG; + } + + public void encode(OutputStream ostream) throws IOException + { + encode(TAG, ostream); + } + + public void encode(Tag implicitTag, OutputStream ostream) + throws IOException + { + sequence.encode(implicitTag, ostream); + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } + + /** + * A Template for decoding an <code>OCSPResponse</code>. + */ + public static class Template implements ASN1Template + { + + private SEQUENCE.Template seqt; + + public Template() + { + seqt = new SEQUENCE.Template(); + seqt.addElement( OCSPResponseStatus.getTemplate() ); + seqt.addOptionalElement( + new EXPLICIT.Template( + new Tag (0), new ResponseBytes.Template()) ); + + } + + public boolean tagMatch(Tag tag) + { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException + { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException + { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); + + OCSPResponseStatus rs = (OCSPResponseStatus) seq.elementAt(0); + ResponseBytes rb = null; + ASN1Value val = seq.elementAt(1); + if (val instanceof EXPLICIT) { + EXPLICIT exp = (EXPLICIT)val; + rb = (ResponseBytes)exp.getContent(); + } else { + rb = (ResponseBytes)val; + } + return new OCSPResponse(rs, rb); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponseStatus.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponseStatus.java index c5fc3386..ee2b6202 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponseStatus.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/OCSPResponseStatus.java @@ -29,7 +29,7 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * OCSPResponseStatus ::= ENUMERATED { * successful (0), --Response has valid confirmations @@ -41,85 +41,95 @@ import org.mozilla.jss.asn1.Tag; * unauthorized (6) --Request unauthorized * } * </pre> - * + * * @version $Revision$ $Date$ */ -public class OCSPResponseStatus implements ASN1Value { - // ///////////////////////////////////////////////////////////////////// - // Members and member access - // ///////////////////////////////////////////////////////////////////// - public final static OCSPResponseStatus SUCCESSFUL = new OCSPResponseStatus( - 0); - public final static OCSPResponseStatus MALFORMED_REQUEST = new OCSPResponseStatus( - 1); - public final static OCSPResponseStatus INTERNAL_ERROR = new OCSPResponseStatus( - 2); - public final static OCSPResponseStatus TRY_LATER = new OCSPResponseStatus(3); - public final static OCSPResponseStatus SIG_REQUIRED = new OCSPResponseStatus( - 5); - public final static OCSPResponseStatus UNAUTHORIZED = new OCSPResponseStatus( - 6); - - private ENUMERATED responseStatus; - - public long getValue() { - return responseStatus.getValue(); - } - - // ///////////////////////////////////////////////////////////////////// - // Constructors - // ///////////////////////////////////////////////////////////////////// - private OCSPResponseStatus() { - } - - public OCSPResponseStatus(long val) { - responseStatus = new ENUMERATED(val); - } - - // ///////////////////////////////////////////////////////////////////// - // encoding/decoding - // ///////////////////////////////////////////////////////////////////// - - private static final Tag TAG = ENUMERATED.TAG; - - public Tag getTag() { - return TAG; - } - - public void encode(OutputStream ostream) throws IOException { - encode(TAG, ostream); - } - - public void encode(Tag implicitTag, OutputStream ostream) - throws IOException { - responseStatus.encode(implicitTag, ostream); - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; - } - - /** - * A Template for decoding an <code>OCSPResponseStatus</code>. - */ - public static class Template implements ASN1Template { - public boolean tagMatch(Tag tag) { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { - ENUMERATED.Template enumt = new ENUMERATED.Template(); - ENUMERATED enum1 = (ENUMERATED) enumt.decode(implicitTag, istream); - - return new OCSPResponseStatus(enum1.getValue()); - } - } +public class OCSPResponseStatus implements ASN1Value +{ + /////////////////////////////////////////////////////////////////////// + // Members and member access + /////////////////////////////////////////////////////////////////////// + public final static OCSPResponseStatus SUCCESSFUL = + new OCSPResponseStatus(0); + public final static OCSPResponseStatus MALFORMED_REQUEST = + new OCSPResponseStatus(1); + public final static OCSPResponseStatus INTERNAL_ERROR = + new OCSPResponseStatus(2); + public final static OCSPResponseStatus TRY_LATER = + new OCSPResponseStatus(3); + public final static OCSPResponseStatus SIG_REQUIRED = + new OCSPResponseStatus(5); + public final static OCSPResponseStatus UNAUTHORIZED = + new OCSPResponseStatus(6); + + private ENUMERATED responseStatus; + + public long getValue() + { + return responseStatus.getValue(); + } + + /////////////////////////////////////////////////////////////////////// + // Constructors + /////////////////////////////////////////////////////////////////////// + private OCSPResponseStatus() { } + + public OCSPResponseStatus(long val) + { + responseStatus = new ENUMERATED(val); + } + + /////////////////////////////////////////////////////////////////////// + // encoding/decoding + /////////////////////////////////////////////////////////////////////// + + private static final Tag TAG = ENUMERATED.TAG; + + public Tag getTag() + { + return TAG; + } + + public void encode(OutputStream ostream) throws IOException + { + encode(TAG, ostream); + } + + public void encode(Tag implicitTag, OutputStream ostream) + throws IOException + { + responseStatus.encode(implicitTag, ostream); + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } + + /** + * A Template for decoding an <code>OCSPResponseStatus</code>. + */ + public static class Template implements ASN1Template + { + public boolean tagMatch(Tag tag) + { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException + { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException + { + ENUMERATED.Template enumt = new ENUMERATED.Template(); + ENUMERATED enum1 = (ENUMERATED) enumt.decode(implicitTag, istream); + + return new OCSPResponseStatus(enum1.getValue()); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/Request.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/Request.java index 705c5592..f180709d 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/Request.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/Request.java @@ -31,120 +31,137 @@ import org.mozilla.jss.pkix.cert.Extension; /** * RFC 2560: - * + * * <pre> * Request ::= SEQUENCE { * reqCert CertID, * singleRequestExtensions [0] EXPLICIT Extensions OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class Request implements ASN1Value { - // ///////////////////////////////////////////////////////////////////// - // members and member access - // ///////////////////////////////////////////////////////////////////// - private CertID reqCert = null; - private SEQUENCE singleRequestExtensions = null; - private SEQUENCE sequence = null; - - public CertID getCertID() { - return reqCert; - } - - public int getExtensionsCount() { - if (singleRequestExtensions == null) { - return 0; - } else { - return singleRequestExtensions.size(); - } - } - - public Extension getRequestExtensionAt(int index) { - if (singleRequestExtensions == null) { - throw new ArrayIndexOutOfBoundsException(); - } - return (Extension) singleRequestExtensions.elementAt(index); - } - - // ///////////////////////////////////////////////////////////////////// - // constructors - // ///////////////////////////////////////////////////////////////////// - private Request() { - } - - public Request(CertID reqCert, SEQUENCE singleRequestExtensions) { - sequence = new SEQUENCE(); - - this.reqCert = reqCert; - sequence.addElement(reqCert); - - if (singleRequestExtensions != null) { - this.singleRequestExtensions = singleRequestExtensions; - sequence.addElement(singleRequestExtensions); - } - } - - // ///////////////////////////////////////////////////////////////////// - // encode / decode - // ///////////////////////////////////////////////////////////////////// - private static final Tag TAG = SEQUENCE.TAG; - - public Tag getTag() { - return TAG; - } - - public void encode(OutputStream ostream) throws IOException { - encode(TAG, ostream); - } - - public void encode(Tag implicitTag, OutputStream ostream) - throws IOException { - sequence.encode(implicitTag, ostream); - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; - } - - /** - * A Template for decoding Request. - */ - public static class Template implements ASN1Template { - - private SEQUENCE.Template seqt; - - public Template() { - seqt = new SEQUENCE.Template(); - seqt.addElement(CertID.getTemplate()); - seqt.addOptionalElement(new EXPLICIT.Template(new Tag(0), - new SEQUENCE.OF_Template(new Extension.Template()))); - } - - public boolean tagMatch(Tag tag) { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - - EXPLICIT tag = (EXPLICIT) seq.elementAt(1); - - if (tag == null) { - return new Request((CertID) seq.elementAt(0), (SEQUENCE) null); - } else { - return new Request((CertID) seq.elementAt(0), - (SEQUENCE) tag.getContent()); - } - } - } +public class Request implements ASN1Value +{ + /////////////////////////////////////////////////////////////////////// + // members and member access + /////////////////////////////////////////////////////////////////////// + private CertID reqCert = null; + private SEQUENCE singleRequestExtensions = null; + private SEQUENCE sequence = null; + + public CertID getCertID() + { + return reqCert; + } + + public int getExtensionsCount() + { + if(singleRequestExtensions == null) { + return 0; + } else { + return singleRequestExtensions.size(); + } + } + + public Extension getRequestExtensionAt(int index) + { + if(singleRequestExtensions == null) { + throw new ArrayIndexOutOfBoundsException(); + } + return (Extension) singleRequestExtensions.elementAt(index); + } + + /////////////////////////////////////////////////////////////////////// + // constructors + /////////////////////////////////////////////////////////////////////// + private Request() { } + + public Request(CertID reqCert, SEQUENCE singleRequestExtensions) + { + sequence = new SEQUENCE(); + + this.reqCert = reqCert; + sequence.addElement(reqCert); + + if (singleRequestExtensions != null) { + this.singleRequestExtensions = singleRequestExtensions; + sequence.addElement(singleRequestExtensions); + } + } + + /////////////////////////////////////////////////////////////////////// + // encode / decode + /////////////////////////////////////////////////////////////////////// + private static final Tag TAG = SEQUENCE.TAG; + + public Tag getTag() + { + return TAG; + } + + public void encode(OutputStream ostream) throws IOException + { + encode(TAG, ostream); + } + + public void encode(Tag implicitTag, OutputStream ostream) + throws IOException + { + sequence.encode(implicitTag, ostream); + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() + { + return templateInstance; + } + + /** + * A Template for decoding Request. + */ + public static class Template implements ASN1Template + { + + private SEQUENCE.Template seqt; + + public Template() + { + seqt = new SEQUENCE.Template(); + seqt.addElement( CertID.getTemplate() ); + seqt.addOptionalElement(new EXPLICIT.Template(new Tag(0), + new SEQUENCE.OF_Template(new Extension.Template()) )); + } + + public boolean tagMatch(Tag tag) + { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException + { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException + { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); + + EXPLICIT tag = (EXPLICIT) seq.elementAt(1); + + if (tag == null) { + return new Request( + (CertID) seq.elementAt(0), + (SEQUENCE) null); + } + else { + return new Request( + (CertID) seq.elementAt(0), + (SEQUENCE) tag.getContent()); + } + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponderID.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponderID.java index 02e30de0..d5cfa680 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponderID.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponderID.java @@ -19,16 +19,18 @@ package com.netscape.cmsutil.ocsp; import org.mozilla.jss.asn1.ASN1Value; + /** * RFC 2560: - * + * * <pre> * ResponderID ::= CHOICE { * byName [1] EXPLICIT Name, * byKey [2] EXPLICIT KeyHash } * </pre> - * + * * @version $Revision$ $Date$ */ -public interface ResponderID extends ASN1Value { +public interface ResponderID extends ASN1Value +{ } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/Response.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/Response.java index 0d363e81..eb011e1c 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/Response.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/Response.java @@ -22,13 +22,14 @@ import org.mozilla.jss.asn1.OCTET_STRING; /** * RFC 2560: - * + * * <pre> * response OCTET STRING * </pre> - * + * * @version $Revision$ $Date$ */ -public interface Response extends ASN1Value { - public OCTET_STRING getBytes(); +public interface Response extends ASN1Value +{ + public OCTET_STRING getBytes(); } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseBytes.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseBytes.java index 6ffd2480..80a15b91 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseBytes.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseBytes.java @@ -31,105 +31,117 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * ResponseBytes ::= SEQUENCE { * responseType OBJECT IDENTIFIER, * response OCTET STRING } * </pre> - * + * * @version $Revision$ $Date$ */ -public class ResponseBytes implements ASN1Value { - // ///////////////////////////////////////////////////////////////////// - // Members and member access - // ///////////////////////////////////////////////////////////////////// - public final static OBJECT_IDENTIFIER OCSP = new OBJECT_IDENTIFIER( - "1.3.6.1.5.5.7.48.1"); - public final static OBJECT_IDENTIFIER OCSP_BASIC = new OBJECT_IDENTIFIER( - "1.3.6.1.5.5.7.48.1.1"); - - private OBJECT_IDENTIFIER responseType = null; - private OCTET_STRING response = null; - private SEQUENCE sequence; - - public OBJECT_IDENTIFIER getObjectIdentifier() { - return responseType; - } - - public OCTET_STRING getResponse() { - return response; - } - - // ///////////////////////////////////////////////////////////////////// - // Constructors - // ///////////////////////////////////////////////////////////////////// - private ResponseBytes() { - } - - public ResponseBytes(OBJECT_IDENTIFIER responseType, OCTET_STRING response) { - sequence = new SEQUENCE(); - - this.responseType = responseType; - sequence.addElement(responseType); - - this.response = response; - sequence.addElement(response); - } - - // ///////////////////////////////////////////////////////////////////// - // encoding/decoding - // ///////////////////////////////////////////////////////////////////// - - private static final Tag TAG = SEQUENCE.TAG; - - public Tag getTag() { - return TAG; - } - - public void encode(OutputStream ostream) throws IOException { - encode(TAG, ostream); - } - - public void encode(Tag implicitTag, OutputStream ostream) - throws IOException { - sequence.encode(implicitTag, ostream); - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; - } - - /** - * A Template for decoding <code>ResponseBytes</code>. - */ - public static class Template implements ASN1Template { - - private SEQUENCE.Template seqt; - - public Template() { - seqt = new SEQUENCE.Template(); - seqt.addElement(OBJECT_IDENTIFIER.getTemplate()); - seqt.addElement(OCTET_STRING.getTemplate()); - } - - public boolean tagMatch(Tag tag) { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - - return new ResponseBytes((OBJECT_IDENTIFIER) seq.elementAt(0), - (OCTET_STRING) seq.elementAt(1)); - } - } +public class ResponseBytes implements ASN1Value +{ + /////////////////////////////////////////////////////////////////////// + // Members and member access + /////////////////////////////////////////////////////////////////////// + public final static OBJECT_IDENTIFIER OCSP = + new OBJECT_IDENTIFIER("1.3.6.1.5.5.7.48.1"); + public final static OBJECT_IDENTIFIER OCSP_BASIC = + new OBJECT_IDENTIFIER("1.3.6.1.5.5.7.48.1.1"); + + private OBJECT_IDENTIFIER responseType = null; + private OCTET_STRING response = null; + private SEQUENCE sequence; + + public OBJECT_IDENTIFIER getObjectIdentifier() + { + return responseType; + } + + public OCTET_STRING getResponse() + { + return response; + } + + /////////////////////////////////////////////////////////////////////// + // Constructors + /////////////////////////////////////////////////////////////////////// + private ResponseBytes() { } + + public ResponseBytes(OBJECT_IDENTIFIER responseType, OCTET_STRING response) + { + sequence = new SEQUENCE(); + + this.responseType = responseType; + sequence.addElement(responseType); + + this.response = response; + sequence.addElement(response); + } + + /////////////////////////////////////////////////////////////////////// + // encoding/decoding + /////////////////////////////////////////////////////////////////////// + + private static final Tag TAG = SEQUENCE.TAG; + + public Tag getTag() + { + return TAG; + } + + public void encode(OutputStream ostream) throws IOException + { + encode(TAG, ostream); + } + + public void encode(Tag implicitTag, OutputStream ostream) + throws IOException + { + sequence.encode(implicitTag, ostream); + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } + + /** + * A Template for decoding <code>ResponseBytes</code>. + */ + public static class Template implements ASN1Template + { + + private SEQUENCE.Template seqt; + + public Template() + { + seqt = new SEQUENCE.Template(); + seqt.addElement( OBJECT_IDENTIFIER.getTemplate() ); + seqt.addElement( OCTET_STRING.getTemplate() ); + } + + public boolean tagMatch(Tag tag) + { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException + { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException + { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); + + return new ResponseBytes( + (OBJECT_IDENTIFIER) seq.elementAt(0), + (OCTET_STRING) seq.elementAt(1)); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseData.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseData.java index 745c2445..81c5eee4 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseData.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/ResponseData.java @@ -35,7 +35,7 @@ import org.mozilla.jss.pkix.cert.Extension; /** * RFC 2560: - * + * * <pre> * ResponseData ::= SEQUENCE { * version [0] EXPLICIT Version DEFAULT v1, @@ -44,12 +44,13 @@ import org.mozilla.jss.pkix.cert.Extension; * responses SEQUENCE OF SingleResponse, * responseExtensions [1] EXPLICIT Extensions OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class ResponseData implements ASN1Value { +public class ResponseData implements ASN1Value +{ private static final INTEGER v1 = new INTEGER(0); - private INTEGER mVer; + private INTEGER mVer; private ResponderID mRID = null; private GeneralizedTime mProduced = null; private SingleResponse mSR[] = null; @@ -57,7 +58,7 @@ public class ResponseData implements ASN1Value { private static final Tag TAG = SEQUENCE.TAG; - public ResponseData(INTEGER ver, ResponderID rid, GeneralizedTime produced, + public ResponseData(INTEGER ver, ResponderID rid, GeneralizedTime produced, SingleResponse sr[], Extension exts[]) { mVer = (ver != null) ? ver : v1; mRID = rid; @@ -66,25 +67,30 @@ public class ResponseData implements ASN1Value { mExts = exts; } - public ResponseData(ResponderID rid, GeneralizedTime produced, - SingleResponse sr[]) { + public ResponseData(ResponderID rid, GeneralizedTime produced, + SingleResponse sr[]) + { this(v1, rid, produced, sr, null); } - public ResponseData(ResponderID rid, GeneralizedTime produced, - SingleResponse sr[], Extension exts[]) { + public ResponseData(ResponderID rid, GeneralizedTime produced, + SingleResponse sr[], Extension exts[]) + { this(v1, rid, produced, sr, exts); } - - public Tag getTag() { + + public Tag getTag() + { return TAG; } - public void encode(OutputStream os) throws IOException { + public void encode(OutputStream os) throws IOException + { encode(null, os); } - public void encode(Tag t, OutputStream os) throws IOException { + public void encode(Tag t, OutputStream os) throws IOException + { SEQUENCE seq = new SEQUENCE(); if (mVer != v1) { @@ -110,29 +116,35 @@ public class ResponseData implements ASN1Value { } else { seq.encode(t, os); } - } + } - public ResponderID getResponderID() { + public ResponderID getResponderID() + { return mRID; } - public GeneralizedTime getProducedAt() { + public GeneralizedTime getProducedAt() + { return mProduced; } - public int getResponseCount() { + public int getResponseCount() + { return (mSR != null) ? mSR.length : 0; } - public SingleResponse getResponseAt(int pos) { + public SingleResponse getResponseAt(int pos) + { return (mSR != null) ? mSR[pos] : null; } - public int getResponseExtensionCount() { - return (mExts != null) ? mExts.length : 0; + public int getResponseExtensionCount() + { + return (mExts != null) ? mExts.length : 0; } - public Extension getResponseExtensionAt(int pos) { + public Extension getResponseExtensionAt(int pos) + { return (mExts != null) ? mExts[pos] : null; } @@ -145,75 +157,83 @@ public class ResponseData implements ASN1Value { /** * A Template for decoding <code>ResponseBytes</code>. */ - public static class Template implements ASN1Template { + public static class Template implements ASN1Template + { private SEQUENCE.Template seqt; - public Template() { - seqt = new SEQUENCE.Template(); - seqt.addOptionalElement(new EXPLICIT.Template(new Tag(0), - new INTEGER.Template())); - seqt.addElement(new ANY.Template()); - seqt.addElement(new GeneralizedTime.Template()); - seqt.addElement(new SEQUENCE.OF_Template(SingleResponse - .getTemplate())); - seqt.addOptionalElement(new EXPLICIT.Template(new Tag(1), - new SEQUENCE.OF_Template(Extension.getTemplate()))); + public Template() + { + seqt = new SEQUENCE.Template(); + seqt.addOptionalElement(new EXPLICIT.Template( + new Tag (0), new INTEGER.Template()) ); + seqt.addElement(new ANY.Template() ); + seqt.addElement(new GeneralizedTime.Template() ); + seqt.addElement(new SEQUENCE.OF_Template( + SingleResponse.getTemplate())); + seqt.addOptionalElement(new EXPLICIT.Template( + new Tag(1), new SEQUENCE.OF_Template( + Extension.getTemplate()))); } - public boolean tagMatch(Tag tag) { + public boolean tagMatch(Tag tag) + { return TAG.equals(tag); } public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { + throws InvalidBERException, IOException + { return decode(TAG, istream); } public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); + throws InvalidBERException, IOException + { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, + istream); INTEGER ver = v1; - EXPLICIT e_ver = (EXPLICIT) seq.elementAt(0); + EXPLICIT e_ver = (EXPLICIT)seq.elementAt(0); if (e_ver != null && e_ver.getTag().getNum() == 0) { - ver = (INTEGER) e_ver.getContent(); + ver = (INTEGER)e_ver.getContent(); } ResponderID rid = null; - ANY e_rid = (ANY) seq.elementAt(1); + ANY e_rid = (ANY)seq.elementAt(1); if (e_rid.getTag().getNum() == 1) { // name id - rid = (NameID) NameID.getTemplate().decode(e_rid.getTag(), - new ByteArrayInputStream(e_rid.getEncoded())); + rid = (NameID) + NameID.getTemplate().decode(e_rid.getTag(), + new ByteArrayInputStream(e_rid.getEncoded())); } else if (e_rid.getTag().getNum() == 2) { // key hash id - rid = (KeyHashID) KeyHashID.getTemplate().decode( - e_rid.getTag(), - new ByteArrayInputStream(e_rid.getEncoded())); + rid = (KeyHashID) + KeyHashID.getTemplate().decode(e_rid.getTag(), + new ByteArrayInputStream(e_rid.getEncoded())); } - GeneralizedTime producedAt = (GeneralizedTime) seq.elementAt(2); - SEQUENCE responses = (SEQUENCE) seq.elementAt(3); + GeneralizedTime producedAt = (GeneralizedTime) seq.elementAt(2); + SEQUENCE responses = (SEQUENCE)seq.elementAt(3); SingleResponse sr[] = null; - if ((responses != null) && (responses.size() > 0)) { + if ((responses != null) && (responses.size() > 0)) { sr = new SingleResponse[responses.size()]; for (int i = 0; i < responses.size(); i++) { - sr[i] = (SingleResponse) responses.elementAt(i); + sr[i] = (SingleResponse)responses.elementAt(i); } } - // decode response extension sequence + //decode response extension sequence EXPLICIT extns_exp = (EXPLICIT) seq.elementAt(4); SEQUENCE extns_seq; Extension[] extns_array = null; if (extns_exp != null) { - extns_seq = (SEQUENCE) extns_exp.getContent(); + extns_seq = (SEQUENCE)extns_exp.getContent(); extns_array = new Extension[extns_seq.size()]; - for (int x = 0; x < extns_array.length; x++) { + for (int x=0;x<extns_array.length;x++) { extns_array[x] = (Extension) extns_seq.elementAt(x); } } return new ResponseData(ver, rid, producedAt, sr, extns_array); - } - } + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/RevokedInfo.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/RevokedInfo.java index ed4cfb44..b1b7489f 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/RevokedInfo.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/RevokedInfo.java @@ -32,79 +32,94 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * RevokedInfo ::= SEQUENCE { * revocationTime GeneralizedTime, * revocationReason [0] EXPLICIT CRLReason OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class RevokedInfo implements CertStatus { - private static final Tag TAG = SEQUENCE.TAG; +public class RevokedInfo implements CertStatus +{ + private static final Tag TAG = SEQUENCE.TAG; - private GeneralizedTime mRevokedAt; + private GeneralizedTime mRevokedAt; - public RevokedInfo(GeneralizedTime revokedAt) { - mRevokedAt = revokedAt; - } - - public Tag getTag() { - return Tag.get(1); - } - - public void encode(Tag t, OutputStream os) throws IOException { - SEQUENCE seq = new SEQUENCE(); - seq.addElement(mRevokedAt); - seq.encode(t, os); - } - - public void encode(OutputStream os) throws IOException { - encode(getTag(), os); - } - - public GeneralizedTime getRevocationTime() { - return mRevokedAt; - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; - } - - /** - * A Template for decoding <code>ResponseBytes</code>. - */ - public static class Template implements ASN1Template { - - private SEQUENCE.Template seqt; - - public Template() { - seqt = new SEQUENCE.Template(); - seqt.addElement(new GeneralizedTime.Template()); - seqt.addOptionalElement(new EXPLICIT.Template(new Tag(0), - new INTEGER.Template())); + public RevokedInfo(GeneralizedTime revokedAt) + { + mRevokedAt = revokedAt; + } + public Tag getTag() + { + return Tag.get(1); } - public boolean tagMatch(Tag tag) { - return TAG.equals(tag); + public void encode(Tag t, OutputStream os) throws IOException + { + SEQUENCE seq = new SEQUENCE(); + seq.addElement(mRevokedAt); + seq.encode(t, os); } - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { - return decode(TAG, istream); + public void encode(OutputStream os) throws IOException + { + encode(getTag(), os); } + + public GeneralizedTime getRevocationTime() + { + return mRevokedAt; + } - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - GeneralizedTime revokedAt = (GeneralizedTime) seq.elementAt(0); - return new RevokedInfo(revokedAt); + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; + } + /** + * A Template for decoding <code>ResponseBytes</code>. + */ + public static class Template implements ASN1Template + { + + private SEQUENCE.Template seqt; + + public Template() + { + seqt = new SEQUENCE.Template(); + seqt.addElement(new GeneralizedTime.Template() ); + seqt.addOptionalElement( + new EXPLICIT.Template( new Tag(0), + new INTEGER.Template()) ); + + } + + public boolean tagMatch(Tag tag) + { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException + { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException + { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, + istream); + + GeneralizedTime revokedAt = (GeneralizedTime) + seq.elementAt(0); + return new RevokedInfo(revokedAt); + + } } - } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/Signature.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/Signature.java index 64194e1c..2810182e 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/Signature.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/Signature.java @@ -33,127 +33,147 @@ import org.mozilla.jss.pkix.primitive.AlgorithmIdentifier; /** * RFC 2560: - * + * * <pre> * Signature ::= SEQUENCE { * signatureAlgorithm AlgorithmIdentifier, * signature BIT STRING, * certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class Signature implements ASN1Value { - // ///////////////////////////////////////////////////////////////////// - // Members and member access - // ///////////////////////////////////////////////////////////////////// - private AlgorithmIdentifier signatureAlgorithm; - private BIT_STRING signature; - private SEQUENCE certs; - private SEQUENCE sequence; - - public AlgorithmIdentifier getSignatureAlgorithm() { - return signatureAlgorithm; - } - - public BIT_STRING getSignature() { - return signature; - } - - public int getCertificateCount() { - if (certs == null) { - return 0; - } else { - return certs.size(); - } - } - - public Certificate getCertificateAt(int index) { - if (certs == null) { - throw new ArrayIndexOutOfBoundsException(); - } - return (Certificate) certs.elementAt(index); - } - - // ///////////////////////////////////////////////////////////////////// - // constructors - // ///////////////////////////////////////////////////////////////////// - private Signature() { - } - - public Signature(AlgorithmIdentifier signatureAlgorithm, - BIT_STRING signature, SEQUENCE certs) { - sequence = new SEQUENCE(); - - this.signatureAlgorithm = signatureAlgorithm; - sequence.addElement(signatureAlgorithm); - - this.signature = signature; - sequence.addElement(signature); - - this.certs = certs; - sequence.addElement(certs); - } - - // ///////////////////////////////////////////////////////////////////// - // encode / decode - // ///////////////////////////////////////////////////////////////////// - private static final Tag TAG = SEQUENCE.TAG; - - public Tag getTag() { - return TAG; - } - - public void encode(OutputStream ostream) throws IOException { - encode(TAG, ostream); - } - - public void encode(Tag implicitTag, OutputStream ostream) - throws IOException { - sequence.encode(implicitTag, ostream); - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; - } - - /** - * A Template for decoding Request. - */ - public static class Template implements ASN1Template { - - private SEQUENCE.Template seqt; - - public Template() { - seqt = new SEQUENCE.Template(); - seqt.addElement(AlgorithmIdentifier.getTemplate()); - seqt.addElement(BIT_STRING.getTemplate()); - seqt.addOptionalElement(new EXPLICIT.Template(new Tag(0), - new SEQUENCE.OF_Template(new Certificate.Template()))); - } - - public boolean tagMatch(Tag tag) { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - SEQUENCE certs = null; - if (seq.elementAt(2) != null) { - certs = (SEQUENCE) ((EXPLICIT) seq.elementAt(2)).getContent(); - } - - return new Signature((AlgorithmIdentifier) seq.elementAt(0), - (BIT_STRING) seq.elementAt(1), certs); - } - } +public class Signature implements ASN1Value +{ + /////////////////////////////////////////////////////////////////////// + // Members and member access + /////////////////////////////////////////////////////////////////////// + private AlgorithmIdentifier signatureAlgorithm; + private BIT_STRING signature; + private SEQUENCE certs; + private SEQUENCE sequence; + + public AlgorithmIdentifier getSignatureAlgorithm() + { + return signatureAlgorithm; + } + + public BIT_STRING getSignature() + { + return signature; + } + + public int getCertificateCount() + { + if(certs == null) { + return 0; + } else { + return certs.size(); + } + } + + public Certificate getCertificateAt(int index) + { + if(certs == null) { + throw new ArrayIndexOutOfBoundsException(); + } + return (Certificate) certs.elementAt(index); + } + + /////////////////////////////////////////////////////////////////////// + // constructors + /////////////////////////////////////////////////////////////////////// + private Signature() { } + + public Signature(AlgorithmIdentifier signatureAlgorithm, + BIT_STRING signature, SEQUENCE certs) + { + sequence = new SEQUENCE(); + + this.signatureAlgorithm = signatureAlgorithm; + sequence.addElement(signatureAlgorithm); + + this.signature = signature; + sequence.addElement(signature); + + this.certs = certs; + sequence.addElement(certs); + } + + /////////////////////////////////////////////////////////////////////// + // encode / decode + /////////////////////////////////////////////////////////////////////// + private static final Tag TAG = SEQUENCE.TAG; + + public Tag getTag() + { + return TAG; + } + + public void encode(OutputStream ostream) throws IOException + { + encode(TAG, ostream); + } + + public void encode(Tag implicitTag, OutputStream ostream) + throws IOException + { + sequence.encode(implicitTag, ostream); + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() + { + return templateInstance; + } + + /** + * A Template for decoding Request. + */ + public static class Template implements ASN1Template + { + + private SEQUENCE.Template seqt; + + public Template() + { + seqt = new SEQUENCE.Template(); + seqt.addElement( AlgorithmIdentifier.getTemplate() ); + seqt.addElement( BIT_STRING.getTemplate() ); + seqt.addOptionalElement( + new EXPLICIT.Template( + new Tag(0), + new SEQUENCE.OF_Template( new Certificate.Template()) + ) + ); + } + + public boolean tagMatch(Tag tag) + { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException + { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException + { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); + SEQUENCE certs=null; + if( seq.elementAt(2) != null ) { + certs = (SEQUENCE) ((EXPLICIT)seq.elementAt(2)).getContent(); + } + + return new Signature( + (AlgorithmIdentifier) seq.elementAt(0), + (BIT_STRING) seq.elementAt(1), + certs); + } + } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/SingleResponse.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/SingleResponse.java index 439a9f41..1ce72747 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/SingleResponse.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/SingleResponse.java @@ -34,7 +34,7 @@ import org.mozilla.jss.pkix.cert.Extension; /** * RFC 2560: - * + * * <pre> * SingleResponse ::= SEQUENCE { * certID CertID, @@ -43,134 +43,157 @@ import org.mozilla.jss.pkix.cert.Extension; * nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL, * singleExtensions [1] EXPLICIT Extensions OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class SingleResponse implements ASN1Value { - private CertID mCID = null; - private CertStatus mStatus = null; - private GeneralizedTime mThisUpdate = null; - private GeneralizedTime mNextUpdate = null; - - private static final Tag TAG = SEQUENCE.TAG; - - public SingleResponse(CertID cid, CertStatus s, GeneralizedTime thisUpdate, - GeneralizedTime nextUpdate) { - mCID = cid; - mStatus = s; - mThisUpdate = thisUpdate; - mNextUpdate = nextUpdate; - } - - public CertID getCertID() { - return mCID; - } - - public Tag getTag() { - return null; - } - - public void encode(Tag t, OutputStream os) throws IOException { - SEQUENCE seq = new SEQUENCE(); - seq.addElement(mCID); - seq.addElement(mStatus); - seq.addElement(mThisUpdate); - if (mNextUpdate != null) { - seq.addElement(new EXPLICIT(Tag.get(0), mNextUpdate)); +public class SingleResponse implements ASN1Value +{ + private CertID mCID = null; + private CertStatus mStatus = null; + private GeneralizedTime mThisUpdate = null; + private GeneralizedTime mNextUpdate = null; + + private static final Tag TAG = SEQUENCE.TAG; + + public SingleResponse(CertID cid, CertStatus s, + GeneralizedTime thisUpdate, GeneralizedTime nextUpdate) + { + mCID = cid; + mStatus = s; + mThisUpdate = thisUpdate; + mNextUpdate = nextUpdate; + } + + public CertID getCertID() + { + return mCID; + } + + public Tag getTag() + { + return null; + } + + public void encode(Tag t, OutputStream os) throws IOException + { + SEQUENCE seq = new SEQUENCE(); + seq.addElement(mCID); + seq.addElement(mStatus); + seq.addElement(mThisUpdate); + if (mNextUpdate != null) + { + seq.addElement(new EXPLICIT(Tag.get(0), mNextUpdate)); + } + if (t == null) { + seq.encode(os); + } else { + seq.encode(t, os); + } + } + + public void encode(OutputStream os) throws IOException + { + encode(null, os); + } + + public CertStatus getCertStatus() + { + return mStatus; + } + + public GeneralizedTime getThisUpdate() + { + return mThisUpdate; + } + + public GeneralizedTime getNextUpdate() + { + return mNextUpdate; + } + + public int getExtensionCount() + { + return 0; + } + + public Extension getExtensionAt(int pos) + { + return null; + } + + private static final Template templateInstance = new Template(); + + public static Template getTemplate() { + return templateInstance; } - if (t == null) { - seq.encode(os); - } else { - seq.encode(t, os); - } - } - - public void encode(OutputStream os) throws IOException { - encode(null, os); - } - - public CertStatus getCertStatus() { - return mStatus; - } - - public GeneralizedTime getThisUpdate() { - return mThisUpdate; - } - - public GeneralizedTime getNextUpdate() { - return mNextUpdate; - } - - public int getExtensionCount() { - return 0; - } - - public Extension getExtensionAt(int pos) { - return null; - } - - private static final Template templateInstance = new Template(); - - public static Template getTemplate() { - return templateInstance; - } - - /** - * A Template for decoding <code>ResponseBytes</code>. - */ - public static class Template implements ASN1Template { - - private SEQUENCE.Template seqt; - - public Template() { - seqt = new SEQUENCE.Template(); - seqt.addElement(new CertID.Template()); - seqt.addElement(new ANY.Template()); - seqt.addElement(new GeneralizedTime.Template()); - seqt.addOptionalElement(new EXPLICIT.Template(new Tag(0), - new GeneralizedTime.Template())); - seqt.addOptionalElement(new EXPLICIT.Template(new Tag(1), - new SEQUENCE.OF_Template(new Extension.Template()))); - - } - - public boolean tagMatch(Tag tag) { - return TAG.equals(tag); - } - - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { - return decode(TAG, istream); - } - - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { - SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - - CertID cid = (CertID) seq.elementAt(0); - CertStatus status = null; - ANY e_status = (ANY) seq.elementAt(1); - if (e_status.getTag().getNum() == 0) { - status = (GoodInfo) GoodInfo.getTemplate().decode( - e_status.getTag(), - new ByteArrayInputStream(e_status.getEncoded())); - // good - } else if (e_status.getTag().getNum() == 1) { - // revoked - status = (RevokedInfo) RevokedInfo.getTemplate().decode( - e_status.getTag(), - new ByteArrayInputStream(e_status.getEncoded())); - } else if (e_status.getTag().getNum() == 2) { - // unknown - status = (UnknownInfo) UnknownInfo.getTemplate().decode( - e_status.getTag(), - new ByteArrayInputStream(e_status.getEncoded())); - } - GeneralizedTime thisUpdate = (GeneralizedTime) seq.elementAt(2); - GeneralizedTime nextUpdate = null; - - return new SingleResponse(cid, status, thisUpdate, nextUpdate); + /** + * A Template for decoding <code>ResponseBytes</code>. + */ + public static class Template implements ASN1Template + { + + private SEQUENCE.Template seqt; + + public Template() + { + seqt = new SEQUENCE.Template(); + seqt.addElement(new CertID.Template() ); + seqt.addElement(new ANY.Template() ); + seqt.addElement(new GeneralizedTime.Template() ); + seqt.addOptionalElement(new EXPLICIT.Template( + new Tag(0), new GeneralizedTime.Template())); + seqt.addOptionalElement(new EXPLICIT.Template(new Tag(1), + new SEQUENCE.OF_Template(new Extension.Template()))); + + } + + public boolean tagMatch(Tag tag) + { + return TAG.equals(tag); + } + + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException + { + return decode(TAG, istream); + } + + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException + { + SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, + istream); + + CertID cid = (CertID)seq.elementAt(0); + CertStatus status = null; + ANY e_status = (ANY)seq.elementAt(1); + if (e_status.getTag().getNum() == 0) { + status = (GoodInfo) + GoodInfo.getTemplate().decode( + e_status.getTag(), + new ByteArrayInputStream(e_status.getEncoded())); + // good + } else if (e_status.getTag().getNum() == 1) { + // revoked + status = (RevokedInfo) + RevokedInfo.getTemplate().decode( + e_status.getTag(), + new ByteArrayInputStream(e_status.getEncoded())); + } else if (e_status.getTag().getNum() == 2) { + // unknown + status = (UnknownInfo) + UnknownInfo.getTemplate().decode( + e_status.getTag(), + new ByteArrayInputStream(e_status.getEncoded())); + } + GeneralizedTime thisUpdate = (GeneralizedTime) + seq.elementAt(2); + GeneralizedTime nextUpdate = null; + + return new SingleResponse(cid, status, thisUpdate, + nextUpdate); + + } } - } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/TBSRequest.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/TBSRequest.java index ffb48e0e..4e09c591 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/TBSRequest.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/TBSRequest.java @@ -33,7 +33,7 @@ import org.mozilla.jss.pkix.cert.Extension; /** * RFC 2560: - * + * * <pre> * TBSRequest ::= SEQUENCE { * version [0] EXPLICIT Version DEFAULT v1, @@ -41,29 +41,33 @@ import org.mozilla.jss.pkix.cert.Extension; * requestList SEQUENCE OF Request, * requestExtensions [2] EXPLICIT Extensions OPTIONAL } * </pre> - * + * * @version $Revision$ $Date$ */ -public class TBSRequest implements ASN1Value { - // ///////////////////////////////////////////////////////////////////// +public class TBSRequest implements ASN1Value +{ + /////////////////////////////////////////////////////////////////////// // members and member access - // ///////////////////////////////////////////////////////////////////// - private static final INTEGER v1 = new INTEGER(0); + /////////////////////////////////////////////////////////////////////// + private static final INTEGER v1 = new INTEGER (0); private INTEGER version; private ANY requestorName; private SEQUENCE requestList; private SEQUENCE requestExtensions; - public INTEGER getVersion() { + public INTEGER getVersion() + { return version; } - public ANY getRequestorName() { + public ANY getRequestorName() + { return requestorName; - } + } - public int getRequestCount() { + public int getRequestCount() + { if (requestList == null) { return 0; } else { @@ -71,11 +75,13 @@ public class TBSRequest implements ASN1Value { } } - public Request getRequestAt(int index) { + public Request getRequestAt(int index) + { return (Request) requestList.elementAt(index); } - public int getExtensionsCount() { + public int getExtensionsCount() + { if (requestExtensions == null) { return 0; } else { @@ -83,40 +89,45 @@ public class TBSRequest implements ASN1Value { } } - public Extension getRequestExtensionAt(int index) { + public Extension getRequestExtensionAt(int index) + { return (Extension) requestExtensions.elementAt(index); } - // ///////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////// // constructors - // ///////////////////////////////////////////////////////////////////// - - private TBSRequest() { - } + /////////////////////////////////////////////////////////////////////// + + private TBSRequest() {} - public TBSRequest(INTEGER version, ANY requestorName, SEQUENCE requestList, - SEQUENCE requestExtensions) { + public TBSRequest(INTEGER version, ANY requestorName, + SEQUENCE requestList, SEQUENCE requestExtensions) + { this.version = (version != null) ? version : v1; this.requestorName = requestorName; this.requestList = requestList; this.requestExtensions = requestExtensions; } - // ///////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////// // encode / decode - // ///////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////// public static final Tag TAG = SEQUENCE.TAG; - public Tag getTag() { + public Tag getTag() + { return TAG; } - public void encode(OutputStream ostream) throws IOException { + public void encode(OutputStream ostream) + throws IOException + { encode(TAG, ostream); } public void encode(Tag implicitTag, OutputStream ostream) - throws IOException { + throws IOException + { SEQUENCE seq = new SEQUENCE(); if (version != v1) { @@ -141,43 +152,52 @@ public class TBSRequest implements ASN1Value { private static final Template templateInstance = new Template(); - public static Template getTemplate() { + public static Template getTemplate() + { return templateInstance; } /** * A Template for decoding TBSRequest. */ - public static class Template implements ASN1Template { + public static class Template implements ASN1Template + { private SEQUENCE.Template seqt; - public Template() { + public Template() + { seqt = new SEQUENCE.Template(); - seqt.addElement(new EXPLICIT.Template(new Tag(0), - new INTEGER.Template()), new EXPLICIT(new Tag(0), - new INTEGER(0))); - seqt.addOptionalElement(new EXPLICIT.Template(new Tag(1), - new ANY.Template())); - seqt.addElement(new SEQUENCE.OF_Template(new Request.Template())); + seqt.addElement( + new EXPLICIT.Template( + new Tag(0), new INTEGER.Template()), + new EXPLICIT( new Tag(0), new INTEGER(0)) + ); + seqt.addOptionalElement( + new EXPLICIT.Template( + new Tag (1), new ANY.Template()) ); + seqt.addElement( new SEQUENCE.OF_Template(new Request.Template()) ); seqt.addOptionalElement(new EXPLICIT.Template(new Tag(2), - new SEQUENCE.OF_Template(new Extension.Template()))); + new SEQUENCE.OF_Template(new Extension.Template())) ); } - public boolean tagMatch(Tag tag) { + public boolean tagMatch(Tag tag) + { return TAG.equals(tag); } public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { + throws InvalidBERException, IOException + { return decode(TAG, istream); } public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { + throws InvalidBERException, IOException + { SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, istream); - INTEGER v = v1; // assume default version + INTEGER v = v1; //assume default version EXPLICIT e_ver = (EXPLICIT) seq.elementAt(0); if (e_ver != null) { v = (INTEGER) e_ver.getContent(); @@ -189,18 +209,21 @@ public class TBSRequest implements ASN1Value { requestorname = (ANY) e_requestorName.getContent(); } - // request sequence (element 2) done below + //request sequence (element 2) done below EXPLICIT exts = (EXPLICIT) seq.elementAt(3); SEQUENCE exts_seq; if (exts != null) { - exts_seq = (SEQUENCE) exts.getContent(); + exts_seq = (SEQUENCE)exts.getContent(); } else { exts_seq = null; } - return new TBSRequest(v, requestorname, - (SEQUENCE) seq.elementAt(2), exts_seq); + return new TBSRequest( + v, + requestorname, + (SEQUENCE) seq.elementAt(2), + exts_seq); } } } diff --git a/pki/base/util/src/com/netscape/cmsutil/ocsp/UnknownInfo.java b/pki/base/util/src/com/netscape/cmsutil/ocsp/UnknownInfo.java index c92ece59..d9891f5a 100644 --- a/pki/base/util/src/com/netscape/cmsutil/ocsp/UnknownInfo.java +++ b/pki/base/util/src/com/netscape/cmsutil/ocsp/UnknownInfo.java @@ -30,66 +30,76 @@ import org.mozilla.jss.asn1.Tag; /** * RFC 2560: - * + * * <pre> * UnknownInfo ::= NULL -- this can be replaced with an enumeration * </pre> - * + * * @version $Revision$ $Date$ */ -public class UnknownInfo implements CertStatus { - private static final Tag TAG = SEQUENCE.TAG; +public class UnknownInfo implements CertStatus +{ + private static final Tag TAG = SEQUENCE.TAG; - public UnknownInfo() { - } + public UnknownInfo() + { + } - public Tag getTag() { - return Tag.get(2); - } + public Tag getTag() + { + return Tag.get(2); + } - public void encode(Tag t, OutputStream os) throws IOException { - NULL.getInstance().encode(getTag(), os); - } + public void encode(Tag t, OutputStream os) throws IOException + { + NULL.getInstance().encode(getTag(), os); + } - public void encode(OutputStream os) throws IOException { - encode(getTag(), os); - } + public void encode(OutputStream os) throws IOException + { + encode(getTag(), os); + } - private static final Template templateInstance = new Template(); + private static final Template templateInstance = new Template(); - public static Template getTemplate() { - return templateInstance; - } + public static Template getTemplate() { + return templateInstance; + } - /** - * A Template for decoding <code>ResponseBytes</code>. - */ - public static class Template implements ASN1Template { + /** + * A Template for decoding <code>ResponseBytes</code>. + */ + public static class Template implements ASN1Template + { - private SEQUENCE.Template seqt; + private SEQUENCE.Template seqt; - public Template() { - // seqt = new SEQUENCE.Template(); - // seqt.addElement(new NULL.Template() ); + public Template() + { +// seqt = new SEQUENCE.Template(); + // seqt.addElement(new NULL.Template() ); - } + } - public boolean tagMatch(Tag tag) { - return TAG.equals(tag); - } + public boolean tagMatch(Tag tag) + { + return TAG.equals(tag); + } - public ASN1Value decode(InputStream istream) - throws InvalidBERException, IOException { - return decode(TAG, istream); - } + public ASN1Value decode(InputStream istream) + throws InvalidBERException, IOException + { + return decode(TAG, istream); + } - public ASN1Value decode(Tag implicitTag, InputStream istream) - throws InvalidBERException, IOException { - // SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, - // istream); + public ASN1Value decode(Tag implicitTag, InputStream istream) + throws InvalidBERException, IOException + { + // SEQUENCE seq = (SEQUENCE) seqt.decode(implicitTag, + // istream); - return new UnknownInfo(); + return new UnknownInfo(); + } } - } } |