1 /* crypto/ts/ts_resp_utils.c */
3 * Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL project
6 /* ====================================================================
7 * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
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
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/)"
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.
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.
35 * 6. Redistributions of any form whatsoever must retain the following
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
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 * ====================================================================
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).
61 #include "internal/cryptlib.h"
62 #include <openssl/objects.h>
63 #include <openssl/ts.h>
64 #include <openssl/pkcs7.h>
67 /* Function definitions. */
69 int TS_RESP_set_status_info(TS_RESP *a, TS_STATUS_INFO *status_info)
71 TS_STATUS_INFO *new_status_info;
73 if (a->status_info == status_info)
75 new_status_info = TS_STATUS_INFO_dup(status_info);
76 if (new_status_info == NULL) {
77 TSerr(TS_F_TS_RESP_SET_STATUS_INFO, ERR_R_MALLOC_FAILURE);
80 TS_STATUS_INFO_free(a->status_info);
81 a->status_info = new_status_info;
86 TS_STATUS_INFO *TS_RESP_get_status_info(TS_RESP *a)
88 return a->status_info;
91 /* Caller loses ownership of PKCS7 and TS_TST_INFO objects. */
92 void TS_RESP_set_tst_info(TS_RESP *a, PKCS7 *p7, TS_TST_INFO *tst_info)
94 /* Set new PKCS7 and TST_INFO objects. */
97 TS_TST_INFO_free(a->tst_info);
98 a->tst_info = tst_info;
101 PKCS7 *TS_RESP_get_token(TS_RESP *a)
106 TS_TST_INFO *TS_RESP_get_tst_info(TS_RESP *a)
111 int TS_TST_INFO_set_version(TS_TST_INFO *a, long version)
113 return ASN1_INTEGER_set(a->version, version);
116 long TS_TST_INFO_get_version(const TS_TST_INFO *a)
118 return ASN1_INTEGER_get(a->version);
121 int TS_TST_INFO_set_policy_id(TS_TST_INFO *a, ASN1_OBJECT *policy)
123 ASN1_OBJECT *new_policy;
125 if (a->policy_id == policy)
127 new_policy = OBJ_dup(policy);
128 if (new_policy == NULL) {
129 TSerr(TS_F_TS_TST_INFO_SET_POLICY_ID, ERR_R_MALLOC_FAILURE);
132 ASN1_OBJECT_free(a->policy_id);
133 a->policy_id = new_policy;
137 ASN1_OBJECT *TS_TST_INFO_get_policy_id(TS_TST_INFO *a)
142 int TS_TST_INFO_set_msg_imprint(TS_TST_INFO *a, TS_MSG_IMPRINT *msg_imprint)
144 TS_MSG_IMPRINT *new_msg_imprint;
146 if (a->msg_imprint == msg_imprint)
148 new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint);
149 if (new_msg_imprint == NULL) {
150 TSerr(TS_F_TS_TST_INFO_SET_MSG_IMPRINT, ERR_R_MALLOC_FAILURE);
153 TS_MSG_IMPRINT_free(a->msg_imprint);
154 a->msg_imprint = new_msg_imprint;
158 TS_MSG_IMPRINT *TS_TST_INFO_get_msg_imprint(TS_TST_INFO *a)
160 return a->msg_imprint;
163 int TS_TST_INFO_set_serial(TS_TST_INFO *a, const ASN1_INTEGER *serial)
165 ASN1_INTEGER *new_serial;
167 if (a->serial == serial)
169 new_serial = ASN1_INTEGER_dup(serial);
170 if (new_serial == NULL) {
171 TSerr(TS_F_TS_TST_INFO_SET_SERIAL, ERR_R_MALLOC_FAILURE);
174 ASN1_INTEGER_free(a->serial);
175 a->serial = new_serial;
179 const ASN1_INTEGER *TS_TST_INFO_get_serial(const TS_TST_INFO *a)
184 int TS_TST_INFO_set_time(TS_TST_INFO *a, const ASN1_GENERALIZEDTIME *gtime)
186 ASN1_GENERALIZEDTIME *new_time;
188 if (a->time == gtime)
190 new_time = ASN1_STRING_dup(gtime);
191 if (new_time == NULL) {
192 TSerr(TS_F_TS_TST_INFO_SET_TIME, ERR_R_MALLOC_FAILURE);
195 ASN1_GENERALIZEDTIME_free(a->time);
200 const ASN1_GENERALIZEDTIME *TS_TST_INFO_get_time(const TS_TST_INFO *a)
205 int TS_TST_INFO_set_accuracy(TS_TST_INFO *a, TS_ACCURACY *accuracy)
207 TS_ACCURACY *new_accuracy;
209 if (a->accuracy == accuracy)
211 new_accuracy = TS_ACCURACY_dup(accuracy);
212 if (new_accuracy == NULL) {
213 TSerr(TS_F_TS_TST_INFO_SET_ACCURACY, ERR_R_MALLOC_FAILURE);
216 TS_ACCURACY_free(a->accuracy);
217 a->accuracy = new_accuracy;
221 TS_ACCURACY *TS_TST_INFO_get_accuracy(TS_TST_INFO *a)
226 int TS_ACCURACY_set_seconds(TS_ACCURACY *a, const ASN1_INTEGER *seconds)
228 ASN1_INTEGER *new_seconds;
230 if (a->seconds == seconds)
232 new_seconds = ASN1_INTEGER_dup(seconds);
233 if (new_seconds == NULL) {
234 TSerr(TS_F_TS_ACCURACY_SET_SECONDS, ERR_R_MALLOC_FAILURE);
237 ASN1_INTEGER_free(a->seconds);
238 a->seconds = new_seconds;
242 const ASN1_INTEGER *TS_ACCURACY_get_seconds(const TS_ACCURACY *a)
247 int TS_ACCURACY_set_millis(TS_ACCURACY *a, const ASN1_INTEGER *millis)
249 ASN1_INTEGER *new_millis = NULL;
251 if (a->millis == millis)
253 if (millis != NULL) {
254 new_millis = ASN1_INTEGER_dup(millis);
255 if (new_millis == NULL) {
256 TSerr(TS_F_TS_ACCURACY_SET_MILLIS, ERR_R_MALLOC_FAILURE);
260 ASN1_INTEGER_free(a->millis);
261 a->millis = new_millis;
265 const ASN1_INTEGER *TS_ACCURACY_get_millis(const TS_ACCURACY *a)
270 int TS_ACCURACY_set_micros(TS_ACCURACY *a, const ASN1_INTEGER *micros)
272 ASN1_INTEGER *new_micros = NULL;
274 if (a->micros == micros)
276 if (micros != NULL) {
277 new_micros = ASN1_INTEGER_dup(micros);
278 if (new_micros == NULL) {
279 TSerr(TS_F_TS_ACCURACY_SET_MICROS, ERR_R_MALLOC_FAILURE);
283 ASN1_INTEGER_free(a->micros);
284 a->micros = new_micros;
288 const ASN1_INTEGER *TS_ACCURACY_get_micros(const TS_ACCURACY *a)
293 int TS_TST_INFO_set_ordering(TS_TST_INFO *a, int ordering)
295 a->ordering = ordering ? 0xFF : 0x00;
299 int TS_TST_INFO_get_ordering(const TS_TST_INFO *a)
301 return a->ordering ? 1 : 0;
304 int TS_TST_INFO_set_nonce(TS_TST_INFO *a, const ASN1_INTEGER *nonce)
306 ASN1_INTEGER *new_nonce;
308 if (a->nonce == nonce)
310 new_nonce = ASN1_INTEGER_dup(nonce);
311 if (new_nonce == NULL) {
312 TSerr(TS_F_TS_TST_INFO_SET_NONCE, ERR_R_MALLOC_FAILURE);
315 ASN1_INTEGER_free(a->nonce);
316 a->nonce = new_nonce;
320 const ASN1_INTEGER *TS_TST_INFO_get_nonce(const TS_TST_INFO *a)
325 int TS_TST_INFO_set_tsa(TS_TST_INFO *a, GENERAL_NAME *tsa)
327 GENERAL_NAME *new_tsa;
331 new_tsa = GENERAL_NAME_dup(tsa);
332 if (new_tsa == NULL) {
333 TSerr(TS_F_TS_TST_INFO_SET_TSA, ERR_R_MALLOC_FAILURE);
336 GENERAL_NAME_free(a->tsa);
341 GENERAL_NAME *TS_TST_INFO_get_tsa(TS_TST_INFO *a)
346 STACK_OF(X509_EXTENSION) *TS_TST_INFO_get_exts(TS_TST_INFO *a)
348 return a->extensions;
351 void TS_TST_INFO_ext_free(TS_TST_INFO *a)
355 sk_X509_EXTENSION_pop_free(a->extensions, X509_EXTENSION_free);
356 a->extensions = NULL;
359 int TS_TST_INFO_get_ext_count(TS_TST_INFO *a)
361 return X509v3_get_ext_count(a->extensions);
364 int TS_TST_INFO_get_ext_by_NID(TS_TST_INFO *a, int nid, int lastpos)
366 return X509v3_get_ext_by_NID(a->extensions, nid, lastpos);
369 int TS_TST_INFO_get_ext_by_OBJ(TS_TST_INFO *a, ASN1_OBJECT *obj, int lastpos)
371 return X509v3_get_ext_by_OBJ(a->extensions, obj, lastpos);
374 int TS_TST_INFO_get_ext_by_critical(TS_TST_INFO *a, int crit, int lastpos)
376 return X509v3_get_ext_by_critical(a->extensions, crit, lastpos);
379 X509_EXTENSION *TS_TST_INFO_get_ext(TS_TST_INFO *a, int loc)
381 return X509v3_get_ext(a->extensions, loc);
384 X509_EXTENSION *TS_TST_INFO_delete_ext(TS_TST_INFO *a, int loc)
386 return X509v3_delete_ext(a->extensions, loc);
389 int TS_TST_INFO_add_ext(TS_TST_INFO *a, X509_EXTENSION *ex, int loc)
391 return X509v3_add_ext(&a->extensions, ex, loc) != NULL;
394 void *TS_TST_INFO_get_ext_d2i(TS_TST_INFO *a, int nid, int *crit, int *idx)
396 return X509V3_get_d2i(a->extensions, nid, crit, idx);
399 int TS_STATUS_INFO_set_status(TS_STATUS_INFO *a, int i)
401 return ASN1_INTEGER_set(a->status, i);