DEFINE_STACK_OF(ASN1_UTF8STRING) moved from ts_lcl.h to asn1.h
[openssl.git] / crypto / ts / ts_lcl.h
1 /* ====================================================================
2  * Copyright (c) 2015 The OpenSSL Project.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in
13  *    the documentation and/or other materials provided with the
14  *    distribution.
15  *
16  * 3. All advertising materials mentioning features or use of this
17  *    software must display the following acknowledgment:
18  *    "This product includes software developed by the OpenSSL Project
19  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
20  *
21  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22  *    endorse or promote products derived from this software without
23  *    prior written permission. For written permission, please contact
24  *    licensing@OpenSSL.org.
25  *
26  * 5. Products derived from this software may not be called "OpenSSL"
27  *    nor may "OpenSSL" appear in their names without prior written
28  *    permission of the OpenSSL Project.
29  *
30  * 6. Redistributions of any form whatsoever must retain the following
31  *    acknowledgment:
32  *    "This product includes software developed by the OpenSSL Project
33  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
34  *
35  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46  * OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This product includes cryptographic software written by Eric Young
50  * (eay@cryptsoft.com).  This product includes software written by Tim
51  * Hudson (tjh@cryptsoft.com).
52  *
53  */
54
55
56 /*-
57  * MessageImprint ::= SEQUENCE  {
58  *      hashAlgorithm                AlgorithmIdentifier,
59  *      hashedMessage                OCTET STRING  }
60  */
61 struct TS_msg_imprint_st {
62     X509_ALGOR *hash_algo;
63     ASN1_OCTET_STRING *hashed_msg;
64 };
65
66 /*-
67  * TimeStampResp ::= SEQUENCE  {
68  *     status                  PKIStatusInfo,
69  *     timeStampToken          TimeStampToken     OPTIONAL }
70  */
71 struct TS_resp_st {
72     TS_STATUS_INFO *status_info;
73     PKCS7 *token;
74     TS_TST_INFO *tst_info;
75 };
76
77 /*-
78  * TimeStampReq ::= SEQUENCE  {
79  *    version                  INTEGER  { v1(1) },
80  *    messageImprint           MessageImprint,
81  *      --a hash algorithm OID and the hash value of the data to be
82  *      --time-stamped
83  *    reqPolicy                TSAPolicyId                OPTIONAL,
84  *    nonce                    INTEGER                    OPTIONAL,
85  *    certReq                  BOOLEAN                    DEFAULT FALSE,
86  *    extensions               [0] IMPLICIT Extensions    OPTIONAL  }
87  */
88 struct TS_req_st {
89     ASN1_INTEGER *version;
90     TS_MSG_IMPRINT *msg_imprint;
91     ASN1_OBJECT *policy_id;
92     ASN1_INTEGER *nonce;
93     ASN1_BOOLEAN cert_req;
94     STACK_OF(X509_EXTENSION) *extensions;
95 };
96
97 /*-
98  * Accuracy ::= SEQUENCE {
99  *                 seconds        INTEGER           OPTIONAL,
100  *                 millis     [0] INTEGER  (1..999) OPTIONAL,
101  *                 micros     [1] INTEGER  (1..999) OPTIONAL  }
102  */
103 struct TS_accuracy_st {
104     ASN1_INTEGER *seconds;
105     ASN1_INTEGER *millis;
106     ASN1_INTEGER *micros;
107 };
108
109 /*-
110  * TSTInfo ::= SEQUENCE  {
111  *     version                      INTEGER  { v1(1) },
112  *     policy                       TSAPolicyId,
113  *     messageImprint               MessageImprint,
114  *       -- MUST have the same value as the similar field in
115  *       -- TimeStampReq
116  *     serialNumber                 INTEGER,
117  *      -- Time-Stamping users MUST be ready to accommodate integers
118  *      -- up to 160 bits.
119  *     genTime                      GeneralizedTime,
120  *     accuracy                     Accuracy                 OPTIONAL,
121  *     ordering                     BOOLEAN             DEFAULT FALSE,
122  *     nonce                        INTEGER                  OPTIONAL,
123  *       -- MUST be present if the similar field was present
124  *       -- in TimeStampReq.  In that case it MUST have the same value.
125  *     tsa                          [0] GeneralName          OPTIONAL,
126  *     extensions                   [1] IMPLICIT Extensions  OPTIONAL   }
127  */
128 struct TS_tst_info_st {
129     ASN1_INTEGER *version;
130     ASN1_OBJECT *policy_id;
131     TS_MSG_IMPRINT *msg_imprint;
132     ASN1_INTEGER *serial;
133     ASN1_GENERALIZEDTIME *time;
134     TS_ACCURACY *accuracy;
135     ASN1_BOOLEAN ordering;
136     ASN1_INTEGER *nonce;
137     GENERAL_NAME *tsa;
138     STACK_OF(X509_EXTENSION) *extensions;
139 };
140
141 struct TS_status_info_st {
142     ASN1_INTEGER *status;
143     STACK_OF(ASN1_UTF8STRING) *text;
144     ASN1_BIT_STRING *failure_info;
145 };
146
147 /*-
148  * IssuerSerial ::= SEQUENCE {
149  *         issuer                   GeneralNames,
150  *         serialNumber             CertificateSerialNumber
151  *         }
152  */
153 struct ESS_issuer_serial {
154     STACK_OF(GENERAL_NAME) *issuer;
155     ASN1_INTEGER *serial;
156 };
157
158 /*-
159  * ESSCertID ::=  SEQUENCE {
160  *         certHash                 Hash,
161  *         issuerSerial             IssuerSerial OPTIONAL
162  * }
163  */
164 struct ESS_cert_id {
165     ASN1_OCTET_STRING *hash;    /* Always SHA-1 digest. */
166     ESS_ISSUER_SERIAL *issuer_serial;
167 };
168
169 /*-
170  * SigningCertificate ::=  SEQUENCE {
171  *        certs        SEQUENCE OF ESSCertID,
172  *        policies     SEQUENCE OF PolicyInformation OPTIONAL
173  * }
174  */
175 struct ESS_signing_cert {
176     STACK_OF(ESS_CERT_ID) *cert_ids;
177     STACK_OF(POLICYINFO) *policy_info;
178 };
179
180
181 struct TS_resp_ctx {
182     X509 *signer_cert;
183     EVP_PKEY *signer_key;
184     const EVP_MD *signer_md;
185     STACK_OF(X509) *certs;      /* Certs to include in signed data. */
186     STACK_OF(ASN1_OBJECT) *policies; /* Acceptable policies. */
187     ASN1_OBJECT *default_policy; /* It may appear in policies, too. */
188     STACK_OF(EVP_MD) *mds;      /* Acceptable message digests. */
189     ASN1_INTEGER *seconds;      /* accuracy, 0 means not specified. */
190     ASN1_INTEGER *millis;       /* accuracy, 0 means not specified. */
191     ASN1_INTEGER *micros;       /* accuracy, 0 means not specified. */
192     unsigned clock_precision_digits; /* fraction of seconds in time stamp
193                                       * token. */
194     unsigned flags;             /* Optional info, see values above. */
195     /* Callback functions. */
196     TS_serial_cb serial_cb;
197     void *serial_cb_data;       /* User data for serial_cb. */
198     TS_time_cb time_cb;
199     void *time_cb_data;         /* User data for time_cb. */
200     TS_extension_cb extension_cb;
201     void *extension_cb_data;    /* User data for extension_cb. */
202     /* These members are used only while creating the response. */
203     TS_REQ *request;
204     TS_RESP *response;
205     TS_TST_INFO *tst_info;
206 };
207
208 struct TS_verify_ctx {
209     /* Set this to the union of TS_VFY_... flags you want to carry out. */
210     unsigned flags;
211     /* Must be set only with TS_VFY_SIGNATURE. certs is optional. */
212     X509_STORE *store;
213     STACK_OF(X509) *certs;
214     /* Must be set only with TS_VFY_POLICY. */
215     ASN1_OBJECT *policy;
216     /*
217      * Must be set only with TS_VFY_IMPRINT. If md_alg is NULL, the
218      * algorithm from the response is used.
219      */
220     X509_ALGOR *md_alg;
221     unsigned char *imprint;
222     unsigned imprint_len;
223     /* Must be set only with TS_VFY_DATA. */
224     BIO *data;
225     /* Must be set only with TS_VFY_TSA_NAME. */
226     ASN1_INTEGER *nonce;
227     /* Must be set only with TS_VFY_TSA_NAME. */
228     GENERAL_NAME *tsa_name;
229 };