diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/pkcs7/verify.c | 66 |
1 files changed, 45 insertions, 21 deletions
diff --git a/src/lib/libcrypto/pkcs7/verify.c b/src/lib/libcrypto/pkcs7/verify.c index 0e1c1b26dc..5f7afe8933 100644 --- a/src/lib/libcrypto/pkcs7/verify.c +++ b/src/lib/libcrypto/pkcs7/verify.c | |||
| @@ -56,41 +56,50 @@ | |||
| 56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
| 57 | */ | 57 | */ |
| 58 | #include <stdio.h> | 58 | #include <stdio.h> |
| 59 | #include "asn1.h" | 59 | #include <string.h> |
| 60 | #include "bio.h" | 60 | #include <openssl/bio.h> |
| 61 | #include "x509.h" | 61 | #include <openssl/asn1.h> |
| 62 | #include "pem.h" | 62 | #include <openssl/x509.h> |
| 63 | #include <openssl/pem.h> | ||
| 64 | #include <openssl/err.h> | ||
| 65 | #include "example.h" | ||
| 63 | 66 | ||
| 64 | int verify_callback(int ok, X509_STORE_CTX *ctx); | 67 | int verify_callback(int ok, X509_STORE_CTX *ctx); |
| 65 | 68 | ||
| 66 | BIO *bio_err=NULL; | 69 | BIO *bio_err=NULL; |
| 70 | BIO *bio_out=NULL; | ||
| 67 | 71 | ||
| 68 | main(argc,argv) | 72 | int main(argc,argv) |
| 69 | int argc; | 73 | int argc; |
| 70 | char *argv[]; | 74 | char *argv[]; |
| 71 | { | 75 | { |
| 72 | X509 *x509,*x; | ||
| 73 | PKCS7 *p7; | 76 | PKCS7 *p7; |
| 74 | PKCS7_SIGNED *s; | ||
| 75 | PKCS7_SIGNER_INFO *si; | 77 | PKCS7_SIGNER_INFO *si; |
| 76 | PKCS7_ISSUER_AND_SERIAL *ias; | ||
| 77 | X509_STORE_CTX cert_ctx; | 78 | X509_STORE_CTX cert_ctx; |
| 78 | X509_STORE *cert_store=NULL; | 79 | X509_STORE *cert_store=NULL; |
| 79 | X509_LOOKUP *lookup=NULL; | ||
| 80 | BIO *data,*detached=NULL,*p7bio=NULL; | 80 | BIO *data,*detached=NULL,*p7bio=NULL; |
| 81 | char buf[1024*4]; | 81 | char buf[1024*4]; |
| 82 | unsigned char *p,*pp; | 82 | char *pp; |
| 83 | int i,j,printit=0; | 83 | int i,printit=0; |
| 84 | STACK *sk; | 84 | STACK_OF(PKCS7_SIGNER_INFO) *sk; |
| 85 | 85 | ||
| 86 | bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); | 86 | bio_err=BIO_new_fp(stderr,BIO_NOCLOSE); |
| 87 | bio_out=BIO_new_fp(stdout,BIO_NOCLOSE); | ||
| 88 | #ifndef OPENSSL_NO_MD2 | ||
| 87 | EVP_add_digest(EVP_md2()); | 89 | EVP_add_digest(EVP_md2()); |
| 90 | #endif | ||
| 91 | #ifndef OPENSSL_NO_MD5 | ||
| 88 | EVP_add_digest(EVP_md5()); | 92 | EVP_add_digest(EVP_md5()); |
| 93 | #endif | ||
| 94 | #ifndef OPENSSL_NO_SHA1 | ||
| 89 | EVP_add_digest(EVP_sha1()); | 95 | EVP_add_digest(EVP_sha1()); |
| 96 | #endif | ||
| 97 | #ifndef OPENSSL_NO_MDC2 | ||
| 90 | EVP_add_digest(EVP_mdc2()); | 98 | EVP_add_digest(EVP_mdc2()); |
| 99 | #endif | ||
| 91 | 100 | ||
| 92 | data=BIO_new(BIO_s_file()); | 101 | data=BIO_new(BIO_s_file()); |
| 93 | again: | 102 | |
| 94 | pp=NULL; | 103 | pp=NULL; |
| 95 | while (argc > 1) | 104 | while (argc > 1) |
| 96 | { | 105 | { |
| @@ -121,7 +130,7 @@ again: | |||
| 121 | 130 | ||
| 122 | 131 | ||
| 123 | /* Load the PKCS7 object from a file */ | 132 | /* Load the PKCS7 object from a file */ |
| 124 | if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL)) == NULL) goto err; | 133 | if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL,NULL)) == NULL) goto err; |
| 125 | 134 | ||
| 126 | /* This stuff is being setup for certificate verification. | 135 | /* This stuff is being setup for certificate verification. |
| 127 | * When using SSL, it could be replaced with a | 136 | * When using SSL, it could be replaced with a |
| @@ -131,10 +140,10 @@ again: | |||
| 131 | X509_STORE_load_locations(cert_store,NULL,"../../certs"); | 140 | X509_STORE_load_locations(cert_store,NULL,"../../certs"); |
| 132 | X509_STORE_set_verify_cb_func(cert_store,verify_callback); | 141 | X509_STORE_set_verify_cb_func(cert_store,verify_callback); |
| 133 | 142 | ||
| 134 | ERR_clear_errors(); | 143 | ERR_clear_error(); |
| 135 | 144 | ||
| 136 | /* We need to process the data */ | 145 | /* We need to process the data */ |
| 137 | if (PKCS7_get_detached(p7)) | 146 | if ((PKCS7_get_detached(p7) || detached)) |
| 138 | { | 147 | { |
| 139 | if (detached == NULL) | 148 | if (detached == NULL) |
| 140 | { | 149 | { |
| @@ -166,12 +175,29 @@ again: | |||
| 166 | } | 175 | } |
| 167 | 176 | ||
| 168 | /* Ok, first we need to, for each subject entry, see if we can verify */ | 177 | /* Ok, first we need to, for each subject entry, see if we can verify */ |
| 169 | for (i=0; i<sk_num(sk); i++) | 178 | for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sk); i++) |
| 170 | { | 179 | { |
| 171 | si=(PKCS7_SIGNER_INFO *)sk_value(sk,i); | 180 | ASN1_UTCTIME *tm; |
| 181 | char *str1,*str2; | ||
| 182 | |||
| 183 | si=sk_PKCS7_SIGNER_INFO_value(sk,i); | ||
| 172 | i=PKCS7_dataVerify(cert_store,&cert_ctx,p7bio,p7,si); | 184 | i=PKCS7_dataVerify(cert_store,&cert_ctx,p7bio,p7,si); |
| 173 | if (i <= 0) | 185 | if (i <= 0) |
| 174 | goto err; | 186 | goto err; |
| 187 | printf("signer info\n"); | ||
| 188 | if ((tm=get_signed_time(si)) != NULL) | ||
| 189 | { | ||
| 190 | BIO_printf(bio_out,"Signed time:"); | ||
| 191 | ASN1_UTCTIME_print(bio_out,tm); | ||
| 192 | ASN1_UTCTIME_free(tm); | ||
| 193 | BIO_printf(bio_out,"\n"); | ||
| 194 | } | ||
| 195 | if (get_signed_seq2string(si,&str1,&str2)) | ||
| 196 | { | ||
| 197 | BIO_printf(bio_out,"String 1 is %s\n",str1); | ||
| 198 | BIO_printf(bio_out,"String 2 is %s\n",str2); | ||
| 199 | } | ||
| 200 | |||
| 175 | } | 201 | } |
| 176 | 202 | ||
| 177 | X509_STORE_free(cert_store); | 203 | X509_STORE_free(cert_store); |
| @@ -185,9 +211,7 @@ err: | |||
| 185 | } | 211 | } |
| 186 | 212 | ||
| 187 | /* should be X509 * but we can just have them as char *. */ | 213 | /* should be X509 * but we can just have them as char *. */ |
| 188 | int verify_callback(ok, ctx) | 214 | int verify_callback(int ok, X509_STORE_CTX *ctx) |
| 189 | int ok; | ||
| 190 | X509_STORE_CTX *ctx; | ||
| 191 | { | 215 | { |
| 192 | char buf[256]; | 216 | char buf[256]; |
| 193 | X509 *err_cert; | 217 | X509 *err_cert; |
