14 PKCS7_SIGNER_INFO *si;
21 EVP_add_digest(EVP_md2());
22 EVP_add_digest(EVP_md5());
23 EVP_add_digest(EVP_sha1());
24 EVP_add_digest(EVP_mdc2());
26 data=BIO_new(BIO_s_file());
30 if (strcmp(argv[1],"-nd") == 0)
36 if (!BIO_read_filename(data,argv[1]))
40 BIO_set_fp(data,stdin,BIO_NOCLOSE);
42 if ((in=BIO_new_file("server.pem","r")) == NULL) goto err;
43 if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err;
45 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err;
49 PKCS7_set_type(p7,NID_pkcs7_signed);
51 if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err;
53 /* we may want to add more */
54 PKCS7_add_certificate(p7,x509);
56 /* Set the content of the signed to 'data' */
57 PKCS7_content_new(p7,NID_pkcs7_data);
60 PKCS7_set_detached(p7,1);
62 if ((p7bio=PKCS7_dataInit(p7,NULL)) == NULL) goto err;
66 i=BIO_read(data,buf,sizeof(buf));
68 BIO_write(p7bio,buf,i);
71 if (!PKCS7_dataSign(p7,p7bio)) goto err;
74 PEM_write_PKCS7(stdout,p7);
79 ERR_load_crypto_strings();
80 ERR_print_errors_fp(stderr);