summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/pkcs7/sign.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/pkcs7/sign.c')
-rw-r--r--src/lib/libcrypto/pkcs7/sign.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/lib/libcrypto/pkcs7/sign.c b/src/lib/libcrypto/pkcs7/sign.c
index ead1cb65ca..8b59885f7e 100644
--- a/src/lib/libcrypto/pkcs7/sign.c
+++ b/src/lib/libcrypto/pkcs7/sign.c
@@ -56,29 +56,38 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58#include <stdio.h> 58#include <stdio.h>
59#include "bio.h" 59#include <string.h>
60#include "x509.h" 60#include <openssl/bio.h>
61#include "pem.h" 61#include <openssl/x509.h>
62#include <openssl/pem.h>
63#include <openssl/err.h>
62 64
63main(argc,argv) 65int main(argc,argv)
64int argc; 66int argc;
65char *argv[]; 67char *argv[];
66 { 68 {
67 X509 *x509; 69 X509 *x509;
68 EVP_PKEY *pkey; 70 EVP_PKEY *pkey;
69 PKCS7 *p7; 71 PKCS7 *p7;
70 PKCS7 *p7_data;
71 PKCS7_SIGNER_INFO *si; 72 PKCS7_SIGNER_INFO *si;
72 BIO *in; 73 BIO *in;
73 BIO *data,*p7bio; 74 BIO *data,*p7bio;
74 char buf[1024*4]; 75 char buf[1024*4];
75 int i,j; 76 int i;
76 int nodetach=0; 77 int nodetach=0;
77 78
79#ifndef OPENSSL_NO_MD2
78 EVP_add_digest(EVP_md2()); 80 EVP_add_digest(EVP_md2());
81#endif
82#ifndef OPENSSL_NO_MD5
79 EVP_add_digest(EVP_md5()); 83 EVP_add_digest(EVP_md5());
84#endif
85#ifndef OPENSSL_NO_SHA1
80 EVP_add_digest(EVP_sha1()); 86 EVP_add_digest(EVP_sha1());
87#endif
88#ifndef OPENSSL_NO_MDC2
81 EVP_add_digest(EVP_mdc2()); 89 EVP_add_digest(EVP_mdc2());
90#endif
82 91
83 data=BIO_new(BIO_s_file()); 92 data=BIO_new(BIO_s_file());
84again: 93again:
@@ -97,15 +106,20 @@ again:
97 BIO_set_fp(data,stdin,BIO_NOCLOSE); 106 BIO_set_fp(data,stdin,BIO_NOCLOSE);
98 107
99 if ((in=BIO_new_file("server.pem","r")) == NULL) goto err; 108 if ((in=BIO_new_file("server.pem","r")) == NULL) goto err;
100 if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err; 109 if ((x509=PEM_read_bio_X509(in,NULL,NULL,NULL)) == NULL) goto err;
101 BIO_reset(in); 110 BIO_reset(in);
102 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err; 111 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,NULL)) == NULL) goto err;
103 BIO_free(in); 112 BIO_free(in);
104 113
105 p7=PKCS7_new(); 114 p7=PKCS7_new();
106 PKCS7_set_type(p7,NID_pkcs7_signed); 115 PKCS7_set_type(p7,NID_pkcs7_signed);
107 116
108 if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err; 117 si=PKCS7_add_signature(p7,x509,pkey,EVP_sha1());
118 if (si == NULL) goto err;
119
120 /* If you do this then you get signing time automatically added */
121 PKCS7_add_signed_attribute(si, NID_pkcs9_contentType, V_ASN1_OBJECT,
122 OBJ_nid2obj(NID_pkcs7_data));
109 123
110 /* we may want to add more */ 124 /* we may want to add more */
111 PKCS7_add_certificate(p7,x509); 125 PKCS7_add_certificate(p7,x509);
@@ -125,7 +139,7 @@ again:
125 BIO_write(p7bio,buf,i); 139 BIO_write(p7bio,buf,i);
126 } 140 }
127 141
128 if (!PKCS7_dataSign(p7,p7bio)) goto err; 142 if (!PKCS7_dataFinal(p7,p7bio)) goto err;
129 BIO_free(p7bio); 143 BIO_free(p7bio);
130 144
131 PEM_write_PKCS7(stdout,p7); 145 PEM_write_PKCS7(stdout,p7);