Welcome to mirror list, hosted at ThFree Co, Russian Federation.

OCSPStatusRequest.java « tls « crypto « bouncycastle « org « j2me « main « src « core - gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 57219998a3e3f9e048ec939a18a7a4ce492d4302 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package org.bouncycastle.crypto.tls;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Vector;

import org.bouncycastle.asn1.ASN1Encoding;
import org.bouncycastle.asn1.ocsp.ResponderID;
import org.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[] derEncoding = responderID.getEncoded(ASN1Encoding.DER);
                TlsUtils.writeOpaque16(derEncoding, buf);
            }
            TlsUtils.checkUint16(buf.size());
            TlsUtils.writeUint16(buf.size(), output);
            output.write(buf.toByteArray());
        }

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

    /**
     * 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[] derEncoding = TlsUtils.readOpaque16(buf);
                    ResponderID responderID = ResponderID.getInstance(TlsUtils.readDERObject(derEncoding));
                    responderIDList.addElement(responderID);
                }
                while (buf.available() > 0);
            }
        }

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

        return new OCSPStatusRequest(responderIDList, requestExtensions);
    }
}