]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/ts/ts_rsp_utils.c
Identify and move common internal libcrypto header files
[thirdparty/openssl.git] / crypto / ts / ts_rsp_utils.c
CommitLineData
c7235be6 1/* crypto/ts/ts_resp_utils.c */
0f113f3e
MC
2/*
3 * Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL project
4 * 2002.
c7235be6
UM
5 */
6/* ====================================================================
7 * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
0f113f3e 14 * notice, this list of conditions and the following disclaimer.
c7235be6
UM
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * licensing@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#include <stdio.h>
b39fc560 61#include "internal/cryptlib.h"
c7235be6
UM
62#include <openssl/objects.h>
63#include <openssl/ts.h>
64#include <openssl/pkcs7.h>
65
66/* Function definitions. */
67
68int TS_RESP_set_status_info(TS_RESP *a, TS_STATUS_INFO *status_info)
0f113f3e
MC
69{
70 TS_STATUS_INFO *new_status_info;
71
72 if (a->status_info == status_info)
73 return 1;
74 new_status_info = TS_STATUS_INFO_dup(status_info);
75 if (new_status_info == NULL) {
76 TSerr(TS_F_TS_RESP_SET_STATUS_INFO, ERR_R_MALLOC_FAILURE);
77 return 0;
78 }
79 TS_STATUS_INFO_free(a->status_info);
80 a->status_info = new_status_info;
81
82 return 1;
83}
c7235be6
UM
84
85TS_STATUS_INFO *TS_RESP_get_status_info(TS_RESP *a)
0f113f3e
MC
86{
87 return a->status_info;
88}
c7235be6
UM
89
90/* Caller loses ownership of PKCS7 and TS_TST_INFO objects. */
91void TS_RESP_set_tst_info(TS_RESP *a, PKCS7 *p7, TS_TST_INFO *tst_info)
0f113f3e
MC
92{
93 /* Set new PKCS7 and TST_INFO objects. */
94 PKCS7_free(a->token);
95 a->token = p7;
96 TS_TST_INFO_free(a->tst_info);
97 a->tst_info = tst_info;
98}
c7235be6
UM
99
100PKCS7 *TS_RESP_get_token(TS_RESP *a)
0f113f3e
MC
101{
102 return a->token;
103}
c7235be6
UM
104
105TS_TST_INFO *TS_RESP_get_tst_info(TS_RESP *a)
0f113f3e
MC
106{
107 return a->tst_info;
108}
c7235be6
UM
109
110int TS_TST_INFO_set_version(TS_TST_INFO *a, long version)
0f113f3e
MC
111{
112 return ASN1_INTEGER_set(a->version, version);
113}
c7235be6 114
6c73d011 115long TS_TST_INFO_get_version(const TS_TST_INFO *a)
0f113f3e
MC
116{
117 return ASN1_INTEGER_get(a->version);
118}
c7235be6
UM
119
120int TS_TST_INFO_set_policy_id(TS_TST_INFO *a, ASN1_OBJECT *policy)
0f113f3e
MC
121{
122 ASN1_OBJECT *new_policy;
123
124 if (a->policy_id == policy)
125 return 1;
126 new_policy = OBJ_dup(policy);
127 if (new_policy == NULL) {
128 TSerr(TS_F_TS_TST_INFO_SET_POLICY_ID, ERR_R_MALLOC_FAILURE);
129 return 0;
130 }
131 ASN1_OBJECT_free(a->policy_id);
132 a->policy_id = new_policy;
133 return 1;
134}
c7235be6
UM
135
136ASN1_OBJECT *TS_TST_INFO_get_policy_id(TS_TST_INFO *a)
0f113f3e
MC
137{
138 return a->policy_id;
139}
c7235be6
UM
140
141int TS_TST_INFO_set_msg_imprint(TS_TST_INFO *a, TS_MSG_IMPRINT *msg_imprint)
0f113f3e
MC
142{
143 TS_MSG_IMPRINT *new_msg_imprint;
144
145 if (a->msg_imprint == msg_imprint)
146 return 1;
147 new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint);
148 if (new_msg_imprint == NULL) {
149 TSerr(TS_F_TS_TST_INFO_SET_MSG_IMPRINT, ERR_R_MALLOC_FAILURE);
150 return 0;
151 }
152 TS_MSG_IMPRINT_free(a->msg_imprint);
153 a->msg_imprint = new_msg_imprint;
154 return 1;
155}
c7235be6
UM
156
157TS_MSG_IMPRINT *TS_TST_INFO_get_msg_imprint(TS_TST_INFO *a)
0f113f3e
MC
158{
159 return a->msg_imprint;
160}
c7235be6 161
6c73d011 162int TS_TST_INFO_set_serial(TS_TST_INFO *a, const ASN1_INTEGER *serial)
0f113f3e
MC
163{
164 ASN1_INTEGER *new_serial;
165
166 if (a->serial == serial)
167 return 1;
168 new_serial = ASN1_INTEGER_dup(serial);
169 if (new_serial == NULL) {
170 TSerr(TS_F_TS_TST_INFO_SET_SERIAL, ERR_R_MALLOC_FAILURE);
171 return 0;
172 }
173 ASN1_INTEGER_free(a->serial);
174 a->serial = new_serial;
175 return 1;
176}
c7235be6 177
6c73d011 178const ASN1_INTEGER *TS_TST_INFO_get_serial(const TS_TST_INFO *a)
0f113f3e
MC
179{
180 return a->serial;
181}
c7235be6 182
6c73d011 183int TS_TST_INFO_set_time(TS_TST_INFO *a, const ASN1_GENERALIZEDTIME *gtime)
0f113f3e
MC
184{
185 ASN1_GENERALIZEDTIME *new_time;
186
187 if (a->time == gtime)
188 return 1;
f422a514 189 new_time = ASN1_STRING_dup(gtime);
0f113f3e
MC
190 if (new_time == NULL) {
191 TSerr(TS_F_TS_TST_INFO_SET_TIME, ERR_R_MALLOC_FAILURE);
192 return 0;
193 }
194 ASN1_GENERALIZEDTIME_free(a->time);
195 a->time = new_time;
196 return 1;
197}
c7235be6 198
6c73d011 199const ASN1_GENERALIZEDTIME *TS_TST_INFO_get_time(const TS_TST_INFO *a)
0f113f3e
MC
200{
201 return a->time;
202}
c7235be6
UM
203
204int TS_TST_INFO_set_accuracy(TS_TST_INFO *a, TS_ACCURACY *accuracy)
0f113f3e
MC
205{
206 TS_ACCURACY *new_accuracy;
207
208 if (a->accuracy == accuracy)
209 return 1;
210 new_accuracy = TS_ACCURACY_dup(accuracy);
211 if (new_accuracy == NULL) {
212 TSerr(TS_F_TS_TST_INFO_SET_ACCURACY, ERR_R_MALLOC_FAILURE);
213 return 0;
214 }
215 TS_ACCURACY_free(a->accuracy);
216 a->accuracy = new_accuracy;
217 return 1;
218}
c7235be6
UM
219
220TS_ACCURACY *TS_TST_INFO_get_accuracy(TS_TST_INFO *a)
0f113f3e
MC
221{
222 return a->accuracy;
223}
c7235be6 224
6c73d011 225int TS_ACCURACY_set_seconds(TS_ACCURACY *a, const ASN1_INTEGER *seconds)
0f113f3e
MC
226{
227 ASN1_INTEGER *new_seconds;
228
229 if (a->seconds == seconds)
230 return 1;
231 new_seconds = ASN1_INTEGER_dup(seconds);
232 if (new_seconds == NULL) {
233 TSerr(TS_F_TS_ACCURACY_SET_SECONDS, ERR_R_MALLOC_FAILURE);
234 return 0;
235 }
236 ASN1_INTEGER_free(a->seconds);
237 a->seconds = new_seconds;
238 return 1;
239}
c7235be6 240
6c73d011 241const ASN1_INTEGER *TS_ACCURACY_get_seconds(const TS_ACCURACY *a)
0f113f3e
MC
242{
243 return a->seconds;
244}
c7235be6 245
6c73d011 246int TS_ACCURACY_set_millis(TS_ACCURACY *a, const ASN1_INTEGER *millis)
0f113f3e
MC
247{
248 ASN1_INTEGER *new_millis = NULL;
249
250 if (a->millis == millis)
251 return 1;
252 if (millis != NULL) {
253 new_millis = ASN1_INTEGER_dup(millis);
254 if (new_millis == NULL) {
255 TSerr(TS_F_TS_ACCURACY_SET_MILLIS, ERR_R_MALLOC_FAILURE);
256 return 0;
257 }
258 }
259 ASN1_INTEGER_free(a->millis);
260 a->millis = new_millis;
261 return 1;
262}
c7235be6 263
6c73d011 264const ASN1_INTEGER *TS_ACCURACY_get_millis(const TS_ACCURACY *a)
0f113f3e
MC
265{
266 return a->millis;
267}
c7235be6 268
6c73d011 269int TS_ACCURACY_set_micros(TS_ACCURACY *a, const ASN1_INTEGER *micros)
0f113f3e
MC
270{
271 ASN1_INTEGER *new_micros = NULL;
272
273 if (a->micros == micros)
274 return 1;
275 if (micros != NULL) {
276 new_micros = ASN1_INTEGER_dup(micros);
277 if (new_micros == NULL) {
278 TSerr(TS_F_TS_ACCURACY_SET_MICROS, ERR_R_MALLOC_FAILURE);
279 return 0;
280 }
281 }
282 ASN1_INTEGER_free(a->micros);
283 a->micros = new_micros;
284 return 1;
285}
c7235be6 286
6c73d011 287const ASN1_INTEGER *TS_ACCURACY_get_micros(const TS_ACCURACY *a)
0f113f3e
MC
288{
289 return a->micros;
290}
c7235be6
UM
291
292int TS_TST_INFO_set_ordering(TS_TST_INFO *a, int ordering)
0f113f3e
MC
293{
294 a->ordering = ordering ? 0xFF : 0x00;
295 return 1;
296}
c7235be6 297
6c73d011 298int TS_TST_INFO_get_ordering(const TS_TST_INFO *a)
0f113f3e
MC
299{
300 return a->ordering ? 1 : 0;
301}
c7235be6 302
6c73d011 303int TS_TST_INFO_set_nonce(TS_TST_INFO *a, const ASN1_INTEGER *nonce)
0f113f3e
MC
304{
305 ASN1_INTEGER *new_nonce;
306
307 if (a->nonce == nonce)
308 return 1;
309 new_nonce = ASN1_INTEGER_dup(nonce);
310 if (new_nonce == NULL) {
311 TSerr(TS_F_TS_TST_INFO_SET_NONCE, ERR_R_MALLOC_FAILURE);
312 return 0;
313 }
314 ASN1_INTEGER_free(a->nonce);
315 a->nonce = new_nonce;
316 return 1;
317}
c7235be6 318
6c73d011 319const ASN1_INTEGER *TS_TST_INFO_get_nonce(const TS_TST_INFO *a)
0f113f3e
MC
320{
321 return a->nonce;
322}
c7235be6
UM
323
324int TS_TST_INFO_set_tsa(TS_TST_INFO *a, GENERAL_NAME *tsa)
0f113f3e
MC
325{
326 GENERAL_NAME *new_tsa;
327
328 if (a->tsa == tsa)
329 return 1;
330 new_tsa = GENERAL_NAME_dup(tsa);
331 if (new_tsa == NULL) {
332 TSerr(TS_F_TS_TST_INFO_SET_TSA, ERR_R_MALLOC_FAILURE);
333 return 0;
334 }
335 GENERAL_NAME_free(a->tsa);
336 a->tsa = new_tsa;
337 return 1;
338}
c7235be6
UM
339
340GENERAL_NAME *TS_TST_INFO_get_tsa(TS_TST_INFO *a)
0f113f3e
MC
341{
342 return a->tsa;
343}
c7235be6
UM
344
345STACK_OF(X509_EXTENSION) *TS_TST_INFO_get_exts(TS_TST_INFO *a)
0f113f3e
MC
346{
347 return a->extensions;
348}
c7235be6
UM
349
350void TS_TST_INFO_ext_free(TS_TST_INFO *a)
0f113f3e
MC
351{
352 if (!a)
353 return;
354 sk_X509_EXTENSION_pop_free(a->extensions, X509_EXTENSION_free);
355 a->extensions = NULL;
356}
c7235be6
UM
357
358int TS_TST_INFO_get_ext_count(TS_TST_INFO *a)
0f113f3e
MC
359{
360 return X509v3_get_ext_count(a->extensions);
361}
c7235be6
UM
362
363int TS_TST_INFO_get_ext_by_NID(TS_TST_INFO *a, int nid, int lastpos)
0f113f3e
MC
364{
365 return X509v3_get_ext_by_NID(a->extensions, nid, lastpos);
366}
c7235be6
UM
367
368int TS_TST_INFO_get_ext_by_OBJ(TS_TST_INFO *a, ASN1_OBJECT *obj, int lastpos)
0f113f3e
MC
369{
370 return X509v3_get_ext_by_OBJ(a->extensions, obj, lastpos);
371}
c7235be6
UM
372
373int TS_TST_INFO_get_ext_by_critical(TS_TST_INFO *a, int crit, int lastpos)
0f113f3e
MC
374{
375 return X509v3_get_ext_by_critical(a->extensions, crit, lastpos);
376}
c7235be6
UM
377
378X509_EXTENSION *TS_TST_INFO_get_ext(TS_TST_INFO *a, int loc)
0f113f3e
MC
379{
380 return X509v3_get_ext(a->extensions, loc);
381}
c7235be6
UM
382
383X509_EXTENSION *TS_TST_INFO_delete_ext(TS_TST_INFO *a, int loc)
0f113f3e
MC
384{
385 return X509v3_delete_ext(a->extensions, loc);
386}
c7235be6
UM
387
388int TS_TST_INFO_add_ext(TS_TST_INFO *a, X509_EXTENSION *ex, int loc)
0f113f3e
MC
389{
390 return X509v3_add_ext(&a->extensions, ex, loc) != NULL;
391}
c7235be6
UM
392
393void *TS_TST_INFO_get_ext_d2i(TS_TST_INFO *a, int nid, int *crit, int *idx)
0f113f3e
MC
394{
395 return X509V3_get_d2i(a->extensions, nid, crit, idx);
396}