GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libcrypto/crypto/../../libssl/src/crypto/ts/ts_asn1.c Lines: 0 104 0.0 %
Date: 2016-12-06 Branches: 0 28 0.0 %

Line Branch Exec Source
1
/* $OpenBSD: ts_asn1.c,v 1.9 2015/07/24 15:25:44 jsing Exp $ */
2
/* Written by Nils Larsch for the OpenSSL project 2004.
3
 */
4
/* ====================================================================
5
 * Copyright (c) 2006 The OpenSSL Project.  All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 *
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
13
 *
14
 * 2. Redistributions in binary form must reproduce the above copyright
15
 *    notice, this list of conditions and the following disclaimer in
16
 *    the documentation and/or other materials provided with the
17
 *    distribution.
18
 *
19
 * 3. All advertising materials mentioning features or use of this
20
 *    software must display the following acknowledgment:
21
 *    "This product includes software developed by the OpenSSL Project
22
 *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
23
 *
24
 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25
 *    endorse or promote products derived from this software without
26
 *    prior written permission. For written permission, please contact
27
 *    licensing@OpenSSL.org.
28
 *
29
 * 5. Products derived from this software may not be called "OpenSSL"
30
 *    nor may "OpenSSL" appear in their names without prior written
31
 *    permission of the OpenSSL Project.
32
 *
33
 * 6. Redistributions of any form whatsoever must retain the following
34
 *    acknowledgment:
35
 *    "This product includes software developed by the OpenSSL Project
36
 *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
37
 *
38
 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
42
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49
 * OF THE POSSIBILITY OF SUCH DAMAGE.
50
 * ====================================================================
51
 *
52
 * This product includes cryptographic software written by Eric Young
53
 * (eay@cryptsoft.com).  This product includes software written by Tim
54
 * Hudson (tjh@cryptsoft.com).
55
 *
56
 */
57
58
#include <openssl/opensslconf.h>
59
60
#include <openssl/ts.h>
61
#include <openssl/err.h>
62
#include <openssl/asn1t.h>
63
64
static const ASN1_TEMPLATE TS_MSG_IMPRINT_seq_tt[] = {
65
	{
66
		.flags = 0,
67
		.tag = 0,
68
		.offset = offsetof(TS_MSG_IMPRINT, hash_algo),
69
		.field_name = "hash_algo",
70
		.item = &X509_ALGOR_it,
71
	},
72
	{
73
		.flags = 0,
74
		.tag = 0,
75
		.offset = offsetof(TS_MSG_IMPRINT, hashed_msg),
76
		.field_name = "hashed_msg",
77
		.item = &ASN1_OCTET_STRING_it,
78
	},
79
};
80
81
const ASN1_ITEM TS_MSG_IMPRINT_it = {
82
	.itype = ASN1_ITYPE_SEQUENCE,
83
	.utype = V_ASN1_SEQUENCE,
84
	.templates = TS_MSG_IMPRINT_seq_tt,
85
	.tcount = sizeof(TS_MSG_IMPRINT_seq_tt) / sizeof(ASN1_TEMPLATE),
86
	.funcs = NULL,
87
	.size = sizeof(TS_MSG_IMPRINT),
88
	.sname = "TS_MSG_IMPRINT",
89
};
90
91
92
TS_MSG_IMPRINT *
93
d2i_TS_MSG_IMPRINT(TS_MSG_IMPRINT **a, const unsigned char **in, long len)
94
{
95
	return (TS_MSG_IMPRINT *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
96
	    &TS_MSG_IMPRINT_it);
97
}
98
99
int
100
i2d_TS_MSG_IMPRINT(const TS_MSG_IMPRINT *a, unsigned char **out)
101
{
102
	return ASN1_item_i2d((ASN1_VALUE *)a, out, &TS_MSG_IMPRINT_it);
103
}
104
105
TS_MSG_IMPRINT *
106
TS_MSG_IMPRINT_new(void)
107
{
108
	return (TS_MSG_IMPRINT *)ASN1_item_new(&TS_MSG_IMPRINT_it);
109
}
110
111
void
112
TS_MSG_IMPRINT_free(TS_MSG_IMPRINT *a)
113
{
114
	ASN1_item_free((ASN1_VALUE *)a, &TS_MSG_IMPRINT_it);
115
}
116
117
TS_MSG_IMPRINT *
118
TS_MSG_IMPRINT_dup(TS_MSG_IMPRINT *x)
119
{
120
	return ASN1_item_dup(&TS_MSG_IMPRINT_it, x);
121
}
122
123
#ifndef OPENSSL_NO_BIO
124
TS_MSG_IMPRINT *
125
d2i_TS_MSG_IMPRINT_bio(BIO *bp, TS_MSG_IMPRINT **a)
126
{
127
	return ASN1_d2i_bio_of(TS_MSG_IMPRINT, TS_MSG_IMPRINT_new,
128
	    d2i_TS_MSG_IMPRINT, bp, a);
129
}
130
131
int
132
i2d_TS_MSG_IMPRINT_bio(BIO *bp, TS_MSG_IMPRINT *a)
133
{
134
	return ASN1_i2d_bio_of_const(TS_MSG_IMPRINT, i2d_TS_MSG_IMPRINT, bp, a);
135
}
136
#endif
137
138
TS_MSG_IMPRINT *
139
d2i_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT **a)
140
{
141
	return ASN1_d2i_fp_of(TS_MSG_IMPRINT, TS_MSG_IMPRINT_new,
142
	    d2i_TS_MSG_IMPRINT, fp, a);
143
}
144
145
int
146
i2d_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT *a)
147
{
148
	return ASN1_i2d_fp_of_const(TS_MSG_IMPRINT, i2d_TS_MSG_IMPRINT, fp, a);
149
}
150
151
static const ASN1_TEMPLATE TS_REQ_seq_tt[] = {
152
	{
153
		.flags = 0,
154
		.tag = 0,
155
		.offset = offsetof(TS_REQ, version),
156
		.field_name = "version",
157
		.item = &ASN1_INTEGER_it,
158
	},
159
	{
160
		.flags = 0,
161
		.tag = 0,
162
		.offset = offsetof(TS_REQ, msg_imprint),
163
		.field_name = "msg_imprint",
164
		.item = &TS_MSG_IMPRINT_it,
165
	},
166
	{
167
		.flags = ASN1_TFLG_OPTIONAL,
168
		.tag = 0,
169
		.offset = offsetof(TS_REQ, policy_id),
170
		.field_name = "policy_id",
171
		.item = &ASN1_OBJECT_it,
172
	},
173
	{
174
		.flags = ASN1_TFLG_OPTIONAL,
175
		.tag = 0,
176
		.offset = offsetof(TS_REQ, nonce),
177
		.field_name = "nonce",
178
		.item = &ASN1_INTEGER_it,
179
	},
180
	{
181
		.flags = ASN1_TFLG_OPTIONAL,
182
		.tag = 0,
183
		.offset = offsetof(TS_REQ, cert_req),
184
		.field_name = "cert_req",
185
		.item = &ASN1_FBOOLEAN_it,
186
	},
187
	{
188
		.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL,
189
		.tag = 0,
190
		.offset = offsetof(TS_REQ, extensions),
191
		.field_name = "extensions",
192
		.item = &X509_EXTENSION_it,
193
	},
194
};
195
196
const ASN1_ITEM TS_REQ_it = {
197
	.itype = ASN1_ITYPE_SEQUENCE,
198
	.utype = V_ASN1_SEQUENCE,
199
	.templates = TS_REQ_seq_tt,
200
	.tcount = sizeof(TS_REQ_seq_tt) / sizeof(ASN1_TEMPLATE),
201
	.funcs = NULL,
202
	.size = sizeof(TS_REQ),
203
	.sname = "TS_REQ",
204
};
205
206
207
TS_REQ *
208
d2i_TS_REQ(TS_REQ **a, const unsigned char **in, long len)
209
{
210
	return (TS_REQ *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
211
	    &TS_REQ_it);
212
}
213
214
int
215
i2d_TS_REQ(const TS_REQ *a, unsigned char **out)
216
{
217
	return ASN1_item_i2d((ASN1_VALUE *)a, out, &TS_REQ_it);
218
}
219
220
TS_REQ *
221
TS_REQ_new(void)
222
{
223
	return (TS_REQ *)ASN1_item_new(&TS_REQ_it);
224
}
225
226
void
227
TS_REQ_free(TS_REQ *a)
228
{
229
	ASN1_item_free((ASN1_VALUE *)a, &TS_REQ_it);
230
}
231
232
TS_REQ *
233
TS_REQ_dup(TS_REQ *x)
234
{
235
	return ASN1_item_dup(&TS_REQ_it, x);
236
}
237
238
#ifndef OPENSSL_NO_BIO
239
TS_REQ *
240
d2i_TS_REQ_bio(BIO *bp, TS_REQ **a)
241
{
242
	return ASN1_d2i_bio_of(TS_REQ, TS_REQ_new, d2i_TS_REQ, bp, a);
243
}
244
245
int
246
i2d_TS_REQ_bio(BIO *bp, TS_REQ *a)
247
{
248
	return ASN1_i2d_bio_of_const(TS_REQ, i2d_TS_REQ, bp, a);
249
}
250
#endif
251
252
TS_REQ *
253
d2i_TS_REQ_fp(FILE *fp, TS_REQ **a)
254
{
255
	return ASN1_d2i_fp_of(TS_REQ, TS_REQ_new, d2i_TS_REQ, fp, a);
256
}
257
258
int
259
i2d_TS_REQ_fp(FILE *fp, TS_REQ *a)
260
{
261
	return ASN1_i2d_fp_of_const(TS_REQ, i2d_TS_REQ, fp, a);
262
}
263
264
static const ASN1_TEMPLATE TS_ACCURACY_seq_tt[] = {
265
	{
266
		.flags = ASN1_TFLG_OPTIONAL,
267
		.tag = 0,
268
		.offset = offsetof(TS_ACCURACY, seconds),
269
		.field_name = "seconds",
270
		.item = &ASN1_INTEGER_it,
271
	},
272
	{
273
		.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_OPTIONAL,
274
		.tag = 0,
275
		.offset = offsetof(TS_ACCURACY, millis),
276
		.field_name = "millis",
277
		.item = &ASN1_INTEGER_it,
278
	},
279
	{
280
		.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_OPTIONAL,
281
		.tag = 1,
282
		.offset = offsetof(TS_ACCURACY, micros),
283
		.field_name = "micros",
284
		.item = &ASN1_INTEGER_it,
285
	},
286
};
287
288
const ASN1_ITEM TS_ACCURACY_it = {
289
	.itype = ASN1_ITYPE_SEQUENCE,
290
	.utype = V_ASN1_SEQUENCE,
291
	.templates = TS_ACCURACY_seq_tt,
292
	.tcount = sizeof(TS_ACCURACY_seq_tt) / sizeof(ASN1_TEMPLATE),
293
	.funcs = NULL,
294
	.size = sizeof(TS_ACCURACY),
295
	.sname = "TS_ACCURACY",
296
};
297
298
299
TS_ACCURACY *
300
d2i_TS_ACCURACY(TS_ACCURACY **a, const unsigned char **in, long len)
301
{
302
	return (TS_ACCURACY *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
303
	    &TS_ACCURACY_it);
304
}
305
306
int
307
i2d_TS_ACCURACY(const TS_ACCURACY *a, unsigned char **out)
308
{
309
	return ASN1_item_i2d((ASN1_VALUE *)a, out, &TS_ACCURACY_it);
310
}
311
312
TS_ACCURACY *
313
TS_ACCURACY_new(void)
314
{
315
	return (TS_ACCURACY *)ASN1_item_new(&TS_ACCURACY_it);
316
}
317
318
void
319
TS_ACCURACY_free(TS_ACCURACY *a)
320
{
321
	ASN1_item_free((ASN1_VALUE *)a, &TS_ACCURACY_it);
322
}
323
324
TS_ACCURACY *
325
TS_ACCURACY_dup(TS_ACCURACY *x)
326
{
327
	return ASN1_item_dup(&TS_ACCURACY_it, x);
328
}
329
330
static const ASN1_TEMPLATE TS_TST_INFO_seq_tt[] = {
331
	{
332
		.flags = 0,
333
		.tag = 0,
334
		.offset = offsetof(TS_TST_INFO, version),
335
		.field_name = "version",
336
		.item = &ASN1_INTEGER_it,
337
	},
338
	{
339
		.flags = 0,
340
		.tag = 0,
341
		.offset = offsetof(TS_TST_INFO, policy_id),
342
		.field_name = "policy_id",
343
		.item = &ASN1_OBJECT_it,
344
	},
345
	{
346
		.flags = 0,
347
		.tag = 0,
348
		.offset = offsetof(TS_TST_INFO, msg_imprint),
349
		.field_name = "msg_imprint",
350
		.item = &TS_MSG_IMPRINT_it,
351
	},
352
	{
353
		.flags = 0,
354
		.tag = 0,
355
		.offset = offsetof(TS_TST_INFO, serial),
356
		.field_name = "serial",
357
		.item = &ASN1_INTEGER_it,
358
	},
359
	{
360
		.flags = 0,
361
		.tag = 0,
362
		.offset = offsetof(TS_TST_INFO, time),
363
		.field_name = "time",
364
		.item = &ASN1_GENERALIZEDTIME_it,
365
	},
366
	{
367
		.flags = ASN1_TFLG_OPTIONAL,
368
		.tag = 0,
369
		.offset = offsetof(TS_TST_INFO, accuracy),
370
		.field_name = "accuracy",
371
		.item = &TS_ACCURACY_it,
372
	},
373
	{
374
		.flags = ASN1_TFLG_OPTIONAL,
375
		.tag = 0,
376
		.offset = offsetof(TS_TST_INFO, ordering),
377
		.field_name = "ordering",
378
		.item = &ASN1_FBOOLEAN_it,
379
	},
380
	{
381
		.flags = ASN1_TFLG_OPTIONAL,
382
		.tag = 0,
383
		.offset = offsetof(TS_TST_INFO, nonce),
384
		.field_name = "nonce",
385
		.item = &ASN1_INTEGER_it,
386
	},
387
	{
388
		.flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_OPTIONAL,
389
		.tag = 0,
390
		.offset = offsetof(TS_TST_INFO, tsa),
391
		.field_name = "tsa",
392
		.item = &GENERAL_NAME_it,
393
	},
394
	{
395
		.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL,
396
		.tag = 1,
397
		.offset = offsetof(TS_TST_INFO, extensions),
398
		.field_name = "extensions",
399
		.item = &X509_EXTENSION_it,
400
	},
401
};
402
403
const ASN1_ITEM TS_TST_INFO_it = {
404
	.itype = ASN1_ITYPE_SEQUENCE,
405
	.utype = V_ASN1_SEQUENCE,
406
	.templates = TS_TST_INFO_seq_tt,
407
	.tcount = sizeof(TS_TST_INFO_seq_tt) / sizeof(ASN1_TEMPLATE),
408
	.funcs = NULL,
409
	.size = sizeof(TS_TST_INFO),
410
	.sname = "TS_TST_INFO",
411
};
412
413
414
TS_TST_INFO *
415
d2i_TS_TST_INFO(TS_TST_INFO **a, const unsigned char **in, long len)
416
{
417
	return (TS_TST_INFO *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
418
	    &TS_TST_INFO_it);
419
}
420
421
int
422
i2d_TS_TST_INFO(const TS_TST_INFO *a, unsigned char **out)
423
{
424
	return ASN1_item_i2d((ASN1_VALUE *)a, out, &TS_TST_INFO_it);
425
}
426
427
TS_TST_INFO *
428
TS_TST_INFO_new(void)
429
{
430
	return (TS_TST_INFO *)ASN1_item_new(&TS_TST_INFO_it);
431
}
432
433
void
434
TS_TST_INFO_free(TS_TST_INFO *a)
435
{
436
	ASN1_item_free((ASN1_VALUE *)a, &TS_TST_INFO_it);
437
}
438
439
TS_TST_INFO *
440
TS_TST_INFO_dup(TS_TST_INFO *x)
441
{
442
	return ASN1_item_dup(&TS_TST_INFO_it, x);
443
}
444
445
#ifndef OPENSSL_NO_BIO
446
TS_TST_INFO *
447
d2i_TS_TST_INFO_bio(BIO *bp, TS_TST_INFO **a)
448
{
449
	return ASN1_d2i_bio_of(TS_TST_INFO, TS_TST_INFO_new, d2i_TS_TST_INFO,
450
	    bp, a);
451
}
452
453
int
454
i2d_TS_TST_INFO_bio(BIO *bp, TS_TST_INFO *a)
455
{
456
	return ASN1_i2d_bio_of_const(TS_TST_INFO, i2d_TS_TST_INFO, bp, a);
457
}
458
#endif
459
460
TS_TST_INFO *
461
d2i_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO **a)
462
{
463
	return ASN1_d2i_fp_of(TS_TST_INFO, TS_TST_INFO_new, d2i_TS_TST_INFO,
464
	    fp, a);
465
}
466
467
int
468
i2d_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO *a)
469
{
470
	return ASN1_i2d_fp_of_const(TS_TST_INFO, i2d_TS_TST_INFO, fp, a);
471
}
472
473
static const ASN1_TEMPLATE TS_STATUS_INFO_seq_tt[] = {
474
	{
475
		.flags = 0,
476
		.tag = 0,
477
		.offset = offsetof(TS_STATUS_INFO, status),
478
		.field_name = "status",
479
		.item = &ASN1_INTEGER_it,
480
	},
481
	{
482
		.flags = ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL,
483
		.tag = 0,
484
		.offset = offsetof(TS_STATUS_INFO, text),
485
		.field_name = "text",
486
		.item = &ASN1_UTF8STRING_it,
487
	},
488
	{
489
		.flags = ASN1_TFLG_OPTIONAL,
490
		.tag = 0,
491
		.offset = offsetof(TS_STATUS_INFO, failure_info),
492
		.field_name = "failure_info",
493
		.item = &ASN1_BIT_STRING_it,
494
	},
495
};
496
497
const ASN1_ITEM TS_STATUS_INFO_it = {
498
	.itype = ASN1_ITYPE_SEQUENCE,
499
	.utype = V_ASN1_SEQUENCE,
500
	.templates = TS_STATUS_INFO_seq_tt,
501
	.tcount = sizeof(TS_STATUS_INFO_seq_tt) / sizeof(ASN1_TEMPLATE),
502
	.funcs = NULL,
503
	.size = sizeof(TS_STATUS_INFO),
504
	.sname = "TS_STATUS_INFO",
505
};
506
507
508
TS_STATUS_INFO *
509
d2i_TS_STATUS_INFO(TS_STATUS_INFO **a, const unsigned char **in, long len)
510
{
511
	return (TS_STATUS_INFO *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
512
	    &TS_STATUS_INFO_it);
513
}
514
515
int
516
i2d_TS_STATUS_INFO(const TS_STATUS_INFO *a, unsigned char **out)
517
{
518
	return ASN1_item_i2d((ASN1_VALUE *)a, out, &TS_STATUS_INFO_it);
519
}
520
521
TS_STATUS_INFO *
522
TS_STATUS_INFO_new(void)
523
{
524
	return (TS_STATUS_INFO *)ASN1_item_new(&TS_STATUS_INFO_it);
525
}
526
527
void
528
TS_STATUS_INFO_free(TS_STATUS_INFO *a)
529
{
530
	ASN1_item_free((ASN1_VALUE *)a, &TS_STATUS_INFO_it);
531
}
532
533
TS_STATUS_INFO *
534
TS_STATUS_INFO_dup(TS_STATUS_INFO *x)
535
{
536
	return ASN1_item_dup(&TS_STATUS_INFO_it, x);
537
}
538
539
static int
540
ts_resp_set_tst_info(TS_RESP *a)
541
{
542
	long    status;
543
544
	status = ASN1_INTEGER_get(a->status_info->status);
545
546
	if (a->token) {
547
		if (status != 0 && status != 1) {
548
			TSerr(TS_F_TS_RESP_SET_TST_INFO, TS_R_TOKEN_PRESENT);
549
			return 0;
550
		}
551
		if (a->tst_info != NULL)
552
			TS_TST_INFO_free(a->tst_info);
553
		a->tst_info = PKCS7_to_TS_TST_INFO(a->token);
554
		if (!a->tst_info) {
555
			TSerr(TS_F_TS_RESP_SET_TST_INFO,
556
			    TS_R_PKCS7_TO_TS_TST_INFO_FAILED);
557
			return 0;
558
		}
559
	} else if (status == 0 || status == 1) {
560
		TSerr(TS_F_TS_RESP_SET_TST_INFO, TS_R_TOKEN_NOT_PRESENT);
561
		return 0;
562
	}
563
564
	return 1;
565
}
566
567
static int
568
ts_resp_cb(int op, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
569
{
570
	TS_RESP *ts_resp = (TS_RESP *)*pval;
571
572
	if (op == ASN1_OP_NEW_POST) {
573
		ts_resp->tst_info = NULL;
574
	} else if (op == ASN1_OP_FREE_POST) {
575
		if (ts_resp->tst_info != NULL)
576
			TS_TST_INFO_free(ts_resp->tst_info);
577
	} else if (op == ASN1_OP_D2I_POST) {
578
		if (ts_resp_set_tst_info(ts_resp) == 0)
579
			return 0;
580
	}
581
	return 1;
582
}
583
584
static const ASN1_AUX TS_RESP_aux = {
585
	.app_data = NULL,
586
	.flags = 0,
587
	.ref_offset = 0,
588
	.ref_lock = 0,
589
	.asn1_cb = ts_resp_cb,
590
	.enc_offset = 0,
591
};
592
static const ASN1_TEMPLATE TS_RESP_seq_tt[] = {
593
	{
594
		.flags = 0,
595
		.tag = 0,
596
		.offset = offsetof(TS_RESP, status_info),
597
		.field_name = "status_info",
598
		.item = &TS_STATUS_INFO_it,
599
	},
600
	{
601
		.flags = ASN1_TFLG_OPTIONAL,
602
		.tag = 0,
603
		.offset = offsetof(TS_RESP, token),
604
		.field_name = "token",
605
		.item = &PKCS7_it,
606
	},
607
};
608
609
const ASN1_ITEM TS_RESP_it = {
610
	.itype = ASN1_ITYPE_SEQUENCE,
611
	.utype = V_ASN1_SEQUENCE,
612
	.templates = TS_RESP_seq_tt,
613
	.tcount = sizeof(TS_RESP_seq_tt) / sizeof(ASN1_TEMPLATE),
614
	.funcs = &TS_RESP_aux,
615
	.size = sizeof(TS_RESP),
616
	.sname = "TS_RESP",
617
};
618
619
620
TS_RESP *
621
d2i_TS_RESP(TS_RESP **a, const unsigned char **in, long len)
622
{
623
	return (TS_RESP *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
624
	    &TS_RESP_it);
625
}
626
627
int
628
i2d_TS_RESP(const TS_RESP *a, unsigned char **out)
629
{
630
	return ASN1_item_i2d((ASN1_VALUE *)a, out, &TS_RESP_it);
631
}
632
633
TS_RESP *
634
TS_RESP_new(void)
635
{
636
	return (TS_RESP *)ASN1_item_new(&TS_RESP_it);
637
}
638
639
void
640
TS_RESP_free(TS_RESP *a)
641
{
642
	ASN1_item_free((ASN1_VALUE *)a, &TS_RESP_it);
643
}
644
645
TS_RESP *
646
TS_RESP_dup(TS_RESP *x)
647
{
648
	return ASN1_item_dup(&TS_RESP_it, x);
649
}
650
651
#ifndef OPENSSL_NO_BIO
652
TS_RESP *
653
d2i_TS_RESP_bio(BIO *bp, TS_RESP **a)
654
{
655
	return ASN1_d2i_bio_of(TS_RESP, TS_RESP_new, d2i_TS_RESP, bp, a);
656
}
657
658
int
659
i2d_TS_RESP_bio(BIO *bp, TS_RESP *a)
660
{
661
	return ASN1_i2d_bio_of_const(TS_RESP, i2d_TS_RESP, bp, a);
662
}
663
#endif
664
665
TS_RESP *
666
d2i_TS_RESP_fp(FILE *fp, TS_RESP **a)
667
{
668
	return ASN1_d2i_fp_of(TS_RESP, TS_RESP_new, d2i_TS_RESP, fp, a);
669
}
670
671
int
672
i2d_TS_RESP_fp(FILE *fp, TS_RESP *a)
673
{
674
	return ASN1_i2d_fp_of_const(TS_RESP, i2d_TS_RESP, fp, a);
675
}
676
677
static const ASN1_TEMPLATE ESS_ISSUER_SERIAL_seq_tt[] = {
678
	{
679
		.flags = ASN1_TFLG_SEQUENCE_OF,
680
		.tag = 0,
681
		.offset = offsetof(ESS_ISSUER_SERIAL, issuer),
682
		.field_name = "issuer",
683
		.item = &GENERAL_NAME_it,
684
	},
685
	{
686
		.flags = 0,
687
		.tag = 0,
688
		.offset = offsetof(ESS_ISSUER_SERIAL, serial),
689
		.field_name = "serial",
690
		.item = &ASN1_INTEGER_it,
691
	},
692
};
693
694
const ASN1_ITEM ESS_ISSUER_SERIAL_it = {
695
	.itype = ASN1_ITYPE_SEQUENCE,
696
	.utype = V_ASN1_SEQUENCE,
697
	.templates = ESS_ISSUER_SERIAL_seq_tt,
698
	.tcount = sizeof(ESS_ISSUER_SERIAL_seq_tt) / sizeof(ASN1_TEMPLATE),
699
	.funcs = NULL,
700
	.size = sizeof(ESS_ISSUER_SERIAL),
701
	.sname = "ESS_ISSUER_SERIAL",
702
};
703
704
705
ESS_ISSUER_SERIAL *
706
d2i_ESS_ISSUER_SERIAL(ESS_ISSUER_SERIAL **a, const unsigned char **in, long len)
707
{
708
	return (ESS_ISSUER_SERIAL *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
709
	    &ESS_ISSUER_SERIAL_it);
710
}
711
712
int
713
i2d_ESS_ISSUER_SERIAL(const ESS_ISSUER_SERIAL *a, unsigned char **out)
714
{
715
	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ESS_ISSUER_SERIAL_it);
716
}
717
718
ESS_ISSUER_SERIAL *
719
ESS_ISSUER_SERIAL_new(void)
720
{
721
	return (ESS_ISSUER_SERIAL *)ASN1_item_new(&ESS_ISSUER_SERIAL_it);
722
}
723
724
void
725
ESS_ISSUER_SERIAL_free(ESS_ISSUER_SERIAL *a)
726
{
727
	ASN1_item_free((ASN1_VALUE *)a, &ESS_ISSUER_SERIAL_it);
728
}
729
730
ESS_ISSUER_SERIAL *
731
ESS_ISSUER_SERIAL_dup(ESS_ISSUER_SERIAL *x)
732
{
733
	return ASN1_item_dup(&ESS_ISSUER_SERIAL_it, x);
734
}
735
736
static const ASN1_TEMPLATE ESS_CERT_ID_seq_tt[] = {
737
	{
738
		.flags = 0,
739
		.tag = 0,
740
		.offset = offsetof(ESS_CERT_ID, hash),
741
		.field_name = "hash",
742
		.item = &ASN1_OCTET_STRING_it,
743
	},
744
	{
745
		.flags = ASN1_TFLG_OPTIONAL,
746
		.tag = 0,
747
		.offset = offsetof(ESS_CERT_ID, issuer_serial),
748
		.field_name = "issuer_serial",
749
		.item = &ESS_ISSUER_SERIAL_it,
750
	},
751
};
752
753
const ASN1_ITEM ESS_CERT_ID_it = {
754
	.itype = ASN1_ITYPE_SEQUENCE,
755
	.utype = V_ASN1_SEQUENCE,
756
	.templates = ESS_CERT_ID_seq_tt,
757
	.tcount = sizeof(ESS_CERT_ID_seq_tt) / sizeof(ASN1_TEMPLATE),
758
	.funcs = NULL,
759
	.size = sizeof(ESS_CERT_ID),
760
	.sname = "ESS_CERT_ID",
761
};
762
763
764
ESS_CERT_ID *
765
d2i_ESS_CERT_ID(ESS_CERT_ID **a, const unsigned char **in, long len)
766
{
767
	return (ESS_CERT_ID *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
768
	    &ESS_CERT_ID_it);
769
}
770
771
int
772
i2d_ESS_CERT_ID(const ESS_CERT_ID *a, unsigned char **out)
773
{
774
	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ESS_CERT_ID_it);
