aboutsummaryrefslogtreecommitdiff
path: root/openssl/demos/cms
diff options
context:
space:
mode:
authorMike DePaulo <mikedep333@gmail.com>2015-03-28 09:50:31 -0400
committerMike DePaulo <mikedep333@gmail.com>2015-03-28 13:13:13 -0400
commit91e3957fb0e38a5d5649f82e5d9f89dd0e85666f (patch)
treefe0992fb4cf6f3c2a5d597557552ae69caccbe70 /openssl/demos/cms
parent9073d97eff3f6d3b33450ef3532a826674c7e1e8 (diff)
downloadvcxsrv-91e3957fb0e38a5d5649f82e5d9f89dd0e85666f.tar.gz
vcxsrv-91e3957fb0e38a5d5649f82e5d9f89dd0e85666f.tar.bz2
vcxsrv-91e3957fb0e38a5d5649f82e5d9f89dd0e85666f.zip
Update openssl to version openssl-1.0.1m
Conflicts: openssl/Makefile openssl/Makefile.bak openssl/crypto/cryptlib.c
Diffstat (limited to 'openssl/demos/cms')
-rw-r--r--openssl/demos/cms/cms_comp.c79
-rw-r--r--openssl/demos/cms/cms_ddec.c120
-rw-r--r--openssl/demos/cms/cms_dec.c103
-rw-r--r--openssl/demos/cms/cms_denc.c133
-rw-r--r--openssl/demos/cms/cms_enc.c126
-rw-r--r--openssl/demos/cms/cms_sign.c119
-rw-r--r--openssl/demos/cms/cms_sign2.c129
-rw-r--r--openssl/demos/cms/cms_uncomp.c69
-rw-r--r--openssl/demos/cms/cms_ver.c110
9 files changed, 491 insertions, 497 deletions
diff --git a/openssl/demos/cms/cms_comp.c b/openssl/demos/cms/cms_comp.c
index 01bf09254..059152fe0 100644
--- a/openssl/demos/cms/cms_comp.c
+++ b/openssl/demos/cms/cms_comp.c
@@ -4,58 +4,57 @@
#include <openssl/err.h>
int main(int argc, char **argv)
- {
- BIO *in = NULL, *out = NULL;
- CMS_ContentInfo *cms = NULL;
- int ret = 1;
+{
+ BIO *in = NULL, *out = NULL;
+ CMS_ContentInfo *cms = NULL;
+ int ret = 1;
- /*
- * On OpenSSL 1.0.0+ only:
- * for streaming set CMS_STREAM
- */
- int flags = CMS_STREAM;
+ /*
+ * On OpenSSL 1.0.0+ only:
+ * for streaming set CMS_STREAM
+ */
+ int flags = CMS_STREAM;
- OpenSSL_add_all_algorithms();
- ERR_load_crypto_strings();
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
- /* Open content being compressed */
+ /* Open content being compressed */
- in = BIO_new_file("comp.txt", "r");
+ in = BIO_new_file("comp.txt", "r");
- if (!in)
- goto err;
+ if (!in)
+ goto err;
- /* compress content */
- cms = CMS_compress(in, NID_zlib_compression, flags);
+ /* compress content */
+ cms = CMS_compress(in, NID_zlib_compression, flags);
- if (!cms)
- goto err;
+ if (!cms)
+ goto err;
- out = BIO_new_file("smcomp.txt", "w");
- if (!out)
- goto err;
+ out = BIO_new_file("smcomp.txt", "w");
+ if (!out)
+ goto err;
- /* Write out S/MIME message */
- if (!SMIME_write_CMS(out, cms, in, flags))
- goto err;
+ /* Write out S/MIME message */
+ if (!SMIME_write_CMS(out, cms, in, flags))
+ goto err;
- ret = 0;
+ ret = 0;
- err:
+ err:
- if (ret)
- {
- fprintf(stderr, "Error Compressing Data\n");
- ERR_print_errors_fp(stderr);
- }
+ if (ret) {
+ fprintf(stderr, "Error Compressing Data\n");
+ ERR_print_errors_fp(stderr);
+ }
- if (cms)
- CMS_ContentInfo_free(cms);
- if (in)
- BIO_free(in);
- if (out)
- BIO_free(out);
+ if (cms)
+ CMS_ContentInfo_free(cms);
+ if (in)
+ BIO_free(in);
+ if (out)
+ BIO_free(out);
- return ret;
+ return ret;
- }
+}
diff --git a/openssl/demos/cms/cms_ddec.c b/openssl/demos/cms/cms_ddec.c
index ba68cfdf7..37ac97fd0 100644
--- a/openssl/demos/cms/cms_ddec.c
+++ b/openssl/demos/cms/cms_ddec.c
@@ -1,89 +1,89 @@
-/* S/MIME detached data decrypt example: rarely done but
- * should the need arise this is an example....
+/*
+ * S/MIME detached data decrypt example: rarely done but should the need
+ * arise this is an example....
*/
#include <openssl/pem.h>
#include <openssl/cms.h>
#include <openssl/err.h>
int main(int argc, char **argv)
- {
- BIO *in = NULL, *out = NULL, *tbio = NULL, *dcont = NULL;
- X509 *rcert = NULL;
- EVP_PKEY *rkey = NULL;
- CMS_ContentInfo *cms = NULL;
- int ret = 1;
+{
+ BIO *in = NULL, *out = NULL, *tbio = NULL, *dcont = NULL;
+ X509 *rcert = NULL;
+ EVP_PKEY *rkey = NULL;
+ CMS_ContentInfo *cms = NULL;
+ int ret = 1;
- OpenSSL_add_all_algorithms();
- ERR_load_crypto_strings();
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
- /* Read in recipient certificate and private key */
- tbio = BIO_new_file("signer.pem", "r");
+ /* Read in recipient certificate and private key */
+ tbio = BIO_new_file("signer.pem", "r");
- if (!tbio)
- goto err;
+ if (!tbio)
+ goto err;
- rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+ rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
- BIO_reset(tbio);
+ BIO_reset(tbio);
- rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+ rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
- if (!rcert || !rkey)
- goto err;
+ if (!rcert || !rkey)
+ goto err;
- /* Open PEM file containing enveloped data */
+ /* Open PEM file containing enveloped data */
- in = BIO_new_file("smencr.pem", "r");
+ in = BIO_new_file("smencr.pem", "r");
- if (!in)
- goto err;
+ if (!in)
+ goto err;
- /* Parse PEM content */
- cms = PEM_read_bio_CMS(in, NULL, 0, NULL);
+ /* Parse PEM content */
+ cms = PEM_read_bio_CMS(in, NULL, 0, NULL);
- if (!cms)
- goto err;
+ if (!cms)
+ goto err;
- /* Open file containing detached content */
- dcont = BIO_new_file("smencr.out", "rb");
+ /* Open file containing detached content */
+ dcont = BIO_new_file("smencr.out", "rb");
- if (!in)
- goto err;
+ if (!in)
+ goto err;
- out = BIO_new_file("encrout.txt", "w");
- if (!out)
- goto err;
+ out = BIO_new_file("encrout.txt", "w");
+ if (!out)
+ goto err;
- /* Decrypt S/MIME message */
- if (!CMS_decrypt(cms, rkey, rcert, dcont, out, 0))
- goto err;
+ /* Decrypt S/MIME message */
+ if (!CMS_decrypt(cms, rkey, rcert, dcont, out, 0))
+ goto err;
- ret = 0;
+ ret = 0;
- err:
+ err:
- if (ret)
- {
- fprintf(stderr, "Error Decrypting Data\n");
- ERR_print_errors_fp(stderr);
- }
+ if (ret) {
+ fprintf(stderr, "Error Decrypting Data\n");
+ ERR_print_errors_fp(stderr);
+ }
- if (cms)
- CMS_ContentInfo_free(cms);
- if (rcert)
- X509_free(rcert);
- if (rkey)
- EVP_PKEY_free(rkey);
+ if (cms)
+ CMS_ContentInfo_free(cms);
+ if (rcert)
+ X509_free(rcert);
+ if (rkey)
+ EVP_PKEY_free(rkey);
- if (in)
- BIO_free(in);
- if (out)
- BIO_free(out);
- if (tbio)
- BIO_free(tbio);
- if (dcont)
- BIO_free(dcont);
+ if (in)
+ BIO_free(in);
+ if (out)
+ BIO_free(out);
+ if (tbio)
+ BIO_free(tbio);
+ if (dcont)
+ BIO_free(dcont);
- return ret;
+ return ret;
- }
+}
diff --git a/openssl/demos/cms/cms_dec.c b/openssl/demos/cms/cms_dec.c
index 9fee0a3eb..3291eacab 100644
--- a/openssl/demos/cms/cms_dec.c
+++ b/openssl/demos/cms/cms_dec.c
@@ -4,76 +4,75 @@
#include <openssl/err.h>
int main(int argc, char **argv)
- {
- BIO *in = NULL, *out = NULL, *tbio = NULL;
- X509 *rcert = NULL;
- EVP_PKEY *rkey = NULL;
- CMS_ContentInfo *cms = NULL;
- int ret = 1;
+{
+ BIO *in = NULL, *out = NULL, *tbio = NULL;
+ X509 *rcert = NULL;
+ EVP_PKEY *rkey = NULL;
+ CMS_ContentInfo *cms = NULL;
+ int ret = 1;
- OpenSSL_add_all_algorithms();
- ERR_load_crypto_strings();
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
- /* Read in recipient certificate and private key */
- tbio = BIO_new_file("signer.pem", "r");
+ /* Read in recipient certificate and private key */
+ tbio = BIO_new_file("signer.pem", "r");
- if (!tbio)
- goto err;
+ if (!tbio)
+ goto err;
- rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+ rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
- BIO_reset(tbio);
+ BIO_reset(tbio);
- rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+ rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
- if (!rcert || !rkey)
- goto err;
+ if (!rcert || !rkey)
+ goto err;
- /* Open S/MIME message to decrypt */
+ /* Open S/MIME message to decrypt */
- in = BIO_new_file("smencr.txt", "r");
+ in = BIO_new_file("smencr.txt", "r");
- if (!in)
- goto err;
+ if (!in)
+ goto err;
- /* Parse message */
- cms = SMIME_read_CMS(in, NULL);
+ /* Parse message */
+ cms = SMIME_read_CMS(in, NULL);
- if (!cms)
- goto err;
+ if (!cms)
+ goto err;
- out = BIO_new_file("decout.txt", "w");
- if (!out)
- goto err;
+ out = BIO_new_file("decout.txt", "w");
+ if (!out)
+ goto err;
- /* Decrypt S/MIME message */
- if (!CMS_decrypt(cms, rkey, rcert, NULL, out, 0))
- goto err;
+ /* Decrypt S/MIME message */
+ if (!CMS_decrypt(cms, rkey, rcert, NULL, out, 0))
+ goto err;
- ret = 0;
+ ret = 0;
- err:
+ err:
- if (ret)
- {
- fprintf(stderr, "Error Decrypting Data\n");
- ERR_print_errors_fp(stderr);
- }
+ if (ret) {
+ fprintf(stderr, "Error Decrypting Data\n");
+ ERR_print_errors_fp(stderr);
+ }
- if (cms)
- CMS_ContentInfo_free(cms);
- if (rcert)
- X509_free(rcert);
- if (rkey)
- EVP_PKEY_free(rkey);
+ if (cms)
+ CMS_ContentInfo_free(cms);
+ if (rcert)
+ X509_free(rcert);
+ if (rkey)
+ EVP_PKEY_free(rkey);
- if (in)
- BIO_free(in);
- if (out)
- BIO_free(out);
- if (tbio)
- BIO_free(tbio);
+ if (in)
+ BIO_free(in);
+ if (out)
+ BIO_free(out);
+ if (tbio)
+ BIO_free(tbio);
- return ret;
+ return ret;
- }
+}
diff --git a/openssl/demos/cms/cms_denc.c b/openssl/demos/cms/cms_denc.c
index 9265e47bf..c86a5fd72 100644
--- a/openssl/demos/cms/cms_denc.c
+++ b/openssl/demos/cms/cms_denc.c
@@ -1,97 +1,98 @@
-/* S/MIME detached data encrypt example: rarely done but
- * should the need arise this is an example....
+/*
+ * S/MIME detached data encrypt example: rarely done but should the need
+ * arise this is an example....
*/
#include <openssl/pem.h>
#include <openssl/cms.h>
#include <openssl/err.h>
int main(int argc, char **argv)
- {
- BIO *in = NULL, *out = NULL, *tbio = NULL, *dout = NULL;
- X509 *rcert = NULL;
- STACK_OF(X509) *recips = NULL;
- CMS_ContentInfo *cms = NULL;
- int ret = 1;
+{
+ BIO *in = NULL, *out = NULL, *tbio = NULL, *dout = NULL;
+ X509 *rcert = NULL;
+ STACK_OF(X509) *recips = NULL;
+ CMS_ContentInfo *cms = NULL;
+ int ret = 1;
- int flags = CMS_STREAM|CMS_DETACHED;
+ int flags = CMS_STREAM | CMS_DETACHED;
- OpenSSL_add_all_algorithms();
- ERR_load_crypto_strings();
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
- /* Read in recipient certificate */
- tbio = BIO_new_file("signer.pem", "r");
+ /* Read in recipient certificate */
+ tbio = BIO_new_file("signer.pem", "r");
- if (!tbio)
- goto err;
+ if (!tbio)
+ goto err;
- rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+ rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
- if (!rcert)
- goto err;
+ if (!rcert)
+ goto err;
- /* Create recipient STACK and add recipient cert to it */
- recips = sk_X509_new_null();
+ /* Create recipient STACK and add recipient cert to it */
+ recips = sk_X509_new_null();
- if (!recips || !sk_X509_push(recips, rcert))
- goto err;
+ if (!recips || !sk_X509_push(recips, rcert))
+ goto err;
- /* sk_X509_pop_free will free up recipient STACK and its contents
- * so set rcert to NULL so it isn't freed up twice.
- */
- rcert = NULL;
+ /*
+ * sk_X509_pop_free will free up recipient STACK and its contents so set
+ * rcert to NULL so it isn't freed up twice.
+ */
+ rcert = NULL;
- /* Open content being encrypted */
+ /* Open content being encrypted */
- in = BIO_new_file("encr.txt", "r");
+ in = BIO_new_file("encr.txt", "r");
- dout = BIO_new_file("smencr.out", "wb");
+ dout = BIO_new_file("smencr.out", "wb");
- if (!in)
- goto err;
+ if (!in)
+ goto err;
- /* encrypt content */
- cms = CMS_encrypt(recips, in, EVP_des_ede3_cbc(), flags);
+ /* encrypt content */
+ cms = CMS_encrypt(recips, in, EVP_des_ede3_cbc(), flags);
- if (!cms)
- goto err;
+ if (!cms)
+ goto err;
- out = BIO_new_file("smencr.pem", "w");
- if (!out)
- goto err;
+ out = BIO_new_file("smencr.pem", "w");
+ if (!out)
+ goto err;
- if (!CMS_final(cms, in, dout, flags))
- goto err;
+ if (!CMS_final(cms, in, dout, flags))
+ goto err;
- /* Write out CMS structure without content */
- if (!PEM_write_bio_CMS(out, cms))
- goto err;
+ /* Write out CMS structure without content */
+ if (!PEM_write_bio_CMS(out, cms))
+ goto err;
- ret = 0;
+ ret = 0;
- err:
+ err:
- if (ret)
- {
- fprintf(stderr, "Error Encrypting Data\n");
- ERR_print_errors_fp(stderr);
- }
+ if (ret) {
+ fprintf(stderr, "Error Encrypting Data\n");
+ ERR_print_errors_fp(stderr);
+ }
- if (cms)
- CMS_ContentInfo_free(cms);
- if (rcert)
- X509_free(rcert);
- if (recips)
- sk_X509_pop_free(recips, X509_free);
+ if (cms)
+ CMS_ContentInfo_free(cms);
+ if (rcert)
+ X509_free(rcert);
+ if (recips)
+ sk_X509_pop_free(recips, X509_free);
- if (in)
- BIO_free(in);
- if (out)
- BIO_free(out);
- if (dout)
- BIO_free(dout);
- if (tbio)
- BIO_free(tbio);
+ if (in)
+ BIO_free(in);
+ if (out)
+ BIO_free(out);
+ if (dout)
+ BIO_free(dout);
+ if (tbio)
+ BIO_free(tbio);
- return ret;
+ return ret;
- }
+}
diff --git a/openssl/demos/cms/cms_enc.c b/openssl/demos/cms/cms_enc.c
index 916b479d3..e8ecb48e2 100644
--- a/openssl/demos/cms/cms_enc.c
+++ b/openssl/demos/cms/cms_enc.c
@@ -4,89 +4,89 @@
#include <openssl/err.h>
int main(int argc, char **argv)
- {
- BIO *in = NULL, *out = NULL, *tbio = NULL;
- X509 *rcert = NULL;
- STACK_OF(X509) *recips = NULL;
- CMS_ContentInfo *cms = NULL;
- int ret = 1;
+{
+ BIO *in = NULL, *out = NULL, *tbio = NULL;
+ X509 *rcert = NULL;
+ STACK_OF(X509) *recips = NULL;
+ CMS_ContentInfo *cms = NULL;
+ int ret = 1;
- /*
- * On OpenSSL 1.0.0 and later only:
- * for streaming set CMS_STREAM
- */
- int flags = CMS_STREAM;
+ /*
+ * On OpenSSL 1.0.0 and later only:
+ * for streaming set CMS_STREAM
+ */
+ int flags = CMS_STREAM;
- OpenSSL_add_all_algorithms();
- ERR_load_crypto_strings();
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
- /* Read in recipient certificate */
- tbio = BIO_new_file("signer.pem", "r");
+ /* Read in recipient certificate */
+ tbio = BIO_new_file("signer.pem", "r");
- if (!tbio)
- goto err;
+ if (!tbio)
+ goto err;
- rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+ rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
- if (!rcert)
- goto err;
+ if (!rcert)
+ goto err;
- /* Create recipient STACK and add recipient cert to it */
- recips = sk_X509_new_null();
+ /* Create recipient STACK and add recipient cert to it */
+ recips = sk_X509_new_null();
- if (!recips || !sk_X509_push(recips, rcert))
- goto err;
+ if (!recips || !sk_X509_push(recips, rcert))
+ goto err;
- /* sk_X509_pop_free will free up recipient STACK and its contents
- * so set rcert to NULL so it isn't freed up twice.
- */
- rcert = NULL;
+ /*
+ * sk_X509_pop_free will free up recipient STACK and its contents so set
+ * rcert to NULL so it isn't freed up twice.
+ */
+ rcert = NULL;
- /* Open content being encrypted */
+ /* Open content being encrypted */
- in = BIO_new_file("encr.txt", "r");
+ in = BIO_new_file("encr.txt", "r");
- if (!in)
- goto err;
+ if (!in)
+ goto err;
- /* encrypt content */
- cms = CMS_encrypt(recips, in, EVP_des_ede3_cbc(), flags);
+ /* encrypt content */
+ cms = CMS_encrypt(recips, in, EVP_des_ede3_cbc(), flags);
- if (!cms)
- goto err;
+ if (!cms)
+ goto err;
- out = BIO_new_file("smencr.txt", "w");
- if (!out)
- goto err;
+ out = BIO_new_file("smencr.txt", "w");
+ if (!out)
+ goto err;
- /* Write out S/MIME message */
- if (!SMIME_write_CMS(out, cms, in, flags))
- goto err;
+ /* Write out S/MIME message */
+ if (!SMIME_write_CMS(out, cms, in, flags))
+ goto err;
- ret = 0;
+ ret = 0;
- err:
+ err:
- if (ret)
- {
- fprintf(stderr, "Error Encrypting Data\n");
- ERR_print_errors_fp(stderr);
- }
+ if (ret) {
+ fprintf(stderr, "Error Encrypting Data\n");
+ ERR_print_errors_fp(stderr);
+ }
- if (cms)
- CMS_ContentInfo_free(cms);
- if (rcert)
- X509_free(rcert);
- if (recips)
- sk_X509_pop_free(recips, X509_free);
+ if (cms)
+ CMS_ContentInfo_free(cms);
+ if (rcert)
+ X509_free(rcert);
+ if (recips)
+ sk_X509_pop_free(recips, X509_free);
- if (in)
- BIO_free(in);
- if (out)
- BIO_free(out);
- if (tbio)
- BIO_free(tbio);
+ if (in)
+ BIO_free(in);
+ if (out)
+ BIO_free(out);
+ if (tbio)
+ BIO_free(tbio);
- return ret;
+ return ret;
- }
+}
diff --git a/openssl/demos/cms/cms_sign.c b/openssl/demos/cms/cms_sign.c
index 6823c34a0..4bf85d138 100644
--- a/openssl/demos/cms/cms_sign.c
+++ b/openssl/demos/cms/cms_sign.c
@@ -4,86 +4,85 @@
#include <openssl/err.h>
int main(int argc, char **argv)
- {
- BIO *in = NULL, *out = NULL, *tbio = NULL;
- X509 *scert = NULL;
- EVP_PKEY *skey = NULL;
- CMS_ContentInfo *cms = NULL;
- int ret = 1;
+{
+ BIO *in = NULL, *out = NULL, *tbio = NULL;
+ X509 *scert = NULL;
+ EVP_PKEY *skey = NULL;
+ CMS_ContentInfo *cms = NULL;
+ int ret = 1;
- /* For simple S/MIME signing use CMS_DETACHED.
- * On OpenSSL 1.0.0 only:
- * for streaming detached set CMS_DETACHED|CMS_STREAM
- * for streaming non-detached set CMS_STREAM
- */
- int flags = CMS_DETACHED|CMS_STREAM;
+ /*
+ * For simple S/MIME signing use CMS_DETACHED. On OpenSSL 1.0.0 only: for
+ * streaming detached set CMS_DETACHED|CMS_STREAM for streaming
+ * non-detached set CMS_STREAM
+ */
+ int flags = CMS_DETACHED | CMS_STREAM;
- OpenSSL_add_all_algorithms();
- ERR_load_crypto_strings();
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
- /* Read in signer certificate and private key */
- tbio = BIO_new_file("signer.pem", "r");
+ /* Read in signer certificate and private key */
+ tbio = BIO_new_file("signer.pem", "r");
- if (!tbio)
- goto err;
+ if (!tbio)
+ goto err;
- scert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+ scert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
- BIO_reset(tbio);
+ BIO_reset(tbio);
- skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+ skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
- if (!scert || !skey)
- goto err;
+ if (!scert || !skey)
+ goto err;
- /* Open content being signed */
+ /* Open content being signed */
- in = BIO_new_file("sign.txt", "r");
+ in = BIO_new_file("sign.txt", "r");
- if (!in)
- goto err;
+ if (!in)
+ goto err;
- /* Sign content */
- cms = CMS_sign(scert, skey, NULL, in, flags);
+ /* Sign content */
+ cms = CMS_sign(scert, skey, NULL, in, flags);
- if (!cms)
- goto err;
+ if (!cms)
+ goto err;
- out = BIO_new_file("smout.txt", "w");
- if (!out)
- goto err;
+ out = BIO_new_file("smout.txt", "w");
+ if (!out)
+ goto err;
- if (!(flags & CMS_STREAM))
- BIO_reset(in);
+ if (!(flags & CMS_STREAM))
+ BIO_reset(in);
- /* Write out S/MIME message */
- if (!SMIME_write_CMS(out, cms, in, flags))
- goto err;
+ /* Write out S/MIME message */
+ if (!SMIME_write_CMS(out, cms, in, flags))
+ goto err;
- ret = 0;
+ ret = 0;
- err:
+ err:
- if (ret)
- {
- fprintf(stderr, "Error Signing Data\n");
- ERR_print_errors_fp(stderr);
- }
+ if (ret) {
+ fprintf(stderr, "Error Signing Data\n");
+ ERR_print_errors_fp(stderr);
+ }
- if (cms)
- CMS_ContentInfo_free(cms);
- if (scert)
- X509_free(scert);
- if (skey)
- EVP_PKEY_free(skey);
+ if (cms)
+ CMS_ContentInfo_free(cms);
+ if (scert)
+ X509_free(scert);
+ if (skey)
+ EVP_PKEY_free(skey);
- if (in)
- BIO_free(in);
- if (out)
- BIO_free(out);
- if (tbio)
- BIO_free(tbio);
+ if (in)
+ BIO_free(in);
+ if (out)
+ BIO_free(out);
+ if (tbio)
+ BIO_free(tbio);
- return ret;
+ return ret;
- }
+}
diff --git a/openssl/demos/cms/cms_sign2.c b/openssl/demos/cms/cms_sign2.c
index 36adee730..7e98a5171 100644
--- a/openssl/demos/cms/cms_sign2.c
+++ b/openssl/demos/cms/cms_sign2.c
@@ -4,100 +4,99 @@
#include <openssl/err.h>
int main(int argc, char **argv)
- {
- BIO *in = NULL, *out = NULL, *tbio = NULL;
- X509 *scert = NULL, *scert2 = NULL;
- EVP_PKEY *skey = NULL, *skey2 = NULL;
- CMS_ContentInfo *cms = NULL;
- int ret = 1;
+{
+ BIO *in = NULL, *out = NULL, *tbio = NULL;
+ X509 *scert = NULL, *scert2 = NULL;
+ EVP_PKEY *skey = NULL, *skey2 = NULL;
+ CMS_ContentInfo *cms = NULL;
+ int ret = 1;
- OpenSSL_add_all_algorithms();
- ERR_load_crypto_strings();
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
- tbio = BIO_new_file("signer.pem", "r");
+ tbio = BIO_new_file("signer.pem", "r");
- if (!tbio)
- goto err;
+ if (!tbio)
+ goto err;
- scert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+ scert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
- BIO_reset(tbio);
+ BIO_reset(tbio);
- skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+ skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
- BIO_free(tbio);
+ BIO_free(tbio);
- tbio = BIO_new_file("signer2.pem", "r");
+ tbio = BIO_new_file("signer2.pem", "r");
- if (!tbio)
- goto err;
+ if (!tbio)
+ goto err;
- scert2 = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+ scert2 = PEM_read_bio_X509(tbio, NULL, 0, NULL);
- BIO_reset(tbio);
+ BIO_reset(tbio);
- skey2 = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+ skey2 = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
- if (!scert2 || !skey2)
- goto err;
+ if (!scert2 || !skey2)
+ goto err;
- in = BIO_new_file("sign.txt", "r");
+ in = BIO_new_file("sign.txt", "r");
- if (!in)
- goto err;
+ if (!in)
+ goto err;
- cms = CMS_sign(NULL, NULL, NULL, in, CMS_STREAM|CMS_PARTIAL);
+ cms = CMS_sign(NULL, NULL, NULL, in, CMS_STREAM | CMS_PARTIAL);
- if (!cms)
- goto err;
+ if (!cms)
+ goto err;
- /* Add each signer in turn */
+ /* Add each signer in turn */
- if (!CMS_add1_signer(cms, scert, skey, NULL, 0))
- goto err;
+ if (!CMS_add1_signer(cms, scert, skey, NULL, 0))
+ goto err;
- if (!CMS_add1_signer(cms, scert2, skey2, NULL, 0))
- goto err;
+ if (!CMS_add1_signer(cms, scert2, skey2, NULL, 0))
+ goto err;
- out = BIO_new_file("smout.txt", "w");
- if (!out)
- goto err;
+ out = BIO_new_file("smout.txt", "w");
+ if (!out)
+ goto err;
- /* NB: content included and finalized by SMIME_write_CMS */
+ /* NB: content included and finalized by SMIME_write_CMS */
- if (!SMIME_write_CMS(out, cms, in, CMS_STREAM))
- goto err;
+ if (!SMIME_write_CMS(out, cms, in, CMS_STREAM))
+ goto err;
- ret = 0;
+ ret = 0;
- err:
+ err:
- if (ret)
- {
- fprintf(stderr, "Error Signing Data\n");
- ERR_print_errors_fp(stderr);
- }
+ if (ret) {
+ fprintf(stderr, "Error Signing Data\n");
+ ERR_print_errors_fp(stderr);
+ }
- if (cms)
- CMS_ContentInfo_free(cms);
+ if (cms)
+ CMS_ContentInfo_free(cms);
- if (scert)
- X509_free(scert);
- if (skey)
- EVP_PKEY_free(skey);
+ if (scert)
+ X509_free(scert);
+ if (skey)
+ EVP_PKEY_free(skey);
- if (scert2)
- X509_free(scert2);
- if (skey)
- EVP_PKEY_free(skey2);
+ if (scert2)
+ X509_free(scert2);
+ if (skey)
+ EVP_PKEY_free(skey2);
- if (in)
- BIO_free(in);
- if (out)
- BIO_free(out);
- if (tbio)
- BIO_free(tbio);
+ if (in)
+ BIO_free(in);
+ if (out)
+ BIO_free(out);
+ if (tbio)
+ BIO_free(tbio);
- return ret;
+ return ret;
- }
+}
diff --git a/openssl/demos/cms/cms_uncomp.c b/openssl/demos/cms/cms_uncomp.c
index f15ae2f13..392f4b450 100644
--- a/openssl/demos/cms/cms_uncomp.c
+++ b/openssl/demos/cms/cms_uncomp.c
@@ -4,53 +4,52 @@
#include <openssl/err.h>
int main(int argc, char **argv)
- {
- BIO *in = NULL, *out = NULL;
- CMS_ContentInfo *cms = NULL;
- int ret = 1;
+{
+ BIO *in = NULL, *out = NULL;
+ CMS_ContentInfo *cms = NULL;
+ int ret = 1;
- OpenSSL_add_all_algorithms();
- ERR_load_crypto_strings();
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
- /* Open compressed content */
+ /* Open compressed content */
- in = BIO_new_file("smcomp.txt", "r");
+ in = BIO_new_file("smcomp.txt", "r");
- if (!in)
- goto err;
+ if (!in)
+ goto err;
- /* Sign content */
- cms = SMIME_read_CMS(in, NULL);
+ /* Sign content */
+ cms = SMIME_read_CMS(in, NULL);
- if (!cms)
- goto err;
+ if (!cms)
+ goto err;
- out = BIO_new_file("smuncomp.txt", "w");
- if (!out)
- goto err;
+ out = BIO_new_file("smuncomp.txt", "w");
+ if (!out)
+ goto err;
- /* Uncompress S/MIME message */
- if (!CMS_uncompress(cms, out, NULL, 0))
- goto err;
+ /* Uncompress S/MIME message */
+ if (!CMS_uncompress(cms, out, NULL, 0))
+ goto err;
- ret = 0;
+ ret = 0;
- err:
+ err:
- if (ret)
- {
- fprintf(stderr, "Error Uncompressing Data\n");
- ERR_print_errors_fp(stderr);
- }
+ if (ret) {
+ fprintf(stderr, "Error Uncompressing Data\n");
+ ERR_print_errors_fp(stderr);
+ }
- if (cms)
- CMS_ContentInfo_free(cms);
+ if (cms)
+ CMS_ContentInfo_free(cms);
- if (in)
- BIO_free(in);
- if (out)
- BIO_free(out);
+ if (in)
+ BIO_free(in);
+ if (out)
+ BIO_free(out);
- return ret;
+ return ret;
- }
+}
diff --git a/openssl/demos/cms/cms_ver.c b/openssl/demos/cms/cms_ver.c
index bf1145ed8..ca935517a 100644
--- a/openssl/demos/cms/cms_ver.c
+++ b/openssl/demos/cms/cms_ver.c
@@ -4,84 +4,82 @@
#include <openssl/err.h>
int main(int argc, char **argv)
- {
- BIO *in = NULL, *out = NULL, *tbio = NULL, *cont = NULL;
- X509_STORE *st = NULL;
- X509 *cacert = NULL;
- CMS_ContentInfo *cms = NULL;
+{
+ BIO *in = NULL, *out = NULL, *tbio = NULL, *cont = NULL;
+ X509_STORE *st = NULL;
+ X509 *cacert = NULL;
+ CMS_ContentInfo *cms = NULL;
- int ret = 1;
+ int ret = 1;
- OpenSSL_add_all_algorithms();
- ERR_load_crypto_strings();
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
- /* Set up trusted CA certificate store */
+ /* Set up trusted CA certificate store */
- st = X509_STORE_new();
+ st = X509_STORE_new();
- /* Read in CA certificate */
- tbio = BIO_new_file("cacert.pem", "r");
+ /* Read in CA certificate */
+ tbio = BIO_new_file("cacert.pem", "r");
- if (!tbio)
- goto err;
+ if (!tbio)
+ goto err;
- cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+ cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
- if (!cacert)
- goto err;
+ if (!cacert)
+ goto err;
- if (!X509_STORE_add_cert(st, cacert))
- goto err;
+ if (!X509_STORE_add_cert(st, cacert))
+ goto err;
- /* Open message being verified */
+ /* Open message being verified */
- in = BIO_new_file("smout.txt", "r");
+ in = BIO_new_file("smout.txt", "r");
- if (!in)
- goto err;
+ if (!in)
+ goto err;
- /* parse message */
- cms = SMIME_read_CMS(in, &cont);
+ /* parse message */
+ cms = SMIME_read_CMS(in, &cont);
- if (!cms)
- goto err;
+ if (!cms)
+ goto err;
- /* File to output verified content to */
- out = BIO_new_file("smver.txt", "w");
- if (!out)
- goto err;
+ /* File to output verified content to */
+ out = BIO_new_file("smver.txt", "w");
+ if (!out)
+ goto err;
- if (!CMS_verify(cms, NULL, st, cont, out, 0))
- {
- fprintf(stderr, "Verification Failure\n");
- goto err;
- }
+ if (!CMS_verify(cms, NULL, st, cont, out, 0)) {
+ fprintf(stderr, "Verification Failure\n");
+ goto err;
+ }
- fprintf(stderr, "Verification Successful\n");
+ fprintf(stderr, "Verification Successful\n");
- ret = 0;
+ ret = 0;
- err:
+ err:
- if (ret)
- {
- fprintf(stderr, "Error Verifying Data\n");
- ERR_print_errors_fp(stderr);
- }
+ if (ret) {
+ fprintf(stderr, "Error Verifying Data\n");
+ ERR_print_errors_fp(stderr);
+ }
- if (cms)
- CMS_ContentInfo_free(cms);
+ if (cms)
+ CMS_ContentInfo_free(cms);
- if (cacert)
- X509_free(cacert);
+ if (cacert)
+ X509_free(cacert);
- if (in)
- BIO_free(in);
- if (out)
- BIO_free(out);
- if (tbio)
- BIO_free(tbio);
+ if (in)
+ BIO_free(in);
+ if (out)
+ BIO_free(out);
+ if (tbio)
+ BIO_free(tbio);
- return ret;
+ return ret;
- }
+}