Avoid structure access in crypto/ts
[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 DECLARE_STACK_OF(ASN1_UTF8STRING)
148
149 /*-
150  * IssuerSerial ::= SEQUENCE {
151  *         issuer                   GeneralNames,
152  *         serialNumber             CertificateSerialNumber
153  *         }
154  */
155 struct ESS_issuer_serial {
156     STACK_OF(GENERAL_NAME) *issuer;
157     ASN1_INTEGER *serial;
158 };
159
160 /*-
161  * ESSCertID ::=  SEQUENCE {
162  *         certHash                 Hash,
163  *         issuerSerial             IssuerSerial OPTIONAL
164  * }
165  */
166 struct ESS_cert_id {
167     ASN1_OCTET_STRING *hash;    /* Always SHA-1 digest. */
168     ESS_ISSUER_SERIAL *issuer_serial;
169 };
170
171 /*-
172  * SigningCertificate ::=  SEQUENCE {
173  *        certs        SEQUENCE OF ESSCertID,
174  *        policies     SEQUENCE OF PolicyInformation OPTIONAL
175  * }
176  */
177 struct ESS_signing_cert {
178     STACK_OF(ESS_CERT_ID) *cert_ids;
179     STACK_OF(POLICYINFO) *policy_info;
180 };
181
182
183 struct TS_resp_ctx {
184     X509 *signer_cert;
185     EVP_PKEY *signer_key;
186     STACK_OF(X509) *certs;      /* Certs to include in signed data. */
187     STACK_OF(ASN1_OBJECT) *policies; /* Acceptable policies. */
188     ASN1_OBJECT *default_policy; /* It may appear in policies, too. */
189     STACK_OF(EVP_MD) *mds;      /* Acceptable message digests. */
190     ASN1_INTEGER *seconds;      /* accuracy, 0 means not specified. */
191     ASN1_INTEGER *millis;       /* accuracy, 0 means not specified. */
192     ASN1_INTEGER *micros;       /* accuracy, 0 means not specified. */
193     unsigned clock_precision_digits; /* fraction of seconds in time stamp
194                                       * token. */
195     unsigned flags;             /* Optional info, see values above. */
196     /* Callback functions. */
197     TS_serial_cb serial_cb;
198     void *serial_cb_data;       /* User data for serial_cb. */
199     TS_time_cb time_cb;
200     void *time_cb_data;         /* User data for time_cb. */
201     TS_extension_cb extension_cb;
202     void *extension_cb_data;    /* User data for extension_cb. */
203     /* These members are used only while creating the response. */
204     TS_REQ *request;
205     TS_RESP *response;
206     TS_TST_INFO *tst_info;
207 };
208
209 struct TS_verify_ctx {
210     /* Set this to the union of TS_VFY_... flags you want to carry out. */
211     unsigned flags;
212     /* Must be set only with TS_VFY_SIGNATURE. certs is optional. */
213     X509_STORE *store;
214     STACK_OF(X509) *certs;
215     /* Must be set only with TS_VFY_POLICY. */
216     ASN1_OBJECT *policy;
217     /*
218      * Must be set only with TS_VFY_IMPRINT. If md_alg is NULL, the
219      * algorithm from the response is used.
220      */
221     X509_ALGOR *md_alg;
222     unsigned char *imprint;
223     unsigned imprint_len;
224     /* Must be set only with TS_VFY_DATA. */
225     BIO *data;
226     /* Must be set only with TS_VFY_TSA_NAME. */
227     ASN1_INTEGER *nonce;
228     /* Must be set only with TS_VFY_TSA_NAME. */
229     GENERAL_NAME *tsa_name;
230 };