Coverage Report

Created: 2022-08-24 06:31

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