diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/x_x509.c')
-rw-r--r-- | src/lib/libcrypto/asn1/x_x509.c | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c index 7abf6b2a6b..11e564ea30 100644 --- a/src/lib/libcrypto/asn1/x_x509.c +++ b/src/lib/libcrypto/asn1/x_x509.c | |||
@@ -62,6 +62,9 @@ | |||
62 | #include <openssl/asn1_mac.h> | 62 | #include <openssl/asn1_mac.h> |
63 | #include <openssl/x509.h> | 63 | #include <openssl/x509.h> |
64 | 64 | ||
65 | static int x509_meth_num = 0; | ||
66 | static STACK_OF(CRYPTO_EX_DATA_FUNCS) *x509_meth = NULL; | ||
67 | |||
65 | static ASN1_METHOD meth={ | 68 | static ASN1_METHOD meth={ |
66 | (int (*)()) i2d_X509, | 69 | (int (*)()) i2d_X509, |
67 | (char *(*)())d2i_X509, | 70 | (char *(*)())d2i_X509, |
@@ -113,10 +116,13 @@ X509 *X509_new(void) | |||
113 | M_ASN1_New_Malloc(ret,X509); | 116 | M_ASN1_New_Malloc(ret,X509); |
114 | ret->references=1; | 117 | ret->references=1; |
115 | ret->valid=0; | 118 | ret->valid=0; |
119 | ret->ex_flags = 0; | ||
116 | ret->name=NULL; | 120 | ret->name=NULL; |
121 | ret->aux=NULL; | ||
117 | M_ASN1_New(ret->cert_info,X509_CINF_new); | 122 | M_ASN1_New(ret->cert_info,X509_CINF_new); |
118 | M_ASN1_New(ret->sig_alg,X509_ALGOR_new); | 123 | M_ASN1_New(ret->sig_alg,X509_ALGOR_new); |
119 | M_ASN1_New(ret->signature,ASN1_BIT_STRING_new); | 124 | M_ASN1_New(ret->signature,M_ASN1_BIT_STRING_new); |
125 | CRYPTO_new_ex_data(x509_meth, ret, &ret->ex_data); | ||
120 | return(ret); | 126 | return(ret); |
121 | M_ASN1_New_Error(ASN1_F_X509_NEW); | 127 | M_ASN1_New_Error(ASN1_F_X509_NEW); |
122 | } | 128 | } |
@@ -140,12 +146,65 @@ void X509_free(X509 *a) | |||
140 | } | 146 | } |
141 | #endif | 147 | #endif |
142 | 148 | ||
143 | /* CRYPTO_free_ex_data(bio_meth,(char *)a,&a->ex_data); */ | 149 | CRYPTO_free_ex_data(x509_meth,a,&a->ex_data); |
144 | X509_CINF_free(a->cert_info); | 150 | X509_CINF_free(a->cert_info); |
145 | X509_ALGOR_free(a->sig_alg); | 151 | X509_ALGOR_free(a->sig_alg); |
146 | ASN1_BIT_STRING_free(a->signature); | 152 | M_ASN1_BIT_STRING_free(a->signature); |
153 | X509_CERT_AUX_free(a->aux); | ||
147 | 154 | ||
148 | if (a->name != NULL) Free(a->name); | 155 | if (a->name != NULL) Free(a->name); |
149 | Free((char *)a); | 156 | Free(a); |
157 | } | ||
158 | |||
159 | int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
160 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
161 | { | ||
162 | x509_meth_num++; | ||
163 | return(CRYPTO_get_ex_new_index(x509_meth_num-1, | ||
164 | &x509_meth,argl,argp,new_func,dup_func,free_func)); | ||
165 | } | ||
166 | |||
167 | int X509_set_ex_data(X509 *r, int idx, void *arg) | ||
168 | { | ||
169 | return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); | ||
150 | } | 170 | } |
151 | 171 | ||
172 | void *X509_get_ex_data(X509 *r, int idx) | ||
173 | { | ||
174 | return(CRYPTO_get_ex_data(&r->ex_data,idx)); | ||
175 | } | ||
176 | |||
177 | /* X509_AUX ASN1 routines. X509_AUX is the name given to | ||
178 | * a certificate with extra info tagged on the end. Since these | ||
179 | * functions set how a certificate is trusted they should only | ||
180 | * be used when the certificate comes from a reliable source | ||
181 | * such as local storage. | ||
182 | * | ||
183 | */ | ||
184 | |||
185 | X509 *d2i_X509_AUX(X509 **a, unsigned char **pp, long length) | ||
186 | { | ||
187 | unsigned char *q; | ||
188 | X509 *ret; | ||
189 | /* Save start position */ | ||
190 | q = *pp; | ||
191 | ret = d2i_X509(a, pp, length); | ||
192 | /* If certificate unreadable then forget it */ | ||
193 | if(!ret) return NULL; | ||
194 | /* update length */ | ||
195 | length -= *pp - q; | ||
196 | if(!length) return ret; | ||
197 | if(!d2i_X509_CERT_AUX(&ret->aux, pp, length)) goto err; | ||
198 | return ret; | ||
199 | err: | ||
200 | X509_free(ret); | ||
201 | return NULL; | ||
202 | } | ||
203 | |||
204 | int i2d_X509_AUX(X509 *a, unsigned char **pp) | ||
205 | { | ||
206 | int length; | ||
207 | length = i2d_X509(a, pp); | ||
208 | if(a) length += i2d_X509_CERT_AUX(a->aux, pp); | ||
209 | return length; | ||
210 | } | ||