Ouch! PKCS7_encrypt() was heading MIME text headers twice
[openssl.git] / crypto / pkcs7 / pk7_smime.c
index 04489380b8f22d0634958ab91ca9fd52f518bcd4..b41f42ed04467216821c62a4e257d18eeaaf26ab 100644 (file)
@@ -184,7 +184,7 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
        }
 
 
-       signers = PKCS7_iget_signers(p7, certs, flags);
+       signers = PKCS7_get0_signers(p7, certs, flags);
 
        if(!signers) return 0;
 
@@ -264,7 +264,7 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
        return 0;
 }
 
-STACK_OF(X509) *PKCS7_iget_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
+STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
 {
        STACK_OF(X509) *signers;
        STACK_OF(PKCS7_SIGNER_INFO) *sinfos;
@@ -274,16 +274,16 @@ STACK_OF(X509) *PKCS7_iget_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
        int i;
 
        if(!p7) {
-               PKCS7err(PKCS7_F_PKCS7_IGET_SIGNERS,PKCS7_R_INVALID_NULL_POINTER);
+               PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_INVALID_NULL_POINTER);
                return NULL;
        }
 
        if(!PKCS7_type_is_signed(p7)) {
-               PKCS7err(PKCS7_F_PKCS7_IGET_SIGNERS,PKCS7_R_WRONG_CONTENT_TYPE);
+               PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_WRONG_CONTENT_TYPE);
                return NULL;
        }
        if(!(signers = sk_X509_new(NULL))) {
-               PKCS7err(PKCS7_F_PKCS7_IGET_SIGNERS,ERR_R_MALLOC_FAILURE);
+               PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,ERR_R_MALLOC_FAILURE);
                return NULL;
        }
 
@@ -292,7 +292,7 @@ STACK_OF(X509) *PKCS7_iget_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
        sinfos = PKCS7_get_signer_info(p7);
 
        if(sk_PKCS7_SIGNER_INFO_num(sinfos) <= 0) {
-               PKCS7err(PKCS7_F_PKCS7_IGET_SIGNERS,PKCS7_R_NO_SIGNERS);
+               PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_NO_SIGNERS);
                return 0;
        }
 
@@ -309,7 +309,7 @@ STACK_OF(X509) *PKCS7_iget_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
                              X509_find_by_issuer_and_serial (p7->d.sign->cert,
                                                ias->issuer, ias->serial);
            if (!signer) {
-                       PKCS7err(PKCS7_F_PKCS7_IGET_SIGNERS,PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND);
+                       PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND);
                        sk_X509_free(signers);
                        return 0;
            }
@@ -329,8 +329,6 @@ PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, EVP_CIPHER *cipher,
        BIO *p7bio = NULL;
        int i;
        X509 *x509;
-       char inbuf[4096];
-       static char txthdr[] = "Content-type: text/plain\r\n\r\n";
        if(!(p7 = PKCS7_new())) {
                PKCS7err(PKCS7_F_PKCS7_ENCRYPT,ERR_R_MALLOC_FAILURE);
                return NULL;
@@ -356,17 +354,8 @@ PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, EVP_CIPHER *cipher,
                goto err;
        }
 
-       if(flags & PKCS7_TEXT) {
-               if(BIO_write(p7bio, txthdr, sizeof(txthdr) - 1) < 0) {
-                       goto err;
-               }
-       }
+       SMIME_crlf_copy(in, p7bio, flags);
 
-       for (;;) {
-               i = BIO_read(in, inbuf, sizeof(inbuf));
-               if (i <= 0) break;
-               BIO_write(p7bio, inbuf, i);
-       }
        BIO_flush(p7bio);
 
         if (!PKCS7_dataFinal(p7,p7bio)) {