diff options
Diffstat (limited to 'src/lib/libcrypto/cms/cms_lib.c')
| -rw-r--r-- | src/lib/libcrypto/cms/cms_lib.c | 141 |
1 files changed, 98 insertions, 43 deletions
diff --git a/src/lib/libcrypto/cms/cms_lib.c b/src/lib/libcrypto/cms/cms_lib.c index baee32c398..71c6796dbb 100644 --- a/src/lib/libcrypto/cms/cms_lib.c +++ b/src/lib/libcrypto/cms/cms_lib.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: cms_lib.c,v 1.9 2019/08/10 16:42:20 jsing Exp $ */ | 1 | /* $OpenBSD: cms_lib.c,v 1.10 2019/08/10 18:15:52 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 3 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 4 | * project. | 4 | * project. |
| @@ -64,14 +64,17 @@ | |||
| 64 | IMPLEMENT_ASN1_FUNCTIONS(CMS_ContentInfo) | 64 | IMPLEMENT_ASN1_FUNCTIONS(CMS_ContentInfo) |
| 65 | IMPLEMENT_ASN1_PRINT_FUNCTION(CMS_ContentInfo) | 65 | IMPLEMENT_ASN1_PRINT_FUNCTION(CMS_ContentInfo) |
| 66 | 66 | ||
| 67 | const ASN1_OBJECT *CMS_get0_type(const CMS_ContentInfo *cms) | 67 | const ASN1_OBJECT * |
| 68 | CMS_get0_type(const CMS_ContentInfo *cms) | ||
| 68 | { | 69 | { |
| 69 | return cms->contentType; | 70 | return cms->contentType; |
| 70 | } | 71 | } |
| 71 | 72 | ||
| 72 | CMS_ContentInfo *cms_Data_create(void) | 73 | CMS_ContentInfo * |
| 74 | cms_Data_create(void) | ||
| 73 | { | 75 | { |
| 74 | CMS_ContentInfo *cms; | 76 | CMS_ContentInfo *cms; |
| 77 | |||
| 75 | cms = CMS_ContentInfo_new(); | 78 | cms = CMS_ContentInfo_new(); |
| 76 | if (cms != NULL) { | 79 | if (cms != NULL) { |
| 77 | cms->contentType = OBJ_nid2obj(NID_pkcs7_data); | 80 | cms->contentType = OBJ_nid2obj(NID_pkcs7_data); |
| @@ -81,9 +84,11 @@ CMS_ContentInfo *cms_Data_create(void) | |||
| 81 | return cms; | 84 | return cms; |
| 82 | } | 85 | } |
| 83 | 86 | ||
| 84 | BIO *cms_content_bio(CMS_ContentInfo *cms) | 87 | BIO * |
| 88 | cms_content_bio(CMS_ContentInfo *cms) | ||
| 85 | { | 89 | { |
| 86 | ASN1_OCTET_STRING **pos = CMS_get0_content(cms); | 90 | ASN1_OCTET_STRING **pos = CMS_get0_content(cms); |
| 91 | |||
| 87 | if (!pos) | 92 | if (!pos) |
| 88 | return NULL; | 93 | return NULL; |
| 89 | /* If content detached data goes nowhere: create NULL BIO */ | 94 | /* If content detached data goes nowhere: create NULL BIO */ |
| @@ -94,13 +99,16 @@ BIO *cms_content_bio(CMS_ContentInfo *cms) | |||
| 94 | */ | 99 | */ |
| 95 | if (!*pos || ((*pos)->flags == ASN1_STRING_FLAG_CONT)) | 100 | if (!*pos || ((*pos)->flags == ASN1_STRING_FLAG_CONT)) |
| 96 | return BIO_new(BIO_s_mem()); | 101 | return BIO_new(BIO_s_mem()); |
| 102 | |||
| 97 | /* Else content was read in: return read only BIO for it */ | 103 | /* Else content was read in: return read only BIO for it */ |
| 98 | return BIO_new_mem_buf((*pos)->data, (*pos)->length); | 104 | return BIO_new_mem_buf((*pos)->data, (*pos)->length); |
| 99 | } | 105 | } |
| 100 | 106 | ||
| 101 | BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont) | 107 | BIO * |
| 108 | CMS_dataInit(CMS_ContentInfo *cms, BIO *icont) | ||
| 102 | { | 109 | { |
| 103 | BIO *cmsbio, *cont; | 110 | BIO *cmsbio, *cont; |
| 111 | |||
| 104 | if (icont) | 112 | if (icont) |
| 105 | cont = icont; | 113 | cont = icont; |
| 106 | else | 114 | else |
| @@ -145,13 +153,15 @@ BIO *CMS_dataInit(CMS_ContentInfo *cms, BIO *icont) | |||
| 145 | 153 | ||
| 146 | if (!icont) | 154 | if (!icont) |
| 147 | BIO_free(cont); | 155 | BIO_free(cont); |
| 148 | return NULL; | ||
| 149 | 156 | ||
| 157 | return NULL; | ||
| 150 | } | 158 | } |
| 151 | 159 | ||
| 152 | int CMS_dataFinal(CMS_ContentInfo *cms, BIO *cmsbio) | 160 | int |
| 161 | CMS_dataFinal(CMS_ContentInfo *cms, BIO *cmsbio) | ||
| 153 | { | 162 | { |
| 154 | ASN1_OCTET_STRING **pos = CMS_get0_content(cms); | 163 | ASN1_OCTET_STRING **pos = CMS_get0_content(cms); |
| 164 | |||
| 155 | if (!pos) | 165 | if (!pos) |
| 156 | return 0; | 166 | return 0; |
| 157 | /* If embedded content find memory BIO and set content */ | 167 | /* If embedded content find memory BIO and set content */ |
| @@ -198,10 +208,10 @@ int CMS_dataFinal(CMS_ContentInfo *cms, BIO *cmsbio) | |||
| 198 | * or set later. | 208 | * or set later. |
| 199 | */ | 209 | */ |
| 200 | 210 | ||
| 201 | ASN1_OCTET_STRING **CMS_get0_content(CMS_ContentInfo *cms) | 211 | ASN1_OCTET_STRING ** |
| 212 | CMS_get0_content(CMS_ContentInfo *cms) | ||
| 202 | { | 213 | { |
| 203 | switch (OBJ_obj2nid(cms->contentType)) { | 214 | switch (OBJ_obj2nid(cms->contentType)) { |
| 204 | |||
| 205 | case NID_pkcs7_data: | 215 | case NID_pkcs7_data: |
| 206 | return &cms->d.data; | 216 | return &cms->d.data; |
| 207 | 217 | ||
| @@ -228,7 +238,6 @@ ASN1_OCTET_STRING **CMS_get0_content(CMS_ContentInfo *cms) | |||
| 228 | return &cms->d.other->value.octet_string; | 238 | return &cms->d.other->value.octet_string; |
| 229 | CMSerr(CMS_F_CMS_GET0_CONTENT, CMS_R_UNSUPPORTED_CONTENT_TYPE); | 239 | CMSerr(CMS_F_CMS_GET0_CONTENT, CMS_R_UNSUPPORTED_CONTENT_TYPE); |
| 230 | return NULL; | 240 | return NULL; |
| 231 | |||
| 232 | } | 241 | } |
| 233 | } | 242 | } |
| 234 | 243 | ||
| @@ -237,10 +246,10 @@ ASN1_OCTET_STRING **CMS_get0_content(CMS_ContentInfo *cms) | |||
| 237 | * accessed or set later. | 246 | * accessed or set later. |
| 238 | */ | 247 | */ |
| 239 | 248 | ||
| 240 | static ASN1_OBJECT **cms_get0_econtent_type(CMS_ContentInfo *cms) | 249 | static ASN1_OBJECT ** |
| 250 | cms_get0_econtent_type(CMS_ContentInfo *cms) | ||
| 241 | { | 251 | { |
| 242 | switch (OBJ_obj2nid(cms->contentType)) { | 252 | switch (OBJ_obj2nid(cms->contentType)) { |
| 243 | |||
| 244 | case NID_pkcs7_signed: | 253 | case NID_pkcs7_signed: |
| 245 | return &cms->d.signedData->encapContentInfo->eContentType; | 254 | return &cms->d.signedData->encapContentInfo->eContentType; |
| 246 | 255 | ||
| @@ -262,22 +271,26 @@ static ASN1_OBJECT **cms_get0_econtent_type(CMS_ContentInfo *cms) | |||
| 262 | default: | 271 | default: |
| 263 | CMSerr(CMS_F_CMS_GET0_ECONTENT_TYPE, CMS_R_UNSUPPORTED_CONTENT_TYPE); | 272 | CMSerr(CMS_F_CMS_GET0_ECONTENT_TYPE, CMS_R_UNSUPPORTED_CONTENT_TYPE); |
| 264 | return NULL; | 273 | return NULL; |
| 265 | |||
| 266 | } | 274 | } |
| 267 | } | 275 | } |
| 268 | 276 | ||
| 269 | const ASN1_OBJECT *CMS_get0_eContentType(CMS_ContentInfo *cms) | 277 | const ASN1_OBJECT * |
| 278 | CMS_get0_eContentType(CMS_ContentInfo *cms) | ||
| 270 | { | 279 | { |
| 271 | ASN1_OBJECT **petype; | 280 | ASN1_OBJECT **petype; |
| 281 | |||
| 272 | petype = cms_get0_econtent_type(cms); | 282 | petype = cms_get0_econtent_type(cms); |
| 273 | if (petype) | 283 | if (petype) |
| 274 | return *petype; | 284 | return *petype; |
| 285 | |||
| 275 | return NULL; | 286 | return NULL; |
| 276 | } | 287 | } |
| 277 | 288 | ||
| 278 | int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid) | 289 | int |
| 290 | CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid) | ||
| 279 | { | 291 | { |
| 280 | ASN1_OBJECT **petype, *etype; | 292 | ASN1_OBJECT **petype, *etype; |
| 293 | |||
| 281 | petype = cms_get0_econtent_type(cms); | 294 | petype = cms_get0_econtent_type(cms); |
| 282 | if (!petype) | 295 | if (!petype) |
| 283 | return 0; | 296 | return 0; |
| @@ -288,23 +301,29 @@ int CMS_set1_eContentType(CMS_ContentInfo *cms, const ASN1_OBJECT *oid) | |||
| 288 | return 0; | 301 | return 0; |
| 289 | ASN1_OBJECT_free(*petype); | 302 | ASN1_OBJECT_free(*petype); |
| 290 | *petype = etype; | 303 | *petype = etype; |
| 304 | |||
| 291 | return 1; | 305 | return 1; |
| 292 | } | 306 | } |
| 293 | 307 | ||
| 294 | int CMS_is_detached(CMS_ContentInfo *cms) | 308 | int |
| 309 | CMS_is_detached(CMS_ContentInfo *cms) | ||
| 295 | { | 310 | { |
| 296 | ASN1_OCTET_STRING **pos; | 311 | ASN1_OCTET_STRING **pos; |
| 312 | |||
| 297 | pos = CMS_get0_content(cms); | 313 | pos = CMS_get0_content(cms); |
| 298 | if (!pos) | 314 | if (!pos) |
| 299 | return -1; | 315 | return -1; |
| 300 | if (*pos) | 316 | if (*pos) |
| 301 | return 0; | 317 | return 0; |
| 318 | |||
| 302 | return 1; | 319 | return 1; |
| 303 | } | 320 | } |
| 304 | 321 | ||
| 305 | int CMS_set_detached(CMS_ContentInfo *cms, int detached) | 322 | int |
| 323 | CMS_set_detached(CMS_ContentInfo *cms, int detached) | ||
| 306 | { | 324 | { |
| 307 | ASN1_OCTET_STRING **pos; | 325 | ASN1_OCTET_STRING **pos; |
| 326 | |||
| 308 | pos = CMS_get0_content(cms); | 327 | pos = CMS_get0_content(cms); |
| 309 | if (!pos) | 328 | if (!pos) |
| 310 | return 0; | 329 | return 0; |
| @@ -323,16 +342,19 @@ int CMS_set_detached(CMS_ContentInfo *cms, int detached) | |||
| 323 | return 1; | 342 | return 1; |
| 324 | } | 343 | } |
| 325 | CMSerr(CMS_F_CMS_SET_DETACHED, ERR_R_MALLOC_FAILURE); | 344 | CMSerr(CMS_F_CMS_SET_DETACHED, ERR_R_MALLOC_FAILURE); |
| 345 | |||
| 326 | return 0; | 346 | return 0; |
| 327 | } | 347 | } |
| 328 | 348 | ||
| 329 | /* Create a digest BIO from an X509_ALGOR structure */ | 349 | /* Create a digest BIO from an X509_ALGOR structure */ |
| 330 | 350 | ||
| 331 | BIO *cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm) | 351 | BIO * |
| 352 | cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm) | ||
| 332 | { | 353 | { |
| 333 | BIO *mdbio = NULL; | 354 | BIO *mdbio = NULL; |
| 334 | const ASN1_OBJECT *digestoid; | 355 | const ASN1_OBJECT *digestoid; |
| 335 | const EVP_MD *digest; | 356 | const EVP_MD *digest; |
| 357 | |||
| 336 | X509_ALGOR_get0(&digestoid, NULL, NULL, digestAlgorithm); | 358 | X509_ALGOR_get0(&digestoid, NULL, NULL, digestAlgorithm); |
| 337 | digest = EVP_get_digestbyobj(digestoid); | 359 | digest = EVP_get_digestbyobj(digestoid); |
| 338 | if (!digest) { | 360 | if (!digest) { |
| @@ -346,18 +368,21 @@ BIO *cms_DigestAlgorithm_init_bio(X509_ALGOR *digestAlgorithm) | |||
| 346 | goto err; | 368 | goto err; |
| 347 | } | 369 | } |
| 348 | return mdbio; | 370 | return mdbio; |
| 371 | |||
| 349 | err: | 372 | err: |
| 350 | BIO_free(mdbio); | 373 | BIO_free(mdbio); |
| 374 | |||
| 351 | return NULL; | 375 | return NULL; |
| 352 | } | 376 | } |
| 353 | 377 | ||
| 354 | /* Locate a message digest content from a BIO chain based on SignerInfo */ | 378 | /* Locate a message digest content from a BIO chain based on SignerInfo */ |
| 355 | 379 | ||
| 356 | int cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain, | 380 | int |
| 357 | X509_ALGOR *mdalg) | 381 | cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain, X509_ALGOR *mdalg) |
| 358 | { | 382 | { |
| 359 | int nid; | 383 | int nid; |
| 360 | const ASN1_OBJECT *mdoid; | 384 | const ASN1_OBJECT *mdoid; |
| 385 | |||
| 361 | X509_ALGOR_get0(&mdoid, NULL, NULL, mdalg); | 386 | X509_ALGOR_get0(&mdoid, NULL, NULL, mdalg); |
| 362 | nid = OBJ_obj2nid(mdoid); | 387 | nid = OBJ_obj2nid(mdoid); |
| 363 | /* Look for digest type to match signature */ | 388 | /* Look for digest type to match signature */ |
| @@ -381,11 +406,10 @@ int cms_DigestAlgorithm_find_ctx(EVP_MD_CTX *mctx, BIO *chain, | |||
| 381 | } | 406 | } |
| 382 | } | 407 | } |
| 383 | 408 | ||
| 384 | static STACK_OF(CMS_CertificateChoices) | 409 | static STACK_OF(CMS_CertificateChoices) ** |
| 385 | **cms_get0_certificate_choices(CMS_ContentInfo *cms) | 410 | cms_get0_certificate_choices(CMS_ContentInfo *cms) |
| 386 | { | 411 | { |
| 387 | switch (OBJ_obj2nid(cms->contentType)) { | 412 | switch (OBJ_obj2nid(cms->contentType)) { |
| 388 | |||
| 389 | case NID_pkcs7_signed: | 413 | case NID_pkcs7_signed: |
| 390 | return &cms->d.signedData->certificates; | 414 | return &cms->d.signedData->certificates; |
| 391 | 415 | ||
| @@ -396,16 +420,17 @@ static STACK_OF(CMS_CertificateChoices) | |||
| 396 | 420 | ||
| 397 | default: | 421 | default: |
| 398 | CMSerr(CMS_F_CMS_GET0_CERTIFICATE_CHOICES, | 422 | CMSerr(CMS_F_CMS_GET0_CERTIFICATE_CHOICES, |
| 399 | CMS_R_UNSUPPORTED_CONTENT_TYPE); | 423 | CMS_R_UNSUPPORTED_CONTENT_TYPE); |
| 400 | return NULL; | 424 | return NULL; |
| 401 | |||
| 402 | } | 425 | } |
| 403 | } | 426 | } |
| 404 | 427 | ||
| 405 | CMS_CertificateChoices *CMS_add0_CertificateChoices(CMS_ContentInfo *cms) | 428 | CMS_CertificateChoices * |
| 429 | CMS_add0_CertificateChoices(CMS_ContentInfo *cms) | ||
| 406 | { | 430 | { |
| 407 | STACK_OF(CMS_CertificateChoices) **pcerts; | 431 | STACK_OF(CMS_CertificateChoices) **pcerts; |
| 408 | CMS_CertificateChoices *cch; | 432 | CMS_CertificateChoices *cch; |
| 433 | |||
| 409 | pcerts = cms_get0_certificate_choices(cms); | 434 | pcerts = cms_get0_certificate_choices(cms); |
| 410 | if (!pcerts) | 435 | if (!pcerts) |
| 411 | return NULL; | 436 | return NULL; |
| @@ -420,14 +445,17 @@ CMS_CertificateChoices *CMS_add0_CertificateChoices(CMS_ContentInfo *cms) | |||
| 420 | M_ASN1_free_of(cch, CMS_CertificateChoices); | 445 | M_ASN1_free_of(cch, CMS_CertificateChoices); |
| 421 | return NULL; | 446 | return NULL; |
| 422 | } | 447 | } |
| 448 | |||
| 423 | return cch; | 449 | return cch; |
| 424 | } | 450 | } |
| 425 | 451 | ||
| 426 | int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert) | 452 | int |
| 453 | CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert) | ||
| 427 | { | 454 | { |
| 428 | CMS_CertificateChoices *cch; | 455 | CMS_CertificateChoices *cch; |
| 429 | STACK_OF(CMS_CertificateChoices) **pcerts; | 456 | STACK_OF(CMS_CertificateChoices) **pcerts; |
| 430 | int i; | 457 | int i; |
| 458 | |||
| 431 | pcerts = cms_get0_certificate_choices(cms); | 459 | pcerts = cms_get0_certificate_choices(cms); |
| 432 | if (!pcerts) | 460 | if (!pcerts) |
| 433 | return 0; | 461 | return 0; |
| @@ -446,23 +474,26 @@ int CMS_add0_cert(CMS_ContentInfo *cms, X509 *cert) | |||
| 446 | return 0; | 474 | return 0; |
| 447 | cch->type = CMS_CERTCHOICE_CERT; | 475 | cch->type = CMS_CERTCHOICE_CERT; |
| 448 | cch->d.certificate = cert; | 476 | cch->d.certificate = cert; |
| 477 | |||
| 449 | return 1; | 478 | return 1; |
| 450 | } | 479 | } |
| 451 | 480 | ||
| 452 | int CMS_add1_cert(CMS_ContentInfo *cms, X509 *cert) | 481 | int |
| 482 | CMS_add1_cert(CMS_ContentInfo *cms, X509 *cert) | ||
| 453 | { | 483 | { |
| 454 | int r; | 484 | int r; |
| 485 | |||
| 455 | r = CMS_add0_cert(cms, cert); | 486 | r = CMS_add0_cert(cms, cert); |
| 456 | if (r > 0) | 487 | if (r > 0) |
| 457 | X509_up_ref(cert); | 488 | X509_up_ref(cert); |
| 489 | |||
| 458 | return r; | 490 | return r; |
| 459 | } | 491 | } |
| 460 | 492 | ||
| 461 | static STACK_OF(CMS_RevocationInfoChoice) | 493 | static STACK_OF(CMS_RevocationInfoChoice) ** |
| 462 | **cms_get0_revocation_choices(CMS_ContentInfo *cms) | 494 | cms_get0_revocation_choices(CMS_ContentInfo *cms) |
| 463 | { | 495 | { |
| 464 | switch (OBJ_obj2nid(cms->contentType)) { | 496 | switch (OBJ_obj2nid(cms->contentType)) { |
| 465 | |||
| 466 | case NID_pkcs7_signed: | 497 | case NID_pkcs7_signed: |
| 467 | return &cms->d.signedData->crls; | 498 | return &cms->d.signedData->crls; |
| 468 | 499 | ||
| @@ -473,16 +504,17 @@ static STACK_OF(CMS_RevocationInfoChoice) | |||
| 473 | 504 | ||
| 474 | default: | 505 | default: |
| 475 | CMSerr(CMS_F_CMS_GET0_REVOCATION_CHOICES, | 506 | CMSerr(CMS_F_CMS_GET0_REVOCATION_CHOICES, |
| 476 | CMS_R_UNSUPPORTED_CONTENT_TYPE); | 507 | CMS_R_UNSUPPORTED_CONTENT_TYPE); |
| 477 | return NULL; | 508 | return NULL; |
| 478 | |||
| 479 | } | 509 | } |
| 480 | } | 510 | } |
| 481 | 511 | ||
| 482 | CMS_RevocationInfoChoice *CMS_add0_RevocationInfoChoice(CMS_ContentInfo *cms) | 512 | CMS_RevocationInfoChoice * |
| 513 | CMS_add0_RevocationInfoChoice(CMS_ContentInfo *cms) | ||
| 483 | { | 514 | { |
| 484 | STACK_OF(CMS_RevocationInfoChoice) **pcrls; | 515 | STACK_OF(CMS_RevocationInfoChoice) **pcrls; |
| 485 | CMS_RevocationInfoChoice *rch; | 516 | CMS_RevocationInfoChoice *rch; |
| 517 | |||
| 486 | pcrls = cms_get0_revocation_choices(cms); | 518 | pcrls = cms_get0_revocation_choices(cms); |
| 487 | if (!pcrls) | 519 | if (!pcrls) |
| 488 | return NULL; | 520 | return NULL; |
| @@ -497,35 +529,44 @@ CMS_RevocationInfoChoice *CMS_add0_RevocationInfoChoice(CMS_ContentInfo *cms) | |||
| 497 | M_ASN1_free_of(rch, CMS_RevocationInfoChoice); | 529 | M_ASN1_free_of(rch, CMS_RevocationInfoChoice); |
| 498 | return NULL; | 530 | return NULL; |
| 499 | } | 531 | } |
| 532 | |||
| 500 | return rch; | 533 | return rch; |
| 501 | } | 534 | } |
| 502 | 535 | ||
| 503 | int CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl) | 536 | int |
| 537 | CMS_add0_crl(CMS_ContentInfo *cms, X509_CRL *crl) | ||
| 504 | { | 538 | { |
| 505 | CMS_RevocationInfoChoice *rch; | 539 | CMS_RevocationInfoChoice *rch; |
| 540 | |||
| 506 | rch = CMS_add0_RevocationInfoChoice(cms); | 541 | rch = CMS_add0_RevocationInfoChoice(cms); |
| 507 | if (!rch) | 542 | if (!rch) |
| 508 | return 0; | 543 | return 0; |
| 509 | rch->type = CMS_REVCHOICE_CRL; | 544 | rch->type = CMS_REVCHOICE_CRL; |
| 510 | rch->d.crl = crl; | 545 | rch->d.crl = crl; |
| 546 | |||
| 511 | return 1; | 547 | return 1; |
| 512 | } | 548 | } |
| 513 | 549 | ||
| 514 | int CMS_add1_crl(CMS_ContentInfo *cms, X509_CRL *crl) | 550 | int |
| 551 | CMS_add1_crl(CMS_ContentInfo *cms, X509_CRL *crl) | ||
| 515 | { | 552 | { |
| 516 | int r; | 553 | int r; |
| 554 | |||
| 517 | r = CMS_add0_crl(cms, crl); | 555 | r = CMS_add0_crl(cms, crl); |
| 518 | if (r > 0) | 556 | if (r > 0) |
| 519 | X509_CRL_up_ref(crl); | 557 | X509_CRL_up_ref(crl); |
| 558 | |||
| 520 | return r; | 559 | return r; |
| 521 | } | 560 | } |
| 522 | 561 | ||
| 523 | STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms) | 562 | STACK_OF(X509) * |
| 563 | CMS_get1_certs(CMS_ContentInfo *cms) | ||
| 524 | { | 564 | { |
| 525 | STACK_OF(X509) *certs = NULL; | 565 | STACK_OF(X509) *certs = NULL; |
| 526 | CMS_CertificateChoices *cch; | 566 | CMS_CertificateChoices *cch; |
| 527 | STACK_OF(CMS_CertificateChoices) **pcerts; | 567 | STACK_OF(CMS_CertificateChoices) **pcerts; |
| 528 | int i; | 568 | int i; |
| 569 | |||
| 529 | pcerts = cms_get0_certificate_choices(cms); | 570 | pcerts = cms_get0_certificate_choices(cms); |
| 530 | if (!pcerts) | 571 | if (!pcerts) |
| 531 | return NULL; | 572 | return NULL; |
| @@ -545,15 +586,16 @@ STACK_OF(X509) *CMS_get1_certs(CMS_ContentInfo *cms) | |||
| 545 | } | 586 | } |
| 546 | } | 587 | } |
| 547 | return certs; | 588 | return certs; |
| 548 | |||
| 549 | } | 589 | } |
| 550 | 590 | ||
| 551 | STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms) | 591 | STACK_OF(X509_CRL) * |
| 592 | CMS_get1_crls(CMS_ContentInfo *cms) | ||
| 552 | { | 593 | { |
| 553 | STACK_OF(X509_CRL) *crls = NULL; | 594 | STACK_OF(X509_CRL) *crls = NULL; |
| 554 | STACK_OF(CMS_RevocationInfoChoice) **pcrls; | 595 | STACK_OF(CMS_RevocationInfoChoice) **pcrls; |
| 555 | CMS_RevocationInfoChoice *rch; | 596 | CMS_RevocationInfoChoice *rch; |
| 556 | int i; | 597 | int i; |
| 598 | |||
| 557 | pcrls = cms_get0_revocation_choices(cms); | 599 | pcrls = cms_get0_revocation_choices(cms); |
| 558 | if (!pcrls) | 600 | if (!pcrls) |
| 559 | return NULL; | 601 | return NULL; |
| @@ -575,27 +617,34 @@ STACK_OF(X509_CRL) *CMS_get1_crls(CMS_ContentInfo *cms) | |||
| 575 | return crls; | 617 | return crls; |
| 576 | } | 618 | } |
| 577 | 619 | ||
| 578 | int cms_ias_cert_cmp(CMS_IssuerAndSerialNumber *ias, X509 *cert) | 620 | int |
| 621 | cms_ias_cert_cmp(CMS_IssuerAndSerialNumber *ias, X509 *cert) | ||
| 579 | { | 622 | { |
| 580 | int ret; | 623 | int ret; |
| 624 | |||
| 581 | ret = X509_NAME_cmp(ias->issuer, X509_get_issuer_name(cert)); | 625 | ret = X509_NAME_cmp(ias->issuer, X509_get_issuer_name(cert)); |
| 582 | if (ret) | 626 | if (ret) |
| 583 | return ret; | 627 | return ret; |
| 628 | |||
| 584 | return ASN1_INTEGER_cmp(ias->serialNumber, X509_get_serialNumber(cert)); | 629 | return ASN1_INTEGER_cmp(ias->serialNumber, X509_get_serialNumber(cert)); |
| 585 | } | 630 | } |
| 586 | 631 | ||
| 587 | int cms_keyid_cert_cmp(ASN1_OCTET_STRING *keyid, X509 *cert) | 632 | int |
| 633 | cms_keyid_cert_cmp(ASN1_OCTET_STRING *keyid, X509 *cert) | ||
| 588 | { | 634 | { |
| 589 | const ASN1_OCTET_STRING *cert_keyid = X509_get0_subject_key_id(cert); | 635 | const ASN1_OCTET_STRING *cert_keyid = X509_get0_subject_key_id(cert); |
| 590 | 636 | ||
| 591 | if (cert_keyid == NULL) | 637 | if (cert_keyid == NULL) |
| 592 | return -1; | 638 | return -1; |
| 639 | |||
| 593 | return ASN1_OCTET_STRING_cmp(keyid, cert_keyid); | 640 | return ASN1_OCTET_STRING_cmp(keyid, cert_keyid); |
| 594 | } | 641 | } |
| 595 | 642 | ||
| 596 | int cms_set1_ias(CMS_IssuerAndSerialNumber **pias, X509 *cert) | 643 | int |
| 644 | cms_set1_ias(CMS_IssuerAndSerialNumber **pias, X509 *cert) | ||
| 597 | { | 645 | { |
| 598 | CMS_IssuerAndSerialNumber *ias; | 646 | CMS_IssuerAndSerialNumber *ias; |
| 647 | |||
| 599 | ias = M_ASN1_new_of(CMS_IssuerAndSerialNumber); | 648 | ias = M_ASN1_new_of(CMS_IssuerAndSerialNumber); |
| 600 | if (!ias) | 649 | if (!ias) |
| 601 | goto err; | 650 | goto err; |
| @@ -605,17 +654,22 @@ int cms_set1_ias(CMS_IssuerAndSerialNumber **pias, X509 *cert) | |||
| 605 | goto err; | 654 | goto err; |
| 606 | M_ASN1_free_of(*pias, CMS_IssuerAndSerialNumber); | 655 | M_ASN1_free_of(*pias, CMS_IssuerAndSerialNumber); |
| 607 | *pias = ias; | 656 | *pias = ias; |
| 657 | |||
| 608 | return 1; | 658 | return 1; |
| 659 | |||
| 609 | err: | 660 | err: |
| 610 | M_ASN1_free_of(ias, CMS_IssuerAndSerialNumber); | 661 | M_ASN1_free_of(ias, CMS_IssuerAndSerialNumber); |
| 611 | CMSerr(CMS_F_CMS_SET1_IAS, ERR_R_MALLOC_FAILURE); | 662 | CMSerr(CMS_F_CMS_SET1_IAS, ERR_R_MALLOC_FAILURE); |
| 663 | |||
| 612 | return 0; | 664 | return 0; |
| 613 | } | 665 | } |
| 614 | 666 | ||
| 615 | int cms_set1_keyid(ASN1_OCTET_STRING **pkeyid, X509 *cert) | 667 | int |
| 668 | cms_set1_keyid(ASN1_OCTET_STRING **pkeyid, X509 *cert) | ||
| 616 | { | 669 | { |
| 617 | ASN1_OCTET_STRING *keyid = NULL; | 670 | ASN1_OCTET_STRING *keyid = NULL; |
| 618 | const ASN1_OCTET_STRING *cert_keyid; | 671 | const ASN1_OCTET_STRING *cert_keyid; |
| 672 | |||
| 619 | cert_keyid = X509_get0_subject_key_id(cert); | 673 | cert_keyid = X509_get0_subject_key_id(cert); |
| 620 | if (cert_keyid == NULL) { | 674 | if (cert_keyid == NULL) { |
| 621 | CMSerr(CMS_F_CMS_SET1_KEYID, CMS_R_CERTIFICATE_HAS_NO_KEYID); | 675 | CMSerr(CMS_F_CMS_SET1_KEYID, CMS_R_CERTIFICATE_HAS_NO_KEYID); |
| @@ -628,5 +682,6 @@ int cms_set1_keyid(ASN1_OCTET_STRING **pkeyid, X509 *cert) | |||
| 628 | } | 682 | } |
| 629 | ASN1_OCTET_STRING_free(*pkeyid); | 683 | ASN1_OCTET_STRING_free(*pkeyid); |
| 630 | *pkeyid = keyid; | 684 | *pkeyid = keyid; |
| 685 | |||
| 631 | return 1; | 686 | return 1; |
| 632 | } | 687 | } |
