diff options
author | Ben Laurie <ben@openssl.org> | 2000-05-16 21:22:45 +0000 |
---|---|---|
committer | Ben Laurie <ben@openssl.org> | 2000-05-16 21:22:45 +0000 |
commit | 5de603abc8fe6fedca529ce58d3741b50ff99592 (patch) | |
tree | 7a255f319401b15b440ec6a692951b2ff92f635a /crypto | |
parent | f2716dada0527bcf200e628fd572514bd395fbfb (diff) | |
download | openssl-5de603abc8fe6fedca529ce58d3741b50ff99592.tar.gz |
Typesafety Thought Police part 3.
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/asn1/p7_lib.c | 2 | ||||
-rw-r--r-- | crypto/pkcs12/p12_crt.c | 9 | ||||
-rw-r--r-- | crypto/pkcs12/p12_decr.c | 2 | ||||
-rw-r--r-- | crypto/pkcs12/p12_kiss.c | 13 | ||||
-rw-r--r-- | crypto/pkcs12/p12_npas.c | 18 | ||||
-rw-r--r-- | crypto/pkcs12/pkcs12.h | 28 | ||||
-rw-r--r-- | crypto/pkcs7/pkcs7.h | 4 | ||||
-rw-r--r-- | crypto/x509/x509.h | 22 |
8 files changed, 54 insertions, 44 deletions
diff --git a/crypto/asn1/p7_lib.c b/crypto/asn1/p7_lib.c index 86db82cfa1..9effc28622 100644 --- a/crypto/asn1/p7_lib.c +++ b/crypto/asn1/p7_lib.c @@ -293,3 +293,5 @@ void PKCS7_content_free(PKCS7 *a) a->d.ptr=NULL; } +IMPLEMENT_STACK_OF(PKCS7) +IMPLEMENT_ASN1_SET_OF(PKCS7) diff --git a/crypto/pkcs12/p12_crt.c b/crypto/pkcs12/p12_crt.c index 37850a089b..a5f17c51a7 100644 --- a/crypto/pkcs12/p12_crt.c +++ b/crypto/pkcs12/p12_crt.c @@ -66,7 +66,7 @@ PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, { PKCS12 *p12; STACK_OF(PKCS12_SAFEBAG) *bags; - STACK *safes; + STACK_OF(PKCS7) *safes; PKCS12_SAFEBAG *bag; PKCS8_PRIV_KEY_INFO *p8; PKCS7 *authsafe; @@ -121,7 +121,8 @@ PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, if (!authsafe) return NULL; - if(!(safes = sk_new (NULL)) || !sk_push(safes, (char *)authsafe)) { + if(!(safes = sk_PKCS7_new (NULL)) + || !sk_PKCS7_push(safes, authsafe)) { PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE); return NULL; } @@ -142,7 +143,7 @@ PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, /* Turn it into unencrypted safe bag */ if(!(authsafe = PKCS12_pack_p7data (bags))) return NULL; sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); - if(!sk_push(safes, (char *)authsafe)) { + if(!sk_PKCS7_push(safes, authsafe)) { PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE); return NULL; } @@ -151,7 +152,7 @@ PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, if(!M_PKCS12_pack_authsafes (p12, safes)) return NULL; - sk_pop_free(safes, (void(*)(void *)) PKCS7_free); + sk_PKCS7_pop_free(safes, PKCS7_free); if(!PKCS12_set_mac (p12, pass, -1, NULL, 0, mac_iter, NULL)) return NULL; diff --git a/crypto/pkcs12/p12_decr.c b/crypto/pkcs12/p12_decr.c index 4be44eac50..778954b99f 100644 --- a/crypto/pkcs12/p12_decr.c +++ b/crypto/pkcs12/p12_decr.c @@ -183,3 +183,5 @@ ASN1_OCTET_STRING *PKCS12_i2d_encrypt (X509_ALGOR *algor, int (*i2d)(), Free (in); return oct; } + +IMPLEMENT_PKCS12_STACK_OF(PKCS7) diff --git a/crypto/pkcs12/p12_kiss.c b/crypto/pkcs12/p12_kiss.c index f49d2e5249..6f78d8a2af 100644 --- a/crypto/pkcs12/p12_kiss.c +++ b/crypto/pkcs12/p12_kiss.c @@ -147,15 +147,16 @@ int PKCS12_parse (PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, static int parse_pk12 (PKCS12 *p12, const char *pass, int passlen, EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca) { - STACK *asafes; + STACK_OF(PKCS7) *asafes; STACK_OF(PKCS12_SAFEBAG) *bags; int i, bagnid; PKCS7 *p7; ASN1_OCTET_STRING *keyid = NULL; + char keymatch = 0; if (!( asafes = M_PKCS12_unpack_authsafes (p12))) return 0; - for (i = 0; i < sk_num (asafes); i++) { - p7 = (PKCS7 *) sk_value (asafes, i); + for (i = 0; i < sk_PKCS7_num (asafes); i++) { + p7 = sk_PKCS7_value (asafes, i); bagnid = OBJ_obj2nid (p7->type); if (bagnid == NID_pkcs7_data) { bags = M_PKCS12_unpack_p7data (p7); @@ -163,18 +164,18 @@ static int parse_pk12 (PKCS12 *p12, const char *pass, int passlen, bags = M_PKCS12_unpack_p7encdata (p7, pass, passlen); } else continue; if (!bags) { - sk_pop_free (asafes, (void(*)(void *)) PKCS7_free); + sk_PKCS7_pop_free (asafes, PKCS7_free); return 0; } if (!parse_bags(bags, pass, passlen, pkey, cert, ca, &keyid, &keymatch)) { sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); - sk_pop_free(asafes, (void(*)(void *)) PKCS7_free); + sk_PKCS7_pop_free(asafes, PKCS7_free); return 0; } sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); } - sk_pop_free(asafes, (void(*)(void *)) PKCS7_free); + sk_PKCS7_pop_free(asafes, PKCS7_free); if (keyid) M_ASN1_OCTET_STRING_free(keyid); return 1; } diff --git a/crypto/pkcs12/p12_npas.c b/crypto/pkcs12/p12_npas.c index cccea84508..eed494a3f3 100644 --- a/crypto/pkcs12/p12_npas.c +++ b/crypto/pkcs12/p12_npas.c @@ -105,7 +105,7 @@ return 1; static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass) { - STACK *asafes, *newsafes; + STACK_OF(PKCS7) *asafes, *newsafes; STACK_OF(PKCS12_SAFEBAG) *bags; int i, bagnid, pbe_nid, pbe_iter, pbe_saltlen; PKCS7 *p7, *p7new; @@ -114,9 +114,9 @@ static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass) unsigned int maclen; if (!(asafes = M_PKCS12_unpack_authsafes(p12))) return 0; - if(!(newsafes = sk_new(NULL))) return 0; - for (i = 0; i < sk_num (asafes); i++) { - p7 = (PKCS7 *) sk_value(asafes, i); + if(!(newsafes = sk_PKCS7_new(NULL))) return 0; + for (i = 0; i < sk_PKCS7_num (asafes); i++) { + p7 = sk_PKCS7_value(asafes, i); bagnid = OBJ_obj2nid(p7->type); if (bagnid == NID_pkcs7_data) { bags = M_PKCS12_unpack_p7data(p7); @@ -126,12 +126,12 @@ static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass) &pbe_nid, &pbe_iter, &pbe_saltlen); } else continue; if (!bags) { - sk_pop_free(asafes, (void(*)(void *)) PKCS7_free); + sk_PKCS7_pop_free(asafes, PKCS7_free); return 0; } if (!newpass_bags(bags, oldpass, newpass)) { sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); - sk_pop_free(asafes, (void(*)(void *)) PKCS7_free); + sk_PKCS7_pop_free(asafes, PKCS7_free); return 0; } /* Repack bag in same form with new password */ @@ -140,12 +140,12 @@ static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass) pbe_saltlen, pbe_iter, bags); sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); if(!p7new) { - sk_pop_free(asafes, (void(*)(void *)) PKCS7_free); + sk_PKCS7_pop_free(asafes, PKCS7_free); return 0; } - sk_push(newsafes, (char *)p7new); + sk_PKCS7_push(newsafes, p7new); } - sk_pop_free(asafes, (void(*)(void *)) PKCS7_free); + sk_PKCS7_pop_free(asafes, PKCS7_free); /* Repack safe: save old safe in case of error */ diff --git a/crypto/pkcs12/pkcs12.h b/crypto/pkcs12/pkcs12.h index 232eab3d4c..4cf92b68ea 100644 --- a/crypto/pkcs12/pkcs12.h +++ b/crypto/pkcs12/pkcs12.h @@ -66,27 +66,6 @@ extern "C" { #endif -#define DECLARE_PKCS12_STACK_OF(type) \ -STACK_OF(type) *PKCS12_decrypt_d2i_##type(struct X509_algor_st *algor, \ - type *(*d2i)(type **, \ - unsigned char **, \ - long), \ - void (*free_func)(type *), \ - const char *pass, int passlen, \ - ASN1_STRING *oct, int seq); - -#define IMPLEMENT_PKCS12_STACK_OF(type) \ -STACK_OF(type) *PKCS12_decrypt_d2i_##type(struct X509_algor_st *algor, \ - type *(*d2i)(type **, \ - unsigned char **, \ - long), \ - void (*free_func)(type *), \ - const char *pass, int passlen, \ - ASN1_STRING *oct, int seq) \ - { return (STACK_OF(type) *)PKCS12_decrypt_d2i(algor,(char *(*)())d2i, \ - (void(*)(void *))free_func, \ - pass,passlen,oct,seq); } - #define PKCS12_KEY_ID 1 #define PKCS12_IV_ID 2 #define PKCS12_MAC_ID 3 @@ -188,13 +167,12 @@ ASN1_seq_unpack_PKCS12_SAFEBAG ((p7)->d.data->data, p7->d.data->length, \ d2i_PKCS12_SAFEBAG, PKCS12_SAFEBAG_free) #define M_PKCS12_pack_authsafes(p12, safes) \ -ASN1_seq_pack((safes), (int (*)())i2d_PKCS7,\ +ASN1_seq_pack_PKCS7((safes), i2d_PKCS7,\ &(p12)->authsafes->d.data->data, &(p12)->authsafes->d.data->length) #define M_PKCS12_unpack_authsafes(p12) \ -ASN1_seq_unpack((p12)->authsafes->d.data->data, \ - (p12)->authsafes->d.data->length, (char *(*)())d2i_PKCS7, \ - PKCS7_free) +ASN1_seq_unpack_PKCS7((p12)->authsafes->d.data->data, \ + (p12)->authsafes->d.data->length, d2i_PKCS7, PKCS7_free) #define M_PKCS12_unpack_p7encdata(p7, pass, passlen) \ PKCS12_decrypt_d2i_PKCS12_SAFEBAG ((p7)->d.encrypted->enc_data->algorithm,\ diff --git a/crypto/pkcs7/pkcs7.h b/crypto/pkcs7/pkcs7.h index fd2877de84..a220440e5c 100644 --- a/crypto/pkcs7/pkcs7.h +++ b/crypto/pkcs7/pkcs7.h @@ -213,6 +213,10 @@ typedef struct pkcs7_st } d; } PKCS7; +DECLARE_STACK_OF(PKCS7) +DECLARE_ASN1_SET_OF(PKCS7) +DECLARE_PKCS12_STACK_OF(PKCS7) + #define PKCS7_OP_SET_DETACHED_SIGNATURE 1 #define PKCS7_OP_GET_DETACHED_SIGNATURE 2 diff --git a/crypto/x509/x509.h b/crypto/x509/x509.h index 57f9bab0fb..d2ad77815e 100644 --- a/crypto/x509/x509.h +++ b/crypto/x509/x509.h @@ -92,6 +92,28 @@ extern "C" { #undef X509_NAME #endif + /* If placed in pkcs12.h, we end up with a circular depency with pkcs7.h */ +#define DECLARE_PKCS12_STACK_OF(type) \ +STACK_OF(type) *PKCS12_decrypt_d2i_##type(struct X509_algor_st *algor, \ + type *(*d2i)(type **, \ + unsigned char **, \ + long), \ + void (*free_func)(type *), \ + const char *pass, int passlen, \ + ASN1_STRING *oct, int seq); + +#define IMPLEMENT_PKCS12_STACK_OF(type) \ +STACK_OF(type) *PKCS12_decrypt_d2i_##type(struct X509_algor_st *algor, \ + type *(*d2i)(type **, \ + unsigned char **, \ + long), \ + void (*free_func)(type *), \ + const char *pass, int passlen, \ + ASN1_STRING *oct, int seq) \ + { return (STACK_OF(type) *)PKCS12_decrypt_d2i(algor,(char *(*)())d2i, \ + (void(*)(void *))free_func, \ + pass,passlen,oct,seq); } + #define X509_FILETYPE_PEM 1 #define X509_FILETYPE_ASN1 2 #define X509_FILETYPE_DEFAULT 3 |