"make update"
[openssl.git] / crypto / pkcs7 / enc.c
index 22bf9b04b5747e20d3d6f98db19fdf0fa2aa1e87..7417f8a4e00b7f60df63095db052807721915e59 100644 (file)
@@ -56,6 +56,7 @@
  * [including the GNU Public Licence.]
  */
 #include <stdio.h>
+#include <string.h>
 #include <openssl/bio.h>
 #include <openssl/x509.h>
 #include <openssl/pem.h>
@@ -74,8 +75,9 @@ char *argv[];
        int nodetach=1;
        char *keyfile = NULL;
        const EVP_CIPHER *cipher=NULL;
+       STACK_OF(X509) *recips=NULL;
 
-       SSLeay_add_all_algorithms();
+       OpenSSL_add_all_algorithms();
 
        data=BIO_new(BIO_s_file());
        while(argc > 1)
@@ -96,13 +98,21 @@ char *argv[];
                        keyfile = argv[2];
                        argc-=2;
                        argv+=2;
+                       if (!(in=BIO_new_file(keyfile,"r"))) goto err;
+                       if (!(x509=PEM_read_bio_X509(in,NULL,NULL,NULL)))
+                               goto err;
+                       if(!recips) recips = sk_X509_new_null();
+                       sk_X509_push(recips, x509);
+                       BIO_free(in);
                } else break;
        }
 
-       if (!BIO_read_filename(data,argv[1])) goto err;
+       if(!recips) {
+               fprintf(stderr, "No recipients\n");
+               goto err;
+       }
 
-       if ((in=BIO_new_file(keyfile,"r")) == NULL) goto err;
-       if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err;
+       if (!BIO_read_filename(data,argv[1])) goto err;
 
        p7=PKCS7_new();
 #if 0
@@ -117,12 +127,20 @@ char *argv[];
 #else
        PKCS7_set_type(p7,NID_pkcs7_enveloped);
 #endif
-       if(!cipher) cipher = EVP_des_ede3_cbc();
+       if(!cipher)     {
+#ifndef OPENSSL_NO_DES
+               cipher = EVP_des_ede3_cbc();
+#else
+               fprintf(stderr, "No cipher selected\n");
+               goto err;
+#endif
+       }
 
        if (!PKCS7_set_cipher(p7,cipher)) goto err;
-       if (PKCS7_add_recipient(p7,x509) == NULL) goto err;
-
-
+       for(i = 0; i < sk_X509_num(recips); i++) {
+               if (!PKCS7_add_recipient(p7,sk_X509_value(recips, i))) goto err;
+       }
+       sk_X509_pop_free(recips, X509_free);
 
        /* Set the content of the signed to 'data' */
        /* PKCS7_content_new(p7,NID_pkcs7_data); not used in envelope */