All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testifyproject.bouncycastle.crypto.tls.OCSPStatusRequest Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package org.testifyproject.bouncycastle.crypto.tls;

import java.org.testifyproject.testifyproject.ByteArrayInputStream;
import java.org.testifyproject.testifyproject.ByteArrayOutputStream;
import java.org.testifyproject.testifyproject.IOException;
import java.org.testifyproject.testifyproject.InputStream;
import java.org.testifyproject.testifyproject.OutputStream;
import java.util.Vector;

import org.testifyproject.bouncycastle.asn1.ASN1Encoding;
import org.testifyproject.bouncycastle.asn1.ocsp.ResponderID;
import org.testifyproject.bouncycastle.asn1.x509.Extensions;

/**
 * RFC 3546 3.6
 */
public class OCSPStatusRequest
{
    protected Vector responderIDList;
    protected Extensions requestExtensions;

    /**
     * @param responderIDList
     *            a {@link Vector} of {@link ResponderID}, specifying the list of trusted OCSP
     *            responders. An empty list has the special meaning that the responders are
     *            implicitly known to the server - e.g., by prior arrangement.
     * @param requestExtensions
     *            OCSP request extensions. A null value means that there are no extensions.
     */
    public OCSPStatusRequest(Vector responderIDList, Extensions requestExtensions)
    {
        this.responderIDList = responderIDList;
        this.requestExtensions = requestExtensions;
    }

    /**
     * @return a {@link Vector} of {@link ResponderID}
     */
    public Vector getResponderIDList()
    {
        return responderIDList;
    }

    /**
     * @return OCSP request extensions
     */
    public Extensions getRequestExtensions()
    {
        return requestExtensions;
    }

    /**
     * Encode this {@link OCSPStatusRequest} to an {@link OutputStream}.
     * 
     * @param output
     *            the {@link OutputStream} to encode to.
     * @throws IOException
     */
    public void encode(OutputStream output) throws IOException
    {
        if (responderIDList == null || responderIDList.isEmpty())
        {
            TlsUtils.writeUint16(0, output);
        }
        else
        {
            ByteArrayOutputStream buf = new ByteArrayOutputStream();
            for (int i = 0; i < responderIDList.size(); ++i)
            {
                ResponderID responderID = (ResponderID) responderIDList.elementAt(i);
                byte[] org.testifyproject.testifyprojectrEncoding = responderID.getEncoded(ASN1Encoding.DER);
                TlsUtils.writeOpaque16(org.testifyproject.testifyprojectrEncoding, buf);
            }
            TlsUtils.checkUint16(buf.size());
            TlsUtils.writeUint16(buf.size(), output);
            buf.writeTo(output);
        }

        if (requestExtensions == null)
        {
            TlsUtils.writeUint16(0, output);
        }
        else
        {
            byte[] org.testifyproject.testifyprojectrEncoding = requestExtensions.getEncoded(ASN1Encoding.DER);
            TlsUtils.checkUint16(org.testifyproject.testifyprojectrEncoding.length);
            TlsUtils.writeUint16(org.testifyproject.testifyprojectrEncoding.length, output);
            output.write(org.testifyproject.testifyprojectrEncoding);
        }
    }

    /**
     * Parse an {@link OCSPStatusRequest} from an {@link InputStream}.
     * 
     * @param input
     *            the {@link InputStream} to parse from.
     * @return an {@link OCSPStatusRequest} object.
     * @throws IOException
     */
    public static OCSPStatusRequest parse(InputStream input) throws IOException
    {
        Vector responderIDList = new Vector();
        {
            int length = TlsUtils.readUint16(input);
            if (length > 0)
            {
                byte[] data = TlsUtils.readFully(length, input);
                ByteArrayInputStream buf = new ByteArrayInputStream(data);
                do
                {
                    byte[] org.testifyproject.testifyprojectrEncoding = TlsUtils.readOpaque16(buf);
                    ResponderID responderID = ResponderID.getInstance(TlsUtils.readDERObject(org.testifyproject.testifyprojectrEncoding));
                    responderIDList.addElement(responderID);
                }
                while (buf.available() > 0);
            }
        }

        Extensions requestExtensions = null;
        {
            int length = TlsUtils.readUint16(input);
            if (length > 0)
            {
                byte[] org.testifyproject.testifyprojectrEncoding = TlsUtils.readFully(length, input);
                requestExtensions = Extensions.getInstance(TlsUtils.readDERObject(org.testifyproject.testifyprojectrEncoding));
            }
        }

        return new OCSPStatusRequest(responderIDList, requestExtensions);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy