summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ts/ts_asn1.c
diff options
context:
space:
mode:
authorjsing <>2014-04-21 16:32:06 +0000
committerjsing <>2014-04-21 16:32:06 +0000
commitdbe50a7f3c84521e4543ad2e5292244bd0b81414 (patch)
treebe04a70e8733f1afb3ae549ad26c1c50ec666f15 /src/lib/libcrypto/ts/ts_asn1.c
parent4e74c38c506a70910cb7f88175f2f718983bbdc6 (diff)
downloadopenbsd-dbe50a7f3c84521e4543ad2e5292244bd0b81414.tar.gz
openbsd-dbe50a7f3c84521e4543ad2e5292244bd0b81414.tar.bz2
openbsd-dbe50a7f3c84521e4543ad2e5292244bd0b81414.zip
KNF.
Diffstat (limited to 'src/lib/libcrypto/ts/ts_asn1.c')
-rw-r--r--src/lib/libcrypto/ts/ts_asn1.c164
1 files changed, 96 insertions, 68 deletions
diff --git a/src/lib/libcrypto/ts/ts_asn1.c b/src/lib/libcrypto/ts/ts_asn1.c
index 40b730c5e2..9e16b01f93 100644
--- a/src/lib/libcrypto/ts/ts_asn1.c
+++ b/src/lib/libcrypto/ts/ts_asn1.c
@@ -9,7 +9,7 @@
9 * are met: 9 * are met:
10 * 10 *
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 13 *
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in 15 * notice, this list of conditions and the following disclaimer in
@@ -66,27 +66,35 @@ ASN1_SEQUENCE(TS_MSG_IMPRINT) = {
66 66
67IMPLEMENT_ASN1_FUNCTIONS_const(TS_MSG_IMPRINT) 67IMPLEMENT_ASN1_FUNCTIONS_const(TS_MSG_IMPRINT)
68IMPLEMENT_ASN1_DUP_FUNCTION(TS_MSG_IMPRINT) 68IMPLEMENT_ASN1_DUP_FUNCTION(TS_MSG_IMPRINT)
69
69#ifndef OPENSSL_NO_BIO 70#ifndef OPENSSL_NO_BIO
70TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT_bio(BIO *bp, TS_MSG_IMPRINT **a) 71TS_MSG_IMPRINT *
71 { 72d2i_TS_MSG_IMPRINT_bio(BIO *bp, TS_MSG_IMPRINT **a)
72 return ASN1_d2i_bio_of(TS_MSG_IMPRINT, TS_MSG_IMPRINT_new, d2i_TS_MSG_IMPRINT, bp, a); 73{
73 } 74 return ASN1_d2i_bio_of(TS_MSG_IMPRINT, TS_MSG_IMPRINT_new,
75 d2i_TS_MSG_IMPRINT, bp, a);
76}
74 77
75int i2d_TS_MSG_IMPRINT_bio(BIO *bp, TS_MSG_IMPRINT *a) 78int
79i2d_TS_MSG_IMPRINT_bio(BIO *bp, TS_MSG_IMPRINT *a)
76{ 80{
77 return ASN1_i2d_bio_of_const(TS_MSG_IMPRINT, i2d_TS_MSG_IMPRINT, bp, a); 81 return ASN1_i2d_bio_of_const(TS_MSG_IMPRINT, i2d_TS_MSG_IMPRINT, bp, a);
78} 82}
79#endif 83#endif
84
80#ifndef OPENSSL_NO_FP_API 85#ifndef OPENSSL_NO_FP_API
81TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT **a) 86TS_MSG_IMPRINT *
82 { 87d2i_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT **a)
83 return ASN1_d2i_fp_of(TS_MSG_IMPRINT, TS_MSG_IMPRINT_new, d2i_TS_MSG_IMPRINT, fp, a); 88{
84 } 89 return ASN1_d2i_fp_of(TS_MSG_IMPRINT, TS_MSG_IMPRINT_new,
90 d2i_TS_MSG_IMPRINT, fp, a);
91}
85 92
86int i2d_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT *a) 93int
87 { 94i2d_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT *a)
95{
88 return ASN1_i2d_fp_of_const(TS_MSG_IMPRINT, i2d_TS_MSG_IMPRINT, fp, a); 96 return ASN1_i2d_fp_of_const(TS_MSG_IMPRINT, i2d_TS_MSG_IMPRINT, fp, a);
89 } 97}
90#endif 98#endif
91 99
92ASN1_SEQUENCE(TS_REQ) = { 100ASN1_SEQUENCE(TS_REQ) = {
@@ -100,27 +108,33 @@ ASN1_SEQUENCE(TS_REQ) = {
100 108
101IMPLEMENT_ASN1_FUNCTIONS_const(TS_REQ) 109IMPLEMENT_ASN1_FUNCTIONS_const(TS_REQ)
102IMPLEMENT_ASN1_DUP_FUNCTION(TS_REQ) 110IMPLEMENT_ASN1_DUP_FUNCTION(TS_REQ)
111
103#ifndef OPENSSL_NO_BIO 112#ifndef OPENSSL_NO_BIO
104TS_REQ *d2i_TS_REQ_bio(BIO *bp, TS_REQ **a) 113TS_REQ *
105 { 114d2i_TS_REQ_bio(BIO *bp, TS_REQ **a)
115{
106 return ASN1_d2i_bio_of(TS_REQ, TS_REQ_new, d2i_TS_REQ, bp, a); 116 return ASN1_d2i_bio_of(TS_REQ, TS_REQ_new, d2i_TS_REQ, bp, a);
107 } 117}
108 118
109int i2d_TS_REQ_bio(BIO *bp, TS_REQ *a) 119int
110 { 120i2d_TS_REQ_bio(BIO *bp, TS_REQ *a)
121{
111 return ASN1_i2d_bio_of_const(TS_REQ, i2d_TS_REQ, bp, a); 122 return ASN1_i2d_bio_of_const(TS_REQ, i2d_TS_REQ, bp, a);
112 } 123}
113#endif 124#endif
125
114#ifndef OPENSSL_NO_FP_API 126#ifndef OPENSSL_NO_FP_API
115TS_REQ *d2i_TS_REQ_fp(FILE *fp, TS_REQ **a) 127TS_REQ *
116 { 128d2i_TS_REQ_fp(FILE *fp, TS_REQ **a)
129{
117 return ASN1_d2i_fp_of(TS_REQ, TS_REQ_new, d2i_TS_REQ, fp, a); 130 return ASN1_d2i_fp_of(TS_REQ, TS_REQ_new, d2i_TS_REQ, fp, a);
118 } 131}
119 132
120int i2d_TS_REQ_fp(FILE *fp, TS_REQ *a) 133int
121 { 134i2d_TS_REQ_fp(FILE *fp, TS_REQ *a)
135{
122 return ASN1_i2d_fp_of_const(TS_REQ, i2d_TS_REQ, fp, a); 136 return ASN1_i2d_fp_of_const(TS_REQ, i2d_TS_REQ, fp, a);
123 } 137}
124#endif 138#endif
125 139
126ASN1_SEQUENCE(TS_ACCURACY) = { 140ASN1_SEQUENCE(TS_ACCURACY) = {
@@ -147,27 +161,35 @@ ASN1_SEQUENCE(TS_TST_INFO) = {
147 161
148IMPLEMENT_ASN1_FUNCTIONS_const(TS_TST_INFO) 162IMPLEMENT_ASN1_FUNCTIONS_const(TS_TST_INFO)
149IMPLEMENT_ASN1_DUP_FUNCTION(TS_TST_INFO) 163IMPLEMENT_ASN1_DUP_FUNCTION(TS_TST_INFO)
164
150#ifndef OPENSSL_NO_BIO 165#ifndef OPENSSL_NO_BIO
151TS_TST_INFO *d2i_TS_TST_INFO_bio(BIO *bp, TS_TST_INFO **a) 166TS_TST_INFO *
152 { 167d2i_TS_TST_INFO_bio(BIO *bp, TS_TST_INFO **a)
153 return ASN1_d2i_bio_of(TS_TST_INFO, TS_TST_INFO_new, d2i_TS_TST_INFO, bp, a); 168{
154 } 169 return ASN1_d2i_bio_of(TS_TST_INFO, TS_TST_INFO_new, d2i_TS_TST_INFO,
170 bp, a);
171}
155 172
156int i2d_TS_TST_INFO_bio(BIO *bp, TS_TST_INFO *a) 173int
157 { 174i2d_TS_TST_INFO_bio(BIO *bp, TS_TST_INFO *a)
175{
158 return ASN1_i2d_bio_of_const(TS_TST_INFO, i2d_TS_TST_INFO, bp, a); 176 return ASN1_i2d_bio_of_const(TS_TST_INFO, i2d_TS_TST_INFO, bp, a);
159 } 177}
160#endif 178#endif
179
161#ifndef OPENSSL_NO_FP_API 180#ifndef OPENSSL_NO_FP_API
162TS_TST_INFO *d2i_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO **a) 181TS_TST_INFO *
163 { 182d2i_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO **a)
164 return ASN1_d2i_fp_of(TS_TST_INFO, TS_TST_INFO_new, d2i_TS_TST_INFO, fp, a); 183{
165 } 184 return ASN1_d2i_fp_of(TS_TST_INFO, TS_TST_INFO_new, d2i_TS_TST_INFO,
185 fp, a);
186}
166 187
167int i2d_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO *a) 188int
168 { 189i2d_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO *a)
190{
169 return ASN1_i2d_fp_of_const(TS_TST_INFO, i2d_TS_TST_INFO, fp, a); 191 return ASN1_i2d_fp_of_const(TS_TST_INFO, i2d_TS_TST_INFO, fp, a);
170 } 192}
171#endif 193#endif
172 194
173ASN1_SEQUENCE(TS_STATUS_INFO) = { 195ASN1_SEQUENCE(TS_STATUS_INFO) = {
@@ -179,7 +201,8 @@ ASN1_SEQUENCE(TS_STATUS_INFO) = {
179IMPLEMENT_ASN1_FUNCTIONS_const(TS_STATUS_INFO) 201IMPLEMENT_ASN1_FUNCTIONS_const(TS_STATUS_INFO)
180IMPLEMENT_ASN1_DUP_FUNCTION(TS_STATUS_INFO) 202IMPLEMENT_ASN1_DUP_FUNCTION(TS_STATUS_INFO)
181 203
182static int ts_resp_set_tst_info(TS_RESP *a) 204static int
205ts_resp_set_tst_info(TS_RESP *a)
183{ 206{
184 long status; 207 long status;
185 208
@@ -194,7 +217,8 @@ static int ts_resp_set_tst_info(TS_RESP *a)
194 TS_TST_INFO_free(a->tst_info); 217 TS_TST_INFO_free(a->tst_info);
195 a->tst_info = PKCS7_to_TS_TST_INFO(a->token); 218 a->tst_info = PKCS7_to_TS_TST_INFO(a->token);
196 if (!a->tst_info) { 219 if (!a->tst_info) {
197 TSerr(TS_F_TS_RESP_SET_TST_INFO, TS_R_PKCS7_TO_TS_TST_INFO_FAILED); 220 TSerr(TS_F_TS_RESP_SET_TST_INFO,
221 TS_R_PKCS7_TO_TS_TST_INFO_FAILED);
198 return 0; 222 return 0;
199 } 223 }
200 } else if (status == 0 || status == 1) { 224 } else if (status == 0 || status == 1) {
@@ -205,10 +229,11 @@ static int ts_resp_set_tst_info(TS_RESP *a)
205 return 1; 229 return 1;
206} 230}
207 231
208static int ts_resp_cb(int op, ASN1_VALUE **pval, const ASN1_ITEM *it, 232static int
209 void *exarg) 233ts_resp_cb(int op, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
210{ 234{
211 TS_RESP *ts_resp = (TS_RESP *)*pval; 235 TS_RESP *ts_resp = (TS_RESP *)*pval;
236
212 if (op == ASN1_OP_NEW_POST) { 237 if (op == ASN1_OP_NEW_POST) {
213 ts_resp->tst_info = NULL; 238 ts_resp->tst_info = NULL;
214 } else if (op == ASN1_OP_FREE_POST) { 239 } else if (op == ASN1_OP_FREE_POST) {
@@ -228,27 +253,33 @@ ASN1_SEQUENCE_cb(TS_RESP, ts_resp_cb) = {
228 253
229IMPLEMENT_ASN1_FUNCTIONS_const(TS_RESP) 254IMPLEMENT_ASN1_FUNCTIONS_const(TS_RESP)
230IMPLEMENT_ASN1_DUP_FUNCTION(TS_RESP) 255IMPLEMENT_ASN1_DUP_FUNCTION(TS_RESP)
256
231#ifndef OPENSSL_NO_BIO 257#ifndef OPENSSL_NO_BIO
232TS_RESP *d2i_TS_RESP_bio(BIO *bp, TS_RESP **a) 258TS_RESP *
233 { 259d2i_TS_RESP_bio(BIO *bp, TS_RESP **a)
260{
234 return ASN1_d2i_bio_of(TS_RESP, TS_RESP_new, d2i_TS_RESP, bp, a); 261 return ASN1_d2i_bio_of(TS_RESP, TS_RESP_new, d2i_TS_RESP, bp, a);
235 } 262}
236 263
237int i2d_TS_RESP_bio(BIO *bp, TS_RESP *a) 264int
238 { 265i2d_TS_RESP_bio(BIO *bp, TS_RESP *a)
266{
239 return ASN1_i2d_bio_of_const(TS_RESP, i2d_TS_RESP, bp, a); 267 return ASN1_i2d_bio_of_const(TS_RESP, i2d_TS_RESP, bp, a);
240 } 268}
241#endif 269#endif
270
242#ifndef OPENSSL_NO_FP_API 271#ifndef OPENSSL_NO_FP_API
243TS_RESP *d2i_TS_RESP_fp(FILE *fp, TS_RESP **a) 272TS_RESP *
244 { 273d2i_TS_RESP_fp(FILE *fp, TS_RESP **a)
274{
245 return ASN1_d2i_fp_of(TS_RESP, TS_RESP_new, d2i_TS_RESP, fp, a); 275 return ASN1_d2i_fp_of(TS_RESP, TS_RESP_new, d2i_TS_RESP, fp, a);
246 } 276}
247 277
248int i2d_TS_RESP_fp(FILE *fp, TS_RESP *a) 278int
249 { 279i2d_TS_RESP_fp(FILE *fp, TS_RESP *a)
280{
250 return ASN1_i2d_fp_of_const(TS_RESP, i2d_TS_RESP, fp, a); 281 return ASN1_i2d_fp_of_const(TS_RESP, i2d_TS_RESP, fp, a);
251 } 282}
252#endif 283#endif
253 284
254ASN1_SEQUENCE(ESS_ISSUER_SERIAL) = { 285ASN1_SEQUENCE(ESS_ISSUER_SERIAL) = {
@@ -276,7 +307,8 @@ IMPLEMENT_ASN1_FUNCTIONS_const(ESS_SIGNING_CERT)
276IMPLEMENT_ASN1_DUP_FUNCTION(ESS_SIGNING_CERT) 307IMPLEMENT_ASN1_DUP_FUNCTION(ESS_SIGNING_CERT)
277 308
278/* Getting encapsulated TS_TST_INFO object from PKCS7. */ 309/* Getting encapsulated TS_TST_INFO object from PKCS7. */
279TS_TST_INFO *PKCS7_to_TS_TST_INFO(PKCS7 *token) 310TS_TST_INFO *
311PKCS7_to_TS_TST_INFO(PKCS7 *token)
280{ 312{
281 PKCS7_SIGNED *pkcs7_signed; 313 PKCS7_SIGNED *pkcs7_signed;
282 PKCS7 *enveloped; 314 PKCS7 *enveloped;
@@ -284,35 +316,31 @@ TS_TST_INFO *PKCS7_to_TS_TST_INFO(PKCS7 *token)
284 ASN1_OCTET_STRING *tst_info_der; 316 ASN1_OCTET_STRING *tst_info_der;
285 const unsigned char *p; 317 const unsigned char *p;
286 318
287 if (!PKCS7_type_is_signed(token)) 319 if (!PKCS7_type_is_signed(token)) {
288 {
289 TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_PKCS7_TYPE); 320 TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_PKCS7_TYPE);
290 return NULL; 321 return NULL;
291 } 322 }
292 323
293 /* Content must be present. */ 324 /* Content must be present. */
294 if (PKCS7_get_detached(token)) 325 if (PKCS7_get_detached(token)) {
295 {
296 TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_DETACHED_CONTENT); 326 TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_DETACHED_CONTENT);
297 return NULL; 327 return NULL;
298 } 328 }
299 329
300 /* We have a signed data with content. */ 330 /* We have a signed data with content. */
301 pkcs7_signed = token->d.sign; 331 pkcs7_signed = token->d.sign;
302 enveloped = pkcs7_signed->contents; 332 enveloped = pkcs7_signed->contents;
303 if (OBJ_obj2nid(enveloped->type) != NID_id_smime_ct_TSTInfo) 333 if (OBJ_obj2nid(enveloped->type) != NID_id_smime_ct_TSTInfo) {
304 {
305 TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_PKCS7_TYPE); 334 TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_PKCS7_TYPE);
306 return NULL; 335 return NULL;
307 } 336 }
308 337
309 /* We have a DER encoded TST_INFO as the signed data. */ 338 /* We have a DER encoded TST_INFO as the signed data. */
310 tst_info_wrapper = enveloped->d.other; 339 tst_info_wrapper = enveloped->d.other;
311 if (tst_info_wrapper->type != V_ASN1_OCTET_STRING) 340 if (tst_info_wrapper->type != V_ASN1_OCTET_STRING) {
312 {
313 TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_TYPE); 341 TSerr(TS_F_PKCS7_TO_TS_TST_INFO, TS_R_BAD_TYPE);
314 return NULL; 342 return NULL;
315 } 343 }
316 344
317 /* We have the correct ASN1_OCTET_STRING type. */ 345 /* We have the correct ASN1_OCTET_STRING type. */
318 tst_info_der = tst_info_wrapper->value.octet_string; 346 tst_info_der = tst_info_wrapper->value.octet_string;