775
}
776
777
ESS_CERT_ID *
778
ESS_CERT_ID_new(void)
779
{
780
	return (ESS_CERT_ID *)ASN1_item_new(&ESS_CERT_ID_it);
781
}
782
783
void
784
ESS_CERT_ID_free(ESS_CERT_ID *a)
785
{
786
	ASN1_item_free((ASN1_VALUE *)a, &ESS_CERT_ID_it);
787
}
788
789
ESS_CERT_ID *
790
ESS_CERT_ID_dup(ESS_CERT_ID *x)
791
{
792
	return ASN1_item_dup(&ESS_CERT_ID_it, x);
793
}
794
795
static const ASN1_TEMPLATE ESS_SIGNING_CERT_seq_tt[] = {
796
	{
797
		.flags = ASN1_TFLG_SEQUENCE_OF,
798
		.tag = 0,
799
		.offset = offsetof(ESS_SIGNING_CERT, cert_ids),
800
		.field_name = "cert_ids",
801
		.item = &ESS_CERT_ID_it,
802
	},
803
	{
804
		.flags = ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL,
805
		.tag = 0,
806
		.offset = offsetof(ESS_SIGNING_CERT, policy_info),
807
		.field_name = "policy_info",
808
		.item = &POLICYINFO_it,
809
	},
810
};
811
812
const ASN1_ITEM ESS_SIGNING_CERT_it = {
813
	.itype = ASN1_ITYPE_SEQUENCE,
814
	.utype = V_ASN1_SEQUENCE,
815
	.templates = ESS_SIGNING_CERT_seq_tt,
816
	.tcount = sizeof(ESS_SIGNING_CERT_seq_tt) / sizeof(ASN1_TEMPLATE),
817
	.funcs = NULL,
818
	.size = sizeof(ESS_SIGNING_CERT),
819
	.sname = "ESS_SIGNING_CERT",
820
};
821
822
823
ESS_SIGNING_CERT *
824
d2i_ESS_SIGNING_CERT(ESS_SIGNING_CERT **a, const unsigned char **in, long len)
825
{
826
	return (ESS_SIGNING_CERT *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
827
	    &ESS_SIGNING_CERT_it);
828
}
829
830
int
831
i2d_ESS_SIGNING_CERT(const ESS_SIGNING_CERT *a, unsigned char **out)
832
{
833
	return ASN1_item_i2d((ASN1_VALUE *)a, out, &ESS_SIGNING_CERT_it);
834
}
835
836
ESS_SIGNING_CERT *
837
ESS_SIGNING_CERT_new(void)
838
{
839
	return (ESS_SIGNING_CERT *)ASN1_item_new(&ESS_SIGNING_CERT_it);
840
}
841
842
void
843
ESS_SIGNING_CERT_free(ESS_SIGNING_CERT *a)
844
{
845
	ASN1_item_free((ASN1_VALUE *)a, &ESS_SIGNING_CERT_it);
846
}
847
848
ESS_SIGNING_CERT *
849
ESS_SIGNING_CERT_dup(ESS_SIGNING_CERT *x)
850
{
851
	return ASN1_item_dup(&ESS_SIGNING_CERT_it, x);
852
}
853
854
/* Getting encapsulated TS_TST_INFO object from PKCS7. */
855
TS_TST_INFO *
856
PKCS7_to_TS_TST_INFO(PKCS7 *token)
857
{
858
	PKCS7_SIGNED *pkcs7_signed;
859
	PKCS7 *enveloped;
860
	ASN1_TYPE *tst_info_wrapper;
861
	ASN1_OCTET_STRING *tst_info_der;
862
	const unsigned char *p;
863
864
	if (!PKCS7_type_is_signed(token)) {
865
		TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_PKCS7_TYPE);
866
		return NULL;
867
	}
868
869
	/* Content must be present. */
870
	if (PKCS7_get_detached(token)) {
871
		TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_DETACHED_CONTENT);
872
		return NULL;
873
	}
874
875
	/* We have a signed data with content. */
876
	pkcs7_signed = token->d.sign;
877
	enveloped = pkcs7_signed->contents;
878
	if (OBJ_obj2nid(enveloped->type) != NID_id_smime_ct_TSTInfo) {
879
		TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_PKCS7_TYPE);
880
		return NULL;
881
	}
882
883
	/* We have a DER encoded TST_INFO as the signed data. */
884
	tst_info_wrapper = enveloped->d.other;
885
	if (tst_info_wrapper->type != V_ASN1_OCTET_STRING) {
886
		TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_TYPE);
887
		return NULL;
888
	}
889
890
	/* We have the correct ASN1_OCTET_STRING type. */
891
	tst_info_der = tst_info_wrapper->value.octet_string;
892
	/* At last, decode the TST_INFO. */
893
	p = tst_info_der->data;
894
	return d2i_TS_TST_INFO(NULL, &p, tst_info_der->length);
895
}