aboutsummaryrefslogtreecommitdiff
path: root/openssl-1.1.0h/demos/cms
diff options
context:
space:
mode:
Diffstat (limited to 'openssl-1.1.0h/demos/cms')
-rw-r--r--openssl-1.1.0h/demos/cms/cacert.pem18
-rw-r--r--openssl-1.1.0h/demos/cms/cakey.pem15
-rw-r--r--openssl-1.1.0h/demos/cms/cms_comp.c64
-rw-r--r--openssl-1.1.0h/demos/cms/cms_ddec.c88
-rw-r--r--openssl-1.1.0h/demos/cms/cms_dec.c78
-rw-r--r--openssl-1.1.0h/demos/cms/cms_denc.c97
-rw-r--r--openssl-1.1.0h/demos/cms/cms_enc.c92
-rw-r--r--openssl-1.1.0h/demos/cms/cms_sign.c88
-rw-r--r--openssl-1.1.0h/demos/cms/cms_sign2.c98
-rw-r--r--openssl-1.1.0h/demos/cms/cms_uncomp.c58
-rw-r--r--openssl-1.1.0h/demos/cms/cms_ver.c85
-rw-r--r--openssl-1.1.0h/demos/cms/comp.txt22
-rw-r--r--openssl-1.1.0h/demos/cms/encr.txt3
-rw-r--r--openssl-1.1.0h/demos/cms/sign.txt3
-rw-r--r--openssl-1.1.0h/demos/cms/signer.pem32
-rw-r--r--openssl-1.1.0h/demos/cms/signer2.pem32
16 files changed, 873 insertions, 0 deletions
diff --git a/openssl-1.1.0h/demos/cms/cacert.pem b/openssl-1.1.0h/demos/cms/cacert.pem
new file mode 100644
index 0000000..75cbb34
--- /dev/null
+++ b/openssl-1.1.0h/demos/cms/cacert.pem
@@ -0,0 +1,18 @@
+-----BEGIN CERTIFICATE-----
+MIIC6DCCAlGgAwIBAgIJAMfGO3rdo2uUMA0GCSqGSIb3DQEBBAUAMFcxCzAJBgNV
+BAYTAlVLMRIwEAYDVQQHEwlUZXN0IENpdHkxFjAUBgNVBAoTDU9wZW5TU0wgR3Jv
+dXAxHDAaBgNVBAMTE1Rlc3QgUy9NSU1FIFJvb3QgQ0EwHhcNMDcwNDEzMTc0MzE3
+WhcNMTcwNDEwMTc0MzE3WjBXMQswCQYDVQQGEwJVSzESMBAGA1UEBxMJVGVzdCBD
+aXR5MRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMRwwGgYDVQQDExNUZXN0IFMvTUlN
+RSBSb290IENBMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqJMal1uC1/1wz
+i5+dE4EZF2im3BgROm5PVMbwPY9V1t+KYvtdc3rMcRgJaMbP+qaEcDXoIsZfYXGR
+ielgfDNZmZcj1y/FOum+Jc2OZMs3ggPmjIQ3dbBECq0hZKcbz7wfr+2OeNWm46iT
+jcSIXpGIRhUYEzOgv7zb8oOU70IbbwIDAQABo4G7MIG4MB0GA1UdDgQWBBRHUypx
+CXFQYqewhGo72lWPQUsjoDCBiAYDVR0jBIGAMH6AFEdTKnEJcVBip7CEajvaVY9B
+SyOgoVukWTBXMQswCQYDVQQGEwJVSzESMBAGA1UEBxMJVGVzdCBDaXR5MRYwFAYD
+VQQKEw1PcGVuU1NMIEdyb3VwMRwwGgYDVQQDExNUZXN0IFMvTUlNRSBSb290IENB
+ggkAx8Y7et2ja5QwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQQFAAOBgQANI+Yc
+G/YDM1WMUGEzEkU9UhsIUqdyBebnK3+OyxZSouDcE/M10jFJzBf/F5b0uUGAKWwo
+u0dzmILfKjdfWe8EyCRafZcm00rVcO09i/63FBYzlHbmfUATIqZdhKzxxQMPs5mF
+1je+pHUpzIY8TSXyh/uD9IkAy04IHwGZQf9akw==
+-----END CERTIFICATE-----
diff --git a/openssl-1.1.0h/demos/cms/cakey.pem b/openssl-1.1.0h/demos/cms/cakey.pem
new file mode 100644
index 0000000..3b53c5e
--- /dev/null
+++ b/openssl-1.1.0h/demos/cms/cakey.pem
@@ -0,0 +1,15 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIICXgIBAAKBgQCqJMal1uC1/1wzi5+dE4EZF2im3BgROm5PVMbwPY9V1t+KYvtd
+c3rMcRgJaMbP+qaEcDXoIsZfYXGRielgfDNZmZcj1y/FOum+Jc2OZMs3ggPmjIQ3
+dbBECq0hZKcbz7wfr+2OeNWm46iTjcSIXpGIRhUYEzOgv7zb8oOU70IbbwIDAQAB
+AoGBAKWOZ2UTc1BkjDjz0XoscmAR8Rj77MdGzfOPkIxPultSW+3yZpkGNyUbnsH5
+HAtf4Avai/m3bMN+s91kDpx9/g/I9ZEHPQLcDICETvwt/EHT7+hwvaQgsM+TgpMs
+tjlGZOWent6wVIuvwwzqOMXZLgK9FvY7upwgtrys4G3Kab5hAkEA2QzFflWyEvKS
+rMSaVtn/IjFilwa7H0IdakkjM34z4peerFTPBr4J47YD4RCR/dAvxyNy3zUxtH18
+9R6dUixI6QJBAMitJD0xOkbGWBX8KVJvRiKOIdf/95ZUAgN/h3bWKy57EB9NYj3u
+jbxXcvdjfSqiITykkjAg7SG7nrlzJsu6CpcCQG6gVsy0auXDY0TRlASuaZ6I40Is
+uRUOgqWYj2uAaHuWYdZeB4LdO3cnX0TISFDAWom6JKNlnmbrCtR4fSDT13kCQQCU
++VQJyV3F5MDHsWbLt6eNR46AV5lpk/vatPXPlrZ/zwPs+PmRmGLICvNiDA2DdNDP
+wCx2Zjsj67CtY3rNitMJAkEAm09BQnjnbBXUb1rd2SjNDWTsu80Z+zLu8pAwXNhW
+8nsvMYqlYMIxuMPwu/QuTnMRhMZ08uhqoD3ukZnBeoMEVg==
+-----END RSA PRIVATE KEY-----
diff --git a/openssl-1.1.0h/demos/cms/cms_comp.c b/openssl-1.1.0h/demos/cms/cms_comp.c
new file mode 100644
index 0000000..0d548f9
--- /dev/null
+++ b/openssl-1.1.0h/demos/cms/cms_comp.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+/* Simple S/MIME compress example */
+#include <openssl/pem.h>
+#include <openssl/cms.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+{
+ 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;
+
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
+
+ /* Open content being compressed */
+
+ in = BIO_new_file("comp.txt", "r");
+
+ if (!in)
+ goto err;
+
+ /* compress content */
+ cms = CMS_compress(in, NID_zlib_compression, flags);
+
+ if (!cms)
+ 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;
+
+ ret = 0;
+
+ err:
+
+ if (ret) {
+ fprintf(stderr, "Error Compressing Data\n");
+ ERR_print_errors_fp(stderr);
+ }
+
+ CMS_ContentInfo_free(cms);
+ BIO_free(in);
+ BIO_free(out);
+ return ret;
+}
diff --git a/openssl-1.1.0h/demos/cms/cms_ddec.c b/openssl-1.1.0h/demos/cms/cms_ddec.c
new file mode 100644
index 0000000..8f2e9ae
--- /dev/null
+++ b/openssl-1.1.0h/demos/cms/cms_ddec.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+/*
+ * 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;
+
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
+
+ /* Read in recipient certificate and private key */
+ tbio = BIO_new_file("signer.pem", "r");
+
+ if (!tbio)
+ goto err;
+
+ rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+ BIO_reset(tbio);
+
+ rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+
+ if (!rcert || !rkey)
+ goto err;
+
+ /* Open PEM file containing enveloped data */
+
+ in = BIO_new_file("smencr.pem", "r");
+
+ if (!in)
+ goto err;
+
+ /* Parse PEM content */
+ cms = PEM_read_bio_CMS(in, NULL, 0, NULL);
+
+ if (!cms)
+ goto err;
+
+ /* Open file containing detached content */
+ dcont = BIO_new_file("smencr.out", "rb");
+
+ if (!in)
+ 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;
+
+ ret = 0;
+
+ err:
+
+ if (ret) {
+ fprintf(stderr, "Error Decrypting Data\n");
+ ERR_print_errors_fp(stderr);
+ }
+
+ CMS_ContentInfo_free(cms);
+ X509_free(rcert);
+ EVP_PKEY_free(rkey);
+ BIO_free(in);
+ BIO_free(out);
+ BIO_free(tbio);
+ BIO_free(dcont);
+ return ret;
+}
diff --git a/openssl-1.1.0h/demos/cms/cms_dec.c b/openssl-1.1.0h/demos/cms/cms_dec.c
new file mode 100644
index 0000000..4f9428b
--- /dev/null
+++ b/openssl-1.1.0h/demos/cms/cms_dec.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+/* Simple S/MIME decryption 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;
+ X509 *rcert = NULL;
+ EVP_PKEY *rkey = NULL;
+ CMS_ContentInfo *cms = NULL;
+ int ret = 1;
+
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
+
+ /* Read in recipient certificate and private key */
+ tbio = BIO_new_file("signer.pem", "r");
+
+ if (!tbio)
+ goto err;
+
+ rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+ BIO_reset(tbio);
+
+ rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+
+ if (!rcert || !rkey)
+ goto err;
+
+ /* Open S/MIME message to decrypt */
+
+ in = BIO_new_file("smencr.txt", "r");
+
+ if (!in)
+ goto err;
+
+ /* Parse message */
+ cms = SMIME_read_CMS(in, NULL);
+
+ if (!cms)
+ 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;
+
+ ret = 0;
+
+ err:
+
+ if (ret) {
+ fprintf(stderr, "Error Decrypting Data\n");
+ ERR_print_errors_fp(stderr);
+ }
+
+ CMS_ContentInfo_free(cms);
+ X509_free(rcert);
+ EVP_PKEY_free(rkey);
+ BIO_free(in);
+ BIO_free(out);
+ BIO_free(tbio);
+ return ret;
+}
diff --git a/openssl-1.1.0h/demos/cms/cms_denc.c b/openssl-1.1.0h/demos/cms/cms_denc.c
new file mode 100644
index 0000000..adba69b
--- /dev/null
+++ b/openssl-1.1.0h/demos/cms/cms_denc.c
@@ -0,0 +1,97 @@
+/*
+ * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+/*
+ * 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;
+
+ int flags = CMS_STREAM | CMS_DETACHED;
+
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
+
+ /* Read in recipient certificate */
+ tbio = BIO_new_file("signer.pem", "r");
+
+ if (!tbio)
+ goto err;
+
+ rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+ if (!rcert)
+ goto err;
+
+ /* Create recipient STACK and add recipient cert to it */
+ recips = sk_X509_new_null();
+
+ 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;
+
+ /* Open content being encrypted */
+
+ in = BIO_new_file("encr.txt", "r");
+
+ dout = BIO_new_file("smencr.out", "wb");
+
+ if (!in)
+ goto err;
+
+ /* encrypt content */
+ cms = CMS_encrypt(recips, in, EVP_des_ede3_cbc(), flags);
+
+ if (!cms)
+ goto err;
+
+ out = BIO_new_file("smencr.pem", "w");
+ if (!out)
+ 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;
+
+ ret = 0;
+
+ err:
+
+ if (ret) {
+ fprintf(stderr, "Error Encrypting Data\n");
+ ERR_print_errors_fp(stderr);
+ }
+
+ CMS_ContentInfo_free(cms);
+ X509_free(rcert);
+ sk_X509_pop_free(recips, X509_free);
+ BIO_free(in);
+ BIO_free(out);
+ BIO_free(dout);
+ BIO_free(tbio);
+ return ret;
+}
diff --git a/openssl-1.1.0h/demos/cms/cms_enc.c b/openssl-1.1.0h/demos/cms/cms_enc.c
new file mode 100644
index 0000000..4d17d72
--- /dev/null
+++ b/openssl-1.1.0h/demos/cms/cms_enc.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+/* Simple S/MIME encrypt 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;
+ 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;
+
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
+
+ /* Read in recipient certificate */
+ tbio = BIO_new_file("signer.pem", "r");
+
+ if (!tbio)
+ goto err;
+
+ rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+ if (!rcert)
+ goto err;
+
+ /* Create recipient STACK and add recipient cert to it */
+ recips = sk_X509_new_null();
+
+ 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;
+
+ /* Open content being encrypted */
+
+ in = BIO_new_file("encr.txt", "r");
+
+ if (!in)
+ goto err;
+
+ /* encrypt content */
+ cms = CMS_encrypt(recips, in, EVP_des_ede3_cbc(), flags);
+
+ if (!cms)
+ 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;
+
+ ret = 0;
+
+ err:
+
+ if (ret) {
+ fprintf(stderr, "Error Encrypting Data\n");
+ ERR_print_errors_fp(stderr);
+ }
+
+ CMS_ContentInfo_free(cms);
+ X509_free(rcert);
+ sk_X509_pop_free(recips, X509_free);
+ BIO_free(in);
+ BIO_free(out);
+ BIO_free(tbio);
+ return ret;
+}
diff --git a/openssl-1.1.0h/demos/cms/cms_sign.c b/openssl-1.1.0h/demos/cms/cms_sign.c
new file mode 100644
index 0000000..15bd5b8
--- /dev/null
+++ b/openssl-1.1.0h/demos/cms/cms_sign.c
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+/* Simple S/MIME signing 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;
+ 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;
+
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
+
+ /* Read in signer certificate and private key */
+ tbio = BIO_new_file("signer.pem", "r");
+
+ if (!tbio)
+ goto err;
+
+ scert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+ BIO_reset(tbio);
+
+ skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+
+ if (!scert || !skey)
+ goto err;
+
+ /* Open content being signed */
+
+ in = BIO_new_file("sign.txt", "r");
+
+ if (!in)
+ goto err;
+
+ /* Sign content */
+ cms = CMS_sign(scert, skey, NULL, in, flags);
+
+ if (!cms)
+ goto err;
+
+ out = BIO_new_file("smout.txt", "w");
+ if (!out)
+ goto err;
+
+ if (!(flags & CMS_STREAM))
+ BIO_reset(in);
+
+ /* Write out S/MIME message */
+ if (!SMIME_write_CMS(out, cms, in, flags))
+ goto err;
+
+ ret = 0;
+
+ err:
+
+ if (ret) {
+ fprintf(stderr, "Error Signing Data\n");
+ ERR_print_errors_fp(stderr);
+ }
+
+ CMS_ContentInfo_free(cms);
+ X509_free(scert);
+ EVP_PKEY_free(skey);
+ BIO_free(in);
+ BIO_free(out);
+ BIO_free(tbio);
+ return ret;
+}
diff --git a/openssl-1.1.0h/demos/cms/cms_sign2.c b/openssl-1.1.0h/demos/cms/cms_sign2.c
new file mode 100644
index 0000000..14ebf27
--- /dev/null
+++ b/openssl-1.1.0h/demos/cms/cms_sign2.c
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+/* S/MIME signing example: 2 signers */
+#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;
+ 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();
+
+ tbio = BIO_new_file("signer.pem", "r");
+
+ if (!tbio)
+ goto err;
+
+ scert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+ BIO_reset(tbio);
+
+ skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+
+ BIO_free(tbio);
+
+ tbio = BIO_new_file("signer2.pem", "r");
+
+ if (!tbio)
+ goto err;
+
+ scert2 = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+ BIO_reset(tbio);
+
+ skey2 = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
+
+ if (!scert2 || !skey2)
+ goto err;
+
+ in = BIO_new_file("sign.txt", "r");
+
+ if (!in)
+ goto err;
+
+ cms = CMS_sign(NULL, NULL, NULL, in, CMS_STREAM | CMS_PARTIAL);
+
+ if (!cms)
+ goto err;
+
+ /* Add each signer in turn */
+
+ if (!CMS_add1_signer(cms, scert, skey, 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;
+
+ /* NB: content included and finalized by SMIME_write_CMS */
+
+ if (!SMIME_write_CMS(out, cms, in, CMS_STREAM))
+ goto err;
+
+ ret = 0;
+
+ err:
+
+ if (ret) {
+ fprintf(stderr, "Error Signing Data\n");
+ ERR_print_errors_fp(stderr);
+ }
+
+ CMS_ContentInfo_free(cms);
+ X509_free(scert);
+ EVP_PKEY_free(skey);
+ X509_free(scert2);
+ EVP_PKEY_free(skey2);
+ BIO_free(in);
+ BIO_free(out);
+ BIO_free(tbio);
+ return ret;
+}
diff --git a/openssl-1.1.0h/demos/cms/cms_uncomp.c b/openssl-1.1.0h/demos/cms/cms_uncomp.c
new file mode 100644
index 0000000..3e3b4c4
--- /dev/null
+++ b/openssl-1.1.0h/demos/cms/cms_uncomp.c
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+/* Simple S/MIME uncompression example */
+#include <openssl/pem.h>
+#include <openssl/cms.h>
+#include <openssl/err.h>
+
+int main(int argc, char **argv)
+{
+ BIO *in = NULL, *out = NULL;
+ CMS_ContentInfo *cms = NULL;
+ int ret = 1;
+
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
+
+ /* Open compressed content */
+
+ in = BIO_new_file("smcomp.txt", "r");
+
+ if (!in)
+ goto err;
+
+ /* Sign content */
+ cms = SMIME_read_CMS(in, NULL);
+
+ if (!cms)
+ 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;
+
+ ret = 0;
+
+ err:
+
+ if (ret) {
+ fprintf(stderr, "Error Uncompressing Data\n");
+ ERR_print_errors_fp(stderr);
+ }
+
+ CMS_ContentInfo_free(cms);
+ BIO_free(in);
+ BIO_free(out);
+ return ret;
+}
diff --git a/openssl-1.1.0h/demos/cms/cms_ver.c b/openssl-1.1.0h/demos/cms/cms_ver.c
new file mode 100644
index 0000000..43c10e2
--- /dev/null
+++ b/openssl-1.1.0h/demos/cms/cms_ver.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the OpenSSL license (the "License"). You may not use
+ * this file except in compliance with the License. You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+/* Simple S/MIME verification 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, *cont = NULL;
+ X509_STORE *st = NULL;
+ X509 *cacert = NULL;
+ CMS_ContentInfo *cms = NULL;
+
+ int ret = 1;
+
+ OpenSSL_add_all_algorithms();
+ ERR_load_crypto_strings();
+
+ /* Set up trusted CA certificate store */
+
+ st = X509_STORE_new();
+
+ /* Read in CA certificate */
+ tbio = BIO_new_file("cacert.pem", "r");
+
+ if (!tbio)
+ goto err;
+
+ cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
+
+ if (!cacert)
+ goto err;
+
+ if (!X509_STORE_add_cert(st, cacert))
+ goto err;
+
+ /* Open message being verified */
+
+ in = BIO_new_file("smout.txt", "r");
+
+ if (!in)
+ goto err;
+
+ /* parse message */
+ cms = SMIME_read_CMS(in, &cont);
+
+ if (!cms)
+ 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;
+ }
+
+ fprintf(stderr, "Verification Successful\n");
+
+ ret = 0;
+
+ err:
+
+ if (ret) {
+ fprintf(stderr, "Error Verifying Data\n");
+ ERR_print_errors_fp(stderr);
+ }
+
+ CMS_ContentInfo_free(cms);
+ X509_free(cacert);
+ BIO_free(in);
+ BIO_free(out);
+ BIO_free(tbio);
+ return ret;
+}
diff --git a/openssl-1.1.0h/demos/cms/comp.txt b/openssl-1.1.0h/demos/cms/comp.txt
new file mode 100644
index 0000000..1672328
--- /dev/null
+++ b/openssl-1.1.0h/demos/cms/comp.txt
@@ -0,0 +1,22 @@
+Content-type: text/plain
+
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
+Some Text To be Compressed
diff --git a/openssl-1.1.0h/demos/cms/encr.txt b/openssl-1.1.0h/demos/cms/encr.txt
new file mode 100644
index 0000000..0eceb40
--- /dev/null
+++ b/openssl-1.1.0h/demos/cms/encr.txt
@@ -0,0 +1,3 @@
+Content-type: text/plain
+
+Sample OpenSSL Data for CMS encryption
diff --git a/openssl-1.1.0h/demos/cms/sign.txt b/openssl-1.1.0h/demos/cms/sign.txt
new file mode 100644
index 0000000..c3f9d73
--- /dev/null
+++ b/openssl-1.1.0h/demos/cms/sign.txt
@@ -0,0 +1,3 @@
+Content-type: text/plain
+
+Test OpenSSL CMS Signed Content
diff --git a/openssl-1.1.0h/demos/cms/signer.pem b/openssl-1.1.0h/demos/cms/signer.pem
new file mode 100644
index 0000000..bac16ba
--- /dev/null
+++ b/openssl-1.1.0h/demos/cms/signer.pem
@@ -0,0 +1,32 @@
+-----BEGIN CERTIFICATE-----
+MIICpjCCAg+gAwIBAgIJAJ+rfmEoLQRhMA0GCSqGSIb3DQEBBAUAMFcxCzAJBgNV
+BAYTAlVLMRIwEAYDVQQHEwlUZXN0IENpdHkxFjAUBgNVBAoTDU9wZW5TU0wgR3Jv
+dXAxHDAaBgNVBAMTE1Rlc3QgUy9NSU1FIFJvb3QgQ0EwHhcNMDcwNDEzMTgyOTI3
+WhcNMTcwNDA5MTgyOTI3WjBWMQswCQYDVQQGEwJVSzElMCMGA1UEAxMcT3BlblNT
+TCB0ZXN0IFMvTUlNRSBzaWduZXIgMTEgMB4GCSqGSIb3DQEJARYRdGVzdDFAb3Bl
+bnNzbC5vcmcwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAL1ocAQ7ON2pIUXz
+jwKPzpPB9ozB6PFG6F6kARO+i0DiT6Qn8abUjwpHPU+lGys83QlpbkQVUD6Fv/4L
+ytihk6N9Pr/feECVcSZ20dI43WXjfYak14dSVrZkGNMMXqKmnnqtkAdD0oJN7A7y
+gcf8RuViV0kvk9/36eCMwMHrImfhAgMBAAGjezB5MAkGA1UdEwQCMAAwLAYJYIZI
+AYb4QgENBB8WHU9wZW5TU0wgR2VuZXJhdGVkIENlcnRpZmljYXRlMB0GA1UdDgQW
+BBSyKqjvctIsFNBHULBTqr8SHtSxpDAfBgNVHSMEGDAWgBRHUypxCXFQYqewhGo7
+2lWPQUsjoDANBgkqhkiG9w0BAQQFAAOBgQBvdYVoBfd4RV/xWSMXIcgw/i5OiwyX
+MsenQePll51MpglfArd7pUipUalCqlJt/Gs8kD16Ih1z1yuWYVTMlnDZ0PwbIOYn
++Jr8XLF9b1SMJt6PwckZZ0LZdIi2KwGAxVsIW1kjJAqu9o4YH37XW37yYdQRxfvv
+lDiQlgX0JtmLgA==
+-----END CERTIFICATE-----
+-----BEGIN RSA PRIVATE KEY-----
+MIICXAIBAAKBgQC9aHAEOzjdqSFF848Cj86TwfaMwejxRuhepAETvotA4k+kJ/Gm
+1I8KRz1PpRsrPN0JaW5EFVA+hb/+C8rYoZOjfT6/33hAlXEmdtHSON1l432GpNeH
+Ula2ZBjTDF6ipp56rZAHQ9KCTewO8oHH/EblYldJL5Pf9+ngjMDB6yJn4QIDAQAB
+AoGACCuYIWaYll80UzslYRvo8lC8nOfEb5v6bBKxBTQD98GLY+5hKywiG3RlPalG
+mb/fXQeSPReaRYgpdwD1OBEIOEMW9kLyqpzokC0xjpZ+MwsuJTlxCesk5GEsMa3o
+wC3QMmiRA7qrZ/SzTtwrs++9mZ/pxp8JZ6pKYUj8SE7/vV0CQQDz8Ix2t40E16hx
+04+XhClnGqydZJyLLSxcTU3ZVhYxL+efo/5hZ8tKpkcDi8wq6T03BOKrKxrlIW55
+qDRNM24rAkEAxsWzu/rJhIouQyNoYygEIEYzFRlTQyZSg59u6dNiewMn27dOAbyc
+YT7B6da7e74QttTXo0lIllsX2S38+XsIIwJBANSRuIU3G66tkr5l4gnhhAaxqtuY
+sgVhvvdL8dvC9aG1Ifzt9hzBSthpHxbK+oYmK07HdhI8hLpIMLHYzoK7n3MCQEy4
+4rccBcxyyYiAkjozp+QNNIpgTBMPJ6pGT7lRLiHtBeV4y1NASdv/LTnk+Fi69Bid
+7t3H24ytfHcHmS1yn6ECQF6Jmh4C7dlvp59zXp+t+VsXxa/8sq41vKNIj0Rx9vh5
+xp9XL0C5ZpgmBnsTydP9pmkiL4ltLbMX0wJU6N2cmFw=
+-----END RSA PRIVATE KEY-----
diff --git a/openssl-1.1.0h/demos/cms/signer2.pem b/openssl-1.1.0h/demos/cms/signer2.pem
new file mode 100644
index 0000000..25e23d1
--- /dev/null
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