Codebase list openssl / 1d02ce4
X509_STORE_new: memory needs to be freed Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/17278) (cherry picked from commit c81eed84e4e9025e933778f5e8326b1e4435e094) Peiwei Hu authored 2 years ago Tomas Mraz committed 2 years ago
2 changed file(s) with 17 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
2626 /* Set up trusted CA certificate store */
2727
2828 st = X509_STORE_new();
29 if (st == NULL)
30 goto err;
2931
3032 /* Read in CA certificate */
3133 tbio = BIO_new_file("cacert.pem", "r");
3234
33 if (!tbio)
35 if (tbio == NULL)
3436 goto err;
3537
3638 cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
3739
38 if (!cacert)
40 if (cacert == NULL)
3941 goto err;
4042
4143 if (!X509_STORE_add_cert(st, cacert))
4547
4648 in = BIO_new_file("smout.txt", "r");
4749
48 if (!in)
50 if (in == NULL)
4951 goto err;
5052
5153 /* parse message */
5254 cms = SMIME_read_CMS(in, &cont);
5355
54 if (!cms)
56 if (cms == NULL)
5557 goto err;
5658
5759 /* File to output verified content to */
5860 out = BIO_new_file("smver.txt", "w");
59 if (!out)
61 if (out == NULL)
6062 goto err;
6163
6264 if (!CMS_verify(cms, NULL, st, cont, out, 0)) {
7577 ERR_print_errors_fp(stderr);
7678 }
7779
80 X509_STORE_free(st);
7881 CMS_ContentInfo_free(cms);
7982 X509_free(cacert);
8083 BIO_free(in);
2626 /* Set up trusted CA certificate store */
2727
2828 st = X509_STORE_new();
29 if (st == NULL)
30 goto err;
2931
3032 /* Read in signer certificate and private key */
3133 tbio = BIO_new_file("cacert.pem", "r");
3234
33 if (!tbio)
35 if (tbio == NULL)
3436 goto err;
3537
3638 cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
3739
38 if (!cacert)
40 if (cacert == NULL)
3941 goto err;
4042
4143 if (!X509_STORE_add_cert(st, cacert))
4547
4648 in = BIO_new_file("smout.txt", "r");
4749
48 if (!in)
50 if (in == NULL)
4951 goto err;
5052
5153 /* Sign content */
5254 p7 = SMIME_read_PKCS7(in, &cont);
5355
54 if (!p7)
56 if (p7 == NULL)
5557 goto err;
5658
5759 /* File to output verified content to */
5860 out = BIO_new_file("smver.txt", "w");
59 if (!out)
61 if (out == NULL)
6062 goto err;
6163
6264 if (!PKCS7_verify(p7, NULL, st, cont, out, 0)) {
7375 fprintf(stderr, "Error Verifying Data\n");
7476 ERR_print_errors_fp(stderr);
7577 }
78
79 X509_STORE_free(st);
7680 PKCS7_free(p7);
7781 X509_free(cacert);
7882 BIO_free(in);