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