diff options
author | beck <> | 2000-12-15 02:58:47 +0000 |
---|---|---|
committer | beck <> | 2000-12-15 02:58:47 +0000 |
commit | 9200bb13d15da4b2a23e6bc92c20e95b74aa2113 (patch) | |
tree | 5c52d628ec1e34be76e7ef2a4235d248b7c44d24 /src/lib/libcrypto/asn1/p7_lib.c | |
parent | e131d25072e3d4197ba4b9bcc0d1b27d34d6488d (diff) | |
download | openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.tar.gz openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.tar.bz2 openbsd-9200bb13d15da4b2a23e6bc92c20e95b74aa2113.zip |
openssl-engine-0.9.6 merge
Diffstat (limited to 'src/lib/libcrypto/asn1/p7_lib.c')
-rw-r--r-- | src/lib/libcrypto/asn1/p7_lib.c | 112 |
1 files changed, 104 insertions, 8 deletions
diff --git a/src/lib/libcrypto/asn1/p7_lib.c b/src/lib/libcrypto/asn1/p7_lib.c index 86db82cfa1..b1196ef581 100644 --- a/src/lib/libcrypto/asn1/p7_lib.c +++ b/src/lib/libcrypto/asn1/p7_lib.c | |||
@@ -62,6 +62,8 @@ | |||
62 | #include <openssl/pkcs7.h> | 62 | #include <openssl/pkcs7.h> |
63 | #include <openssl/objects.h> | 63 | #include <openssl/objects.h> |
64 | 64 | ||
65 | #ifdef PKCS7_INDEFINITE_ENCODING | ||
66 | |||
65 | int i2d_PKCS7(PKCS7 *a, unsigned char **pp) | 67 | int i2d_PKCS7(PKCS7 *a, unsigned char **pp) |
66 | { | 68 | { |
67 | M_ASN1_I2D_vars(a); | 69 | M_ASN1_I2D_vars(a); |
@@ -102,6 +104,7 @@ int i2d_PKCS7(PKCS7 *a, unsigned char **pp) | |||
102 | M_ASN1_I2D_len(a->d.encrypted,i2d_PKCS7_ENCRYPT); | 104 | M_ASN1_I2D_len(a->d.encrypted,i2d_PKCS7_ENCRYPT); |
103 | break; | 105 | break; |
104 | default: | 106 | default: |
107 | M_ASN1_I2D_len(a->d.other,i2d_ASN1_TYPE); | ||
105 | break; | 108 | break; |
106 | } | 109 | } |
107 | } | 110 | } |
@@ -136,6 +139,7 @@ int i2d_PKCS7(PKCS7 *a, unsigned char **pp) | |||
136 | M_ASN1_I2D_put(a->d.encrypted,i2d_PKCS7_ENCRYPT); | 139 | M_ASN1_I2D_put(a->d.encrypted,i2d_PKCS7_ENCRYPT); |
137 | break; | 140 | break; |
138 | default: | 141 | default: |
142 | M_ASN1_I2D_put(a->d.other,i2d_ASN1_TYPE); | ||
139 | break; | 143 | break; |
140 | } | 144 | } |
141 | M_ASN1_I2D_INF_seq_end(); | 145 | M_ASN1_I2D_INF_seq_end(); |
@@ -144,6 +148,98 @@ int i2d_PKCS7(PKCS7 *a, unsigned char **pp) | |||
144 | M_ASN1_I2D_finish(); | 148 | M_ASN1_I2D_finish(); |
145 | } | 149 | } |
146 | 150 | ||
151 | #else | ||
152 | |||
153 | int i2d_PKCS7(PKCS7 *a, unsigned char **pp) | ||
154 | { | ||
155 | int explen = 0; | ||
156 | M_ASN1_I2D_vars(a); | ||
157 | |||
158 | if (a->asn1 != NULL) | ||
159 | { | ||
160 | if (pp == NULL) | ||
161 | return((int)a->length); | ||
162 | memcpy(*pp,a->asn1,(int)a->length); | ||
163 | *pp+=a->length; | ||
164 | return((int)a->length); | ||
165 | } | ||
166 | |||
167 | M_ASN1_I2D_len(a->type,i2d_ASN1_OBJECT); | ||
168 | if (a->d.ptr != NULL) | ||
169 | { | ||
170 | /* Save current length */ | ||
171 | r = ret; | ||
172 | switch (OBJ_obj2nid(a->type)) | ||
173 | { | ||
174 | case NID_pkcs7_data: | ||
175 | M_ASN1_I2D_len(a->d.data,i2d_ASN1_OCTET_STRING); | ||
176 | break; | ||
177 | case NID_pkcs7_signed: | ||
178 | M_ASN1_I2D_len(a->d.sign,i2d_PKCS7_SIGNED); | ||
179 | break; | ||
180 | case NID_pkcs7_enveloped: | ||
181 | M_ASN1_I2D_len(a->d.enveloped,i2d_PKCS7_ENVELOPE); | ||
182 | break; | ||
183 | case NID_pkcs7_signedAndEnveloped: | ||
184 | M_ASN1_I2D_len(a->d.signed_and_enveloped, | ||
185 | i2d_PKCS7_SIGN_ENVELOPE); | ||
186 | break; | ||
187 | case NID_pkcs7_digest: | ||
188 | M_ASN1_I2D_len(a->d.digest,i2d_PKCS7_DIGEST); | ||
189 | break; | ||
190 | case NID_pkcs7_encrypted: | ||
191 | M_ASN1_I2D_len(a->d.encrypted,i2d_PKCS7_ENCRYPT); | ||
192 | break; | ||
193 | default: | ||
194 | M_ASN1_I2D_len(a->d.other,i2d_ASN1_TYPE); | ||
195 | break; | ||
196 | } | ||
197 | /* Work out explicit tag content size */ | ||
198 | explen = ret - r; | ||
199 | /* Work out explicit tag size: Note: ASN1_object_size | ||
200 | * includes the content length. | ||
201 | */ | ||
202 | ret = r + ASN1_object_size(1, explen, 0); | ||
203 | } | ||
204 | |||
205 | M_ASN1_I2D_seq_total(); | ||
206 | |||
207 | M_ASN1_I2D_put(a->type,i2d_ASN1_OBJECT); | ||
208 | |||
209 | if (a->d.ptr != NULL) | ||
210 | { | ||
211 | ASN1_put_object(&p, 1, explen, 0, V_ASN1_CONTEXT_SPECIFIC); | ||
212 | switch (OBJ_obj2nid(a->type)) | ||
213 | { | ||
214 | case NID_pkcs7_data: | ||
215 | M_ASN1_I2D_put(a->d.data,i2d_ASN1_OCTET_STRING); | ||
216 | break; | ||
217 | case NID_pkcs7_signed: | ||
218 | M_ASN1_I2D_put(a->d.sign,i2d_PKCS7_SIGNED); | ||
219 | break; | ||
220 | case NID_pkcs7_enveloped: | ||
221 | M_ASN1_I2D_put(a->d.enveloped,i2d_PKCS7_ENVELOPE); | ||
222 | break; | ||
223 | case NID_pkcs7_signedAndEnveloped: | ||
224 | M_ASN1_I2D_put(a->d.signed_and_enveloped, | ||
225 | i2d_PKCS7_SIGN_ENVELOPE); | ||
226 | break; | ||
227 | case NID_pkcs7_digest: | ||
228 | M_ASN1_I2D_put(a->d.digest,i2d_PKCS7_DIGEST); | ||
229 | break; | ||
230 | case NID_pkcs7_encrypted: | ||
231 | M_ASN1_I2D_put(a->d.encrypted,i2d_PKCS7_ENCRYPT); | ||
232 | break; | ||
233 | default: | ||
234 | M_ASN1_I2D_put(a->d.other,i2d_ASN1_TYPE); | ||
235 | break; | ||
236 | } | ||
237 | } | ||
238 | M_ASN1_I2D_finish(); | ||
239 | } | ||
240 | |||
241 | #endif | ||
242 | |||
147 | PKCS7 *d2i_PKCS7(PKCS7 **a, unsigned char **pp, long length) | 243 | PKCS7 *d2i_PKCS7(PKCS7 **a, unsigned char **pp, long length) |
148 | { | 244 | { |
149 | M_ASN1_D2I_vars(a,PKCS7 *,PKCS7_new); | 245 | M_ASN1_D2I_vars(a,PKCS7 *,PKCS7_new); |
@@ -152,7 +248,7 @@ PKCS7 *d2i_PKCS7(PKCS7 **a, unsigned char **pp, long length) | |||
152 | { | 248 | { |
153 | if ((*a)->asn1 != NULL) | 249 | if ((*a)->asn1 != NULL) |
154 | { | 250 | { |
155 | Free((*a)->asn1); | 251 | OPENSSL_free((*a)->asn1); |
156 | (*a)->asn1=NULL; | 252 | (*a)->asn1=NULL; |
157 | } | 253 | } |
158 | (*a)->length=0; | 254 | (*a)->length=0; |
@@ -206,10 +302,8 @@ PKCS7 *d2i_PKCS7(PKCS7 **a, unsigned char **pp, long length) | |||
206 | M_ASN1_D2I_get(ret->d.encrypted,d2i_PKCS7_ENCRYPT); | 302 | M_ASN1_D2I_get(ret->d.encrypted,d2i_PKCS7_ENCRYPT); |
207 | break; | 303 | break; |
208 | default: | 304 | default: |
209 | c.error=ASN1_R_BAD_PKCS7_TYPE; | 305 | M_ASN1_D2I_get(ret->d.other,d2i_ASN1_TYPE); |
210 | c.line=__LINE__; | 306 | break; |
211 | goto err; | ||
212 | /* break; */ | ||
213 | } | 307 | } |
214 | if (Tinf == (1|V_ASN1_CONSTRUCTED)) | 308 | if (Tinf == (1|V_ASN1_CONSTRUCTED)) |
215 | { | 309 | { |
@@ -251,7 +345,7 @@ void PKCS7_free(PKCS7 *a) | |||
251 | { | 345 | { |
252 | ASN1_OBJECT_free(a->type); | 346 | ASN1_OBJECT_free(a->type); |
253 | } | 347 | } |
254 | Free(a); | 348 | OPENSSL_free(a); |
255 | } | 349 | } |
256 | 350 | ||
257 | void PKCS7_content_free(PKCS7 *a) | 351 | void PKCS7_content_free(PKCS7 *a) |
@@ -259,7 +353,7 @@ void PKCS7_content_free(PKCS7 *a) | |||
259 | if(a == NULL) | 353 | if(a == NULL) |
260 | return; | 354 | return; |
261 | 355 | ||
262 | if (a->asn1 != NULL) Free(a->asn1); | 356 | if (a->asn1 != NULL) OPENSSL_free(a->asn1); |
263 | 357 | ||
264 | if (a->d.ptr != NULL) | 358 | if (a->d.ptr != NULL) |
265 | { | 359 | { |
@@ -286,10 +380,12 @@ void PKCS7_content_free(PKCS7 *a) | |||
286 | PKCS7_ENCRYPT_free(a->d.encrypted); | 380 | PKCS7_ENCRYPT_free(a->d.encrypted); |
287 | break; | 381 | break; |
288 | default: | 382 | default: |
289 | /* MEMORY LEAK */ | 383 | ASN1_TYPE_free(a->d.other); |
290 | break; | 384 | break; |
291 | } | 385 | } |
292 | } | 386 | } |
293 | a->d.ptr=NULL; | 387 | a->d.ptr=NULL; |
294 | } | 388 | } |
295 | 389 | ||
390 | IMPLEMENT_STACK_OF(PKCS7) | ||
391 | IMPLEMENT_ASN1_SET_OF(PKCS7) | ||