make no-des and no-rc2 work.
[openssl.git] / crypto / pkcs7 / sign.c
index ead1cb65cae7a06a38da43d11a7be735e390ea5e..22290e192ccfb15b36e78d47e5a8a63f9ecf113b 100644 (file)
  * [including the GNU Public Licence.]
  */
 #include <stdio.h>
-#include "bio.h"
-#include "x509.h"
-#include "pem.h"
+#include <string.h>
+#include <openssl/bio.h>
+#include <openssl/x509.h>
+#include <openssl/pem.h>
+#include <openssl/err.h>
 
-main(argc,argv)
+int main(argc,argv)
 int argc;
 char *argv[];
        {
        X509 *x509;
        EVP_PKEY *pkey;
        PKCS7 *p7;
-       PKCS7 *p7_data;
        PKCS7_SIGNER_INFO *si;
        BIO *in;
        BIO *data,*p7bio;
        char buf[1024*4];
-       int i,j;
+       int i;
        int nodetach=0;
 
+#ifndef NO_MD2
        EVP_add_digest(EVP_md2());
+#endif
+#ifndef NO_MD5
        EVP_add_digest(EVP_md5());
+#endif
+#ifndef NO_SHA1
        EVP_add_digest(EVP_sha1());
+#endif
+#ifndef NO_MDC2
        EVP_add_digest(EVP_mdc2());
+#endif
 
        data=BIO_new(BIO_s_file());
 again:
@@ -97,15 +106,20 @@ again:
                BIO_set_fp(data,stdin,BIO_NOCLOSE);
 
        if ((in=BIO_new_file("server.pem","r")) == NULL) goto err;
-       if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err;
+       if ((x509=PEM_read_bio_X509(in,NULL,NULL,NULL)) == NULL) goto err;
        BIO_reset(in);
-       if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err;
+       if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,NULL)) == NULL) goto err;
        BIO_free(in);
 
        p7=PKCS7_new();
        PKCS7_set_type(p7,NID_pkcs7_signed);
         
-       if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err;
+       si=PKCS7_add_signature(p7,x509,pkey,EVP_sha1());
+       if (si == NULL) goto err;
+
+       /* If you do this then you get signing time automatically added */
+       PKCS7_add_signed_attribute(si, NID_pkcs9_contentType, V_ASN1_OBJECT,
+                                               OBJ_nid2obj(NID_pkcs7_data));
 
        /* we may want to add more */
        PKCS7_add_certificate(p7,x509);
@@ -125,7 +139,7 @@ again:
                BIO_write(p7bio,buf,i);
                }
 
-       if (!PKCS7_dataSign(p7,p7bio)) goto err;
+       if (!PKCS7_dataFinal(p7,p7bio)) goto err;
        BIO_free(p7bio);
 
        PEM_write_PKCS7(stdout,p7);