~andersk/ubuntu/oneiric/openssl/spurious-reboot

« back to all changes in this revision

Viewing changes to demos/cms/cms_enc.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2011-05-01 23:51:53 UTC
  • mfrom: (11.1.20 sid)
  • Revision ID: james.westby@ubuntu.com-20110501235153-bjcxitndquaezb68
Tags: 1.0.0d-2ubuntu1
* Resynchronise with Debian (LP: #675566).  Remaining changes:
  - debian/libssl1.0.0.postinst:
    + Display a system restart required notification bubble on libssl1.0.0
      upgrade.
    + Use a different priority for libssl1.0.0/restart-services depending
      on whether a desktop, or server dist-upgrade is being performed.
  - debian/{libssl1.0.0-udeb.dirs, control, rules}: Create
    libssl1.0.0-udeb, for the benefit of wget-udeb (no wget-udeb package
    in Debian).
  - debian/{libcrypto1.0.0-udeb.dirs, libssl1.0.0.dirs, libssl1.0.0.files,
    rules}: Move runtime libraries to /lib, for the benefit of
    wpasupplicant.
  - debian/patches/aesni.patch: Backport Intel AES-NI support, now from
    http://rt.openssl.org/Ticket/Display.html?id=2065 rather than the
    0.9.8 variant.
  - debian/patches/Bsymbolic-functions.patch: Link using
    -Bsymbolic-functions.
  - debian/patches/perlpath-quilt.patch: Don't change perl #! paths under
    .pc.
  - debian/rules:
    + Don't run 'make test' when cross-building.
    + Use host compiler when cross-building.  Patch from Neil Williams.
    + Don't build for processors no longer supported: i486, i586 (on
      i386), v8 (on sparc).
    + Fix Makefile to properly clean up libs/ dirs in clean target.
    + Replace duplicate files in the doc directory with symlinks.
* Update architectures affected by Bsymbolic-functions.patch.
* Drop debian/patches/no-sslv2.patch; Debian now adds the 'no-ssl2'
  configure option, which compiles out SSLv2 support entirely, so this is
  no longer needed.
* Drop openssl-doc in favour of the libssl-doc package introduced by
  Debian.  Add Conflicts/Replaces until the next LTS release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Simple S/MIME encrypt example */
 
2
#include <openssl/pem.h>
 
3
#include <openssl/cms.h>
 
4
#include <openssl/err.h>
 
5
 
 
6
int main(int argc, char **argv)
 
7
        {
 
8
        BIO *in = NULL, *out = NULL, *tbio = NULL;
 
9
        X509 *rcert = NULL;
 
10
        STACK_OF(X509) *recips = NULL;
 
11
        CMS_ContentInfo *cms = NULL;
 
12
        int ret = 1;
 
13
 
 
14
        /*
 
15
         * On OpenSSL 1.0.0 and later only:
 
16
         * for streaming set CMS_STREAM
 
17
         */
 
18
        int flags = CMS_STREAM;
 
19
 
 
20
        OpenSSL_add_all_algorithms();
 
21
        ERR_load_crypto_strings();
 
22
 
 
23
        /* Read in recipient certificate */
 
24
        tbio = BIO_new_file("signer.pem", "r");
 
25
 
 
26
        if (!tbio)
 
27
                goto err;
 
28
 
 
29
        rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
 
30
 
 
31
        if (!rcert)
 
32
                goto err;
 
33
 
 
34
        /* Create recipient STACK and add recipient cert to it */
 
35
        recips = sk_X509_new_null();
 
36
 
 
37
        if (!recips || !sk_X509_push(recips, rcert))
 
38
                goto err;
 
39
 
 
40
        /* sk_X509_pop_free will free up recipient STACK and its contents
 
41
         * so set rcert to NULL so it isn't freed up twice.
 
42
         */
 
43
        rcert = NULL;
 
44
 
 
45
        /* Open content being encrypted */
 
46
 
 
47
        in = BIO_new_file("encr.txt", "r");
 
48
 
 
49
        if (!in)
 
50
                goto err;
 
51
 
 
52
        /* encrypt content */
 
53
        cms = CMS_encrypt(recips, in, EVP_des_ede3_cbc(), flags);
 
54
 
 
55
        if (!cms)
 
56
                goto err;
 
57
 
 
58
        out = BIO_new_file("smencr.txt", "w");
 
59
        if (!out)
 
60
                goto err;
 
61
 
 
62
        /* Write out S/MIME message */
 
63
        if (!SMIME_write_CMS(out, cms, in, flags))
 
64
                goto err;
 
65
 
 
66
        ret = 0;
 
67
 
 
68
        err:
 
69
 
 
70
        if (ret)
 
71
                {
 
72
                fprintf(stderr, "Error Encrypting Data\n");
 
73
                ERR_print_errors_fp(stderr);
 
74
                }
 
75
 
 
76
        if (cms)
 
77
                CMS_ContentInfo_free(cms);
 
78
        if (rcert)
 
79
                X509_free(rcert);
 
80
        if (recips)
 
81
                sk_X509_pop_free(recips, X509_free);
 
82
 
 
83
        if (in)
 
84
                BIO_free(in);
 
85
        if (out)
 
86
                BIO_free(out);
 
87
        if (tbio)
 
88
                BIO_free(tbio);
 
89
 
 
90
        return ret;
 
91
 
 
92
        }