diff options
Diffstat (limited to 'src/lib/libcrypto/ts/ts_asn1.c')
| -rw-r--r-- | src/lib/libcrypto/ts/ts_asn1.c | 164 |
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 | ||
| 67 | IMPLEMENT_ASN1_FUNCTIONS_const(TS_MSG_IMPRINT) | 67 | IMPLEMENT_ASN1_FUNCTIONS_const(TS_MSG_IMPRINT) |
| 68 | IMPLEMENT_ASN1_DUP_FUNCTION(TS_MSG_IMPRINT) | 68 | IMPLEMENT_ASN1_DUP_FUNCTION(TS_MSG_IMPRINT) |
| 69 | |||
| 69 | #ifndef OPENSSL_NO_BIO | 70 | #ifndef OPENSSL_NO_BIO |
| 70 | TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT_bio(BIO *bp, TS_MSG_IMPRINT **a) | 71 | TS_MSG_IMPRINT * |
| 71 | { | 72 | d2i_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 | ||
| 75 | int i2d_TS_MSG_IMPRINT_bio(BIO *bp, TS_MSG_IMPRINT *a) | 78 | int |
| 79 | i2d_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 |
| 81 | TS_MSG_IMPRINT *d2i_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT **a) | 86 | TS_MSG_IMPRINT * |
| 82 | { | 87 | d2i_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 | ||
| 86 | int i2d_TS_MSG_IMPRINT_fp(FILE *fp, TS_MSG_IMPRINT *a) | 93 | int |
| 87 | { | 94 | i2d_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 | ||
| 92 | ASN1_SEQUENCE(TS_REQ) = { | 100 | ASN1_SEQUENCE(TS_REQ) = { |
| @@ -100,27 +108,33 @@ ASN1_SEQUENCE(TS_REQ) = { | |||
| 100 | 108 | ||
| 101 | IMPLEMENT_ASN1_FUNCTIONS_const(TS_REQ) | 109 | IMPLEMENT_ASN1_FUNCTIONS_const(TS_REQ) |
| 102 | IMPLEMENT_ASN1_DUP_FUNCTION(TS_REQ) | 110 | IMPLEMENT_ASN1_DUP_FUNCTION(TS_REQ) |
| 111 | |||
| 103 | #ifndef OPENSSL_NO_BIO | 112 | #ifndef OPENSSL_NO_BIO |
| 104 | TS_REQ *d2i_TS_REQ_bio(BIO *bp, TS_REQ **a) | 113 | TS_REQ * |
| 105 | { | 114 | d2i_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 | ||
| 109 | int i2d_TS_REQ_bio(BIO *bp, TS_REQ *a) | 119 | int |
| 110 | { | 120 | i2d_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 |
| 115 | TS_REQ *d2i_TS_REQ_fp(FILE *fp, TS_REQ **a) | 127 | TS_REQ * |
| 116 | { | 128 | d2i_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 | ||
| 120 | int i2d_TS_REQ_fp(FILE *fp, TS_REQ *a) | 133 | int |
| 121 | { | 134 | i2d_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 | ||
| 126 | ASN1_SEQUENCE(TS_ACCURACY) = { | 140 | ASN1_SEQUENCE(TS_ACCURACY) = { |
| @@ -147,27 +161,35 @@ ASN1_SEQUENCE(TS_TST_INFO) = { | |||
| 147 | 161 | ||
| 148 | IMPLEMENT_ASN1_FUNCTIONS_const(TS_TST_INFO) | 162 | IMPLEMENT_ASN1_FUNCTIONS_const(TS_TST_INFO) |
| 149 | IMPLEMENT_ASN1_DUP_FUNCTION(TS_TST_INFO) | 163 | IMPLEMENT_ASN1_DUP_FUNCTION(TS_TST_INFO) |
| 164 | |||
| 150 | #ifndef OPENSSL_NO_BIO | 165 | #ifndef OPENSSL_NO_BIO |
| 151 | TS_TST_INFO *d2i_TS_TST_INFO_bio(BIO *bp, TS_TST_INFO **a) | 166 | TS_TST_INFO * |
| 152 | { | 167 | d2i_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 | ||
| 156 | int i2d_TS_TST_INFO_bio(BIO *bp, TS_TST_INFO *a) | 173 | int |
| 157 | { | 174 | i2d_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 |
| 162 | TS_TST_INFO *d2i_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO **a) | 181 | TS_TST_INFO * |
| 163 | { | 182 | d2i_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 | ||
| 167 | int i2d_TS_TST_INFO_fp(FILE *fp, TS_TST_INFO *a) | 188 | int |
| 168 | { | 189 | i2d_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 | ||
| 173 | ASN1_SEQUENCE(TS_STATUS_INFO) = { | 195 | ASN1_SEQUENCE(TS_STATUS_INFO) = { |
| @@ -179,7 +201,8 @@ ASN1_SEQUENCE(TS_STATUS_INFO) = { | |||
| 179 | IMPLEMENT_ASN1_FUNCTIONS_const(TS_STATUS_INFO) | 201 | IMPLEMENT_ASN1_FUNCTIONS_const(TS_STATUS_INFO) |
| 180 | IMPLEMENT_ASN1_DUP_FUNCTION(TS_STATUS_INFO) | 202 | IMPLEMENT_ASN1_DUP_FUNCTION(TS_STATUS_INFO) |
| 181 | 203 | ||
| 182 | static int ts_resp_set_tst_info(TS_RESP *a) | 204 | static int |
| 205 | ts_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 | ||
| 208 | static int ts_resp_cb(int op, ASN1_VALUE **pval, const ASN1_ITEM *it, | 232 | static int |
| 209 | void *exarg) | 233 | ts_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 | ||
| 229 | IMPLEMENT_ASN1_FUNCTIONS_const(TS_RESP) | 254 | IMPLEMENT_ASN1_FUNCTIONS_const(TS_RESP) |
| 230 | IMPLEMENT_ASN1_DUP_FUNCTION(TS_RESP) | 255 | IMPLEMENT_ASN1_DUP_FUNCTION(TS_RESP) |
| 256 | |||
| 231 | #ifndef OPENSSL_NO_BIO | 257 | #ifndef OPENSSL_NO_BIO |
| 232 | TS_RESP *d2i_TS_RESP_bio(BIO *bp, TS_RESP **a) | 258 | TS_RESP * |
| 233 | { | 259 | d2i_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 | ||
| 237 | int i2d_TS_RESP_bio(BIO *bp, TS_RESP *a) | 264 | int |
| 238 | { | 265 | i2d_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 |
| 243 | TS_RESP *d2i_TS_RESP_fp(FILE *fp, TS_RESP **a) | 272 | TS_RESP * |
| 244 | { | 273 | d2i_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 | ||
| 248 | int i2d_TS_RESP_fp(FILE *fp, TS_RESP *a) | 278 | int |
| 249 | { | 279 | i2d_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 | ||
| 254 | ASN1_SEQUENCE(ESS_ISSUER_SERIAL) = { | 285 | ASN1_SEQUENCE(ESS_ISSUER_SERIAL) = { |
| @@ -276,7 +307,8 @@ IMPLEMENT_ASN1_FUNCTIONS_const(ESS_SIGNING_CERT) | |||
| 276 | IMPLEMENT_ASN1_DUP_FUNCTION(ESS_SIGNING_CERT) | 307 | IMPLEMENT_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. */ |
| 279 | TS_TST_INFO *PKCS7_to_TS_TST_INFO(PKCS7 *token) | 310 | TS_TST_INFO * |
| 311 | PKCS7_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; |
