Coverage Report

Created: 2025-04-22 06:18

/src/openssl/crypto/ts/ts_rsp_utils.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2006-2020 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
#include <stdio.h>
11
#include "internal/cryptlib.h"
12
#include <openssl/objects.h>
13
#include <openssl/ts.h>
14
#include <openssl/pkcs7.h>
15
#include "ts_local.h"
16
17
int TS_RESP_set_status_info(TS_RESP *a, TS_STATUS_INFO *status_info)
18
0
{
19
0
    TS_STATUS_INFO *new_status_info;
20
21
0
    if (a->status_info == status_info)
22
0
        return 1;
23
0
    new_status_info = TS_STATUS_INFO_dup(status_info);
24
0
    if (new_status_info == NULL) {
25
0
        ERR_raise(ERR_LIB_TS, ERR_R_MALLOC_FAILURE);
26
0
        return 0;
27
0
    }
28
0
    TS_STATUS_INFO_free(a->status_info);
29
0
    a->status_info = new_status_info;
30
31
0
    return 1;
32
0
}
33
34
TS_STATUS_INFO *TS_RESP_get_status_info(TS_RESP *a)
35
0
{
36
0
    return a->status_info;
37
0
}
38
39
/* Caller loses ownership of PKCS7 and TS_TST_INFO objects. */
40
void TS_RESP_set_tst_info(TS_RESP *a, PKCS7 *p7, TS_TST_INFO *tst_info)
41
0
{
42
0
    PKCS7_free(a->token);
43
0
    a->token = p7;
44
0
    TS_TST_INFO_free(a->tst_info);
45
0
    a->tst_info = tst_info;
46
0
}
47
48
PKCS7 *TS_RESP_get_token(TS_RESP *a)
49
0
{
50
0
    return a->token;
51
0
}
52
53
TS_TST_INFO *TS_RESP_get_tst_info(TS_RESP *a)
54
0
{
55
0
    return a->tst_info;
56
0
}
57
58
int TS_TST_INFO_set_version(TS_TST_INFO *a, long version)
59
0
{
60
0
    return ASN1_INTEGER_set(a->version, version);
61
0
}
62
63
long TS_TST_INFO_get_version(const TS_TST_INFO *a)
64
0
{
65
0
    return ASN1_INTEGER_get(a->version);
66
0
}
67
68
int TS_TST_INFO_set_policy_id(TS_TST_INFO *a, ASN1_OBJECT *policy)
69
0
{
70
0
    ASN1_OBJECT *new_policy;
71
72
0
    if (a->policy_id == policy)
73
0
        return 1;
74
0
    new_policy = OBJ_dup(policy);
75
0
    if (new_policy == NULL) {
76
0
        ERR_raise(ERR_LIB_TS, ERR_R_MALLOC_FAILURE);
77
0
        return 0;
78
0
    }
79
0
    ASN1_OBJECT_free(a->policy_id);
80
0
    a->policy_id = new_policy;
81
0
    return 1;
82
0
}
83
84
ASN1_OBJECT *TS_TST_INFO_get_policy_id(TS_TST_INFO *a)
85
0
{
86
0
    return a->policy_id;
87
0
}
88
89
int TS_TST_INFO_set_msg_imprint(TS_TST_INFO *a, TS_MSG_IMPRINT *msg_imprint)
90
0
{
91
0
    TS_MSG_IMPRINT *new_msg_imprint;
92
93
0
    if (a->msg_imprint == msg_imprint)
94
0
        return 1;
95
0
    new_msg_imprint = TS_MSG_IMPRINT_dup(msg_imprint);
96
0
    if (new_msg_imprint == NULL) {
97
0
        ERR_raise(ERR_LIB_TS, ERR_R_MALLOC_FAILURE);
98
0
        return 0;
99
0
    }
100
0
    TS_MSG_IMPRINT_free(a->msg_imprint);
101
0
    a->msg_imprint = new_msg_imprint;
102
0
    return 1;
103
0
}
104
105
TS_MSG_IMPRINT *TS_TST_INFO_get_msg_imprint(TS_TST_INFO *a)
106
0
{
107
0
    return a->msg_imprint;
108
0
}
109
110
int TS_TST_INFO_set_serial(TS_TST_INFO *a, const ASN1_INTEGER *serial)
111
0
{
112
0
    ASN1_INTEGER *new_serial;
113
114
0
    if (a->serial == serial)
115
0
        return 1;
116
0
    new_serial = ASN1_INTEGER_dup(serial);
117
0
    if (new_serial == NULL) {
118
0
        ERR_raise(ERR_LIB_TS, ERR_R_MALLOC_FAILURE);
119
0
        return 0;
120
0
    }
121
0
    ASN1_INTEGER_free(a->serial);
122
0
    a->serial = new_serial;
123
0
    return 1;
124
0
}
125
126
const ASN1_INTEGER *TS_TST_INFO_get_serial(const TS_TST_INFO *a)
127
0
{
128
0
    return a->serial;
129
0
}
130
131
int TS_TST_INFO_set_time(TS_TST_INFO *a, const ASN1_GENERALIZEDTIME *gtime)
132
0
{
133
0
    ASN1_GENERALIZEDTIME *new_time;
134
135
0
    if (a->time == gtime)
136
0
        return 1;
137
0
    new_time = ASN1_STRING_dup(gtime);
138
0
    if (new_time == NULL) {
139
0
        ERR_raise(ERR_LIB_TS, ERR_R_MALLOC_FAILURE);
140
0
        return 0;
141
0
    }
142
0
    ASN1_GENERALIZEDTIME_free(a->time);
143
0
    a->time = new_time;
144
0
    return 1;
145
0
}
146
147
const ASN1_GENERALIZEDTIME *TS_TST_INFO_get_time(const TS_TST_INFO *a)
148
0
{
149
0
    return a->time;
150
0
}
151
152
int TS_TST_INFO_set_accuracy(TS_TST_INFO *a, TS_ACCURACY *accuracy)
153
0
{
154
0
    TS_ACCURACY *new_accuracy;
155
156
0
    if (a->accuracy == accuracy)
157
0
        return 1;
158
0
    new_accuracy = TS_ACCURACY_dup(accuracy);
159
0
    if (new_accuracy == NULL) {
160
0
        ERR_raise(ERR_LIB_TS, ERR_R_MALLOC_FAILURE);
161
0
        return 0;
162
0
    }
163
0
    TS_ACCURACY_free(a->accuracy);
164
0
    a->accuracy = new_accuracy;
165
0
    return 1;
166
0
}
167
168
TS_ACCURACY *TS_TST_INFO_get_accuracy(TS_TST_INFO *a)
169
0
{
170
0
    return a->accuracy;
171
0
}
172
173
int TS_ACCURACY_set_seconds(TS_ACCURACY *a, const ASN1_INTEGER *seconds)
174
0
{
175
0
    ASN1_INTEGER *new_seconds;
176
177
0
    if (a->seconds == seconds)
178
0
        return 1;
179
0
    new_seconds = ASN1_INTEGER_dup(seconds);
180
0
    if (new_seconds == NULL) {
181
0
        ERR_raise(ERR_LIB_TS, ERR_R_MALLOC_FAILURE);
182
0
        return 0;
183
0
    }
184
0
    ASN1_INTEGER_free(a->seconds);
185
0
    a->seconds = new_seconds;
186
0
    return 1;
187
0
}
188
189
const ASN1_INTEGER *TS_ACCURACY_get_seconds(const TS_ACCURACY *a)
190
0
{
191
0
    return a->seconds;
192
0
}
193
194
int TS_ACCURACY_set_millis(TS_ACCURACY *a, const ASN1_INTEGER *millis)
195
0
{
196
0
    ASN1_INTEGER *new_millis = NULL;
197
198
0
    if (a->millis == millis)
199
0
        return 1;
200
0
    if (millis != NULL) {
201
0
        new_millis = ASN1_INTEGER_dup(millis);
202
0
        if (new_millis == NULL) {
203
0
            ERR_raise(ERR_LIB_TS, ERR_R_MALLOC_FAILURE);
204
0
            return 0;
205
0
        }
206
0
    }
207
0
    ASN1_INTEGER_free(a->millis);
208
0
    a->millis = new_millis;
209
0
    return 1;
210
0
}
211
212
const ASN1_INTEGER *TS_ACCURACY_get_millis(const TS_ACCURACY *a)
213
0
{
214
0
    return a->millis;
215
0
}
216
217
int TS_ACCURACY_set_micros(TS_ACCURACY *a, const ASN1_INTEGER *micros)
218
0
{
219
0
    ASN1_INTEGER *new_micros = NULL;
220
221
0
    if (a->micros == micros)
222
0
        return 1;
223
0
    if (micros != NULL) {
224
0
        new_micros = ASN1_INTEGER_dup(micros);
225
0
        if (new_micros == NULL) {
226
0
            ERR_raise(ERR_LIB_TS, ERR_R_MALLOC_FAILURE);
227
0
            return 0;
228
0
        }
229
0
    }
230
0
    ASN1_INTEGER_free(a->micros);
231
0
    a->micros = new_micros;
232
0
    return 1;
233
0
}
234
235
const ASN1_INTEGER *TS_ACCURACY_get_micros(const TS_ACCURACY *a)
236
0
{
237
0
    return a->micros;
238
0
}
239
240
int TS_TST_INFO_set_ordering(TS_TST_INFO *a, int ordering)
241
0
{
242
0
    a->ordering = ordering ? 0xFF : 0x00;
243
0
    return 1;
244
0
}
245
246
int TS_TST_INFO_get_ordering(const TS_TST_INFO *a)
247
0
{
248
0
    return a->ordering ? 1 : 0;
249
0
}
250
251
int TS_TST_INFO_set_nonce(TS_TST_INFO *a, const ASN1_INTEGER *nonce)
252
0
{
253
0
    ASN1_INTEGER *new_nonce;
254
255
0
    if (a->nonce == nonce)
256
0
        return 1;
257
0
    new_nonce = ASN1_INTEGER_dup(nonce);
258
0
    if (new_nonce == NULL) {
259
0
        ERR_raise(ERR_LIB_TS, ERR_R_MALLOC_FAILURE);
260
0
        return 0;
261
0
    }
262
0
    ASN1_INTEGER_free(a->nonce);
263
0
    a->nonce = new_nonce;
264
0
    return 1;
265
0
}
266
267
const ASN1_INTEGER *TS_TST_INFO_get_nonce(const TS_TST_INFO *a)
268
0
{
269
0
    return a->nonce;
270
0
}
271
272
int TS_TST_INFO_set_tsa(TS_TST_INFO *a, GENERAL_NAME *tsa)
273
0
{
274
0
    GENERAL_NAME *new_tsa;
275
276
0
    if (a->tsa == tsa)
277
0
        return 1;
278
0
    new_tsa = GENERAL_NAME_dup(tsa);
279
0
    if (new_tsa == NULL) {
280
0
        ERR_raise(ERR_LIB_TS, ERR_R_MALLOC_FAILURE);
281
0
        return 0;
282
0
    }
283
0
    GENERAL_NAME_free(a->tsa);
284
0
    a->tsa = new_tsa;
285
0
    return 1;
286
0
}
287
288
GENERAL_NAME *TS_TST_INFO_get_tsa(TS_TST_INFO *a)
289
0
{
290
0
    return a->tsa;
291
0
}
292
293
STACK_OF(X509_EXTENSION) *TS_TST_INFO_get_exts(TS_TST_INFO *a)
294
0
{
295
0
    return a->extensions;
296
0
}
297
298
void TS_TST_INFO_ext_free(TS_TST_INFO *a)
299
0
{
300
0
    if (!a)
301
0
        return;
302
0
    sk_X509_EXTENSION_pop_free(a->extensions, X509_EXTENSION_free);
303
0
    a->extensions = NULL;
304
0
}
305
306
int TS_TST_INFO_get_ext_count(TS_TST_INFO *a)
307
0
{
308
0
    return X509v3_get_ext_count(a->extensions);
309
0
}
310
311
int TS_TST_INFO_get_ext_by_NID(TS_TST_INFO *a, int nid, int lastpos)
312
0
{
313
0
    return X509v3_get_ext_by_NID(a->extensions, nid, lastpos);
314
0
}
315
316
int TS_TST_INFO_get_ext_by_OBJ(TS_TST_INFO *a, const ASN1_OBJECT *obj, int lastpos)
317
0
{
318
0
    return X509v3_get_ext_by_OBJ(a->extensions, obj, lastpos);
319
0
}
320
321
int TS_TST_INFO_get_ext_by_critical(TS_TST_INFO *a, int crit, int lastpos)
322
0
{
323
0
    return X509v3_get_ext_by_critical(a->extensions, crit, lastpos);
324
0
}
325
326
X509_EXTENSION *TS_TST_INFO_get_ext(TS_TST_INFO *a, int loc)
327
0
{
328
0
    return X509v3_get_ext(a->extensions, loc);
329
0
}
330
331
X509_EXTENSION *TS_TST_INFO_delete_ext(TS_TST_INFO *a, int loc)
332
0
{
333
0
    return X509v3_delete_ext(a->extensions, loc);
334
0
}
335
336
int TS_TST_INFO_add_ext(TS_TST_INFO *a, X509_EXTENSION *ex, int loc)
337
0
{
338
0
    return X509v3_add_ext(&a->extensions, ex, loc) != NULL;
339
0
}
340
341
void *TS_TST_INFO_get_ext_d2i(TS_TST_INFO *a, int nid, int *crit, int *idx)
342
0
{
343
0
    return X509V3_get_d2i(a->extensions, nid, crit, idx);
344
0
}
345
346
int TS_STATUS_INFO_set_status(TS_STATUS_INFO *a, int i)
347
0
{
348
0
    return ASN1_INTEGER_set(a->status, i);
349
0
}
350
351
const ASN1_INTEGER *TS_STATUS_INFO_get0_status(const TS_STATUS_INFO *a)
352
0
{
353
0
    return a->status;
354
0
}
355
356
const STACK_OF(ASN1_UTF8STRING) *
357
TS_STATUS_INFO_get0_text(const TS_STATUS_INFO *a)
358
0
{
359
0
    return a->text;
360
0
}
361
362
const ASN1_BIT_STRING *TS_STATUS_INFO_get0_failure_info(const TS_STATUS_INFO *a)
363
0
{
364
0
    return a->failure_info;
365
0
}