X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=lib%2Fopenssl%2Fdemos%2Fcms%2Fcms_sign.c;fp=lib%2Fopenssl%2Fdemos%2Fcms%2Fcms_sign.c;h=15bd5b8dd950b18733345d4d0ddc7a36489c7414;hb=02ed66432c92de70694700164f986190aad3cbc5;hp=6823c34a0e3e53ff344b29886fcbe098676d1e54;hpb=89016837dcbf2775cd15dc8cbaba00dc6379f86e;p=cassiopeia.git diff --git a/lib/openssl/demos/cms/cms_sign.c b/lib/openssl/demos/cms/cms_sign.c index 6823c34..15bd5b8 100644 --- a/lib/openssl/demos/cms/cms_sign.c +++ b/lib/openssl/demos/cms/cms_sign.c @@ -1,89 +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 #include #include 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"); +{ + BIO *in = NULL, *out = NULL, *tbio = NULL; + X509 *scert = NULL; + EVP_PKEY *skey = NULL; + CMS_ContentInfo *cms = NULL; + int ret = 1; - if (!tbio) - goto err; + /* + * 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; - scert = PEM_read_bio_X509(tbio, NULL, 0, NULL); + OpenSSL_add_all_algorithms(); + ERR_load_crypto_strings(); - BIO_reset(tbio); + /* Read in signer certificate and private key */ + tbio = BIO_new_file("signer.pem", "r"); - skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); + if (!tbio) + goto err; - if (!scert || !skey) - goto err; + scert = PEM_read_bio_X509(tbio, NULL, 0, NULL); - /* Open content being signed */ + BIO_reset(tbio); - in = BIO_new_file("sign.txt", "r"); + skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); - if (!in) - goto err; + if (!scert || !skey) + goto err; - /* Sign content */ - cms = CMS_sign(scert, skey, NULL, in, flags); + /* Open content being signed */ - if (!cms) - goto err; + in = BIO_new_file("sign.txt", "r"); - out = BIO_new_file("smout.txt", "w"); - if (!out) - goto err; + if (!in) + goto err; - if (!(flags & CMS_STREAM)) - BIO_reset(in); + /* Sign content */ + cms = CMS_sign(scert, skey, NULL, in, flags); - /* Write out S/MIME message */ - if (!SMIME_write_CMS(out, cms, in, flags)) - goto err; + if (!cms) + goto err; - ret = 0; + out = BIO_new_file("smout.txt", "w"); + if (!out) + goto err; - err: + if (!(flags & CMS_STREAM)) + BIO_reset(in); - if (ret) - { - fprintf(stderr, "Error Signing Data\n"); - ERR_print_errors_fp(stderr); - } + /* Write out S/MIME message */ + if (!SMIME_write_CMS(out, cms, in, flags)) + goto err; - if (cms) - CMS_ContentInfo_free(cms); - if (scert) - X509_free(scert); - if (skey) - EVP_PKEY_free(skey); + ret = 0; - if (in) - BIO_free(in); - if (out) - BIO_free(out); - if (tbio) - BIO_free(tbio); + err: - return ret; + 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; +}