diff options
Diffstat (limited to 'src/lib/libcrypto/asn1')
74 files changed, 0 insertions, 17417 deletions
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c deleted file mode 100644 index f4ea96cd54..0000000000 --- a/src/lib/libcrypto/asn1/a_bitstr.c +++ /dev/null | |||
@@ -1,218 +0,0 @@ | |||
1 | /* crypto/asn1/a_bitstr.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1.h> | ||
62 | |||
63 | int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, unsigned char *d, int len) | ||
64 | { return M_ASN1_BIT_STRING_set(x, d, len); } | ||
65 | |||
66 | int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp) | ||
67 | { | ||
68 | int ret,j,bits,len; | ||
69 | unsigned char *p,*d; | ||
70 | |||
71 | if (a == NULL) return(0); | ||
72 | |||
73 | len=a->length; | ||
74 | |||
75 | if (len > 0) | ||
76 | { | ||
77 | if (a->flags & ASN1_STRING_FLAG_BITS_LEFT) | ||
78 | { | ||
79 | bits=(int)a->flags&0x07; | ||
80 | } | ||
81 | else | ||
82 | { | ||
83 | for ( ; len > 0; len--) | ||
84 | { | ||
85 | if (a->data[len-1]) break; | ||
86 | } | ||
87 | j=a->data[len-1]; | ||
88 | if (j & 0x01) bits=0; | ||
89 | else if (j & 0x02) bits=1; | ||
90 | else if (j & 0x04) bits=2; | ||
91 | else if (j & 0x08) bits=3; | ||
92 | else if (j & 0x10) bits=4; | ||
93 | else if (j & 0x20) bits=5; | ||
94 | else if (j & 0x40) bits=6; | ||
95 | else if (j & 0x80) bits=7; | ||
96 | else bits=0; /* should not happen */ | ||
97 | } | ||
98 | } | ||
99 | else | ||
100 | bits=0; | ||
101 | |||
102 | ret=1+len; | ||
103 | if (pp == NULL) return(ret); | ||
104 | |||
105 | p= *pp; | ||
106 | |||
107 | *(p++)=(unsigned char)bits; | ||
108 | d=a->data; | ||
109 | memcpy(p,d,len); | ||
110 | p+=len; | ||
111 | if (len > 0) p[-1]&=(0xff<<bits); | ||
112 | *pp=p; | ||
113 | return(ret); | ||
114 | } | ||
115 | |||
116 | ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp, | ||
117 | long len) | ||
118 | { | ||
119 | ASN1_BIT_STRING *ret=NULL; | ||
120 | unsigned char *p,*s; | ||
121 | int i; | ||
122 | |||
123 | if (len < 1) | ||
124 | { | ||
125 | i=ASN1_R_STRING_TOO_SHORT; | ||
126 | goto err; | ||
127 | } | ||
128 | |||
129 | if ((a == NULL) || ((*a) == NULL)) | ||
130 | { | ||
131 | if ((ret=M_ASN1_BIT_STRING_new()) == NULL) return(NULL); | ||
132 | } | ||
133 | else | ||
134 | ret=(*a); | ||
135 | |||
136 | p= *pp; | ||
137 | i= *(p++); | ||
138 | /* We do this to preserve the settings. If we modify | ||
139 | * the settings, via the _set_bit function, we will recalculate | ||
140 | * on output */ | ||
141 | ret->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear */ | ||
142 | ret->flags|=(ASN1_STRING_FLAG_BITS_LEFT|(i&0x07)); /* set */ | ||
143 | |||
144 | if (len-- > 1) /* using one because of the bits left byte */ | ||
145 | { | ||
146 | s=(unsigned char *)OPENSSL_malloc((int)len); | ||
147 | if (s == NULL) | ||
148 | { | ||
149 | i=ERR_R_MALLOC_FAILURE; | ||
150 | goto err; | ||
151 | } | ||
152 | memcpy(s,p,(int)len); | ||
153 | s[len-1]&=(0xff<<i); | ||
154 | p+=len; | ||
155 | } | ||
156 | else | ||
157 | s=NULL; | ||
158 | |||
159 | ret->length=(int)len; | ||
160 | if (ret->data != NULL) OPENSSL_free(ret->data); | ||
161 | ret->data=s; | ||
162 | ret->type=V_ASN1_BIT_STRING; | ||
163 | if (a != NULL) (*a)=ret; | ||
164 | *pp=p; | ||
165 | return(ret); | ||
166 | err: | ||
167 | ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,i); | ||
168 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
169 | M_ASN1_BIT_STRING_free(ret); | ||
170 | return(NULL); | ||
171 | } | ||
172 | |||
173 | /* These next 2 functions from Goetz Babin-Ebell <babinebell@trustcenter.de> | ||
174 | */ | ||
175 | int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value) | ||
176 | { | ||
177 | int w,v,iv; | ||
178 | unsigned char *c; | ||
179 | |||
180 | w=n/8; | ||
181 | v=1<<(7-(n&0x07)); | ||
182 | iv= ~v; | ||
183 | if (!value) v=0; | ||
184 | |||
185 | a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */ | ||
186 | |||
187 | if (a == NULL) return(0); | ||
188 | if ((a->length < (w+1)) || (a->data == NULL)) | ||
189 | { | ||
190 | if (!value) return(1); /* Don't need to set */ | ||
191 | if (a->data == NULL) | ||
192 | c=(unsigned char *)OPENSSL_malloc(w+1); | ||
193 | else | ||
194 | c=(unsigned char *)OPENSSL_realloc_clean(a->data, | ||
195 | a->length, | ||
196 | w+1); | ||
197 | if (c == NULL) return(0); | ||
198 | if (w+1-a->length > 0) memset(c+a->length, 0, w+1-a->length); | ||
199 | a->data=c; | ||
200 | a->length=w+1; | ||
201 | } | ||
202 | a->data[w]=((a->data[w])&iv)|v; | ||
203 | while ((a->length > 0) && (a->data[a->length-1] == 0)) | ||
204 | a->length--; | ||
205 | return(1); | ||
206 | } | ||
207 | |||
208 | int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n) | ||
209 | { | ||
210 | int w,v; | ||
211 | |||
212 | w=n/8; | ||
213 | v=1<<(7-(n&0x07)); | ||
214 | if ((a == NULL) || (a->length < (w+1)) || (a->data == NULL)) | ||
215 | return(0); | ||
216 | return((a->data[w]&v) != 0); | ||
217 | } | ||
218 | |||
diff --git a/src/lib/libcrypto/asn1/a_bool.c b/src/lib/libcrypto/asn1/a_bool.c deleted file mode 100644 index 24333ea4d5..0000000000 --- a/src/lib/libcrypto/asn1/a_bool.c +++ /dev/null | |||
@@ -1,114 +0,0 @@ | |||
1 | /* crypto/asn1/a_bool.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1t.h> | ||
62 | |||
63 | int i2d_ASN1_BOOLEAN(int a, unsigned char **pp) | ||
64 | { | ||
65 | int r; | ||
66 | unsigned char *p; | ||
67 | |||
68 | r=ASN1_object_size(0,1,V_ASN1_BOOLEAN); | ||
69 | if (pp == NULL) return(r); | ||
70 | p= *pp; | ||
71 | |||
72 | ASN1_put_object(&p,0,1,V_ASN1_BOOLEAN,V_ASN1_UNIVERSAL); | ||
73 | *(p++)= (unsigned char)a; | ||
74 | *pp=p; | ||
75 | return(r); | ||
76 | } | ||
77 | |||
78 | int d2i_ASN1_BOOLEAN(int *a, unsigned char **pp, long length) | ||
79 | { | ||
80 | int ret= -1; | ||
81 | unsigned char *p; | ||
82 | long len; | ||
83 | int inf,tag,xclass; | ||
84 | int i=0; | ||
85 | |||
86 | p= *pp; | ||
87 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
88 | if (inf & 0x80) | ||
89 | { | ||
90 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
91 | goto err; | ||
92 | } | ||
93 | |||
94 | if (tag != V_ASN1_BOOLEAN) | ||
95 | { | ||
96 | i=ASN1_R_EXPECTING_A_BOOLEAN; | ||
97 | goto err; | ||
98 | } | ||
99 | |||
100 | if (len != 1) | ||
101 | { | ||
102 | i=ASN1_R_BOOLEAN_IS_WRONG_LENGTH; | ||
103 | goto err; | ||
104 | } | ||
105 | ret= (int)*(p++); | ||
106 | if (a != NULL) (*a)=ret; | ||
107 | *pp=p; | ||
108 | return(ret); | ||
109 | err: | ||
110 | ASN1err(ASN1_F_D2I_ASN1_BOOLEAN,i); | ||
111 | return(ret); | ||
112 | } | ||
113 | |||
114 | |||
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c deleted file mode 100644 index 2407f7c87a..0000000000 --- a/src/lib/libcrypto/asn1/a_bytes.c +++ /dev/null | |||
@@ -1,312 +0,0 @@ | |||
1 | /* crypto/asn1/a_bytes.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1.h> | ||
62 | |||
63 | static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c); | ||
64 | /* type is a 'bitmap' of acceptable string types. | ||
65 | */ | ||
66 | ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, unsigned char **pp, | ||
67 | long length, int type) | ||
68 | { | ||
69 | ASN1_STRING *ret=NULL; | ||
70 | unsigned char *p,*s; | ||
71 | long len; | ||
72 | int inf,tag,xclass; | ||
73 | int i=0; | ||
74 | |||
75 | p= *pp; | ||
76 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
77 | if (inf & 0x80) goto err; | ||
78 | |||
79 | if (tag >= 32) | ||
80 | { | ||
81 | i=ASN1_R_TAG_VALUE_TOO_HIGH; | ||
82 | goto err; | ||
83 | } | ||
84 | if (!(ASN1_tag2bit(tag) & type)) | ||
85 | { | ||
86 | i=ASN1_R_WRONG_TYPE; | ||
87 | goto err; | ||
88 | } | ||
89 | |||
90 | /* If a bit-string, exit early */ | ||
91 | if (tag == V_ASN1_BIT_STRING) | ||
92 | return(d2i_ASN1_BIT_STRING(a,pp,length)); | ||
93 | |||
94 | if ((a == NULL) || ((*a) == NULL)) | ||
95 | { | ||
96 | if ((ret=ASN1_STRING_new()) == NULL) return(NULL); | ||
97 | } | ||
98 | else | ||
99 | ret=(*a); | ||
100 | |||
101 | if (len != 0) | ||
102 | { | ||
103 | s=(unsigned char *)OPENSSL_malloc((int)len+1); | ||
104 | if (s == NULL) | ||
105 | { | ||
106 | i=ERR_R_MALLOC_FAILURE; | ||
107 | goto err; | ||
108 | } | ||
109 | memcpy(s,p,(int)len); | ||
110 | s[len]='\0'; | ||
111 | p+=len; | ||
112 | } | ||
113 | else | ||
114 | s=NULL; | ||
115 | |||
116 | if (ret->data != NULL) OPENSSL_free(ret->data); | ||
117 | ret->length=(int)len; | ||
118 | ret->data=s; | ||
119 | ret->type=tag; | ||
120 | if (a != NULL) (*a)=ret; | ||
121 | *pp=p; | ||
122 | return(ret); | ||
123 | err: | ||
124 | ASN1err(ASN1_F_D2I_ASN1_TYPE_BYTES,i); | ||
125 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
126 | ASN1_STRING_free(ret); | ||
127 | return(NULL); | ||
128 | } | ||
129 | |||
130 | int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass) | ||
131 | { | ||
132 | int ret,r,constructed; | ||
133 | unsigned char *p; | ||
134 | |||
135 | if (a == NULL) return(0); | ||
136 | |||
137 | if (tag == V_ASN1_BIT_STRING) | ||
138 | return(i2d_ASN1_BIT_STRING(a,pp)); | ||
139 | |||
140 | ret=a->length; | ||
141 | r=ASN1_object_size(0,ret,tag); | ||
142 | if (pp == NULL) return(r); | ||
143 | p= *pp; | ||
144 | |||
145 | if ((tag == V_ASN1_SEQUENCE) || (tag == V_ASN1_SET)) | ||
146 | constructed=1; | ||
147 | else | ||
148 | constructed=0; | ||
149 | ASN1_put_object(&p,constructed,ret,tag,xclass); | ||
150 | memcpy(p,a->data,a->length); | ||
151 | p+=a->length; | ||
152 | *pp= p; | ||
153 | return(r); | ||
154 | } | ||
155 | |||
156 | ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, long length, | ||
157 | int Ptag, int Pclass) | ||
158 | { | ||
159 | ASN1_STRING *ret=NULL; | ||
160 | unsigned char *p,*s; | ||
161 | long len; | ||
162 | int inf,tag,xclass; | ||
163 | int i=0; | ||
164 | |||
165 | if ((a == NULL) || ((*a) == NULL)) | ||
166 | { | ||
167 | if ((ret=ASN1_STRING_new()) == NULL) return(NULL); | ||
168 | } | ||
169 | else | ||
170 | ret=(*a); | ||
171 | |||
172 | p= *pp; | ||
173 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
174 | if (inf & 0x80) | ||
175 | { | ||
176 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
177 | goto err; | ||
178 | } | ||
179 | |||
180 | if (tag != Ptag) | ||
181 | { | ||
182 | i=ASN1_R_WRONG_TAG; | ||
183 | goto err; | ||
184 | } | ||
185 | |||
186 | if (inf & V_ASN1_CONSTRUCTED) | ||
187 | { | ||
188 | ASN1_CTX c; | ||
189 | |||
190 | c.pp=pp; | ||
191 | c.p=p; | ||
192 | c.inf=inf; | ||
193 | c.slen=len; | ||
194 | c.tag=Ptag; | ||
195 | c.xclass=Pclass; | ||
196 | c.max=(length == 0)?0:(p+length); | ||
197 | if (!asn1_collate_primitive(ret,&c)) | ||
198 | goto err; | ||
199 | else | ||
200 | { | ||
201 | p=c.p; | ||
202 | } | ||
203 | } | ||
204 | else | ||
205 | { | ||
206 | if (len != 0) | ||
207 | { | ||
208 | if ((ret->length < len) || (ret->data == NULL)) | ||
209 | { | ||
210 | if (ret->data != NULL) OPENSSL_free(ret->data); | ||
211 | s=(unsigned char *)OPENSSL_malloc((int)len + 1); | ||
212 | if (s == NULL) | ||
213 | { | ||
214 | i=ERR_R_MALLOC_FAILURE; | ||
215 | goto err; | ||
216 | } | ||
217 | } | ||
218 | else | ||
219 | s=ret->data; | ||
220 | memcpy(s,p,(int)len); | ||
221 | s[len] = '\0'; | ||
222 | p+=len; | ||
223 | } | ||
224 | else | ||
225 | { | ||
226 | s=NULL; | ||
227 | if (ret->data != NULL) OPENSSL_free(ret->data); | ||
228 | } | ||
229 | |||
230 | ret->length=(int)len; | ||
231 | ret->data=s; | ||
232 | ret->type=Ptag; | ||
233 | } | ||
234 | |||
235 | if (a != NULL) (*a)=ret; | ||
236 | *pp=p; | ||
237 | return(ret); | ||
238 | err: | ||
239 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
240 | ASN1_STRING_free(ret); | ||
241 | ASN1err(ASN1_F_D2I_ASN1_BYTES,i); | ||
242 | return(NULL); | ||
243 | } | ||
244 | |||
245 | |||
246 | /* We are about to parse 0..n d2i_ASN1_bytes objects, we are to collapse | ||
247 | * them into the one structure that is then returned */ | ||
248 | /* There have been a few bug fixes for this function from | ||
249 | * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */ | ||
250 | static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c) | ||
251 | { | ||
252 | ASN1_STRING *os=NULL; | ||
253 | BUF_MEM b; | ||
254 | int num; | ||
255 | |||
256 | b.length=0; | ||
257 | b.max=0; | ||
258 | b.data=NULL; | ||
259 | |||
260 | if (a == NULL) | ||
261 | { | ||
262 | c->error=ERR_R_PASSED_NULL_PARAMETER; | ||
263 | goto err; | ||
264 | } | ||
265 | |||
266 | num=0; | ||
267 | for (;;) | ||
268 | { | ||
269 | if (c->inf & 1) | ||
270 | { | ||
271 | c->eos=ASN1_check_infinite_end(&c->p, | ||
272 | (long)(c->max-c->p)); | ||
273 | if (c->eos) break; | ||
274 | } | ||
275 | else | ||
276 | { | ||
277 | if (c->slen <= 0) break; | ||
278 | } | ||
279 | |||
280 | c->q=c->p; | ||
281 | if (d2i_ASN1_bytes(&os,&c->p,c->max-c->p,c->tag,c->xclass) | ||
282 | == NULL) | ||
283 | { | ||
284 | c->error=ERR_R_ASN1_LIB; | ||
285 | goto err; | ||
286 | } | ||
287 | |||
288 | if (!BUF_MEM_grow_clean(&b,num+os->length)) | ||
289 | { | ||
290 | c->error=ERR_R_BUF_LIB; | ||
291 | goto err; | ||
292 | } | ||
293 | memcpy(&(b.data[num]),os->data,os->length); | ||
294 | if (!(c->inf & 1)) | ||
295 | c->slen-=(c->p-c->q); | ||
296 | num+=os->length; | ||
297 | } | ||
298 | |||
299 | if (!asn1_Finish(c)) goto err; | ||
300 | |||
301 | a->length=num; | ||
302 | if (a->data != NULL) OPENSSL_free(a->data); | ||
303 | a->data=(unsigned char *)b.data; | ||
304 | if (os != NULL) ASN1_STRING_free(os); | ||
305 | return(1); | ||
306 | err: | ||
307 | ASN1err(ASN1_F_ASN1_COLLATE_PRIMITIVE,c->error); | ||
308 | if (os != NULL) ASN1_STRING_free(os); | ||
309 | if (b.data != NULL) OPENSSL_free(b.data); | ||
310 | return(0); | ||
311 | } | ||
312 | |||
diff --git a/src/lib/libcrypto/asn1/a_d2i_fp.c b/src/lib/libcrypto/asn1/a_d2i_fp.c deleted file mode 100644 index b67b75e7c2..0000000000 --- a/src/lib/libcrypto/asn1/a_d2i_fp.c +++ /dev/null | |||
@@ -1,262 +0,0 @@ | |||
1 | /* crypto/asn1/a_d2i_fp.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/buffer.h> | ||
62 | #include <openssl/asn1_mac.h> | ||
63 | |||
64 | static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb); | ||
65 | |||
66 | #ifndef NO_OLD_ASN1 | ||
67 | #ifndef OPENSSL_NO_FP_API | ||
68 | |||
69 | char *ASN1_d2i_fp(char *(*xnew)(), char *(*d2i)(), FILE *in, | ||
70 | unsigned char **x) | ||
71 | { | ||
72 | BIO *b; | ||
73 | char *ret; | ||
74 | |||
75 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
76 | { | ||
77 | ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB); | ||
78 | return(NULL); | ||
79 | } | ||
80 | BIO_set_fp(b,in,BIO_NOCLOSE); | ||
81 | ret=ASN1_d2i_bio(xnew,d2i,b,x); | ||
82 | BIO_free(b); | ||
83 | return(ret); | ||
84 | } | ||
85 | #endif | ||
86 | |||
87 | char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in, | ||
88 | unsigned char **x) | ||
89 | { | ||
90 | BUF_MEM *b = NULL; | ||
91 | unsigned char *p; | ||
92 | char *ret=NULL; | ||
93 | int len; | ||
94 | |||
95 | len = asn1_d2i_read_bio(in, &b); | ||
96 | if(len < 0) goto err; | ||
97 | |||
98 | p=(unsigned char *)b->data; | ||
99 | ret=d2i(x,&p,len); | ||
100 | err: | ||
101 | if (b != NULL) BUF_MEM_free(b); | ||
102 | return(ret); | ||
103 | } | ||
104 | |||
105 | #endif | ||
106 | |||
107 | void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x) | ||
108 | { | ||
109 | BUF_MEM *b = NULL; | ||
110 | unsigned char *p; | ||
111 | void *ret=NULL; | ||
112 | int len; | ||
113 | |||
114 | len = asn1_d2i_read_bio(in, &b); | ||
115 | if(len < 0) goto err; | ||
116 | |||
117 | p=(unsigned char *)b->data; | ||
118 | ret=ASN1_item_d2i(x,&p,len, it); | ||
119 | err: | ||
120 | if (b != NULL) BUF_MEM_free(b); | ||
121 | return(ret); | ||
122 | } | ||
123 | |||
124 | #ifndef OPENSSL_NO_FP_API | ||
125 | void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x) | ||
126 | { | ||
127 | BIO *b; | ||
128 | char *ret; | ||
129 | |||
130 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
131 | { | ||
132 | ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB); | ||
133 | return(NULL); | ||
134 | } | ||
135 | BIO_set_fp(b,in,BIO_NOCLOSE); | ||
136 | ret=ASN1_item_d2i_bio(it,b,x); | ||
137 | BIO_free(b); | ||
138 | return(ret); | ||
139 | } | ||
140 | #endif | ||
141 | |||
142 | #define HEADER_SIZE 8 | ||
143 | static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb) | ||
144 | { | ||
145 | BUF_MEM *b; | ||
146 | unsigned char *p; | ||
147 | int i; | ||
148 | int ret=-1; | ||
149 | ASN1_CTX c; | ||
150 | int want=HEADER_SIZE; | ||
151 | int eos=0; | ||
152 | #if defined(__GNUC__) && defined(__ia64) | ||
153 | /* pathetic compiler bug in all known versions as of Nov. 2002 */ | ||
154 | long off=0; | ||
155 | #else | ||
156 | int off=0; | ||
157 | #endif | ||
158 | int len=0; | ||
159 | |||
160 | b=BUF_MEM_new(); | ||
161 | if (b == NULL) | ||
162 | { | ||
163 | ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); | ||
164 | return -1; | ||
165 | } | ||
166 | |||
167 | ERR_clear_error(); | ||
168 | for (;;) | ||
169 | { | ||
170 | if (want >= (len-off)) | ||
171 | { | ||
172 | want-=(len-off); | ||
173 | |||
174 | if (!BUF_MEM_grow_clean(b,len+want)) | ||
175 | { | ||
176 | ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); | ||
177 | goto err; | ||
178 | } | ||
179 | i=BIO_read(in,&(b->data[len]),want); | ||
180 | if ((i < 0) && ((len-off) == 0)) | ||
181 | { | ||
182 | ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA); | ||
183 | goto err; | ||
184 | } | ||
185 | if (i > 0) | ||
186 | len+=i; | ||
187 | } | ||
188 | /* else data already loaded */ | ||
189 | |||
190 | p=(unsigned char *)&(b->data[off]); | ||
191 | c.p=p; | ||
192 | c.inf=ASN1_get_object(&(c.p),&(c.slen),&(c.tag),&(c.xclass), | ||
193 | len-off); | ||
194 | if (c.inf & 0x80) | ||
195 | { | ||
196 | unsigned long e; | ||
197 | |||
198 | e=ERR_GET_REASON(ERR_peek_error()); | ||
199 | if (e != ASN1_R_TOO_LONG) | ||
200 | goto err; | ||
201 | else | ||
202 | ERR_get_error(); /* clear error */ | ||
203 | } | ||
204 | i=c.p-p;/* header length */ | ||
205 | off+=i; /* end of data */ | ||
206 | |||
207 | if (c.inf & 1) | ||
208 | { | ||
209 | /* no data body so go round again */ | ||
210 | eos++; | ||
211 | want=HEADER_SIZE; | ||
212 | } | ||
213 | else if (eos && (c.slen == 0) && (c.tag == V_ASN1_EOC)) | ||
214 | { | ||
215 | /* eos value, so go back and read another header */ | ||
216 | eos--; | ||
217 | if (eos <= 0) | ||
218 | break; | ||
219 | else | ||
220 | want=HEADER_SIZE; | ||
221 | } | ||
222 | else | ||
223 | { | ||
224 | /* suck in c.slen bytes of data */ | ||
225 | want=(int)c.slen; | ||
226 | if (want > (len-off)) | ||
227 | { | ||
228 | want-=(len-off); | ||
229 | if (!BUF_MEM_grow_clean(b,len+want)) | ||
230 | { | ||
231 | ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); | ||
232 | goto err; | ||
233 | } | ||
234 | while (want > 0) | ||
235 | { | ||
236 | i=BIO_read(in,&(b->data[len]),want); | ||
237 | if (i <= 0) | ||
238 | { | ||
239 | ASN1err(ASN1_F_ASN1_D2I_BIO, | ||
240 | ASN1_R_NOT_ENOUGH_DATA); | ||
241 | goto err; | ||
242 | } | ||
243 | len+=i; | ||
244 | want -= i; | ||
245 | } | ||
246 | } | ||
247 | off+=(int)c.slen; | ||
248 | if (eos <= 0) | ||
249 | { | ||
250 | break; | ||
251 | } | ||
252 | else | ||
253 | want=HEADER_SIZE; | ||
254 | } | ||
255 | } | ||
256 | |||
257 | *pb = b; | ||
258 | return off; | ||
259 | err: | ||
260 | if (b != NULL) BUF_MEM_free(b); | ||
261 | return(ret); | ||
262 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_digest.c b/src/lib/libcrypto/asn1/a_digest.c deleted file mode 100644 index 4931e222a0..0000000000 --- a/src/lib/libcrypto/asn1/a_digest.c +++ /dev/null | |||
@@ -1,106 +0,0 @@ | |||
1 | /* crypto/asn1/a_digest.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <time.h> | ||
61 | |||
62 | #include "cryptlib.h" | ||
63 | |||
64 | #ifndef NO_SYS_TYPES_H | ||
65 | # include <sys/types.h> | ||
66 | #endif | ||
67 | |||
68 | #include <openssl/evp.h> | ||
69 | #include <openssl/buffer.h> | ||
70 | #include <openssl/x509.h> | ||
71 | |||
72 | #ifndef NO_ASN1_OLD | ||
73 | |||
74 | int ASN1_digest(int (*i2d)(), const EVP_MD *type, char *data, | ||
75 | unsigned char *md, unsigned int *len) | ||
76 | { | ||
77 | int i; | ||
78 | unsigned char *str,*p; | ||
79 | |||
80 | i=i2d(data,NULL); | ||
81 | if ((str=(unsigned char *)OPENSSL_malloc(i)) == NULL) return(0); | ||
82 | p=str; | ||
83 | i2d(data,&p); | ||
84 | |||
85 | EVP_Digest(str, i, md, len, type, NULL); | ||
86 | OPENSSL_free(str); | ||
87 | return(1); | ||
88 | } | ||
89 | |||
90 | #endif | ||
91 | |||
92 | |||
93 | int ASN1_item_digest(const ASN1_ITEM *it, const EVP_MD *type, void *asn, | ||
94 | unsigned char *md, unsigned int *len) | ||
95 | { | ||
96 | int i; | ||
97 | unsigned char *str = NULL; | ||
98 | |||
99 | i=ASN1_item_i2d(asn,&str, it); | ||
100 | if (!str) return(0); | ||
101 | |||
102 | EVP_Digest(str, i, md, len, type, NULL); | ||
103 | OPENSSL_free(str); | ||
104 | return(1); | ||
105 | } | ||
106 | |||
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c deleted file mode 100644 index 58a017884c..0000000000 --- a/src/lib/libcrypto/asn1/a_dup.c +++ /dev/null | |||
@@ -1,107 +0,0 @@ | |||
1 | /* crypto/asn1/a_dup.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1.h> | ||
62 | |||
63 | #ifndef NO_OLD_ASN1 | ||
64 | |||
65 | char *ASN1_dup(int (*i2d)(), char *(*d2i)(), char *x) | ||
66 | { | ||
67 | unsigned char *b,*p; | ||
68 | long i; | ||
69 | char *ret; | ||
70 | |||
71 | if (x == NULL) return(NULL); | ||
72 | |||
73 | i=(long)i2d(x,NULL); | ||
74 | b=(unsigned char *)OPENSSL_malloc((unsigned int)i+10); | ||
75 | if (b == NULL) | ||
76 | { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } | ||
77 | p= b; | ||
78 | i=i2d(x,&p); | ||
79 | p= b; | ||
80 | ret=d2i(NULL,&p,i); | ||
81 | OPENSSL_free(b); | ||
82 | return(ret); | ||
83 | } | ||
84 | |||
85 | #endif | ||
86 | |||
87 | /* ASN1_ITEM version of dup: this follows the model above except we don't need | ||
88 | * to allocate the buffer. At some point this could be rewritten to directly dup | ||
89 | * the underlying structure instead of doing and encode and decode. | ||
90 | */ | ||
91 | |||
92 | void *ASN1_item_dup(const ASN1_ITEM *it, void *x) | ||
93 | { | ||
94 | unsigned char *b = NULL, *p; | ||
95 | long i; | ||
96 | void *ret; | ||
97 | |||
98 | if (x == NULL) return(NULL); | ||
99 | |||
100 | i=ASN1_item_i2d(x,&b,it); | ||
101 | if (b == NULL) | ||
102 | { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } | ||
103 | p= b; | ||
104 | ret=ASN1_item_d2i(NULL,&p,i, it); | ||
105 | OPENSSL_free(b); | ||
106 | return(ret); | ||
107 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c deleted file mode 100644 index ad8f0ffd1a..0000000000 --- a/src/lib/libcrypto/asn1/a_enum.c +++ /dev/null | |||
@@ -1,180 +0,0 @@ | |||
1 | /* crypto/asn1/a_enum.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1.h> | ||
62 | |||
63 | /* | ||
64 | * Code for ENUMERATED type: identical to INTEGER apart from a different tag. | ||
65 | * for comments on encoding see a_int.c | ||
66 | */ | ||
67 | |||
68 | int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) | ||
69 | { | ||
70 | int i,j,k; | ||
71 | unsigned char buf[sizeof(long)+1]; | ||
72 | long d; | ||
73 | |||
74 | a->type=V_ASN1_ENUMERATED; | ||
75 | if (a->length < (sizeof(long)+1)) | ||
76 | { | ||
77 | if (a->data != NULL) | ||
78 | OPENSSL_free(a->data); | ||
79 | if ((a->data=(unsigned char *)OPENSSL_malloc(sizeof(long)+1)) != NULL) | ||
80 | memset((char *)a->data,0,sizeof(long)+1); | ||
81 | } | ||
82 | if (a->data == NULL) | ||
83 | { | ||
84 | ASN1err(ASN1_F_ASN1_ENUMERATED_SET,ERR_R_MALLOC_FAILURE); | ||
85 | return(0); | ||
86 | } | ||
87 | d=v; | ||
88 | if (d < 0) | ||
89 | { | ||
90 | d= -d; | ||
91 | a->type=V_ASN1_NEG_ENUMERATED; | ||
92 | } | ||
93 | |||
94 | for (i=0; i<sizeof(long); i++) | ||
95 | { | ||
96 | if (d == 0) break; | ||
97 | buf[i]=(int)d&0xff; | ||
98 | d>>=8; | ||
99 | } | ||
100 | j=0; | ||
101 | for (k=i-1; k >=0; k--) | ||
102 | a->data[j++]=buf[k]; | ||
103 | a->length=j; | ||
104 | return(1); | ||
105 | } | ||
106 | |||
107 | long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a) | ||
108 | { | ||
109 | int neg=0,i; | ||
110 | long r=0; | ||
111 | |||
112 | if (a == NULL) return(0L); | ||
113 | i=a->type; | ||
114 | if (i == V_ASN1_NEG_ENUMERATED) | ||
115 | neg=1; | ||
116 | else if (i != V_ASN1_ENUMERATED) | ||
117 | return -1; | ||
118 | |||
119 | if (a->length > sizeof(long)) | ||
120 | { | ||
121 | /* hmm... a bit ugly */ | ||
122 | return(0xffffffffL); | ||
123 | } | ||
124 | if (a->data == NULL) | ||
125 | return 0; | ||
126 | |||
127 | for (i=0; i<a->length; i++) | ||
128 | { | ||
129 | r<<=8; | ||
130 | r|=(unsigned char)a->data[i]; | ||
131 | } | ||
132 | if (neg) r= -r; | ||
133 | return(r); | ||
134 | } | ||
135 | |||
136 | ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai) | ||
137 | { | ||
138 | ASN1_ENUMERATED *ret; | ||
139 | int len,j; | ||
140 | |||
141 | if (ai == NULL) | ||
142 | ret=M_ASN1_ENUMERATED_new(); | ||
143 | else | ||
144 | ret=ai; | ||
145 | if (ret == NULL) | ||
146 | { | ||
147 | ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR); | ||
148 | goto err; | ||
149 | } | ||
150 | if(bn->neg) ret->type = V_ASN1_NEG_ENUMERATED; | ||
151 | else ret->type=V_ASN1_ENUMERATED; | ||
152 | j=BN_num_bits(bn); | ||
153 | len=((j == 0)?0:((j/8)+1)); | ||
154 | if (ret->length < len+4) | ||
155 | { | ||
156 | unsigned char *new_data=OPENSSL_realloc(ret->data, len+4); | ||
157 | if (!new_data) | ||
158 | { | ||
159 | ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); | ||
160 | goto err; | ||
161 | } | ||
162 | ret->data=new_data; | ||
163 | } | ||
164 | |||
165 | ret->length=BN_bn2bin(bn,ret->data); | ||
166 | return(ret); | ||
167 | err: | ||
168 | if (ret != ai) M_ASN1_ENUMERATED_free(ret); | ||
169 | return(NULL); | ||
170 | } | ||
171 | |||
172 | BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn) | ||
173 | { | ||
174 | BIGNUM *ret; | ||
175 | |||
176 | if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) | ||
177 | ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB); | ||
178 | else if(ai->type == V_ASN1_NEG_ENUMERATED) ret->neg = 1; | ||
179 | return(ret); | ||
180 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_i2d_fp.c b/src/lib/libcrypto/asn1/a_i2d_fp.c deleted file mode 100644 index f4f1b73ebe..0000000000 --- a/src/lib/libcrypto/asn1/a_i2d_fp.c +++ /dev/null | |||
@@ -1,163 +0,0 @@ | |||
1 | /* crypto/asn1/a_i2d_fp.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/buffer.h> | ||
62 | #include <openssl/asn1.h> | ||
63 | |||
64 | #ifndef NO_OLD_ASN1 | ||
65 | |||
66 | #ifndef OPENSSL_NO_FP_API | ||
67 | int ASN1_i2d_fp(int (*i2d)(), FILE *out, unsigned char *x) | ||
68 | { | ||
69 | BIO *b; | ||
70 | int ret; | ||
71 | |||
72 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
73 | { | ||
74 | ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB); | ||
75 | return(0); | ||
76 | } | ||
77 | BIO_set_fp(b,out,BIO_NOCLOSE); | ||
78 | ret=ASN1_i2d_bio(i2d,b,x); | ||
79 | BIO_free(b); | ||
80 | return(ret); | ||
81 | } | ||
82 | #endif | ||
83 | |||
84 | int ASN1_i2d_bio(int (*i2d)(), BIO *out, unsigned char *x) | ||
85 | { | ||
86 | char *b; | ||
87 | unsigned char *p; | ||
88 | int i,j=0,n,ret=1; | ||
89 | |||
90 | n=i2d(x,NULL); | ||
91 | b=(char *)OPENSSL_malloc(n); | ||
92 | if (b == NULL) | ||
93 | { | ||
94 | ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); | ||
95 | return(0); | ||
96 | } | ||
97 | |||
98 | p=(unsigned char *)b; | ||
99 | i2d(x,&p); | ||
100 | |||
101 | for (;;) | ||
102 | { | ||
103 | i=BIO_write(out,&(b[j]),n); | ||
104 | if (i == n) break; | ||
105 | if (i <= 0) | ||
106 | { | ||
107 | ret=0; | ||
108 | break; | ||
109 | } | ||
110 | j+=i; | ||
111 | n-=i; | ||
112 | } | ||
113 | OPENSSL_free(b); | ||
114 | return(ret); | ||
115 | } | ||
116 | |||
117 | #endif | ||
118 | |||
119 | #ifndef OPENSSL_NO_FP_API | ||
120 | int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) | ||
121 | { | ||
122 | BIO *b; | ||
123 | int ret; | ||
124 | |||
125 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
126 | { | ||
127 | ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB); | ||
128 | return(0); | ||
129 | } | ||
130 | BIO_set_fp(b,out,BIO_NOCLOSE); | ||
131 | ret=ASN1_item_i2d_bio(it,b,x); | ||
132 | BIO_free(b); | ||
133 | return(ret); | ||
134 | } | ||
135 | #endif | ||
136 | |||
137 | int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x) | ||
138 | { | ||
139 | unsigned char *b = NULL; | ||
140 | int i,j=0,n,ret=1; | ||
141 | |||
142 | n = ASN1_item_i2d(x, &b, it); | ||
143 | if (b == NULL) | ||
144 | { | ||
145 | ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE); | ||
146 | return(0); | ||
147 | } | ||
148 | |||
149 | for (;;) | ||
150 | { | ||
151 | i=BIO_write(out,&(b[j]),n); | ||
152 | if (i == n) break; | ||
153 | if (i <= 0) | ||
154 | { | ||
155 | ret=0; | ||
156 | break; | ||
157 | } | ||
158 | j+=i; | ||
159 | n-=i; | ||
160 | } | ||
161 | OPENSSL_free(b); | ||
162 | return(ret); | ||
163 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c deleted file mode 100644 index edb243c021..0000000000 --- a/src/lib/libcrypto/asn1/a_int.c +++ /dev/null | |||
@@ -1,434 +0,0 @@ | |||
1 | /* crypto/asn1/a_int.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1.h> | ||
62 | |||
63 | ASN1_INTEGER *ASN1_INTEGER_dup(ASN1_INTEGER *x) | ||
64 | { return M_ASN1_INTEGER_dup(x);} | ||
65 | |||
66 | int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y) | ||
67 | { return M_ASN1_INTEGER_cmp(x,y);} | ||
68 | |||
69 | /* | ||
70 | * This converts an ASN1 INTEGER into its content encoding. | ||
71 | * The internal representation is an ASN1_STRING whose data is a big endian | ||
72 | * representation of the value, ignoring the sign. The sign is determined by | ||
73 | * the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative. | ||
74 | * | ||
75 | * Positive integers are no problem: they are almost the same as the DER | ||
76 | * encoding, except if the first byte is >= 0x80 we need to add a zero pad. | ||
77 | * | ||
78 | * Negative integers are a bit trickier... | ||
79 | * The DER representation of negative integers is in 2s complement form. | ||
80 | * The internal form is converted by complementing each octet and finally | ||
81 | * adding one to the result. This can be done less messily with a little trick. | ||
82 | * If the internal form has trailing zeroes then they will become FF by the | ||
83 | * complement and 0 by the add one (due to carry) so just copy as many trailing | ||
84 | * zeros to the destination as there are in the source. The carry will add one | ||
85 | * to the last none zero octet: so complement this octet and add one and finally | ||
86 | * complement any left over until you get to the start of the string. | ||
87 | * | ||
88 | * Padding is a little trickier too. If the first bytes is > 0x80 then we pad | ||
89 | * with 0xff. However if the first byte is 0x80 and one of the following bytes | ||
90 | * is non-zero we pad with 0xff. The reason for this distinction is that 0x80 | ||
91 | * followed by optional zeros isn't padded. | ||
92 | */ | ||
93 | |||
94 | int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp) | ||
95 | { | ||
96 | int pad=0,ret,i,neg; | ||
97 | unsigned char *p,*n,pb=0; | ||
98 | |||
99 | if ((a == NULL) || (a->data == NULL)) return(0); | ||
100 | neg=a->type & V_ASN1_NEG; | ||
101 | if (a->length == 0) | ||
102 | ret=1; | ||
103 | else | ||
104 | { | ||
105 | ret=a->length; | ||
106 | i=a->data[0]; | ||
107 | if (!neg && (i > 127)) { | ||
108 | pad=1; | ||
109 | pb=0; | ||
110 | } else if(neg) { | ||
111 | if(i>128) { | ||
112 | pad=1; | ||
113 | pb=0xFF; | ||
114 | } else if(i == 128) { | ||
115 | /* | ||
116 | * Special case: if any other bytes non zero we pad: | ||
117 | * otherwise we don't. | ||
118 | */ | ||
119 | for(i = 1; i < a->length; i++) if(a->data[i]) { | ||
120 | pad=1; | ||
121 | pb=0xFF; | ||
122 | break; | ||
123 | } | ||
124 | } | ||
125 | } | ||
126 | ret+=pad; | ||
127 | } | ||
128 | if (pp == NULL) return(ret); | ||
129 | p= *pp; | ||
130 | |||
131 | if (pad) *(p++)=pb; | ||
132 | if (a->length == 0) *(p++)=0; | ||
133 | else if (!neg) memcpy(p,a->data,(unsigned int)a->length); | ||
134 | else { | ||
135 | /* Begin at the end of the encoding */ | ||
136 | n=a->data + a->length - 1; | ||
137 | p += a->length - 1; | ||
138 | i = a->length; | ||
139 | /* Copy zeros to destination as long as source is zero */ | ||
140 | while(!*n) { | ||
141 | *(p--) = 0; | ||
142 | n--; | ||
143 | i--; | ||
144 | } | ||
145 | /* Complement and increment next octet */ | ||
146 | *(p--) = ((*(n--)) ^ 0xff) + 1; | ||
147 | i--; | ||
148 | /* Complement any octets left */ | ||
149 | for(;i > 0; i--) *(p--) = *(n--) ^ 0xff; | ||
150 | } | ||
151 | |||
152 | *pp+=ret; | ||
153 | return(ret); | ||
154 | } | ||
155 | |||
156 | /* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */ | ||
157 | |||
158 | ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp, | ||
159 | long len) | ||
160 | { | ||
161 | ASN1_INTEGER *ret=NULL; | ||
162 | unsigned char *p,*to,*s, *pend; | ||
163 | int i; | ||
164 | |||
165 | if ((a == NULL) || ((*a) == NULL)) | ||
166 | { | ||
167 | if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); | ||
168 | ret->type=V_ASN1_INTEGER; | ||
169 | } | ||
170 | else | ||
171 | ret=(*a); | ||
172 | |||
173 | p= *pp; | ||
174 | pend = p + len; | ||
175 | |||
176 | /* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it | ||
177 | * signifies a missing NULL parameter. */ | ||
178 | s=(unsigned char *)OPENSSL_malloc((int)len+1); | ||
179 | if (s == NULL) | ||
180 | { | ||
181 | i=ERR_R_MALLOC_FAILURE; | ||
182 | goto err; | ||
183 | } | ||
184 | to=s; | ||
185 | if(!len) { | ||
186 | /* Strictly speaking this is an illegal INTEGER but we | ||
187 | * tolerate it. | ||
188 | */ | ||
189 | ret->type=V_ASN1_INTEGER; | ||
190 | } else if (*p & 0x80) /* a negative number */ | ||
191 | { | ||
192 | ret->type=V_ASN1_NEG_INTEGER; | ||
193 | if ((*p == 0xff) && (len != 1)) { | ||
194 | p++; | ||
195 | len--; | ||
196 | } | ||
197 | i = len; | ||
198 | p += i - 1; | ||
199 | to += i - 1; | ||
200 | while((!*p) && i) { | ||
201 | *(to--) = 0; | ||
202 | i--; | ||
203 | p--; | ||
204 | } | ||
205 | /* Special case: if all zeros then the number will be of | ||
206 | * the form FF followed by n zero bytes: this corresponds to | ||
207 | * 1 followed by n zero bytes. We've already written n zeros | ||
208 | * so we just append an extra one and set the first byte to | ||
209 | * a 1. This is treated separately because it is the only case | ||
210 | * where the number of bytes is larger than len. | ||
211 | */ | ||
212 | if(!i) { | ||
213 | *s = 1; | ||
214 | s[len] = 0; | ||
215 | len++; | ||
216 | } else { | ||
217 | *(to--) = (*(p--) ^ 0xff) + 1; | ||
218 | i--; | ||
219 | for(;i > 0; i--) *(to--) = *(p--) ^ 0xff; | ||
220 | } | ||
221 | } else { | ||
222 | ret->type=V_ASN1_INTEGER; | ||
223 | if ((*p == 0) && (len != 1)) | ||
224 | { | ||
225 | p++; | ||
226 | len--; | ||
227 | } | ||
228 | memcpy(s,p,(int)len); | ||
229 | } | ||
230 | |||
231 | if (ret->data != NULL) OPENSSL_free(ret->data); | ||
232 | ret->data=s; | ||
233 | ret->length=(int)len; | ||
234 | if (a != NULL) (*a)=ret; | ||
235 | *pp=pend; | ||
236 | return(ret); | ||
237 | err: | ||
238 | ASN1err(ASN1_F_D2I_ASN1_INTEGER,i); | ||
239 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
240 | M_ASN1_INTEGER_free(ret); | ||
241 | return(NULL); | ||
242 | } | ||
243 | |||
244 | |||
245 | /* This is a version of d2i_ASN1_INTEGER that ignores the sign bit of | ||
246 | * ASN1 integers: some broken software can encode a positive INTEGER | ||
247 | * with its MSB set as negative (it doesn't add a padding zero). | ||
248 | */ | ||
249 | |||
250 | ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp, | ||
251 | long length) | ||
252 | { | ||
253 | ASN1_INTEGER *ret=NULL; | ||
254 | unsigned char *p,*to,*s; | ||
255 | long len; | ||
256 | int inf,tag,xclass; | ||
257 | int i; | ||
258 | |||
259 | if ((a == NULL) || ((*a) == NULL)) | ||
260 | { | ||
261 | if ((ret=M_ASN1_INTEGER_new()) == NULL) return(NULL); | ||
262 | ret->type=V_ASN1_INTEGER; | ||
263 | } | ||
264 | else | ||
265 | ret=(*a); | ||
266 | |||
267 | p= *pp; | ||
268 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
269 | if (inf & 0x80) | ||
270 | { | ||
271 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
272 | goto err; | ||
273 | } | ||
274 | |||
275 | if (tag != V_ASN1_INTEGER) | ||
276 | { | ||
277 | i=ASN1_R_EXPECTING_AN_INTEGER; | ||
278 | goto err; | ||
279 | } | ||
280 | |||
281 | /* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it | ||
282 | * signifies a missing NULL parameter. */ | ||
283 | s=(unsigned char *)OPENSSL_malloc((int)len+1); | ||
284 | if (s == NULL) | ||
285 | { | ||
286 | i=ERR_R_MALLOC_FAILURE; | ||
287 | goto err; | ||
288 | } | ||
289 | to=s; | ||
290 | ret->type=V_ASN1_INTEGER; | ||
291 | if(len) { | ||
292 | if ((*p == 0) && (len != 1)) | ||
293 | { | ||
294 | p++; | ||
295 | len--; | ||
296 | } | ||
297 | memcpy(s,p,(int)len); | ||
298 | p+=len; | ||
299 | } | ||
300 | |||
301 | if (ret->data != NULL) OPENSSL_free(ret->data); | ||
302 | ret->data=s; | ||
303 | ret->length=(int)len; | ||
304 | if (a != NULL) (*a)=ret; | ||
305 | *pp=p; | ||
306 | return(ret); | ||
307 | err: | ||
308 | ASN1err(ASN1_F_D2I_ASN1_UINTEGER,i); | ||
309 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
310 | M_ASN1_INTEGER_free(ret); | ||
311 | return(NULL); | ||
312 | } | ||
313 | |||
314 | int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) | ||
315 | { | ||
316 | int i,j,k; | ||
317 | unsigned char buf[sizeof(long)+1]; | ||
318 | long d; | ||
319 | |||
320 | a->type=V_ASN1_INTEGER; | ||
321 | if (a->length < (sizeof(long)+1)) | ||
322 | { | ||
323 | if (a->data != NULL) | ||
324 | OPENSSL_free(a->data); | ||
325 | if ((a->data=(unsigned char *)OPENSSL_malloc(sizeof(long)+1)) != NULL) | ||
326 | memset((char *)a->data,0,sizeof(long)+1); | ||
327 | } | ||
328 | if (a->data == NULL) | ||
329 | { | ||
330 | ASN1err(ASN1_F_ASN1_INTEGER_SET,ERR_R_MALLOC_FAILURE); | ||
331 | return(0); | ||
332 | } | ||
333 | d=v; | ||
334 | if (d < 0) | ||
335 | { | ||
336 | d= -d; | ||
337 | a->type=V_ASN1_NEG_INTEGER; | ||
338 | } | ||
339 | |||
340 | for (i=0; i<sizeof(long); i++) | ||
341 | { | ||
342 | if (d == 0) break; | ||
343 | buf[i]=(int)d&0xff; | ||
344 | d>>=8; | ||
345 | } | ||
346 | j=0; | ||
347 | for (k=i-1; k >=0; k--) | ||
348 | a->data[j++]=buf[k]; | ||
349 | a->length=j; | ||
350 | return(1); | ||
351 | } | ||
352 | |||
353 | long ASN1_INTEGER_get(ASN1_INTEGER *a) | ||
354 | { | ||
355 | int neg=0,i; | ||
356 | long r=0; | ||
357 | |||
358 | if (a == NULL) return(0L); | ||
359 | i=a->type; | ||
360 | if (i == V_ASN1_NEG_INTEGER) | ||
361 | neg=1; | ||
362 | else if (i != V_ASN1_INTEGER) | ||
363 | return -1; | ||
364 | |||
365 | if (a->length > sizeof(long)) | ||
366 | { | ||
367 | /* hmm... a bit ugly */ | ||
368 | return(0xffffffffL); | ||
369 | } | ||
370 | if (a->data == NULL) | ||
371 | return 0; | ||
372 | |||
373 | for (i=0; i<a->length; i++) | ||
374 | { | ||
375 | r<<=8; | ||
376 | r|=(unsigned char)a->data[i]; | ||
377 | } | ||
378 | if (neg) r= -r; | ||
379 | return(r); | ||
380 | } | ||
381 | |||
382 | ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai) | ||
383 | { | ||
384 | ASN1_INTEGER *ret; | ||
385 | int len,j; | ||
386 | |||
387 | if (ai == NULL) | ||
388 | ret=M_ASN1_INTEGER_new(); | ||
389 | else | ||
390 | ret=ai; | ||
391 | if (ret == NULL) | ||
392 | { | ||
393 | ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR); | ||
394 | goto err; | ||
395 | } | ||
396 | if(bn->neg) ret->type = V_ASN1_NEG_INTEGER; | ||
397 | else ret->type=V_ASN1_INTEGER; | ||
398 | j=BN_num_bits(bn); | ||
399 | len=((j == 0)?0:((j/8)+1)); | ||
400 | if (ret->length < len+4) | ||
401 | { | ||
402 | unsigned char *new_data=OPENSSL_realloc(ret->data, len+4); | ||
403 | if (!new_data) | ||
404 | { | ||
405 | ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); | ||
406 | goto err; | ||
407 | } | ||
408 | ret->data=new_data; | ||
409 | } | ||
410 | ret->length=BN_bn2bin(bn,ret->data); | ||
411 | /* Correct zero case */ | ||
412 | if(!ret->length) | ||
413 | { | ||
414 | ret->data[0] = 0; | ||
415 | ret->length = 1; | ||
416 | } | ||
417 | return(ret); | ||
418 | err: | ||
419 | if (ret != ai) M_ASN1_INTEGER_free(ret); | ||
420 | return(NULL); | ||
421 | } | ||
422 | |||
423 | BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai, BIGNUM *bn) | ||
424 | { | ||
425 | BIGNUM *ret; | ||
426 | |||
427 | if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) | ||
428 | ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB); | ||
429 | else if(ai->type == V_ASN1_NEG_INTEGER) ret->neg = 1; | ||
430 | return(ret); | ||
431 | } | ||
432 | |||
433 | IMPLEMENT_STACK_OF(ASN1_INTEGER) | ||
434 | IMPLEMENT_ASN1_SET_OF(ASN1_INTEGER) | ||
diff --git a/src/lib/libcrypto/asn1/a_mbstr.c b/src/lib/libcrypto/asn1/a_mbstr.c deleted file mode 100644 index 208b3ec395..0000000000 --- a/src/lib/libcrypto/asn1/a_mbstr.c +++ /dev/null | |||
@@ -1,400 +0,0 @@ | |||
1 | /* a_mbstr.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <ctype.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/asn1.h> | ||
63 | |||
64 | static int traverse_string(const unsigned char *p, int len, int inform, | ||
65 | int (*rfunc)(unsigned long value, void *in), void *arg); | ||
66 | static int in_utf8(unsigned long value, void *arg); | ||
67 | static int out_utf8(unsigned long value, void *arg); | ||
68 | static int type_str(unsigned long value, void *arg); | ||
69 | static int cpy_asc(unsigned long value, void *arg); | ||
70 | static int cpy_bmp(unsigned long value, void *arg); | ||
71 | static int cpy_univ(unsigned long value, void *arg); | ||
72 | static int cpy_utf8(unsigned long value, void *arg); | ||
73 | static int is_printable(unsigned long value); | ||
74 | |||
75 | /* These functions take a string in UTF8, ASCII or multibyte form and | ||
76 | * a mask of permissible ASN1 string types. It then works out the minimal | ||
77 | * type (using the order Printable < IA5 < T61 < BMP < Universal < UTF8) | ||
78 | * and creates a string of the correct type with the supplied data. | ||
79 | * Yes this is horrible: it has to be :-( | ||
80 | * The 'ncopy' form checks minimum and maximum size limits too. | ||
81 | */ | ||
82 | |||
83 | int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len, | ||
84 | int inform, unsigned long mask) | ||
85 | { | ||
86 | return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0); | ||
87 | } | ||
88 | |||
89 | int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, | ||
90 | int inform, unsigned long mask, | ||
91 | long minsize, long maxsize) | ||
92 | { | ||
93 | int str_type; | ||
94 | int ret; | ||
95 | char free_out; | ||
96 | int outform, outlen; | ||
97 | ASN1_STRING *dest; | ||
98 | unsigned char *p; | ||
99 | int nchar; | ||
100 | char strbuf[32]; | ||
101 | int (*cpyfunc)(unsigned long,void *) = NULL; | ||
102 | if(len == -1) len = strlen((const char *)in); | ||
103 | if(!mask) mask = DIRSTRING_TYPE; | ||
104 | |||
105 | /* First do a string check and work out the number of characters */ | ||
106 | switch(inform) { | ||
107 | |||
108 | case MBSTRING_BMP: | ||
109 | if(len & 1) { | ||
110 | ASN1err(ASN1_F_ASN1_MBSTRING_COPY, | ||
111 | ASN1_R_INVALID_BMPSTRING_LENGTH); | ||
112 | return -1; | ||
113 | } | ||
114 | nchar = len >> 1; | ||
115 | break; | ||
116 | |||
117 | case MBSTRING_UNIV: | ||
118 | if(len & 3) { | ||
119 | ASN1err(ASN1_F_ASN1_MBSTRING_COPY, | ||
120 | ASN1_R_INVALID_UNIVERSALSTRING_LENGTH); | ||
121 | return -1; | ||
122 | } | ||
123 | nchar = len >> 2; | ||
124 | break; | ||
125 | |||
126 | case MBSTRING_UTF8: | ||
127 | nchar = 0; | ||
128 | /* This counts the characters and does utf8 syntax checking */ | ||
129 | ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar); | ||
130 | if(ret < 0) { | ||
131 | ASN1err(ASN1_F_ASN1_MBSTRING_COPY, | ||
132 | ASN1_R_INVALID_UTF8STRING); | ||
133 | return -1; | ||
134 | } | ||
135 | break; | ||
136 | |||
137 | case MBSTRING_ASC: | ||
138 | nchar = len; | ||
139 | break; | ||
140 | |||
141 | default: | ||
142 | ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_UNKNOWN_FORMAT); | ||
143 | return -1; | ||
144 | } | ||
145 | |||
146 | if((minsize > 0) && (nchar < minsize)) { | ||
147 | ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_SHORT); | ||
148 | BIO_snprintf(strbuf, sizeof strbuf, "%ld", minsize); | ||
149 | ERR_add_error_data(2, "minsize=", strbuf); | ||
150 | return -1; | ||
151 | } | ||
152 | |||
153 | if((maxsize > 0) && (nchar > maxsize)) { | ||
154 | ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_LONG); | ||
155 | BIO_snprintf(strbuf, sizeof strbuf, "%ld", maxsize); | ||
156 | ERR_add_error_data(2, "maxsize=", strbuf); | ||
157 | return -1; | ||
158 | } | ||
159 | |||
160 | /* Now work out minimal type (if any) */ | ||
161 | if(traverse_string(in, len, inform, type_str, &mask) < 0) { | ||
162 | ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_ILLEGAL_CHARACTERS); | ||
163 | return -1; | ||
164 | } | ||
165 | |||
166 | |||
167 | /* Now work out output format and string type */ | ||
168 | outform = MBSTRING_ASC; | ||
169 | if(mask & B_ASN1_PRINTABLESTRING) str_type = V_ASN1_PRINTABLESTRING; | ||
170 | else if(mask & B_ASN1_IA5STRING) str_type = V_ASN1_IA5STRING; | ||
171 | else if(mask & B_ASN1_T61STRING) str_type = V_ASN1_T61STRING; | ||
172 | else if(mask & B_ASN1_BMPSTRING) { | ||
173 | str_type = V_ASN1_BMPSTRING; | ||
174 | outform = MBSTRING_BMP; | ||
175 | } else if(mask & B_ASN1_UNIVERSALSTRING) { | ||
176 | str_type = V_ASN1_UNIVERSALSTRING; | ||
177 | outform = MBSTRING_UNIV; | ||
178 | } else { | ||
179 | str_type = V_ASN1_UTF8STRING; | ||
180 | outform = MBSTRING_UTF8; | ||
181 | } | ||
182 | if(!out) return str_type; | ||
183 | if(*out) { | ||
184 | free_out = 0; | ||
185 | dest = *out; | ||
186 | if(dest->data) { | ||
187 | dest->length = 0; | ||
188 | OPENSSL_free(dest->data); | ||
189 | dest->data = NULL; | ||
190 | } | ||
191 | dest->type = str_type; | ||
192 | } else { | ||
193 | free_out = 1; | ||
194 | dest = ASN1_STRING_type_new(str_type); | ||
195 | if(!dest) { | ||
196 | ASN1err(ASN1_F_ASN1_MBSTRING_COPY, | ||
197 | ERR_R_MALLOC_FAILURE); | ||
198 | return -1; | ||
199 | } | ||
200 | *out = dest; | ||
201 | } | ||
202 | /* If both the same type just copy across */ | ||
203 | if(inform == outform) { | ||
204 | if(!ASN1_STRING_set(dest, in, len)) { | ||
205 | ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE); | ||
206 | return -1; | ||
207 | } | ||
208 | return str_type; | ||
209 | } | ||
210 | |||
211 | /* Work out how much space the destination will need */ | ||
212 | switch(outform) { | ||
213 | case MBSTRING_ASC: | ||
214 | outlen = nchar; | ||
215 | cpyfunc = cpy_asc; | ||
216 | break; | ||
217 | |||
218 | case MBSTRING_BMP: | ||
219 | outlen = nchar << 1; | ||
220 | cpyfunc = cpy_bmp; | ||
221 | break; | ||
222 | |||
223 | case MBSTRING_UNIV: | ||
224 | outlen = nchar << 2; | ||
225 | cpyfunc = cpy_univ; | ||
226 | break; | ||
227 | |||
228 | case MBSTRING_UTF8: | ||
229 | outlen = 0; | ||
230 | traverse_string(in, len, inform, out_utf8, &outlen); | ||
231 | cpyfunc = cpy_utf8; | ||
232 | break; | ||
233 | } | ||
234 | if(!(p = OPENSSL_malloc(outlen + 1))) { | ||
235 | if(free_out) ASN1_STRING_free(dest); | ||
236 | ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE); | ||
237 | return -1; | ||
238 | } | ||
239 | dest->length = outlen; | ||
240 | dest->data = p; | ||
241 | p[outlen] = 0; | ||
242 | traverse_string(in, len, inform, cpyfunc, &p); | ||
243 | return str_type; | ||
244 | } | ||
245 | |||
246 | /* This function traverses a string and passes the value of each character | ||
247 | * to an optional function along with a void * argument. | ||
248 | */ | ||
249 | |||
250 | static int traverse_string(const unsigned char *p, int len, int inform, | ||
251 | int (*rfunc)(unsigned long value, void *in), void *arg) | ||
252 | { | ||
253 | unsigned long value; | ||
254 | int ret; | ||
255 | while(len) { | ||
256 | if(inform == MBSTRING_ASC) { | ||
257 | value = *p++; | ||
258 | len--; | ||
259 | } else if(inform == MBSTRING_BMP) { | ||
260 | value = *p++ << 8; | ||
261 | value |= *p++; | ||
262 | len -= 2; | ||
263 | } else if(inform == MBSTRING_UNIV) { | ||
264 | value = ((unsigned long)*p++) << 24; | ||
265 | value |= ((unsigned long)*p++) << 16; | ||
266 | value |= *p++ << 8; | ||
267 | value |= *p++; | ||
268 | len -= 4; | ||
269 | } else { | ||
270 | ret = UTF8_getc(p, len, &value); | ||
271 | if(ret < 0) return -1; | ||
272 | len -= ret; | ||
273 | p += ret; | ||
274 | } | ||
275 | if(rfunc) { | ||
276 | ret = rfunc(value, arg); | ||
277 | if(ret <= 0) return ret; | ||
278 | } | ||
279 | } | ||
280 | return 1; | ||
281 | } | ||
282 | |||
283 | /* Various utility functions for traverse_string */ | ||
284 | |||
285 | /* Just count number of characters */ | ||
286 | |||
287 | static int in_utf8(unsigned long value, void *arg) | ||
288 | { | ||
289 | int *nchar; | ||
290 | nchar = arg; | ||
291 | (*nchar)++; | ||
292 | return 1; | ||
293 | } | ||
294 | |||
295 | /* Determine size of output as a UTF8 String */ | ||
296 | |||
297 | static int out_utf8(unsigned long value, void *arg) | ||
298 | { | ||
299 | int *outlen; | ||
300 | outlen = arg; | ||
301 | *outlen += UTF8_putc(NULL, -1, value); | ||
302 | return 1; | ||
303 | } | ||
304 | |||
305 | /* Determine the "type" of a string: check each character against a | ||
306 | * supplied "mask". | ||
307 | */ | ||
308 | |||
309 | static int type_str(unsigned long value, void *arg) | ||
310 | { | ||
311 | unsigned long types; | ||
312 | types = *((unsigned long *)arg); | ||
313 | if((types & B_ASN1_PRINTABLESTRING) && !is_printable(value)) | ||
314 | types &= ~B_ASN1_PRINTABLESTRING; | ||
315 | if((types & B_ASN1_IA5STRING) && (value > 127)) | ||
316 | types &= ~B_ASN1_IA5STRING; | ||
317 | if((types & B_ASN1_T61STRING) && (value > 0xff)) | ||
318 | types &= ~B_ASN1_T61STRING; | ||
319 | if((types & B_ASN1_BMPSTRING) && (value > 0xffff)) | ||
320 | types &= ~B_ASN1_BMPSTRING; | ||
321 | if(!types) return -1; | ||
322 | *((unsigned long *)arg) = types; | ||
323 | return 1; | ||
324 | } | ||
325 | |||
326 | /* Copy one byte per character ASCII like strings */ | ||
327 | |||
328 | static int cpy_asc(unsigned long value, void *arg) | ||
329 | { | ||
330 | unsigned char **p, *q; | ||
331 | p = arg; | ||
332 | q = *p; | ||
333 | *q = (unsigned char) value; | ||
334 | (*p)++; | ||
335 | return 1; | ||
336 | } | ||
337 | |||
338 | /* Copy two byte per character BMPStrings */ | ||
339 | |||
340 | static int cpy_bmp(unsigned long value, void *arg) | ||
341 | { | ||
342 | unsigned char **p, *q; | ||
343 | p = arg; | ||
344 | q = *p; | ||
345 | *q++ = (unsigned char) ((value >> 8) & 0xff); | ||
346 | *q = (unsigned char) (value & 0xff); | ||
347 | *p += 2; | ||
348 | return 1; | ||
349 | } | ||
350 | |||
351 | /* Copy four byte per character UniversalStrings */ | ||
352 | |||
353 | static int cpy_univ(unsigned long value, void *arg) | ||
354 | { | ||
355 | unsigned char **p, *q; | ||
356 | p = arg; | ||
357 | q = *p; | ||
358 | *q++ = (unsigned char) ((value >> 24) & 0xff); | ||
359 | *q++ = (unsigned char) ((value >> 16) & 0xff); | ||
360 | *q++ = (unsigned char) ((value >> 8) & 0xff); | ||
361 | *q = (unsigned char) (value & 0xff); | ||
362 | *p += 4; | ||
363 | return 1; | ||
364 | } | ||
365 | |||
366 | /* Copy to a UTF8String */ | ||
367 | |||
368 | static int cpy_utf8(unsigned long value, void *arg) | ||
369 | { | ||
370 | unsigned char **p; | ||
371 | int ret; | ||
372 | p = arg; | ||
373 | /* We already know there is enough room so pass 0xff as the length */ | ||
374 | ret = UTF8_putc(*p, 0xff, value); | ||
375 | *p += ret; | ||
376 | return 1; | ||
377 | } | ||
378 | |||
379 | /* Return 1 if the character is permitted in a PrintableString */ | ||
380 | static int is_printable(unsigned long value) | ||
381 | { | ||
382 | int ch; | ||
383 | if(value > 0x7f) return 0; | ||
384 | ch = (int) value; | ||
385 | /* Note: we can't use 'isalnum' because certain accented | ||
386 | * characters may count as alphanumeric in some environments. | ||
387 | */ | ||
388 | #ifndef CHARSET_EBCDIC | ||
389 | if((ch >= 'a') && (ch <= 'z')) return 1; | ||
390 | if((ch >= 'A') && (ch <= 'Z')) return 1; | ||
391 | if((ch >= '0') && (ch <= '9')) return 1; | ||
392 | if ((ch == ' ') || strchr("'()+,-./:=?", ch)) return 1; | ||
393 | #else /*CHARSET_EBCDIC*/ | ||
394 | if((ch >= os_toascii['a']) && (ch <= os_toascii['z'])) return 1; | ||
395 | if((ch >= os_toascii['A']) && (ch <= os_toascii['Z'])) return 1; | ||
396 | if((ch >= os_toascii['0']) && (ch <= os_toascii['9'])) return 1; | ||
397 | if ((ch == os_toascii[' ']) || strchr("'()+,-./:=?", os_toebcdic[ch])) return 1; | ||
398 | #endif /*CHARSET_EBCDIC*/ | ||
399 | return 0; | ||
400 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c deleted file mode 100644 index 0a8e6c287c..0000000000 --- a/src/lib/libcrypto/asn1/a_object.c +++ /dev/null | |||
@@ -1,320 +0,0 @@ | |||
1 | /* crypto/asn1/a_object.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/buffer.h> | ||
62 | #include <openssl/asn1.h> | ||
63 | #include <openssl/objects.h> | ||
64 | |||
65 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) | ||
66 | { | ||
67 | unsigned char *p; | ||
68 | int objsize; | ||
69 | |||
70 | if ((a == NULL) || (a->data == NULL)) return(0); | ||
71 | |||
72 | objsize = ASN1_object_size(0,a->length,V_ASN1_OBJECT); | ||
73 | if (pp == NULL) return objsize; | ||
74 | |||
75 | p= *pp; | ||
76 | ASN1_put_object(&p,0,a->length,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); | ||
77 | memcpy(p,a->data,a->length); | ||
78 | p+=a->length; | ||
79 | |||
80 | *pp=p; | ||
81 | return(objsize); | ||
82 | } | ||
83 | |||
84 | int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) | ||
85 | { | ||
86 | int i,first,len=0,c; | ||
87 | char tmp[24]; | ||
88 | const char *p; | ||
89 | unsigned long l; | ||
90 | |||
91 | if (num == 0) | ||
92 | return(0); | ||
93 | else if (num == -1) | ||
94 | num=strlen(buf); | ||
95 | |||
96 | p=buf; | ||
97 | c= *(p++); | ||
98 | num--; | ||
99 | if ((c >= '0') && (c <= '2')) | ||
100 | { | ||
101 | first=(c-'0')*40; | ||
102 | } | ||
103 | else | ||
104 | { | ||
105 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_FIRST_NUM_TOO_LARGE); | ||
106 | goto err; | ||
107 | } | ||
108 | |||
109 | if (num <= 0) | ||
110 | { | ||
111 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_MISSING_SECOND_NUMBER); | ||
112 | goto err; | ||
113 | } | ||
114 | c= *(p++); | ||
115 | num--; | ||
116 | for (;;) | ||
117 | { | ||
118 | if (num <= 0) break; | ||
119 | if ((c != '.') && (c != ' ')) | ||
120 | { | ||
121 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_SEPARATOR); | ||
122 | goto err; | ||
123 | } | ||
124 | l=0; | ||
125 | for (;;) | ||
126 | { | ||
127 | if (num <= 0) break; | ||
128 | num--; | ||
129 | c= *(p++); | ||
130 | if ((c == ' ') || (c == '.')) | ||
131 | break; | ||
132 | if ((c < '0') || (c > '9')) | ||
133 | { | ||
134 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT); | ||
135 | goto err; | ||
136 | } | ||
137 | l=l*10L+(long)(c-'0'); | ||
138 | } | ||
139 | if (len == 0) | ||
140 | { | ||
141 | if ((first < 2) && (l >= 40)) | ||
142 | { | ||
143 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE); | ||
144 | goto err; | ||
145 | } | ||
146 | l+=(long)first; | ||
147 | } | ||
148 | i=0; | ||
149 | for (;;) | ||
150 | { | ||
151 | tmp[i++]=(unsigned char)l&0x7f; | ||
152 | l>>=7L; | ||
153 | if (l == 0L) break; | ||
154 | } | ||
155 | if (out != NULL) | ||
156 | { | ||
157 | if (len+i > olen) | ||
158 | { | ||
159 | ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_BUFFER_TOO_SMALL); | ||
160 | goto err; | ||
161 | } | ||
162 | while (--i > 0) | ||
163 | out[len++]=tmp[i]|0x80; | ||
164 | out[len++]=tmp[0]; | ||
165 | } | ||
166 | else | ||
167 | len+=i; | ||
168 | } | ||
169 | return(len); | ||
170 | err: | ||
171 | return(0); | ||
172 | } | ||
173 | |||
174 | int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a) | ||
175 | { | ||
176 | return OBJ_obj2txt(buf, buf_len, a, 0); | ||
177 | } | ||
178 | |||
179 | int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) | ||
180 | { | ||
181 | char buf[80]; | ||
182 | int i; | ||
183 | |||
184 | if ((a == NULL) || (a->data == NULL)) | ||
185 | return(BIO_write(bp,"NULL",4)); | ||
186 | i=i2t_ASN1_OBJECT(buf,sizeof buf,a); | ||
187 | if (i > sizeof buf) i=sizeof buf; | ||
188 | BIO_write(bp,buf,i); | ||
189 | return(i); | ||
190 | } | ||
191 | |||
192 | ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, | ||
193 | long length) | ||
194 | { | ||
195 | unsigned char *p; | ||
196 | long len; | ||
197 | int tag,xclass; | ||
198 | int inf,i; | ||
199 | ASN1_OBJECT *ret = NULL; | ||
200 | p= *pp; | ||
201 | inf=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
202 | if (inf & 0x80) | ||
203 | { | ||
204 | i=ASN1_R_BAD_OBJECT_HEADER; | ||
205 | goto err; | ||
206 | } | ||
207 | |||
208 | if (tag != V_ASN1_OBJECT) | ||
209 | { | ||
210 | i=ASN1_R_EXPECTING_AN_OBJECT; | ||
211 | goto err; | ||
212 | } | ||
213 | ret = c2i_ASN1_OBJECT(a, &p, len); | ||
214 | if(ret) *pp = p; | ||
215 | return ret; | ||
216 | err: | ||
217 | ASN1err(ASN1_F_D2I_ASN1_OBJECT,i); | ||
218 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
219 | ASN1_OBJECT_free(ret); | ||
220 | return(NULL); | ||
221 | } | ||
222 | ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, | ||
223 | long len) | ||
224 | { | ||
225 | ASN1_OBJECT *ret=NULL; | ||
226 | unsigned char *p; | ||
227 | int i; | ||
228 | |||
229 | /* only the ASN1_OBJECTs from the 'table' will have values | ||
230 | * for ->sn or ->ln */ | ||
231 | if ((a == NULL) || ((*a) == NULL) || | ||
232 | !((*a)->flags & ASN1_OBJECT_FLAG_DYNAMIC)) | ||
233 | { | ||
234 | if ((ret=ASN1_OBJECT_new()) == NULL) return(NULL); | ||
235 | } | ||
236 | else ret=(*a); | ||
237 | |||
238 | p= *pp; | ||
239 | if ((ret->data == NULL) || (ret->length < len)) | ||
240 | { | ||
241 | if (ret->data != NULL) OPENSSL_free(ret->data); | ||
242 | ret->data=(unsigned char *)OPENSSL_malloc(len ? (int)len : 1); | ||
243 | ret->flags|=ASN1_OBJECT_FLAG_DYNAMIC_DATA; | ||
244 | if (ret->data == NULL) | ||
245 | { i=ERR_R_MALLOC_FAILURE; goto err; } | ||
246 | } | ||
247 | memcpy(ret->data,p,(int)len); | ||
248 | ret->length=(int)len; | ||
249 | ret->sn=NULL; | ||
250 | ret->ln=NULL; | ||
251 | /* ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; we know it is dynamic */ | ||
252 | p+=len; | ||
253 | |||
254 | if (a != NULL) (*a)=ret; | ||
255 | *pp=p; | ||
256 | return(ret); | ||
257 | err: | ||
258 | ASN1err(ASN1_F_D2I_ASN1_OBJECT,i); | ||
259 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
260 | ASN1_OBJECT_free(ret); | ||
261 | return(NULL); | ||
262 | } | ||
263 | |||
264 | ASN1_OBJECT *ASN1_OBJECT_new(void) | ||
265 | { | ||
266 | ASN1_OBJECT *ret; | ||
267 | |||
268 | ret=(ASN1_OBJECT *)OPENSSL_malloc(sizeof(ASN1_OBJECT)); | ||
269 | if (ret == NULL) | ||
270 | { | ||
271 | ASN1err(ASN1_F_ASN1_OBJECT_NEW,ERR_R_MALLOC_FAILURE); | ||
272 | return(NULL); | ||
273 | } | ||
274 | ret->length=0; | ||
275 | ret->data=NULL; | ||
276 | ret->nid=0; | ||
277 | ret->sn=NULL; | ||
278 | ret->ln=NULL; | ||
279 | ret->flags=ASN1_OBJECT_FLAG_DYNAMIC; | ||
280 | return(ret); | ||
281 | } | ||
282 | |||
283 | void ASN1_OBJECT_free(ASN1_OBJECT *a) | ||
284 | { | ||
285 | if (a == NULL) return; | ||
286 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_STRINGS) | ||
287 | { | ||
288 | #ifndef CONST_STRICT /* disable purely for compile-time strict const checking. Doing this on a "real" compile will cause memory leaks */ | ||
289 | if (a->sn != NULL) OPENSSL_free((void *)a->sn); | ||
290 | if (a->ln != NULL) OPENSSL_free((void *)a->ln); | ||
291 | #endif | ||
292 | a->sn=a->ln=NULL; | ||
293 | } | ||
294 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC_DATA) | ||
295 | { | ||
296 | if (a->data != NULL) OPENSSL_free(a->data); | ||
297 | a->data=NULL; | ||
298 | a->length=0; | ||
299 | } | ||
300 | if (a->flags & ASN1_OBJECT_FLAG_DYNAMIC) | ||
301 | OPENSSL_free(a); | ||
302 | } | ||
303 | |||
304 | ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, int len, | ||
305 | const char *sn, const char *ln) | ||
306 | { | ||
307 | ASN1_OBJECT o; | ||
308 | |||
309 | o.sn=sn; | ||
310 | o.ln=ln; | ||
311 | o.data=data; | ||
312 | o.nid=nid; | ||
313 | o.length=len; | ||
314 | o.flags=ASN1_OBJECT_FLAG_DYNAMIC|ASN1_OBJECT_FLAG_DYNAMIC_STRINGS| | ||
315 | ASN1_OBJECT_FLAG_DYNAMIC_DATA; | ||
316 | return(OBJ_dup(&o)); | ||
317 | } | ||
318 | |||
319 | IMPLEMENT_STACK_OF(ASN1_OBJECT) | ||
320 | IMPLEMENT_ASN1_SET_OF(ASN1_OBJECT) | ||
diff --git a/src/lib/libcrypto/asn1/a_octet.c b/src/lib/libcrypto/asn1/a_octet.c deleted file mode 100644 index 9690bae0f1..0000000000 --- a/src/lib/libcrypto/asn1/a_octet.c +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | /* crypto/asn1/a_octet.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1.h> | ||
62 | |||
63 | ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *x) | ||
64 | { return M_ASN1_OCTET_STRING_dup(x); } | ||
65 | |||
66 | int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b) | ||
67 | { return M_ASN1_OCTET_STRING_cmp(a, b); } | ||
68 | |||
69 | int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, unsigned char *d, int len) | ||
70 | { return M_ASN1_OCTET_STRING_set(x, d, len); } | ||
71 | |||
diff --git a/src/lib/libcrypto/asn1/a_print.c b/src/lib/libcrypto/asn1/a_print.c deleted file mode 100644 index 8035513f04..0000000000 --- a/src/lib/libcrypto/asn1/a_print.c +++ /dev/null | |||
@@ -1,127 +0,0 @@ | |||
1 | /* crypto/asn1/a_print.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1.h> | ||
62 | |||
63 | int ASN1_PRINTABLE_type(unsigned char *s, int len) | ||
64 | { | ||
65 | int c; | ||
66 | int ia5=0; | ||
67 | int t61=0; | ||
68 | |||
69 | if (len <= 0) len= -1; | ||
70 | if (s == NULL) return(V_ASN1_PRINTABLESTRING); | ||
71 | |||
72 | while ((*s) && (len-- != 0)) | ||
73 | { | ||
74 | c= *(s++); | ||
75 | #ifndef CHARSET_EBCDIC | ||
76 | if (!( ((c >= 'a') && (c <= 'z')) || | ||
77 | ((c >= 'A') && (c <= 'Z')) || | ||
78 | (c == ' ') || | ||
79 | ((c >= '0') && (c <= '9')) || | ||
80 | (c == ' ') || (c == '\'') || | ||
81 | (c == '(') || (c == ')') || | ||
82 | (c == '+') || (c == ',') || | ||
83 | (c == '-') || (c == '.') || | ||
84 | (c == '/') || (c == ':') || | ||
85 | (c == '=') || (c == '?'))) | ||
86 | ia5=1; | ||
87 | if (c&0x80) | ||
88 | t61=1; | ||
89 | #else | ||
90 | if (!isalnum(c) && (c != ' ') && | ||
91 | strchr("'()+,-./:=?", c) == NULL) | ||
92 | ia5=1; | ||
93 | if (os_toascii[c] & 0x80) | ||
94 | t61=1; | ||
95 | #endif | ||
96 | } | ||
97 | if (t61) return(V_ASN1_T61STRING); | ||
98 | if (ia5) return(V_ASN1_IA5STRING); | ||
99 | return(V_ASN1_PRINTABLESTRING); | ||
100 | } | ||
101 | |||
102 | int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s) | ||
103 | { | ||
104 | int i; | ||
105 | unsigned char *p; | ||
106 | |||
107 | if (s->type != V_ASN1_UNIVERSALSTRING) return(0); | ||
108 | if ((s->length%4) != 0) return(0); | ||
109 | p=s->data; | ||
110 | for (i=0; i<s->length; i+=4) | ||
111 | { | ||
112 | if ((p[0] != '\0') || (p[1] != '\0') || (p[2] != '\0')) | ||
113 | break; | ||
114 | else | ||
115 | p+=4; | ||
116 | } | ||
117 | if (i < s->length) return(0); | ||
118 | p=s->data; | ||
119 | for (i=3; i<s->length; i+=4) | ||
120 | { | ||
121 | *(p++)=s->data[i]; | ||
122 | } | ||
123 | *(p)='\0'; | ||
124 | s->length/=4; | ||
125 | s->type=ASN1_PRINTABLE_type(s->data,s->length); | ||
126 | return(1); | ||
127 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_set.c b/src/lib/libcrypto/asn1/a_set.c deleted file mode 100644 index 0f839822ff..0000000000 --- a/src/lib/libcrypto/asn1/a_set.c +++ /dev/null | |||
@@ -1,220 +0,0 @@ | |||
1 | /* crypto/asn1/a_set.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1_mac.h> | ||
62 | |||
63 | #ifndef NO_ASN1_OLD | ||
64 | |||
65 | typedef struct | ||
66 | { | ||
67 | unsigned char *pbData; | ||
68 | int cbData; | ||
69 | } MYBLOB; | ||
70 | |||
71 | /* SetBlobCmp | ||
72 | * This function compares two elements of SET_OF block | ||
73 | */ | ||
74 | static int SetBlobCmp(const void *elem1, const void *elem2 ) | ||
75 | { | ||
76 | const MYBLOB *b1 = (const MYBLOB *)elem1; | ||
77 | const MYBLOB *b2 = (const MYBLOB *)elem2; | ||
78 | int r; | ||
79 | |||
80 | r = memcmp(b1->pbData, b2->pbData, | ||
81 | b1->cbData < b2->cbData ? b1->cbData : b2->cbData); | ||
82 | if(r != 0) | ||
83 | return r; | ||
84 | return b1->cbData-b2->cbData; | ||
85 | } | ||
86 | |||
87 | /* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */ | ||
88 | int i2d_ASN1_SET(STACK *a, unsigned char **pp, int (*func)(), int ex_tag, | ||
89 | int ex_class, int is_set) | ||
90 | { | ||
91 | int ret=0,r; | ||
92 | int i; | ||
93 | unsigned char *p; | ||
94 | unsigned char *pStart, *pTempMem; | ||
95 | MYBLOB *rgSetBlob; | ||
96 | int totSize; | ||
97 | |||
98 | if (a == NULL) return(0); | ||
99 | for (i=sk_num(a)-1; i>=0; i--) | ||
100 | ret+=func(sk_value(a,i),NULL); | ||
101 | r=ASN1_object_size(1,ret,ex_tag); | ||
102 | if (pp == NULL) return(r); | ||
103 | |||
104 | p= *pp; | ||
105 | ASN1_put_object(&p,1,ret,ex_tag,ex_class); | ||
106 | |||
107 | /* Modified by gp@nsj.co.jp */ | ||
108 | /* And then again by Ben */ | ||
109 | /* And again by Steve */ | ||
110 | |||
111 | if(!is_set || (sk_num(a) < 2)) | ||
112 | { | ||
113 | for (i=0; i<sk_num(a); i++) | ||
114 | func(sk_value(a,i),&p); | ||
115 | |||
116 | *pp=p; | ||
117 | return(r); | ||
118 | } | ||
119 | |||
120 | pStart = p; /* Catch the beg of Setblobs*/ | ||
121 | if (!(rgSetBlob = (MYBLOB *)OPENSSL_malloc( sk_num(a) * sizeof(MYBLOB)))) return 0; /* In this array | ||
122 | we will store the SET blobs */ | ||
123 | |||
124 | for (i=0; i<sk_num(a); i++) | ||
125 | { | ||
126 | rgSetBlob[i].pbData = p; /* catch each set encode blob */ | ||
127 | func(sk_value(a,i),&p); | ||
128 | rgSetBlob[i].cbData = p - rgSetBlob[i].pbData; /* Length of this | ||
129 | SetBlob | ||
130 | */ | ||
131 | } | ||
132 | *pp=p; | ||
133 | totSize = p - pStart; /* This is the total size of all set blobs */ | ||
134 | |||
135 | /* Now we have to sort the blobs. I am using a simple algo. | ||
136 | *Sort ptrs *Copy to temp-mem *Copy from temp-mem to user-mem*/ | ||
137 | qsort( rgSetBlob, sk_num(a), sizeof(MYBLOB), SetBlobCmp); | ||
138 | if (!(pTempMem = OPENSSL_malloc(totSize))) return 0; | ||
139 | |||
140 | /* Copy to temp mem */ | ||
141 | p = pTempMem; | ||
142 | for(i=0; i<sk_num(a); ++i) | ||
143 | { | ||
144 | memcpy(p, rgSetBlob[i].pbData, rgSetBlob[i].cbData); | ||
145 | p += rgSetBlob[i].cbData; | ||
146 | } | ||
147 | |||
148 | /* Copy back to user mem*/ | ||
149 | memcpy(pStart, pTempMem, totSize); | ||
150 | OPENSSL_free(pTempMem); | ||
151 | OPENSSL_free(rgSetBlob); | ||
152 | |||
153 | return(r); | ||
154 | } | ||
155 | |||
156 | STACK *d2i_ASN1_SET(STACK **a, unsigned char **pp, long length, | ||
157 | char *(*func)(), void (*free_func)(void *), int ex_tag, int ex_class) | ||
158 | { | ||
159 | ASN1_CTX c; | ||
160 | STACK *ret=NULL; | ||
161 | |||
162 | if ((a == NULL) || ((*a) == NULL)) | ||
163 | { if ((ret=sk_new_null()) == NULL) goto err; } | ||
164 | else | ||
165 | ret=(*a); | ||
166 | |||
167 | c.p= *pp; | ||
168 | c.max=(length == 0)?0:(c.p+length); | ||
169 | |||
170 | c.inf=ASN1_get_object(&c.p,&c.slen,&c.tag,&c.xclass,c.max-c.p); | ||
171 | if (c.inf & 0x80) goto err; | ||
172 | if (ex_class != c.xclass) | ||
173 | { | ||
174 | ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_CLASS); | ||
175 | goto err; | ||
176 | } | ||
177 | if (ex_tag != c.tag) | ||
178 | { | ||
179 | ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_BAD_TAG); | ||
180 | goto err; | ||
181 | } | ||
182 | if ((c.slen+c.p) > c.max) | ||
183 | { | ||
184 | ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_LENGTH_ERROR); | ||
185 | goto err; | ||
186 | } | ||
187 | /* check for infinite constructed - it can be as long | ||
188 | * as the amount of data passed to us */ | ||
189 | if (c.inf == (V_ASN1_CONSTRUCTED+1)) | ||
190 | c.slen=length+ *pp-c.p; | ||
191 | c.max=c.p+c.slen; | ||
192 | |||
193 | while (c.p < c.max) | ||
194 | { | ||
195 | char *s; | ||
196 | |||
197 | if (M_ASN1_D2I_end_sequence()) break; | ||
198 | if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL) | ||
199 | { | ||
200 | ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT); | ||
201 | asn1_add_error(*pp,(int)(c.q- *pp)); | ||
202 | goto err; | ||
203 | } | ||
204 | if (!sk_push(ret,s)) goto err; | ||
205 | } | ||
206 | if (a != NULL) (*a)=ret; | ||
207 | *pp=c.p; | ||
208 | return(ret); | ||
209 | err: | ||
210 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) | ||
211 | { | ||
212 | if (free_func != NULL) | ||
213 | sk_pop_free(ret,free_func); | ||
214 | else | ||
215 | sk_free(ret); | ||
216 | } | ||
217 | return(NULL); | ||
218 | } | ||
219 | |||
220 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c deleted file mode 100644 index 52ce7e3974..0000000000 --- a/src/lib/libcrypto/asn1/a_sign.c +++ /dev/null | |||
@@ -1,294 +0,0 @@ | |||
1 | /* crypto/asn1/a_sign.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | /* ==================================================================== | ||
59 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | ||
60 | * | ||
61 | * Redistribution and use in source and binary forms, with or without | ||
62 | * modification, are permitted provided that the following conditions | ||
63 | * are met: | ||
64 | * | ||
65 | * 1. Redistributions of source code must retain the above copyright | ||
66 | * notice, this list of conditions and the following disclaimer. | ||
67 | * | ||
68 | * 2. Redistributions in binary form must reproduce the above copyright | ||
69 | * notice, this list of conditions and the following disclaimer in | ||
70 | * the documentation and/or other materials provided with the | ||
71 | * distribution. | ||
72 | * | ||
73 | * 3. All advertising materials mentioning features or use of this | ||
74 | * software must display the following acknowledgment: | ||
75 | * "This product includes software developed by the OpenSSL Project | ||
76 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
77 | * | ||
78 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
79 | * endorse or promote products derived from this software without | ||
80 | * prior written permission. For written permission, please contact | ||
81 | * openssl-core@openssl.org. | ||
82 | * | ||
83 | * 5. Products derived from this software may not be called "OpenSSL" | ||
84 | * nor may "OpenSSL" appear in their names without prior written | ||
85 | * permission of the OpenSSL Project. | ||
86 | * | ||
87 | * 6. Redistributions of any form whatsoever must retain the following | ||
88 | * acknowledgment: | ||
89 | * "This product includes software developed by the OpenSSL Project | ||
90 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
91 | * | ||
92 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
93 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
94 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
95 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
96 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
97 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
98 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
99 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
100 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
101 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
102 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
103 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
104 | * ==================================================================== | ||
105 | * | ||
106 | * This product includes cryptographic software written by Eric Young | ||
107 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
108 | * Hudson (tjh@cryptsoft.com). | ||
109 | * | ||
110 | */ | ||
111 | |||
112 | #include <stdio.h> | ||
113 | #include <time.h> | ||
114 | |||
115 | #include "cryptlib.h" | ||
116 | |||
117 | #ifndef NO_SYS_TYPES_H | ||
118 | # include <sys/types.h> | ||
119 | #endif | ||
120 | |||
121 | #include <openssl/bn.h> | ||
122 | #include <openssl/evp.h> | ||
123 | #include <openssl/x509.h> | ||
124 | #include <openssl/objects.h> | ||
125 | #include <openssl/buffer.h> | ||
126 | |||
127 | #ifndef NO_ASN1_OLD | ||
128 | |||
129 | int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2, | ||
130 | ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey, | ||
131 | const EVP_MD *type) | ||
132 | { | ||
133 | EVP_MD_CTX ctx; | ||
134 | unsigned char *p,*buf_in=NULL,*buf_out=NULL; | ||
135 | int i,inl=0,outl=0,outll=0; | ||
136 | X509_ALGOR *a; | ||
137 | |||
138 | EVP_MD_CTX_init(&ctx); | ||
139 | for (i=0; i<2; i++) | ||
140 | { | ||
141 | if (i == 0) | ||
142 | a=algor1; | ||
143 | else | ||
144 | a=algor2; | ||
145 | if (a == NULL) continue; | ||
146 | if (type->pkey_type == NID_dsaWithSHA1) | ||
147 | { | ||
148 | /* special case: RFC 2459 tells us to omit 'parameters' | ||
149 | * with id-dsa-with-sha1 */ | ||
150 | ASN1_TYPE_free(a->parameter); | ||
151 | a->parameter = NULL; | ||
152 | } | ||
153 | else if ((a->parameter == NULL) || | ||
154 | (a->parameter->type != V_ASN1_NULL)) | ||
155 | { | ||
156 | ASN1_TYPE_free(a->parameter); | ||
157 | if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err; | ||
158 | a->parameter->type=V_ASN1_NULL; | ||
159 | } | ||
160 | ASN1_OBJECT_free(a->algorithm); | ||
161 | a->algorithm=OBJ_nid2obj(type->pkey_type); | ||
162 | if (a->algorithm == NULL) | ||
163 | { | ||
164 | ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE); | ||
165 | goto err; | ||
166 | } | ||
167 | if (a->algorithm->length == 0) | ||
168 | { | ||
169 | ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD); | ||
170 | goto err; | ||
171 | } | ||
172 | } | ||
173 | inl=i2d(data,NULL); | ||
174 | buf_in=(unsigned char *)OPENSSL_malloc((unsigned int)inl); | ||
175 | outll=outl=EVP_PKEY_size(pkey); | ||
176 | buf_out=(unsigned char *)OPENSSL_malloc((unsigned int)outl); | ||
177 | if ((buf_in == NULL) || (buf_out == NULL)) | ||
178 | { | ||
179 | outl=0; | ||
180 | ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE); | ||
181 | goto err; | ||
182 | } | ||
183 | p=buf_in; | ||
184 | |||
185 | i2d(data,&p); | ||
186 | EVP_SignInit_ex(&ctx,type, NULL); | ||
187 | EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl); | ||
188 | if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out, | ||
189 | (unsigned int *)&outl,pkey)) | ||
190 | { | ||
191 | outl=0; | ||
192 | ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB); | ||
193 | goto err; | ||
194 | } | ||
195 | if (signature->data != NULL) OPENSSL_free(signature->data); | ||
196 | signature->data=buf_out; | ||
197 | buf_out=NULL; | ||
198 | signature->length=outl; | ||
199 | /* In the interests of compatibility, I'll make sure that | ||
200 | * the bit string has a 'not-used bits' value of 0 | ||
201 | */ | ||
202 | signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); | ||
203 | signature->flags|=ASN1_STRING_FLAG_BITS_LEFT; | ||
204 | err: | ||
205 | EVP_MD_CTX_cleanup(&ctx); | ||
206 | if (buf_in != NULL) | ||
207 | { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); OPENSSL_free(buf_in); } | ||
208 | if (buf_out != NULL) | ||
209 | { OPENSSL_cleanse((char *)buf_out,outll); OPENSSL_free(buf_out); } | ||
210 | return(outl); | ||
211 | } | ||
212 | |||
213 | #endif | ||
214 | |||
215 | int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | ||
216 | ASN1_BIT_STRING *signature, void *asn, EVP_PKEY *pkey, | ||
217 | const EVP_MD *type) | ||
218 | { | ||
219 | EVP_MD_CTX ctx; | ||
220 | unsigned char *buf_in=NULL,*buf_out=NULL; | ||
221 | int i,inl=0,outl=0,outll=0; | ||
222 | X509_ALGOR *a; | ||
223 | |||
224 | EVP_MD_CTX_init(&ctx); | ||
225 | for (i=0; i<2; i++) | ||
226 | { | ||
227 | if (i == 0) | ||
228 | a=algor1; | ||
229 | else | ||
230 | a=algor2; | ||
231 | if (a == NULL) continue; | ||
232 | if (type->pkey_type == NID_dsaWithSHA1) | ||
233 | { | ||
234 | /* special case: RFC 2459 tells us to omit 'parameters' | ||
235 | * with id-dsa-with-sha1 */ | ||
236 | ASN1_TYPE_free(a->parameter); | ||
237 | a->parameter = NULL; | ||
238 | } | ||
239 | else if ((a->parameter == NULL) || | ||
240 | (a->parameter->type != V_ASN1_NULL)) | ||
241 | { | ||
242 | ASN1_TYPE_free(a->parameter); | ||
243 | if ((a->parameter=ASN1_TYPE_new()) == NULL) goto err; | ||
244 | a->parameter->type=V_ASN1_NULL; | ||
245 | } | ||
246 | ASN1_OBJECT_free(a->algorithm); | ||
247 | a->algorithm=OBJ_nid2obj(type->pkey_type); | ||
248 | if (a->algorithm == NULL) | ||
249 | { | ||
250 | ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE); | ||
251 | goto err; | ||
252 | } | ||
253 | if (a->algorithm->length == 0) | ||
254 | { | ||
255 | ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD); | ||
256 | goto err; | ||
257 | } | ||
258 | } | ||
259 | inl=ASN1_item_i2d(asn,&buf_in, it); | ||
260 | outll=outl=EVP_PKEY_size(pkey); | ||
261 | buf_out=(unsigned char *)OPENSSL_malloc((unsigned int)outl); | ||
262 | if ((buf_in == NULL) || (buf_out == NULL)) | ||
263 | { | ||
264 | outl=0; | ||
265 | ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE); | ||
266 | goto err; | ||
267 | } | ||
268 | |||
269 | EVP_SignInit_ex(&ctx,type, NULL); | ||
270 | EVP_SignUpdate(&ctx,(unsigned char *)buf_in,inl); | ||
271 | if (!EVP_SignFinal(&ctx,(unsigned char *)buf_out, | ||
272 | (unsigned int *)&outl,pkey)) | ||
273 | { | ||
274 | outl=0; | ||
275 | ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB); | ||
276 | goto err; | ||
277 | } | ||
278 | if (signature->data != NULL) OPENSSL_free(signature->data); | ||
279 | signature->data=buf_out; | ||
280 | buf_out=NULL; | ||
281 | signature->length=outl; | ||
282 | /* In the interests of compatibility, I'll make sure that | ||
283 | * the bit string has a 'not-used bits' value of 0 | ||
284 | */ | ||
285 | signature->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); | ||
286 | signature->flags|=ASN1_STRING_FLAG_BITS_LEFT; | ||
287 | err: | ||
288 | EVP_MD_CTX_cleanup(&ctx); | ||
289 | if (buf_in != NULL) | ||
290 | { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); OPENSSL_free(buf_in); } | ||
291 | if (buf_out != NULL) | ||
292 | { OPENSSL_cleanse((char *)buf_out,outll); OPENSSL_free(buf_out); } | ||
293 | return(outl); | ||
294 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c deleted file mode 100644 index bde666a6ff..0000000000 --- a/src/lib/libcrypto/asn1/a_strex.c +++ /dev/null | |||
@@ -1,562 +0,0 @@ | |||
1 | /* a_strex.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <string.h> | ||
61 | #include <openssl/crypto.h> | ||
62 | #include <openssl/x509.h> | ||
63 | #include <openssl/asn1.h> | ||
64 | |||
65 | #include "charmap.h" | ||
66 | #include "cryptlib.h" | ||
67 | |||
68 | /* ASN1_STRING_print_ex() and X509_NAME_print_ex(). | ||
69 | * Enhanced string and name printing routines handling | ||
70 | * multibyte characters, RFC2253 and a host of other | ||
71 | * options. | ||
72 | */ | ||
73 | |||
74 | |||
75 | #define CHARTYPE_BS_ESC (ASN1_STRFLGS_ESC_2253 | CHARTYPE_FIRST_ESC_2253 | CHARTYPE_LAST_ESC_2253) | ||
76 | |||
77 | |||
78 | /* Three IO functions for sending data to memory, a BIO and | ||
79 | * and a FILE pointer. | ||
80 | */ | ||
81 | #if 0 /* never used */ | ||
82 | static int send_mem_chars(void *arg, const void *buf, int len) | ||
83 | { | ||
84 | unsigned char **out = arg; | ||
85 | if(!out) return 1; | ||
86 | memcpy(*out, buf, len); | ||
87 | *out += len; | ||
88 | return 1; | ||
89 | } | ||
90 | #endif | ||
91 | |||
92 | static int send_bio_chars(void *arg, const void *buf, int len) | ||
93 | { | ||
94 | if(!arg) return 1; | ||
95 | if(BIO_write(arg, buf, len) != len) return 0; | ||
96 | return 1; | ||
97 | } | ||
98 | |||
99 | static int send_fp_chars(void *arg, const void *buf, int len) | ||
100 | { | ||
101 | if(!arg) return 1; | ||
102 | if(fwrite(buf, 1, len, arg) != (unsigned int)len) return 0; | ||
103 | return 1; | ||
104 | } | ||
105 | |||
106 | typedef int char_io(void *arg, const void *buf, int len); | ||
107 | |||
108 | /* This function handles display of | ||
109 | * strings, one character at a time. | ||
110 | * It is passed an unsigned long for each | ||
111 | * character because it could come from 2 or even | ||
112 | * 4 byte forms. | ||
113 | */ | ||
114 | |||
115 | static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, char_io *io_ch, void *arg) | ||
116 | { | ||
117 | unsigned char chflgs, chtmp; | ||
118 | char tmphex[HEX_SIZE(long)+3]; | ||
119 | |||
120 | if(c > 0xffffffffL) | ||
121 | return -1; | ||
122 | if(c > 0xffff) { | ||
123 | BIO_snprintf(tmphex, sizeof tmphex, "\\W%08lX", c); | ||
124 | if(!io_ch(arg, tmphex, 10)) return -1; | ||
125 | return 10; | ||
126 | } | ||
127 | if(c > 0xff) { | ||
128 | BIO_snprintf(tmphex, sizeof tmphex, "\\U%04lX", c); | ||
129 | if(!io_ch(arg, tmphex, 6)) return -1; | ||
130 | return 6; | ||
131 | } | ||
132 | chtmp = (unsigned char)c; | ||
133 | if(chtmp > 0x7f) chflgs = flags & ASN1_STRFLGS_ESC_MSB; | ||
134 | else chflgs = char_type[chtmp] & flags; | ||
135 | if(chflgs & CHARTYPE_BS_ESC) { | ||
136 | /* If we don't escape with quotes, signal we need quotes */ | ||
137 | if(chflgs & ASN1_STRFLGS_ESC_QUOTE) { | ||
138 | if(do_quotes) *do_quotes = 1; | ||
139 | if(!io_ch(arg, &chtmp, 1)) return -1; | ||
140 | return 1; | ||
141 | } | ||
142 | if(!io_ch(arg, "\\", 1)) return -1; | ||
143 | if(!io_ch(arg, &chtmp, 1)) return -1; | ||
144 | return 2; | ||
145 | } | ||
146 | if(chflgs & (ASN1_STRFLGS_ESC_CTRL|ASN1_STRFLGS_ESC_MSB)) { | ||
147 | BIO_snprintf(tmphex, 11, "\\%02X", chtmp); | ||
148 | if(!io_ch(arg, tmphex, 3)) return -1; | ||
149 | return 3; | ||
150 | } | ||
151 | if(!io_ch(arg, &chtmp, 1)) return -1; | ||
152 | return 1; | ||
153 | } | ||
154 | |||
155 | #define BUF_TYPE_WIDTH_MASK 0x7 | ||
156 | #define BUF_TYPE_CONVUTF8 0x8 | ||
157 | |||
158 | /* This function sends each character in a buffer to | ||
159 | * do_esc_char(). It interprets the content formats | ||
160 | * and converts to or from UTF8 as appropriate. | ||
161 | */ | ||
162 | |||
163 | static int do_buf(unsigned char *buf, int buflen, | ||
164 | int type, unsigned char flags, char *quotes, char_io *io_ch, void *arg) | ||
165 | { | ||
166 | int i, outlen, len; | ||
167 | unsigned char orflags, *p, *q; | ||
168 | unsigned long c; | ||
169 | p = buf; | ||
170 | q = buf + buflen; | ||
171 | outlen = 0; | ||
172 | while(p != q) { | ||
173 | if(p == buf) orflags = CHARTYPE_FIRST_ESC_2253; | ||
174 | else orflags = 0; | ||
175 | switch(type & BUF_TYPE_WIDTH_MASK) { | ||
176 | case 4: | ||
177 | c = ((unsigned long)*p++) << 24; | ||
178 | c |= ((unsigned long)*p++) << 16; | ||
179 | c |= ((unsigned long)*p++) << 8; | ||
180 | c |= *p++; | ||
181 | break; | ||
182 | |||
183 | case 2: | ||
184 | c = ((unsigned long)*p++) << 8; | ||
185 | c |= *p++; | ||
186 | break; | ||
187 | |||
188 | case 1: | ||
189 | c = *p++; | ||
190 | break; | ||
191 | |||
192 | case 0: | ||
193 | i = UTF8_getc(p, buflen, &c); | ||
194 | if(i < 0) return -1; /* Invalid UTF8String */ | ||
195 | p += i; | ||
196 | break; | ||
197 | } | ||
198 | if (p == q) orflags = CHARTYPE_LAST_ESC_2253; | ||
199 | if(type & BUF_TYPE_CONVUTF8) { | ||
200 | unsigned char utfbuf[6]; | ||
201 | int utflen; | ||
202 | utflen = UTF8_putc(utfbuf, sizeof utfbuf, c); | ||
203 | for(i = 0; i < utflen; i++) { | ||
204 | /* We don't need to worry about setting orflags correctly | ||
205 | * because if utflen==1 its value will be correct anyway | ||
206 | * otherwise each character will be > 0x7f and so the | ||
207 | * character will never be escaped on first and last. | ||
208 | */ | ||
209 | len = do_esc_char(utfbuf[i], (unsigned char)(flags | orflags), quotes, io_ch, arg); | ||
210 | if(len < 0) return -1; | ||
211 | outlen += len; | ||
212 | } | ||
213 | } else { | ||
214 | len = do_esc_char(c, (unsigned char)(flags | orflags), quotes, io_ch, arg); | ||
215 | if(len < 0) return -1; | ||
216 | outlen += len; | ||
217 | } | ||
218 | } | ||
219 | return outlen; | ||
220 | } | ||
221 | |||
222 | /* This function hex dumps a buffer of characters */ | ||
223 | |||
224 | static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen) | ||
225 | { | ||
226 | const static char hexdig[] = "0123456789ABCDEF"; | ||
227 | unsigned char *p, *q; | ||
228 | char hextmp[2]; | ||
229 | if(arg) { | ||
230 | p = buf; | ||
231 | q = buf + buflen; | ||
232 | while(p != q) { | ||
233 | hextmp[0] = hexdig[*p >> 4]; | ||
234 | hextmp[1] = hexdig[*p & 0xf]; | ||
235 | if(!io_ch(arg, hextmp, 2)) return -1; | ||
236 | p++; | ||
237 | } | ||
238 | } | ||
239 | return buflen << 1; | ||
240 | } | ||
241 | |||
242 | /* "dump" a string. This is done when the type is unknown, | ||
243 | * or the flags request it. We can either dump the content | ||
244 | * octets or the entire DER encoding. This uses the RFC2253 | ||
245 | * #01234 format. | ||
246 | */ | ||
247 | |||
248 | static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING *str) | ||
249 | { | ||
250 | /* Placing the ASN1_STRING in a temp ASN1_TYPE allows | ||
251 | * the DER encoding to readily obtained | ||
252 | */ | ||
253 | ASN1_TYPE t; | ||
254 | unsigned char *der_buf, *p; | ||
255 | int outlen, der_len; | ||
256 | |||
257 | if(!io_ch(arg, "#", 1)) return -1; | ||
258 | /* If we don't dump DER encoding just dump content octets */ | ||
259 | if(!(lflags & ASN1_STRFLGS_DUMP_DER)) { | ||
260 | outlen = do_hex_dump(io_ch, arg, str->data, str->length); | ||
261 | if(outlen < 0) return -1; | ||
262 | return outlen + 1; | ||
263 | } | ||
264 | t.type = str->type; | ||
265 | t.value.ptr = (char *)str; | ||
266 | der_len = i2d_ASN1_TYPE(&t, NULL); | ||
267 | der_buf = OPENSSL_malloc(der_len); | ||
268 | if(!der_buf) return -1; | ||
269 | p = der_buf; | ||
270 | i2d_ASN1_TYPE(&t, &p); | ||
271 | outlen = do_hex_dump(io_ch, arg, der_buf, der_len); | ||
272 | OPENSSL_free(der_buf); | ||
273 | if(outlen < 0) return -1; | ||
274 | return outlen + 1; | ||
275 | } | ||
276 | |||
277 | /* Lookup table to convert tags to character widths, | ||
278 | * 0 = UTF8 encoded, -1 is used for non string types | ||
279 | * otherwise it is the number of bytes per character | ||
280 | */ | ||
281 | |||
282 | const static signed char tag2nbyte[] = { | ||
283 | -1, -1, -1, -1, -1, /* 0-4 */ | ||
284 | -1, -1, -1, -1, -1, /* 5-9 */ | ||
285 | -1, -1, 0, -1, /* 10-13 */ | ||
286 | -1, -1, -1, -1, /* 15-17 */ | ||
287 | -1, 1, 1, /* 18-20 */ | ||
288 | -1, 1, 1, 1, /* 21-24 */ | ||
289 | -1, 1, -1, /* 25-27 */ | ||
290 | 4, -1, 2 /* 28-30 */ | ||
291 | }; | ||
292 | |||
293 | #define ESC_FLAGS (ASN1_STRFLGS_ESC_2253 | \ | ||
294 | ASN1_STRFLGS_ESC_QUOTE | \ | ||
295 | ASN1_STRFLGS_ESC_CTRL | \ | ||
296 | ASN1_STRFLGS_ESC_MSB) | ||
297 | |||
298 | /* This is the main function, print out an | ||
299 | * ASN1_STRING taking note of various escape | ||
300 | * and display options. Returns number of | ||
301 | * characters written or -1 if an error | ||
302 | * occurred. | ||
303 | */ | ||
304 | |||
305 | static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STRING *str) | ||
306 | { | ||
307 | int outlen, len; | ||
308 | int type; | ||
309 | char quotes; | ||
310 | unsigned char flags; | ||
311 | quotes = 0; | ||
312 | /* Keep a copy of escape flags */ | ||
313 | flags = (unsigned char)(lflags & ESC_FLAGS); | ||
314 | |||
315 | type = str->type; | ||
316 | |||
317 | outlen = 0; | ||
318 | |||
319 | |||
320 | if(lflags & ASN1_STRFLGS_SHOW_TYPE) { | ||
321 | const char *tagname; | ||
322 | tagname = ASN1_tag2str(type); | ||
323 | outlen += strlen(tagname); | ||
324 | if(!io_ch(arg, tagname, outlen) || !io_ch(arg, ":", 1)) return -1; | ||
325 | outlen++; | ||
326 | } | ||
327 | |||
328 | /* Decide what to do with type, either dump content or display it */ | ||
329 | |||
330 | /* Dump everything */ | ||
331 | if(lflags & ASN1_STRFLGS_DUMP_ALL) type = -1; | ||
332 | /* Ignore the string type */ | ||
333 | else if(lflags & ASN1_STRFLGS_IGNORE_TYPE) type = 1; | ||
334 | else { | ||
335 | /* Else determine width based on type */ | ||
336 | if((type > 0) && (type < 31)) type = tag2nbyte[type]; | ||
337 | else type = -1; | ||
338 | if((type == -1) && !(lflags & ASN1_STRFLGS_DUMP_UNKNOWN)) type = 1; | ||
339 | } | ||
340 | |||
341 | if(type == -1) { | ||
342 | len = do_dump(lflags, io_ch, arg, str); | ||
343 | if(len < 0) return -1; | ||
344 | outlen += len; | ||
345 | return outlen; | ||
346 | } | ||
347 | |||
348 | if(lflags & ASN1_STRFLGS_UTF8_CONVERT) { | ||
349 | /* Note: if string is UTF8 and we want | ||
350 | * to convert to UTF8 then we just interpret | ||
351 | * it as 1 byte per character to avoid converting | ||
352 | * twice. | ||
353 | */ | ||
354 | if(!type) type = 1; | ||
355 | else type |= BUF_TYPE_CONVUTF8; | ||
356 | } | ||
357 | |||
358 | len = do_buf(str->data, str->length, type, flags, "es, io_ch, NULL); | ||
359 | if(outlen < 0) return -1; | ||
360 | outlen += len; | ||
361 | if(quotes) outlen += 2; | ||
362 | if(!arg) return outlen; | ||
363 | if(quotes && !io_ch(arg, "\"", 1)) return -1; | ||
364 | do_buf(str->data, str->length, type, flags, NULL, io_ch, arg); | ||
365 | if(quotes && !io_ch(arg, "\"", 1)) return -1; | ||
366 | return outlen; | ||
367 | } | ||
368 | |||
369 | /* Used for line indenting: print 'indent' spaces */ | ||
370 | |||
371 | static int do_indent(char_io *io_ch, void *arg, int indent) | ||
372 | { | ||
373 | int i; | ||
374 | for(i = 0; i < indent; i++) | ||
375 | if(!io_ch(arg, " ", 1)) return 0; | ||
376 | return 1; | ||
377 | } | ||
378 | |||
379 | #define FN_WIDTH_LN 25 | ||
380 | #define FN_WIDTH_SN 10 | ||
381 | |||
382 | static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | ||
383 | int indent, unsigned long flags) | ||
384 | { | ||
385 | int i, prev = -1, orflags, cnt; | ||
386 | int fn_opt, fn_nid; | ||
387 | ASN1_OBJECT *fn; | ||
388 | ASN1_STRING *val; | ||
389 | X509_NAME_ENTRY *ent; | ||
390 | char objtmp[80]; | ||
391 | const char *objbuf; | ||
392 | int outlen, len; | ||
393 | char *sep_dn, *sep_mv, *sep_eq; | ||
394 | int sep_dn_len, sep_mv_len, sep_eq_len; | ||
395 | if(indent < 0) indent = 0; | ||
396 | outlen = indent; | ||
397 | if(!do_indent(io_ch, arg, indent)) return -1; | ||
398 | switch (flags & XN_FLAG_SEP_MASK) | ||
399 | { | ||
400 | case XN_FLAG_SEP_MULTILINE: | ||
401 | sep_dn = "\n"; | ||
402 | sep_dn_len = 1; | ||
403 | sep_mv = " + "; | ||
404 | sep_mv_len = 3; | ||
405 | break; | ||
406 | |||
407 | case XN_FLAG_SEP_COMMA_PLUS: | ||
408 | sep_dn = ","; | ||
409 | sep_dn_len = 1; | ||
410 | sep_mv = "+"; | ||
411 | sep_mv_len = 1; | ||
412 | indent = 0; | ||
413 | break; | ||
414 | |||
415 | case XN_FLAG_SEP_CPLUS_SPC: | ||
416 | sep_dn = ", "; | ||
417 | sep_dn_len = 2; | ||
418 | sep_mv = " + "; | ||
419 | sep_mv_len = 3; | ||
420 | indent = 0; | ||
421 | break; | ||
422 | |||
423 | case XN_FLAG_SEP_SPLUS_SPC: | ||
424 | sep_dn = "; "; | ||
425 | sep_dn_len = 2; | ||
426 | sep_mv = " + "; | ||
427 | sep_mv_len = 3; | ||
428 | indent = 0; | ||
429 | break; | ||
430 | |||
431 | default: | ||
432 | return -1; | ||
433 | } | ||
434 | |||
435 | if(flags & XN_FLAG_SPC_EQ) { | ||
436 | sep_eq = " = "; | ||
437 | sep_eq_len = 3; | ||
438 | } else { | ||
439 | sep_eq = "="; | ||
440 | sep_eq_len = 1; | ||
441 | } | ||
442 | |||
443 | fn_opt = flags & XN_FLAG_FN_MASK; | ||
444 | |||
445 | cnt = X509_NAME_entry_count(n); | ||
446 | for(i = 0; i < cnt; i++) { | ||
447 | if(flags & XN_FLAG_DN_REV) | ||
448 | ent = X509_NAME_get_entry(n, cnt - i - 1); | ||
449 | else ent = X509_NAME_get_entry(n, i); | ||
450 | if(prev != -1) { | ||
451 | if(prev == ent->set) { | ||
452 | if(!io_ch(arg, sep_mv, sep_mv_len)) return -1; | ||
453 | outlen += sep_mv_len; | ||
454 | } else { | ||
455 | if(!io_ch(arg, sep_dn, sep_dn_len)) return -1; | ||
456 | outlen += sep_dn_len; | ||
457 | if(!do_indent(io_ch, arg, indent)) return -1; | ||
458 | outlen += indent; | ||
459 | } | ||
460 | } | ||
461 | prev = ent->set; | ||
462 | fn = X509_NAME_ENTRY_get_object(ent); | ||
463 | val = X509_NAME_ENTRY_get_data(ent); | ||
464 | fn_nid = OBJ_obj2nid(fn); | ||
465 | if(fn_opt != XN_FLAG_FN_NONE) { | ||
466 | int objlen, fld_len; | ||
467 | if((fn_opt == XN_FLAG_FN_OID) || (fn_nid==NID_undef) ) { | ||
468 | OBJ_obj2txt(objtmp, sizeof objtmp, fn, 1); | ||
469 | fld_len = 0; /* XXX: what should this be? */ | ||
470 | objbuf = objtmp; | ||
471 | } else { | ||
472 | if(fn_opt == XN_FLAG_FN_SN) { | ||
473 | fld_len = FN_WIDTH_SN; | ||
474 | objbuf = OBJ_nid2sn(fn_nid); | ||
475 | } else if(fn_opt == XN_FLAG_FN_LN) { | ||
476 | fld_len = FN_WIDTH_LN; | ||
477 | objbuf = OBJ_nid2ln(fn_nid); | ||
478 | } else { | ||
479 | fld_len = 0; /* XXX: what should this be? */ | ||
480 | objbuf = ""; | ||
481 | } | ||
482 | } | ||
483 | objlen = strlen(objbuf); | ||
484 | if(!io_ch(arg, objbuf, objlen)) return -1; | ||
485 | if ((objlen < fld_len) && (flags & XN_FLAG_FN_ALIGN)) { | ||
486 | if (!do_indent(io_ch, arg, fld_len - objlen)) return -1; | ||
487 | outlen += fld_len - objlen; | ||
488 | } | ||
489 | if(!io_ch(arg, sep_eq, sep_eq_len)) return -1; | ||
490 | outlen += objlen + sep_eq_len; | ||
491 | } | ||
492 | /* If the field name is unknown then fix up the DER dump | ||
493 | * flag. We might want to limit this further so it will | ||
494 | * DER dump on anything other than a few 'standard' fields. | ||
495 | */ | ||
496 | if((fn_nid == NID_undef) && (flags & XN_FLAG_DUMP_UNKNOWN_FIELDS)) | ||
497 | orflags = ASN1_STRFLGS_DUMP_ALL; | ||
498 | else orflags = 0; | ||
499 | |||
500 | len = do_print_ex(io_ch, arg, flags | orflags, val); | ||
501 | if(len < 0) return -1; | ||
502 | outlen += len; | ||
503 | } | ||
504 | return outlen; | ||
505 | } | ||
506 | |||
507 | /* Wrappers round the main functions */ | ||
508 | |||
509 | int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags) | ||
510 | { | ||
511 | if(flags == XN_FLAG_COMPAT) | ||
512 | return X509_NAME_print(out, nm, indent); | ||
513 | return do_name_ex(send_bio_chars, out, nm, indent, flags); | ||
514 | } | ||
515 | |||
516 | |||
517 | int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags) | ||
518 | { | ||
519 | if(flags == XN_FLAG_COMPAT) | ||
520 | { | ||
521 | BIO *btmp; | ||
522 | int ret; | ||
523 | btmp = BIO_new_fp(fp, BIO_NOCLOSE); | ||
524 | if(!btmp) return -1; | ||
525 | ret = X509_NAME_print(btmp, nm, indent); | ||
526 | BIO_free(btmp); | ||
527 | return ret; | ||
528 | } | ||
529 | return do_name_ex(send_fp_chars, fp, nm, indent, flags); | ||
530 | } | ||
531 | |||
532 | int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags) | ||
533 | { | ||
534 | return do_print_ex(send_bio_chars, out, flags, str); | ||
535 | } | ||
536 | |||
537 | |||
538 | int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags) | ||
539 | { | ||
540 | return do_print_ex(send_fp_chars, fp, flags, str); | ||
541 | } | ||
542 | |||
543 | /* Utility function: convert any string type to UTF8, returns number of bytes | ||
544 | * in output string or a negative error code | ||
545 | */ | ||
546 | |||
547 | int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in) | ||
548 | { | ||
549 | ASN1_STRING stmp, *str = &stmp; | ||
550 | int mbflag, type, ret; | ||
551 | if(!in) return -1; | ||
552 | type = in->type; | ||
553 | if((type < 0) || (type > 30)) return -1; | ||
554 | mbflag = tag2nbyte[type]; | ||
555 | if(mbflag == -1) return -1; | ||
556 | mbflag |= MBSTRING_FLAG; | ||
557 | stmp.data = NULL; | ||
558 | ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING); | ||
559 | if(ret < 0) return ret; | ||
560 | *out = stmp.data; | ||
561 | return stmp.length; | ||
562 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_strnid.c b/src/lib/libcrypto/asn1/a_strnid.c deleted file mode 100644 index 613bbc4a7d..0000000000 --- a/src/lib/libcrypto/asn1/a_strnid.c +++ /dev/null | |||
@@ -1,290 +0,0 @@ | |||
1 | /* a_strnid.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <ctype.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/asn1.h> | ||
63 | #include <openssl/objects.h> | ||
64 | |||
65 | |||
66 | static STACK_OF(ASN1_STRING_TABLE) *stable = NULL; | ||
67 | static void st_free(ASN1_STRING_TABLE *tbl); | ||
68 | static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, | ||
69 | const ASN1_STRING_TABLE * const *b); | ||
70 | static int table_cmp(const void *a, const void *b); | ||
71 | |||
72 | |||
73 | /* This is the global mask for the mbstring functions: this is use to | ||
74 | * mask out certain types (such as BMPString and UTF8String) because | ||
75 | * certain software (e.g. Netscape) has problems with them. | ||
76 | */ | ||
77 | |||
78 | static unsigned long global_mask = 0xFFFFFFFFL; | ||
79 | |||
80 | void ASN1_STRING_set_default_mask(unsigned long mask) | ||
81 | { | ||
82 | global_mask = mask; | ||
83 | } | ||
84 | |||
85 | unsigned long ASN1_STRING_get_default_mask(void) | ||
86 | { | ||
87 | return global_mask; | ||
88 | } | ||
89 | |||
90 | /* This function sets the default to various "flavours" of configuration. | ||
91 | * based on an ASCII string. Currently this is: | ||
92 | * MASK:XXXX : a numerical mask value. | ||
93 | * nobmp : Don't use BMPStrings (just Printable, T61). | ||
94 | * pkix : PKIX recommendation in RFC2459. | ||
95 | * utf8only : only use UTF8Strings (RFC2459 recommendation for 2004). | ||
96 | * default: the default value, Printable, T61, BMP. | ||
97 | */ | ||
98 | |||
99 | int ASN1_STRING_set_default_mask_asc(char *p) | ||
100 | { | ||
101 | unsigned long mask; | ||
102 | char *end; | ||
103 | if(!strncmp(p, "MASK:", 5)) { | ||
104 | if(!p[5]) return 0; | ||
105 | mask = strtoul(p + 5, &end, 0); | ||
106 | if(*end) return 0; | ||
107 | } else if(!strcmp(p, "nombstr")) | ||
108 | mask = ~((unsigned long)(B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)); | ||
109 | else if(!strcmp(p, "pkix")) | ||
110 | mask = ~((unsigned long)B_ASN1_T61STRING); | ||
111 | else if(!strcmp(p, "utf8only")) mask = B_ASN1_UTF8STRING; | ||
112 | else if(!strcmp(p, "default")) | ||
113 | mask = 0xFFFFFFFFL; | ||
114 | else return 0; | ||
115 | ASN1_STRING_set_default_mask(mask); | ||
116 | return 1; | ||
117 | } | ||
118 | |||
119 | /* The following function generates an ASN1_STRING based on limits in a table. | ||
120 | * Frequently the types and length of an ASN1_STRING are restricted by a | ||
121 | * corresponding OID. For example certificates and certificate requests. | ||
122 | */ | ||
123 | |||
124 | ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in, | ||
125 | int inlen, int inform, int nid) | ||
126 | { | ||
127 | ASN1_STRING_TABLE *tbl; | ||
128 | ASN1_STRING *str = NULL; | ||
129 | unsigned long mask; | ||
130 | int ret; | ||
131 | if(!out) out = &str; | ||
132 | tbl = ASN1_STRING_TABLE_get(nid); | ||
133 | if(tbl) { | ||
134 | mask = tbl->mask; | ||
135 | if(!(tbl->flags & STABLE_NO_MASK)) mask &= global_mask; | ||
136 | ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask, | ||
137 | tbl->minsize, tbl->maxsize); | ||
138 | } else ret = ASN1_mbstring_copy(out, in, inlen, inform, DIRSTRING_TYPE & global_mask); | ||
139 | if(ret <= 0) return NULL; | ||
140 | return *out; | ||
141 | } | ||
142 | |||
143 | /* Now the tables and helper functions for the string table: | ||
144 | */ | ||
145 | |||
146 | /* size limits: this stuff is taken straight from RFC3280 */ | ||
147 | |||
148 | #define ub_name 32768 | ||
149 | #define ub_common_name 64 | ||
150 | #define ub_locality_name 128 | ||
151 | #define ub_state_name 128 | ||
152 | #define ub_organization_name 64 | ||
153 | #define ub_organization_unit_name 64 | ||
154 | #define ub_title 64 | ||
155 | #define ub_email_address 128 | ||
156 | #define ub_serial_number 64 | ||
157 | |||
158 | |||
159 | /* This table must be kept in NID order */ | ||
160 | |||
161 | static ASN1_STRING_TABLE tbl_standard[] = { | ||
162 | {NID_commonName, 1, ub_common_name, DIRSTRING_TYPE, 0}, | ||
163 | {NID_countryName, 2, 2, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, | ||
164 | {NID_localityName, 1, ub_locality_name, DIRSTRING_TYPE, 0}, | ||
165 | {NID_stateOrProvinceName, 1, ub_state_name, DIRSTRING_TYPE, 0}, | ||
166 | {NID_organizationName, 1, ub_organization_name, DIRSTRING_TYPE, 0}, | ||
167 | {NID_organizationalUnitName, 1, ub_organization_unit_name, DIRSTRING_TYPE, 0}, | ||
168 | {NID_pkcs9_emailAddress, 1, ub_email_address, B_ASN1_IA5STRING, STABLE_NO_MASK}, | ||
169 | {NID_pkcs9_unstructuredName, 1, -1, PKCS9STRING_TYPE, 0}, | ||
170 | {NID_pkcs9_challengePassword, 1, -1, PKCS9STRING_TYPE, 0}, | ||
171 | {NID_pkcs9_unstructuredAddress, 1, -1, DIRSTRING_TYPE, 0}, | ||
172 | {NID_givenName, 1, ub_name, DIRSTRING_TYPE, 0}, | ||
173 | {NID_surname, 1, ub_name, DIRSTRING_TYPE, 0}, | ||
174 | {NID_initials, 1, ub_name, DIRSTRING_TYPE, 0}, | ||
175 | {NID_serialNumber, 1, ub_serial_number, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, | ||
176 | {NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}, | ||
177 | {NID_name, 1, ub_name, DIRSTRING_TYPE, 0}, | ||
178 | {NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, | ||
179 | {NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK}, | ||
180 | {NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK} | ||
181 | }; | ||
182 | |||
183 | static int sk_table_cmp(const ASN1_STRING_TABLE * const *a, | ||
184 | const ASN1_STRING_TABLE * const *b) | ||
185 | { | ||
186 | return (*a)->nid - (*b)->nid; | ||
187 | } | ||
188 | |||
189 | static int table_cmp(const void *a, const void *b) | ||
190 | { | ||
191 | const ASN1_STRING_TABLE *sa = a, *sb = b; | ||
192 | return sa->nid - sb->nid; | ||
193 | } | ||
194 | |||
195 | ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid) | ||
196 | { | ||
197 | int idx; | ||
198 | ASN1_STRING_TABLE *ttmp; | ||
199 | ASN1_STRING_TABLE fnd; | ||
200 | fnd.nid = nid; | ||
201 | ttmp = (ASN1_STRING_TABLE *) OBJ_bsearch((char *)&fnd, | ||
202 | (char *)tbl_standard, | ||
203 | sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE), | ||
204 | sizeof(ASN1_STRING_TABLE), table_cmp); | ||
205 | if(ttmp) return ttmp; | ||
206 | if(!stable) return NULL; | ||
207 | idx = sk_ASN1_STRING_TABLE_find(stable, &fnd); | ||
208 | if(idx < 0) return NULL; | ||
209 | return sk_ASN1_STRING_TABLE_value(stable, idx); | ||
210 | } | ||
211 | |||
212 | int ASN1_STRING_TABLE_add(int nid, | ||
213 | long minsize, long maxsize, unsigned long mask, | ||
214 | unsigned long flags) | ||
215 | { | ||
216 | ASN1_STRING_TABLE *tmp; | ||
217 | char new_nid = 0; | ||
218 | flags &= ~STABLE_FLAGS_MALLOC; | ||
219 | if(!stable) stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp); | ||
220 | if(!stable) { | ||
221 | ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, ERR_R_MALLOC_FAILURE); | ||
222 | return 0; | ||
223 | } | ||
224 | if(!(tmp = ASN1_STRING_TABLE_get(nid))) { | ||
225 | tmp = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE)); | ||
226 | if(!tmp) { | ||
227 | ASN1err(ASN1_F_ASN1_STRING_TABLE_ADD, | ||
228 | ERR_R_MALLOC_FAILURE); | ||
229 | return 0; | ||
230 | } | ||
231 | tmp->flags = flags | STABLE_FLAGS_MALLOC; | ||
232 | tmp->nid = nid; | ||
233 | new_nid = 1; | ||
234 | } else tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags; | ||
235 | if(minsize != -1) tmp->minsize = minsize; | ||
236 | if(maxsize != -1) tmp->maxsize = maxsize; | ||
237 | tmp->mask = mask; | ||
238 | if(new_nid) sk_ASN1_STRING_TABLE_push(stable, tmp); | ||
239 | return 1; | ||
240 | } | ||
241 | |||
242 | void ASN1_STRING_TABLE_cleanup(void) | ||
243 | { | ||
244 | STACK_OF(ASN1_STRING_TABLE) *tmp; | ||
245 | tmp = stable; | ||
246 | if(!tmp) return; | ||
247 | stable = NULL; | ||
248 | sk_ASN1_STRING_TABLE_pop_free(tmp, st_free); | ||
249 | } | ||
250 | |||
251 | static void st_free(ASN1_STRING_TABLE *tbl) | ||
252 | { | ||
253 | if(tbl->flags & STABLE_FLAGS_MALLOC) OPENSSL_free(tbl); | ||
254 | } | ||
255 | |||
256 | |||
257 | IMPLEMENT_STACK_OF(ASN1_STRING_TABLE) | ||
258 | |||
259 | #ifdef STRING_TABLE_TEST | ||
260 | |||
261 | main() | ||
262 | { | ||
263 | ASN1_STRING_TABLE *tmp; | ||
264 | int i, last_nid = -1; | ||
265 | |||
266 | for (tmp = tbl_standard, i = 0; | ||
267 | i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) | ||
268 | { | ||
269 | if (tmp->nid < last_nid) | ||
270 | { | ||
271 | last_nid = 0; | ||
272 | break; | ||
273 | } | ||
274 | last_nid = tmp->nid; | ||
275 | } | ||
276 | |||
277 | if (last_nid != 0) | ||
278 | { | ||
279 | printf("Table order OK\n"); | ||
280 | exit(0); | ||
281 | } | ||
282 | |||
283 | for (tmp = tbl_standard, i = 0; | ||
284 | i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) | ||
285 | printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, | ||
286 | OBJ_nid2ln(tmp->nid)); | ||
287 | |||
288 | } | ||
289 | |||
290 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c deleted file mode 100644 index 159681fbcb..0000000000 --- a/src/lib/libcrypto/asn1/a_time.c +++ /dev/null | |||
@@ -1,164 +0,0 @@ | |||
1 | /* crypto/asn1/a_time.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | |||
57 | /* This is an implementation of the ASN1 Time structure which is: | ||
58 | * Time ::= CHOICE { | ||
59 | * utcTime UTCTime, | ||
60 | * generalTime GeneralizedTime } | ||
61 | * written by Steve Henson. | ||
62 | */ | ||
63 | |||
64 | #include <stdio.h> | ||
65 | #include <time.h> | ||
66 | #include "cryptlib.h" | ||
67 | #include "o_time.h" | ||
68 | #include <openssl/asn1t.h> | ||
69 | |||
70 | IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME) | ||
71 | |||
72 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME) | ||
73 | |||
74 | #if 0 | ||
75 | int i2d_ASN1_TIME(ASN1_TIME *a, unsigned char **pp) | ||
76 | { | ||
77 | #ifdef CHARSET_EBCDIC | ||
78 | /* KLUDGE! We convert to ascii before writing DER */ | ||
79 | char tmp[24]; | ||
80 | ASN1_STRING tmpstr; | ||
81 | |||
82 | if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) { | ||
83 | int len; | ||
84 | |||
85 | tmpstr = *(ASN1_STRING *)a; | ||
86 | len = tmpstr.length; | ||
87 | ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len); | ||
88 | tmpstr.data = tmp; | ||
89 | a = (ASN1_GENERALIZEDTIME *) &tmpstr; | ||
90 | } | ||
91 | #endif | ||
92 | if(a->type == V_ASN1_UTCTIME || a->type == V_ASN1_GENERALIZEDTIME) | ||
93 | return(i2d_ASN1_bytes((ASN1_STRING *)a,pp, | ||
94 | a->type ,V_ASN1_UNIVERSAL)); | ||
95 | ASN1err(ASN1_F_I2D_ASN1_TIME,ASN1_R_EXPECTING_A_TIME); | ||
96 | return -1; | ||
97 | } | ||
98 | #endif | ||
99 | |||
100 | |||
101 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) | ||
102 | { | ||
103 | struct tm *ts; | ||
104 | struct tm data; | ||
105 | |||
106 | ts=OPENSSL_gmtime(&t,&data); | ||
107 | if (ts == NULL) | ||
108 | { | ||
109 | ASN1err(ASN1_F_ASN1_TIME_SET, ASN1_R_ERROR_GETTING_TIME); | ||
110 | return NULL; | ||
111 | } | ||
112 | if((ts->tm_year >= 50) && (ts->tm_year < 150)) | ||
113 | return ASN1_UTCTIME_set(s, t); | ||
114 | return ASN1_GENERALIZEDTIME_set(s,t); | ||
115 | } | ||
116 | |||
117 | int ASN1_TIME_check(ASN1_TIME *t) | ||
118 | { | ||
119 | if (t->type == V_ASN1_GENERALIZEDTIME) | ||
120 | return ASN1_GENERALIZEDTIME_check(t); | ||
121 | else if (t->type == V_ASN1_UTCTIME) | ||
122 | return ASN1_UTCTIME_check(t); | ||
123 | return 0; | ||
124 | } | ||
125 | |||
126 | /* Convert an ASN1_TIME structure to GeneralizedTime */ | ||
127 | ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out) | ||
128 | { | ||
129 | ASN1_GENERALIZEDTIME *ret; | ||
130 | char *str; | ||
131 | int newlen; | ||
132 | |||
133 | if (!ASN1_TIME_check(t)) return NULL; | ||
134 | |||
135 | if (!out || !*out) | ||
136 | { | ||
137 | if (!(ret = ASN1_GENERALIZEDTIME_new ())) | ||
138 | return NULL; | ||
139 | if (out) *out = ret; | ||
140 | } | ||
141 | else ret = *out; | ||
142 | |||
143 | /* If already GeneralizedTime just copy across */ | ||
144 | if (t->type == V_ASN1_GENERALIZEDTIME) | ||
145 | { | ||
146 | if(!ASN1_STRING_set(ret, t->data, t->length)) | ||
147 | return NULL; | ||
148 | return ret; | ||
149 | } | ||
150 | |||
151 | /* grow the string */ | ||
152 | if (!ASN1_STRING_set(ret, NULL, t->length + 2)) | ||
153 | return NULL; | ||
154 | /* ASN1_STRING_set() allocated 'len + 1' bytes. */ | ||
155 | newlen = t->length + 2 + 1; | ||
156 | str = (char *)ret->data; | ||
157 | /* Work out the century and prepend */ | ||
158 | if (t->data[0] >= '5') BUF_strlcpy(str, "19", newlen); | ||
159 | else BUF_strlcpy(str, "20", newlen); | ||
160 | |||
161 | BUF_strlcat(str, (char *)t->data, newlen); | ||
162 | |||
163 | return ret; | ||
164 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c deleted file mode 100644 index fe3fcd40b0..0000000000 --- a/src/lib/libcrypto/asn1/a_type.c +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | /* crypto/asn1/a_type.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <openssl/asn1t.h> | ||
61 | #include "cryptlib.h" | ||
62 | |||
63 | int ASN1_TYPE_get(ASN1_TYPE *a) | ||
64 | { | ||
65 | if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL)) | ||
66 | return(a->type); | ||
67 | else | ||
68 | return(0); | ||
69 | } | ||
70 | |||
71 | void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value) | ||
72 | { | ||
73 | if (a->value.ptr != NULL) | ||
74 | ASN1_primitive_free((ASN1_VALUE **)&a, NULL); | ||
75 | a->type=type; | ||
76 | a->value.ptr=value; | ||
77 | } | ||
78 | |||
79 | |||
80 | IMPLEMENT_STACK_OF(ASN1_TYPE) | ||
81 | IMPLEMENT_ASN1_SET_OF(ASN1_TYPE) | ||
diff --git a/src/lib/libcrypto/asn1/a_utf8.c b/src/lib/libcrypto/asn1/a_utf8.c deleted file mode 100644 index 508e11e527..0000000000 --- a/src/lib/libcrypto/asn1/a_utf8.c +++ /dev/null | |||
@@ -1,211 +0,0 @@ | |||
1 | /* crypto/asn1/a_utf8.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1.h> | ||
62 | |||
63 | |||
64 | /* UTF8 utilities */ | ||
65 | |||
66 | /* This parses a UTF8 string one character at a time. It is passed a pointer | ||
67 | * to the string and the length of the string. It sets 'value' to the value of | ||
68 | * the current character. It returns the number of characters read or a | ||
69 | * negative error code: | ||
70 | * -1 = string too short | ||
71 | * -2 = illegal character | ||
72 | * -3 = subsequent characters not of the form 10xxxxxx | ||
73 | * -4 = character encoded incorrectly (not minimal length). | ||
74 | */ | ||
75 | |||
76 | int UTF8_getc(const unsigned char *str, int len, unsigned long *val) | ||
77 | { | ||
78 | const unsigned char *p; | ||
79 | unsigned long value; | ||
80 | int ret; | ||
81 | if(len <= 0) return 0; | ||
82 | p = str; | ||
83 | |||
84 | /* Check syntax and work out the encoded value (if correct) */ | ||
85 | if((*p & 0x80) == 0) { | ||
86 | value = *p++ & 0x7f; | ||
87 | ret = 1; | ||
88 | } else if((*p & 0xe0) == 0xc0) { | ||
89 | if(len < 2) return -1; | ||
90 | if((p[1] & 0xc0) != 0x80) return -3; | ||
91 | value = (*p++ & 0x1f) << 6; | ||
92 | value |= *p++ & 0x3f; | ||
93 | if(value < 0x80) return -4; | ||
94 | ret = 2; | ||
95 | } else if((*p & 0xf0) == 0xe0) { | ||
96 | if(len < 3) return -1; | ||
97 | if( ((p[1] & 0xc0) != 0x80) | ||
98 | || ((p[2] & 0xc0) != 0x80) ) return -3; | ||
99 | value = (*p++ & 0xf) << 12; | ||
100 | value |= (*p++ & 0x3f) << 6; | ||
101 | value |= *p++ & 0x3f; | ||
102 | if(value < 0x800) return -4; | ||
103 | ret = 3; | ||
104 | } else if((*p & 0xf8) == 0xf0) { | ||
105 | if(len < 4) return -1; | ||
106 | if( ((p[1] & 0xc0) != 0x80) | ||
107 | || ((p[2] & 0xc0) != 0x80) | ||
108 | || ((p[3] & 0xc0) != 0x80) ) return -3; | ||
109 | value = ((unsigned long)(*p++ & 0x7)) << 18; | ||
110 | value |= (*p++ & 0x3f) << 12; | ||
111 | value |= (*p++ & 0x3f) << 6; | ||
112 | value |= *p++ & 0x3f; | ||
113 | if(value < 0x10000) return -4; | ||
114 | ret = 4; | ||
115 | } else if((*p & 0xfc) == 0xf8) { | ||
116 | if(len < 5) return -1; | ||
117 | if( ((p[1] & 0xc0) != 0x80) | ||
118 | || ((p[2] & 0xc0) != 0x80) | ||
119 | || ((p[3] & 0xc0) != 0x80) | ||
120 | || ((p[4] & 0xc0) != 0x80) ) return -3; | ||
121 | value = ((unsigned long)(*p++ & 0x3)) << 24; | ||
122 | value |= ((unsigned long)(*p++ & 0x3f)) << 18; | ||
123 | value |= ((unsigned long)(*p++ & 0x3f)) << 12; | ||
124 | value |= (*p++ & 0x3f) << 6; | ||
125 | value |= *p++ & 0x3f; | ||
126 | if(value < 0x200000) return -4; | ||
127 | ret = 5; | ||
128 | } else if((*p & 0xfe) == 0xfc) { | ||
129 | if(len < 6) return -1; | ||
130 | if( ((p[1] & 0xc0) != 0x80) | ||
131 | || ((p[2] & 0xc0) != 0x80) | ||
132 | || ((p[3] & 0xc0) != 0x80) | ||
133 | || ((p[4] & 0xc0) != 0x80) | ||
134 | || ((p[5] & 0xc0) != 0x80) ) return -3; | ||
135 | value = ((unsigned long)(*p++ & 0x1)) << 30; | ||
136 | value |= ((unsigned long)(*p++ & 0x3f)) << 24; | ||
137 | value |= ((unsigned long)(*p++ & 0x3f)) << 18; | ||
138 | value |= ((unsigned long)(*p++ & 0x3f)) << 12; | ||
139 | value |= (*p++ & 0x3f) << 6; | ||
140 | value |= *p++ & 0x3f; | ||
141 | if(value < 0x4000000) return -4; | ||
142 | ret = 6; | ||
143 | } else return -2; | ||
144 | *val = value; | ||
145 | return ret; | ||
146 | } | ||
147 | |||
148 | /* This takes a character 'value' and writes the UTF8 encoded value in | ||
149 | * 'str' where 'str' is a buffer containing 'len' characters. Returns | ||
150 | * the number of characters written or -1 if 'len' is too small. 'str' can | ||
151 | * be set to NULL in which case it just returns the number of characters. | ||
152 | * It will need at most 6 characters. | ||
153 | */ | ||
154 | |||
155 | int UTF8_putc(unsigned char *str, int len, unsigned long value) | ||
156 | { | ||
157 | if(!str) len = 6; /* Maximum we will need */ | ||
158 | else if(len <= 0) return -1; | ||
159 | if(value < 0x80) { | ||
160 | if(str) *str = (unsigned char)value; | ||
161 | return 1; | ||
162 | } | ||
163 | if(value < 0x800) { | ||
164 | if(len < 2) return -1; | ||
165 | if(str) { | ||
166 | *str++ = (unsigned char)(((value >> 6) & 0x1f) | 0xc0); | ||
167 | *str = (unsigned char)((value & 0x3f) | 0x80); | ||
168 | } | ||
169 | return 2; | ||
170 | } | ||
171 | if(value < 0x10000) { | ||
172 | if(len < 3) return -1; | ||
173 | if(str) { | ||
174 | *str++ = (unsigned char)(((value >> 12) & 0xf) | 0xe0); | ||
175 | *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80); | ||
176 | *str = (unsigned char)((value & 0x3f) | 0x80); | ||
177 | } | ||
178 | return 3; | ||
179 | } | ||
180 | if(value < 0x200000) { | ||
181 | if(len < 4) return -1; | ||
182 | if(str) { | ||
183 | *str++ = (unsigned char)(((value >> 18) & 0x7) | 0xf0); | ||
184 | *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80); | ||
185 | *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80); | ||
186 | *str = (unsigned char)((value & 0x3f) | 0x80); | ||
187 | } | ||
188 | return 4; | ||
189 | } | ||
190 | if(value < 0x4000000) { | ||
191 | if(len < 5) return -1; | ||
192 | if(str) { | ||
193 | *str++ = (unsigned char)(((value >> 24) & 0x3) | 0xf8); | ||
194 | *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80); | ||
195 | *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80); | ||
196 | *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80); | ||
197 | *str = (unsigned char)((value & 0x3f) | 0x80); | ||
198 | } | ||
199 | return 5; | ||
200 | } | ||
201 | if(len < 6) return -1; | ||
202 | if(str) { | ||
203 | *str++ = (unsigned char)(((value >> 30) & 0x1) | 0xfc); | ||
204 | *str++ = (unsigned char)(((value >> 24) & 0x3f) | 0x80); | ||
205 | *str++ = (unsigned char)(((value >> 18) & 0x3f) | 0x80); | ||
206 | *str++ = (unsigned char)(((value >> 12) & 0x3f) | 0x80); | ||
207 | *str++ = (unsigned char)(((value >> 6) & 0x3f) | 0x80); | ||
208 | *str = (unsigned char)((value & 0x3f) | 0x80); | ||
209 | } | ||
210 | return 6; | ||
211 | } | ||
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c deleted file mode 100644 index da2a0a6d69..0000000000 --- a/src/lib/libcrypto/asn1/a_verify.c +++ /dev/null | |||
@@ -1,175 +0,0 @@ | |||
1 | /* crypto/asn1/a_verify.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <time.h> | ||
61 | |||
62 | #include "cryptlib.h" | ||
63 | |||
64 | #ifndef NO_SYS_TYPES_H | ||
65 | # include <sys/types.h> | ||
66 | #endif | ||
67 | |||
68 | #include <openssl/bn.h> | ||
69 | #include <openssl/x509.h> | ||
70 | #include <openssl/objects.h> | ||
71 | #include <openssl/buffer.h> | ||
72 | #include <openssl/evp.h> | ||
73 | |||
74 | #ifndef NO_ASN1_OLD | ||
75 | |||
76 | int ASN1_verify(int (*i2d)(), X509_ALGOR *a, ASN1_BIT_STRING *signature, | ||
77 | char *data, EVP_PKEY *pkey) | ||
78 | { | ||
79 | EVP_MD_CTX ctx; | ||
80 | const EVP_MD *type; | ||
81 | unsigned char *p,*buf_in=NULL; | ||
82 | int ret= -1,i,inl; | ||
83 | |||
84 | EVP_MD_CTX_init(&ctx); | ||
85 | i=OBJ_obj2nid(a->algorithm); | ||
86 | type=EVP_get_digestbyname(OBJ_nid2sn(i)); | ||
87 | if (type == NULL) | ||
88 | { | ||
89 | ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM); | ||
90 | goto err; | ||
91 | } | ||
92 | |||
93 | inl=i2d(data,NULL); | ||
94 | buf_in=OPENSSL_malloc((unsigned int)inl); | ||
95 | if (buf_in == NULL) | ||
96 | { | ||
97 | ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE); | ||
98 | goto err; | ||
99 | } | ||
100 | p=buf_in; | ||
101 | |||
102 | i2d(data,&p); | ||
103 | EVP_VerifyInit_ex(&ctx,type, NULL); | ||
104 | EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl); | ||
105 | |||
106 | OPENSSL_cleanse(buf_in,(unsigned int)inl); | ||
107 | OPENSSL_free(buf_in); | ||
108 | |||
109 | if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data, | ||
110 | (unsigned int)signature->length,pkey) <= 0) | ||
111 | { | ||
112 | ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB); | ||
113 | ret=0; | ||
114 | goto err; | ||
115 | } | ||
116 | /* we don't need to zero the 'ctx' because we just checked | ||
117 | * public information */ | ||
118 | /* memset(&ctx,0,sizeof(ctx)); */ | ||
119 | ret=1; | ||
120 | err: | ||
121 | EVP_MD_CTX_cleanup(&ctx); | ||
122 | return(ret); | ||
123 | } | ||
124 | |||
125 | #endif | ||
126 | |||
127 | |||
128 | int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, ASN1_BIT_STRING *signature, | ||
129 | void *asn, EVP_PKEY *pkey) | ||
130 | { | ||
131 | EVP_MD_CTX ctx; | ||
132 | const EVP_MD *type; | ||
133 | unsigned char *buf_in=NULL; | ||
134 | int ret= -1,i,inl; | ||
135 | |||
136 | EVP_MD_CTX_init(&ctx); | ||
137 | i=OBJ_obj2nid(a->algorithm); | ||
138 | type=EVP_get_digestbyname(OBJ_nid2sn(i)); | ||
139 | if (type == NULL) | ||
140 | { | ||
141 | ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM); | ||
142 | goto err; | ||
143 | } | ||
144 | |||
145 | inl = ASN1_item_i2d(asn, &buf_in, it); | ||
146 | |||
147 | if (buf_in == NULL) | ||
148 | { | ||
149 | ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE); | ||
150 | goto err; | ||
151 | } | ||
152 | |||
153 | EVP_VerifyInit_ex(&ctx,type, NULL); | ||
154 | EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl); | ||
155 | |||
156 | OPENSSL_cleanse(buf_in,(unsigned int)inl); | ||
157 | OPENSSL_free(buf_in); | ||
158 | |||
159 | if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data, | ||
160 | (unsigned int)signature->length,pkey) <= 0) | ||
161 | { | ||
162 | ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB); | ||
163 | ret=0; | ||
164 | goto err; | ||
165 | } | ||
166 | /* we don't need to zero the 'ctx' because we just checked | ||
167 | * public information */ | ||
168 | /* memset(&ctx,0,sizeof(ctx)); */ | ||
169 | ret=1; | ||
170 | err: | ||
171 | EVP_MD_CTX_cleanup(&ctx); | ||
172 | return(ret); | ||
173 | } | ||
174 | |||
175 | |||
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h deleted file mode 100644 index 3414509f1b..0000000000 --- a/src/lib/libcrypto/asn1/asn1.h +++ /dev/null | |||
@@ -1,1105 +0,0 @@ | |||
1 | /* crypto/asn1/asn1.h */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #ifndef HEADER_ASN1_H | ||
60 | #define HEADER_ASN1_H | ||
61 | |||
62 | #include <time.h> | ||
63 | #ifndef OPENSSL_NO_BIO | ||
64 | #include <openssl/bio.h> | ||
65 | #endif | ||
66 | #include <openssl/e_os2.h> | ||
67 | #include <openssl/bn.h> | ||
68 | #include <openssl/stack.h> | ||
69 | #include <openssl/safestack.h> | ||
70 | |||
71 | #include <openssl/symhacks.h> | ||
72 | |||
73 | #include <openssl/ossl_typ.h> | ||
74 | |||
75 | #ifdef OPENSSL_BUILD_SHLIBCRYPTO | ||
76 | # undef OPENSSL_EXTERN | ||
77 | # define OPENSSL_EXTERN OPENSSL_EXPORT | ||
78 | #endif | ||
79 | |||
80 | #ifdef __cplusplus | ||
81 | extern "C" { | ||
82 | #endif | ||
83 | |||
84 | #define V_ASN1_UNIVERSAL 0x00 | ||
85 | #define V_ASN1_APPLICATION 0x40 | ||
86 | #define V_ASN1_CONTEXT_SPECIFIC 0x80 | ||
87 | #define V_ASN1_PRIVATE 0xc0 | ||
88 | |||
89 | #define V_ASN1_CONSTRUCTED 0x20 | ||
90 | #define V_ASN1_PRIMITIVE_TAG 0x1f | ||
91 | #define V_ASN1_PRIMATIVE_TAG 0x1f | ||
92 | |||
93 | #define V_ASN1_APP_CHOOSE -2 /* let the recipient choose */ | ||
94 | #define V_ASN1_OTHER -3 /* used in ASN1_TYPE */ | ||
95 | #define V_ASN1_ANY -4 /* used in ASN1 template code */ | ||
96 | |||
97 | #define V_ASN1_NEG 0x100 /* negative flag */ | ||
98 | |||
99 | #define V_ASN1_UNDEF -1 | ||
100 | #define V_ASN1_EOC 0 | ||
101 | #define V_ASN1_BOOLEAN 1 /**/ | ||
102 | #define V_ASN1_INTEGER 2 | ||
103 | #define V_ASN1_NEG_INTEGER (2 | V_ASN1_NEG) | ||
104 | #define V_ASN1_BIT_STRING 3 | ||
105 | #define V_ASN1_OCTET_STRING 4 | ||
106 | #define V_ASN1_NULL 5 | ||
107 | #define V_ASN1_OBJECT 6 | ||
108 | #define V_ASN1_OBJECT_DESCRIPTOR 7 | ||
109 | #define V_ASN1_EXTERNAL 8 | ||
110 | #define V_ASN1_REAL 9 | ||
111 | #define V_ASN1_ENUMERATED 10 | ||
112 | #define V_ASN1_NEG_ENUMERATED (10 | V_ASN1_NEG) | ||
113 | #define V_ASN1_UTF8STRING 12 | ||
114 | #define V_ASN1_SEQUENCE 16 | ||
115 | #define V_ASN1_SET 17 | ||
116 | #define V_ASN1_NUMERICSTRING 18 /**/ | ||
117 | #define V_ASN1_PRINTABLESTRING 19 | ||
118 | #define V_ASN1_T61STRING 20 | ||
119 | #define V_ASN1_TELETEXSTRING 20 /* alias */ | ||
120 | #define V_ASN1_VIDEOTEXSTRING 21 /**/ | ||
121 | #define V_ASN1_IA5STRING 22 | ||
122 | #define V_ASN1_UTCTIME 23 | ||
123 | #define V_ASN1_GENERALIZEDTIME 24 /**/ | ||
124 | #define V_ASN1_GRAPHICSTRING 25 /**/ | ||
125 | #define V_ASN1_ISO64STRING 26 /**/ | ||
126 | #define V_ASN1_VISIBLESTRING 26 /* alias */ | ||
127 | #define V_ASN1_GENERALSTRING 27 /**/ | ||
128 | #define V_ASN1_UNIVERSALSTRING 28 /**/ | ||
129 | #define V_ASN1_BMPSTRING 30 | ||
130 | |||
131 | /* For use with d2i_ASN1_type_bytes() */ | ||
132 | #define B_ASN1_NUMERICSTRING 0x0001 | ||
133 | #define B_ASN1_PRINTABLESTRING 0x0002 | ||
134 | #define B_ASN1_T61STRING 0x0004 | ||
135 | #define B_ASN1_TELETEXSTRING 0x0004 | ||
136 | #define B_ASN1_VIDEOTEXSTRING 0x0008 | ||
137 | #define B_ASN1_IA5STRING 0x0010 | ||
138 | #define B_ASN1_GRAPHICSTRING 0x0020 | ||
139 | #define B_ASN1_ISO64STRING 0x0040 | ||
140 | #define B_ASN1_VISIBLESTRING 0x0040 | ||
141 | #define B_ASN1_GENERALSTRING 0x0080 | ||
142 | #define B_ASN1_UNIVERSALSTRING 0x0100 | ||
143 | #define B_ASN1_OCTET_STRING 0x0200 | ||
144 | #define B_ASN1_BIT_STRING 0x0400 | ||
145 | #define B_ASN1_BMPSTRING 0x0800 | ||
146 | #define B_ASN1_UNKNOWN 0x1000 | ||
147 | #define B_ASN1_UTF8STRING 0x2000 | ||
148 | #define B_ASN1_UTCTIME 0x4000 | ||
149 | #define B_ASN1_GENERALIZEDTIME 0x8000 | ||
150 | |||
151 | /* For use with ASN1_mbstring_copy() */ | ||
152 | #define MBSTRING_FLAG 0x1000 | ||
153 | #define MBSTRING_ASC (MBSTRING_FLAG|1) | ||
154 | #define MBSTRING_BMP (MBSTRING_FLAG|2) | ||
155 | #define MBSTRING_UNIV (MBSTRING_FLAG|3) | ||
156 | #define MBSTRING_UTF8 (MBSTRING_FLAG|4) | ||
157 | |||
158 | struct X509_algor_st; | ||
159 | |||
160 | #define DECLARE_ASN1_SET_OF(type) /* filled in by mkstack.pl */ | ||
161 | #define IMPLEMENT_ASN1_SET_OF(type) /* nothing, no longer needed */ | ||
162 | |||
163 | typedef struct asn1_ctx_st | ||
164 | { | ||
165 | unsigned char *p;/* work char pointer */ | ||
166 | int eos; /* end of sequence read for indefinite encoding */ | ||
167 | int error; /* error code to use when returning an error */ | ||
168 | int inf; /* constructed if 0x20, indefinite is 0x21 */ | ||
169 | int tag; /* tag from last 'get object' */ | ||
170 | int xclass; /* class from last 'get object' */ | ||
171 | long slen; /* length of last 'get object' */ | ||
172 | unsigned char *max; /* largest value of p allowed */ | ||
173 | unsigned char *q;/* temporary variable */ | ||
174 | unsigned char **pp;/* variable */ | ||
175 | int line; /* used in error processing */ | ||
176 | } ASN1_CTX; | ||
177 | |||
178 | /* These are used internally in the ASN1_OBJECT to keep track of | ||
179 | * whether the names and data need to be free()ed */ | ||
180 | #define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */ | ||
181 | #define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */ | ||
182 | #define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */ | ||
183 | #define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */ | ||
184 | typedef struct asn1_object_st | ||
185 | { | ||
186 | const char *sn,*ln; | ||
187 | int nid; | ||
188 | int length; | ||
189 | unsigned char *data; | ||
190 | int flags; /* Should we free this one */ | ||
191 | } ASN1_OBJECT; | ||
192 | |||
193 | #define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */ | ||
194 | /* This is the base type that holds just about everything :-) */ | ||
195 | typedef struct asn1_string_st | ||
196 | { | ||
197 | int length; | ||
198 | int type; | ||
199 | unsigned char *data; | ||
200 | /* The value of the following field depends on the type being | ||
201 | * held. It is mostly being used for BIT_STRING so if the | ||
202 | * input data has a non-zero 'unused bits' value, it will be | ||
203 | * handled correctly */ | ||
204 | long flags; | ||
205 | } ASN1_STRING; | ||
206 | |||
207 | /* ASN1_ENCODING structure: this is used to save the received | ||
208 | * encoding of an ASN1 type. This is useful to get round | ||
209 | * problems with invalid encodings which can break signatures. | ||
210 | */ | ||
211 | |||
212 | typedef struct ASN1_ENCODING_st | ||
213 | { | ||
214 | unsigned char *enc; /* DER encoding */ | ||
215 | long len; /* Length of encoding */ | ||
216 | int modified; /* set to 1 if 'enc' is invalid */ | ||
217 | } ASN1_ENCODING; | ||
218 | |||
219 | /* Used with ASN1 LONG type: if a long is set to this it is omitted */ | ||
220 | #define ASN1_LONG_UNDEF 0x7fffffffL | ||
221 | |||
222 | #define STABLE_FLAGS_MALLOC 0x01 | ||
223 | #define STABLE_NO_MASK 0x02 | ||
224 | #define DIRSTRING_TYPE \ | ||
225 | (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING) | ||
226 | #define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING) | ||
227 | |||
228 | typedef struct asn1_string_table_st { | ||
229 | int nid; | ||
230 | long minsize; | ||
231 | long maxsize; | ||
232 | unsigned long mask; | ||
233 | unsigned long flags; | ||
234 | } ASN1_STRING_TABLE; | ||
235 | |||
236 | DECLARE_STACK_OF(ASN1_STRING_TABLE) | ||
237 | |||
238 | /* size limits: this stuff is taken straight from RFC2459 */ | ||
239 | |||
240 | #define ub_name 32768 | ||
241 | #define ub_common_name 64 | ||
242 | #define ub_locality_name 128 | ||
243 | #define ub_state_name 128 | ||
244 | #define ub_organization_name 64 | ||
245 | #define ub_organization_unit_name 64 | ||
246 | #define ub_title 64 | ||
247 | #define ub_email_address 128 | ||
248 | |||
249 | /* Declarations for template structures: for full definitions | ||
250 | * see asn1t.h | ||
251 | */ | ||
252 | typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE; | ||
253 | typedef struct ASN1_ITEM_st ASN1_ITEM; | ||
254 | typedef struct ASN1_TLC_st ASN1_TLC; | ||
255 | /* This is just an opaque pointer */ | ||
256 | typedef struct ASN1_VALUE_st ASN1_VALUE; | ||
257 | |||
258 | /* Declare ASN1 functions: the implement macro in in asn1t.h */ | ||
259 | |||
260 | #define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type) | ||
261 | |||
262 | #define DECLARE_ASN1_FUNCTIONS_name(type, name) \ | ||
263 | type *name##_new(void); \ | ||
264 | void name##_free(type *a); \ | ||
265 | DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name) | ||
266 | |||
267 | #define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \ | ||
268 | type *name##_new(void); \ | ||
269 | void name##_free(type *a); \ | ||
270 | DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) | ||
271 | |||
272 | #define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \ | ||
273 | type *d2i_##name(type **a, unsigned char **in, long len); \ | ||
274 | int i2d_##name(type *a, unsigned char **out); \ | ||
275 | DECLARE_ASN1_ITEM(itname) | ||
276 | |||
277 | #define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \ | ||
278 | type *d2i_##name(type **a, const unsigned char **in, long len); \ | ||
279 | int i2d_##name(const type *a, unsigned char **out); \ | ||
280 | DECLARE_ASN1_ITEM(name) | ||
281 | |||
282 | #define DECLARE_ASN1_FUNCTIONS_const(name) \ | ||
283 | name *name##_new(void); \ | ||
284 | void name##_free(name *a); | ||
285 | |||
286 | |||
287 | /* The following macros and typedefs allow an ASN1_ITEM | ||
288 | * to be embedded in a structure and referenced. Since | ||
289 | * the ASN1_ITEM pointers need to be globally accessible | ||
290 | * (possibly from shared libraries) they may exist in | ||
291 | * different forms. On platforms that support it the | ||
292 | * ASN1_ITEM structure itself will be globally exported. | ||
293 | * Other platforms will export a function that returns | ||
294 | * an ASN1_ITEM pointer. | ||
295 | * | ||
296 | * To handle both cases transparently the macros below | ||
297 | * should be used instead of hard coding an ASN1_ITEM | ||
298 | * pointer in a structure. | ||
299 | * | ||
300 | * The structure will look like this: | ||
301 | * | ||
302 | * typedef struct SOMETHING_st { | ||
303 | * ... | ||
304 | * ASN1_ITEM_EXP *iptr; | ||
305 | * ... | ||
306 | * } SOMETHING; | ||
307 | * | ||
308 | * It would be initialised as e.g.: | ||
309 | * | ||
310 | * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...}; | ||
311 | * | ||
312 | * and the actual pointer extracted with: | ||
313 | * | ||
314 | * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr); | ||
315 | * | ||
316 | * Finally an ASN1_ITEM pointer can be extracted from an | ||
317 | * appropriate reference with: ASN1_ITEM_rptr(X509). This | ||
318 | * would be used when a function takes an ASN1_ITEM * argument. | ||
319 | * | ||
320 | */ | ||
321 | |||
322 | #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION | ||
323 | |||
324 | /* ASN1_ITEM pointer exported type */ | ||
325 | typedef const ASN1_ITEM ASN1_ITEM_EXP; | ||
326 | |||
327 | /* Macro to obtain ASN1_ITEM pointer from exported type */ | ||
328 | #define ASN1_ITEM_ptr(iptr) (iptr) | ||
329 | |||
330 | /* Macro to include ASN1_ITEM pointer from base type */ | ||
331 | #define ASN1_ITEM_ref(iptr) (&(iptr##_it)) | ||
332 | |||
333 | #define ASN1_ITEM_rptr(ref) (&(ref##_it)) | ||
334 | |||
335 | #define DECLARE_ASN1_ITEM(name) \ | ||
336 | OPENSSL_EXTERN const ASN1_ITEM name##_it; | ||
337 | |||
338 | #else | ||
339 | |||
340 | /* Platforms that can't easily handle shared global variables are declared | ||
341 | * as functions returning ASN1_ITEM pointers. | ||
342 | */ | ||
343 | |||
344 | /* ASN1_ITEM pointer exported type */ | ||
345 | typedef const ASN1_ITEM * ASN1_ITEM_EXP(void); | ||
346 | |||
347 | /* Macro to obtain ASN1_ITEM pointer from exported type */ | ||
348 | #define ASN1_ITEM_ptr(iptr) (iptr()) | ||
349 | |||
350 | /* Macro to include ASN1_ITEM pointer from base type */ | ||
351 | #define ASN1_ITEM_ref(iptr) (iptr##_it) | ||
352 | |||
353 | #define ASN1_ITEM_rptr(ref) (ref##_it()) | ||
354 | |||
355 | #define DECLARE_ASN1_ITEM(name) \ | ||
356 | const ASN1_ITEM * name##_it(void); | ||
357 | |||
358 | #endif | ||
359 | |||
360 | /* Parameters used by ASN1_STRING_print_ex() */ | ||
361 | |||
362 | /* These determine which characters to escape: | ||
363 | * RFC2253 special characters, control characters and | ||
364 | * MSB set characters | ||
365 | */ | ||
366 | |||
367 | #define ASN1_STRFLGS_ESC_2253 1 | ||
368 | #define ASN1_STRFLGS_ESC_CTRL 2 | ||
369 | #define ASN1_STRFLGS_ESC_MSB 4 | ||
370 | |||
371 | |||
372 | /* This flag determines how we do escaping: normally | ||
373 | * RC2253 backslash only, set this to use backslash and | ||
374 | * quote. | ||
375 | */ | ||
376 | |||
377 | #define ASN1_STRFLGS_ESC_QUOTE 8 | ||
378 | |||
379 | |||
380 | /* These three flags are internal use only. */ | ||
381 | |||
382 | /* Character is a valid PrintableString character */ | ||
383 | #define CHARTYPE_PRINTABLESTRING 0x10 | ||
384 | /* Character needs escaping if it is the first character */ | ||
385 | #define CHARTYPE_FIRST_ESC_2253 0x20 | ||
386 | /* Character needs escaping if it is the last character */ | ||
387 | #define CHARTYPE_LAST_ESC_2253 0x40 | ||
388 | |||
389 | /* NB the internal flags are safely reused below by flags | ||
390 | * handled at the top level. | ||
391 | */ | ||
392 | |||
393 | /* If this is set we convert all character strings | ||
394 | * to UTF8 first | ||
395 | */ | ||
396 | |||
397 | #define ASN1_STRFLGS_UTF8_CONVERT 0x10 | ||
398 | |||
399 | /* If this is set we don't attempt to interpret content: | ||
400 | * just assume all strings are 1 byte per character. This | ||
401 | * will produce some pretty odd looking output! | ||
402 | */ | ||
403 | |||
404 | #define ASN1_STRFLGS_IGNORE_TYPE 0x20 | ||
405 | |||
406 | /* If this is set we include the string type in the output */ | ||
407 | #define ASN1_STRFLGS_SHOW_TYPE 0x40 | ||
408 | |||
409 | /* This determines which strings to display and which to | ||
410 | * 'dump' (hex dump of content octets or DER encoding). We can | ||
411 | * only dump non character strings or everything. If we | ||
412 | * don't dump 'unknown' they are interpreted as character | ||
413 | * strings with 1 octet per character and are subject to | ||
414 | * the usual escaping options. | ||
415 | */ | ||
416 | |||
417 | #define ASN1_STRFLGS_DUMP_ALL 0x80 | ||
418 | #define ASN1_STRFLGS_DUMP_UNKNOWN 0x100 | ||
419 | |||
420 | /* These determine what 'dumping' does, we can dump the | ||
421 | * content octets or the DER encoding: both use the | ||
422 | * RFC2253 #XXXXX notation. | ||
423 | */ | ||
424 | |||
425 | #define ASN1_STRFLGS_DUMP_DER 0x200 | ||
426 | |||
427 | /* All the string flags consistent with RFC2253, | ||
428 | * escaping control characters isn't essential in | ||
429 | * RFC2253 but it is advisable anyway. | ||
430 | */ | ||
431 | |||
432 | #define ASN1_STRFLGS_RFC2253 (ASN1_STRFLGS_ESC_2253 | \ | ||
433 | ASN1_STRFLGS_ESC_CTRL | \ | ||
434 | ASN1_STRFLGS_ESC_MSB | \ | ||
435 | ASN1_STRFLGS_UTF8_CONVERT | \ | ||
436 | ASN1_STRFLGS_DUMP_UNKNOWN | \ | ||
437 | ASN1_STRFLGS_DUMP_DER) | ||
438 | |||
439 | DECLARE_STACK_OF(ASN1_INTEGER) | ||
440 | DECLARE_ASN1_SET_OF(ASN1_INTEGER) | ||
441 | |||
442 | DECLARE_STACK_OF(ASN1_GENERALSTRING) | ||
443 | |||
444 | typedef struct asn1_type_st | ||
445 | { | ||
446 | int type; | ||
447 | union { | ||
448 | char *ptr; | ||
449 | ASN1_BOOLEAN boolean; | ||
450 | ASN1_STRING * asn1_string; | ||
451 | ASN1_OBJECT * object; | ||
452 | ASN1_INTEGER * integer; | ||
453 | ASN1_ENUMERATED * enumerated; | ||
454 | ASN1_BIT_STRING * bit_string; | ||
455 | ASN1_OCTET_STRING * octet_string; | ||
456 | ASN1_PRINTABLESTRING * printablestring; | ||
457 | ASN1_T61STRING * t61string; | ||
458 | ASN1_IA5STRING * ia5string; | ||
459 | ASN1_GENERALSTRING * generalstring; | ||
460 | ASN1_BMPSTRING * bmpstring; | ||
461 | ASN1_UNIVERSALSTRING * universalstring; | ||
462 | ASN1_UTCTIME * utctime; | ||
463 | ASN1_GENERALIZEDTIME * generalizedtime; | ||
464 | ASN1_VISIBLESTRING * visiblestring; | ||
465 | ASN1_UTF8STRING * utf8string; | ||
466 | /* set and sequence are left complete and still | ||
467 | * contain the set or sequence bytes */ | ||
468 | ASN1_STRING * set; | ||
469 | ASN1_STRING * sequence; | ||
470 | } value; | ||
471 | } ASN1_TYPE; | ||
472 | |||
473 | DECLARE_STACK_OF(ASN1_TYPE) | ||
474 | DECLARE_ASN1_SET_OF(ASN1_TYPE) | ||
475 | |||
476 | typedef struct asn1_method_st | ||
477 | { | ||
478 | int (*i2d)(); | ||
479 | char *(*d2i)(); | ||
480 | char *(*create)(); | ||
481 | void (*destroy)(); | ||
482 | } ASN1_METHOD; | ||
483 | |||
484 | /* This is used when parsing some Netscape objects */ | ||
485 | typedef struct asn1_header_st | ||
486 | { | ||
487 | ASN1_OCTET_STRING *header; | ||
488 | char *data; | ||
489 | ASN1_METHOD *meth; | ||
490 | } ASN1_HEADER; | ||
491 | |||
492 | /* This is used to contain a list of bit names */ | ||
493 | typedef struct BIT_STRING_BITNAME_st { | ||
494 | int bitnum; | ||
495 | const char *lname; | ||
496 | const char *sname; | ||
497 | } BIT_STRING_BITNAME; | ||
498 | |||
499 | |||
500 | #define M_ASN1_STRING_length(x) ((x)->length) | ||
501 | #define M_ASN1_STRING_length_set(x, n) ((x)->length = (n)) | ||
502 | #define M_ASN1_STRING_type(x) ((x)->type) | ||
503 | #define M_ASN1_STRING_data(x) ((x)->data) | ||
504 | |||
505 | /* Macros for string operations */ | ||
506 | #define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\ | ||
507 | ASN1_STRING_type_new(V_ASN1_BIT_STRING) | ||
508 | #define M_ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
509 | #define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\ | ||
510 | ASN1_STRING_dup((ASN1_STRING *)a) | ||
511 | #define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\ | ||
512 | (ASN1_STRING *)a,(ASN1_STRING *)b) | ||
513 | #define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c) | ||
514 | |||
515 | #define M_ASN1_INTEGER_new() (ASN1_INTEGER *)\ | ||
516 | ASN1_STRING_type_new(V_ASN1_INTEGER) | ||
517 | #define M_ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
518 | #define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)ASN1_STRING_dup((ASN1_STRING *)a) | ||
519 | #define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\ | ||
520 | (ASN1_STRING *)a,(ASN1_STRING *)b) | ||
521 | |||
522 | #define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\ | ||
523 | ASN1_STRING_type_new(V_ASN1_ENUMERATED) | ||
524 | #define M_ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
525 | #define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)ASN1_STRING_dup((ASN1_STRING *)a) | ||
526 | #define M_ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\ | ||
527 | (ASN1_STRING *)a,(ASN1_STRING *)b) | ||
528 | |||
529 | #define M_ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\ | ||
530 | ASN1_STRING_type_new(V_ASN1_OCTET_STRING) | ||
531 | #define M_ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
532 | #define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\ | ||
533 | ASN1_STRING_dup((ASN1_STRING *)a) | ||
534 | #define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\ | ||
535 | (ASN1_STRING *)a,(ASN1_STRING *)b) | ||
536 | #define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c) | ||
537 | #define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b) | ||
538 | #define M_i2d_ASN1_OCTET_STRING(a,pp) \ | ||
539 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_OCTET_STRING,\ | ||
540 | V_ASN1_UNIVERSAL) | ||
541 | |||
542 | #define B_ASN1_TIME \ | ||
543 | B_ASN1_UTCTIME | \ | ||
544 | B_ASN1_GENERALIZEDTIME | ||
545 | |||
546 | #define B_ASN1_PRINTABLE \ | ||
547 | B_ASN1_PRINTABLESTRING| \ | ||
548 | B_ASN1_T61STRING| \ | ||
549 | B_ASN1_IA5STRING| \ | ||
550 | B_ASN1_BIT_STRING| \ | ||
551 | B_ASN1_UNIVERSALSTRING|\ | ||
552 | B_ASN1_BMPSTRING|\ | ||
553 | B_ASN1_UTF8STRING|\ | ||
554 | B_ASN1_UNKNOWN | ||
555 | |||
556 | #define B_ASN1_DIRECTORYSTRING \ | ||
557 | B_ASN1_PRINTABLESTRING| \ | ||
558 | B_ASN1_TELETEXSTRING|\ | ||
559 | B_ASN1_BMPSTRING|\ | ||
560 | B_ASN1_UNIVERSALSTRING|\ | ||
561 | B_ASN1_UTF8STRING | ||
562 | |||
563 | #define B_ASN1_DISPLAYTEXT \ | ||
564 | B_ASN1_IA5STRING| \ | ||
565 | B_ASN1_VISIBLESTRING| \ | ||
566 | B_ASN1_BMPSTRING|\ | ||
567 | B_ASN1_UTF8STRING | ||
568 | |||
569 | #define M_ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING) | ||
570 | #define M_ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
571 | #define M_i2d_ASN1_PRINTABLE(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\ | ||
572 | pp,a->type,V_ASN1_UNIVERSAL) | ||
573 | #define M_d2i_ASN1_PRINTABLE(a,pp,l) \ | ||
574 | d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \ | ||
575 | B_ASN1_PRINTABLE) | ||
576 | |||
577 | #define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING) | ||
578 | #define M_DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
579 | #define M_i2d_DIRECTORYSTRING(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\ | ||
580 | pp,a->type,V_ASN1_UNIVERSAL) | ||
581 | #define M_d2i_DIRECTORYSTRING(a,pp,l) \ | ||
582 | d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \ | ||
583 | B_ASN1_DIRECTORYSTRING) | ||
584 | |||
585 | #define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING) | ||
586 | #define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
587 | #define M_i2d_DISPLAYTEXT(a,pp) i2d_ASN1_bytes((ASN1_STRING *)a,\ | ||
588 | pp,a->type,V_ASN1_UNIVERSAL) | ||
589 | #define M_d2i_DISPLAYTEXT(a,pp,l) \ | ||
590 | d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l, \ | ||
591 | B_ASN1_DISPLAYTEXT) | ||
592 | |||
593 | #define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\ | ||
594 | ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING) | ||
595 | #define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
596 | #define M_i2d_ASN1_PRINTABLESTRING(a,pp) \ | ||
597 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_PRINTABLESTRING,\ | ||
598 | V_ASN1_UNIVERSAL) | ||
599 | #define M_d2i_ASN1_PRINTABLESTRING(a,pp,l) \ | ||
600 | (ASN1_PRINTABLESTRING *)d2i_ASN1_type_bytes\ | ||
601 | ((ASN1_STRING **)a,pp,l,B_ASN1_PRINTABLESTRING) | ||
602 | |||
603 | #define M_ASN1_T61STRING_new() (ASN1_T61STRING *)\ | ||
604 | ASN1_STRING_type_new(V_ASN1_T61STRING) | ||
605 | #define M_ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
606 | #define M_i2d_ASN1_T61STRING(a,pp) \ | ||
607 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_T61STRING,\ | ||
608 | V_ASN1_UNIVERSAL) | ||
609 | #define M_d2i_ASN1_T61STRING(a,pp,l) \ | ||
610 | (ASN1_T61STRING *)d2i_ASN1_type_bytes\ | ||
611 | ((ASN1_STRING **)a,pp,l,B_ASN1_T61STRING) | ||
612 | |||
613 | #define M_ASN1_IA5STRING_new() (ASN1_IA5STRING *)\ | ||
614 | ASN1_STRING_type_new(V_ASN1_IA5STRING) | ||
615 | #define M_ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
616 | #define M_ASN1_IA5STRING_dup(a) \ | ||
617 | (ASN1_IA5STRING *)ASN1_STRING_dup((ASN1_STRING *)a) | ||
618 | #define M_i2d_ASN1_IA5STRING(a,pp) \ | ||
619 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_IA5STRING,\ | ||
620 | V_ASN1_UNIVERSAL) | ||
621 | #define M_d2i_ASN1_IA5STRING(a,pp,l) \ | ||
622 | (ASN1_IA5STRING *)d2i_ASN1_type_bytes((ASN1_STRING **)a,pp,l,\ | ||
623 | B_ASN1_IA5STRING) | ||
624 | |||
625 | #define M_ASN1_UTCTIME_new() (ASN1_UTCTIME *)\ | ||
626 | ASN1_STRING_type_new(V_ASN1_UTCTIME) | ||
627 | #define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
628 | #define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)ASN1_STRING_dup((ASN1_STRING *)a) | ||
629 | |||
630 | #define M_ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\ | ||
631 | ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME) | ||
632 | #define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
633 | #define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\ | ||
634 | (ASN1_STRING *)a) | ||
635 | |||
636 | #define M_ASN1_TIME_new() (ASN1_TIME *)\ | ||
637 | ASN1_STRING_type_new(V_ASN1_UTCTIME) | ||
638 | #define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
639 | #define M_ASN1_TIME_dup(a) (ASN1_TIME *)ASN1_STRING_dup((ASN1_STRING *)a) | ||
640 | |||
641 | #define M_ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\ | ||
642 | ASN1_STRING_type_new(V_ASN1_GENERALSTRING) | ||
643 | #define M_ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
644 | #define M_i2d_ASN1_GENERALSTRING(a,pp) \ | ||
645 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_GENERALSTRING,\ | ||
646 | V_ASN1_UNIVERSAL) | ||
647 | #define M_d2i_ASN1_GENERALSTRING(a,pp,l) \ | ||
648 | (ASN1_GENERALSTRING *)d2i_ASN1_type_bytes\ | ||
649 | ((ASN1_STRING **)a,pp,l,B_ASN1_GENERALSTRING) | ||
650 | |||
651 | #define M_ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\ | ||
652 | ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING) | ||
653 | #define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
654 | #define M_i2d_ASN1_UNIVERSALSTRING(a,pp) \ | ||
655 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UNIVERSALSTRING,\ | ||
656 | V_ASN1_UNIVERSAL) | ||
657 | #define M_d2i_ASN1_UNIVERSALSTRING(a,pp,l) \ | ||
658 | (ASN1_UNIVERSALSTRING *)d2i_ASN1_type_bytes\ | ||
659 | ((ASN1_STRING **)a,pp,l,B_ASN1_UNIVERSALSTRING) | ||
660 | |||
661 | #define M_ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\ | ||
662 | ASN1_STRING_type_new(V_ASN1_BMPSTRING) | ||
663 | #define M_ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
664 | #define M_i2d_ASN1_BMPSTRING(a,pp) \ | ||
665 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_BMPSTRING,\ | ||
666 | V_ASN1_UNIVERSAL) | ||
667 | #define M_d2i_ASN1_BMPSTRING(a,pp,l) \ | ||
668 | (ASN1_BMPSTRING *)d2i_ASN1_type_bytes\ | ||
669 | ((ASN1_STRING **)a,pp,l,B_ASN1_BMPSTRING) | ||
670 | |||
671 | #define M_ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\ | ||
672 | ASN1_STRING_type_new(V_ASN1_VISIBLESTRING) | ||
673 | #define M_ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
674 | #define M_i2d_ASN1_VISIBLESTRING(a,pp) \ | ||
675 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_VISIBLESTRING,\ | ||
676 | V_ASN1_UNIVERSAL) | ||
677 | #define M_d2i_ASN1_VISIBLESTRING(a,pp,l) \ | ||
678 | (ASN1_VISIBLESTRING *)d2i_ASN1_type_bytes\ | ||
679 | ((ASN1_STRING **)a,pp,l,B_ASN1_VISIBLESTRING) | ||
680 | |||
681 | #define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\ | ||
682 | ASN1_STRING_type_new(V_ASN1_UTF8STRING) | ||
683 | #define M_ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a) | ||
684 | #define M_i2d_ASN1_UTF8STRING(a,pp) \ | ||
685 | i2d_ASN1_bytes((ASN1_STRING *)a,pp,V_ASN1_UTF8STRING,\ | ||
686 | V_ASN1_UNIVERSAL) | ||
687 | #define M_d2i_ASN1_UTF8STRING(a,pp,l) \ | ||
688 | (ASN1_UTF8STRING *)d2i_ASN1_type_bytes\ | ||
689 | ((ASN1_STRING **)a,pp,l,B_ASN1_UTF8STRING) | ||
690 | |||
691 | /* for the is_set parameter to i2d_ASN1_SET */ | ||
692 | #define IS_SEQUENCE 0 | ||
693 | #define IS_SET 1 | ||
694 | |||
695 | DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) | ||
696 | |||
697 | int ASN1_TYPE_get(ASN1_TYPE *a); | ||
698 | void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value); | ||
699 | |||
700 | ASN1_OBJECT * ASN1_OBJECT_new(void ); | ||
701 | void ASN1_OBJECT_free(ASN1_OBJECT *a); | ||
702 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp); | ||
703 | ASN1_OBJECT * c2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp, | ||
704 | long length); | ||
705 | ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp, | ||
706 | long length); | ||
707 | |||
708 | DECLARE_ASN1_ITEM(ASN1_OBJECT) | ||
709 | |||
710 | DECLARE_STACK_OF(ASN1_OBJECT) | ||
711 | DECLARE_ASN1_SET_OF(ASN1_OBJECT) | ||
712 | |||
713 | ASN1_STRING * ASN1_STRING_new(void); | ||
714 | void ASN1_STRING_free(ASN1_STRING *a); | ||
715 | ASN1_STRING * ASN1_STRING_dup(ASN1_STRING *a); | ||
716 | ASN1_STRING * ASN1_STRING_type_new(int type ); | ||
717 | int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b); | ||
718 | /* Since this is used to store all sorts of things, via macros, for now, make | ||
719 | its data void * */ | ||
720 | int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len); | ||
721 | int ASN1_STRING_length(ASN1_STRING *x); | ||
722 | void ASN1_STRING_length_set(ASN1_STRING *x, int n); | ||
723 | int ASN1_STRING_type(ASN1_STRING *x); | ||
724 | unsigned char * ASN1_STRING_data(ASN1_STRING *x); | ||
725 | |||
726 | DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING) | ||
727 | int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp); | ||
728 | ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp, | ||
729 | long length); | ||
730 | int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d, | ||
731 | int length ); | ||
732 | int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value); | ||
733 | int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n); | ||
734 | |||
735 | #ifndef OPENSSL_NO_BIO | ||
736 | int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs, | ||
737 | BIT_STRING_BITNAME *tbl, int indent); | ||
738 | #endif | ||
739 | int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl); | ||
740 | int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value, | ||
741 | BIT_STRING_BITNAME *tbl); | ||
742 | |||
743 | int i2d_ASN1_BOOLEAN(int a,unsigned char **pp); | ||
744 | int d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length); | ||
745 | |||
746 | DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER) | ||
747 | int i2c_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp); | ||
748 | ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp, | ||
749 | long length); | ||
750 | ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,unsigned char **pp, | ||
751 | long length); | ||
752 | ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x); | ||
753 | int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y); | ||
754 | |||
755 | DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED) | ||
756 | |||
757 | int ASN1_UTCTIME_check(ASN1_UTCTIME *a); | ||
758 | ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t); | ||
759 | int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str); | ||
760 | int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t); | ||
761 | #if 0 | ||
762 | time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s); | ||
763 | #endif | ||
764 | |||
765 | int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a); | ||
766 | ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t); | ||
767 | int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str); | ||
768 | |||
769 | DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING) | ||
770 | ASN1_OCTET_STRING * ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *a); | ||
771 | int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b); | ||
772 | int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, unsigned char *data, int len); | ||
773 | |||
774 | DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING) | ||
775 | DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING) | ||
776 | DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING) | ||
777 | DECLARE_ASN1_FUNCTIONS(ASN1_NULL) | ||
778 | DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING) | ||
779 | |||
780 | int UTF8_getc(const unsigned char *str, int len, unsigned long *val); | ||
781 | int UTF8_putc(unsigned char *str, int len, unsigned long value); | ||
782 | |||
783 | DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE) | ||
784 | |||
785 | DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING) | ||
786 | DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT) | ||
787 | DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING) | ||
788 | DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING) | ||
789 | DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING) | ||
790 | DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING) | ||
791 | DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME) | ||
792 | DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME) | ||
793 | DECLARE_ASN1_FUNCTIONS(ASN1_TIME) | ||
794 | |||
795 | ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t); | ||
796 | int ASN1_TIME_check(ASN1_TIME *t); | ||
797 | ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out); | ||
798 | |||
799 | int i2d_ASN1_SET(STACK *a, unsigned char **pp, | ||
800 | int (*func)(), int ex_tag, int ex_class, int is_set); | ||
801 | STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length, | ||
802 | char *(*func)(), void (*free_func)(void *), | ||
803 | int ex_tag, int ex_class); | ||
804 | |||
805 | #ifndef OPENSSL_NO_BIO | ||
806 | int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a); | ||
807 | int a2i_ASN1_INTEGER(BIO *bp,ASN1_INTEGER *bs,char *buf,int size); | ||
808 | int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a); | ||
809 | int a2i_ASN1_ENUMERATED(BIO *bp,ASN1_ENUMERATED *bs,char *buf,int size); | ||
810 | int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a); | ||
811 | int a2i_ASN1_STRING(BIO *bp,ASN1_STRING *bs,char *buf,int size); | ||
812 | int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type); | ||
813 | #endif | ||
814 | int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a); | ||
815 | |||
816 | int a2d_ASN1_OBJECT(unsigned char *out,int olen, const char *buf, int num); | ||
817 | ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len, | ||
818 | const char *sn, const char *ln); | ||
819 | |||
820 | int ASN1_INTEGER_set(ASN1_INTEGER *a, long v); | ||
821 | long ASN1_INTEGER_get(ASN1_INTEGER *a); | ||
822 | ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai); | ||
823 | BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai,BIGNUM *bn); | ||
824 | |||
825 | int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v); | ||
826 | long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a); | ||
827 | ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai); | ||
828 | BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn); | ||
829 | |||
830 | /* General */ | ||
831 | /* given a string, return the correct type, max is the maximum length */ | ||
832 | int ASN1_PRINTABLE_type(unsigned char *s, int max); | ||
833 | |||
834 | int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass); | ||
835 | ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, | ||
836 | long length, int Ptag, int Pclass); | ||
837 | unsigned long ASN1_tag2bit(int tag); | ||
838 | /* type is one or more of the B_ASN1_ values. */ | ||
839 | ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,unsigned char **pp, | ||
840 | long length,int type); | ||
841 | |||
842 | /* PARSING */ | ||
843 | int asn1_Finish(ASN1_CTX *c); | ||
844 | |||
845 | /* SPECIALS */ | ||
846 | int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, | ||
847 | int *pclass, long omax); | ||
848 | int ASN1_check_infinite_end(unsigned char **p,long len); | ||
849 | void ASN1_put_object(unsigned char **pp, int constructed, int length, | ||
850 | int tag, int xclass); | ||
851 | int ASN1_object_size(int constructed, int length, int tag); | ||
852 | |||
853 | /* Used to implement other functions */ | ||
854 | char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x); | ||
855 | |||
856 | void *ASN1_item_dup(const ASN1_ITEM *it, void *x); | ||
857 | |||
858 | #ifndef OPENSSL_NO_FP_API | ||
859 | char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x); | ||
860 | void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x); | ||
861 | int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x); | ||
862 | int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x); | ||
863 | int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags); | ||
864 | #endif | ||
865 | |||
866 | int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in); | ||
867 | |||
868 | #ifndef OPENSSL_NO_BIO | ||
869 | char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x); | ||
870 | void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x); | ||
871 | int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x); | ||
872 | int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x); | ||
873 | int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a); | ||
874 | int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a); | ||
875 | int ASN1_TIME_print(BIO *fp,ASN1_TIME *a); | ||
876 | int ASN1_STRING_print(BIO *bp,ASN1_STRING *v); | ||
877 | int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags); | ||
878 | int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent); | ||
879 | int ASN1_parse_dump(BIO *bp,unsigned char *pp,long len,int indent,int dump); | ||
880 | #endif | ||
881 | const char *ASN1_tag2str(int tag); | ||
882 | |||
883 | /* Used to load and write netscape format cert/key */ | ||
884 | int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp); | ||
885 | ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,unsigned char **pp, long length); | ||
886 | ASN1_HEADER *ASN1_HEADER_new(void ); | ||
887 | void ASN1_HEADER_free(ASN1_HEADER *a); | ||
888 | |||
889 | int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s); | ||
890 | |||
891 | /* Not used that much at this point, except for the first two */ | ||
892 | ASN1_METHOD *X509_asn1_meth(void); | ||
893 | ASN1_METHOD *RSAPrivateKey_asn1_meth(void); | ||
894 | ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void); | ||
895 | ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void); | ||
896 | |||
897 | int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, | ||
898 | unsigned char *data, int len); | ||
899 | int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, | ||
900 | unsigned char *data, int max_len); | ||
901 | int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, | ||
902 | unsigned char *data, int len); | ||
903 | int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num, | ||
904 | unsigned char *data, int max_len); | ||
905 | |||
906 | STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(), | ||
907 | void (*free_func)(void *) ); | ||
908 | unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf, | ||
909 | int *len ); | ||
910 | void *ASN1_unpack_string(ASN1_STRING *oct, char *(*d2i)()); | ||
911 | void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it); | ||
912 | ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct); | ||
913 | ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct); | ||
914 | |||
915 | void ASN1_STRING_set_default_mask(unsigned long mask); | ||
916 | int ASN1_STRING_set_default_mask_asc(char *p); | ||
917 | unsigned long ASN1_STRING_get_default_mask(void); | ||
918 | int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len, | ||
919 | int inform, unsigned long mask); | ||
920 | int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, | ||
921 | int inform, unsigned long mask, | ||
922 | long minsize, long maxsize); | ||
923 | |||
924 | ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, | ||
925 | const unsigned char *in, int inlen, int inform, int nid); | ||
926 | ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid); | ||
927 | int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long); | ||
928 | void ASN1_STRING_TABLE_cleanup(void); | ||
929 | |||
930 | /* ASN1 template functions */ | ||
931 | |||
932 | /* Old API compatible functions */ | ||
933 | ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it); | ||
934 | void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it); | ||
935 | ASN1_VALUE * ASN1_item_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it); | ||
936 | int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it); | ||
937 | |||
938 | void ASN1_add_oid_module(void); | ||
939 | |||
940 | /* BEGIN ERROR CODES */ | ||
941 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
942 | * made after this point may be overwritten when the script is next run. | ||
943 | */ | ||
944 | void ERR_load_ASN1_strings(void); | ||
945 | |||
946 | /* Error codes for the ASN1 functions. */ | ||
947 | |||
948 | /* Function codes. */ | ||
949 | #define ASN1_F_A2D_ASN1_OBJECT 100 | ||
950 | #define ASN1_F_A2I_ASN1_ENUMERATED 101 | ||
951 | #define ASN1_F_A2I_ASN1_INTEGER 102 | ||
952 | #define ASN1_F_A2I_ASN1_STRING 103 | ||
953 | #define ASN1_F_ASN1_CHECK_TLEN 104 | ||
954 | #define ASN1_F_ASN1_COLLATE_PRIMITIVE 105 | ||
955 | #define ASN1_F_ASN1_COLLECT 106 | ||
956 | #define ASN1_F_ASN1_D2I_BIO 107 | ||
957 | #define ASN1_F_ASN1_D2I_EX_PRIMITIVE 108 | ||
958 | #define ASN1_F_ASN1_D2I_FP 109 | ||
959 | #define ASN1_F_ASN1_DO_ADB 110 | ||
960 | #define ASN1_F_ASN1_DUP 111 | ||
961 | #define ASN1_F_ASN1_ENUMERATED_SET 112 | ||
962 | #define ASN1_F_ASN1_ENUMERATED_TO_BN 113 | ||
963 | #define ASN1_F_ASN1_GET_OBJECT 114 | ||
964 | #define ASN1_F_ASN1_HEADER_NEW 115 | ||
965 | #define ASN1_F_ASN1_I2D_BIO 116 | ||
966 | #define ASN1_F_ASN1_I2D_FP 117 | ||
967 | #define ASN1_F_ASN1_INTEGER_SET 118 | ||
968 | #define ASN1_F_ASN1_INTEGER_TO_BN 119 | ||
969 | #define ASN1_F_ASN1_ITEM_EX_D2I 120 | ||
970 | #define ASN1_F_ASN1_ITEM_NEW 121 | ||
971 | #define ASN1_F_ASN1_MBSTRING_COPY 122 | ||
972 | #define ASN1_F_ASN1_OBJECT_NEW 123 | ||
973 | #define ASN1_F_ASN1_PACK_STRING 124 | ||
974 | #define ASN1_F_ASN1_PBE_SET 125 | ||
975 | #define ASN1_F_ASN1_SEQ_PACK 126 | ||
976 | #define ASN1_F_ASN1_SEQ_UNPACK 127 | ||
977 | #define ASN1_F_ASN1_SIGN 128 | ||
978 | #define ASN1_F_ASN1_STRING_TABLE_ADD 129 | ||
979 | #define ASN1_F_ASN1_STRING_TYPE_NEW 130 | ||
980 | #define ASN1_F_ASN1_TEMPLATE_D2I 131 | ||
981 | #define ASN1_F_ASN1_TEMPLATE_EX_D2I 132 | ||
982 | #define ASN1_F_ASN1_TEMPLATE_NEW 133 | ||
983 | #define ASN1_F_ASN1_TIME_SET 175 | ||
984 | #define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 134 | ||
985 | #define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 135 | ||
986 | #define ASN1_F_ASN1_UNPACK_STRING 136 | ||
987 | #define ASN1_F_ASN1_VERIFY 137 | ||
988 | #define ASN1_F_BN_TO_ASN1_ENUMERATED 138 | ||
989 | #define ASN1_F_BN_TO_ASN1_INTEGER 139 | ||
990 | #define ASN1_F_COLLECT_DATA 140 | ||
991 | #define ASN1_F_D2I_ASN1_BIT_STRING 141 | ||
992 | #define ASN1_F_D2I_ASN1_BOOLEAN 142 | ||
993 | #define ASN1_F_D2I_ASN1_BYTES 143 | ||
994 | #define ASN1_F_D2I_ASN1_GENERALIZEDTIME 144 | ||
995 | #define ASN1_F_D2I_ASN1_HEADER 145 | ||
996 | #define ASN1_F_D2I_ASN1_INTEGER 146 | ||
997 | #define ASN1_F_D2I_ASN1_OBJECT 147 | ||
998 | #define ASN1_F_D2I_ASN1_SET 148 | ||
999 | #define ASN1_F_D2I_ASN1_TYPE_BYTES 149 | ||
1000 | #define ASN1_F_D2I_ASN1_UINTEGER 150 | ||
1001 | #define ASN1_F_D2I_ASN1_UTCTIME 151 | ||
1002 | #define ASN1_F_D2I_NETSCAPE_RSA 152 | ||
1003 | #define ASN1_F_D2I_NETSCAPE_RSA_2 153 | ||
1004 | #define ASN1_F_D2I_PRIVATEKEY 154 | ||
1005 | #define ASN1_F_D2I_PUBLICKEY 155 | ||
1006 | #define ASN1_F_D2I_X509 156 | ||
1007 | #define ASN1_F_D2I_X509_CINF 157 | ||
1008 | #define ASN1_F_D2I_X509_NAME 158 | ||
1009 | #define ASN1_F_D2I_X509_PKEY 159 | ||
1010 | #define ASN1_F_I2D_ASN1_TIME 160 | ||
1011 | #define ASN1_F_I2D_DSA_PUBKEY 161 | ||
1012 | #define ASN1_F_I2D_NETSCAPE_RSA 162 | ||
1013 | #define ASN1_F_I2D_PRIVATEKEY 163 | ||
1014 | #define ASN1_F_I2D_PUBLICKEY 164 | ||
1015 | #define ASN1_F_I2D_RSA_PUBKEY 165 | ||
1016 | #define ASN1_F_LONG_C2I 166 | ||
1017 | #define ASN1_F_OID_MODULE_INIT 174 | ||
1018 | #define ASN1_F_PKCS5_PBE2_SET 167 | ||
1019 | #define ASN1_F_X509_CINF_NEW 168 | ||
1020 | #define ASN1_F_X509_CRL_ADD0_REVOKED 169 | ||
1021 | #define ASN1_F_X509_INFO_NEW 170 | ||
1022 | #define ASN1_F_X509_NAME_NEW 171 | ||
1023 | #define ASN1_F_X509_NEW 172 | ||
1024 | #define ASN1_F_X509_PKEY_NEW 173 | ||
1025 | |||
1026 | /* Reason codes. */ | ||
1027 | #define ASN1_R_ADDING_OBJECT 171 | ||
1028 | #define ASN1_R_AUX_ERROR 100 | ||
1029 | #define ASN1_R_BAD_CLASS 101 | ||
1030 | #define ASN1_R_BAD_OBJECT_HEADER 102 | ||
1031 | #define ASN1_R_BAD_PASSWORD_READ 103 | ||
1032 | #define ASN1_R_BAD_TAG 104 | ||
1033 | #define ASN1_R_BN_LIB 105 | ||
1034 | #define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 106 | ||
1035 | #define ASN1_R_BUFFER_TOO_SMALL 107 | ||
1036 | #define ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER 108 | ||
1037 | #define ASN1_R_DATA_IS_WRONG 109 | ||
1038 | #define ASN1_R_DECODE_ERROR 110 | ||
1039 | #define ASN1_R_DECODING_ERROR 111 | ||
1040 | #define ASN1_R_ENCODE_ERROR 112 | ||
1041 | #define ASN1_R_ERROR_GETTING_TIME 173 | ||
1042 | #define ASN1_R_ERROR_LOADING_SECTION 172 | ||
1043 | #define ASN1_R_ERROR_PARSING_SET_ELEMENT 113 | ||
1044 | #define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 114 | ||
1045 | #define ASN1_R_EXPECTING_AN_INTEGER 115 | ||
1046 | #define ASN1_R_EXPECTING_AN_OBJECT 116 | ||
1047 | #define ASN1_R_EXPECTING_A_BOOLEAN 117 | ||
1048 | #define ASN1_R_EXPECTING_A_TIME 118 | ||
1049 | #define ASN1_R_EXPLICIT_LENGTH_MISMATCH 119 | ||
1050 | #define ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED 120 | ||
1051 | #define ASN1_R_FIELD_MISSING 121 | ||
1052 | #define ASN1_R_FIRST_NUM_TOO_LARGE 122 | ||
1053 | #define ASN1_R_HEADER_TOO_LONG 123 | ||
1054 | #define ASN1_R_ILLEGAL_CHARACTERS 124 | ||
1055 | #define ASN1_R_ILLEGAL_NULL 125 | ||
1056 | #define ASN1_R_ILLEGAL_OPTIONAL_ANY 126 | ||
1057 | #define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE 170 | ||
1058 | #define ASN1_R_ILLEGAL_TAGGED_ANY 127 | ||
1059 | #define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 128 | ||
1060 | #define ASN1_R_INVALID_BMPSTRING_LENGTH 129 | ||
1061 | #define ASN1_R_INVALID_DIGIT 130 | ||
1062 | #define ASN1_R_INVALID_SEPARATOR 131 | ||
1063 | #define ASN1_R_INVALID_TIME_FORMAT 132 | ||
1064 | #define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 133 | ||
1065 | #define ASN1_R_INVALID_UTF8STRING 134 | ||
1066 | #define ASN1_R_IV_TOO_LARGE 135 | ||
1067 | #define ASN1_R_LENGTH_ERROR 136 | ||
1068 | #define ASN1_R_MISSING_EOC 137 | ||
1069 | #define ASN1_R_MISSING_SECOND_NUMBER 138 | ||
1070 | #define ASN1_R_MSTRING_NOT_UNIVERSAL 139 | ||
1071 | #define ASN1_R_MSTRING_WRONG_TAG 140 | ||
1072 | #define ASN1_R_NON_HEX_CHARACTERS 141 | ||
1073 | #define ASN1_R_NOT_ENOUGH_DATA 142 | ||
1074 | #define ASN1_R_NO_MATCHING_CHOICE_TYPE 143 | ||
1075 | #define ASN1_R_NULL_IS_WRONG_LENGTH 144 | ||
1076 | #define ASN1_R_ODD_NUMBER_OF_CHARS 145 | ||
1077 | #define ASN1_R_PRIVATE_KEY_HEADER_MISSING 146 | ||
1078 | #define ASN1_R_SECOND_NUMBER_TOO_LARGE 147 | ||
1079 | #define ASN1_R_SEQUENCE_LENGTH_MISMATCH 148 | ||
1080 | #define ASN1_R_SEQUENCE_NOT_CONSTRUCTED 149 | ||
1081 | #define ASN1_R_SHORT_LINE 150 | ||
1082 | #define ASN1_R_STRING_TOO_LONG 151 | ||
1083 | #define ASN1_R_STRING_TOO_SHORT 152 | ||
1084 | #define ASN1_R_TAG_VALUE_TOO_HIGH 153 | ||
1085 | #define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 154 | ||
1086 | #define ASN1_R_TOO_LONG 155 | ||
1087 | #define ASN1_R_TYPE_NOT_CONSTRUCTED 156 | ||
1088 | #define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 157 | ||
1089 | #define ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY 158 | ||
1090 | #define ASN1_R_UNEXPECTED_EOC 159 | ||
1091 | #define ASN1_R_UNKNOWN_FORMAT 160 | ||
1092 | #define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 161 | ||
1093 | #define ASN1_R_UNKNOWN_OBJECT_TYPE 162 | ||
1094 | #define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 163 | ||
1095 | #define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE 164 | ||
1096 | #define ASN1_R_UNSUPPORTED_CIPHER 165 | ||
1097 | #define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 166 | ||
1098 | #define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 167 | ||
1099 | #define ASN1_R_WRONG_TAG 168 | ||
1100 | #define ASN1_R_WRONG_TYPE 169 | ||
1101 | |||
1102 | #ifdef __cplusplus | ||
1103 | } | ||
1104 | #endif | ||
1105 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/asn1_err.c b/src/lib/libcrypto/asn1/asn1_err.c deleted file mode 100644 index 094ec06fda..0000000000 --- a/src/lib/libcrypto/asn1/asn1_err.c +++ /dev/null | |||
@@ -1,242 +0,0 @@ | |||
1 | /* crypto/asn1/asn1_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include <openssl/asn1.h> | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef OPENSSL_NO_ERR | ||
67 | static ERR_STRING_DATA ASN1_str_functs[]= | ||
68 | { | ||
69 | {ERR_PACK(0,ASN1_F_A2D_ASN1_OBJECT,0), "a2d_ASN1_OBJECT"}, | ||
70 | {ERR_PACK(0,ASN1_F_A2I_ASN1_ENUMERATED,0), "a2i_ASN1_ENUMERATED"}, | ||
71 | {ERR_PACK(0,ASN1_F_A2I_ASN1_INTEGER,0), "a2i_ASN1_INTEGER"}, | ||
72 | {ERR_PACK(0,ASN1_F_A2I_ASN1_STRING,0), "a2i_ASN1_STRING"}, | ||
73 | {ERR_PACK(0,ASN1_F_ASN1_CHECK_TLEN,0), "ASN1_CHECK_TLEN"}, | ||
74 | {ERR_PACK(0,ASN1_F_ASN1_COLLATE_PRIMITIVE,0), "ASN1_COLLATE_PRIMITIVE"}, | ||
75 | {ERR_PACK(0,ASN1_F_ASN1_COLLECT,0), "ASN1_COLLECT"}, | ||
76 | {ERR_PACK(0,ASN1_F_ASN1_D2I_BIO,0), "ASN1_d2i_bio"}, | ||
77 | {ERR_PACK(0,ASN1_F_ASN1_D2I_EX_PRIMITIVE,0), "ASN1_D2I_EX_PRIMITIVE"}, | ||
78 | {ERR_PACK(0,ASN1_F_ASN1_D2I_FP,0), "ASN1_d2i_fp"}, | ||
79 | {ERR_PACK(0,ASN1_F_ASN1_DO_ADB,0), "ASN1_DO_ADB"}, | ||
80 | {ERR_PACK(0,ASN1_F_ASN1_DUP,0), "ASN1_dup"}, | ||
81 | {ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_SET,0), "ASN1_ENUMERATED_set"}, | ||
82 | {ERR_PACK(0,ASN1_F_ASN1_ENUMERATED_TO_BN,0), "ASN1_ENUMERATED_to_BN"}, | ||
83 | {ERR_PACK(0,ASN1_F_ASN1_GET_OBJECT,0), "ASN1_get_object"}, | ||
84 | {ERR_PACK(0,ASN1_F_ASN1_HEADER_NEW,0), "ASN1_HEADER_new"}, | ||
85 | {ERR_PACK(0,ASN1_F_ASN1_I2D_BIO,0), "ASN1_i2d_bio"}, | ||
86 | {ERR_PACK(0,ASN1_F_ASN1_I2D_FP,0), "ASN1_i2d_fp"}, | ||
87 | {ERR_PACK(0,ASN1_F_ASN1_INTEGER_SET,0), "ASN1_INTEGER_set"}, | ||
88 | {ERR_PACK(0,ASN1_F_ASN1_INTEGER_TO_BN,0), "ASN1_INTEGER_to_BN"}, | ||
89 | {ERR_PACK(0,ASN1_F_ASN1_ITEM_EX_D2I,0), "ASN1_ITEM_EX_D2I"}, | ||
90 | {ERR_PACK(0,ASN1_F_ASN1_ITEM_NEW,0), "ASN1_item_new"}, | ||
91 | {ERR_PACK(0,ASN1_F_ASN1_MBSTRING_COPY,0), "ASN1_mbstring_copy"}, | ||
92 | {ERR_PACK(0,ASN1_F_ASN1_OBJECT_NEW,0), "ASN1_OBJECT_new"}, | ||
93 | {ERR_PACK(0,ASN1_F_ASN1_PACK_STRING,0), "ASN1_pack_string"}, | ||
94 | {ERR_PACK(0,ASN1_F_ASN1_PBE_SET,0), "ASN1_PBE_SET"}, | ||
95 | {ERR_PACK(0,ASN1_F_ASN1_SEQ_PACK,0), "ASN1_seq_pack"}, | ||
96 | {ERR_PACK(0,ASN1_F_ASN1_SEQ_UNPACK,0), "ASN1_seq_unpack"}, | ||
97 | {ERR_PACK(0,ASN1_F_ASN1_SIGN,0), "ASN1_sign"}, | ||
98 | {ERR_PACK(0,ASN1_F_ASN1_STRING_TABLE_ADD,0), "ASN1_STRING_TABLE_add"}, | ||
99 | {ERR_PACK(0,ASN1_F_ASN1_STRING_TYPE_NEW,0), "ASN1_STRING_type_new"}, | ||
100 | {ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_D2I,0), "ASN1_TEMPLATE_D2I"}, | ||
101 | {ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_EX_D2I,0), "ASN1_TEMPLATE_EX_D2I"}, | ||
102 | {ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_NEW,0), "ASN1_TEMPLATE_NEW"}, | ||
103 | {ERR_PACK(0,ASN1_F_ASN1_TIME_SET,0), "ASN1_TIME_set"}, | ||
104 | {ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,0), "ASN1_TYPE_get_int_octetstring"}, | ||
105 | {ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"}, | ||
106 | {ERR_PACK(0,ASN1_F_ASN1_UNPACK_STRING,0), "ASN1_unpack_string"}, | ||
107 | {ERR_PACK(0,ASN1_F_ASN1_VERIFY,0), "ASN1_verify"}, | ||
108 | {ERR_PACK(0,ASN1_F_BN_TO_ASN1_ENUMERATED,0), "BN_to_ASN1_ENUMERATED"}, | ||
109 | {ERR_PACK(0,ASN1_F_BN_TO_ASN1_INTEGER,0), "BN_to_ASN1_INTEGER"}, | ||
110 | {ERR_PACK(0,ASN1_F_COLLECT_DATA,0), "COLLECT_DATA"}, | ||
111 | {ERR_PACK(0,ASN1_F_D2I_ASN1_BIT_STRING,0), "D2I_ASN1_BIT_STRING"}, | ||
112 | {ERR_PACK(0,ASN1_F_D2I_ASN1_BOOLEAN,0), "d2i_ASN1_BOOLEAN"}, | ||
113 | {ERR_PACK(0,ASN1_F_D2I_ASN1_BYTES,0), "d2i_ASN1_bytes"}, | ||
114 | {ERR_PACK(0,ASN1_F_D2I_ASN1_GENERALIZEDTIME,0), "D2I_ASN1_GENERALIZEDTIME"}, | ||
115 | {ERR_PACK(0,ASN1_F_D2I_ASN1_HEADER,0), "d2i_ASN1_HEADER"}, | ||
116 | {ERR_PACK(0,ASN1_F_D2I_ASN1_INTEGER,0), "D2I_ASN1_INTEGER"}, | ||
117 | {ERR_PACK(0,ASN1_F_D2I_ASN1_OBJECT,0), "d2i_ASN1_OBJECT"}, | ||
118 | {ERR_PACK(0,ASN1_F_D2I_ASN1_SET,0), "d2i_ASN1_SET"}, | ||
119 | {ERR_PACK(0,ASN1_F_D2I_ASN1_TYPE_BYTES,0), "d2i_ASN1_type_bytes"}, | ||
120 | {ERR_PACK(0,ASN1_F_D2I_ASN1_UINTEGER,0), "d2i_ASN1_UINTEGER"}, | ||
121 | {ERR_PACK(0,ASN1_F_D2I_ASN1_UTCTIME,0), "D2I_ASN1_UTCTIME"}, | ||
122 | {ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA,0), "d2i_Netscape_RSA"}, | ||
123 | {ERR_PACK(0,ASN1_F_D2I_NETSCAPE_RSA_2,0), "D2I_NETSCAPE_RSA_2"}, | ||
124 | {ERR_PACK(0,ASN1_F_D2I_PRIVATEKEY,0), "d2i_PrivateKey"}, | ||
125 | {ERR_PACK(0,ASN1_F_D2I_PUBLICKEY,0), "d2i_PublicKey"}, | ||
126 | {ERR_PACK(0,ASN1_F_D2I_X509,0), "D2I_X509"}, | ||
127 | {ERR_PACK(0,ASN1_F_D2I_X509_CINF,0), "D2I_X509_CINF"}, | ||
128 | {ERR_PACK(0,ASN1_F_D2I_X509_NAME,0), "D2I_X509_NAME"}, | ||
129 | {ERR_PACK(0,ASN1_F_D2I_X509_PKEY,0), "d2i_X509_PKEY"}, | ||
130 | {ERR_PACK(0,ASN1_F_I2D_ASN1_TIME,0), "I2D_ASN1_TIME"}, | ||
131 | {ERR_PACK(0,ASN1_F_I2D_DSA_PUBKEY,0), "i2d_DSA_PUBKEY"}, | ||
132 | {ERR_PACK(0,ASN1_F_I2D_NETSCAPE_RSA,0), "i2d_Netscape_RSA"}, | ||
133 | {ERR_PACK(0,ASN1_F_I2D_PRIVATEKEY,0), "i2d_PrivateKey"}, | ||
134 | {ERR_PACK(0,ASN1_F_I2D_PUBLICKEY,0), "i2d_PublicKey"}, | ||
135 | {ERR_PACK(0,ASN1_F_I2D_RSA_PUBKEY,0), "i2d_RSA_PUBKEY"}, | ||
136 | {ERR_PACK(0,ASN1_F_LONG_C2I,0), "LONG_C2I"}, | ||
137 | {ERR_PACK(0,ASN1_F_OID_MODULE_INIT,0), "OID_MODULE_INIT"}, | ||
138 | {ERR_PACK(0,ASN1_F_PKCS5_PBE2_SET,0), "PKCS5_pbe2_set"}, | ||
139 | {ERR_PACK(0,ASN1_F_X509_CINF_NEW,0), "X509_CINF_NEW"}, | ||
140 | {ERR_PACK(0,ASN1_F_X509_CRL_ADD0_REVOKED,0), "X509_CRL_add0_revoked"}, | ||
141 | {ERR_PACK(0,ASN1_F_X509_INFO_NEW,0), "X509_INFO_new"}, | ||
142 | {ERR_PACK(0,ASN1_F_X509_NAME_NEW,0), "X509_NAME_NEW"}, | ||
143 | {ERR_PACK(0,ASN1_F_X509_NEW,0), "X509_NEW"}, | ||
144 | {ERR_PACK(0,ASN1_F_X509_PKEY_NEW,0), "X509_PKEY_new"}, | ||
145 | {0,NULL} | ||
146 | }; | ||
147 | |||
148 | static ERR_STRING_DATA ASN1_str_reasons[]= | ||
149 | { | ||
150 | {ASN1_R_ADDING_OBJECT ,"adding object"}, | ||
151 | {ASN1_R_AUX_ERROR ,"aux error"}, | ||
152 | {ASN1_R_BAD_CLASS ,"bad class"}, | ||
153 | {ASN1_R_BAD_OBJECT_HEADER ,"bad object header"}, | ||
154 | {ASN1_R_BAD_PASSWORD_READ ,"bad password read"}, | ||
155 | {ASN1_R_BAD_TAG ,"bad tag"}, | ||
156 | {ASN1_R_BN_LIB ,"bn lib"}, | ||
157 | {ASN1_R_BOOLEAN_IS_WRONG_LENGTH ,"boolean is wrong length"}, | ||
158 | {ASN1_R_BUFFER_TOO_SMALL ,"buffer too small"}, | ||
159 | {ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER ,"cipher has no object identifier"}, | ||
160 | {ASN1_R_DATA_IS_WRONG ,"data is wrong"}, | ||
161 | {ASN1_R_DECODE_ERROR ,"decode error"}, | ||
162 | {ASN1_R_DECODING_ERROR ,"decoding error"}, | ||
163 | {ASN1_R_ENCODE_ERROR ,"encode error"}, | ||
164 | {ASN1_R_ERROR_GETTING_TIME ,"error getting time"}, | ||
165 | {ASN1_R_ERROR_LOADING_SECTION ,"error loading section"}, | ||
166 | {ASN1_R_ERROR_PARSING_SET_ELEMENT ,"error parsing set element"}, | ||
167 | {ASN1_R_ERROR_SETTING_CIPHER_PARAMS ,"error setting cipher params"}, | ||
168 | {ASN1_R_EXPECTING_AN_INTEGER ,"expecting an integer"}, | ||
169 | {ASN1_R_EXPECTING_AN_OBJECT ,"expecting an object"}, | ||
170 | {ASN1_R_EXPECTING_A_BOOLEAN ,"expecting a boolean"}, | ||
171 | {ASN1_R_EXPECTING_A_TIME ,"expecting a time"}, | ||
172 | {ASN1_R_EXPLICIT_LENGTH_MISMATCH ,"explicit length mismatch"}, | ||
173 | {ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED ,"explicit tag not constructed"}, | ||
174 | {ASN1_R_FIELD_MISSING ,"field missing"}, | ||
175 | {ASN1_R_FIRST_NUM_TOO_LARGE ,"first num too large"}, | ||
176 | {ASN1_R_HEADER_TOO_LONG ,"header too long"}, | ||
177 | {ASN1_R_ILLEGAL_CHARACTERS ,"illegal characters"}, | ||
178 | {ASN1_R_ILLEGAL_NULL ,"illegal null"}, | ||
179 | {ASN1_R_ILLEGAL_OPTIONAL_ANY ,"illegal optional any"}, | ||
180 | {ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE ,"illegal options on item template"}, | ||
181 | {ASN1_R_ILLEGAL_TAGGED_ANY ,"illegal tagged any"}, | ||
182 | {ASN1_R_INTEGER_TOO_LARGE_FOR_LONG ,"integer too large for long"}, | ||
183 | {ASN1_R_INVALID_BMPSTRING_LENGTH ,"invalid bmpstring length"}, | ||
184 | {ASN1_R_INVALID_DIGIT ,"invalid digit"}, | ||
185 | {ASN1_R_INVALID_SEPARATOR ,"invalid separator"}, | ||
186 | {ASN1_R_INVALID_TIME_FORMAT ,"invalid time format"}, | ||
187 | {ASN1_R_INVALID_UNIVERSALSTRING_LENGTH ,"invalid universalstring length"}, | ||
188 | {ASN1_R_INVALID_UTF8STRING ,"invalid utf8string"}, | ||
189 | {ASN1_R_IV_TOO_LARGE ,"iv too large"}, | ||
190 | {ASN1_R_LENGTH_ERROR ,"length error"}, | ||
191 | {ASN1_R_MISSING_EOC ,"missing eoc"}, | ||
192 | {ASN1_R_MISSING_SECOND_NUMBER ,"missing second number"}, | ||
193 | {ASN1_R_MSTRING_NOT_UNIVERSAL ,"mstring not universal"}, | ||
194 | {ASN1_R_MSTRING_WRONG_TAG ,"mstring wrong tag"}, | ||
195 | {ASN1_R_NON_HEX_CHARACTERS ,"non hex characters"}, | ||
196 | {ASN1_R_NOT_ENOUGH_DATA ,"not enough data"}, | ||
197 | {ASN1_R_NO_MATCHING_CHOICE_TYPE ,"no matching choice type"}, | ||
198 | {ASN1_R_NULL_IS_WRONG_LENGTH ,"null is wrong length"}, | ||
199 | {ASN1_R_ODD_NUMBER_OF_CHARS ,"odd number of chars"}, | ||
200 | {ASN1_R_PRIVATE_KEY_HEADER_MISSING ,"private key header missing"}, | ||
201 | {ASN1_R_SECOND_NUMBER_TOO_LARGE ,"second number too large"}, | ||
202 | {ASN1_R_SEQUENCE_LENGTH_MISMATCH ,"sequence length mismatch"}, | ||
203 | {ASN1_R_SEQUENCE_NOT_CONSTRUCTED ,"sequence not constructed"}, | ||
204 | {ASN1_R_SHORT_LINE ,"short line"}, | ||
205 | {ASN1_R_STRING_TOO_LONG ,"string too long"}, | ||
206 | {ASN1_R_STRING_TOO_SHORT ,"string too short"}, | ||
207 | {ASN1_R_TAG_VALUE_TOO_HIGH ,"tag value too high"}, | ||
208 | {ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD,"the asn1 object identifier is not known for this md"}, | ||
209 | {ASN1_R_TOO_LONG ,"too long"}, | ||
210 | {ASN1_R_TYPE_NOT_CONSTRUCTED ,"type not constructed"}, | ||
211 | {ASN1_R_UNABLE_TO_DECODE_RSA_KEY ,"unable to decode rsa key"}, | ||
212 | {ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY ,"unable to decode rsa private key"}, | ||
213 | {ASN1_R_UNEXPECTED_EOC ,"unexpected eoc"}, | ||
214 | {ASN1_R_UNKNOWN_FORMAT ,"unknown format"}, | ||
215 | {ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM ,"unknown message digest algorithm"}, | ||
216 | {ASN1_R_UNKNOWN_OBJECT_TYPE ,"unknown object type"}, | ||
217 | {ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE ,"unknown public key type"}, | ||
218 | {ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE ,"unsupported any defined by type"}, | ||
219 | {ASN1_R_UNSUPPORTED_CIPHER ,"unsupported cipher"}, | ||
220 | {ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM ,"unsupported encryption algorithm"}, | ||
221 | {ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE ,"unsupported public key type"}, | ||
222 | {ASN1_R_WRONG_TAG ,"wrong tag"}, | ||
223 | {ASN1_R_WRONG_TYPE ,"wrong type"}, | ||
224 | {0,NULL} | ||
225 | }; | ||
226 | |||
227 | #endif | ||
228 | |||
229 | void ERR_load_ASN1_strings(void) | ||
230 | { | ||
231 | static int init=1; | ||
232 | |||
233 | if (init) | ||
234 | { | ||
235 | init=0; | ||
236 | #ifndef OPENSSL_NO_ERR | ||
237 | ERR_load_strings(ERR_LIB_ASN1,ASN1_str_functs); | ||
238 | ERR_load_strings(ERR_LIB_ASN1,ASN1_str_reasons); | ||
239 | #endif | ||
240 | |||
241 | } | ||
242 | } | ||
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c deleted file mode 100644 index a74f1368d3..0000000000 --- a/src/lib/libcrypto/asn1/asn1_lib.c +++ /dev/null | |||
@@ -1,432 +0,0 @@ | |||
1 | /* crypto/asn1/asn1_lib.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <limits.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/asn1.h> | ||
63 | #include <openssl/asn1_mac.h> | ||
64 | |||
65 | static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max); | ||
66 | static void asn1_put_length(unsigned char **pp, int length); | ||
67 | const char *ASN1_version="ASN.1" OPENSSL_VERSION_PTEXT; | ||
68 | |||
69 | int ASN1_check_infinite_end(unsigned char **p, long len) | ||
70 | { | ||
71 | /* If there is 0 or 1 byte left, the length check should pick | ||
72 | * things up */ | ||
73 | if (len <= 0) | ||
74 | return(1); | ||
75 | else if ((len >= 2) && ((*p)[0] == 0) && ((*p)[1] == 0)) | ||
76 | { | ||
77 | (*p)+=2; | ||
78 | return(1); | ||
79 | } | ||
80 | return(0); | ||
81 | } | ||
82 | |||
83 | |||
84 | int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass, | ||
85 | long omax) | ||
86 | { | ||
87 | int i,ret; | ||
88 | long l; | ||
89 | unsigned char *p= *pp; | ||
90 | int tag,xclass,inf; | ||
91 | long max=omax; | ||
92 | |||
93 | if (!max) goto err; | ||
94 | ret=(*p&V_ASN1_CONSTRUCTED); | ||
95 | xclass=(*p&V_ASN1_PRIVATE); | ||
96 | i= *p&V_ASN1_PRIMITIVE_TAG; | ||
97 | if (i == V_ASN1_PRIMITIVE_TAG) | ||
98 | { /* high-tag */ | ||
99 | p++; | ||
100 | if (--max == 0) goto err; | ||
101 | l=0; | ||
102 | while (*p&0x80) | ||
103 | { | ||
104 | l<<=7L; | ||
105 | l|= *(p++)&0x7f; | ||
106 | if (--max == 0) goto err; | ||
107 | if (l > (INT_MAX >> 7L)) goto err; | ||
108 | } | ||
109 | l<<=7L; | ||
110 | l|= *(p++)&0x7f; | ||
111 | tag=(int)l; | ||
112 | if (--max == 0) goto err; | ||
113 | } | ||
114 | else | ||
115 | { | ||
116 | tag=i; | ||
117 | p++; | ||
118 | if (--max == 0) goto err; | ||
119 | } | ||
120 | *ptag=tag; | ||
121 | *pclass=xclass; | ||
122 | if (!asn1_get_length(&p,&inf,plength,(int)max)) goto err; | ||
123 | |||
124 | #if 0 | ||
125 | fprintf(stderr,"p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n", | ||
126 | (int)p,*plength,omax,(int)*pp,(int)(p+ *plength), | ||
127 | (int)(omax+ *pp)); | ||
128 | |||
129 | #endif | ||
130 | if (*plength > (omax - (p - *pp))) | ||
131 | { | ||
132 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_TOO_LONG); | ||
133 | /* Set this so that even if things are not long enough | ||
134 | * the values are set correctly */ | ||
135 | ret|=0x80; | ||
136 | } | ||
137 | *pp=p; | ||
138 | return(ret|inf); | ||
139 | err: | ||
140 | ASN1err(ASN1_F_ASN1_GET_OBJECT,ASN1_R_HEADER_TOO_LONG); | ||
141 | return(0x80); | ||
142 | } | ||
143 | |||
144 | static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max) | ||
145 | { | ||
146 | unsigned char *p= *pp; | ||
147 | unsigned long ret=0; | ||
148 | int i; | ||
149 | |||
150 | if (max-- < 1) return(0); | ||
151 | if (*p == 0x80) | ||
152 | { | ||
153 | *inf=1; | ||
154 | ret=0; | ||
155 | p++; | ||
156 | } | ||
157 | else | ||
158 | { | ||
159 | *inf=0; | ||
160 | i= *p&0x7f; | ||
161 | if (*(p++) & 0x80) | ||
162 | { | ||
163 | if (i > sizeof(long)) | ||
164 | return 0; | ||
165 | if (max-- == 0) return(0); | ||
166 | while (i-- > 0) | ||
167 | { | ||
168 | ret<<=8L; | ||
169 | ret|= *(p++); | ||
170 | if (max-- == 0) return(0); | ||
171 | } | ||
172 | } | ||
173 | else | ||
174 | ret=i; | ||
175 | } | ||
176 | if (ret > LONG_MAX) | ||
177 | return 0; | ||
178 | *pp=p; | ||
179 | *rl=(long)ret; | ||
180 | return(1); | ||
181 | } | ||
182 | |||
183 | /* class 0 is constructed | ||
184 | * constructed == 2 for indefinite length constructed */ | ||
185 | void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, | ||
186 | int xclass) | ||
187 | { | ||
188 | unsigned char *p= *pp; | ||
189 | int i, ttag; | ||
190 | |||
191 | i=(constructed)?V_ASN1_CONSTRUCTED:0; | ||
192 | i|=(xclass&V_ASN1_PRIVATE); | ||
193 | if (tag < 31) | ||
194 | *(p++)=i|(tag&V_ASN1_PRIMITIVE_TAG); | ||
195 | else | ||
196 | { | ||
197 | *(p++)=i|V_ASN1_PRIMITIVE_TAG; | ||
198 | for(i = 0, ttag = tag; ttag > 0; i++) ttag >>=7; | ||
199 | ttag = i; | ||
200 | while(i-- > 0) | ||
201 | { | ||
202 | p[i] = tag & 0x7f; | ||
203 | if(i != (ttag - 1)) p[i] |= 0x80; | ||
204 | tag >>= 7; | ||
205 | } | ||
206 | p += ttag; | ||
207 | } | ||
208 | if ((constructed == 2) && (length == 0)) | ||
209 | *(p++)=0x80; /* der_put_length would output 0 instead */ | ||
210 | else | ||
211 | asn1_put_length(&p,length); | ||
212 | *pp=p; | ||
213 | } | ||
214 | |||
215 | static void asn1_put_length(unsigned char **pp, int length) | ||
216 | { | ||
217 | unsigned char *p= *pp; | ||
218 | int i,l; | ||
219 | if (length <= 127) | ||
220 | *(p++)=(unsigned char)length; | ||
221 | else | ||
222 | { | ||
223 | l=length; | ||
224 | for (i=0; l > 0; i++) | ||
225 | l>>=8; | ||
226 | *(p++)=i|0x80; | ||
227 | l=i; | ||
228 | while (i-- > 0) | ||
229 | { | ||
230 | p[i]=length&0xff; | ||
231 | length>>=8; | ||
232 | } | ||
233 | p+=l; | ||
234 | } | ||
235 | *pp=p; | ||
236 | } | ||
237 | |||
238 | int ASN1_object_size(int constructed, int length, int tag) | ||
239 | { | ||
240 | int ret; | ||
241 | |||
242 | ret=length; | ||
243 | ret++; | ||
244 | if (tag >= 31) | ||
245 | { | ||
246 | while (tag > 0) | ||
247 | { | ||
248 | tag>>=7; | ||
249 | ret++; | ||
250 | } | ||
251 | } | ||
252 | if ((length == 0) && (constructed == 2)) | ||
253 | ret+=2; | ||
254 | ret++; | ||
255 | if (length > 127) | ||
256 | { | ||
257 | while (length > 0) | ||
258 | { | ||
259 | length>>=8; | ||
260 | ret++; | ||
261 | } | ||
262 | } | ||
263 | return(ret); | ||
264 | } | ||
265 | |||
266 | int asn1_Finish(ASN1_CTX *c) | ||
267 | { | ||
268 | if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) | ||
269 | { | ||
270 | if (!ASN1_check_infinite_end(&c->p,c->slen)) | ||
271 | { | ||
272 | c->error=ERR_R_MISSING_ASN1_EOS; | ||
273 | return(0); | ||
274 | } | ||
275 | } | ||
276 | if ( ((c->slen != 0) && !(c->inf & 1)) || | ||
277 | ((c->slen < 0) && (c->inf & 1))) | ||
278 | { | ||
279 | c->error=ERR_R_ASN1_LENGTH_MISMATCH; | ||
280 | return(0); | ||
281 | } | ||
282 | return(1); | ||
283 | } | ||
284 | |||
285 | int asn1_GetSequence(ASN1_CTX *c, long *length) | ||
286 | { | ||
287 | unsigned char *q; | ||
288 | |||
289 | q=c->p; | ||
290 | c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass), | ||
291 | *length); | ||
292 | if (c->inf & 0x80) | ||
293 | { | ||
294 | c->error=ERR_R_BAD_GET_ASN1_OBJECT_CALL; | ||
295 | return(0); | ||
296 | } | ||
297 | if (c->tag != V_ASN1_SEQUENCE) | ||
298 | { | ||
299 | c->error=ERR_R_EXPECTING_AN_ASN1_SEQUENCE; | ||
300 | return(0); | ||
301 | } | ||
302 | (*length)-=(c->p-q); | ||
303 | if (c->max && (*length < 0)) | ||
304 | { | ||
305 | c->error=ERR_R_ASN1_LENGTH_MISMATCH; | ||
306 | return(0); | ||
307 | } | ||
308 | if (c->inf == (1|V_ASN1_CONSTRUCTED)) | ||
309 | c->slen= *length+ *(c->pp)-c->p; | ||
310 | c->eos=0; | ||
311 | return(1); | ||
312 | } | ||
313 | |||
314 | ASN1_STRING *ASN1_STRING_dup(ASN1_STRING *str) | ||
315 | { | ||
316 | ASN1_STRING *ret; | ||
317 | |||
318 | if (str == NULL) return(NULL); | ||
319 | if ((ret=ASN1_STRING_type_new(str->type)) == NULL) | ||
320 | return(NULL); | ||
321 | if (!ASN1_STRING_set(ret,str->data,str->length)) | ||
322 | { | ||
323 | ASN1_STRING_free(ret); | ||
324 | return(NULL); | ||
325 | } | ||
326 | ret->flags = str->flags; | ||
327 | return(ret); | ||
328 | } | ||
329 | |||
330 | int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len) | ||
331 | { | ||
332 | unsigned char *c; | ||
333 | const char *data=_data; | ||
334 | |||
335 | if (len < 0) | ||
336 | { | ||
337 | if (data == NULL) | ||
338 | return(0); | ||
339 | else | ||
340 | len=strlen(data); | ||
341 | } | ||
342 | if ((str->length < len) || (str->data == NULL)) | ||
343 | { | ||
344 | c=str->data; | ||
345 | if (c == NULL) | ||
346 | str->data=OPENSSL_malloc(len+1); | ||
347 | else | ||
348 | str->data=OPENSSL_realloc(c,len+1); | ||
349 | |||
350 | if (str->data == NULL) | ||
351 | { | ||
352 | str->data=c; | ||
353 | return(0); | ||
354 | } | ||
355 | } | ||
356 | str->length=len; | ||
357 | if (data != NULL) | ||
358 | { | ||
359 | memcpy(str->data,data,len); | ||
360 | /* an allowance for strings :-) */ | ||
361 | str->data[len]='\0'; | ||
362 | } | ||
363 | return(1); | ||
364 | } | ||
365 | |||
366 | ASN1_STRING *ASN1_STRING_new(void) | ||
367 | { | ||
368 | return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); | ||
369 | } | ||
370 | |||
371 | |||
372 | ASN1_STRING *ASN1_STRING_type_new(int type) | ||
373 | { | ||
374 | ASN1_STRING *ret; | ||
375 | |||
376 | ret=(ASN1_STRING *)OPENSSL_malloc(sizeof(ASN1_STRING)); | ||
377 | if (ret == NULL) | ||
378 | { | ||
379 | ASN1err(ASN1_F_ASN1_STRING_TYPE_NEW,ERR_R_MALLOC_FAILURE); | ||
380 | return(NULL); | ||
381 | } | ||
382 | ret->length=0; | ||
383 | ret->type=type; | ||
384 | ret->data=NULL; | ||
385 | ret->flags=0; | ||
386 | return(ret); | ||
387 | } | ||
388 | |||
389 | void ASN1_STRING_free(ASN1_STRING *a) | ||
390 | { | ||
391 | if (a == NULL) return; | ||
392 | if (a->data != NULL) OPENSSL_free(a->data); | ||
393 | OPENSSL_free(a); | ||
394 | } | ||
395 | |||
396 | int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b) | ||
397 | { | ||
398 | int i; | ||
399 | |||
400 | i=(a->length-b->length); | ||
401 | if (i == 0) | ||
402 | { | ||
403 | i=memcmp(a->data,b->data,a->length); | ||
404 | if (i == 0) | ||
405 | return(a->type-b->type); | ||
406 | else | ||
407 | return(i); | ||
408 | } | ||
409 | else | ||
410 | return(i); | ||
411 | } | ||
412 | |||
413 | void asn1_add_error(unsigned char *address, int offset) | ||
414 | { | ||
415 | char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1]; | ||
416 | |||
417 | BIO_snprintf(buf1,sizeof buf1,"%lu",(unsigned long)address); | ||
418 | BIO_snprintf(buf2,sizeof buf2,"%d",offset); | ||
419 | ERR_add_error_data(4,"address=",buf1," offset=",buf2); | ||
420 | } | ||
421 | |||
422 | int ASN1_STRING_length(ASN1_STRING *x) | ||
423 | { return M_ASN1_STRING_length(x); } | ||
424 | |||
425 | void ASN1_STRING_length_set(ASN1_STRING *x, int len) | ||
426 | { M_ASN1_STRING_length_set(x, len); return; } | ||
427 | |||
428 | int ASN1_STRING_type(ASN1_STRING *x) | ||
429 | { return M_ASN1_STRING_type(x); } | ||
430 | |||
431 | unsigned char * ASN1_STRING_data(ASN1_STRING *x) | ||
432 | { return M_ASN1_STRING_data(x); } | ||
diff --git a/src/lib/libcrypto/asn1/asn1_mac.h b/src/lib/libcrypto/asn1/asn1_mac.h deleted file mode 100644 index a48649ceeb..0000000000 --- a/src/lib/libcrypto/asn1/asn1_mac.h +++ /dev/null | |||
@@ -1,560 +0,0 @@ | |||
1 | /* crypto/asn1/asn1_mac.h */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #ifndef HEADER_ASN1_MAC_H | ||
60 | #define HEADER_ASN1_MAC_H | ||
61 | |||
62 | #include <openssl/asn1.h> | ||
63 | |||
64 | #ifdef __cplusplus | ||
65 | extern "C" { | ||
66 | #endif | ||
67 | |||
68 | #ifndef ASN1_MAC_ERR_LIB | ||
69 | #define ASN1_MAC_ERR_LIB ERR_LIB_ASN1 | ||
70 | #endif | ||
71 | |||
72 | #define ASN1_MAC_H_err(f,r,line) \ | ||
73 | ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line)) | ||
74 | |||
75 | #define M_ASN1_D2I_vars(a,type,func) \ | ||
76 | ASN1_CTX c; \ | ||
77 | type ret=NULL; \ | ||
78 | \ | ||
79 | c.pp=(unsigned char **)pp; \ | ||
80 | c.q= *(unsigned char **)pp; \ | ||
81 | c.error=ERR_R_NESTED_ASN1_ERROR; \ | ||
82 | if ((a == NULL) || ((*a) == NULL)) \ | ||
83 | { if ((ret=(type)func()) == NULL) \ | ||
84 | { c.line=__LINE__; goto err; } } \ | ||
85 | else ret=(*a); | ||
86 | |||
87 | #define M_ASN1_D2I_Init() \ | ||
88 | c.p= *(unsigned char **)pp; \ | ||
89 | c.max=(length == 0)?0:(c.p+length); | ||
90 | |||
91 | #define M_ASN1_D2I_Finish_2(a) \ | ||
92 | if (!asn1_Finish(&c)) \ | ||
93 | { c.line=__LINE__; goto err; } \ | ||
94 | *(unsigned char **)pp=c.p; \ | ||
95 | if (a != NULL) (*a)=ret; \ | ||
96 | return(ret); | ||
97 | |||
98 | #define M_ASN1_D2I_Finish(a,func,e) \ | ||
99 | M_ASN1_D2I_Finish_2(a); \ | ||
100 | err:\ | ||
101 | ASN1_MAC_H_err((e),c.error,c.line); \ | ||
102 | asn1_add_error(*(unsigned char **)pp,(int)(c.q- *pp)); \ | ||
103 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ | ||
104 | return(NULL) | ||
105 | |||
106 | #define M_ASN1_D2I_start_sequence() \ | ||
107 | if (!asn1_GetSequence(&c,&length)) \ | ||
108 | { c.line=__LINE__; goto err; } | ||
109 | /* Begin reading ASN1 without a surrounding sequence */ | ||
110 | #define M_ASN1_D2I_begin() \ | ||
111 | c.slen = length; | ||
112 | |||
113 | /* End reading ASN1 with no check on length */ | ||
114 | #define M_ASN1_D2I_Finish_nolen(a, func, e) \ | ||
115 | *pp=c.p; \ | ||
116 | if (a != NULL) (*a)=ret; \ | ||
117 | return(ret); \ | ||
118 | err:\ | ||
119 | ASN1_MAC_H_err((e),c.error,c.line); \ | ||
120 | asn1_add_error(*pp,(int)(c.q- *pp)); \ | ||
121 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ | ||
122 | return(NULL) | ||
123 | |||
124 | #define M_ASN1_D2I_end_sequence() \ | ||
125 | (((c.inf&1) == 0)?(c.slen <= 0): \ | ||
126 | (c.eos=ASN1_check_infinite_end(&c.p,c.slen))) | ||
127 | |||
128 | /* Don't use this with d2i_ASN1_BOOLEAN() */ | ||
129 | #define M_ASN1_D2I_get(b,func) \ | ||
130 | c.q=c.p; \ | ||
131 | if (func(&(b),&c.p,c.slen) == NULL) \ | ||
132 | {c.line=__LINE__; goto err; } \ | ||
133 | c.slen-=(c.p-c.q); | ||
134 | |||
135 | /* use this instead () */ | ||
136 | #define M_ASN1_D2I_get_int(b,func) \ | ||
137 | c.q=c.p; \ | ||
138 | if (func(&(b),&c.p,c.slen) < 0) \ | ||
139 | {c.line=__LINE__; goto err; } \ | ||
140 | c.slen-=(c.p-c.q); | ||
141 | |||
142 | #define M_ASN1_D2I_get_opt(b,func,type) \ | ||
143 | if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) \ | ||
144 | == (V_ASN1_UNIVERSAL|(type)))) \ | ||
145 | { \ | ||
146 | M_ASN1_D2I_get(b,func); \ | ||
147 | } | ||
148 | |||
149 | #define M_ASN1_D2I_get_imp(b,func, type) \ | ||
150 | M_ASN1_next=(_tmp& V_ASN1_CONSTRUCTED)|type; \ | ||
151 | c.q=c.p; \ | ||
152 | if (func(&(b),&c.p,c.slen) == NULL) \ | ||
153 | {c.line=__LINE__; M_ASN1_next_prev = _tmp; goto err; } \ | ||
154 | c.slen-=(c.p-c.q);\ | ||
155 | M_ASN1_next_prev=_tmp; | ||
156 | |||
157 | #define M_ASN1_D2I_get_IMP_opt(b,func,tag,type) \ | ||
158 | if ((c.slen != 0) && ((M_ASN1_next & (~V_ASN1_CONSTRUCTED)) == \ | ||
159 | (V_ASN1_CONTEXT_SPECIFIC|(tag)))) \ | ||
160 | { \ | ||
161 | unsigned char _tmp = M_ASN1_next; \ | ||
162 | M_ASN1_D2I_get_imp(b,func, type);\ | ||
163 | } | ||
164 | |||
165 | #define M_ASN1_D2I_get_set(r,func,free_func) \ | ||
166 | M_ASN1_D2I_get_imp_set(r,func,free_func, \ | ||
167 | V_ASN1_SET,V_ASN1_UNIVERSAL); | ||
168 | |||
169 | #define M_ASN1_D2I_get_set_type(type,r,func,free_func) \ | ||
170 | M_ASN1_D2I_get_imp_set_type(type,r,func,free_func, \ | ||
171 | V_ASN1_SET,V_ASN1_UNIVERSAL); | ||
172 | |||
173 | #define M_ASN1_D2I_get_set_opt(r,func,free_func) \ | ||
174 | if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ | ||
175 | V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ | ||
176 | { M_ASN1_D2I_get_set(r,func,free_func); } | ||
177 | |||
178 | #define M_ASN1_D2I_get_set_opt_type(type,r,func,free_func) \ | ||
179 | if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ | ||
180 | V_ASN1_CONSTRUCTED|V_ASN1_SET)))\ | ||
181 | { M_ASN1_D2I_get_set_type(type,r,func,free_func); } | ||
182 | |||
183 | #define M_ASN1_I2D_len_SET_opt(a,f) \ | ||
184 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
185 | M_ASN1_I2D_len_SET(a,f); | ||
186 | |||
187 | #define M_ASN1_I2D_put_SET_opt(a,f) \ | ||
188 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
189 | M_ASN1_I2D_put_SET(a,f); | ||
190 | |||
191 | #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \ | ||
192 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
193 | M_ASN1_I2D_put_SEQUENCE(a,f); | ||
194 | |||
195 | #define M_ASN1_I2D_put_SEQUENCE_opt_type(type,a,f) \ | ||
196 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | ||
197 | M_ASN1_I2D_put_SEQUENCE_type(type,a,f); | ||
198 | |||
199 | #define M_ASN1_D2I_get_IMP_set_opt(b,func,free_func,tag) \ | ||
200 | if ((c.slen != 0) && \ | ||
201 | (M_ASN1_next == \ | ||
202 | (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ | ||
203 | { \ | ||
204 | M_ASN1_D2I_get_imp_set(b,func,free_func,\ | ||
205 | tag,V_ASN1_CONTEXT_SPECIFIC); \ | ||
206 | } | ||
207 | |||
208 | #define M_ASN1_D2I_get_IMP_set_opt_type(type,b,func,free_func,tag) \ | ||
209 | if ((c.slen != 0) && \ | ||
210 | (M_ASN1_next == \ | ||
211 | (V_ASN1_CONTEXT_SPECIFIC|V_ASN1_CONSTRUCTED|(tag))))\ | ||
212 | { \ | ||
213 | M_ASN1_D2I_get_imp_set_type(type,b,func,free_func,\ | ||
214 | tag,V_ASN1_CONTEXT_SPECIFIC); \ | ||
215 | } | ||
216 | |||
217 | #define M_ASN1_D2I_get_seq(r,func,free_func) \ | ||
218 | M_ASN1_D2I_get_imp_set(r,func,free_func,\ | ||
219 | V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
220 | |||
221 | #define M_ASN1_D2I_get_seq_type(type,r,func,free_func) \ | ||
222 | M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ | ||
223 | V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL) | ||
224 | |||
225 | #define M_ASN1_D2I_get_seq_opt(r,func,free_func) \ | ||
226 | if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ | ||
227 | V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ | ||
228 | { M_ASN1_D2I_get_seq(r,func,free_func); } | ||
229 | |||
230 | #define M_ASN1_D2I_get_seq_opt_type(type,r,func,free_func) \ | ||
231 | if ((c.slen != 0) && (M_ASN1_next == (V_ASN1_UNIVERSAL| \ | ||
232 | V_ASN1_CONSTRUCTED|V_ASN1_SEQUENCE)))\ | ||
233 | { M_ASN1_D2I_get_seq_type(type,r,func,free_func); } | ||
234 | |||
235 | #define M_ASN1_D2I_get_IMP_set(r,func,free_func,x) \ | ||
236 | M_ASN1_D2I_get_imp_set(r,func,free_func,\ | ||
237 | x,V_ASN1_CONTEXT_SPECIFIC); | ||
238 | |||
239 | #define M_ASN1_D2I_get_IMP_set_type(type,r,func,free_func,x) \ | ||
240 | M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,\ | ||
241 | x,V_ASN1_CONTEXT_SPECIFIC); | ||
242 | |||
243 | #define M_ASN1_D2I_get_imp_set(r,func,free_func,a,b) \ | ||
244 | c.q=c.p; \ | ||
245 | if (d2i_ASN1_SET(&(r),&c.p,c.slen,(char *(*)())func,\ | ||
246 | (void (*)())free_func,a,b) == NULL) \ | ||
247 | { c.line=__LINE__; goto err; } \ | ||
248 | c.slen-=(c.p-c.q); | ||
249 | |||
250 | #define M_ASN1_D2I_get_imp_set_type(type,r,func,free_func,a,b) \ | ||
251 | c.q=c.p; \ | ||
252 | if (d2i_ASN1_SET_OF_##type(&(r),&c.p,c.slen,func,\ | ||
253 | free_func,a,b) == NULL) \ | ||
254 | { c.line=__LINE__; goto err; } \ | ||
255 | c.slen-=(c.p-c.q); | ||
256 | |||
257 | #define M_ASN1_D2I_get_set_strings(r,func,a,b) \ | ||
258 | c.q=c.p; \ | ||
259 | if (d2i_ASN1_STRING_SET(&(r),&c.p,c.slen,a,b) == NULL) \ | ||
260 | { c.line=__LINE__; goto err; } \ | ||
261 | c.slen-=(c.p-c.q); | ||
262 | |||
263 | #define M_ASN1_D2I_get_EXP_opt(r,func,tag) \ | ||
264 | if ((c.slen != 0L) && (M_ASN1_next == \ | ||
265 | (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ | ||
266 | { \ | ||
267 | int Tinf,Ttag,Tclass; \ | ||
268 | long Tlen; \ | ||
269 | \ | ||
270 | c.q=c.p; \ | ||
271 | Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ | ||
272 | if (Tinf & 0x80) \ | ||
273 | { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ | ||
274 | c.line=__LINE__; goto err; } \ | ||
275 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ | ||
276 | Tlen = c.slen - (c.p - c.q) - 2; \ | ||
277 | if (func(&(r),&c.p,Tlen) == NULL) \ | ||
278 | { c.line=__LINE__; goto err; } \ | ||
279 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ | ||
280 | Tlen = c.slen - (c.p - c.q); \ | ||
281 | if(!ASN1_check_infinite_end(&c.p, Tlen)) \ | ||
282 | { c.error=ERR_R_MISSING_ASN1_EOS; \ | ||
283 | c.line=__LINE__; goto err; } \ | ||
284 | }\ | ||
285 | c.slen-=(c.p-c.q); \ | ||
286 | } | ||
287 | |||
288 | #define M_ASN1_D2I_get_EXP_set_opt(r,func,free_func,tag,b) \ | ||
289 | if ((c.slen != 0) && (M_ASN1_next == \ | ||
290 | (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ | ||
291 | { \ | ||
292 | int Tinf,Ttag,Tclass; \ | ||
293 | long Tlen; \ | ||
294 | \ | ||
295 | c.q=c.p; \ | ||
296 | Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ | ||
297 | if (Tinf & 0x80) \ | ||
298 | { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ | ||
299 | c.line=__LINE__; goto err; } \ | ||
300 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ | ||
301 | Tlen = c.slen - (c.p - c.q) - 2; \ | ||
302 | if (d2i_ASN1_SET(&(r),&c.p,Tlen,(char *(*)())func, \ | ||
303 | (void (*)())free_func, \ | ||
304 | b,V_ASN1_UNIVERSAL) == NULL) \ | ||
305 | { c.line=__LINE__; goto err; } \ | ||
306 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ | ||
307 | Tlen = c.slen - (c.p - c.q); \ | ||
308 | if(!ASN1_check_infinite_end(&c.p, Tlen)) \ | ||
309 | { c.error=ERR_R_MISSING_ASN1_EOS; \ | ||
310 | c.line=__LINE__; goto err; } \ | ||
311 | }\ | ||
312 | c.slen-=(c.p-c.q); \ | ||
313 | } | ||
314 | |||
315 | #define M_ASN1_D2I_get_EXP_set_opt_type(type,r,func,free_func,tag,b) \ | ||
316 | if ((c.slen != 0) && (M_ASN1_next == \ | ||
317 | (V_ASN1_CONSTRUCTED|V_ASN1_CONTEXT_SPECIFIC|tag))) \ | ||
318 | { \ | ||
319 | int Tinf,Ttag,Tclass; \ | ||
320 | long Tlen; \ | ||
321 | \ | ||
322 | c.q=c.p; \ | ||
323 | Tinf=ASN1_get_object(&c.p,&Tlen,&Ttag,&Tclass,c.slen); \ | ||
324 | if (Tinf & 0x80) \ | ||
325 | { c.error=ERR_R_BAD_ASN1_OBJECT_HEADER; \ | ||
326 | c.line=__LINE__; goto err; } \ | ||
327 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) \ | ||
328 | Tlen = c.slen - (c.p - c.q) - 2; \ | ||
329 | if (d2i_ASN1_SET_OF_##type(&(r),&c.p,Tlen,func, \ | ||
330 | free_func,b,V_ASN1_UNIVERSAL) == NULL) \ | ||
331 | { c.line=__LINE__; goto err; } \ | ||
332 | if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ | ||
333 | Tlen = c.slen - (c.p - c.q); \ | ||
334 | if(!ASN1_check_infinite_end(&c.p, Tlen)) \ | ||
335 | { c.error=ERR_R_MISSING_ASN1_EOS; \ | ||
336 | c.line=__LINE__; goto err; } \ | ||
337 | }\ | ||
338 | c.slen-=(c.p-c.q); \ | ||
339 | } | ||
340 | |||
341 | /* New macros */ | ||
342 | #define M_ASN1_New_Malloc(ret,type) \ | ||
343 | if ((ret=(type *)OPENSSL_malloc(sizeof(type))) == NULL) \ | ||
344 | { c.line=__LINE__; goto err2; } | ||
345 | |||
346 | #define M_ASN1_New(arg,func) \ | ||
347 | if (((arg)=func()) == NULL) return(NULL) | ||
348 | |||
349 | #define M_ASN1_New_Error(a) \ | ||
350 | /* err: ASN1_MAC_H_err((a),ERR_R_NESTED_ASN1_ERROR,c.line); \ | ||
351 | return(NULL);*/ \ | ||
352 | err2: ASN1_MAC_H_err((a),ERR_R_MALLOC_FAILURE,c.line); \ | ||
353 | return(NULL) | ||
354 | |||
355 | |||
356 | #define M_ASN1_next (*c.p) | ||
357 | #define M_ASN1_next_prev (*c.q) | ||
358 | |||
359 | /*************************************************/ | ||
360 | |||
361 | #define M_ASN1_I2D_vars(a) int r=0,ret=0; \ | ||
362 | unsigned char *p; \ | ||
363 | if (a == NULL) return(0) | ||
364 | |||
365 | /* Length Macros */ | ||
366 | #define M_ASN1_I2D_len(a,f) ret+=f(a,NULL) | ||
367 | #define M_ASN1_I2D_len_IMP_opt(a,f) if (a != NULL) M_ASN1_I2D_len(a,f) | ||
368 | |||
369 | #define M_ASN1_I2D_len_SET(a,f) \ | ||
370 | ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET); | ||
371 | |||
372 | #define M_ASN1_I2D_len_SET_type(type,a,f) \ | ||
373 | ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SET, \ | ||
374 | V_ASN1_UNIVERSAL,IS_SET); | ||
375 | |||
376 | #define M_ASN1_I2D_len_SEQUENCE(a,f) \ | ||
377 | ret+=i2d_ASN1_SET(a,NULL,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \ | ||
378 | IS_SEQUENCE); | ||
379 | |||
380 | #define M_ASN1_I2D_len_SEQUENCE_type(type,a,f) \ | ||
381 | ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,V_ASN1_SEQUENCE, \ | ||
382 | V_ASN1_UNIVERSAL,IS_SEQUENCE) | ||
383 | |||
384 | #define M_ASN1_I2D_len_SEQUENCE_opt(a,f) \ | ||
385 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
386 | M_ASN1_I2D_len_SEQUENCE(a,f); | ||
387 | |||
388 | #define M_ASN1_I2D_len_SEQUENCE_opt_type(type,a,f) \ | ||
389 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | ||
390 | M_ASN1_I2D_len_SEQUENCE_type(type,a,f); | ||
391 | |||
392 | #define M_ASN1_I2D_len_IMP_SET(a,f,x) \ | ||
393 | ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET); | ||
394 | |||
395 | #define M_ASN1_I2D_len_IMP_SET_type(type,a,f,x) \ | ||
396 | ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ | ||
397 | V_ASN1_CONTEXT_SPECIFIC,IS_SET); | ||
398 | |||
399 | #define M_ASN1_I2D_len_IMP_SET_opt(a,f,x) \ | ||
400 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
401 | ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ | ||
402 | IS_SET); | ||
403 | |||
404 | #define M_ASN1_I2D_len_IMP_SET_opt_type(type,a,f,x) \ | ||
405 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | ||
406 | ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ | ||
407 | V_ASN1_CONTEXT_SPECIFIC,IS_SET); | ||
408 | |||
409 | #define M_ASN1_I2D_len_IMP_SEQUENCE(a,f,x) \ | ||
410 | ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ | ||
411 | IS_SEQUENCE); | ||
412 | |||
413 | #define M_ASN1_I2D_len_IMP_SEQUENCE_opt(a,f,x) \ | ||
414 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
415 | ret+=i2d_ASN1_SET(a,NULL,f,x,V_ASN1_CONTEXT_SPECIFIC, \ | ||
416 | IS_SEQUENCE); | ||
417 | |||
418 | #define M_ASN1_I2D_len_IMP_SEQUENCE_opt_type(type,a,f,x) \ | ||
419 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | ||
420 | ret+=i2d_ASN1_SET_OF_##type(a,NULL,f,x, \ | ||
421 | V_ASN1_CONTEXT_SPECIFIC, \ | ||
422 | IS_SEQUENCE); | ||
423 | |||
424 | #define M_ASN1_I2D_len_EXP_opt(a,f,mtag,v) \ | ||
425 | if (a != NULL)\ | ||
426 | { \ | ||
427 | v=f(a,NULL); \ | ||
428 | ret+=ASN1_object_size(1,v,mtag); \ | ||
429 | } | ||
430 | |||
431 | #define M_ASN1_I2D_len_EXP_SET_opt(a,f,mtag,tag,v) \ | ||
432 | if ((a != NULL) && (sk_num(a) != 0))\ | ||
433 | { \ | ||
434 | v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL,IS_SET); \ | ||
435 | ret+=ASN1_object_size(1,v,mtag); \ | ||
436 | } | ||
437 | |||
438 | #define M_ASN1_I2D_len_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \ | ||
439 | if ((a != NULL) && (sk_num(a) != 0))\ | ||
440 | { \ | ||
441 | v=i2d_ASN1_SET(a,NULL,f,tag,V_ASN1_UNIVERSAL, \ | ||
442 | IS_SEQUENCE); \ | ||
443 | ret+=ASN1_object_size(1,v,mtag); \ | ||
444 | } | ||
445 | |||
446 | #define M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ | ||
447 | if ((a != NULL) && (sk_##type##_num(a) != 0))\ | ||
448 | { \ | ||
449 | v=i2d_ASN1_SET_OF_##type(a,NULL,f,tag, \ | ||
450 | V_ASN1_UNIVERSAL, \ | ||
451 | IS_SEQUENCE); \ | ||
452 | ret+=ASN1_object_size(1,v,mtag); \ | ||
453 | } | ||
454 | |||
455 | /* Put Macros */ | ||
456 | #define M_ASN1_I2D_put(a,f) f(a,&p) | ||
457 | |||
458 | #define M_ASN1_I2D_put_IMP_opt(a,f,t) \ | ||
459 | if (a != NULL) \ | ||
460 | { \ | ||
461 | unsigned char *q=p; \ | ||
462 | f(a,&p); \ | ||
463 | *q=(V_ASN1_CONTEXT_SPECIFIC|t|(*q&V_ASN1_CONSTRUCTED));\ | ||
464 | } | ||
465 | |||
466 | #define M_ASN1_I2D_put_SET(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SET,\ | ||
467 | V_ASN1_UNIVERSAL,IS_SET) | ||
468 | #define M_ASN1_I2D_put_SET_type(type,a,f) \ | ||
469 | i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SET,V_ASN1_UNIVERSAL,IS_SET) | ||
470 | #define M_ASN1_I2D_put_IMP_SET(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ | ||
471 | V_ASN1_CONTEXT_SPECIFIC,IS_SET) | ||
472 | #define M_ASN1_I2D_put_IMP_SET_type(type,a,f,x) \ | ||
473 | i2d_ASN1_SET_OF_##type(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC,IS_SET) | ||
474 | #define M_ASN1_I2D_put_IMP_SEQUENCE(a,f,x) i2d_ASN1_SET(a,&p,f,x,\ | ||
475 | V_ASN1_CONTEXT_SPECIFIC,IS_SEQUENCE) | ||
476 | |||
477 | #define M_ASN1_I2D_put_SEQUENCE(a,f) i2d_ASN1_SET(a,&p,f,V_ASN1_SEQUENCE,\ | ||
478 | V_ASN1_UNIVERSAL,IS_SEQUENCE) | ||
479 | |||
480 | #define M_ASN1_I2D_put_SEQUENCE_type(type,a,f) \ | ||
481 | i2d_ASN1_SET_OF_##type(a,&p,f,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL, \ | ||
482 | IS_SEQUENCE) | ||
483 | |||
484 | #define M_ASN1_I2D_put_SEQUENCE_opt(a,f) \ | ||
485 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
486 | M_ASN1_I2D_put_SEQUENCE(a,f); | ||
487 | |||
488 | #define M_ASN1_I2D_put_IMP_SET_opt(a,f,x) \ | ||
489 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
490 | { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ | ||
491 | IS_SET); } | ||
492 | |||
493 | #define M_ASN1_I2D_put_IMP_SET_opt_type(type,a,f,x) \ | ||
494 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | ||
495 | { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ | ||
496 | V_ASN1_CONTEXT_SPECIFIC, \ | ||
497 | IS_SET); } | ||
498 | |||
499 | #define M_ASN1_I2D_put_IMP_SEQUENCE_opt(a,f,x) \ | ||
500 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
501 | { i2d_ASN1_SET(a,&p,f,x,V_ASN1_CONTEXT_SPECIFIC, \ | ||
502 | IS_SEQUENCE); } | ||
503 | |||
504 | #define M_ASN1_I2D_put_IMP_SEQUENCE_opt_type(type,a,f,x) \ | ||
505 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | ||
506 | { i2d_ASN1_SET_OF_##type(a,&p,f,x, \ | ||
507 | V_ASN1_CONTEXT_SPECIFIC, \ | ||
508 | IS_SEQUENCE); } | ||
509 | |||
510 | #define M_ASN1_I2D_put_EXP_opt(a,f,tag,v) \ | ||
511 | if (a != NULL) \ | ||
512 | { \ | ||
513 | ASN1_put_object(&p,1,v,tag,V_ASN1_CONTEXT_SPECIFIC); \ | ||
514 | f(a,&p); \ | ||
515 | } | ||
516 | |||
517 | #define M_ASN1_I2D_put_EXP_SET_opt(a,f,mtag,tag,v) \ | ||
518 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
519 | { \ | ||
520 | ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ | ||
521 | i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SET); \ | ||
522 | } | ||
523 | |||
524 | #define M_ASN1_I2D_put_EXP_SEQUENCE_opt(a,f,mtag,tag,v) \ | ||
525 | if ((a != NULL) && (sk_num(a) != 0)) \ | ||
526 | { \ | ||
527 | ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ | ||
528 | i2d_ASN1_SET(a,&p,f,tag,V_ASN1_UNIVERSAL,IS_SEQUENCE); \ | ||
529 | } | ||
530 | |||
531 | #define M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(type,a,f,mtag,tag,v) \ | ||
532 | if ((a != NULL) && (sk_##type##_num(a) != 0)) \ | ||
533 | { \ | ||
534 | ASN1_put_object(&p,1,v,mtag,V_ASN1_CONTEXT_SPECIFIC); \ | ||
535 | i2d_ASN1_SET_OF_##type(a,&p,f,tag,V_ASN1_UNIVERSAL, \ | ||
536 | IS_SEQUENCE); \ | ||
537 | } | ||
538 | |||
539 | #define M_ASN1_I2D_seq_total() \ | ||
540 | r=ASN1_object_size(1,ret,V_ASN1_SEQUENCE); \ | ||
541 | if (pp == NULL) return(r); \ | ||
542 | p= *pp; \ | ||
543 | ASN1_put_object(&p,1,ret,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL) | ||
544 | |||
545 | #define M_ASN1_I2D_INF_seq_start(tag,ctx) \ | ||
546 | *(p++)=(V_ASN1_CONSTRUCTED|(tag)|(ctx)); \ | ||
547 | *(p++)=0x80 | ||
548 | |||
549 | #define M_ASN1_I2D_INF_seq_end() *(p++)=0x00; *(p++)=0x00 | ||
550 | |||
551 | #define M_ASN1_I2D_finish() *pp=p; \ | ||
552 | return(r); | ||
553 | |||
554 | int asn1_GetSequence(ASN1_CTX *c, long *length); | ||
555 | void asn1_add_error(unsigned char *address,int offset); | ||
556 | #ifdef __cplusplus | ||
557 | } | ||
558 | #endif | ||
559 | |||
560 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c deleted file mode 100644 index 676d434f03..0000000000 --- a/src/lib/libcrypto/asn1/asn1_par.c +++ /dev/null | |||
@@ -1,418 +0,0 @@ | |||
1 | /* crypto/asn1/asn1_par.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/buffer.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/asn1.h> | ||
64 | |||
65 | static int asn1_print_info(BIO *bp, int tag, int xclass,int constructed, | ||
66 | int indent); | ||
67 | static int asn1_parse2(BIO *bp, unsigned char **pp, long length, | ||
68 | int offset, int depth, int indent, int dump); | ||
69 | static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, | ||
70 | int indent) | ||
71 | { | ||
72 | static const char fmt[]="%-18s"; | ||
73 | static const char fmt2[]="%2d %-15s"; | ||
74 | char str[128]; | ||
75 | const char *p,*p2=NULL; | ||
76 | |||
77 | if (constructed & V_ASN1_CONSTRUCTED) | ||
78 | p="cons: "; | ||
79 | else | ||
80 | p="prim: "; | ||
81 | if (BIO_write(bp,p,6) < 6) goto err; | ||
82 | BIO_indent(bp,indent,128); | ||
83 | |||
84 | p=str; | ||
85 | if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE) | ||
86 | BIO_snprintf(str,sizeof str,"priv [ %d ] ",tag); | ||
87 | else if ((xclass & V_ASN1_CONTEXT_SPECIFIC) == V_ASN1_CONTEXT_SPECIFIC) | ||
88 | BIO_snprintf(str,sizeof str,"cont [ %d ]",tag); | ||
89 | else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) | ||
90 | BIO_snprintf(str,sizeof str,"appl [ %d ]",tag); | ||
91 | else p = ASN1_tag2str(tag); | ||
92 | |||
93 | if (p2 != NULL) | ||
94 | { | ||
95 | if (BIO_printf(bp,fmt2,tag,p2) <= 0) goto err; | ||
96 | } | ||
97 | else | ||
98 | { | ||
99 | if (BIO_printf(bp,fmt,p) <= 0) goto err; | ||
100 | } | ||
101 | return(1); | ||
102 | err: | ||
103 | return(0); | ||
104 | } | ||
105 | |||
106 | int ASN1_parse(BIO *bp, unsigned char *pp, long len, int indent) | ||
107 | { | ||
108 | return(asn1_parse2(bp,&pp,len,0,0,indent,0)); | ||
109 | } | ||
110 | |||
111 | int ASN1_parse_dump(BIO *bp, unsigned char *pp, long len, int indent, int dump) | ||
112 | { | ||
113 | return(asn1_parse2(bp,&pp,len,0,0,indent,dump)); | ||
114 | } | ||
115 | |||
116 | static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset, | ||
117 | int depth, int indent, int dump) | ||
118 | { | ||
119 | unsigned char *p,*ep,*tot,*op,*opp; | ||
120 | long len; | ||
121 | int tag,xclass,ret=0; | ||
122 | int nl,hl,j,r; | ||
123 | ASN1_OBJECT *o=NULL; | ||
124 | ASN1_OCTET_STRING *os=NULL; | ||
125 | /* ASN1_BMPSTRING *bmp=NULL;*/ | ||
126 | int dump_indent; | ||
127 | |||
128 | #if 0 | ||
129 | dump_indent = indent; | ||
130 | #else | ||
131 | dump_indent = 6; /* Because we know BIO_dump_indent() */ | ||
132 | #endif | ||
133 | p= *pp; | ||
134 | tot=p+length; | ||
135 | op=p-1; | ||
136 | while ((p < tot) && (op < p)) | ||
137 | { | ||
138 | op=p; | ||
139 | j=ASN1_get_object(&p,&len,&tag,&xclass,length); | ||
140 | #ifdef LINT | ||
141 | j=j; | ||
142 | #endif | ||
143 | if (j & 0x80) | ||
144 | { | ||
145 | if (BIO_write(bp,"Error in encoding\n",18) <= 0) | ||
146 | goto end; | ||
147 | ret=0; | ||
148 | goto end; | ||
149 | } | ||
150 | hl=(p-op); | ||
151 | length-=hl; | ||
152 | /* if j == 0x21 it is a constructed indefinite length object */ | ||
153 | if (BIO_printf(bp,"%5ld:",(long)offset+(long)(op- *pp)) | ||
154 | <= 0) goto end; | ||
155 | |||
156 | if (j != (V_ASN1_CONSTRUCTED | 1)) | ||
157 | { | ||
158 | if (BIO_printf(bp,"d=%-2d hl=%ld l=%4ld ", | ||
159 | depth,(long)hl,len) <= 0) | ||
160 | goto end; | ||
161 | } | ||
162 | else | ||
163 | { | ||
164 | if (BIO_printf(bp,"d=%-2d hl=%ld l=inf ", | ||
165 | depth,(long)hl) <= 0) | ||
166 | goto end; | ||
167 | } | ||
168 | if (!asn1_print_info(bp,tag,xclass,j,(indent)?depth:0)) | ||
169 | goto end; | ||
170 | if (j & V_ASN1_CONSTRUCTED) | ||
171 | { | ||
172 | ep=p+len; | ||
173 | if (BIO_write(bp,"\n",1) <= 0) goto end; | ||
174 | if (len > length) | ||
175 | { | ||
176 | BIO_printf(bp, | ||
177 | "length is greater than %ld\n",length); | ||
178 | ret=0; | ||
179 | goto end; | ||
180 | } | ||
181 | if ((j == 0x21) && (len == 0)) | ||
182 | { | ||
183 | for (;;) | ||
184 | { | ||
185 | r=asn1_parse2(bp,&p,(long)(tot-p), | ||
186 | offset+(p - *pp),depth+1, | ||
187 | indent,dump); | ||
188 | if (r == 0) { ret=0; goto end; } | ||
189 | if ((r == 2) || (p >= tot)) break; | ||
190 | } | ||
191 | } | ||
192 | else | ||
193 | while (p < ep) | ||
194 | { | ||
195 | r=asn1_parse2(bp,&p,(long)len, | ||
196 | offset+(p - *pp),depth+1, | ||
197 | indent,dump); | ||
198 | if (r == 0) { ret=0; goto end; } | ||
199 | } | ||
200 | } | ||
201 | else if (xclass != 0) | ||
202 | { | ||
203 | p+=len; | ||
204 | if (BIO_write(bp,"\n",1) <= 0) goto end; | ||
205 | } | ||
206 | else | ||
207 | { | ||
208 | nl=0; | ||
209 | if ( (tag == V_ASN1_PRINTABLESTRING) || | ||
210 | (tag == V_ASN1_T61STRING) || | ||
211 | (tag == V_ASN1_IA5STRING) || | ||
212 | (tag == V_ASN1_VISIBLESTRING) || | ||
213 | (tag == V_ASN1_UTCTIME) || | ||
214 | (tag == V_ASN1_GENERALIZEDTIME)) | ||
215 | { | ||
216 | if (BIO_write(bp,":",1) <= 0) goto end; | ||
217 | if ((len > 0) && | ||
218 | BIO_write(bp,(char *)p,(int)len) | ||
219 | != (int)len) | ||
220 | goto end; | ||
221 | } | ||
222 | else if (tag == V_ASN1_OBJECT) | ||
223 | { | ||
224 | opp=op; | ||
225 | if (d2i_ASN1_OBJECT(&o,&opp,len+hl) != NULL) | ||
226 | { | ||
227 | if (BIO_write(bp,":",1) <= 0) goto end; | ||
228 | i2a_ASN1_OBJECT(bp,o); | ||
229 | } | ||
230 | else | ||
231 | { | ||
232 | if (BIO_write(bp,":BAD OBJECT",11) <= 0) | ||
233 | goto end; | ||
234 | } | ||
235 | } | ||
236 | else if (tag == V_ASN1_BOOLEAN) | ||
237 | { | ||
238 | int ii; | ||
239 | |||
240 | opp=op; | ||
241 | ii=d2i_ASN1_BOOLEAN(NULL,&opp,len+hl); | ||
242 | if (ii < 0) | ||
243 | { | ||
244 | if (BIO_write(bp,"Bad boolean\n",12)) | ||
245 | goto end; | ||
246 | } | ||
247 | BIO_printf(bp,":%d",ii); | ||
248 | } | ||
249 | else if (tag == V_ASN1_BMPSTRING) | ||
250 | { | ||
251 | /* do the BMP thang */ | ||
252 | } | ||
253 | else if (tag == V_ASN1_OCTET_STRING) | ||
254 | { | ||
255 | int i,printable=1; | ||
256 | |||
257 | opp=op; | ||
258 | os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl); | ||
259 | if (os != NULL) | ||
260 | { | ||
261 | opp=os->data; | ||
262 | for (i=0; i<os->length; i++) | ||
263 | { | ||
264 | if (( (opp[i] < ' ') && | ||
265 | (opp[i] != '\n') && | ||
266 | (opp[i] != '\r') && | ||
267 | (opp[i] != '\t')) || | ||
268 | (opp[i] > '~')) | ||
269 | { | ||
270 | printable=0; | ||
271 | break; | ||
272 | } | ||
273 | } | ||
274 | if (printable && (os->length > 0)) | ||
275 | { | ||
276 | if (BIO_write(bp,":",1) <= 0) | ||
277 | goto end; | ||
278 | if (BIO_write(bp,(char *)opp, | ||
279 | os->length) <= 0) | ||
280 | goto end; | ||
281 | } | ||
282 | if (!printable && (os->length > 0) | ||
283 | && dump) | ||
284 | { | ||
285 | if (!nl) | ||
286 | { | ||
287 | if (BIO_write(bp,"\n",1) <= 0) | ||
288 | goto end; | ||
289 | } | ||
290 | if (BIO_dump_indent(bp,(char *)opp, | ||
291 | ((dump == -1 || dump > os->length)?os->length:dump), | ||
292 | dump_indent) <= 0) | ||
293 | goto end; | ||
294 | nl=1; | ||
295 | } | ||
296 | M_ASN1_OCTET_STRING_free(os); | ||
297 | os=NULL; | ||
298 | } | ||
299 | } | ||
300 | else if (tag == V_ASN1_INTEGER) | ||
301 | { | ||
302 | ASN1_INTEGER *bs; | ||
303 | int i; | ||
304 | |||
305 | opp=op; | ||
306 | bs=d2i_ASN1_INTEGER(NULL,&opp,len+hl); | ||
307 | if (bs != NULL) | ||
308 | { | ||
309 | if (BIO_write(bp,":",1) <= 0) goto end; | ||
310 | if (bs->type == V_ASN1_NEG_INTEGER) | ||
311 | if (BIO_write(bp,"-",1) <= 0) | ||
312 | goto end; | ||
313 | for (i=0; i<bs->length; i++) | ||
314 | { | ||
315 | if (BIO_printf(bp,"%02X", | ||
316 | bs->data[i]) <= 0) | ||
317 | goto end; | ||
318 | } | ||
319 | if (bs->length == 0) | ||
320 | { | ||
321 | if (BIO_write(bp,"00",2) <= 0) | ||
322 | goto end; | ||
323 | } | ||
324 | } | ||
325 | else | ||
326 | { | ||
327 | if (BIO_write(bp,"BAD INTEGER",11) <= 0) | ||
328 | goto end; | ||
329 | } | ||
330 | M_ASN1_INTEGER_free(bs); | ||
331 | } | ||
332 | else if (tag == V_ASN1_ENUMERATED) | ||
333 | { | ||
334 | ASN1_ENUMERATED *bs; | ||
335 | int i; | ||
336 | |||
337 | opp=op; | ||
338 | bs=d2i_ASN1_ENUMERATED(NULL,&opp,len+hl); | ||
339 | if (bs != NULL) | ||
340 | { | ||
341 | if (BIO_write(bp,":",1) <= 0) goto end; | ||
342 | if (bs->type == V_ASN1_NEG_ENUMERATED) | ||
343 | if (BIO_write(bp,"-",1) <= 0) | ||
344 | goto end; | ||
345 | for (i=0; i<bs->length; i++) | ||
346 | { | ||
347 | if (BIO_printf(bp,"%02X", | ||
348 | bs->data[i]) <= 0) | ||
349 | goto end; | ||
350 | } | ||
351 | if (bs->length == 0) | ||
352 | { | ||
353 | if (BIO_write(bp,"00",2) <= 0) | ||
354 | goto end; | ||
355 | } | ||
356 | } | ||
357 | else | ||
358 | { | ||
359 | if (BIO_write(bp,"BAD ENUMERATED",11) <= 0) | ||
360 | goto end; | ||
361 | } | ||
362 | M_ASN1_ENUMERATED_free(bs); | ||
363 | } | ||
364 | else if (len > 0 && dump) | ||
365 | { | ||
366 | if (!nl) | ||
367 | { | ||
368 | if (BIO_write(bp,"\n",1) <= 0) | ||
369 | goto end; | ||
370 | } | ||
371 | if (BIO_dump_indent(bp,(char *)p, | ||
372 | ((dump == -1 || dump > len)?len:dump), | ||
373 | dump_indent) <= 0) | ||
374 | goto end; | ||
375 | nl=1; | ||
376 | } | ||
377 | |||
378 | if (!nl) | ||
379 | { | ||
380 | if (BIO_write(bp,"\n",1) <= 0) goto end; | ||
381 | } | ||
382 | p+=len; | ||
383 | if ((tag == V_ASN1_EOC) && (xclass == 0)) | ||
384 | { | ||
385 | ret=2; /* End of sequence */ | ||
386 | goto end; | ||
387 | } | ||
388 | } | ||
389 | length-=len; | ||
390 | } | ||
391 | ret=1; | ||
392 | end: | ||
393 | if (o != NULL) ASN1_OBJECT_free(o); | ||
394 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); | ||
395 | *pp=p; | ||
396 | return(ret); | ||
397 | } | ||
398 | |||
399 | const char *ASN1_tag2str(int tag) | ||
400 | { | ||
401 | const static char *tag2str[] = { | ||
402 | "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */ | ||
403 | "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */ | ||
404 | "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */ | ||
405 | "<ASN1 14>", "<ASN1 15>", "SEQUENCE", "SET", /* 15-17 */ | ||
406 | "NUMERICSTRING", "PRINTABLESTRING", "T61STRING", /* 18-20 */ | ||
407 | "VIDEOTEXSTRING", "IA5STRING", "UTCTIME","GENERALIZEDTIME", /* 21-24 */ | ||
408 | "GRAPHICSTRING", "VISIBLESTRING", "GENERALSTRING", /* 25-27 */ | ||
409 | "UNIVERSALSTRING", "<ASN1 29>", "BMPSTRING" /* 28-30 */ | ||
410 | }; | ||
411 | |||
412 | if((tag == V_ASN1_NEG_INTEGER) || (tag == V_ASN1_NEG_ENUMERATED)) | ||
413 | tag &= ~0x100; | ||
414 | |||
415 | if(tag < 0 || tag > 30) return "(unknown)"; | ||
416 | return tag2str[tag]; | ||
417 | } | ||
418 | |||
diff --git a/src/lib/libcrypto/asn1/asn1t.h b/src/lib/libcrypto/asn1/asn1t.h deleted file mode 100644 index ed372f8554..0000000000 --- a/src/lib/libcrypto/asn1/asn1t.h +++ /dev/null | |||
@@ -1,846 +0,0 @@ | |||
1 | /* asn1t.h */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | #ifndef HEADER_ASN1T_H | ||
59 | #define HEADER_ASN1T_H | ||
60 | |||
61 | #include <stddef.h> | ||
62 | #include <openssl/e_os2.h> | ||
63 | #include <openssl/asn1.h> | ||
64 | |||
65 | #ifdef OPENSSL_BUILD_SHLIBCRYPTO | ||
66 | # undef OPENSSL_EXTERN | ||
67 | # define OPENSSL_EXTERN OPENSSL_EXPORT | ||
68 | #endif | ||
69 | |||
70 | /* ASN1 template defines, structures and functions */ | ||
71 | |||
72 | #ifdef __cplusplus | ||
73 | extern "C" { | ||
74 | #endif | ||
75 | |||
76 | |||
77 | #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION | ||
78 | |||
79 | /* Macro to obtain ASN1_ADB pointer from a type (only used internally) */ | ||
80 | #define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr)) | ||
81 | |||
82 | |||
83 | /* Macros for start and end of ASN1_ITEM definition */ | ||
84 | |||
85 | #define ASN1_ITEM_start(itname) \ | ||
86 | OPENSSL_GLOBAL const ASN1_ITEM itname##_it = { | ||
87 | |||
88 | #define ASN1_ITEM_end(itname) \ | ||
89 | }; | ||
90 | |||
91 | #else | ||
92 | |||
93 | /* Macro to obtain ASN1_ADB pointer from a type (only used internally) */ | ||
94 | #define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr())) | ||
95 | |||
96 | |||
97 | /* Macros for start and end of ASN1_ITEM definition */ | ||
98 | |||
99 | #define ASN1_ITEM_start(itname) \ | ||
100 | const ASN1_ITEM * itname##_it(void) \ | ||
101 | { \ | ||
102 | static const ASN1_ITEM local_it = { \ | ||
103 | |||
104 | #define ASN1_ITEM_end(itname) \ | ||
105 | }; \ | ||
106 | return &local_it; \ | ||
107 | } | ||
108 | |||
109 | #endif | ||
110 | |||
111 | |||
112 | /* Macros to aid ASN1 template writing */ | ||
113 | |||
114 | #define ASN1_ITEM_TEMPLATE(tname) \ | ||
115 | const static ASN1_TEMPLATE tname##_item_tt | ||
116 | |||
117 | #define ASN1_ITEM_TEMPLATE_END(tname) \ | ||
118 | ;\ | ||
119 | ASN1_ITEM_start(tname) \ | ||
120 | ASN1_ITYPE_PRIMITIVE,\ | ||
121 | -1,\ | ||
122 | &tname##_item_tt,\ | ||
123 | 0,\ | ||
124 | NULL,\ | ||
125 | 0,\ | ||
126 | #tname \ | ||
127 | ASN1_ITEM_end(tname) | ||
128 | |||
129 | |||
130 | /* This is a ASN1 type which just embeds a template */ | ||
131 | |||
132 | /* This pair helps declare a SEQUENCE. We can do: | ||
133 | * | ||
134 | * ASN1_SEQUENCE(stname) = { | ||
135 | * ... SEQUENCE components ... | ||
136 | * } ASN1_SEQUENCE_END(stname) | ||
137 | * | ||
138 | * This will produce an ASN1_ITEM called stname_it | ||
139 | * for a structure called stname. | ||
140 | * | ||
141 | * If you want the same structure but a different | ||
142 | * name then use: | ||
143 | * | ||
144 | * ASN1_SEQUENCE(itname) = { | ||
145 | * ... SEQUENCE components ... | ||
146 | * } ASN1_SEQUENCE_END_name(stname, itname) | ||
147 | * | ||
148 | * This will create an item called itname_it using | ||
149 | * a structure called stname. | ||
150 | */ | ||
151 | |||
152 | #define ASN1_SEQUENCE(tname) \ | ||
153 | const static ASN1_TEMPLATE tname##_seq_tt[] | ||
154 | |||
155 | #define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname) | ||
156 | |||
157 | #define ASN1_SEQUENCE_END_name(stname, tname) \ | ||
158 | ;\ | ||
159 | ASN1_ITEM_start(tname) \ | ||
160 | ASN1_ITYPE_SEQUENCE,\ | ||
161 | V_ASN1_SEQUENCE,\ | ||
162 | tname##_seq_tt,\ | ||
163 | sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ | ||
164 | NULL,\ | ||
165 | sizeof(stname),\ | ||
166 | #stname \ | ||
167 | ASN1_ITEM_end(tname) | ||
168 | |||
169 | #define ASN1_SEQUENCE_cb(tname, cb) \ | ||
170 | const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ | ||
171 | ASN1_SEQUENCE(tname) | ||
172 | |||
173 | #define ASN1_BROKEN_SEQUENCE(tname) \ | ||
174 | const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \ | ||
175 | ASN1_SEQUENCE(tname) | ||
176 | |||
177 | #define ASN1_SEQUENCE_ref(tname, cb, lck) \ | ||
178 | const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \ | ||
179 | ASN1_SEQUENCE(tname) | ||
180 | |||
181 | #define ASN1_SEQUENCE_enc(tname, enc, cb) \ | ||
182 | const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \ | ||
183 | ASN1_SEQUENCE(tname) | ||
184 | |||
185 | #define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname) | ||
186 | |||
187 | #define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) | ||
188 | |||
189 | #define ASN1_SEQUENCE_END_cb(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) | ||
190 | |||
191 | #define ASN1_SEQUENCE_END_ref(stname, tname) \ | ||
192 | ;\ | ||
193 | ASN1_ITEM_start(tname) \ | ||
194 | ASN1_ITYPE_SEQUENCE,\ | ||
195 | V_ASN1_SEQUENCE,\ | ||
196 | tname##_seq_tt,\ | ||
197 | sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\ | ||
198 | &tname##_aux,\ | ||
199 | sizeof(stname),\ | ||
200 | #stname \ | ||
201 | ASN1_ITEM_end(tname) | ||
202 | |||
203 | |||
204 | /* This pair helps declare a CHOICE type. We can do: | ||
205 | * | ||
206 | * ASN1_CHOICE(chname) = { | ||
207 | * ... CHOICE options ... | ||
208 | * ASN1_CHOICE_END(chname) | ||
209 | * | ||
210 | * This will produce an ASN1_ITEM called chname_it | ||
211 | * for a structure called chname. The structure | ||
212 | * definition must look like this: | ||
213 | * typedef struct { | ||
214 | * int type; | ||
215 | * union { | ||
216 | * ASN1_SOMETHING *opt1; | ||
217 | * ASN1_SOMEOTHER *opt2; | ||
218 | * } value; | ||
219 | * } chname; | ||
220 | * | ||
221 | * the name of the selector must be 'type'. | ||
222 | * to use an alternative selector name use the | ||
223 | * ASN1_CHOICE_END_selector() version. | ||
224 | */ | ||
225 | |||
226 | #define ASN1_CHOICE(tname) \ | ||
227 | const static ASN1_TEMPLATE tname##_ch_tt[] | ||
228 | |||
229 | #define ASN1_CHOICE_cb(tname, cb) \ | ||
230 | const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ | ||
231 | ASN1_CHOICE(tname) | ||
232 | |||
233 | #define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname) | ||
234 | |||
235 | #define ASN1_CHOICE_END_name(stname, tname) ASN1_CHOICE_END_selector(stname, tname, type) | ||
236 | |||
237 | #define ASN1_CHOICE_END_selector(stname, tname, selname) \ | ||
238 | ;\ | ||
239 | ASN1_ITEM_start(tname) \ | ||
240 | ASN1_ITYPE_CHOICE,\ | ||
241 | offsetof(stname,selname) ,\ | ||
242 | tname##_ch_tt,\ | ||
243 | sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ | ||
244 | NULL,\ | ||
245 | sizeof(stname),\ | ||
246 | #stname \ | ||
247 | ASN1_ITEM_end(tname) | ||
248 | |||
249 | #define ASN1_CHOICE_END_cb(stname, tname, selname) \ | ||
250 | ;\ | ||
251 | ASN1_ITEM_start(tname) \ | ||
252 | ASN1_ITYPE_CHOICE,\ | ||
253 | offsetof(stname,selname) ,\ | ||
254 | tname##_ch_tt,\ | ||
255 | sizeof(tname##_ch_tt) / sizeof(ASN1_TEMPLATE),\ | ||
256 | &tname##_aux,\ | ||
257 | sizeof(stname),\ | ||
258 | #stname \ | ||
259 | ASN1_ITEM_end(tname) | ||
260 | |||
261 | /* This helps with the template wrapper form of ASN1_ITEM */ | ||
262 | |||
263 | #define ASN1_EX_TEMPLATE_TYPE(flags, tag, name, type) { \ | ||
264 | (flags), (tag), 0,\ | ||
265 | #name, ASN1_ITEM_ref(type) } | ||
266 | |||
267 | /* These help with SEQUENCE or CHOICE components */ | ||
268 | |||
269 | /* used to declare other types */ | ||
270 | |||
271 | #define ASN1_EX_TYPE(flags, tag, stname, field, type) { \ | ||
272 | (flags), (tag), offsetof(stname, field),\ | ||
273 | #field, ASN1_ITEM_ref(type) } | ||
274 | |||
275 | /* used when the structure is combined with the parent */ | ||
276 | |||
277 | #define ASN1_EX_COMBINE(flags, tag, type) { \ | ||
278 | (flags)|ASN1_TFLG_COMBINE, (tag), 0, NULL, ASN1_ITEM_ref(type) } | ||
279 | |||
280 | /* implicit and explicit helper macros */ | ||
281 | |||
282 | #define ASN1_IMP_EX(stname, field, type, tag, ex) \ | ||
283 | ASN1_EX_TYPE(ASN1_TFLG_IMPLICIT | ex, tag, stname, field, type) | ||
284 | |||
285 | #define ASN1_EXP_EX(stname, field, type, tag, ex) \ | ||
286 | ASN1_EX_TYPE(ASN1_TFLG_EXPLICIT | ex, tag, stname, field, type) | ||
287 | |||
288 | /* Any defined by macros: the field used is in the table itself */ | ||
289 | |||
290 | #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION | ||
291 | #define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } | ||
292 | #define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) } | ||
293 | #else | ||
294 | #define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, tblname##_adb } | ||
295 | #define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, tblname##_adb } | ||
296 | #endif | ||
297 | /* Plain simple type */ | ||
298 | #define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type) | ||
299 | |||
300 | /* OPTIONAL simple type */ | ||
301 | #define ASN1_OPT(stname, field, type) ASN1_EX_TYPE(ASN1_TFLG_OPTIONAL, 0, stname, field, type) | ||
302 | |||
303 | /* IMPLICIT tagged simple type */ | ||
304 | #define ASN1_IMP(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, 0) | ||
305 | |||
306 | /* IMPLICIT tagged OPTIONAL simple type */ | ||
307 | #define ASN1_IMP_OPT(stname, field, type, tag) ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) | ||
308 | |||
309 | /* Same as above but EXPLICIT */ | ||
310 | |||
311 | #define ASN1_EXP(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, 0) | ||
312 | #define ASN1_EXP_OPT(stname, field, type, tag) ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL) | ||
313 | |||
314 | /* SEQUENCE OF type */ | ||
315 | #define ASN1_SEQUENCE_OF(stname, field, type) \ | ||
316 | ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, stname, field, type) | ||
317 | |||
318 | /* OPTIONAL SEQUENCE OF */ | ||
319 | #define ASN1_SEQUENCE_OF_OPT(stname, field, type) \ | ||
320 | ASN1_EX_TYPE(ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) | ||
321 | |||
322 | /* Same as above but for SET OF */ | ||
323 | |||
324 | #define ASN1_SET_OF(stname, field, type) \ | ||
325 | ASN1_EX_TYPE(ASN1_TFLG_SET_OF, 0, stname, field, type) | ||
326 | |||
327 | #define ASN1_SET_OF_OPT(stname, field, type) \ | ||
328 | ASN1_EX_TYPE(ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL, 0, stname, field, type) | ||
329 | |||
330 | /* Finally compound types of SEQUENCE, SET, IMPLICIT, EXPLICIT and OPTIONAL */ | ||
331 | |||
332 | #define ASN1_IMP_SET_OF(stname, field, type, tag) \ | ||
333 | ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) | ||
334 | |||
335 | #define ASN1_EXP_SET_OF(stname, field, type, tag) \ | ||
336 | ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF) | ||
337 | |||
338 | #define ASN1_IMP_SET_OF_OPT(stname, field, type, tag) \ | ||
339 | ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) | ||
340 | |||
341 | #define ASN1_EXP_SET_OF_OPT(stname, field, type, tag) \ | ||
342 | ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SET_OF|ASN1_TFLG_OPTIONAL) | ||
343 | |||
344 | #define ASN1_IMP_SEQUENCE_OF(stname, field, type, tag) \ | ||
345 | ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) | ||
346 | |||
347 | #define ASN1_IMP_SEQUENCE_OF_OPT(stname, field, type, tag) \ | ||
348 | ASN1_IMP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) | ||
349 | |||
350 | #define ASN1_EXP_SEQUENCE_OF(stname, field, type, tag) \ | ||
351 | ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF) | ||
352 | |||
353 | #define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \ | ||
354 | ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) | ||
355 | |||
356 | /* Macros for the ASN1_ADB structure */ | ||
357 | |||
358 | #define ASN1_ADB(name) \ | ||
359 | const static ASN1_ADB_TABLE name##_adbtbl[] | ||
360 | |||
361 | #ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION | ||
362 | |||
363 | #define ASN1_ADB_END(name, flags, field, app_table, def, none) \ | ||
364 | ;\ | ||
365 | const static ASN1_ADB name##_adb = {\ | ||
366 | flags,\ | ||
367 | offsetof(name, field),\ | ||
368 | app_table,\ | ||
369 | name##_adbtbl,\ | ||
370 | sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ | ||
371 | def,\ | ||
372 | none\ | ||
373 | } | ||
374 | |||
375 | #else | ||
376 | |||
377 | #define ASN1_ADB_END(name, flags, field, app_table, def, none) \ | ||
378 | ;\ | ||
379 | const static ASN1_ITEM *name##_adb(void) \ | ||
380 | { \ | ||
381 | const static ASN1_ADB internal_adb = \ | ||
382 | {\ | ||
383 | flags,\ | ||
384 | offsetof(name, field),\ | ||
385 | app_table,\ | ||
386 | name##_adbtbl,\ | ||
387 | sizeof(name##_adbtbl) / sizeof(ASN1_ADB_TABLE),\ | ||
388 | def,\ | ||
389 | none\ | ||
390 | }; \ | ||
391 | return (const ASN1_ITEM *) &internal_adb; \ | ||
392 | } \ | ||
393 | void dummy_function(void) | ||
394 | |||
395 | #endif | ||
396 | |||
397 | #define ADB_ENTRY(val, template) {val, template} | ||
398 | |||
399 | #define ASN1_ADB_TEMPLATE(name) \ | ||
400 | const static ASN1_TEMPLATE name##_tt | ||
401 | |||
402 | /* This is the ASN1 template structure that defines | ||
403 | * a wrapper round the actual type. It determines the | ||
404 | * actual position of the field in the value structure, | ||
405 | * various flags such as OPTIONAL and the field name. | ||
406 | */ | ||
407 | |||
408 | struct ASN1_TEMPLATE_st { | ||
409 | unsigned long flags; /* Various flags */ | ||
410 | long tag; /* tag, not used if no tagging */ | ||
411 | unsigned long offset; /* Offset of this field in structure */ | ||
412 | #ifndef NO_ASN1_FIELD_NAMES | ||
413 | char *field_name; /* Field name */ | ||
414 | #endif | ||
415 | ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */ | ||
416 | }; | ||
417 | |||
418 | /* Macro to extract ASN1_ITEM and ASN1_ADB pointer from ASN1_TEMPLATE */ | ||
419 | |||
420 | #define ASN1_TEMPLATE_item(t) (t->item_ptr) | ||
421 | #define ASN1_TEMPLATE_adb(t) (t->item_ptr) | ||
422 | |||
423 | typedef struct ASN1_ADB_TABLE_st ASN1_ADB_TABLE; | ||
424 | typedef struct ASN1_ADB_st ASN1_ADB; | ||
425 | |||
426 | struct ASN1_ADB_st { | ||
427 | unsigned long flags; /* Various flags */ | ||
428 | unsigned long offset; /* Offset of selector field */ | ||
429 | STACK_OF(ASN1_ADB_TABLE) **app_items; /* Application defined items */ | ||
430 | const ASN1_ADB_TABLE *tbl; /* Table of possible types */ | ||
431 | long tblcount; /* Number of entries in tbl */ | ||
432 | const ASN1_TEMPLATE *default_tt; /* Type to use if no match */ | ||
433 | const ASN1_TEMPLATE *null_tt; /* Type to use if selector is NULL */ | ||
434 | }; | ||
435 | |||
436 | struct ASN1_ADB_TABLE_st { | ||
437 | long value; /* NID for an object or value for an int */ | ||
438 | const ASN1_TEMPLATE tt; /* item for this value */ | ||
439 | }; | ||
440 | |||
441 | /* template flags */ | ||
442 | |||
443 | /* Field is optional */ | ||
444 | #define ASN1_TFLG_OPTIONAL (0x1) | ||
445 | |||
446 | /* Field is a SET OF */ | ||
447 | #define ASN1_TFLG_SET_OF (0x1 << 1) | ||
448 | |||
449 | /* Field is a SEQUENCE OF */ | ||
450 | #define ASN1_TFLG_SEQUENCE_OF (0x2 << 1) | ||
451 | |||
452 | /* Special case: this refers to a SET OF that | ||
453 | * will be sorted into DER order when encoded *and* | ||
454 | * the corresponding STACK will be modified to match | ||
455 | * the new order. | ||
456 | */ | ||
457 | #define ASN1_TFLG_SET_ORDER (0x3 << 1) | ||
458 | |||
459 | /* Mask for SET OF or SEQUENCE OF */ | ||
460 | #define ASN1_TFLG_SK_MASK (0x3 << 1) | ||
461 | |||
462 | /* These flags mean the tag should be taken from the | ||
463 | * tag field. If EXPLICIT then the underlying type | ||
464 | * is used for the inner tag. | ||
465 | */ | ||
466 | |||
467 | /* IMPLICIT tagging */ | ||
468 | #define ASN1_TFLG_IMPTAG (0x1 << 3) | ||
469 | |||
470 | |||
471 | /* EXPLICIT tagging, inner tag from underlying type */ | ||
472 | #define ASN1_TFLG_EXPTAG (0x2 << 3) | ||
473 | |||
474 | #define ASN1_TFLG_TAG_MASK (0x3 << 3) | ||
475 | |||
476 | /* context specific IMPLICIT */ | ||
477 | #define ASN1_TFLG_IMPLICIT ASN1_TFLG_IMPTAG|ASN1_TFLG_CONTEXT | ||
478 | |||
479 | /* context specific EXPLICIT */ | ||
480 | #define ASN1_TFLG_EXPLICIT ASN1_TFLG_EXPTAG|ASN1_TFLG_CONTEXT | ||
481 | |||
482 | /* If tagging is in force these determine the | ||
483 | * type of tag to use. Otherwise the tag is | ||
484 | * determined by the underlying type. These | ||
485 | * values reflect the actual octet format. | ||
486 | */ | ||
487 | |||
488 | /* Universal tag */ | ||
489 | #define ASN1_TFLG_UNIVERSAL (0x0<<6) | ||
490 | /* Application tag */ | ||
491 | #define ASN1_TFLG_APPLICATION (0x1<<6) | ||
492 | /* Context specific tag */ | ||
493 | #define ASN1_TFLG_CONTEXT (0x2<<6) | ||
494 | /* Private tag */ | ||
495 | #define ASN1_TFLG_PRIVATE (0x3<<6) | ||
496 | |||
497 | #define ASN1_TFLG_TAG_CLASS (0x3<<6) | ||
498 | |||
499 | /* These are for ANY DEFINED BY type. In this case | ||
500 | * the 'item' field points to an ASN1_ADB structure | ||
501 | * which contains a table of values to decode the | ||
502 | * relevant type | ||
503 | */ | ||
504 | |||
505 | #define ASN1_TFLG_ADB_MASK (0x3<<8) | ||
506 | |||
507 | #define ASN1_TFLG_ADB_OID (0x1<<8) | ||
508 | |||
509 | #define ASN1_TFLG_ADB_INT (0x1<<9) | ||
510 | |||
511 | /* This flag means a parent structure is passed | ||
512 | * instead of the field: this is useful is a | ||
513 | * SEQUENCE is being combined with a CHOICE for | ||
514 | * example. Since this means the structure and | ||
515 | * item name will differ we need to use the | ||
516 | * ASN1_CHOICE_END_name() macro for example. | ||
517 | */ | ||
518 | |||
519 | #define ASN1_TFLG_COMBINE (0x1<<10) | ||
520 | |||
521 | /* This is the actual ASN1 item itself */ | ||
522 | |||
523 | struct ASN1_ITEM_st { | ||
524 | char itype; /* The item type, primitive, SEQUENCE, CHOICE or extern */ | ||
525 | long utype; /* underlying type */ | ||
526 | const ASN1_TEMPLATE *templates; /* If SEQUENCE or CHOICE this contains the contents */ | ||
527 | long tcount; /* Number of templates if SEQUENCE or CHOICE */ | ||
528 | const void *funcs; /* functions that handle this type */ | ||
529 | long size; /* Structure size (usually)*/ | ||
530 | #ifndef NO_ASN1_FIELD_NAMES | ||
531 | const char *sname; /* Structure name */ | ||
532 | #endif | ||
533 | }; | ||
534 | |||
535 | /* These are values for the itype field and | ||
536 | * determine how the type is interpreted. | ||
537 | * | ||
538 | * For PRIMITIVE types the underlying type | ||
539 | * determines the behaviour if items is NULL. | ||
540 | * | ||
541 | * Otherwise templates must contain a single | ||
542 | * template and the type is treated in the | ||
543 | * same way as the type specified in the template. | ||
544 | * | ||
545 | * For SEQUENCE types the templates field points | ||
546 | * to the members, the size field is the | ||
547 | * structure size. | ||
548 | * | ||
549 | * For CHOICE types the templates field points | ||
550 | * to each possible member (typically a union) | ||
551 | * and the 'size' field is the offset of the | ||
552 | * selector. | ||
553 | * | ||
554 | * The 'funcs' field is used for application | ||
555 | * specific functions. | ||
556 | * | ||
557 | * For COMPAT types the funcs field gives a | ||
558 | * set of functions that handle this type, this | ||
559 | * supports the old d2i, i2d convention. | ||
560 | * | ||
561 | * The EXTERN type uses a new style d2i/i2d. | ||
562 | * The new style should be used where possible | ||
563 | * because it avoids things like the d2i IMPLICIT | ||
564 | * hack. | ||
565 | * | ||
566 | * MSTRING is a multiple string type, it is used | ||
567 | * for a CHOICE of character strings where the | ||
568 | * actual strings all occupy an ASN1_STRING | ||
569 | * structure. In this case the 'utype' field | ||
570 | * has a special meaning, it is used as a mask | ||
571 | * of acceptable types using the B_ASN1 constants. | ||
572 | * | ||
573 | */ | ||
574 | |||
575 | #define ASN1_ITYPE_PRIMITIVE 0x0 | ||
576 | |||
577 | #define ASN1_ITYPE_SEQUENCE 0x1 | ||
578 | |||
579 | #define ASN1_ITYPE_CHOICE 0x2 | ||
580 | |||
581 | #define ASN1_ITYPE_COMPAT 0x3 | ||
582 | |||
583 | #define ASN1_ITYPE_EXTERN 0x4 | ||
584 | |||
585 | #define ASN1_ITYPE_MSTRING 0x5 | ||
586 | |||
587 | /* Cache for ASN1 tag and length, so we | ||
588 | * don't keep re-reading it for things | ||
589 | * like CHOICE | ||
590 | */ | ||
591 | |||
592 | struct ASN1_TLC_st{ | ||
593 | char valid; /* Values below are valid */ | ||
594 | int ret; /* return value */ | ||
595 | long plen; /* length */ | ||
596 | int ptag; /* class value */ | ||
597 | int pclass; /* class value */ | ||
598 | int hdrlen; /* header length */ | ||
599 | }; | ||
600 | |||
601 | /* Typedefs for ASN1 function pointers */ | ||
602 | |||
603 | typedef ASN1_VALUE * ASN1_new_func(void); | ||
604 | typedef void ASN1_free_func(ASN1_VALUE *a); | ||
605 | typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, unsigned char ** in, long length); | ||
606 | typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in); | ||
607 | |||
608 | typedef int ASN1_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it, | ||
609 | int tag, int aclass, char opt, ASN1_TLC *ctx); | ||
610 | |||
611 | typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); | ||
612 | typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
613 | typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
614 | |||
615 | typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); | ||
616 | typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); | ||
617 | |||
618 | typedef struct ASN1_COMPAT_FUNCS_st { | ||
619 | ASN1_new_func *asn1_new; | ||
620 | ASN1_free_func *asn1_free; | ||
621 | ASN1_d2i_func *asn1_d2i; | ||
622 | ASN1_i2d_func *asn1_i2d; | ||
623 | } ASN1_COMPAT_FUNCS; | ||
624 | |||
625 | typedef struct ASN1_EXTERN_FUNCS_st { | ||
626 | void *app_data; | ||
627 | ASN1_ex_new_func *asn1_ex_new; | ||
628 | ASN1_ex_free_func *asn1_ex_free; | ||
629 | ASN1_ex_free_func *asn1_ex_clear; | ||
630 | ASN1_ex_d2i *asn1_ex_d2i; | ||
631 | ASN1_ex_i2d *asn1_ex_i2d; | ||
632 | } ASN1_EXTERN_FUNCS; | ||
633 | |||
634 | typedef struct ASN1_PRIMITIVE_FUNCS_st { | ||
635 | void *app_data; | ||
636 | unsigned long flags; | ||
637 | ASN1_ex_new_func *prim_new; | ||
638 | ASN1_ex_free_func *prim_free; | ||
639 | ASN1_ex_free_func *prim_clear; | ||
640 | ASN1_primitive_c2i *prim_c2i; | ||
641 | ASN1_primitive_i2c *prim_i2c; | ||
642 | } ASN1_PRIMITIVE_FUNCS; | ||
643 | |||
644 | /* This is the ASN1_AUX structure: it handles various | ||
645 | * miscellaneous requirements. For example the use of | ||
646 | * reference counts and an informational callback. | ||
647 | * | ||
648 | * The "informational callback" is called at various | ||
649 | * points during the ASN1 encoding and decoding. It can | ||
650 | * be used to provide minor customisation of the structures | ||
651 | * used. This is most useful where the supplied routines | ||
652 | * *almost* do the right thing but need some extra help | ||
653 | * at a few points. If the callback returns zero then | ||
654 | * it is assumed a fatal error has occurred and the | ||
655 | * main operation should be abandoned. | ||
656 | * | ||
657 | * If major changes in the default behaviour are required | ||
658 | * then an external type is more appropriate. | ||
659 | */ | ||
660 | |||
661 | typedef int ASN1_aux_cb(int operation, ASN1_VALUE **in, const ASN1_ITEM *it); | ||
662 | |||
663 | typedef struct ASN1_AUX_st { | ||
664 | void *app_data; | ||
665 | int flags; | ||
666 | int ref_offset; /* Offset of reference value */ | ||
667 | int ref_lock; /* Lock type to use */ | ||
668 | ASN1_aux_cb *asn1_cb; | ||
669 | int enc_offset; /* Offset of ASN1_ENCODING structure */ | ||
670 | } ASN1_AUX; | ||
671 | |||
672 | /* Flags in ASN1_AUX */ | ||
673 | |||
674 | /* Use a reference count */ | ||
675 | #define ASN1_AFLG_REFCOUNT 1 | ||
676 | /* Save the encoding of structure (useful for signatures) */ | ||
677 | #define ASN1_AFLG_ENCODING 2 | ||
678 | /* The Sequence length is invalid */ | ||
679 | #define ASN1_AFLG_BROKEN 4 | ||
680 | |||
681 | /* operation values for asn1_cb */ | ||
682 | |||
683 | #define ASN1_OP_NEW_PRE 0 | ||
684 | #define ASN1_OP_NEW_POST 1 | ||
685 | #define ASN1_OP_FREE_PRE 2 | ||
686 | #define ASN1_OP_FREE_POST 3 | ||
687 | #define ASN1_OP_D2I_PRE 4 | ||
688 | #define ASN1_OP_D2I_POST 5 | ||
689 | #define ASN1_OP_I2D_PRE 6 | ||
690 | #define ASN1_OP_I2D_POST 7 | ||
691 | |||
692 | /* Macro to implement a primitive type */ | ||
693 | #define IMPLEMENT_ASN1_TYPE(stname) IMPLEMENT_ASN1_TYPE_ex(stname, stname, 0) | ||
694 | #define IMPLEMENT_ASN1_TYPE_ex(itname, vname, ex) \ | ||
695 | ASN1_ITEM_start(itname) \ | ||
696 | ASN1_ITYPE_PRIMITIVE, V_##vname, NULL, 0, NULL, ex, #itname \ | ||
697 | ASN1_ITEM_end(itname) | ||
698 | |||
699 | /* Macro to implement a multi string type */ | ||
700 | #define IMPLEMENT_ASN1_MSTRING(itname, mask) \ | ||
701 | ASN1_ITEM_start(itname) \ | ||
702 | ASN1_ITYPE_MSTRING, mask, NULL, 0, NULL, sizeof(ASN1_STRING), #itname \ | ||
703 | ASN1_ITEM_end(itname) | ||
704 | |||
705 | /* Macro to implement an ASN1_ITEM in terms of old style funcs */ | ||
706 | |||
707 | #define IMPLEMENT_COMPAT_ASN1(sname) IMPLEMENT_COMPAT_ASN1_type(sname, V_ASN1_SEQUENCE) | ||
708 | |||
709 | #define IMPLEMENT_COMPAT_ASN1_type(sname, tag) \ | ||
710 | static const ASN1_COMPAT_FUNCS sname##_ff = { \ | ||
711 | (ASN1_new_func *)sname##_new, \ | ||
712 | (ASN1_free_func *)sname##_free, \ | ||
713 | (ASN1_d2i_func *)d2i_##sname, \ | ||
714 | (ASN1_i2d_func *)i2d_##sname, \ | ||
715 | }; \ | ||
716 | ASN1_ITEM_start(sname) \ | ||
717 | ASN1_ITYPE_COMPAT, \ | ||
718 | tag, \ | ||
719 | NULL, \ | ||
720 | 0, \ | ||
721 | &sname##_ff, \ | ||
722 | 0, \ | ||
723 | #sname \ | ||
724 | ASN1_ITEM_end(sname) | ||
725 | |||
726 | #define IMPLEMENT_EXTERN_ASN1(sname, tag, fptrs) \ | ||
727 | ASN1_ITEM_start(sname) \ | ||
728 | ASN1_ITYPE_EXTERN, \ | ||
729 | tag, \ | ||
730 | NULL, \ | ||
731 | 0, \ | ||
732 | &fptrs, \ | ||
733 | 0, \ | ||
734 | #sname \ | ||
735 | ASN1_ITEM_end(sname) | ||
736 | |||
737 | /* Macro to implement standard functions in terms of ASN1_ITEM structures */ | ||
738 | |||
739 | #define IMPLEMENT_ASN1_FUNCTIONS(stname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, stname, stname) | ||
740 | |||
741 | #define IMPLEMENT_ASN1_FUNCTIONS_name(stname, itname) IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, itname) | ||
742 | |||
743 | #define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \ | ||
744 | IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname) | ||
745 | |||
746 | #define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \ | ||
747 | stname *fname##_new(void) \ | ||
748 | { \ | ||
749 | return (stname *)ASN1_item_new(ASN1_ITEM_rptr(itname)); \ | ||
750 | } \ | ||
751 | void fname##_free(stname *a) \ | ||
752 | { \ | ||
753 | ASN1_item_free((ASN1_VALUE *)a, ASN1_ITEM_rptr(itname)); \ | ||
754 | } | ||
755 | |||
756 | #define IMPLEMENT_ASN1_FUNCTIONS_fname(stname, itname, fname) \ | ||
757 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ | ||
758 | IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) | ||
759 | |||
760 | #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ | ||
761 | stname *d2i_##fname(stname **a, unsigned char **in, long len) \ | ||
762 | { \ | ||
763 | return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ | ||
764 | } \ | ||
765 | int i2d_##fname(stname *a, unsigned char **out) \ | ||
766 | { \ | ||
767 | return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ | ||
768 | } | ||
769 | |||
770 | /* This includes evil casts to remove const: they will go away when full | ||
771 | * ASN1 constification is done. | ||
772 | */ | ||
773 | #define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ | ||
774 | stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ | ||
775 | { \ | ||
776 | return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, (unsigned char **)in, len, ASN1_ITEM_rptr(itname));\ | ||
777 | } \ | ||
778 | int i2d_##fname(const stname *a, unsigned char **out) \ | ||
779 | { \ | ||
780 | return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ | ||
781 | } | ||
782 | |||
783 | #define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \ | ||
784 | stname * stname##_dup(stname *x) \ | ||
785 | { \ | ||
786 | return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \ | ||
787 | } | ||
788 | |||
789 | #define IMPLEMENT_ASN1_FUNCTIONS_const(name) \ | ||
790 | IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name) | ||
791 | |||
792 | #define IMPLEMENT_ASN1_FUNCTIONS_const_fname(stname, itname, fname) \ | ||
793 | IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ | ||
794 | IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) | ||
795 | |||
796 | /* external definitions for primitive types */ | ||
797 | |||
798 | DECLARE_ASN1_ITEM(ASN1_BOOLEAN) | ||
799 | DECLARE_ASN1_ITEM(ASN1_TBOOLEAN) | ||
800 | DECLARE_ASN1_ITEM(ASN1_FBOOLEAN) | ||
801 | DECLARE_ASN1_ITEM(ASN1_ANY) | ||
802 | DECLARE_ASN1_ITEM(ASN1_SEQUENCE) | ||
803 | DECLARE_ASN1_ITEM(CBIGNUM) | ||
804 | DECLARE_ASN1_ITEM(BIGNUM) | ||
805 | DECLARE_ASN1_ITEM(LONG) | ||
806 | DECLARE_ASN1_ITEM(ZLONG) | ||
807 | |||
808 | DECLARE_STACK_OF(ASN1_VALUE) | ||
809 | |||
810 | /* Functions used internally by the ASN1 code */ | ||
811 | |||
812 | int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
813 | void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
814 | int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); | ||
815 | int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
816 | |||
817 | void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); | ||
818 | int ASN1_template_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt); | ||
819 | int ASN1_item_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it, | ||
820 | int tag, int aclass, char opt, ASN1_TLC *ctx); | ||
821 | |||
822 | int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); | ||
823 | int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt); | ||
824 | void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
825 | |||
826 | int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); | ||
827 | int asn1_ex_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); | ||
828 | |||
829 | int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
830 | int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it); | ||
831 | |||
832 | ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); | ||
833 | |||
834 | const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr); | ||
835 | |||
836 | int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it); | ||
837 | |||
838 | void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
839 | void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
840 | int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
841 | int asn1_enc_save(ASN1_VALUE **pval, unsigned char *in, int inlen, const ASN1_ITEM *it); | ||
842 | |||
843 | #ifdef __cplusplus | ||
844 | } | ||
845 | #endif | ||
846 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/asn_moid.c b/src/lib/libcrypto/asn1/asn_moid.c deleted file mode 100644 index edb44c988f..0000000000 --- a/src/lib/libcrypto/asn1/asn_moid.c +++ /dev/null | |||
@@ -1,100 +0,0 @@ | |||
1 | /* asn_moid.c */ | ||
2 | /* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2001. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <openssl/crypto.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/conf.h> | ||
63 | #include <openssl/dso.h> | ||
64 | #include <openssl/x509.h> | ||
65 | |||
66 | /* Simple ASN1 OID module: add all objects in a given section */ | ||
67 | |||
68 | static int oid_module_init(CONF_IMODULE *md, const CONF *cnf) | ||
69 | { | ||
70 | int i; | ||
71 | const char *oid_section; | ||
72 | STACK_OF(CONF_VALUE) *sktmp; | ||
73 | CONF_VALUE *oval; | ||
74 | oid_section = CONF_imodule_get_value(md); | ||
75 | if(!(sktmp = NCONF_get_section(cnf, oid_section))) | ||
76 | { | ||
77 | ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ERROR_LOADING_SECTION); | ||
78 | return 0; | ||
79 | } | ||
80 | for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) | ||
81 | { | ||
82 | oval = sk_CONF_VALUE_value(sktmp, i); | ||
83 | if(OBJ_create(oval->value, oval->name, oval->name) == NID_undef) | ||
84 | { | ||
85 | ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT); | ||
86 | return 0; | ||
87 | } | ||
88 | } | ||
89 | return 1; | ||
90 | } | ||
91 | |||
92 | static void oid_module_finish(CONF_IMODULE *md) | ||
93 | { | ||
94 | OBJ_cleanup(); | ||
95 | } | ||
96 | |||
97 | void ASN1_add_oid_module(void) | ||
98 | { | ||
99 | CONF_module_add("oid_section", oid_module_init, oid_module_finish); | ||
100 | } | ||
diff --git a/src/lib/libcrypto/asn1/asn_pack.c b/src/lib/libcrypto/asn1/asn_pack.c deleted file mode 100644 index e6051db2dc..0000000000 --- a/src/lib/libcrypto/asn1/asn_pack.c +++ /dev/null | |||
@@ -1,191 +0,0 @@ | |||
1 | /* asn_pack.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1.h> | ||
62 | |||
63 | #ifndef NO_ASN1_OLD | ||
64 | |||
65 | /* ASN1 packing and unpacking functions */ | ||
66 | |||
67 | /* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */ | ||
68 | |||
69 | STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(), | ||
70 | void (*free_func)(void *)) | ||
71 | { | ||
72 | STACK *sk; | ||
73 | unsigned char *pbuf; | ||
74 | pbuf = buf; | ||
75 | if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func, | ||
76 | V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL))) | ||
77 | ASN1err(ASN1_F_ASN1_SEQ_UNPACK,ASN1_R_DECODE_ERROR); | ||
78 | return sk; | ||
79 | } | ||
80 | |||
81 | /* Turn a STACK structures into an ASN1 encoded SEQUENCE OF structure in a | ||
82 | * OPENSSL_malloc'ed buffer | ||
83 | */ | ||
84 | |||
85 | unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf, | ||
86 | int *len) | ||
87 | { | ||
88 | int safelen; | ||
89 | unsigned char *safe, *p; | ||
90 | if (!(safelen = i2d_ASN1_SET(safes, NULL, i2d, V_ASN1_SEQUENCE, | ||
91 | V_ASN1_UNIVERSAL, IS_SEQUENCE))) { | ||
92 | ASN1err(ASN1_F_ASN1_SEQ_PACK,ASN1_R_ENCODE_ERROR); | ||
93 | return NULL; | ||
94 | } | ||
95 | if (!(safe = OPENSSL_malloc (safelen))) { | ||
96 | ASN1err(ASN1_F_ASN1_SEQ_PACK,ERR_R_MALLOC_FAILURE); | ||
97 | return NULL; | ||
98 | } | ||
99 | p = safe; | ||
100 | i2d_ASN1_SET(safes, &p, i2d, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, | ||
101 | IS_SEQUENCE); | ||
102 | if (len) *len = safelen; | ||
103 | if (buf) *buf = safe; | ||
104 | return safe; | ||
105 | } | ||
106 | |||
107 | /* Extract an ASN1 object from an ASN1_STRING */ | ||
108 | |||
109 | void *ASN1_unpack_string (ASN1_STRING *oct, char *(*d2i)()) | ||
110 | { | ||
111 | unsigned char *p; | ||
112 | char *ret; | ||
113 | |||
114 | p = oct->data; | ||
115 | if(!(ret = d2i(NULL, &p, oct->length))) | ||
116 | ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR); | ||
117 | return ret; | ||
118 | } | ||
119 | |||
120 | /* Pack an ASN1 object into an ASN1_STRING */ | ||
121 | |||
122 | ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_STRING **oct) | ||
123 | { | ||
124 | unsigned char *p; | ||
125 | ASN1_STRING *octmp; | ||
126 | |||
127 | if (!oct || !*oct) { | ||
128 | if (!(octmp = ASN1_STRING_new ())) { | ||
129 | ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE); | ||
130 | return NULL; | ||
131 | } | ||
132 | if (oct) *oct = octmp; | ||
133 | } else octmp = *oct; | ||
134 | |||
135 | if (!(octmp->length = i2d(obj, NULL))) { | ||
136 | ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR); | ||
137 | return NULL; | ||
138 | } | ||
139 | if (!(p = OPENSSL_malloc (octmp->length))) { | ||
140 | ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE); | ||
141 | return NULL; | ||
142 | } | ||
143 | octmp->data = p; | ||
144 | i2d (obj, &p); | ||
145 | return octmp; | ||
146 | } | ||
147 | |||
148 | #endif | ||
149 | |||
150 | /* ASN1_ITEM versions of the above */ | ||
151 | |||
152 | ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct) | ||
153 | { | ||
154 | ASN1_STRING *octmp; | ||
155 | |||
156 | if (!oct || !*oct) { | ||
157 | if (!(octmp = ASN1_STRING_new ())) { | ||
158 | ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE); | ||
159 | return NULL; | ||
160 | } | ||
161 | if (oct) *oct = octmp; | ||
162 | } else octmp = *oct; | ||
163 | |||
164 | if(octmp->data) { | ||
165 | OPENSSL_free(octmp->data); | ||
166 | octmp->data = NULL; | ||
167 | } | ||
168 | |||
169 | if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) { | ||
170 | ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR); | ||
171 | return NULL; | ||
172 | } | ||
173 | if (!octmp->data) { | ||
174 | ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE); | ||
175 | return NULL; | ||
176 | } | ||
177 | return octmp; | ||
178 | } | ||
179 | |||
180 | /* Extract an ASN1 object from an ASN1_STRING */ | ||
181 | |||
182 | void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it) | ||
183 | { | ||
184 | unsigned char *p; | ||
185 | void *ret; | ||
186 | |||
187 | p = oct->data; | ||
188 | if(!(ret = ASN1_item_d2i(NULL, &p, oct->length, it))) | ||
189 | ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR); | ||
190 | return ret; | ||
191 | } | ||
diff --git a/src/lib/libcrypto/asn1/charmap.h b/src/lib/libcrypto/asn1/charmap.h deleted file mode 100644 index bd020a9562..0000000000 --- a/src/lib/libcrypto/asn1/charmap.h +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | /* Auto generated with chartype.pl script. | ||
2 | * Mask of various character properties | ||
3 | */ | ||
4 | |||
5 | static unsigned char char_type[] = { | ||
6 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | ||
7 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | ||
8 | 120, 0, 1,40, 0, 0, 0,16,16,16, 0,25,25,16,16,16, | ||
9 | 16,16,16,16,16,16,16,16,16,16,16, 9, 9,16, 9,16, | ||
10 | 0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
11 | 16,16,16,16,16,16,16,16,16,16,16, 0, 1, 0, 0, 0, | ||
12 | 0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
13 | 16,16,16,16,16,16,16,16,16,16,16, 0, 0, 0, 0, 2 | ||
14 | }; | ||
15 | |||
diff --git a/src/lib/libcrypto/asn1/charmap.pl b/src/lib/libcrypto/asn1/charmap.pl deleted file mode 100644 index 2875c59867..0000000000 --- a/src/lib/libcrypto/asn1/charmap.pl +++ /dev/null | |||
@@ -1,80 +0,0 @@ | |||
1 | #!/usr/local/bin/perl -w | ||
2 | |||
3 | use strict; | ||
4 | |||
5 | my ($i, @arr); | ||
6 | |||
7 | # Set up an array with the type of ASCII characters | ||
8 | # Each set bit represents a character property. | ||
9 | |||
10 | # RFC2253 character properties | ||
11 | my $RFC2253_ESC = 1; # Character escaped with \ | ||
12 | my $ESC_CTRL = 2; # Escaped control character | ||
13 | # These are used with RFC1779 quoting using " | ||
14 | my $NOESC_QUOTE = 8; # Not escaped if quoted | ||
15 | my $PSTRING_CHAR = 0x10; # Valid PrintableString character | ||
16 | my $RFC2253_FIRST_ESC = 0x20; # Escaped with \ if first character | ||
17 | my $RFC2253_LAST_ESC = 0x40; # Escaped with \ if last character | ||
18 | |||
19 | for($i = 0; $i < 128; $i++) { | ||
20 | # Set the RFC2253 escape characters (control) | ||
21 | $arr[$i] = 0; | ||
22 | if(($i < 32) || ($i > 126)) { | ||
23 | $arr[$i] |= $ESC_CTRL; | ||
24 | } | ||
25 | |||
26 | # Some PrintableString characters | ||
27 | if( ( ( $i >= ord("a")) && ( $i <= ord("z")) ) | ||
28 | || ( ( $i >= ord("A")) && ( $i <= ord("Z")) ) | ||
29 | || ( ( $i >= ord("0")) && ( $i <= ord("9")) ) ) { | ||
30 | $arr[$i] |= $PSTRING_CHAR; | ||
31 | } | ||
32 | } | ||
33 | |||
34 | # Now setup the rest | ||
35 | |||
36 | # Remaining RFC2253 escaped characters | ||
37 | |||
38 | $arr[ord(" ")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC | $RFC2253_LAST_ESC; | ||
39 | $arr[ord("#")] |= $NOESC_QUOTE | $RFC2253_FIRST_ESC; | ||
40 | |||
41 | $arr[ord(",")] |= $NOESC_QUOTE | $RFC2253_ESC; | ||
42 | $arr[ord("+")] |= $NOESC_QUOTE | $RFC2253_ESC; | ||
43 | $arr[ord("\"")] |= $RFC2253_ESC; | ||
44 | $arr[ord("\\")] |= $RFC2253_ESC; | ||
45 | $arr[ord("<")] |= $NOESC_QUOTE | $RFC2253_ESC; | ||
46 | $arr[ord(">")] |= $NOESC_QUOTE | $RFC2253_ESC; | ||
47 | $arr[ord(";")] |= $NOESC_QUOTE | $RFC2253_ESC; | ||
48 | |||
49 | # Remaining PrintableString characters | ||
50 | |||
51 | $arr[ord(" ")] |= $PSTRING_CHAR; | ||
52 | $arr[ord("'")] |= $PSTRING_CHAR; | ||
53 | $arr[ord("(")] |= $PSTRING_CHAR; | ||
54 | $arr[ord(")")] |= $PSTRING_CHAR; | ||
55 | $arr[ord("+")] |= $PSTRING_CHAR; | ||
56 | $arr[ord(",")] |= $PSTRING_CHAR; | ||
57 | $arr[ord("-")] |= $PSTRING_CHAR; | ||
58 | $arr[ord(".")] |= $PSTRING_CHAR; | ||
59 | $arr[ord("/")] |= $PSTRING_CHAR; | ||
60 | $arr[ord(":")] |= $PSTRING_CHAR; | ||
61 | $arr[ord("=")] |= $PSTRING_CHAR; | ||
62 | $arr[ord("?")] |= $PSTRING_CHAR; | ||
63 | |||
64 | # Now generate the C code | ||
65 | |||
66 | print <<EOF; | ||
67 | /* Auto generated with chartype.pl script. | ||
68 | * Mask of various character properties | ||
69 | */ | ||
70 | |||
71 | static unsigned char char_type[] = { | ||
72 | EOF | ||
73 | |||
74 | for($i = 0; $i < 128; $i++) { | ||
75 | print("\n") if($i && (($i % 16) == 0)); | ||
76 | printf("%2d", $arr[$i]); | ||
77 | print(",") if ($i != 127); | ||
78 | } | ||
79 | print("\n};\n\n"); | ||
80 | |||
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c deleted file mode 100644 index 2e7d96af90..0000000000 --- a/src/lib/libcrypto/asn1/d2i_pr.c +++ /dev/null | |||
@@ -1,145 +0,0 @@ | |||
1 | /* crypto/asn1/d2i_pr.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/bn.h> | ||
62 | #include <openssl/evp.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/asn1.h> | ||
65 | #ifndef OPENSSL_NO_RSA | ||
66 | #include <openssl/rsa.h> | ||
67 | #endif | ||
68 | #ifndef OPENSSL_NO_DSA | ||
69 | #include <openssl/dsa.h> | ||
70 | #endif | ||
71 | |||
72 | EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, unsigned char **pp, | ||
73 | long length) | ||
74 | { | ||
75 | EVP_PKEY *ret; | ||
76 | |||
77 | if ((a == NULL) || (*a == NULL)) | ||
78 | { | ||
79 | if ((ret=EVP_PKEY_new()) == NULL) | ||
80 | { | ||
81 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_EVP_LIB); | ||
82 | return(NULL); | ||
83 | } | ||
84 | } | ||
85 | else ret= *a; | ||
86 | |||
87 | ret->save_type=type; | ||
88 | ret->type=EVP_PKEY_type(type); | ||
89 | switch (ret->type) | ||
90 | { | ||
91 | #ifndef OPENSSL_NO_RSA | ||
92 | case EVP_PKEY_RSA: | ||
93 | if ((ret->pkey.rsa=d2i_RSAPrivateKey(NULL, | ||
94 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ | ||
95 | { | ||
96 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); | ||
97 | goto err; | ||
98 | } | ||
99 | break; | ||
100 | #endif | ||
101 | #ifndef OPENSSL_NO_DSA | ||
102 | case EVP_PKEY_DSA: | ||
103 | if ((ret->pkey.dsa=d2i_DSAPrivateKey(NULL, | ||
104 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ | ||
105 | { | ||
106 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ERR_R_ASN1_LIB); | ||
107 | goto err; | ||
108 | } | ||
109 | break; | ||
110 | #endif | ||
111 | default: | ||
112 | ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | ||
113 | goto err; | ||
114 | /* break; */ | ||
115 | } | ||
116 | if (a != NULL) (*a)=ret; | ||
117 | return(ret); | ||
118 | err: | ||
119 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); | ||
120 | return(NULL); | ||
121 | } | ||
122 | |||
123 | /* This works like d2i_PrivateKey() except it automatically works out the type */ | ||
124 | |||
125 | EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp, | ||
126 | long length) | ||
127 | { | ||
128 | STACK_OF(ASN1_TYPE) *inkey; | ||
129 | unsigned char *p; | ||
130 | int keytype; | ||
131 | p = *pp; | ||
132 | /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE): | ||
133 | * by analyzing it we can determine the passed structure: this | ||
134 | * assumes the input is surrounded by an ASN1 SEQUENCE. | ||
135 | */ | ||
136 | inkey = d2i_ASN1_SET_OF_ASN1_TYPE(NULL, &p, length, d2i_ASN1_TYPE, | ||
137 | ASN1_TYPE_free, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); | ||
138 | /* Since we only need to discern "traditional format" RSA and DSA | ||
139 | * keys we can just count the elements. | ||
140 | */ | ||
141 | if(sk_ASN1_TYPE_num(inkey) == 6) keytype = EVP_PKEY_DSA; | ||
142 | else keytype = EVP_PKEY_RSA; | ||
143 | sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); | ||
144 | return d2i_PrivateKey(keytype, a, pp, length); | ||
145 | } | ||
diff --git a/src/lib/libcrypto/asn1/d2i_pu.c b/src/lib/libcrypto/asn1/d2i_pu.c deleted file mode 100644 index 71f2eb361b..0000000000 --- a/src/lib/libcrypto/asn1/d2i_pu.c +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | /* crypto/asn1/d2i_pu.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/bn.h> | ||
62 | #include <openssl/evp.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/asn1.h> | ||
65 | #ifndef OPENSSL_NO_RSA | ||
66 | #include <openssl/rsa.h> | ||
67 | #endif | ||
68 | #ifndef OPENSSL_NO_DSA | ||
69 | #include <openssl/dsa.h> | ||
70 | #endif | ||
71 | |||
72 | EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp, | ||
73 | long length) | ||
74 | { | ||
75 | EVP_PKEY *ret; | ||
76 | |||
77 | if ((a == NULL) || (*a == NULL)) | ||
78 | { | ||
79 | if ((ret=EVP_PKEY_new()) == NULL) | ||
80 | { | ||
81 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_EVP_LIB); | ||
82 | return(NULL); | ||
83 | } | ||
84 | } | ||
85 | else ret= *a; | ||
86 | |||
87 | ret->save_type=type; | ||
88 | ret->type=EVP_PKEY_type(type); | ||
89 | switch (ret->type) | ||
90 | { | ||
91 | #ifndef OPENSSL_NO_RSA | ||
92 | case EVP_PKEY_RSA: | ||
93 | if ((ret->pkey.rsa=d2i_RSAPublicKey(NULL, | ||
94 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ | ||
95 | { | ||
96 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); | ||
97 | goto err; | ||
98 | } | ||
99 | break; | ||
100 | #endif | ||
101 | #ifndef OPENSSL_NO_DSA | ||
102 | case EVP_PKEY_DSA: | ||
103 | if ((ret->pkey.dsa=d2i_DSAPublicKey(NULL, | ||
104 | (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */ | ||
105 | { | ||
106 | ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); | ||
107 | goto err; | ||
108 | } | ||
109 | break; | ||
110 | #endif | ||
111 | default: | ||
112 | ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); | ||
113 | goto err; | ||
114 | /* break; */ | ||
115 | } | ||
116 | if (a != NULL) (*a)=ret; | ||
117 | return(ret); | ||
118 | err: | ||
119 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); | ||
120 | return(NULL); | ||
121 | } | ||
122 | |||
diff --git a/src/lib/libcrypto/asn1/evp_asn1.c b/src/lib/libcrypto/asn1/evp_asn1.c deleted file mode 100644 index 3506005a71..0000000000 --- a/src/lib/libcrypto/asn1/evp_asn1.c +++ /dev/null | |||
@@ -1,185 +0,0 @@ | |||
1 | /* crypto/asn1/evp_asn1.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1.h> | ||
62 | #include <openssl/asn1_mac.h> | ||
63 | |||
64 | int ASN1_TYPE_set_octetstring(ASN1_TYPE *a, unsigned char *data, int len) | ||
65 | { | ||
66 | ASN1_STRING *os; | ||
67 | |||
68 | if ((os=M_ASN1_OCTET_STRING_new()) == NULL) return(0); | ||
69 | if (!M_ASN1_OCTET_STRING_set(os,data,len)) return(0); | ||
70 | ASN1_TYPE_set(a,V_ASN1_OCTET_STRING,os); | ||
71 | return(1); | ||
72 | } | ||
73 | |||
74 | /* int max_len: for returned value */ | ||
75 | int ASN1_TYPE_get_octetstring(ASN1_TYPE *a, unsigned char *data, | ||
76 | int max_len) | ||
77 | { | ||
78 | int ret,num; | ||
79 | unsigned char *p; | ||
80 | |||
81 | if ((a->type != V_ASN1_OCTET_STRING) || (a->value.octet_string == NULL)) | ||
82 | { | ||
83 | ASN1err(ASN1_F_ASN1_TYPE_GET_OCTETSTRING,ASN1_R_DATA_IS_WRONG); | ||
84 | return(-1); | ||
85 | } | ||
86 | p=M_ASN1_STRING_data(a->value.octet_string); | ||
87 | ret=M_ASN1_STRING_length(a->value.octet_string); | ||
88 | if (ret < max_len) | ||
89 | num=ret; | ||
90 | else | ||
91 | num=max_len; | ||
92 | memcpy(data,p,num); | ||
93 | return(ret); | ||
94 | } | ||
95 | |||
96 | int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num, unsigned char *data, | ||
97 | int len) | ||
98 | { | ||
99 | int n,size; | ||
100 | ASN1_OCTET_STRING os,*osp; | ||
101 | ASN1_INTEGER in; | ||
102 | unsigned char *p; | ||
103 | unsigned char buf[32]; /* when they have 256bit longs, | ||
104 | * I'll be in trouble */ | ||
105 | in.data=buf; | ||
106 | in.length=32; | ||
107 | os.data=data; | ||
108 | os.type=V_ASN1_OCTET_STRING; | ||
109 | os.length=len; | ||
110 | ASN1_INTEGER_set(&in,num); | ||
111 | n = i2d_ASN1_INTEGER(&in,NULL); | ||
112 | n+=M_i2d_ASN1_OCTET_STRING(&os,NULL); | ||
113 | |||
114 | size=ASN1_object_size(1,n,V_ASN1_SEQUENCE); | ||
115 | |||
116 | if ((osp=ASN1_STRING_new()) == NULL) return(0); | ||
117 | /* Grow the 'string' */ | ||
118 | ASN1_STRING_set(osp,NULL,size); | ||
119 | |||
120 | M_ASN1_STRING_length_set(osp, size); | ||
121 | p=M_ASN1_STRING_data(osp); | ||
122 | |||
123 | ASN1_put_object(&p,1,n,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
124 | i2d_ASN1_INTEGER(&in,&p); | ||
125 | M_i2d_ASN1_OCTET_STRING(&os,&p); | ||
126 | |||
127 | ASN1_TYPE_set(a,V_ASN1_SEQUENCE,osp); | ||
128 | return(1); | ||
129 | } | ||
130 | |||
131 | /* we return the actual length..., num may be missing, in which | ||
132 | * case, set it to zero */ | ||
133 | /* int max_len: for returned value */ | ||
134 | int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data, | ||
135 | int max_len) | ||
136 | { | ||
137 | int ret= -1,n; | ||
138 | ASN1_INTEGER *ai=NULL; | ||
139 | ASN1_OCTET_STRING *os=NULL; | ||
140 | unsigned char *p; | ||
141 | long length; | ||
142 | ASN1_CTX c; | ||
143 | |||
144 | if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) | ||
145 | { | ||
146 | goto err; | ||
147 | } | ||
148 | p=M_ASN1_STRING_data(a->value.sequence); | ||
149 | length=M_ASN1_STRING_length(a->value.sequence); | ||
150 | |||
151 | c.pp= &p; | ||
152 | c.p=p; | ||
153 | c.max=p+length; | ||
154 | c.error=ASN1_R_DATA_IS_WRONG; | ||
155 | |||
156 | M_ASN1_D2I_start_sequence(); | ||
157 | c.q=c.p; | ||
158 | if ((ai=d2i_ASN1_INTEGER(NULL,&c.p,c.slen)) == NULL) goto err; | ||
159 | c.slen-=(c.p-c.q); | ||
160 | c.q=c.p; | ||
161 | if ((os=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL) goto err; | ||
162 | c.slen-=(c.p-c.q); | ||
163 | if (!M_ASN1_D2I_end_sequence()) goto err; | ||
164 | |||
165 | if (num != NULL) | ||
166 | *num=ASN1_INTEGER_get(ai); | ||
167 | |||
168 | ret=M_ASN1_STRING_length(os); | ||
169 | if (max_len > ret) | ||
170 | n=ret; | ||
171 | else | ||
172 | n=max_len; | ||
173 | |||
174 | if (data != NULL) | ||
175 | memcpy(data,M_ASN1_STRING_data(os),n); | ||
176 | if (0) | ||
177 | { | ||
178 | err: | ||
179 | ASN1err(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,ASN1_R_DATA_IS_WRONG); | ||
180 | } | ||
181 | if (os != NULL) M_ASN1_OCTET_STRING_free(os); | ||
182 | if (ai != NULL) M_ASN1_INTEGER_free(ai); | ||
183 | return(ret); | ||
184 | } | ||
185 | |||
diff --git a/src/lib/libcrypto/asn1/f_enum.c b/src/lib/libcrypto/asn1/f_enum.c deleted file mode 100644 index 56e3cc8df2..0000000000 --- a/src/lib/libcrypto/asn1/f_enum.c +++ /dev/null | |||
@@ -1,207 +0,0 @@ | |||
1 | /* crypto/asn1/f_enum.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/buffer.h> | ||
62 | #include <openssl/asn1.h> | ||
63 | |||
64 | /* Based on a_int.c: equivalent ENUMERATED functions */ | ||
65 | |||
66 | int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a) | ||
67 | { | ||
68 | int i,n=0; | ||
69 | static const char *h="0123456789ABCDEF"; | ||
70 | char buf[2]; | ||
71 | |||
72 | if (a == NULL) return(0); | ||
73 | |||
74 | if (a->length == 0) | ||
75 | { | ||
76 | if (BIO_write(bp,"00",2) != 2) goto err; | ||
77 | n=2; | ||
78 | } | ||
79 | else | ||
80 | { | ||
81 | for (i=0; i<a->length; i++) | ||
82 | { | ||
83 | if ((i != 0) && (i%35 == 0)) | ||
84 | { | ||
85 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | ||
86 | n+=2; | ||
87 | } | ||
88 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | ||
89 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | ||
90 | if (BIO_write(bp,buf,2) != 2) goto err; | ||
91 | n+=2; | ||
92 | } | ||
93 | } | ||
94 | return(n); | ||
95 | err: | ||
96 | return(-1); | ||
97 | } | ||
98 | |||
99 | int a2i_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *bs, char *buf, int size) | ||
100 | { | ||
101 | int ret=0; | ||
102 | int i,j,k,m,n,again,bufsize; | ||
103 | unsigned char *s=NULL,*sp; | ||
104 | unsigned char *bufp; | ||
105 | int num=0,slen=0,first=1; | ||
106 | |||
107 | bs->type=V_ASN1_ENUMERATED; | ||
108 | |||
109 | bufsize=BIO_gets(bp,buf,size); | ||
110 | for (;;) | ||
111 | { | ||
112 | if (bufsize < 1) goto err_sl; | ||
113 | i=bufsize; | ||
114 | if (buf[i-1] == '\n') buf[--i]='\0'; | ||
115 | if (i == 0) goto err_sl; | ||
116 | if (buf[i-1] == '\r') buf[--i]='\0'; | ||
117 | if (i == 0) goto err_sl; | ||
118 | again=(buf[i-1] == '\\'); | ||
119 | |||
120 | for (j=0; j<i; j++) | ||
121 | { | ||
122 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | ||
123 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | ||
124 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) | ||
125 | { | ||
126 | i=j; | ||
127 | break; | ||
128 | } | ||
129 | } | ||
130 | buf[i]='\0'; | ||
131 | /* We have now cleared all the crap off the end of the | ||
132 | * line */ | ||
133 | if (i < 2) goto err_sl; | ||
134 | |||
135 | bufp=(unsigned char *)buf; | ||
136 | if (first) | ||
137 | { | ||
138 | first=0; | ||
139 | if ((bufp[0] == '0') && (buf[1] == '0')) | ||
140 | { | ||
141 | bufp+=2; | ||
142 | i-=2; | ||
143 | } | ||
144 | } | ||
145 | k=0; | ||
146 | i-=again; | ||
147 | if (i%2 != 0) | ||
148 | { | ||
149 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_ODD_NUMBER_OF_CHARS); | ||
150 | goto err; | ||
151 | } | ||
152 | i/=2; | ||
153 | if (num+i > slen) | ||
154 | { | ||
155 | if (s == NULL) | ||
156 | sp=(unsigned char *)OPENSSL_malloc( | ||
157 | (unsigned int)num+i*2); | ||
158 | else | ||
159 | sp=(unsigned char *)OPENSSL_realloc(s, | ||
160 | (unsigned int)num+i*2); | ||
161 | if (sp == NULL) | ||
162 | { | ||
163 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ERR_R_MALLOC_FAILURE); | ||
164 | if (s != NULL) OPENSSL_free(s); | ||
165 | goto err; | ||
166 | } | ||
167 | s=sp; | ||
168 | slen=num+i*2; | ||
169 | } | ||
170 | for (j=0; j<i; j++,k+=2) | ||
171 | { | ||
172 | for (n=0; n<2; n++) | ||
173 | { | ||
174 | m=bufp[k+n]; | ||
175 | if ((m >= '0') && (m <= '9')) | ||
176 | m-='0'; | ||
177 | else if ((m >= 'a') && (m <= 'f')) | ||
178 | m=m-'a'+10; | ||
179 | else if ((m >= 'A') && (m <= 'F')) | ||
180 | m=m-'A'+10; | ||
181 | else | ||
182 | { | ||
183 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_NON_HEX_CHARACTERS); | ||
184 | goto err; | ||
185 | } | ||
186 | s[num+j]<<=4; | ||
187 | s[num+j]|=m; | ||
188 | } | ||
189 | } | ||
190 | num+=i; | ||
191 | if (again) | ||
192 | bufsize=BIO_gets(bp,buf,size); | ||
193 | else | ||
194 | break; | ||
195 | } | ||
196 | bs->length=num; | ||
197 | bs->data=s; | ||
198 | ret=1; | ||
199 | err: | ||
200 | if (0) | ||
201 | { | ||
202 | err_sl: | ||
203 | ASN1err(ASN1_F_A2I_ASN1_ENUMERATED,ASN1_R_SHORT_LINE); | ||
204 | } | ||
205 | return(ret); | ||
206 | } | ||
207 | |||
diff --git a/src/lib/libcrypto/asn1/f_int.c b/src/lib/libcrypto/asn1/f_int.c deleted file mode 100644 index 9494e597ab..0000000000 --- a/src/lib/libcrypto/asn1/f_int.c +++ /dev/null | |||
@@ -1,219 +0,0 @@ | |||
1 | /* crypto/asn1/f_int.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/buffer.h> | ||
62 | #include <openssl/asn1.h> | ||
63 | |||
64 | int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a) | ||
65 | { | ||
66 | int i,n=0; | ||
67 | static const char *h="0123456789ABCDEF"; | ||
68 | char buf[2]; | ||
69 | |||
70 | if (a == NULL) return(0); | ||
71 | |||
72 | if (a->type & V_ASN1_NEG) | ||
73 | { | ||
74 | if (BIO_write(bp, "-", 1) != 1) goto err; | ||
75 | n = 1; | ||
76 | } | ||
77 | |||
78 | if (a->length == 0) | ||
79 | { | ||
80 | if (BIO_write(bp,"00",2) != 2) goto err; | ||
81 | n += 2; | ||
82 | } | ||
83 | else | ||
84 | { | ||
85 | for (i=0; i<a->length; i++) | ||
86 | { | ||
87 | if ((i != 0) && (i%35 == 0)) | ||
88 | { | ||
89 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | ||
90 | n+=2; | ||
91 | } | ||
92 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | ||
93 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | ||
94 | if (BIO_write(bp,buf,2) != 2) goto err; | ||
95 | n+=2; | ||
96 | } | ||
97 | } | ||
98 | return(n); | ||
99 | err: | ||
100 | return(-1); | ||
101 | } | ||
102 | |||
103 | int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | ||
104 | { | ||
105 | int ret=0; | ||
106 | int i,j,k,m,n,again,bufsize; | ||
107 | unsigned char *s=NULL,*sp; | ||
108 | unsigned char *bufp; | ||
109 | int num=0,slen=0,first=1; | ||
110 | |||
111 | bs->type=V_ASN1_INTEGER; | ||
112 | |||
113 | bufsize=BIO_gets(bp,buf,size); | ||
114 | for (;;) | ||
115 | { | ||
116 | if (bufsize < 1) goto err_sl; | ||
117 | i=bufsize; | ||
118 | if (buf[i-1] == '\n') buf[--i]='\0'; | ||
119 | if (i == 0) goto err_sl; | ||
120 | if (buf[i-1] == '\r') buf[--i]='\0'; | ||
121 | if (i == 0) goto err_sl; | ||
122 | again=(buf[i-1] == '\\'); | ||
123 | |||
124 | for (j=0; j<i; j++) | ||
125 | { | ||
126 | #ifndef CHARSET_EBCDIC | ||
127 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | ||
128 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | ||
129 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) | ||
130 | #else | ||
131 | /* This #ifdef is not strictly necessary, since | ||
132 | * the characters A...F a...f 0...9 are contiguous | ||
133 | * (yes, even in EBCDIC - but not the whole alphabet). | ||
134 | * Nevertheless, isxdigit() is faster. | ||
135 | */ | ||
136 | if (!isxdigit(buf[j])) | ||
137 | #endif | ||
138 | { | ||
139 | i=j; | ||
140 | break; | ||
141 | } | ||
142 | } | ||
143 | buf[i]='\0'; | ||
144 | /* We have now cleared all the crap off the end of the | ||
145 | * line */ | ||
146 | if (i < 2) goto err_sl; | ||
147 | |||
148 | bufp=(unsigned char *)buf; | ||
149 | if (first) | ||
150 | { | ||
151 | first=0; | ||
152 | if ((bufp[0] == '0') && (buf[1] == '0')) | ||
153 | { | ||
154 | bufp+=2; | ||
155 | i-=2; | ||
156 | } | ||
157 | } | ||
158 | k=0; | ||
159 | i-=again; | ||
160 | if (i%2 != 0) | ||
161 | { | ||
162 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_ODD_NUMBER_OF_CHARS); | ||
163 | goto err; | ||
164 | } | ||
165 | i/=2; | ||
166 | if (num+i > slen) | ||
167 | { | ||
168 | if (s == NULL) | ||
169 | sp=(unsigned char *)OPENSSL_malloc( | ||
170 | (unsigned int)num+i*2); | ||
171 | else | ||
172 | sp=OPENSSL_realloc_clean(s,slen,num+i*2); | ||
173 | if (sp == NULL) | ||
174 | { | ||
175 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); | ||
176 | if (s != NULL) OPENSSL_free(s); | ||
177 | goto err; | ||
178 | } | ||
179 | s=sp; | ||
180 | slen=num+i*2; | ||
181 | } | ||
182 | for (j=0; j<i; j++,k+=2) | ||
183 | { | ||
184 | for (n=0; n<2; n++) | ||
185 | { | ||
186 | m=bufp[k+n]; | ||
187 | if ((m >= '0') && (m <= '9')) | ||
188 | m-='0'; | ||
189 | else if ((m >= 'a') && (m <= 'f')) | ||
190 | m=m-'a'+10; | ||
191 | else if ((m >= 'A') && (m <= 'F')) | ||
192 | m=m-'A'+10; | ||
193 | else | ||
194 | { | ||
195 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_NON_HEX_CHARACTERS); | ||
196 | goto err; | ||
197 | } | ||
198 | s[num+j]<<=4; | ||
199 | s[num+j]|=m; | ||
200 | } | ||
201 | } | ||
202 | num+=i; | ||
203 | if (again) | ||
204 | bufsize=BIO_gets(bp,buf,size); | ||
205 | else | ||
206 | break; | ||
207 | } | ||
208 | bs->length=num; | ||
209 | bs->data=s; | ||
210 | ret=1; | ||
211 | err: | ||
212 | if (0) | ||
213 | { | ||
214 | err_sl: | ||
215 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ASN1_R_SHORT_LINE); | ||
216 | } | ||
217 | return(ret); | ||
218 | } | ||
219 | |||
diff --git a/src/lib/libcrypto/asn1/f_string.c b/src/lib/libcrypto/asn1/f_string.c deleted file mode 100644 index 968698a798..0000000000 --- a/src/lib/libcrypto/asn1/f_string.c +++ /dev/null | |||
@@ -1,212 +0,0 @@ | |||
1 | /* crypto/asn1/f_string.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/buffer.h> | ||
62 | #include <openssl/asn1.h> | ||
63 | |||
64 | int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type) | ||
65 | { | ||
66 | int i,n=0; | ||
67 | static const char *h="0123456789ABCDEF"; | ||
68 | char buf[2]; | ||
69 | |||
70 | if (a == NULL) return(0); | ||
71 | |||
72 | if (a->length == 0) | ||
73 | { | ||
74 | if (BIO_write(bp,"0",1) != 1) goto err; | ||
75 | n=1; | ||
76 | } | ||
77 | else | ||
78 | { | ||
79 | for (i=0; i<a->length; i++) | ||
80 | { | ||
81 | if ((i != 0) && (i%35 == 0)) | ||
82 | { | ||
83 | if (BIO_write(bp,"\\\n",2) != 2) goto err; | ||
84 | n+=2; | ||
85 | } | ||
86 | buf[0]=h[((unsigned char)a->data[i]>>4)&0x0f]; | ||
87 | buf[1]=h[((unsigned char)a->data[i] )&0x0f]; | ||
88 | if (BIO_write(bp,buf,2) != 2) goto err; | ||
89 | n+=2; | ||
90 | } | ||
91 | } | ||
92 | return(n); | ||
93 | err: | ||
94 | return(-1); | ||
95 | } | ||
96 | |||
97 | int a2i_ASN1_STRING(BIO *bp, ASN1_STRING *bs, char *buf, int size) | ||
98 | { | ||
99 | int ret=0; | ||
100 | int i,j,k,m,n,again,bufsize; | ||
101 | unsigned char *s=NULL,*sp; | ||
102 | unsigned char *bufp; | ||
103 | int num=0,slen=0,first=1; | ||
104 | |||
105 | bufsize=BIO_gets(bp,buf,size); | ||
106 | for (;;) | ||
107 | { | ||
108 | if (bufsize < 1) | ||
109 | { | ||
110 | if (first) | ||
111 | break; | ||
112 | else | ||
113 | goto err_sl; | ||
114 | } | ||
115 | first=0; | ||
116 | |||
117 | i=bufsize; | ||
118 | if (buf[i-1] == '\n') buf[--i]='\0'; | ||
119 | if (i == 0) goto err_sl; | ||
120 | if (buf[i-1] == '\r') buf[--i]='\0'; | ||
121 | if (i == 0) goto err_sl; | ||
122 | again=(buf[i-1] == '\\'); | ||
123 | |||
124 | for (j=i-1; j>0; j--) | ||
125 | { | ||
126 | #ifndef CHARSET_EBCDIC | ||
127 | if (!( ((buf[j] >= '0') && (buf[j] <= '9')) || | ||
128 | ((buf[j] >= 'a') && (buf[j] <= 'f')) || | ||
129 | ((buf[j] >= 'A') && (buf[j] <= 'F')))) | ||
130 | #else | ||
131 | /* This #ifdef is not strictly necessary, since | ||
132 | * the characters A...F a...f 0...9 are contiguous | ||
133 | * (yes, even in EBCDIC - but not the whole alphabet). | ||
134 | * Nevertheless, isxdigit() is faster. | ||
135 | */ | ||
136 | if (!isxdigit(buf[j])) | ||
137 | #endif | ||
138 | { | ||
139 | i=j; | ||
140 | break; | ||
141 | } | ||
142 | } | ||
143 | buf[i]='\0'; | ||
144 | /* We have now cleared all the crap off the end of the | ||
145 | * line */ | ||
146 | if (i < 2) goto err_sl; | ||
147 | |||
148 | bufp=(unsigned char *)buf; | ||
149 | |||
150 | k=0; | ||
151 | i-=again; | ||
152 | if (i%2 != 0) | ||
153 | { | ||
154 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_ODD_NUMBER_OF_CHARS); | ||
155 | goto err; | ||
156 | } | ||
157 | i/=2; | ||
158 | if (num+i > slen) | ||
159 | { | ||
160 | if (s == NULL) | ||
161 | sp=(unsigned char *)OPENSSL_malloc( | ||
162 | (unsigned int)num+i*2); | ||
163 | else | ||
164 | sp=(unsigned char *)OPENSSL_realloc(s, | ||
165 | (unsigned int)num+i*2); | ||
166 | if (sp == NULL) | ||
167 | { | ||
168 | ASN1err(ASN1_F_A2I_ASN1_STRING,ERR_R_MALLOC_FAILURE); | ||
169 | if (s != NULL) OPENSSL_free(s); | ||
170 | goto err; | ||
171 | } | ||
172 | s=sp; | ||
173 | slen=num+i*2; | ||
174 | } | ||
175 | for (j=0; j<i; j++,k+=2) | ||
176 | { | ||
177 | for (n=0; n<2; n++) | ||
178 | { | ||
179 | m=bufp[k+n]; | ||
180 | if ((m >= '0') && (m <= '9')) | ||
181 | m-='0'; | ||
182 | else if ((m >= 'a') && (m <= 'f')) | ||
183 | m=m-'a'+10; | ||
184 | else if ((m >= 'A') && (m <= 'F')) | ||
185 | m=m-'A'+10; | ||
186 | else | ||
187 | { | ||
188 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_NON_HEX_CHARACTERS); | ||
189 | goto err; | ||
190 | } | ||
191 | s[num+j]<<=4; | ||
192 | s[num+j]|=m; | ||
193 | } | ||
194 | } | ||
195 | num+=i; | ||
196 | if (again) | ||
197 | bufsize=BIO_gets(bp,buf,size); | ||
198 | else | ||
199 | break; | ||
200 | } | ||
201 | bs->length=num; | ||
202 | bs->data=s; | ||
203 | ret=1; | ||
204 | err: | ||
205 | if (0) | ||
206 | { | ||
207 | err_sl: | ||
208 | ASN1err(ASN1_F_A2I_ASN1_STRING,ASN1_R_SHORT_LINE); | ||
209 | } | ||
210 | return(ret); | ||
211 | } | ||
212 | |||
diff --git a/src/lib/libcrypto/asn1/i2d_pr.c b/src/lib/libcrypto/asn1/i2d_pr.c deleted file mode 100644 index 1e951ae01d..0000000000 --- a/src/lib/libcrypto/asn1/i2d_pr.c +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | /* crypto/asn1/i2d_pr.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/bn.h> | ||
62 | #include <openssl/evp.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #ifndef OPENSSL_NO_RSA | ||
65 | #include <openssl/rsa.h> | ||
66 | #endif | ||
67 | #ifndef OPENSSL_NO_DSA | ||
68 | #include <openssl/dsa.h> | ||
69 | #endif | ||
70 | |||
71 | int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp) | ||
72 | { | ||
73 | #ifndef OPENSSL_NO_RSA | ||
74 | if (a->type == EVP_PKEY_RSA) | ||
75 | { | ||
76 | return(i2d_RSAPrivateKey(a->pkey.rsa,pp)); | ||
77 | } | ||
78 | else | ||
79 | #endif | ||
80 | #ifndef OPENSSL_NO_DSA | ||
81 | if (a->type == EVP_PKEY_DSA) | ||
82 | { | ||
83 | return(i2d_DSAPrivateKey(a->pkey.dsa,pp)); | ||
84 | } | ||
85 | #endif | ||
86 | |||
87 | ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | ||
88 | return(-1); | ||
89 | } | ||
90 | |||
diff --git a/src/lib/libcrypto/asn1/i2d_pu.c b/src/lib/libcrypto/asn1/i2d_pu.c deleted file mode 100644 index 013d19bbf4..0000000000 --- a/src/lib/libcrypto/asn1/i2d_pu.c +++ /dev/null | |||
@@ -1,88 +0,0 @@ | |||
1 | /* crypto/asn1/i2d_pu.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/bn.h> | ||
62 | #include <openssl/evp.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #ifndef OPENSSL_NO_RSA | ||
65 | #include <openssl/rsa.h> | ||
66 | #endif | ||
67 | #ifndef OPENSSL_NO_DSA | ||
68 | #include <openssl/dsa.h> | ||
69 | #endif | ||
70 | |||
71 | int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp) | ||
72 | { | ||
73 | switch (a->type) | ||
74 | { | ||
75 | #ifndef OPENSSL_NO_RSA | ||
76 | case EVP_PKEY_RSA: | ||
77 | return(i2d_RSAPublicKey(a->pkey.rsa,pp)); | ||
78 | #endif | ||
79 | #ifndef OPENSSL_NO_DSA | ||
80 | case EVP_PKEY_DSA: | ||
81 | return(i2d_DSAPublicKey(a->pkey.dsa,pp)); | ||
82 | #endif | ||
83 | default: | ||
84 | ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); | ||
85 | return(-1); | ||
86 | } | ||
87 | } | ||
88 | |||
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c deleted file mode 100644 index 766b51c538..0000000000 --- a/src/lib/libcrypto/asn1/n_pkey.c +++ /dev/null | |||
@@ -1,333 +0,0 @@ | |||
1 | /* crypto/asn1/n_pkey.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #ifndef OPENSSL_NO_RSA | ||
60 | #include <stdio.h> | ||
61 | #include "cryptlib.h" | ||
62 | #include <openssl/rsa.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/asn1t.h> | ||
65 | #include <openssl/asn1_mac.h> | ||
66 | #include <openssl/evp.h> | ||
67 | #include <openssl/x509.h> | ||
68 | |||
69 | |||
70 | #ifndef OPENSSL_NO_RC4 | ||
71 | |||
72 | typedef struct netscape_pkey_st | ||
73 | { | ||
74 | long version; | ||
75 | X509_ALGOR *algor; | ||
76 | ASN1_OCTET_STRING *private_key; | ||
77 | } NETSCAPE_PKEY; | ||
78 | |||
79 | typedef struct netscape_encrypted_pkey_st | ||
80 | { | ||
81 | ASN1_OCTET_STRING *os; | ||
82 | /* This is the same structure as DigestInfo so use it: | ||
83 | * although this isn't really anything to do with | ||
84 | * digests. | ||
85 | */ | ||
86 | X509_SIG *enckey; | ||
87 | } NETSCAPE_ENCRYPTED_PKEY; | ||
88 | |||
89 | |||
90 | ASN1_BROKEN_SEQUENCE(NETSCAPE_ENCRYPTED_PKEY) = { | ||
91 | ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, os, ASN1_OCTET_STRING), | ||
92 | ASN1_SIMPLE(NETSCAPE_ENCRYPTED_PKEY, enckey, X509_SIG) | ||
93 | } ASN1_BROKEN_SEQUENCE_END(NETSCAPE_ENCRYPTED_PKEY) | ||
94 | |||
95 | DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY) | ||
96 | DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY,NETSCAPE_ENCRYPTED_PKEY) | ||
97 | IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_ENCRYPTED_PKEY) | ||
98 | |||
99 | ASN1_SEQUENCE(NETSCAPE_PKEY) = { | ||
100 | ASN1_SIMPLE(NETSCAPE_PKEY, version, LONG), | ||
101 | ASN1_SIMPLE(NETSCAPE_PKEY, algor, X509_ALGOR), | ||
102 | ASN1_SIMPLE(NETSCAPE_PKEY, private_key, ASN1_OCTET_STRING) | ||
103 | } ASN1_SEQUENCE_END(NETSCAPE_PKEY) | ||
104 | |||
105 | DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_PKEY) | ||
106 | DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_PKEY,NETSCAPE_PKEY) | ||
107 | IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_PKEY) | ||
108 | |||
109 | static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | ||
110 | int (*cb)(), int sgckey); | ||
111 | |||
112 | int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, int (*cb)()) | ||
113 | { | ||
114 | return i2d_RSA_NET(a, pp, cb, 0); | ||
115 | } | ||
116 | |||
117 | int i2d_RSA_NET(const RSA *a, unsigned char **pp, int (*cb)(), int sgckey) | ||
118 | { | ||
119 | int i, j, ret = 0; | ||
120 | int rsalen, pkeylen, olen; | ||
121 | NETSCAPE_PKEY *pkey = NULL; | ||
122 | NETSCAPE_ENCRYPTED_PKEY *enckey = NULL; | ||
123 | unsigned char buf[256],*zz; | ||
124 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
125 | EVP_CIPHER_CTX ctx; | ||
126 | |||
127 | if (a == NULL) return(0); | ||
128 | |||
129 | if ((pkey=NETSCAPE_PKEY_new()) == NULL) goto err; | ||
130 | if ((enckey=NETSCAPE_ENCRYPTED_PKEY_new()) == NULL) goto err; | ||
131 | pkey->version = 0; | ||
132 | |||
133 | pkey->algor->algorithm=OBJ_nid2obj(NID_rsaEncryption); | ||
134 | if ((pkey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err; | ||
135 | pkey->algor->parameter->type=V_ASN1_NULL; | ||
136 | |||
137 | rsalen = i2d_RSAPrivateKey(a, NULL); | ||
138 | |||
139 | /* Fake some octet strings just for the initial length | ||
140 | * calculation. | ||
141 | */ | ||
142 | |||
143 | pkey->private_key->length=rsalen; | ||
144 | |||
145 | pkeylen=i2d_NETSCAPE_PKEY(pkey,NULL); | ||
146 | |||
147 | enckey->enckey->digest->length = pkeylen; | ||
148 | |||
149 | enckey->os->length = 11; /* "private-key" */ | ||
150 | |||
151 | enckey->enckey->algor->algorithm=OBJ_nid2obj(NID_rc4); | ||
152 | if ((enckey->enckey->algor->parameter=ASN1_TYPE_new()) == NULL) goto err; | ||
153 | enckey->enckey->algor->parameter->type=V_ASN1_NULL; | ||
154 | |||
155 | if (pp == NULL) | ||
156 | { | ||
157 | olen = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, NULL); | ||
158 | NETSCAPE_PKEY_free(pkey); | ||
159 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | ||
160 | return olen; | ||
161 | } | ||
162 | |||
163 | |||
164 | /* Since its RC4 encrypted length is actual length */ | ||
165 | if ((zz=(unsigned char *)OPENSSL_malloc(rsalen)) == NULL) | ||
166 | { | ||
167 | ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE); | ||
168 | goto err; | ||
169 | } | ||
170 | |||
171 | pkey->private_key->data = zz; | ||
172 | /* Write out private key encoding */ | ||
173 | i2d_RSAPrivateKey(a,&zz); | ||
174 | |||
175 | if ((zz=OPENSSL_malloc(pkeylen)) == NULL) | ||
176 | { | ||
177 | ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE); | ||
178 | goto err; | ||
179 | } | ||
180 | |||
181 | if (!ASN1_STRING_set(enckey->os, "private-key", -1)) | ||
182 | { | ||
183 | ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE); | ||
184 | goto err; | ||
185 | } | ||
186 | enckey->enckey->digest->data = zz; | ||
187 | i2d_NETSCAPE_PKEY(pkey,&zz); | ||
188 | |||
189 | /* Wipe the private key encoding */ | ||
190 | OPENSSL_cleanse(pkey->private_key->data, rsalen); | ||
191 | |||
192 | if (cb == NULL) | ||
193 | cb=EVP_read_pw_string; | ||
194 | i=cb(buf,256,"Enter Private Key password:",1); | ||
195 | if (i != 0) | ||
196 | { | ||
197 | ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ASN1_R_BAD_PASSWORD_READ); | ||
198 | goto err; | ||
199 | } | ||
200 | i = strlen((char *)buf); | ||
201 | /* If the key is used for SGC the algorithm is modified a little. */ | ||
202 | if(sgckey) { | ||
203 | EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL); | ||
204 | memcpy(buf + 16, "SGCKEYSALT", 10); | ||
205 | i = 26; | ||
206 | } | ||
207 | |||
208 | EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL); | ||
209 | OPENSSL_cleanse(buf,256); | ||
210 | |||
211 | /* Encrypt private key in place */ | ||
212 | zz = enckey->enckey->digest->data; | ||
213 | EVP_CIPHER_CTX_init(&ctx); | ||
214 | EVP_EncryptInit_ex(&ctx,EVP_rc4(),NULL,key,NULL); | ||
215 | EVP_EncryptUpdate(&ctx,zz,&i,zz,pkeylen); | ||
216 | EVP_EncryptFinal_ex(&ctx,zz + i,&j); | ||
217 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
218 | |||
219 | ret = i2d_NETSCAPE_ENCRYPTED_PKEY(enckey, pp); | ||
220 | err: | ||
221 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | ||
222 | NETSCAPE_PKEY_free(pkey); | ||
223 | return(ret); | ||
224 | } | ||
225 | |||
226 | |||
227 | RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, int (*cb)()) | ||
228 | { | ||
229 | return d2i_RSA_NET(a, pp, length, cb, 0); | ||
230 | } | ||
231 | |||
232 | RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, int (*cb)(), int sgckey) | ||
233 | { | ||
234 | RSA *ret=NULL; | ||
235 | const unsigned char *p, *kp; | ||
236 | NETSCAPE_ENCRYPTED_PKEY *enckey = NULL; | ||
237 | |||
238 | p = *pp; | ||
239 | |||
240 | enckey = d2i_NETSCAPE_ENCRYPTED_PKEY(NULL, &p, length); | ||
241 | if(!enckey) { | ||
242 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_DECODING_ERROR); | ||
243 | return NULL; | ||
244 | } | ||
245 | |||
246 | if ((enckey->os->length != 11) || (strncmp("private-key", | ||
247 | (char *)enckey->os->data,11) != 0)) | ||
248 | { | ||
249 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_PRIVATE_KEY_HEADER_MISSING); | ||
250 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | ||
251 | return NULL; | ||
252 | } | ||
253 | if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) | ||
254 | { | ||
255 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM); | ||
256 | goto err; | ||
257 | } | ||
258 | kp = enckey->enckey->digest->data; | ||
259 | if (cb == NULL) | ||
260 | cb=EVP_read_pw_string; | ||
261 | if ((ret=d2i_RSA_NET_2(a, enckey->enckey->digest,cb, sgckey)) == NULL) goto err; | ||
262 | |||
263 | *pp = p; | ||
264 | |||
265 | err: | ||
266 | NETSCAPE_ENCRYPTED_PKEY_free(enckey); | ||
267 | return ret; | ||
268 | |||
269 | } | ||
270 | |||
271 | static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | ||
272 | int (*cb)(), int sgckey) | ||
273 | { | ||
274 | NETSCAPE_PKEY *pkey=NULL; | ||
275 | RSA *ret=NULL; | ||
276 | int i,j; | ||
277 | unsigned char buf[256]; | ||
278 | const unsigned char *zz; | ||
279 | unsigned char key[EVP_MAX_KEY_LENGTH]; | ||
280 | EVP_CIPHER_CTX ctx; | ||
281 | |||
282 | i=cb(buf,256,"Enter Private Key password:",0); | ||
283 | if (i != 0) | ||
284 | { | ||
285 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_BAD_PASSWORD_READ); | ||
286 | goto err; | ||
287 | } | ||
288 | |||
289 | i = strlen((char *)buf); | ||
290 | if(sgckey){ | ||
291 | EVP_Digest(buf, i, buf, NULL, EVP_md5(), NULL); | ||
292 | memcpy(buf + 16, "SGCKEYSALT", 10); | ||
293 | i = 26; | ||
294 | } | ||
295 | |||
296 | EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL); | ||
297 | OPENSSL_cleanse(buf,256); | ||
298 | |||
299 | EVP_CIPHER_CTX_init(&ctx); | ||
300 | EVP_DecryptInit_ex(&ctx,EVP_rc4(),NULL, key,NULL); | ||
301 | EVP_DecryptUpdate(&ctx,os->data,&i,os->data,os->length); | ||
302 | EVP_DecryptFinal_ex(&ctx,&(os->data[i]),&j); | ||
303 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
304 | os->length=i+j; | ||
305 | |||
306 | zz=os->data; | ||
307 | |||
308 | if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) | ||
309 | { | ||
310 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY); | ||
311 | goto err; | ||
312 | } | ||
313 | |||
314 | zz=pkey->private_key->data; | ||
315 | if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) | ||
316 | { | ||
317 | ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY); | ||
318 | goto err; | ||
319 | } | ||
320 | err: | ||
321 | NETSCAPE_PKEY_free(pkey); | ||
322 | return(ret); | ||
323 | } | ||
324 | |||
325 | #endif /* OPENSSL_NO_RC4 */ | ||
326 | |||
327 | #else /* !OPENSSL_NO_RSA */ | ||
328 | |||
329 | # if PEDANTIC | ||
330 | static void *dummy=&dummy; | ||
331 | # endif | ||
332 | |||
333 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/nsseq.c b/src/lib/libcrypto/asn1/nsseq.c deleted file mode 100644 index 50e2d4d07a..0000000000 --- a/src/lib/libcrypto/asn1/nsseq.c +++ /dev/null | |||
@@ -1,82 +0,0 @@ | |||
1 | /* nsseq.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include <stdlib.h> | ||
61 | #include <openssl/asn1t.h> | ||
62 | #include <openssl/x509.h> | ||
63 | #include <openssl/objects.h> | ||
64 | |||
65 | static int nsseq_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
66 | { | ||
67 | if(operation == ASN1_OP_NEW_POST) { | ||
68 | NETSCAPE_CERT_SEQUENCE *nsseq; | ||
69 | nsseq = (NETSCAPE_CERT_SEQUENCE *)*pval; | ||
70 | nsseq->type = OBJ_nid2obj(NID_netscape_cert_sequence); | ||
71 | } | ||
72 | return 1; | ||
73 | } | ||
74 | |||
75 | /* Netscape certificate sequence structure */ | ||
76 | |||
77 | ASN1_SEQUENCE_cb(NETSCAPE_CERT_SEQUENCE, nsseq_cb) = { | ||
78 | ASN1_SIMPLE(NETSCAPE_CERT_SEQUENCE, type, ASN1_OBJECT), | ||
79 | ASN1_EXP_SEQUENCE_OF_OPT(NETSCAPE_CERT_SEQUENCE, certs, X509, 0) | ||
80 | } ASN1_SEQUENCE_END_cb(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE) | ||
81 | |||
82 | IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_CERT_SEQUENCE) | ||
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c deleted file mode 100644 index 891150638e..0000000000 --- a/src/lib/libcrypto/asn1/p5_pbe.c +++ /dev/null | |||
@@ -1,122 +0,0 @@ | |||
1 | /* p5_pbe.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1t.h> | ||
62 | #include <openssl/x509.h> | ||
63 | #include <openssl/rand.h> | ||
64 | |||
65 | /* PKCS#5 password based encryption structure */ | ||
66 | |||
67 | ASN1_SEQUENCE(PBEPARAM) = { | ||
68 | ASN1_SIMPLE(PBEPARAM, salt, ASN1_OCTET_STRING), | ||
69 | ASN1_SIMPLE(PBEPARAM, iter, ASN1_INTEGER) | ||
70 | } ASN1_SEQUENCE_END(PBEPARAM) | ||
71 | |||
72 | IMPLEMENT_ASN1_FUNCTIONS(PBEPARAM) | ||
73 | |||
74 | /* Return an algorithm identifier for a PKCS#5 PBE algorithm */ | ||
75 | |||
76 | X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt, | ||
77 | int saltlen) | ||
78 | { | ||
79 | PBEPARAM *pbe; | ||
80 | ASN1_OBJECT *al; | ||
81 | X509_ALGOR *algor; | ||
82 | ASN1_TYPE *astype; | ||
83 | |||
84 | if (!(pbe = PBEPARAM_new ())) { | ||
85 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); | ||
86 | return NULL; | ||
87 | } | ||
88 | if(iter <= 0) iter = PKCS5_DEFAULT_ITER; | ||
89 | ASN1_INTEGER_set (pbe->iter, iter); | ||
90 | if (!saltlen) saltlen = PKCS5_SALT_LEN; | ||
91 | if (!(pbe->salt->data = OPENSSL_malloc (saltlen))) { | ||
92 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); | ||
93 | return NULL; | ||
94 | } | ||
95 | pbe->salt->length = saltlen; | ||
96 | if (salt) memcpy (pbe->salt->data, salt, saltlen); | ||
97 | else if (RAND_pseudo_bytes (pbe->salt->data, saltlen) < 0) | ||
98 | return NULL; | ||
99 | |||
100 | if (!(astype = ASN1_TYPE_new())) { | ||
101 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); | ||
102 | return NULL; | ||
103 | } | ||
104 | |||
105 | astype->type = V_ASN1_SEQUENCE; | ||
106 | if(!ASN1_pack_string(pbe, i2d_PBEPARAM, &astype->value.sequence)) { | ||
107 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); | ||
108 | return NULL; | ||
109 | } | ||
110 | PBEPARAM_free (pbe); | ||
111 | |||
112 | al = OBJ_nid2obj(alg); /* never need to free al */ | ||
113 | if (!(algor = X509_ALGOR_new())) { | ||
114 | ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE); | ||
115 | return NULL; | ||
116 | } | ||
117 | ASN1_OBJECT_free(algor->algorithm); | ||
118 | algor->algorithm = al; | ||
119 | algor->parameter = astype; | ||
120 | |||
121 | return (algor); | ||
122 | } | ||
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c deleted file mode 100644 index 91e1c8987d..0000000000 --- a/src/lib/libcrypto/asn1/p5_pbev2.c +++ /dev/null | |||
@@ -1,203 +0,0 @@ | |||
1 | /* p5_pbev2.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1t.h> | ||
62 | #include <openssl/x509.h> | ||
63 | #include <openssl/rand.h> | ||
64 | |||
65 | /* PKCS#5 v2.0 password based encryption structures */ | ||
66 | |||
67 | ASN1_SEQUENCE(PBE2PARAM) = { | ||
68 | ASN1_SIMPLE(PBE2PARAM, keyfunc, X509_ALGOR), | ||
69 | ASN1_SIMPLE(PBE2PARAM, encryption, X509_ALGOR) | ||
70 | } ASN1_SEQUENCE_END(PBE2PARAM) | ||
71 | |||
72 | IMPLEMENT_ASN1_FUNCTIONS(PBE2PARAM) | ||
73 | |||
74 | ASN1_SEQUENCE(PBKDF2PARAM) = { | ||
75 | ASN1_SIMPLE(PBKDF2PARAM, salt, ASN1_ANY), | ||
76 | ASN1_SIMPLE(PBKDF2PARAM, iter, ASN1_INTEGER), | ||
77 | ASN1_OPT(PBKDF2PARAM, keylength, ASN1_INTEGER), | ||
78 | ASN1_OPT(PBKDF2PARAM, prf, X509_ALGOR) | ||
79 | } ASN1_SEQUENCE_END(PBKDF2PARAM) | ||
80 | |||
81 | IMPLEMENT_ASN1_FUNCTIONS(PBKDF2PARAM) | ||
82 | |||
83 | /* Return an algorithm identifier for a PKCS#5 v2.0 PBE algorithm: | ||
84 | * yes I know this is horrible! | ||
85 | */ | ||
86 | |||
87 | X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter, | ||
88 | unsigned char *salt, int saltlen) | ||
89 | { | ||
90 | X509_ALGOR *scheme = NULL, *kalg = NULL, *ret = NULL; | ||
91 | int alg_nid; | ||
92 | EVP_CIPHER_CTX ctx; | ||
93 | unsigned char iv[EVP_MAX_IV_LENGTH]; | ||
94 | PBKDF2PARAM *kdf = NULL; | ||
95 | PBE2PARAM *pbe2 = NULL; | ||
96 | ASN1_OCTET_STRING *osalt = NULL; | ||
97 | ASN1_OBJECT *obj; | ||
98 | |||
99 | alg_nid = EVP_CIPHER_type(cipher); | ||
100 | if(alg_nid == NID_undef) { | ||
101 | ASN1err(ASN1_F_PKCS5_PBE2_SET, | ||
102 | ASN1_R_CIPHER_HAS_NO_OBJECT_IDENTIFIER); | ||
103 | goto err; | ||
104 | } | ||
105 | obj = OBJ_nid2obj(alg_nid); | ||
106 | |||
107 | if(!(pbe2 = PBE2PARAM_new())) goto merr; | ||
108 | |||
109 | /* Setup the AlgorithmIdentifier for the encryption scheme */ | ||
110 | scheme = pbe2->encryption; | ||
111 | |||
112 | scheme->algorithm = obj; | ||
113 | if(!(scheme->parameter = ASN1_TYPE_new())) goto merr; | ||
114 | |||
115 | /* Create random IV */ | ||
116 | if (RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0) | ||
117 | goto err; | ||
118 | |||
119 | EVP_CIPHER_CTX_init(&ctx); | ||
120 | |||
121 | /* Dummy cipherinit to just setup the IV */ | ||
122 | EVP_CipherInit_ex(&ctx, cipher, NULL, NULL, iv, 0); | ||
123 | if(EVP_CIPHER_param_to_asn1(&ctx, scheme->parameter) < 0) { | ||
124 | ASN1err(ASN1_F_PKCS5_PBE2_SET, | ||
125 | ASN1_R_ERROR_SETTING_CIPHER_PARAMS); | ||
126 | goto err; | ||
127 | } | ||
128 | EVP_CIPHER_CTX_cleanup(&ctx); | ||
129 | |||
130 | if(!(kdf = PBKDF2PARAM_new())) goto merr; | ||
131 | if(!(osalt = M_ASN1_OCTET_STRING_new())) goto merr; | ||
132 | |||
133 | if (!saltlen) saltlen = PKCS5_SALT_LEN; | ||
134 | if (!(osalt->data = OPENSSL_malloc (saltlen))) goto merr; | ||
135 | osalt->length = saltlen; | ||
136 | if (salt) memcpy (osalt->data, salt, saltlen); | ||
137 | else if (RAND_pseudo_bytes (osalt->data, saltlen) < 0) goto merr; | ||
138 | |||
139 | if(iter <= 0) iter = PKCS5_DEFAULT_ITER; | ||
140 | if(!ASN1_INTEGER_set(kdf->iter, iter)) goto merr; | ||
141 | |||
142 | /* Now include salt in kdf structure */ | ||
143 | kdf->salt->value.octet_string = osalt; | ||
144 | kdf->salt->type = V_ASN1_OCTET_STRING; | ||
145 | osalt = NULL; | ||
146 | |||
147 | /* If its RC2 then we'd better setup the key length */ | ||
148 | |||
149 | if(alg_nid == NID_rc2_cbc) { | ||
150 | if(!(kdf->keylength = M_ASN1_INTEGER_new())) goto merr; | ||
151 | if(!ASN1_INTEGER_set (kdf->keylength, | ||
152 | EVP_CIPHER_key_length(cipher))) goto merr; | ||
153 | } | ||
154 | |||
155 | /* prf can stay NULL because we are using hmacWithSHA1 */ | ||
156 | |||
157 | /* Now setup the PBE2PARAM keyfunc structure */ | ||
158 | |||
159 | pbe2->keyfunc->algorithm = OBJ_nid2obj(NID_id_pbkdf2); | ||
160 | |||
161 | /* Encode PBKDF2PARAM into parameter of pbe2 */ | ||
162 | |||
163 | if(!(pbe2->keyfunc->parameter = ASN1_TYPE_new())) goto merr; | ||
164 | |||
165 | if(!ASN1_pack_string(kdf, i2d_PBKDF2PARAM, | ||
166 | &pbe2->keyfunc->parameter->value.sequence)) goto merr; | ||
167 | pbe2->keyfunc->parameter->type = V_ASN1_SEQUENCE; | ||
168 | |||
169 | PBKDF2PARAM_free(kdf); | ||
170 | kdf = NULL; | ||
171 | |||
172 | /* Now set up top level AlgorithmIdentifier */ | ||
173 | |||
174 | if(!(ret = X509_ALGOR_new())) goto merr; | ||
175 | if(!(ret->parameter = ASN1_TYPE_new())) goto merr; | ||
176 | |||
177 | ret->algorithm = OBJ_nid2obj(NID_pbes2); | ||
178 | |||
179 | /* Encode PBE2PARAM into parameter */ | ||
180 | |||
181 | if(!ASN1_pack_string(pbe2, i2d_PBE2PARAM, | ||
182 | &ret->parameter->value.sequence)) goto merr; | ||
183 | ret->parameter->type = V_ASN1_SEQUENCE; | ||
184 | |||
185 | PBE2PARAM_free(pbe2); | ||
186 | pbe2 = NULL; | ||
187 | |||
188 | return ret; | ||
189 | |||
190 | merr: | ||
191 | ASN1err(ASN1_F_PKCS5_PBE2_SET,ERR_R_MALLOC_FAILURE); | ||
192 | |||
193 | err: | ||
194 | PBE2PARAM_free(pbe2); | ||
195 | /* Note 'scheme' is freed as part of pbe2 */ | ||
196 | M_ASN1_OCTET_STRING_free(osalt); | ||
197 | PBKDF2PARAM_free(kdf); | ||
198 | X509_ALGOR_free(kalg); | ||
199 | X509_ALGOR_free(ret); | ||
200 | |||
201 | return NULL; | ||
202 | |||
203 | } | ||
diff --git a/src/lib/libcrypto/asn1/p8_pkey.c b/src/lib/libcrypto/asn1/p8_pkey.c deleted file mode 100644 index 24b409132f..0000000000 --- a/src/lib/libcrypto/asn1/p8_pkey.c +++ /dev/null | |||
@@ -1,84 +0,0 @@ | |||
1 | /* p8_pkey.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1t.h> | ||
62 | #include <openssl/x509.h> | ||
63 | |||
64 | /* Minor tweak to operation: zero private key data */ | ||
65 | static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
66 | { | ||
67 | /* Since the structure must still be valid use ASN1_OP_FREE_PRE */ | ||
68 | if(operation == ASN1_OP_FREE_PRE) { | ||
69 | PKCS8_PRIV_KEY_INFO *key = (PKCS8_PRIV_KEY_INFO *)*pval; | ||
70 | if (key->pkey->value.octet_string) | ||
71 | OPENSSL_cleanse(key->pkey->value.octet_string->data, | ||
72 | key->pkey->value.octet_string->length); | ||
73 | } | ||
74 | return 1; | ||
75 | } | ||
76 | |||
77 | ASN1_SEQUENCE_cb(PKCS8_PRIV_KEY_INFO, pkey_cb) = { | ||
78 | ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, version, ASN1_INTEGER), | ||
79 | ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkeyalg, X509_ALGOR), | ||
80 | ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkey, ASN1_ANY), | ||
81 | ASN1_IMP_SET_OF_OPT(PKCS8_PRIV_KEY_INFO, attributes, X509_ATTRIBUTE, 0) | ||
82 | } ASN1_SEQUENCE_END_cb(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) | ||
83 | |||
84 | IMPLEMENT_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO) | ||
diff --git a/src/lib/libcrypto/asn1/t_bitst.c b/src/lib/libcrypto/asn1/t_bitst.c deleted file mode 100644 index 8ee789f082..0000000000 --- a/src/lib/libcrypto/asn1/t_bitst.c +++ /dev/null | |||
@@ -1,99 +0,0 @@ | |||
1 | /* t_bitst.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/conf.h> | ||
62 | #include <openssl/x509v3.h> | ||
63 | |||
64 | int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs, | ||
65 | BIT_STRING_BITNAME *tbl, int indent) | ||
66 | { | ||
67 | BIT_STRING_BITNAME *bnam; | ||
68 | char first = 1; | ||
69 | BIO_printf(out, "%*s", indent, ""); | ||
70 | for(bnam = tbl; bnam->lname; bnam++) { | ||
71 | if(ASN1_BIT_STRING_get_bit(bs, bnam->bitnum)) { | ||
72 | if(!first) BIO_puts(out, ", "); | ||
73 | BIO_puts(out, bnam->lname); | ||
74 | first = 0; | ||
75 | } | ||
76 | } | ||
77 | BIO_puts(out, "\n"); | ||
78 | return 1; | ||
79 | } | ||
80 | |||
81 | int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value, | ||
82 | BIT_STRING_BITNAME *tbl) | ||
83 | { | ||
84 | int bitnum; | ||
85 | bitnum = ASN1_BIT_STRING_num_asc(name, tbl); | ||
86 | if(bitnum < 0) return 0; | ||
87 | if(bs) ASN1_BIT_STRING_set_bit(bs, bitnum, value); | ||
88 | return 1; | ||
89 | } | ||
90 | |||
91 | int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl) | ||
92 | { | ||
93 | BIT_STRING_BITNAME *bnam; | ||
94 | for(bnam = tbl; bnam->lname; bnam++) { | ||
95 | if(!strcmp(bnam->sname, name) || | ||
96 | !strcmp(bnam->lname, name) ) return bnam->bitnum; | ||
97 | } | ||
98 | return -1; | ||
99 | } | ||
diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c deleted file mode 100644 index 757c148df8..0000000000 --- a/src/lib/libcrypto/asn1/t_crl.c +++ /dev/null | |||
@@ -1,134 +0,0 @@ | |||
1 | /* t_crl.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/buffer.h> | ||
62 | #include <openssl/bn.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/x509.h> | ||
65 | #include <openssl/x509v3.h> | ||
66 | |||
67 | #ifndef OPENSSL_NO_FP_API | ||
68 | int X509_CRL_print_fp(FILE *fp, X509_CRL *x) | ||
69 | { | ||
70 | BIO *b; | ||
71 | int ret; | ||
72 | |||
73 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
74 | { | ||
75 | X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB); | ||
76 | return(0); | ||
77 | } | ||
78 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
79 | ret=X509_CRL_print(b, x); | ||
80 | BIO_free(b); | ||
81 | return(ret); | ||
82 | } | ||
83 | #endif | ||
84 | |||
85 | int X509_CRL_print(BIO *out, X509_CRL *x) | ||
86 | { | ||
87 | STACK_OF(X509_REVOKED) *rev; | ||
88 | X509_REVOKED *r; | ||
89 | long l; | ||
90 | int i, n; | ||
91 | char *p; | ||
92 | |||
93 | BIO_printf(out, "Certificate Revocation List (CRL):\n"); | ||
94 | l = X509_CRL_get_version(x); | ||
95 | BIO_printf(out, "%8sVersion %lu (0x%lx)\n", "", l+1, l); | ||
96 | i = OBJ_obj2nid(x->sig_alg->algorithm); | ||
97 | BIO_printf(out, "%8sSignature Algorithm: %s\n", "", | ||
98 | (i == NID_undef) ? "NONE" : OBJ_nid2ln(i)); | ||
99 | p=X509_NAME_oneline(X509_CRL_get_issuer(x),NULL,0); | ||
100 | BIO_printf(out,"%8sIssuer: %s\n","",p); | ||
101 | OPENSSL_free(p); | ||
102 | BIO_printf(out,"%8sLast Update: ",""); | ||
103 | ASN1_TIME_print(out,X509_CRL_get_lastUpdate(x)); | ||
104 | BIO_printf(out,"\n%8sNext Update: ",""); | ||
105 | if (X509_CRL_get_nextUpdate(x)) | ||
106 | ASN1_TIME_print(out,X509_CRL_get_nextUpdate(x)); | ||
107 | else BIO_printf(out,"NONE"); | ||
108 | BIO_printf(out,"\n"); | ||
109 | |||
110 | n=X509_CRL_get_ext_count(x); | ||
111 | X509V3_extensions_print(out, "CRL extensions", | ||
112 | x->crl->extensions, 0, 8); | ||
113 | |||
114 | rev = X509_CRL_get_REVOKED(x); | ||
115 | |||
116 | if(sk_X509_REVOKED_num(rev) > 0) | ||
117 | BIO_printf(out, "Revoked Certificates:\n"); | ||
118 | else BIO_printf(out, "No Revoked Certificates.\n"); | ||
119 | |||
120 | for(i = 0; i < sk_X509_REVOKED_num(rev); i++) { | ||
121 | r = sk_X509_REVOKED_value(rev, i); | ||
122 | BIO_printf(out," Serial Number: "); | ||
123 | i2a_ASN1_INTEGER(out,r->serialNumber); | ||
124 | BIO_printf(out,"\n Revocation Date: ",""); | ||
125 | ASN1_TIME_print(out,r->revocationDate); | ||
126 | BIO_printf(out,"\n"); | ||
127 | X509V3_extensions_print(out, "CRL entry extensions", | ||
128 | r->extensions, 0, 8); | ||
129 | } | ||
130 | X509_signature_print(out, x->sig_alg, x->signature); | ||
131 | |||
132 | return 1; | ||
133 | |||
134 | } | ||
diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c deleted file mode 100644 index d15006e654..0000000000 --- a/src/lib/libcrypto/asn1/t_pkey.c +++ /dev/null | |||
@@ -1,387 +0,0 @@ | |||
1 | /* crypto/asn1/t_pkey.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/buffer.h> | ||
62 | #include <openssl/bn.h> | ||
63 | #ifndef OPENSSL_NO_RSA | ||
64 | #include <openssl/rsa.h> | ||
65 | #endif | ||
66 | #ifndef OPENSSL_NO_DH | ||
67 | #include <openssl/dh.h> | ||
68 | #endif | ||
69 | #ifndef OPENSSL_NO_DSA | ||
70 | #include <openssl/dsa.h> | ||
71 | #endif | ||
72 | |||
73 | static int print(BIO *fp,const char *str,BIGNUM *num, | ||
74 | unsigned char *buf,int off); | ||
75 | #ifndef OPENSSL_NO_RSA | ||
76 | #ifndef OPENSSL_NO_FP_API | ||
77 | int RSA_print_fp(FILE *fp, const RSA *x, int off) | ||
78 | { | ||
79 | BIO *b; | ||
80 | int ret; | ||
81 | |||
82 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
83 | { | ||
84 | RSAerr(RSA_F_RSA_PRINT_FP,ERR_R_BUF_LIB); | ||
85 | return(0); | ||
86 | } | ||
87 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
88 | ret=RSA_print(b,x,off); | ||
89 | BIO_free(b); | ||
90 | return(ret); | ||
91 | } | ||
92 | #endif | ||
93 | |||
94 | int RSA_print(BIO *bp, const RSA *x, int off) | ||
95 | { | ||
96 | char str[128]; | ||
97 | const char *s; | ||
98 | unsigned char *m=NULL; | ||
99 | int ret=0; | ||
100 | size_t buf_len=0, i; | ||
101 | |||
102 | if (x->n) | ||
103 | buf_len = (size_t)BN_num_bytes(x->n); | ||
104 | if (x->e) | ||
105 | if (buf_len < (i = (size_t)BN_num_bytes(x->e))) | ||
106 | buf_len = i; | ||
107 | if (x->d) | ||
108 | if (buf_len < (i = (size_t)BN_num_bytes(x->d))) | ||
109 | buf_len = i; | ||
110 | if (x->p) | ||
111 | if (buf_len < (i = (size_t)BN_num_bytes(x->p))) | ||
112 | buf_len = i; | ||
113 | if (x->q) | ||
114 | if (buf_len < (i = (size_t)BN_num_bytes(x->q))) | ||
115 | buf_len = i; | ||
116 | if (x->dmp1) | ||
117 | if (buf_len < (i = (size_t)BN_num_bytes(x->dmp1))) | ||
118 | buf_len = i; | ||
119 | if (x->dmq1) | ||
120 | if (buf_len < (i = (size_t)BN_num_bytes(x->dmq1))) | ||
121 | buf_len = i; | ||
122 | if (x->iqmp) | ||
123 | if (buf_len < (i = (size_t)BN_num_bytes(x->iqmp))) | ||
124 | buf_len = i; | ||
125 | |||
126 | m=(unsigned char *)OPENSSL_malloc(buf_len+10); | ||
127 | if (m == NULL) | ||
128 | { | ||
129 | RSAerr(RSA_F_RSA_PRINT,ERR_R_MALLOC_FAILURE); | ||
130 | goto err; | ||
131 | } | ||
132 | |||
133 | if (x->d != NULL) | ||
134 | { | ||
135 | if(!BIO_indent(bp,off,128)) | ||
136 | goto err; | ||
137 | if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->n)) | ||
138 | <= 0) goto err; | ||
139 | } | ||
140 | |||
141 | if (x->d == NULL) | ||
142 | BIO_snprintf(str,sizeof str,"Modulus (%d bit):",BN_num_bits(x->n)); | ||
143 | else | ||
144 | BUF_strlcpy(str,"modulus:",sizeof str); | ||
145 | if (!print(bp,str,x->n,m,off)) goto err; | ||
146 | s=(x->d == NULL)?"Exponent:":"publicExponent:"; | ||
147 | if (!print(bp,s,x->e,m,off)) goto err; | ||
148 | if (!print(bp,"privateExponent:",x->d,m,off)) goto err; | ||
149 | if (!print(bp,"prime1:",x->p,m,off)) goto err; | ||
150 | if (!print(bp,"prime2:",x->q,m,off)) goto err; | ||
151 | if (!print(bp,"exponent1:",x->dmp1,m,off)) goto err; | ||
152 | if (!print(bp,"exponent2:",x->dmq1,m,off)) goto err; | ||
153 | if (!print(bp,"coefficient:",x->iqmp,m,off)) goto err; | ||
154 | ret=1; | ||
155 | err: | ||
156 | if (m != NULL) OPENSSL_free(m); | ||
157 | return(ret); | ||
158 | } | ||
159 | #endif /* OPENSSL_NO_RSA */ | ||
160 | |||
161 | #ifndef OPENSSL_NO_DSA | ||
162 | #ifndef OPENSSL_NO_FP_API | ||
163 | int DSA_print_fp(FILE *fp, const DSA *x, int off) | ||
164 | { | ||
165 | BIO *b; | ||
166 | int ret; | ||
167 | |||
168 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
169 | { | ||
170 | DSAerr(DSA_F_DSA_PRINT_FP,ERR_R_BUF_LIB); | ||
171 | return(0); | ||
172 | } | ||
173 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
174 | ret=DSA_print(b,x,off); | ||
175 | BIO_free(b); | ||
176 | return(ret); | ||
177 | } | ||
178 | #endif | ||
179 | |||
180 | int DSA_print(BIO *bp, const DSA *x, int off) | ||
181 | { | ||
182 | unsigned char *m=NULL; | ||
183 | int ret=0; | ||
184 | size_t buf_len=0,i; | ||
185 | |||
186 | if (x->p) | ||
187 | buf_len = (size_t)BN_num_bytes(x->p); | ||
188 | if (x->q) | ||
189 | if (buf_len < (i = (size_t)BN_num_bytes(x->q))) | ||
190 | buf_len = i; | ||
191 | if (x->g) | ||
192 | if (buf_len < (i = (size_t)BN_num_bytes(x->g))) | ||
193 | buf_len = i; | ||
194 | if (x->priv_key) | ||
195 | if (buf_len < (i = (size_t)BN_num_bytes(x->priv_key))) | ||
196 | buf_len = i; | ||
197 | if (x->pub_key) | ||
198 | if (buf_len < (i = (size_t)BN_num_bytes(x->pub_key))) | ||
199 | buf_len = i; | ||
200 | |||
201 | m=(unsigned char *)OPENSSL_malloc(buf_len+10); | ||
202 | if (m == NULL) | ||
203 | { | ||
204 | DSAerr(DSA_F_DSA_PRINT,ERR_R_MALLOC_FAILURE); | ||
205 | goto err; | ||
206 | } | ||
207 | |||
208 | if (x->priv_key != NULL) | ||
209 | { | ||
210 | if(!BIO_indent(bp,off,128)) | ||
211 | goto err; | ||
212 | if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->p)) | ||
213 | <= 0) goto err; | ||
214 | } | ||
215 | |||
216 | if ((x->priv_key != NULL) && !print(bp,"priv:",x->priv_key,m,off)) | ||
217 | goto err; | ||
218 | if ((x->pub_key != NULL) && !print(bp,"pub: ",x->pub_key,m,off)) | ||
219 | goto err; | ||
220 | if ((x->p != NULL) && !print(bp,"P: ",x->p,m,off)) goto err; | ||
221 | if ((x->q != NULL) && !print(bp,"Q: ",x->q,m,off)) goto err; | ||
222 | if ((x->g != NULL) && !print(bp,"G: ",x->g,m,off)) goto err; | ||
223 | ret=1; | ||
224 | err: | ||
225 | if (m != NULL) OPENSSL_free(m); | ||
226 | return(ret); | ||
227 | } | ||
228 | #endif /* !OPENSSL_NO_DSA */ | ||
229 | |||
230 | static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf, | ||
231 | int off) | ||
232 | { | ||
233 | int n,i; | ||
234 | const char *neg; | ||
235 | |||
236 | if (num == NULL) return(1); | ||
237 | neg=(num->neg)?"-":""; | ||
238 | if(!BIO_indent(bp,off,128)) | ||
239 | return 0; | ||
240 | |||
241 | if (BN_num_bytes(num) <= BN_BYTES) | ||
242 | { | ||
243 | if (BIO_printf(bp,"%s %s%lu (%s0x%lx)\n",number,neg, | ||
244 | (unsigned long)num->d[0],neg,(unsigned long)num->d[0]) | ||
245 | <= 0) return(0); | ||
246 | } | ||
247 | else | ||
248 | { | ||
249 | buf[0]=0; | ||
250 | if (BIO_printf(bp,"%s%s",number, | ||
251 | (neg[0] == '-')?" (Negative)":"") <= 0) | ||
252 | return(0); | ||
253 | n=BN_bn2bin(num,&buf[1]); | ||
254 | |||
255 | if (buf[1] & 0x80) | ||
256 | n++; | ||
257 | else buf++; | ||
258 | |||
259 | for (i=0; i<n; i++) | ||
260 | { | ||
261 | if ((i%15) == 0) | ||
262 | { | ||
263 | if(BIO_puts(bp,"\n") <= 0 | ||
264 | || !BIO_indent(bp,off+4,128)) | ||
265 | return 0; | ||
266 | } | ||
267 | if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":") | ||
268 | <= 0) return(0); | ||
269 | } | ||
270 | if (BIO_write(bp,"\n",1) <= 0) return(0); | ||
271 | } | ||
272 | return(1); | ||
273 | } | ||
274 | |||
275 | #ifndef OPENSSL_NO_DH | ||
276 | #ifndef OPENSSL_NO_FP_API | ||
277 | int DHparams_print_fp(FILE *fp, const DH *x) | ||
278 | { | ||
279 | BIO *b; | ||
280 | int ret; | ||
281 | |||
282 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
283 | { | ||
284 | DHerr(DH_F_DHPARAMS_PRINT_FP,ERR_R_BUF_LIB); | ||
285 | return(0); | ||
286 | } | ||
287 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
288 | ret=DHparams_print(b, x); | ||
289 | BIO_free(b); | ||
290 | return(ret); | ||
291 | } | ||
292 | #endif | ||
293 | |||
294 | int DHparams_print(BIO *bp, const DH *x) | ||
295 | { | ||
296 | unsigned char *m=NULL; | ||
297 | int reason=ERR_R_BUF_LIB,ret=0; | ||
298 | size_t buf_len=0, i; | ||
299 | |||
300 | if (x->p) | ||
301 | buf_len = (size_t)BN_num_bytes(x->p); | ||
302 | if (x->g) | ||
303 | if (buf_len < (i = (size_t)BN_num_bytes(x->g))) | ||
304 | buf_len = i; | ||
305 | m=(unsigned char *)OPENSSL_malloc(buf_len+10); | ||
306 | if (m == NULL) | ||
307 | { | ||
308 | reason=ERR_R_MALLOC_FAILURE; | ||
309 | goto err; | ||
310 | } | ||
311 | |||
312 | if (BIO_printf(bp,"Diffie-Hellman-Parameters: (%d bit)\n", | ||
313 | BN_num_bits(x->p)) <= 0) | ||
314 | goto err; | ||
315 | if (!print(bp,"prime:",x->p,m,4)) goto err; | ||
316 | if (!print(bp,"generator:",x->g,m,4)) goto err; | ||
317 | if (x->length != 0) | ||
318 | { | ||
319 | if (BIO_printf(bp," recommended-private-length: %d bits\n", | ||
320 | (int)x->length) <= 0) goto err; | ||
321 | } | ||
322 | ret=1; | ||
323 | if (0) | ||
324 | { | ||
325 | err: | ||
326 | DHerr(DH_F_DHPARAMS_PRINT,reason); | ||
327 | } | ||
328 | if (m != NULL) OPENSSL_free(m); | ||
329 | return(ret); | ||
330 | } | ||
331 | #endif | ||
332 | |||
333 | #ifndef OPENSSL_NO_DSA | ||
334 | #ifndef OPENSSL_NO_FP_API | ||
335 | int DSAparams_print_fp(FILE *fp, const DSA *x) | ||
336 | { | ||
337 | BIO *b; | ||
338 | int ret; | ||
339 | |||
340 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
341 | { | ||
342 | DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB); | ||
343 | return(0); | ||
344 | } | ||
345 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
346 | ret=DSAparams_print(b, x); | ||
347 | BIO_free(b); | ||
348 | return(ret); | ||
349 | } | ||
350 | #endif | ||
351 | |||
352 | int DSAparams_print(BIO *bp, const DSA *x) | ||
353 | { | ||
354 | unsigned char *m=NULL; | ||
355 | int reason=ERR_R_BUF_LIB,ret=0; | ||
356 | size_t buf_len=0,i; | ||
357 | |||
358 | if (x->p) | ||
359 | buf_len = (size_t)BN_num_bytes(x->p); | ||
360 | if (x->q) | ||
361 | if (buf_len < (i = (size_t)BN_num_bytes(x->q))) | ||
362 | buf_len = i; | ||
363 | if (x->g) | ||
364 | if (buf_len < (i = (size_t)BN_num_bytes(x->g))) | ||
365 | buf_len = i; | ||
366 | m=(unsigned char *)OPENSSL_malloc(buf_len+10); | ||
367 | if (m == NULL) | ||
368 | { | ||
369 | reason=ERR_R_MALLOC_FAILURE; | ||
370 | goto err; | ||
371 | } | ||
372 | |||
373 | if (BIO_printf(bp,"DSA-Parameters: (%d bit)\n", | ||
374 | BN_num_bits(x->p)) <= 0) | ||
375 | goto err; | ||
376 | if (!print(bp,"p:",x->p,m,4)) goto err; | ||
377 | if (!print(bp,"q:",x->q,m,4)) goto err; | ||
378 | if (!print(bp,"g:",x->g,m,4)) goto err; | ||
379 | ret=1; | ||
380 | err: | ||
381 | if (m != NULL) OPENSSL_free(m); | ||
382 | DSAerr(DSA_F_DSAPARAMS_PRINT,reason); | ||
383 | return(ret); | ||
384 | } | ||
385 | |||
386 | #endif /* !OPENSSL_NO_DSA */ | ||
387 | |||
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c deleted file mode 100644 index 740cee80c0..0000000000 --- a/src/lib/libcrypto/asn1/t_req.c +++ /dev/null | |||
@@ -1,276 +0,0 @@ | |||
1 | /* crypto/asn1/t_req.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/buffer.h> | ||
62 | #include <openssl/bn.h> | ||
63 | #include <openssl/objects.h> | ||
64 | #include <openssl/x509.h> | ||
65 | #include <openssl/x509v3.h> | ||
66 | |||
67 | #ifndef OPENSSL_NO_FP_API | ||
68 | int X509_REQ_print_fp(FILE *fp, X509_REQ *x) | ||
69 | { | ||
70 | BIO *b; | ||
71 | int ret; | ||
72 | |||
73 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
74 | { | ||
75 | X509err(X509_F_X509_REQ_PRINT_FP,ERR_R_BUF_LIB); | ||
76 | return(0); | ||
77 | } | ||
78 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
79 | ret=X509_REQ_print(b, x); | ||
80 | BIO_free(b); | ||
81 | return(ret); | ||
82 | } | ||
83 | #endif | ||
84 | |||
85 | int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long cflag) | ||
86 | { | ||
87 | unsigned long l; | ||
88 | int i; | ||
89 | const char *neg; | ||
90 | X509_REQ_INFO *ri; | ||
91 | EVP_PKEY *pkey; | ||
92 | STACK_OF(X509_ATTRIBUTE) *sk; | ||
93 | STACK_OF(X509_EXTENSION) *exts; | ||
94 | char mlch = ' '; | ||
95 | int nmindent = 0; | ||
96 | |||
97 | if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) { | ||
98 | mlch = '\n'; | ||
99 | nmindent = 12; | ||
100 | } | ||
101 | |||
102 | if(nmflags == X509_FLAG_COMPAT) | ||
103 | nmindent = 16; | ||
104 | |||
105 | |||
106 | ri=x->req_info; | ||
107 | if(!(cflag & X509_FLAG_NO_HEADER)) | ||
108 | { | ||
109 | if (BIO_write(bp,"Certificate Request:\n",21) <= 0) goto err; | ||
110 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; | ||
111 | } | ||
112 | if(!(cflag & X509_FLAG_NO_VERSION)) | ||
113 | { | ||
114 | neg=(ri->version->type == V_ASN1_NEG_INTEGER)?"-":""; | ||
115 | l=0; | ||
116 | for (i=0; i<ri->version->length; i++) | ||
117 | { l<<=8; l+=ri->version->data[i]; } | ||
118 | if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg, | ||
119 | l) <= 0) | ||
120 | goto err; | ||
121 | } | ||
122 | if(!(cflag & X509_FLAG_NO_SUBJECT)) | ||
123 | { | ||
124 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; | ||
125 | if (X509_NAME_print_ex(bp,ri->subject,nmindent, nmflags) < 0) goto err; | ||
126 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
127 | } | ||
128 | if(!(cflag & X509_FLAG_NO_PUBKEY)) | ||
129 | { | ||
130 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) | ||
131 | goto err; | ||
132 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) | ||
133 | goto err; | ||
134 | if (i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm) <= 0) | ||
135 | goto err; | ||
136 | if (BIO_puts(bp, "\n") <= 0) | ||
137 | goto err; | ||
138 | |||
139 | pkey=X509_REQ_get_pubkey(x); | ||
140 | if (pkey == NULL) | ||
141 | { | ||
142 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); | ||
143 | ERR_print_errors(bp); | ||
144 | } | ||
145 | else | ||
146 | #ifndef OPENSSL_NO_RSA | ||
147 | if (pkey->type == EVP_PKEY_RSA) | ||
148 | { | ||
149 | BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","", | ||
150 | BN_num_bits(pkey->pkey.rsa->n)); | ||
151 | RSA_print(bp,pkey->pkey.rsa,16); | ||
152 | } | ||
153 | else | ||
154 | #endif | ||
155 | #ifndef OPENSSL_NO_DSA | ||
156 | if (pkey->type == EVP_PKEY_DSA) | ||
157 | { | ||
158 | BIO_printf(bp,"%12sDSA Public Key:\n",""); | ||
159 | DSA_print(bp,pkey->pkey.dsa,16); | ||
160 | } | ||
161 | else | ||
162 | #endif | ||
163 | BIO_printf(bp,"%12sUnknown Public Key:\n",""); | ||
164 | |||
165 | EVP_PKEY_free(pkey); | ||
166 | } | ||
167 | |||
168 | if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) | ||
169 | { | ||
170 | /* may not be */ | ||
171 | if(BIO_printf(bp,"%8sAttributes:\n","") <= 0) | ||
172 | goto err; | ||
173 | |||
174 | sk=x->req_info->attributes; | ||
175 | if (sk_X509_ATTRIBUTE_num(sk) == 0) | ||
176 | { | ||
177 | if(BIO_printf(bp,"%12sa0:00\n","") <= 0) | ||
178 | goto err; | ||
179 | } | ||
180 | else | ||
181 | { | ||
182 | for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) | ||
183 | { | ||
184 | ASN1_TYPE *at; | ||
185 | X509_ATTRIBUTE *a; | ||
186 | ASN1_BIT_STRING *bs=NULL; | ||
187 | ASN1_TYPE *t; | ||
188 | int j,type=0,count=1,ii=0; | ||
189 | |||
190 | a=sk_X509_ATTRIBUTE_value(sk,i); | ||
191 | if(X509_REQ_extension_nid(OBJ_obj2nid(a->object))) | ||
192 | continue; | ||
193 | if(BIO_printf(bp,"%12s","") <= 0) | ||
194 | goto err; | ||
195 | if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) | ||
196 | { | ||
197 | if (a->single) | ||
198 | { | ||
199 | t=a->value.single; | ||
200 | type=t->type; | ||
201 | bs=t->value.bit_string; | ||
202 | } | ||
203 | else | ||
204 | { | ||
205 | ii=0; | ||
206 | count=sk_ASN1_TYPE_num(a->value.set); | ||
207 | get_next: | ||
208 | at=sk_ASN1_TYPE_value(a->value.set,ii); | ||
209 | type=at->type; | ||
210 | bs=at->value.asn1_string; | ||
211 | } | ||
212 | } | ||
213 | for (j=25-j; j>0; j--) | ||
214 | if (BIO_write(bp," ",1) != 1) goto err; | ||
215 | if (BIO_puts(bp,":") <= 0) goto err; | ||
216 | if ( (type == V_ASN1_PRINTABLESTRING) || | ||
217 | (type == V_ASN1_T61STRING) || | ||
218 | (type == V_ASN1_IA5STRING)) | ||
219 | { | ||
220 | if (BIO_write(bp,(char *)bs->data,bs->length) | ||
221 | != bs->length) | ||
222 | goto err; | ||
223 | BIO_puts(bp,"\n"); | ||
224 | } | ||
225 | else | ||
226 | { | ||
227 | BIO_puts(bp,"unable to print attribute\n"); | ||
228 | } | ||
229 | if (++ii < count) goto get_next; | ||
230 | } | ||
231 | } | ||
232 | } | ||
233 | if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) | ||
234 | { | ||
235 | exts = X509_REQ_get_extensions(x); | ||
236 | if(exts) | ||
237 | { | ||
238 | BIO_printf(bp,"%8sRequested Extensions:\n",""); | ||
239 | for (i=0; i<sk_X509_EXTENSION_num(exts); i++) | ||
240 | { | ||
241 | ASN1_OBJECT *obj; | ||
242 | X509_EXTENSION *ex; | ||
243 | int j; | ||
244 | ex=sk_X509_EXTENSION_value(exts, i); | ||
245 | if (BIO_printf(bp,"%12s","") <= 0) goto err; | ||
246 | obj=X509_EXTENSION_get_object(ex); | ||
247 | i2a_ASN1_OBJECT(bp,obj); | ||
248 | j=X509_EXTENSION_get_critical(ex); | ||
249 | if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0) | ||
250 | goto err; | ||
251 | if(!X509V3_EXT_print(bp, ex, 0, 16)) | ||
252 | { | ||
253 | BIO_printf(bp, "%16s", ""); | ||
254 | M_ASN1_OCTET_STRING_print(bp,ex->value); | ||
255 | } | ||
256 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
257 | } | ||
258 | sk_X509_EXTENSION_pop_free(exts, X509_EXTENSION_free); | ||
259 | } | ||
260 | } | ||
261 | |||
262 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) | ||
263 | { | ||
264 | if(!X509_signature_print(bp, x->sig_alg, x->signature)) goto err; | ||
265 | } | ||
266 | |||
267 | return(1); | ||
268 | err: | ||
269 | X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB); | ||
270 | return(0); | ||
271 | } | ||
272 | |||
273 | int X509_REQ_print(BIO *bp, X509_REQ *x) | ||
274 | { | ||
275 | return X509_REQ_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); | ||
276 | } | ||
diff --git a/src/lib/libcrypto/asn1/t_spki.c b/src/lib/libcrypto/asn1/t_spki.c deleted file mode 100644 index 5abfbc815e..0000000000 --- a/src/lib/libcrypto/asn1/t_spki.c +++ /dev/null | |||
@@ -1,116 +0,0 @@ | |||
1 | /* t_spki.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/x509.h> | ||
62 | #include <openssl/asn1.h> | ||
63 | |||
64 | /* Print out an SPKI */ | ||
65 | |||
66 | int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki) | ||
67 | { | ||
68 | EVP_PKEY *pkey; | ||
69 | ASN1_IA5STRING *chal; | ||
70 | int i, n; | ||
71 | char *s; | ||
72 | BIO_printf(out, "Netscape SPKI:\n"); | ||
73 | i=OBJ_obj2nid(spki->spkac->pubkey->algor->algorithm); | ||
74 | BIO_printf(out," Public Key Algorithm: %s\n", | ||
75 | (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); | ||
76 | pkey = X509_PUBKEY_get(spki->spkac->pubkey); | ||
77 | if(!pkey) BIO_printf(out, " Unable to load public key\n"); | ||
78 | else { | ||
79 | #ifndef OPENSSL_NO_RSA | ||
80 | if (pkey->type == EVP_PKEY_RSA) | ||
81 | { | ||
82 | BIO_printf(out," RSA Public Key: (%d bit)\n", | ||
83 | BN_num_bits(pkey->pkey.rsa->n)); | ||
84 | RSA_print(out,pkey->pkey.rsa,2); | ||
85 | } | ||
86 | else | ||
87 | #endif | ||
88 | #ifndef OPENSSL_NO_DSA | ||
89 | if (pkey->type == EVP_PKEY_DSA) | ||
90 | { | ||
91 | BIO_printf(out," DSA Public Key:\n"); | ||
92 | DSA_print(out,pkey->pkey.dsa,2); | ||
93 | } | ||
94 | else | ||
95 | #endif | ||
96 | BIO_printf(out," Unknown Public Key:\n"); | ||
97 | EVP_PKEY_free(pkey); | ||
98 | } | ||
99 | chal = spki->spkac->challenge; | ||
100 | if(chal->length) | ||
101 | BIO_printf(out, " Challenge String: %s\n", chal->data); | ||
102 | i=OBJ_obj2nid(spki->sig_algor->algorithm); | ||
103 | BIO_printf(out," Signature Algorithm: %s", | ||
104 | (i == NID_undef)?"UNKNOWN":OBJ_nid2ln(i)); | ||
105 | |||
106 | n=spki->signature->length; | ||
107 | s=(char *)spki->signature->data; | ||
108 | for (i=0; i<n; i++) | ||
109 | { | ||
110 | if ((i%18) == 0) BIO_write(out,"\n ",7); | ||
111 | BIO_printf(out,"%02x%s",(unsigned char)s[i], | ||
112 | ((i+1) == n)?"":":"); | ||
113 | } | ||
114 | BIO_write(out,"\n",1); | ||
115 | return 1; | ||
116 | } | ||
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c deleted file mode 100644 index 30f68561b7..0000000000 --- a/src/lib/libcrypto/asn1/t_x509.c +++ /dev/null | |||
@@ -1,505 +0,0 @@ | |||
1 | /* crypto/asn1/t_x509.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/buffer.h> | ||
62 | #include <openssl/bn.h> | ||
63 | #ifndef OPENSSL_NO_RSA | ||
64 | #include <openssl/rsa.h> | ||
65 | #endif | ||
66 | #ifndef OPENSSL_NO_DSA | ||
67 | #include <openssl/dsa.h> | ||
68 | #endif | ||
69 | #include <openssl/objects.h> | ||
70 | #include <openssl/x509.h> | ||
71 | #include <openssl/x509v3.h> | ||
72 | |||
73 | #ifndef OPENSSL_NO_FP_API | ||
74 | int X509_print_fp(FILE *fp, X509 *x) | ||
75 | { | ||
76 | return X509_print_ex_fp(fp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); | ||
77 | } | ||
78 | |||
79 | int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cflag) | ||
80 | { | ||
81 | BIO *b; | ||
82 | int ret; | ||
83 | |||
84 | if ((b=BIO_new(BIO_s_file())) == NULL) | ||
85 | { | ||
86 | X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB); | ||
87 | return(0); | ||
88 | } | ||
89 | BIO_set_fp(b,fp,BIO_NOCLOSE); | ||
90 | ret=X509_print_ex(b, x, nmflag, cflag); | ||
91 | BIO_free(b); | ||
92 | return(ret); | ||
93 | } | ||
94 | #endif | ||
95 | |||
96 | int X509_print(BIO *bp, X509 *x) | ||
97 | { | ||
98 | return X509_print_ex(bp, x, XN_FLAG_COMPAT, X509_FLAG_COMPAT); | ||
99 | } | ||
100 | |||
101 | int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag) | ||
102 | { | ||
103 | long l; | ||
104 | int ret=0,i; | ||
105 | char *m=NULL,mlch = ' '; | ||
106 | int nmindent = 0; | ||
107 | X509_CINF *ci; | ||
108 | ASN1_INTEGER *bs; | ||
109 | EVP_PKEY *pkey=NULL; | ||
110 | const char *neg; | ||
111 | ASN1_STRING *str=NULL; | ||
112 | |||
113 | if((nmflags & XN_FLAG_SEP_MASK) == XN_FLAG_SEP_MULTILINE) { | ||
114 | mlch = '\n'; | ||
115 | nmindent = 12; | ||
116 | } | ||
117 | |||
118 | if(nmflags == X509_FLAG_COMPAT) | ||
119 | nmindent = 16; | ||
120 | |||
121 | ci=x->cert_info; | ||
122 | if(!(cflag & X509_FLAG_NO_HEADER)) | ||
123 | { | ||
124 | if (BIO_write(bp,"Certificate:\n",13) <= 0) goto err; | ||
125 | if (BIO_write(bp," Data:\n",10) <= 0) goto err; | ||
126 | } | ||
127 | if(!(cflag & X509_FLAG_NO_VERSION)) | ||
128 | { | ||
129 | l=X509_get_version(x); | ||
130 | if (BIO_printf(bp,"%8sVersion: %lu (0x%lx)\n","",l+1,l) <= 0) goto err; | ||
131 | } | ||
132 | if(!(cflag & X509_FLAG_NO_SERIAL)) | ||
133 | { | ||
134 | |||
135 | if (BIO_write(bp," Serial Number:",22) <= 0) goto err; | ||
136 | |||
137 | bs=X509_get_serialNumber(x); | ||
138 | if (bs->length <= 4) | ||
139 | { | ||
140 | l=ASN1_INTEGER_get(bs); | ||
141 | if (l < 0) | ||
142 | { | ||
143 | l= -l; | ||
144 | neg="-"; | ||
145 | } | ||
146 | else | ||
147 | neg=""; | ||
148 | if (BIO_printf(bp," %s%lu (%s0x%lx)\n",neg,l,neg,l) <= 0) | ||
149 | goto err; | ||
150 | } | ||
151 | else | ||
152 | { | ||
153 | neg=(bs->type == V_ASN1_NEG_INTEGER)?" (Negative)":""; | ||
154 | if (BIO_printf(bp,"\n%12s%s","",neg) <= 0) goto err; | ||
155 | |||
156 | for (i=0; i<bs->length; i++) | ||
157 | { | ||
158 | if (BIO_printf(bp,"%02x%c",bs->data[i], | ||
159 | ((i+1 == bs->length)?'\n':':')) <= 0) | ||
160 | goto err; | ||
161 | } | ||
162 | } | ||
163 | |||
164 | } | ||
165 | |||
166 | if(!(cflag & X509_FLAG_NO_SIGNAME)) | ||
167 | { | ||
168 | if (BIO_printf(bp,"%8sSignature Algorithm: ","") <= 0) | ||
169 | goto err; | ||
170 | if (i2a_ASN1_OBJECT(bp, ci->signature->algorithm) <= 0) | ||
171 | goto err; | ||
172 | if (BIO_puts(bp, "\n") <= 0) | ||
173 | goto err; | ||
174 | } | ||
175 | |||
176 | if(!(cflag & X509_FLAG_NO_ISSUER)) | ||
177 | { | ||
178 | if (BIO_printf(bp," Issuer:%c",mlch) <= 0) goto err; | ||
179 | if (X509_NAME_print_ex(bp,X509_get_issuer_name(x),nmindent, nmflags) < 0) goto err; | ||
180 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
181 | } | ||
182 | if(!(cflag & X509_FLAG_NO_VALIDITY)) | ||
183 | { | ||
184 | if (BIO_write(bp," Validity\n",17) <= 0) goto err; | ||
185 | if (BIO_write(bp," Not Before: ",24) <= 0) goto err; | ||
186 | if (!ASN1_TIME_print(bp,X509_get_notBefore(x))) goto err; | ||
187 | if (BIO_write(bp,"\n Not After : ",25) <= 0) goto err; | ||
188 | if (!ASN1_TIME_print(bp,X509_get_notAfter(x))) goto err; | ||
189 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
190 | } | ||
191 | if(!(cflag & X509_FLAG_NO_SUBJECT)) | ||
192 | { | ||
193 | if (BIO_printf(bp," Subject:%c",mlch) <= 0) goto err; | ||
194 | if (X509_NAME_print_ex(bp,X509_get_subject_name(x),nmindent, nmflags) < 0) goto err; | ||
195 | if (BIO_write(bp,"\n",1) <= 0) goto err; | ||
196 | } | ||
197 | if(!(cflag & X509_FLAG_NO_PUBKEY)) | ||
198 | { | ||
199 | if (BIO_write(bp," Subject Public Key Info:\n",33) <= 0) | ||
200 | goto err; | ||
201 | if (BIO_printf(bp,"%12sPublic Key Algorithm: ","") <= 0) | ||
202 | goto err; | ||
203 | if (i2a_ASN1_OBJECT(bp, ci->key->algor->algorithm) <= 0) | ||
204 | goto err; | ||
205 | if (BIO_puts(bp, "\n") <= 0) | ||
206 | goto err; | ||
207 | |||
208 | pkey=X509_get_pubkey(x); | ||
209 | if (pkey == NULL) | ||
210 | { | ||
211 | BIO_printf(bp,"%12sUnable to load Public Key\n",""); | ||
212 | ERR_print_errors(bp); | ||
213 | } | ||
214 | else | ||
215 | #ifndef OPENSSL_NO_RSA | ||
216 | if (pkey->type == EVP_PKEY_RSA) | ||
217 | { | ||
218 | BIO_printf(bp,"%12sRSA Public Key: (%d bit)\n","", | ||
219 | BN_num_bits(pkey->pkey.rsa->n)); | ||
220 | RSA_print(bp,pkey->pkey.rsa,16); | ||
221 | } | ||
222 | else | ||
223 | #endif | ||
224 | #ifndef OPENSSL_NO_DSA | ||
225 | if (pkey->type == EVP_PKEY_DSA) | ||
226 | { | ||
227 | BIO_printf(bp,"%12sDSA Public Key:\n",""); | ||
228 | DSA_print(bp,pkey->pkey.dsa,16); | ||
229 | } | ||
230 | else | ||
231 | #endif | ||
232 | BIO_printf(bp,"%12sUnknown Public Key:\n",""); | ||
233 | |||
234 | EVP_PKEY_free(pkey); | ||
235 | } | ||
236 | |||
237 | if (!(cflag & X509_FLAG_NO_EXTENSIONS)) | ||
238 | X509V3_extensions_print(bp, "X509v3 extensions", | ||
239 | ci->extensions, cflag, 8); | ||
240 | |||
241 | if(!(cflag & X509_FLAG_NO_SIGDUMP)) | ||
242 | { | ||
243 | if(X509_signature_print(bp, x->sig_alg, x->signature) <= 0) goto err; | ||
244 | } | ||
245 | if(!(cflag & X509_FLAG_NO_AUX)) | ||
246 | { | ||
247 | if (!X509_CERT_AUX_print(bp, x->aux, 0)) goto err; | ||
248 | } | ||
249 | ret=1; | ||
250 | err: | ||
251 | if (str != NULL) ASN1_STRING_free(str); | ||
252 | if (m != NULL) OPENSSL_free(m); | ||
253 | return(ret); | ||
254 | } | ||
255 | |||
256 | int X509_ocspid_print (BIO *bp, X509 *x) | ||
257 | { | ||
258 | unsigned char *der=NULL ; | ||
259 | unsigned char *dertmp; | ||
260 | int derlen; | ||
261 | int i; | ||
262 | unsigned char SHA1md[SHA_DIGEST_LENGTH]; | ||
263 | |||
264 | /* display the hash of the subject as it would appear | ||
265 | in OCSP requests */ | ||
266 | if (BIO_printf(bp," Subject OCSP hash: ") <= 0) | ||
267 | goto err; | ||
268 | derlen = i2d_X509_NAME(x->cert_info->subject, NULL); | ||
269 | if ((der = dertmp = (unsigned char *)OPENSSL_malloc (derlen)) == NULL) | ||
270 | goto err; | ||
271 | i2d_X509_NAME(x->cert_info->subject, &dertmp); | ||
272 | |||
273 | EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL); | ||
274 | for (i=0; i < SHA_DIGEST_LENGTH; i++) | ||
275 | { | ||
276 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err; | ||
277 | } | ||
278 | OPENSSL_free (der); | ||
279 | der=NULL; | ||
280 | |||
281 | /* display the hash of the public key as it would appear | ||
282 | in OCSP requests */ | ||
283 | if (BIO_printf(bp,"\n Public key OCSP hash: ") <= 0) | ||
284 | goto err; | ||
285 | |||
286 | EVP_Digest(x->cert_info->key->public_key->data, | ||
287 | x->cert_info->key->public_key->length, SHA1md, NULL, EVP_sha1(), NULL); | ||
288 | for (i=0; i < SHA_DIGEST_LENGTH; i++) | ||
289 | { | ||
290 | if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) | ||
291 | goto err; | ||
292 | } | ||
293 | BIO_printf(bp,"\n"); | ||
294 | |||
295 | return (1); | ||
296 | err: | ||
297 | if (der != NULL) OPENSSL_free(der); | ||
298 | return(0); | ||
299 | } | ||
300 | |||
301 | int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig) | ||
302 | { | ||
303 | unsigned char *s; | ||
304 | int i, n; | ||
305 | if (BIO_puts(bp," Signature Algorithm: ") <= 0) return 0; | ||
306 | if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0; | ||
307 | |||
308 | n=sig->length; | ||
309 | s=sig->data; | ||
310 | for (i=0; i<n; i++) | ||
311 | { | ||
312 | if ((i%18) == 0) | ||
313 | if (BIO_write(bp,"\n ",9) <= 0) return 0; | ||
314 | if (BIO_printf(bp,"%02x%s",s[i], | ||
315 | ((i+1) == n)?"":":") <= 0) return 0; | ||
316 | } | ||
317 | if (BIO_write(bp,"\n",1) != 1) return 0; | ||
318 | return 1; | ||
319 | } | ||
320 | |||
321 | int ASN1_STRING_print(BIO *bp, ASN1_STRING *v) | ||
322 | { | ||
323 | int i,n; | ||
324 | char buf[80],*p; | ||
325 | |||
326 | if (v == NULL) return(0); | ||
327 | n=0; | ||
328 | p=(char *)v->data; | ||
329 | for (i=0; i<v->length; i++) | ||
330 | { | ||
331 | if ((p[i] > '~') || ((p[i] < ' ') && | ||
332 | (p[i] != '\n') && (p[i] != '\r'))) | ||
333 | buf[n]='.'; | ||
334 | else | ||
335 | buf[n]=p[i]; | ||
336 | n++; | ||
337 | if (n >= 80) | ||
338 | { | ||
339 | if (BIO_write(bp,buf,n) <= 0) | ||
340 | return(0); | ||
341 | n=0; | ||
342 | } | ||
343 | } | ||
344 | if (n > 0) | ||
345 | if (BIO_write(bp,buf,n) <= 0) | ||
346 | return(0); | ||
347 | return(1); | ||
348 | } | ||
349 | |||
350 | int ASN1_TIME_print(BIO *bp, ASN1_TIME *tm) | ||
351 | { | ||
352 | if(tm->type == V_ASN1_UTCTIME) return ASN1_UTCTIME_print(bp, tm); | ||
353 | if(tm->type == V_ASN1_GENERALIZEDTIME) | ||
354 | return ASN1_GENERALIZEDTIME_print(bp, tm); | ||
355 | BIO_write(bp,"Bad time value",14); | ||
356 | return(0); | ||
357 | } | ||
358 | |||
359 | static const char *mon[12]= | ||
360 | { | ||
361 | "Jan","Feb","Mar","Apr","May","Jun", | ||
362 | "Jul","Aug","Sep","Oct","Nov","Dec" | ||
363 | }; | ||
364 | |||
365 | int ASN1_GENERALIZEDTIME_print(BIO *bp, ASN1_GENERALIZEDTIME *tm) | ||
366 | { | ||
367 | char *v; | ||
368 | int gmt=0; | ||
369 | int i; | ||
370 | int y=0,M=0,d=0,h=0,m=0,s=0; | ||
371 | |||
372 | i=tm->length; | ||
373 | v=(char *)tm->data; | ||
374 | |||
375 | if (i < 12) goto err; | ||
376 | if (v[i-1] == 'Z') gmt=1; | ||
377 | for (i=0; i<12; i++) | ||
378 | if ((v[i] > '9') || (v[i] < '0')) goto err; | ||
379 | y= (v[0]-'0')*1000+(v[1]-'0')*100 + (v[2]-'0')*10+(v[3]-'0'); | ||
380 | M= (v[4]-'0')*10+(v[5]-'0'); | ||
381 | if ((M > 12) || (M < 1)) goto err; | ||
382 | d= (v[6]-'0')*10+(v[7]-'0'); | ||
383 | h= (v[8]-'0')*10+(v[9]-'0'); | ||
384 | m= (v[10]-'0')*10+(v[11]-'0'); | ||
385 | if ( (v[12] >= '0') && (v[12] <= '9') && | ||
386 | (v[13] >= '0') && (v[13] <= '9')) | ||
387 | s= (v[12]-'0')*10+(v[13]-'0'); | ||
388 | |||
389 | if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s", | ||
390 | mon[M-1],d,h,m,s,y,(gmt)?" GMT":"") <= 0) | ||
391 | return(0); | ||
392 | else | ||
393 | return(1); | ||
394 | err: | ||
395 | BIO_write(bp,"Bad time value",14); | ||
396 | return(0); | ||
397 | } | ||
398 | |||
399 | int ASN1_UTCTIME_print(BIO *bp, ASN1_UTCTIME *tm) | ||
400 | { | ||
401 | char *v; | ||
402 | int gmt=0; | ||
403 | int i; | ||
404 | int y=0,M=0,d=0,h=0,m=0,s=0; | ||
405 | |||
406 | i=tm->length; | ||
407 | v=(char *)tm->data; | ||
408 | |||
409 | if (i < 10) goto err; | ||
410 | if (v[i-1] == 'Z') gmt=1; | ||
411 | for (i=0; i<10; i++) | ||
412 | if ((v[i] > '9') || (v[i] < '0')) goto err; | ||
413 | y= (v[0]-'0')*10+(v[1]-'0'); | ||
414 | if (y < 50) y+=100; | ||
415 | M= (v[2]-'0')*10+(v[3]-'0'); | ||
416 | if ((M > 12) || (M < 1)) goto err; | ||
417 | d= (v[4]-'0')*10+(v[5]-'0'); | ||
418 | h= (v[6]-'0')*10+(v[7]-'0'); | ||
419 | m= (v[8]-'0')*10+(v[9]-'0'); | ||
420 | if ( (v[10] >= '0') && (v[10] <= '9') && | ||
421 | (v[11] >= '0') && (v[11] <= '9')) | ||
422 | s= (v[10]-'0')*10+(v[11]-'0'); | ||
423 | |||
424 | if (BIO_printf(bp,"%s %2d %02d:%02d:%02d %d%s", | ||
425 | mon[M-1],d,h,m,s,y+1900,(gmt)?" GMT":"") <= 0) | ||
426 | return(0); | ||
427 | else | ||
428 | return(1); | ||
429 | err: | ||
430 | BIO_write(bp,"Bad time value",14); | ||
431 | return(0); | ||
432 | } | ||
433 | |||
434 | int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) | ||
435 | { | ||
436 | char *s,*c,*b; | ||
437 | int ret=0,l,ll,i,first=1; | ||
438 | |||
439 | ll=80-2-obase; | ||
440 | |||
441 | b=s=X509_NAME_oneline(name,NULL,0); | ||
442 | if (!*s) | ||
443 | { | ||
444 | OPENSSL_free(b); | ||
445 | return 1; | ||
446 | } | ||
447 | s++; /* skip the first slash */ | ||
448 | |||
449 | l=ll; | ||
450 | c=s; | ||
451 | for (;;) | ||
452 | { | ||
453 | #ifndef CHARSET_EBCDIC | ||
454 | if ( ((*s == '/') && | ||
455 | ((s[1] >= 'A') && (s[1] <= 'Z') && ( | ||
456 | (s[2] == '=') || | ||
457 | ((s[2] >= 'A') && (s[2] <= 'Z') && | ||
458 | (s[3] == '=')) | ||
459 | ))) || | ||
460 | (*s == '\0')) | ||
461 | #else | ||
462 | if ( ((*s == '/') && | ||
463 | (isupper(s[1]) && ( | ||
464 | (s[2] == '=') || | ||
465 | (isupper(s[2]) && | ||
466 | (s[3] == '=')) | ||
467 | ))) || | ||
468 | (*s == '\0')) | ||
469 | #endif | ||
470 | { | ||
471 | if ((l <= 0) && !first) | ||
472 | { | ||
473 | first=0; | ||
474 | if (BIO_write(bp,"\n",1) != 1) goto err; | ||
475 | for (i=0; i<obase; i++) | ||
476 | { | ||
477 | if (BIO_write(bp," ",1) != 1) goto err; | ||
478 | } | ||
479 | l=ll; | ||
480 | } | ||
481 | i=s-c; | ||
482 | if (BIO_write(bp,c,i) != i) goto err; | ||
483 | c+=i; | ||
484 | c++; | ||
485 | if (*s != '\0') | ||
486 | { | ||
487 | if (BIO_write(bp,", ",2) != 2) goto err; | ||
488 | } | ||
489 | l--; | ||
490 | } | ||
491 | if (*s == '\0') break; | ||
492 | s++; | ||
493 | l--; | ||
494 | } | ||
495 | |||
496 | ret=1; | ||
497 | if (0) | ||
498 | { | ||
499 | err: | ||
500 | X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB); | ||
501 | } | ||
502 | OPENSSL_free(b); | ||
503 | return(ret); | ||
504 | } | ||
505 | |||
diff --git a/src/lib/libcrypto/asn1/t_x509a.c b/src/lib/libcrypto/asn1/t_x509a.c deleted file mode 100644 index ffbbfb51f4..0000000000 --- a/src/lib/libcrypto/asn1/t_x509a.c +++ /dev/null | |||
@@ -1,110 +0,0 @@ | |||
1 | /* t_x509a.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/evp.h> | ||
62 | #include <openssl/asn1.h> | ||
63 | #include <openssl/x509.h> | ||
64 | |||
65 | /* X509_CERT_AUX and string set routines | ||
66 | */ | ||
67 | |||
68 | int X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent) | ||
69 | { | ||
70 | char oidstr[80], first; | ||
71 | int i; | ||
72 | if(!aux) return 1; | ||
73 | if(aux->trust) { | ||
74 | first = 1; | ||
75 | BIO_printf(out, "%*sTrusted Uses:\n%*s", | ||
76 | indent, "", indent + 2, ""); | ||
77 | for(i = 0; i < sk_ASN1_OBJECT_num(aux->trust); i++) { | ||
78 | if(!first) BIO_puts(out, ", "); | ||
79 | else first = 0; | ||
80 | OBJ_obj2txt(oidstr, sizeof oidstr, | ||
81 | sk_ASN1_OBJECT_value(aux->trust, i), 0); | ||
82 | BIO_puts(out, oidstr); | ||
83 | } | ||
84 | BIO_puts(out, "\n"); | ||
85 | } else BIO_printf(out, "%*sNo Trusted Uses.\n", indent, ""); | ||
86 | if(aux->reject) { | ||
87 | first = 1; | ||
88 | BIO_printf(out, "%*sRejected Uses:\n%*s", | ||
89 | indent, "", indent + 2, ""); | ||
90 | for(i = 0; i < sk_ASN1_OBJECT_num(aux->reject); i++) { | ||
91 | if(!first) BIO_puts(out, ", "); | ||
92 | else first = 0; | ||
93 | OBJ_obj2txt(oidstr, sizeof oidstr, | ||
94 | sk_ASN1_OBJECT_value(aux->reject, i), 0); | ||
95 | BIO_puts(out, oidstr); | ||
96 | } | ||
97 | BIO_puts(out, "\n"); | ||
98 | } else BIO_printf(out, "%*sNo Rejected Uses.\n", indent, ""); | ||
99 | if(aux->alias) BIO_printf(out, "%*sAlias: %s\n", indent, "", | ||
100 | aux->alias->data); | ||
101 | if(aux->keyid) { | ||
102 | BIO_printf(out, "%*sKey Id: ", indent, ""); | ||
103 | for(i = 0; i < aux->keyid->length; i++) | ||
104 | BIO_printf(out, "%s%02X", | ||
105 | i ? ":" : "", | ||
106 | aux->keyid->data[i]); | ||
107 | BIO_write(out,"\n",1); | ||
108 | } | ||
109 | return 1; | ||
110 | } | ||
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c deleted file mode 100644 index 2426cb6253..0000000000 --- a/src/lib/libcrypto/asn1/tasn_dec.c +++ /dev/null | |||
@@ -1,965 +0,0 @@ | |||
1 | /* tasn_dec.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | |||
60 | #include <stddef.h> | ||
61 | #include <string.h> | ||
62 | #include <openssl/asn1.h> | ||
63 | #include <openssl/asn1t.h> | ||
64 | #include <openssl/objects.h> | ||
65 | #include <openssl/buffer.h> | ||
66 | #include <openssl/err.h> | ||
67 | |||
68 | static int asn1_check_eoc(unsigned char **in, long len); | ||
69 | static int asn1_collect(BUF_MEM *buf, unsigned char **in, long len, char inf, int tag, int aclass); | ||
70 | static int collect_data(BUF_MEM *buf, unsigned char **p, long plen); | ||
71 | static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf, char *cst, | ||
72 | unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx); | ||
73 | static int asn1_template_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx); | ||
74 | static int asn1_template_noexp_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx); | ||
75 | static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, unsigned char **in, long len, | ||
76 | const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx); | ||
77 | |||
78 | /* Table to convert tags to bit values, used for MSTRING type */ | ||
79 | static unsigned long tag2bit[32]={ | ||
80 | 0, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */ | ||
81 | B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */ | ||
82 | B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */ | ||
83 | B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */ | ||
84 | 0, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, /* tags 16-19 */ | ||
85 | B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING, /* tags 20-22 */ | ||
86 | B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME, /* tags 23-24 */ | ||
87 | B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, /* tags 25-27 */ | ||
88 | B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 28-31 */ | ||
89 | }; | ||
90 | |||
91 | unsigned long ASN1_tag2bit(int tag) | ||
92 | { | ||
93 | if((tag < 0) || (tag > 30)) return 0; | ||
94 | return tag2bit[tag]; | ||
95 | } | ||
96 | |||
97 | /* Macro to initialize and invalidate the cache */ | ||
98 | |||
99 | #define asn1_tlc_clear(c) if(c) (c)->valid = 0 | ||
100 | |||
101 | /* Decode an ASN1 item, this currently behaves just | ||
102 | * like a standard 'd2i' function. 'in' points to | ||
103 | * a buffer to read the data from, in future we will | ||
104 | * have more advanced versions that can input data | ||
105 | * a piece at a time and this will simply be a special | ||
106 | * case. | ||
107 | */ | ||
108 | |||
109 | ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it) | ||
110 | { | ||
111 | ASN1_TLC c; | ||
112 | ASN1_VALUE *ptmpval = NULL; | ||
113 | if(!pval) pval = &ptmpval; | ||
114 | asn1_tlc_clear(&c); | ||
115 | if(ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0) | ||
116 | return *pval; | ||
117 | return NULL; | ||
118 | } | ||
119 | |||
120 | int ASN1_template_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt) | ||
121 | { | ||
122 | ASN1_TLC c; | ||
123 | asn1_tlc_clear(&c); | ||
124 | return asn1_template_ex_d2i(pval, in, len, tt, 0, &c); | ||
125 | } | ||
126 | |||
127 | |||
128 | /* Decode an item, taking care of IMPLICIT tagging, if any. | ||
129 | * If 'opt' set and tag mismatch return -1 to handle OPTIONAL | ||
130 | */ | ||
131 | |||
132 | int ASN1_item_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it, | ||
133 | int tag, int aclass, char opt, ASN1_TLC *ctx) | ||
134 | { | ||
135 | const ASN1_TEMPLATE *tt, *errtt = NULL; | ||
136 | const ASN1_COMPAT_FUNCS *cf; | ||
137 | const ASN1_EXTERN_FUNCS *ef; | ||
138 | const ASN1_AUX *aux = it->funcs; | ||
139 | ASN1_aux_cb *asn1_cb; | ||
140 | unsigned char *p, *q, imphack = 0, oclass; | ||
141 | char seq_eoc, seq_nolen, cst, isopt; | ||
142 | long tmplen; | ||
143 | int i; | ||
144 | int otag; | ||
145 | int ret = 0; | ||
146 | ASN1_VALUE *pchval, **pchptr, *ptmpval; | ||
147 | if(!pval) return 0; | ||
148 | if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb; | ||
149 | else asn1_cb = 0; | ||
150 | |||
151 | switch(it->itype) { | ||
152 | |||
153 | case ASN1_ITYPE_PRIMITIVE: | ||
154 | if(it->templates) { | ||
155 | /* tagging or OPTIONAL is currently illegal on an item template | ||
156 | * because the flags can't get passed down. In practice this isn't | ||
157 | * a problem: we include the relevant flags from the item template | ||
158 | * in the template itself. | ||
159 | */ | ||
160 | if ((tag != -1) || opt) { | ||
161 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE); | ||
162 | goto err; | ||
163 | } | ||
164 | return asn1_template_ex_d2i(pval, in, len, it->templates, opt, ctx); | ||
165 | } | ||
166 | return asn1_d2i_ex_primitive(pval, in, len, it, tag, aclass, opt, ctx); | ||
167 | break; | ||
168 | |||
169 | case ASN1_ITYPE_MSTRING: | ||
170 | p = *in; | ||
171 | /* Just read in tag and class */ | ||
172 | ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, &p, len, -1, 0, 1, ctx); | ||
173 | if(!ret) { | ||
174 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); | ||
175 | goto err; | ||
176 | } | ||
177 | /* Must be UNIVERSAL class */ | ||
178 | if(oclass != V_ASN1_UNIVERSAL) { | ||
179 | /* If OPTIONAL, assume this is OK */ | ||
180 | if(opt) return -1; | ||
181 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_NOT_UNIVERSAL); | ||
182 | goto err; | ||
183 | } | ||
184 | /* Check tag matches bit map */ | ||
185 | if(!(ASN1_tag2bit(otag) & it->utype)) { | ||
186 | /* If OPTIONAL, assume this is OK */ | ||
187 | if(opt) return -1; | ||
188 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_WRONG_TAG); | ||
189 | goto err; | ||
190 | } | ||
191 | return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0, ctx); | ||
192 | |||
193 | case ASN1_ITYPE_EXTERN: | ||
194 | /* Use new style d2i */ | ||
195 | ef = it->funcs; | ||
196 | return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx); | ||
197 | |||
198 | case ASN1_ITYPE_COMPAT: | ||
199 | /* we must resort to old style evil hackery */ | ||
200 | cf = it->funcs; | ||
201 | |||
202 | /* If OPTIONAL see if it is there */ | ||
203 | if(opt) { | ||
204 | int exptag; | ||
205 | p = *in; | ||
206 | if(tag == -1) exptag = it->utype; | ||
207 | else exptag = tag; | ||
208 | /* Don't care about anything other than presence of expected tag */ | ||
209 | ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, &p, len, exptag, aclass, 1, ctx); | ||
210 | if(!ret) { | ||
211 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); | ||
212 | goto err; | ||
213 | } | ||
214 | if(ret == -1) return -1; | ||
215 | } | ||
216 | /* This is the old style evil hack IMPLICIT handling: | ||
217 | * since the underlying code is expecting a tag and | ||
218 | * class other than the one present we change the | ||
219 | * buffer temporarily then change it back afterwards. | ||
220 | * This doesn't and never did work for tags > 30. | ||
221 | * | ||
222 | * Yes this is *horrible* but it is only needed for | ||
223 | * old style d2i which will hopefully not be around | ||
224 | * for much longer. | ||
225 | * FIXME: should copy the buffer then modify it so | ||
226 | * the input buffer can be const: we should *always* | ||
227 | * copy because the old style d2i might modify the | ||
228 | * buffer. | ||
229 | */ | ||
230 | |||
231 | if(tag != -1) { | ||
232 | p = *in; | ||
233 | imphack = *p; | ||
234 | *p = (unsigned char)((*p & V_ASN1_CONSTRUCTED) | it->utype); | ||
235 | } | ||
236 | |||
237 | ptmpval = cf->asn1_d2i(pval, in, len); | ||
238 | |||
239 | if(tag != -1) *p = imphack; | ||
240 | |||
241 | if(ptmpval) return 1; | ||
242 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); | ||
243 | goto err; | ||
244 | |||
245 | |||
246 | case ASN1_ITYPE_CHOICE: | ||
247 | if(asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it)) | ||
248 | goto auxerr; | ||
249 | |||
250 | /* Allocate structure */ | ||
251 | if(!*pval) { | ||
252 | if(!ASN1_item_ex_new(pval, it)) { | ||
253 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); | ||
254 | goto err; | ||
255 | } | ||
256 | } | ||
257 | /* CHOICE type, try each possibility in turn */ | ||
258 | pchval = NULL; | ||
259 | p = *in; | ||
260 | for(i = 0, tt=it->templates; i < it->tcount; i++, tt++) { | ||
261 | pchptr = asn1_get_field_ptr(pval, tt); | ||
262 | /* We mark field as OPTIONAL so its absence | ||
263 | * can be recognised. | ||
264 | */ | ||
265 | ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx); | ||
266 | /* If field not present, try the next one */ | ||
267 | if(ret == -1) continue; | ||
268 | /* If positive return, read OK, break loop */ | ||
269 | if(ret > 0) break; | ||
270 | /* Otherwise must be an ASN1 parsing error */ | ||
271 | errtt = tt; | ||
272 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); | ||
273 | goto err; | ||
274 | } | ||
275 | /* Did we fall off the end without reading anything? */ | ||
276 | if(i == it->tcount) { | ||
277 | /* If OPTIONAL, this is OK */ | ||
278 | if(opt) { | ||
279 | /* Free and zero it */ | ||
280 | ASN1_item_ex_free(pval, it); | ||
281 | return -1; | ||
282 | } | ||
283 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_NO_MATCHING_CHOICE_TYPE); | ||
284 | goto err; | ||
285 | } | ||
286 | asn1_set_choice_selector(pval, i, it); | ||
287 | *in = p; | ||
288 | if(asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it)) | ||
289 | goto auxerr; | ||
290 | return 1; | ||
291 | |||
292 | case ASN1_ITYPE_SEQUENCE: | ||
293 | p = *in; | ||
294 | tmplen = len; | ||
295 | |||
296 | /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ | ||
297 | if(tag == -1) { | ||
298 | tag = V_ASN1_SEQUENCE; | ||
299 | aclass = V_ASN1_UNIVERSAL; | ||
300 | } | ||
301 | /* Get SEQUENCE length and update len, p */ | ||
302 | ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, &p, len, tag, aclass, opt, ctx); | ||
303 | if(!ret) { | ||
304 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); | ||
305 | goto err; | ||
306 | } else if(ret == -1) return -1; | ||
307 | if(aux && (aux->flags & ASN1_AFLG_BROKEN)) { | ||
308 | len = tmplen - (p - *in); | ||
309 | seq_nolen = 1; | ||
310 | } else seq_nolen = seq_eoc; /* If indefinite we don't do a length check */ | ||
311 | if(!cst) { | ||
312 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_NOT_CONSTRUCTED); | ||
313 | goto err; | ||
314 | } | ||
315 | |||
316 | if(!*pval) { | ||
317 | if(!ASN1_item_ex_new(pval, it)) { | ||
318 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); | ||
319 | goto err; | ||
320 | } | ||
321 | } | ||
322 | if(asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it)) | ||
323 | goto auxerr; | ||
324 | |||
325 | /* Get each field entry */ | ||
326 | for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) { | ||
327 | const ASN1_TEMPLATE *seqtt; | ||
328 | ASN1_VALUE **pseqval; | ||
329 | seqtt = asn1_do_adb(pval, tt, 1); | ||
330 | if(!seqtt) goto err; | ||
331 | pseqval = asn1_get_field_ptr(pval, seqtt); | ||
332 | /* Have we ran out of data? */ | ||
333 | if(!len) break; | ||
334 | q = p; | ||
335 | if(asn1_check_eoc(&p, len)) { | ||
336 | if(!seq_eoc) { | ||
337 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_UNEXPECTED_EOC); | ||
338 | goto err; | ||
339 | } | ||
340 | len -= p - q; | ||
341 | seq_eoc = 0; | ||
342 | q = p; | ||
343 | break; | ||
344 | } | ||
345 | /* This determines the OPTIONAL flag value. The field cannot | ||
346 | * be omitted if it is the last of a SEQUENCE and there is | ||
347 | * still data to be read. This isn't strictly necessary but | ||
348 | * it increases efficiency in some cases. | ||
349 | */ | ||
350 | if(i == (it->tcount - 1)) isopt = 0; | ||
351 | else isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL); | ||
352 | /* attempt to read in field, allowing each to be OPTIONAL */ | ||
353 | ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx); | ||
354 | if(!ret) { | ||
355 | errtt = seqtt; | ||
356 | goto err; | ||
357 | } else if(ret == -1) { | ||
358 | /* OPTIONAL component absent. Free and zero the field | ||
359 | */ | ||
360 | ASN1_template_free(pseqval, seqtt); | ||
361 | continue; | ||
362 | } | ||
363 | /* Update length */ | ||
364 | len -= p - q; | ||
365 | } | ||
366 | /* Check for EOC if expecting one */ | ||
367 | if(seq_eoc && !asn1_check_eoc(&p, len)) { | ||
368 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC); | ||
369 | goto err; | ||
370 | } | ||
371 | /* Check all data read */ | ||
372 | if(!seq_nolen && len) { | ||
373 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_LENGTH_MISMATCH); | ||
374 | goto err; | ||
375 | } | ||
376 | |||
377 | /* If we get here we've got no more data in the SEQUENCE, | ||
378 | * however we may not have read all fields so check all | ||
379 | * remaining are OPTIONAL and clear any that are. | ||
380 | */ | ||
381 | for(; i < it->tcount; tt++, i++) { | ||
382 | const ASN1_TEMPLATE *seqtt; | ||
383 | seqtt = asn1_do_adb(pval, tt, 1); | ||
384 | if(!seqtt) goto err; | ||
385 | if(seqtt->flags & ASN1_TFLG_OPTIONAL) { | ||
386 | ASN1_VALUE **pseqval; | ||
387 | pseqval = asn1_get_field_ptr(pval, seqtt); | ||
388 | ASN1_template_free(pseqval, seqtt); | ||
389 | } else { | ||
390 | errtt = seqtt; | ||
391 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_FIELD_MISSING); | ||
392 | goto err; | ||
393 | } | ||
394 | } | ||
395 | /* Save encoding */ | ||
396 | if(!asn1_enc_save(pval, *in, p - *in, it)) goto auxerr; | ||
397 | *in = p; | ||
398 | if(asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it)) | ||
399 | goto auxerr; | ||
400 | return 1; | ||
401 | |||
402 | default: | ||
403 | return 0; | ||
404 | } | ||
405 | auxerr: | ||
406 | ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR); | ||
407 | err: | ||
408 | ASN1_item_ex_free(pval, it); | ||
409 | if(errtt) ERR_add_error_data(4, "Field=", errtt->field_name, ", Type=", it->sname); | ||
410 | else ERR_add_error_data(2, "Type=", it->sname); | ||
411 | return 0; | ||
412 | } | ||
413 | |||
414 | /* Templates are handled with two separate functions. One handles any EXPLICIT tag and the other handles the | ||
415 | * rest. | ||
416 | */ | ||
417 | |||
418 | static int asn1_template_ex_d2i(ASN1_VALUE **val, unsigned char **in, long inlen, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx) | ||
419 | { | ||
420 | int flags, aclass; | ||
421 | int ret; | ||
422 | long len; | ||
423 | unsigned char *p, *q; | ||
424 | char exp_eoc; | ||
425 | if(!val) return 0; | ||
426 | flags = tt->flags; | ||
427 | aclass = flags & ASN1_TFLG_TAG_CLASS; | ||
428 | |||
429 | p = *in; | ||
430 | |||
431 | /* Check if EXPLICIT tag expected */ | ||
432 | if(flags & ASN1_TFLG_EXPTAG) { | ||
433 | char cst; | ||
434 | /* Need to work out amount of data available to the inner content and where it | ||
435 | * starts: so read in EXPLICIT header to get the info. | ||
436 | */ | ||
437 | ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst, &p, inlen, tt->tag, aclass, opt, ctx); | ||
438 | q = p; | ||
439 | if(!ret) { | ||
440 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR); | ||
441 | return 0; | ||
442 | } else if(ret == -1) return -1; | ||
443 | if(!cst) { | ||
444 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED); | ||
445 | return 0; | ||
446 | } | ||
447 | /* We've found the field so it can't be OPTIONAL now */ | ||
448 | ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx); | ||
449 | if(!ret) { | ||
450 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR); | ||
451 | return 0; | ||
452 | } | ||
453 | /* We read the field in OK so update length */ | ||
454 | len -= p - q; | ||
455 | if(exp_eoc) { | ||
456 | /* If NDEF we must have an EOC here */ | ||
457 | if(!asn1_check_eoc(&p, len)) { | ||
458 | ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_MISSING_EOC); | ||
459 | goto err; | ||
460 | } | ||
461 | } else { | ||
462 | /* Otherwise we must hit the EXPLICIT tag end or its an error */ | ||
463 | if(len) { | ||
464 | ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_EXPLICIT_LENGTH_MISMATCH); | ||
465 | goto err; | ||
466 | } | ||
467 | } | ||
468 | } else | ||
469 | return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx); | ||
470 | |||
471 | *in = p; | ||
472 | return 1; | ||
473 | |||
474 | err: | ||
475 | ASN1_template_free(val, tt); | ||
476 | *val = NULL; | ||
477 | return 0; | ||
478 | } | ||
479 | |||
480 | static int asn1_template_noexp_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx) | ||
481 | { | ||
482 | int flags, aclass; | ||
483 | int ret; | ||
484 | unsigned char *p, *q; | ||
485 | if(!val) return 0; | ||
486 | flags = tt->flags; | ||
487 | aclass = flags & ASN1_TFLG_TAG_CLASS; | ||
488 | |||
489 | p = *in; | ||
490 | q = p; | ||
491 | |||
492 | if(flags & ASN1_TFLG_SK_MASK) { | ||
493 | /* SET OF, SEQUENCE OF */ | ||
494 | int sktag, skaclass; | ||
495 | char sk_eoc; | ||
496 | /* First work out expected inner tag value */ | ||
497 | if(flags & ASN1_TFLG_IMPTAG) { | ||
498 | sktag = tt->tag; | ||
499 | skaclass = aclass; | ||
500 | } else { | ||
501 | skaclass = V_ASN1_UNIVERSAL; | ||
502 | if(flags & ASN1_TFLG_SET_OF) sktag = V_ASN1_SET; | ||
503 | else sktag = V_ASN1_SEQUENCE; | ||
504 | } | ||
505 | /* Get the tag */ | ||
506 | ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, &p, len, sktag, skaclass, opt, ctx); | ||
507 | if(!ret) { | ||
508 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR); | ||
509 | return 0; | ||
510 | } else if(ret == -1) return -1; | ||
511 | if(!*val) *val = (ASN1_VALUE *)sk_new_null(); | ||
512 | else { | ||
513 | /* We've got a valid STACK: free up any items present */ | ||
514 | STACK *sktmp = (STACK *)*val; | ||
515 | ASN1_VALUE *vtmp; | ||
516 | while(sk_num(sktmp) > 0) { | ||
517 | vtmp = (ASN1_VALUE *)sk_pop(sktmp); | ||
518 | ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item)); | ||
519 | } | ||
520 | } | ||
521 | |||
522 | if(!*val) { | ||
523 | ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_MALLOC_FAILURE); | ||
524 | goto err; | ||
525 | } | ||
526 | /* Read as many items as we can */ | ||
527 | while(len > 0) { | ||
528 | ASN1_VALUE *skfield; | ||
529 | q = p; | ||
530 | /* See if EOC found */ | ||
531 | if(asn1_check_eoc(&p, len)) { | ||
532 | if(!sk_eoc) { | ||
533 | ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_UNEXPECTED_EOC); | ||
534 | goto err; | ||
535 | } | ||
536 | len -= p - q; | ||
537 | sk_eoc = 0; | ||
538 | break; | ||
539 | } | ||
540 | skfield = NULL; | ||
541 | if(!ASN1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx)) { | ||
542 | ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR); | ||
543 | goto err; | ||
544 | } | ||
545 | len -= p - q; | ||
546 | if(!sk_push((STACK *)*val, (char *)skfield)) { | ||
547 | ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_MALLOC_FAILURE); | ||
548 | goto err; | ||
549 | } | ||
550 | } | ||
551 | if(sk_eoc) { | ||
552 | ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_MISSING_EOC); | ||
553 | goto err; | ||
554 | } | ||
555 | } else if(flags & ASN1_TFLG_IMPTAG) { | ||
556 | /* IMPLICIT tagging */ | ||
557 | ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx); | ||
558 | if(!ret) { | ||
559 | ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR); | ||
560 | goto err; | ||
561 | } else if(ret == -1) return -1; | ||
562 | } else { | ||
563 | /* Nothing special */ | ||
564 | ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, opt, ctx); | ||
565 | if(!ret) { | ||
566 | ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR); | ||
567 | goto err; | ||
568 | } else if(ret == -1) return -1; | ||
569 | } | ||
570 | |||
571 | *in = p; | ||
572 | return 1; | ||
573 | |||
574 | err: | ||
575 | ASN1_template_free(val, tt); | ||
576 | *val = NULL; | ||
577 | return 0; | ||
578 | } | ||
579 | |||
580 | static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, unsigned char **in, long inlen, | ||
581 | const ASN1_ITEM *it, | ||
582 | int tag, int aclass, char opt, ASN1_TLC *ctx) | ||
583 | { | ||
584 | int ret = 0, utype; | ||
585 | long plen; | ||
586 | char cst, inf, free_cont = 0; | ||
587 | unsigned char *p; | ||
588 | BUF_MEM buf; | ||
589 | unsigned char *cont = NULL; | ||
590 | long len; | ||
591 | if(!pval) { | ||
592 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL); | ||
593 | return 0; /* Should never happen */ | ||
594 | } | ||
595 | |||
596 | if(it->itype == ASN1_ITYPE_MSTRING) { | ||
597 | utype = tag; | ||
598 | tag = -1; | ||
599 | } else utype = it->utype; | ||
600 | |||
601 | if(utype == V_ASN1_ANY) { | ||
602 | /* If type is ANY need to figure out type from tag */ | ||
603 | unsigned char oclass; | ||
604 | if(tag >= 0) { | ||
605 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_TAGGED_ANY); | ||
606 | return 0; | ||
607 | } | ||
608 | if(opt) { | ||
609 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_OPTIONAL_ANY); | ||
610 | return 0; | ||
611 | } | ||
612 | p = *in; | ||
613 | ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, &p, inlen, -1, 0, 0, ctx); | ||
614 | if(!ret) { | ||
615 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); | ||
616 | return 0; | ||
617 | } | ||
618 | if(oclass != V_ASN1_UNIVERSAL) utype = V_ASN1_OTHER; | ||
619 | } | ||
620 | if(tag == -1) { | ||
621 | tag = utype; | ||
622 | aclass = V_ASN1_UNIVERSAL; | ||
623 | } | ||
624 | p = *in; | ||
625 | /* Check header */ | ||
626 | ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, &p, inlen, tag, aclass, opt, ctx); | ||
627 | if(!ret) { | ||
628 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); | ||
629 | return 0; | ||
630 | } else if(ret == -1) return -1; | ||
631 | /* SEQUENCE, SET and "OTHER" are left in encoded form */ | ||
632 | if((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) { | ||
633 | /* Clear context cache for type OTHER because the auto clear when | ||
634 | * we have a exact match wont work | ||
635 | */ | ||
636 | if(utype == V_ASN1_OTHER) { | ||
637 | asn1_tlc_clear(ctx); | ||
638 | /* SEQUENCE and SET must be constructed */ | ||
639 | } else if(!cst) { | ||
640 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_TYPE_NOT_CONSTRUCTED); | ||
641 | return 0; | ||
642 | } | ||
643 | |||
644 | cont = *in; | ||
645 | /* If indefinite length constructed find the real end */ | ||
646 | if(inf) { | ||
647 | if(!asn1_collect(NULL, &p, plen, inf, -1, -1)) goto err; | ||
648 | len = p - cont; | ||
649 | } else { | ||
650 | len = p - cont + plen; | ||
651 | p += plen; | ||
652 | buf.data = NULL; | ||
653 | } | ||
654 | } else if(cst) { | ||
655 | buf.length = 0; | ||
656 | buf.max = 0; | ||
657 | buf.data = NULL; | ||
658 | /* Should really check the internal tags are correct but | ||
659 | * some things may get this wrong. The relevant specs | ||
660 | * say that constructed string types should be OCTET STRINGs | ||
661 | * internally irrespective of the type. So instead just check | ||
662 | * for UNIVERSAL class and ignore the tag. | ||
663 | */ | ||
664 | if(!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL)) goto err; | ||
665 | len = buf.length; | ||
666 | /* Append a final null to string */ | ||
667 | if(!BUF_MEM_grow_clean(&buf, len + 1)) { | ||
668 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE); | ||
669 | return 0; | ||
670 | } | ||
671 | buf.data[len] = 0; | ||
672 | cont = (unsigned char *)buf.data; | ||
673 | free_cont = 1; | ||
674 | } else { | ||
675 | cont = p; | ||
676 | len = plen; | ||
677 | p += plen; | ||
678 | } | ||
679 | |||
680 | /* We now have content length and type: translate into a structure */ | ||
681 | if(!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it)) goto err; | ||
682 | |||
683 | *in = p; | ||
684 | ret = 1; | ||
685 | err: | ||
686 | if(free_cont && buf.data) OPENSSL_free(buf.data); | ||
687 | return ret; | ||
688 | } | ||
689 | |||
690 | /* Translate ASN1 content octets into a structure */ | ||
691 | |||
692 | int asn1_ex_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it) | ||
693 | { | ||
694 | ASN1_VALUE **opval = NULL; | ||
695 | ASN1_STRING *stmp; | ||
696 | ASN1_TYPE *typ = NULL; | ||
697 | int ret = 0; | ||
698 | const ASN1_PRIMITIVE_FUNCS *pf; | ||
699 | ASN1_INTEGER **tint; | ||
700 | pf = it->funcs; | ||
701 | if(pf && pf->prim_c2i) return pf->prim_c2i(pval, cont, len, utype, free_cont, it); | ||
702 | /* If ANY type clear type and set pointer to internal value */ | ||
703 | if(it->utype == V_ASN1_ANY) { | ||
704 | if(!*pval) { | ||
705 | typ = ASN1_TYPE_new(); | ||
706 | *pval = (ASN1_VALUE *)typ; | ||
707 | } else typ = (ASN1_TYPE *)*pval; | ||
708 | if(utype != typ->type) ASN1_TYPE_set(typ, utype, NULL); | ||
709 | opval = pval; | ||
710 | pval = (ASN1_VALUE **)&typ->value.ptr; | ||
711 | } | ||
712 | switch(utype) { | ||
713 | case V_ASN1_OBJECT: | ||
714 | if(!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) goto err; | ||
715 | break; | ||
716 | |||
717 | case V_ASN1_NULL: | ||
718 | if(len) { | ||
719 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_NULL_IS_WRONG_LENGTH); | ||
720 | goto err; | ||
721 | } | ||
722 | *pval = (ASN1_VALUE *)1; | ||
723 | break; | ||
724 | |||
725 | case V_ASN1_BOOLEAN: | ||
726 | if(len != 1) { | ||
727 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_BOOLEAN_IS_WRONG_LENGTH); | ||
728 | goto err; | ||
729 | } else { | ||
730 | ASN1_BOOLEAN *tbool; | ||
731 | tbool = (ASN1_BOOLEAN *)pval; | ||
732 | *tbool = *cont; | ||
733 | } | ||
734 | break; | ||
735 | |||
736 | case V_ASN1_BIT_STRING: | ||
737 | if(!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len)) goto err; | ||
738 | break; | ||
739 | |||
740 | case V_ASN1_INTEGER: | ||
741 | case V_ASN1_NEG_INTEGER: | ||
742 | case V_ASN1_ENUMERATED: | ||
743 | case V_ASN1_NEG_ENUMERATED: | ||
744 | tint = (ASN1_INTEGER **)pval; | ||
745 | if(!c2i_ASN1_INTEGER(tint, &cont, len)) goto err; | ||
746 | /* Fixup type to match the expected form */ | ||
747 | (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG); | ||
748 | break; | ||
749 | |||
750 | case V_ASN1_OCTET_STRING: | ||
751 | case V_ASN1_NUMERICSTRING: | ||
752 | case V_ASN1_PRINTABLESTRING: | ||
753 | case V_ASN1_T61STRING: | ||
754 | case V_ASN1_VIDEOTEXSTRING: | ||
755 | case V_ASN1_IA5STRING: | ||
756 | case V_ASN1_UTCTIME: | ||
757 | case V_ASN1_GENERALIZEDTIME: | ||
758 | case V_ASN1_GRAPHICSTRING: | ||
759 | case V_ASN1_VISIBLESTRING: | ||
760 | case V_ASN1_GENERALSTRING: | ||
761 | case V_ASN1_UNIVERSALSTRING: | ||
762 | case V_ASN1_BMPSTRING: | ||
763 | case V_ASN1_UTF8STRING: | ||
764 | case V_ASN1_OTHER: | ||
765 | case V_ASN1_SET: | ||
766 | case V_ASN1_SEQUENCE: | ||
767 | default: | ||
768 | /* All based on ASN1_STRING and handled the same */ | ||
769 | if(!*pval) { | ||
770 | stmp = ASN1_STRING_type_new(utype); | ||
771 | if(!stmp) { | ||
772 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE); | ||
773 | goto err; | ||
774 | } | ||
775 | *pval = (ASN1_VALUE *)stmp; | ||
776 | } else { | ||
777 | stmp = (ASN1_STRING *)*pval; | ||
778 | stmp->type = utype; | ||
779 | } | ||
780 | /* If we've already allocated a buffer use it */ | ||
781 | if(*free_cont) { | ||
782 | if(stmp->data) OPENSSL_free(stmp->data); | ||
783 | stmp->data = cont; | ||
784 | stmp->length = len; | ||
785 | *free_cont = 0; | ||
786 | } else { | ||
787 | if(!ASN1_STRING_set(stmp, cont, len)) { | ||
788 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE); | ||
789 | ASN1_STRING_free(stmp); | ||
790 | *pval = NULL; | ||
791 | goto err; | ||
792 | } | ||
793 | } | ||
794 | break; | ||
795 | } | ||
796 | /* If ASN1_ANY and NULL type fix up value */ | ||
797 | if(typ && utype==V_ASN1_NULL) typ->value.ptr = NULL; | ||
798 | |||
799 | ret = 1; | ||
800 | err: | ||
801 | if(!ret) | ||
802 | { | ||
803 | ASN1_TYPE_free(typ); | ||
804 | if (opval) | ||
805 | *opval = NULL; | ||
806 | } | ||
807 | return ret; | ||
808 | } | ||
809 | |||
810 | /* This function collects the asn1 data from a constructred string | ||
811 | * type into a buffer. The values of 'in' and 'len' should refer | ||
812 | * to the contents of the constructed type and 'inf' should be set | ||
813 | * if it is indefinite length. If 'buf' is NULL then we just want | ||
814 | * to find the end of the current structure: useful for indefinite | ||
815 | * length constructed stuff. | ||
816 | */ | ||
817 | |||
818 | static int asn1_collect(BUF_MEM *buf, unsigned char **in, long len, char inf, int tag, int aclass) | ||
819 | { | ||
820 | unsigned char *p, *q; | ||
821 | long plen; | ||
822 | char cst, ininf; | ||
823 | p = *in; | ||
824 | inf &= 1; | ||
825 | /* If no buffer and not indefinite length constructed just pass over the encoded data */ | ||
826 | if(!buf && !inf) { | ||
827 | *in += len; | ||
828 | return 1; | ||
829 | } | ||
830 | while(len > 0) { | ||
831 | q = p; | ||
832 | /* Check for EOC */ | ||
833 | if(asn1_check_eoc(&p, len)) { | ||
834 | /* EOC is illegal outside indefinite length constructed form */ | ||
835 | if(!inf) { | ||
836 | ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_UNEXPECTED_EOC); | ||
837 | return 0; | ||
838 | } | ||
839 | inf = 0; | ||
840 | break; | ||
841 | } | ||
842 | if(!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, len, tag, aclass, 0, NULL)) { | ||
843 | ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR); | ||
844 | return 0; | ||
845 | } | ||
846 | /* If indefinite length constructed update max length */ | ||
847 | if(cst) { | ||
848 | if(!asn1_collect(buf, &p, plen, ininf, tag, aclass)) return 0; | ||
849 | } else { | ||
850 | if(!collect_data(buf, &p, plen)) return 0; | ||
851 | } | ||
852 | len -= p - q; | ||
853 | } | ||
854 | if(inf) { | ||
855 | ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC); | ||
856 | return 0; | ||
857 | } | ||
858 | *in = p; | ||
859 | return 1; | ||
860 | } | ||
861 | |||
862 | static int collect_data(BUF_MEM *buf, unsigned char **p, long plen) | ||
863 | { | ||
864 | int len; | ||
865 | if(buf) { | ||
866 | len = buf->length; | ||
867 | if(!BUF_MEM_grow_clean(buf, len + plen)) { | ||
868 | ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE); | ||
869 | return 0; | ||
870 | } | ||
871 | memcpy(buf->data + len, *p, plen); | ||
872 | } | ||
873 | *p += plen; | ||
874 | return 1; | ||
875 | } | ||
876 | |||
877 | /* Check for ASN1 EOC and swallow it if found */ | ||
878 | |||
879 | static int asn1_check_eoc(unsigned char **in, long len) | ||
880 | { | ||
881 | unsigned char *p; | ||
882 | if(len < 2) return 0; | ||
883 | p = *in; | ||
884 | if(!p[0] && !p[1]) { | ||
885 | *in += 2; | ||
886 | return 1; | ||
887 | } | ||
888 | return 0; | ||
889 | } | ||
890 | |||
891 | /* Check an ASN1 tag and length: a bit like ASN1_get_object | ||
892 | * but it sets the length for indefinite length constructed | ||
893 | * form, we don't know the exact length but we can set an | ||
894 | * upper bound to the amount of data available minus the | ||
895 | * header length just read. | ||
896 | */ | ||
897 | |||
898 | static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf, char *cst, | ||
899 | unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx) | ||
900 | { | ||
901 | int i; | ||
902 | int ptag, pclass; | ||
903 | long plen; | ||
904 | unsigned char *p, *q; | ||
905 | p = *in; | ||
906 | q = p; | ||
907 | |||
908 | if(ctx && ctx->valid) { | ||
909 | i = ctx->ret; | ||
910 | plen = ctx->plen; | ||
911 | pclass = ctx->pclass; | ||
912 | ptag = ctx->ptag; | ||
913 | p += ctx->hdrlen; | ||
914 | } else { | ||
915 | i = ASN1_get_object(&p, &plen, &ptag, &pclass, len); | ||
916 | if(ctx) { | ||
917 | ctx->ret = i; | ||
918 | ctx->plen = plen; | ||
919 | ctx->pclass = pclass; | ||
920 | ctx->ptag = ptag; | ||
921 | ctx->hdrlen = p - q; | ||
922 | ctx->valid = 1; | ||
923 | /* If definite length, and no error, length + | ||
924 | * header can't exceed total amount of data available. | ||
925 | */ | ||
926 | if(!(i & 0x81) && ((plen + ctx->hdrlen) > len)) { | ||
927 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG); | ||
928 | asn1_tlc_clear(ctx); | ||
929 | return 0; | ||
930 | } | ||
931 | } | ||
932 | } | ||
933 | |||
934 | if(i & 0x80) { | ||
935 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER); | ||
936 | asn1_tlc_clear(ctx); | ||
937 | return 0; | ||
938 | } | ||
939 | if(exptag >= 0) { | ||
940 | if((exptag != ptag) || (expclass != pclass)) { | ||
941 | /* If type is OPTIONAL, not an error, but indicate missing | ||
942 | * type. | ||
943 | */ | ||
944 | if(opt) return -1; | ||
945 | asn1_tlc_clear(ctx); | ||
946 | ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG); | ||
947 | return 0; | ||
948 | } | ||
949 | /* We have a tag and class match, so assume we are going to do something with it */ | ||
950 | asn1_tlc_clear(ctx); | ||
951 | } | ||
952 | |||
953 | if(i & 1) plen = len - (p - q); | ||
954 | |||
955 | if(inf) *inf = i & 1; | ||
956 | |||
957 | if(cst) *cst = i & V_ASN1_CONSTRUCTED; | ||
958 | |||
959 | if(olen) *olen = plen; | ||
960 | if(oclass) *oclass = pclass; | ||
961 | if(otag) *otag = ptag; | ||
962 | |||
963 | *in = p; | ||
964 | return 1; | ||
965 | } | ||
diff --git a/src/lib/libcrypto/asn1/tasn_enc.c b/src/lib/libcrypto/asn1/tasn_enc.c deleted file mode 100644 index f6c8ddef0a..0000000000 --- a/src/lib/libcrypto/asn1/tasn_enc.c +++ /dev/null | |||
@@ -1,497 +0,0 @@ | |||
1 | /* tasn_enc.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | |||
60 | #include <stddef.h> | ||
61 | #include <string.h> | ||
62 | #include <openssl/asn1.h> | ||
63 | #include <openssl/asn1t.h> | ||
64 | #include <openssl/objects.h> | ||
65 | |||
66 | static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); | ||
67 | static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *seq, unsigned char **out, int skcontlen, const ASN1_ITEM *item, int isset); | ||
68 | |||
69 | /* Encode an ASN1 item, this is compatible with the | ||
70 | * standard 'i2d' function. 'out' points to | ||
71 | * a buffer to output the data to, in future we will | ||
72 | * have more advanced versions that can output data | ||
73 | * a piece at a time and this will simply be a special | ||
74 | * case. | ||
75 | * | ||
76 | * The new i2d has one additional feature. If the output | ||
77 | * buffer is NULL (i.e. *out == NULL) then a buffer is | ||
78 | * allocated and populated with the encoding. | ||
79 | */ | ||
80 | |||
81 | |||
82 | int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) | ||
83 | { | ||
84 | if(out && !*out) { | ||
85 | unsigned char *p, *buf; | ||
86 | int len; | ||
87 | len = ASN1_item_ex_i2d(&val, NULL, it, -1, 0); | ||
88 | if(len <= 0) return len; | ||
89 | buf = OPENSSL_malloc(len); | ||
90 | if(!buf) return -1; | ||
91 | p = buf; | ||
92 | ASN1_item_ex_i2d(&val, &p, it, -1, 0); | ||
93 | *out = buf; | ||
94 | return len; | ||
95 | } | ||
96 | |||
97 | return ASN1_item_ex_i2d(&val, out, it, -1, 0); | ||
98 | } | ||
99 | |||
100 | /* Encode an item, taking care of IMPLICIT tagging (if any). | ||
101 | * This function performs the normal item handling: it can be | ||
102 | * used in external types. | ||
103 | */ | ||
104 | |||
105 | int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass) | ||
106 | { | ||
107 | const ASN1_TEMPLATE *tt = NULL; | ||
108 | unsigned char *p = NULL; | ||
109 | int i, seqcontlen, seqlen; | ||
110 | ASN1_STRING *strtmp; | ||
111 | const ASN1_COMPAT_FUNCS *cf; | ||
112 | const ASN1_EXTERN_FUNCS *ef; | ||
113 | const ASN1_AUX *aux = it->funcs; | ||
114 | ASN1_aux_cb *asn1_cb; | ||
115 | if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return 0; | ||
116 | if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb; | ||
117 | else asn1_cb = 0; | ||
118 | |||
119 | switch(it->itype) { | ||
120 | |||
121 | case ASN1_ITYPE_PRIMITIVE: | ||
122 | if(it->templates) | ||
123 | return ASN1_template_i2d(pval, out, it->templates); | ||
124 | return asn1_i2d_ex_primitive(pval, out, it, tag, aclass); | ||
125 | break; | ||
126 | |||
127 | case ASN1_ITYPE_MSTRING: | ||
128 | strtmp = (ASN1_STRING *)*pval; | ||
129 | return asn1_i2d_ex_primitive(pval, out, it, -1, 0); | ||
130 | |||
131 | case ASN1_ITYPE_CHOICE: | ||
132 | if(asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it)) | ||
133 | return 0; | ||
134 | i = asn1_get_choice_selector(pval, it); | ||
135 | if((i >= 0) && (i < it->tcount)) { | ||
136 | ASN1_VALUE **pchval; | ||
137 | const ASN1_TEMPLATE *chtt; | ||
138 | chtt = it->templates + i; | ||
139 | pchval = asn1_get_field_ptr(pval, chtt); | ||
140 | return ASN1_template_i2d(pchval, out, chtt); | ||
141 | } | ||
142 | /* Fixme: error condition if selector out of range */ | ||
143 | if(asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it)) | ||
144 | return 0; | ||
145 | break; | ||
146 | |||
147 | case ASN1_ITYPE_EXTERN: | ||
148 | /* If new style i2d it does all the work */ | ||
149 | ef = it->funcs; | ||
150 | return ef->asn1_ex_i2d(pval, out, it, tag, aclass); | ||
151 | |||
152 | case ASN1_ITYPE_COMPAT: | ||
153 | /* old style hackery... */ | ||
154 | cf = it->funcs; | ||
155 | if(out) p = *out; | ||
156 | i = cf->asn1_i2d(*pval, out); | ||
157 | /* Fixup for IMPLICIT tag: note this messes up for tags > 30, | ||
158 | * but so did the old code. Tags > 30 are very rare anyway. | ||
159 | */ | ||
160 | if(out && (tag != -1)) | ||
161 | *p = aclass | tag | (*p & V_ASN1_CONSTRUCTED); | ||
162 | return i; | ||
163 | |||
164 | case ASN1_ITYPE_SEQUENCE: | ||
165 | i = asn1_enc_restore(&seqcontlen, out, pval, it); | ||
166 | /* An error occurred */ | ||
167 | if(i < 0) return 0; | ||
168 | /* We have a valid cached encoding... */ | ||
169 | if(i > 0) return seqcontlen; | ||
170 | /* Otherwise carry on */ | ||
171 | seqcontlen = 0; | ||
172 | /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ | ||
173 | if(tag == -1) { | ||
174 | tag = V_ASN1_SEQUENCE; | ||
175 | aclass = V_ASN1_UNIVERSAL; | ||
176 | } | ||
177 | if(asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it)) | ||
178 | return 0; | ||
179 | /* First work out sequence content length */ | ||
180 | for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) { | ||
181 | const ASN1_TEMPLATE *seqtt; | ||
182 | ASN1_VALUE **pseqval; | ||
183 | seqtt = asn1_do_adb(pval, tt, 1); | ||
184 | if(!seqtt) return 0; | ||
185 | pseqval = asn1_get_field_ptr(pval, seqtt); | ||
186 | /* FIXME: check for errors in enhanced version */ | ||
187 | /* FIXME: special handling of indefinite length encoding */ | ||
188 | seqcontlen += ASN1_template_i2d(pseqval, NULL, seqtt); | ||
189 | } | ||
190 | seqlen = ASN1_object_size(1, seqcontlen, tag); | ||
191 | if(!out) return seqlen; | ||
192 | /* Output SEQUENCE header */ | ||
193 | ASN1_put_object(out, 1, seqcontlen, tag, aclass); | ||
194 | for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) { | ||
195 | const ASN1_TEMPLATE *seqtt; | ||
196 | ASN1_VALUE **pseqval; | ||
197 | seqtt = asn1_do_adb(pval, tt, 1); | ||
198 | if(!seqtt) return 0; | ||
199 | pseqval = asn1_get_field_ptr(pval, seqtt); | ||
200 | /* FIXME: check for errors in enhanced version */ | ||
201 | ASN1_template_i2d(pseqval, out, seqtt); | ||
202 | } | ||
203 | if(asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it)) | ||
204 | return 0; | ||
205 | return seqlen; | ||
206 | |||
207 | default: | ||
208 | return 0; | ||
209 | } | ||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt) | ||
214 | { | ||
215 | int i, ret, flags, aclass; | ||
216 | flags = tt->flags; | ||
217 | aclass = flags & ASN1_TFLG_TAG_CLASS; | ||
218 | if(flags & ASN1_TFLG_SK_MASK) { | ||
219 | /* SET OF, SEQUENCE OF */ | ||
220 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; | ||
221 | int isset, sktag, skaclass; | ||
222 | int skcontlen, sklen; | ||
223 | ASN1_VALUE *skitem; | ||
224 | if(!*pval) return 0; | ||
225 | if(flags & ASN1_TFLG_SET_OF) { | ||
226 | isset = 1; | ||
227 | /* 2 means we reorder */ | ||
228 | if(flags & ASN1_TFLG_SEQUENCE_OF) isset = 2; | ||
229 | } else isset = 0; | ||
230 | /* First work out inner tag value */ | ||
231 | if(flags & ASN1_TFLG_IMPTAG) { | ||
232 | sktag = tt->tag; | ||
233 | skaclass = aclass; | ||
234 | } else { | ||
235 | skaclass = V_ASN1_UNIVERSAL; | ||
236 | if(isset) sktag = V_ASN1_SET; | ||
237 | else sktag = V_ASN1_SEQUENCE; | ||
238 | } | ||
239 | /* Now work out length of items */ | ||
240 | skcontlen = 0; | ||
241 | for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) { | ||
242 | skitem = sk_ASN1_VALUE_value(sk, i); | ||
243 | skcontlen += ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item), -1, 0); | ||
244 | } | ||
245 | sklen = ASN1_object_size(1, skcontlen, sktag); | ||
246 | /* If EXPLICIT need length of surrounding tag */ | ||
247 | if(flags & ASN1_TFLG_EXPTAG) | ||
248 | ret = ASN1_object_size(1, sklen, tt->tag); | ||
249 | else ret = sklen; | ||
250 | |||
251 | if(!out) return ret; | ||
252 | |||
253 | /* Now encode this lot... */ | ||
254 | /* EXPLICIT tag */ | ||
255 | if(flags & ASN1_TFLG_EXPTAG) | ||
256 | ASN1_put_object(out, 1, sklen, tt->tag, aclass); | ||
257 | /* SET or SEQUENCE and IMPLICIT tag */ | ||
258 | ASN1_put_object(out, 1, skcontlen, sktag, skaclass); | ||
259 | /* And finally the stuff itself */ | ||
260 | asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), isset); | ||
261 | |||
262 | return ret; | ||
263 | } | ||
264 | |||
265 | if(flags & ASN1_TFLG_EXPTAG) { | ||
266 | /* EXPLICIT tagging */ | ||
267 | /* Find length of tagged item */ | ||
268 | i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, 0); | ||
269 | if(!i) return 0; | ||
270 | /* Find length of EXPLICIT tag */ | ||
271 | ret = ASN1_object_size(1, i, tt->tag); | ||
272 | if(out) { | ||
273 | /* Output tag and item */ | ||
274 | ASN1_put_object(out, 1, i, tt->tag, aclass); | ||
275 | ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0); | ||
276 | } | ||
277 | return ret; | ||
278 | } | ||
279 | if(flags & ASN1_TFLG_IMPTAG) { | ||
280 | /* IMPLICIT tagging */ | ||
281 | return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), tt->tag, aclass); | ||
282 | } | ||
283 | /* Nothing special: treat as normal */ | ||
284 | return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0); | ||
285 | } | ||
286 | |||
287 | /* Temporary structure used to hold DER encoding of items for SET OF */ | ||
288 | |||
289 | typedef struct { | ||
290 | unsigned char *data; | ||
291 | int length; | ||
292 | ASN1_VALUE *field; | ||
293 | } DER_ENC; | ||
294 | |||
295 | static int der_cmp(const void *a, const void *b) | ||
296 | { | ||
297 | const DER_ENC *d1 = a, *d2 = b; | ||
298 | int cmplen, i; | ||
299 | cmplen = (d1->length < d2->length) ? d1->length : d2->length; | ||
300 | i = memcmp(d1->data, d2->data, cmplen); | ||
301 | if(i) return i; | ||
302 | return d1->length - d2->length; | ||
303 | } | ||
304 | |||
305 | /* Output the content octets of SET OF or SEQUENCE OF */ | ||
306 | |||
307 | static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, int skcontlen, const ASN1_ITEM *item, int do_sort) | ||
308 | { | ||
309 | int i; | ||
310 | ASN1_VALUE *skitem; | ||
311 | unsigned char *tmpdat = NULL, *p = NULL; | ||
312 | DER_ENC *derlst = NULL, *tder; | ||
313 | if(do_sort) { | ||
314 | /* Don't need to sort less than 2 items */ | ||
315 | if(sk_ASN1_VALUE_num(sk) < 2) do_sort = 0; | ||
316 | else { | ||
317 | derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) * sizeof(*derlst)); | ||
318 | tmpdat = OPENSSL_malloc(skcontlen); | ||
319 | if(!derlst || !tmpdat) return 0; | ||
320 | } | ||
321 | } | ||
322 | /* If not sorting just output each item */ | ||
323 | if(!do_sort) { | ||
324 | for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) { | ||
325 | skitem = sk_ASN1_VALUE_value(sk, i); | ||
326 | ASN1_item_i2d(skitem, out, item); | ||
327 | } | ||
328 | return 1; | ||
329 | } | ||
330 | p = tmpdat; | ||
331 | /* Doing sort: build up a list of each member's DER encoding */ | ||
332 | for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) { | ||
333 | skitem = sk_ASN1_VALUE_value(sk, i); | ||
334 | tder->data = p; | ||
335 | tder->length = ASN1_item_i2d(skitem, &p, item); | ||
336 | tder->field = skitem; | ||
337 | } | ||
338 | /* Now sort them */ | ||
339 | qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp); | ||
340 | /* Output sorted DER encoding */ | ||
341 | p = *out; | ||
342 | for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) { | ||
343 | memcpy(p, tder->data, tder->length); | ||
344 | p += tder->length; | ||
345 | } | ||
346 | *out = p; | ||
347 | /* If do_sort is 2 then reorder the STACK */ | ||
348 | if(do_sort == 2) { | ||
349 | for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) | ||
350 | sk_ASN1_VALUE_set(sk, i, tder->field); | ||
351 | } | ||
352 | OPENSSL_free(derlst); | ||
353 | OPENSSL_free(tmpdat); | ||
354 | return 1; | ||
355 | } | ||
356 | |||
357 | static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass) | ||
358 | { | ||
359 | int len; | ||
360 | int utype; | ||
361 | int usetag; | ||
362 | |||
363 | utype = it->utype; | ||
364 | |||
365 | /* Get length of content octets and maybe find | ||
366 | * out the underlying type. | ||
367 | */ | ||
368 | |||
369 | len = asn1_ex_i2c(pval, NULL, &utype, it); | ||
370 | |||
371 | /* If SEQUENCE, SET or OTHER then header is | ||
372 | * included in pseudo content octets so don't | ||
373 | * include tag+length. We need to check here | ||
374 | * because the call to asn1_ex_i2c() could change | ||
375 | * utype. | ||
376 | */ | ||
377 | if((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) || | ||
378 | (utype == V_ASN1_OTHER)) | ||
379 | usetag = 0; | ||
380 | else usetag = 1; | ||
381 | |||
382 | /* -1 means omit type */ | ||
383 | |||
384 | if(len == -1) return 0; | ||
385 | |||
386 | /* If not implicitly tagged get tag from underlying type */ | ||
387 | if(tag == -1) tag = utype; | ||
388 | |||
389 | /* Output tag+length followed by content octets */ | ||
390 | if(out) { | ||
391 | if(usetag) ASN1_put_object(out, 0, len, tag, aclass); | ||
392 | asn1_ex_i2c(pval, *out, &utype, it); | ||
393 | *out += len; | ||
394 | } | ||
395 | |||
396 | if(usetag) return ASN1_object_size(0, len, tag); | ||
397 | return len; | ||
398 | } | ||
399 | |||
400 | /* Produce content octets from a structure */ | ||
401 | |||
402 | int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, const ASN1_ITEM *it) | ||
403 | { | ||
404 | ASN1_BOOLEAN *tbool = NULL; | ||
405 | ASN1_STRING *strtmp; | ||
406 | ASN1_OBJECT *otmp; | ||
407 | int utype; | ||
408 | unsigned char *cont, c; | ||
409 | int len; | ||
410 | const ASN1_PRIMITIVE_FUNCS *pf; | ||
411 | pf = it->funcs; | ||
412 | if(pf && pf->prim_i2c) return pf->prim_i2c(pval, cout, putype, it); | ||
413 | |||
414 | /* Should type be omitted? */ | ||
415 | if((it->itype != ASN1_ITYPE_PRIMITIVE) || (it->utype != V_ASN1_BOOLEAN)) { | ||
416 | if(!*pval) return -1; | ||
417 | } | ||
418 | |||
419 | if(it->itype == ASN1_ITYPE_MSTRING) { | ||
420 | /* If MSTRING type set the underlying type */ | ||
421 | strtmp = (ASN1_STRING *)*pval; | ||
422 | utype = strtmp->type; | ||
423 | *putype = utype; | ||
424 | } else if(it->utype == V_ASN1_ANY) { | ||
425 | /* If ANY set type and pointer to value */ | ||
426 | ASN1_TYPE *typ; | ||
427 | typ = (ASN1_TYPE *)*pval; | ||
428 | utype = typ->type; | ||
429 | *putype = utype; | ||
430 | pval = (ASN1_VALUE **)&typ->value.ptr; | ||
431 | } else utype = *putype; | ||
432 | |||
433 | switch(utype) { | ||
434 | case V_ASN1_OBJECT: | ||
435 | otmp = (ASN1_OBJECT *)*pval; | ||
436 | cont = otmp->data; | ||
437 | len = otmp->length; | ||
438 | break; | ||
439 | |||
440 | case V_ASN1_NULL: | ||
441 | cont = NULL; | ||
442 | len = 0; | ||
443 | break; | ||
444 | |||
445 | case V_ASN1_BOOLEAN: | ||
446 | tbool = (ASN1_BOOLEAN *)pval; | ||
447 | if(*tbool == -1) return -1; | ||
448 | /* Default handling if value == size field then omit */ | ||
449 | if(*tbool && (it->size > 0)) return -1; | ||
450 | if(!*tbool && !it->size) return -1; | ||
451 | c = (unsigned char)*tbool; | ||
452 | cont = &c; | ||
453 | len = 1; | ||
454 | break; | ||
455 | |||
456 | case V_ASN1_BIT_STRING: | ||
457 | return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, cout ? &cout : NULL); | ||
458 | break; | ||
459 | |||
460 | case V_ASN1_INTEGER: | ||
461 | case V_ASN1_NEG_INTEGER: | ||
462 | case V_ASN1_ENUMERATED: | ||
463 | case V_ASN1_NEG_ENUMERATED: | ||
464 | /* These are all have the same content format | ||
465 | * as ASN1_INTEGER | ||
466 | */ | ||
467 | return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : NULL); | ||
468 | break; | ||
469 | |||
470 | case V_ASN1_OCTET_STRING: | ||
471 | case V_ASN1_NUMERICSTRING: | ||
472 | case V_ASN1_PRINTABLESTRING: | ||
473 | case V_ASN1_T61STRING: | ||
474 | case V_ASN1_VIDEOTEXSTRING: | ||
475 | case V_ASN1_IA5STRING: | ||
476 | case V_ASN1_UTCTIME: | ||
477 | case V_ASN1_GENERALIZEDTIME: | ||
478 | case V_ASN1_GRAPHICSTRING: | ||
479 | case V_ASN1_VISIBLESTRING: | ||
480 | case V_ASN1_GENERALSTRING: | ||
481 | case V_ASN1_UNIVERSALSTRING: | ||
482 | case V_ASN1_BMPSTRING: | ||
483 | case V_ASN1_UTF8STRING: | ||
484 | case V_ASN1_SEQUENCE: | ||
485 | case V_ASN1_SET: | ||
486 | default: | ||
487 | /* All based on ASN1_STRING and handled the same */ | ||
488 | strtmp = (ASN1_STRING *)*pval; | ||
489 | cont = strtmp->data; | ||
490 | len = strtmp->length; | ||
491 | |||
492 | break; | ||
493 | |||
494 | } | ||
495 | if(cout && len) memcpy(cout, cont, len); | ||
496 | return len; | ||
497 | } | ||
diff --git a/src/lib/libcrypto/asn1/tasn_fre.c b/src/lib/libcrypto/asn1/tasn_fre.c deleted file mode 100644 index 2dd844159e..0000000000 --- a/src/lib/libcrypto/asn1/tasn_fre.c +++ /dev/null | |||
@@ -1,229 +0,0 @@ | |||
1 | /* tasn_fre.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | |||
60 | #include <stddef.h> | ||
61 | #include <openssl/asn1.h> | ||
62 | #include <openssl/asn1t.h> | ||
63 | #include <openssl/objects.h> | ||
64 | |||
65 | static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine); | ||
66 | |||
67 | /* Free up an ASN1 structure */ | ||
68 | |||
69 | void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) | ||
70 | { | ||
71 | asn1_item_combine_free(&val, it, 0); | ||
72 | } | ||
73 | |||
74 | void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
75 | { | ||
76 | asn1_item_combine_free(pval, it, 0); | ||
77 | } | ||
78 | |||
79 | static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) | ||
80 | { | ||
81 | const ASN1_TEMPLATE *tt = NULL, *seqtt; | ||
82 | const ASN1_EXTERN_FUNCS *ef; | ||
83 | const ASN1_COMPAT_FUNCS *cf; | ||
84 | const ASN1_AUX *aux = it->funcs; | ||
85 | ASN1_aux_cb *asn1_cb; | ||
86 | int i; | ||
87 | if(!pval) return; | ||
88 | if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return; | ||
89 | if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb; | ||
90 | else asn1_cb = 0; | ||
91 | |||
92 | switch(it->itype) { | ||
93 | |||
94 | case ASN1_ITYPE_PRIMITIVE: | ||
95 | if(it->templates) ASN1_template_free(pval, it->templates); | ||
96 | else ASN1_primitive_free(pval, it); | ||
97 | break; | ||
98 | |||
99 | case ASN1_ITYPE_MSTRING: | ||
100 | ASN1_primitive_free(pval, it); | ||
101 | break; | ||
102 | |||
103 | case ASN1_ITYPE_CHOICE: | ||
104 | if(asn1_cb) { | ||
105 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it); | ||
106 | if(i == 2) return; | ||
107 | } | ||
108 | i = asn1_get_choice_selector(pval, it); | ||
109 | if(asn1_cb) asn1_cb(ASN1_OP_FREE_PRE, pval, it); | ||
110 | if((i >= 0) && (i < it->tcount)) { | ||
111 | ASN1_VALUE **pchval; | ||
112 | tt = it->templates + i; | ||
113 | pchval = asn1_get_field_ptr(pval, tt); | ||
114 | ASN1_template_free(pchval, tt); | ||
115 | } | ||
116 | if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it); | ||
117 | if(!combine) { | ||
118 | OPENSSL_free(*pval); | ||
119 | *pval = NULL; | ||
120 | } | ||
121 | break; | ||
122 | |||
123 | case ASN1_ITYPE_COMPAT: | ||
124 | cf = it->funcs; | ||
125 | if(cf && cf->asn1_free) cf->asn1_free(*pval); | ||
126 | break; | ||
127 | |||
128 | case ASN1_ITYPE_EXTERN: | ||
129 | ef = it->funcs; | ||
130 | if(ef && ef->asn1_ex_free) ef->asn1_ex_free(pval, it); | ||
131 | break; | ||
132 | |||
133 | case ASN1_ITYPE_SEQUENCE: | ||
134 | if(asn1_do_lock(pval, -1, it) > 0) return; | ||
135 | if(asn1_cb) { | ||
136 | i = asn1_cb(ASN1_OP_FREE_PRE, pval, it); | ||
137 | if(i == 2) return; | ||
138 | } | ||
139 | asn1_enc_free(pval, it); | ||
140 | /* If we free up as normal we will invalidate any | ||
141 | * ANY DEFINED BY field and we wont be able to | ||
142 | * determine the type of the field it defines. So | ||
143 | * free up in reverse order. | ||
144 | */ | ||
145 | tt = it->templates + it->tcount - 1; | ||
146 | for(i = 0; i < it->tcount; tt--, i++) { | ||
147 | ASN1_VALUE **pseqval; | ||
148 | seqtt = asn1_do_adb(pval, tt, 0); | ||
149 | if(!seqtt) continue; | ||
150 | pseqval = asn1_get_field_ptr(pval, seqtt); | ||
151 | ASN1_template_free(pseqval, seqtt); | ||
152 | } | ||
153 | if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it); | ||
154 | if(!combine) { | ||
155 | OPENSSL_free(*pval); | ||
156 | *pval = NULL; | ||
157 | } | ||
158 | break; | ||
159 | } | ||
160 | } | ||
161 | |||
162 | void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | ||
163 | { | ||
164 | int i; | ||
165 | if(tt->flags & ASN1_TFLG_SK_MASK) { | ||
166 | STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; | ||
167 | for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) { | ||
168 | ASN1_VALUE *vtmp; | ||
169 | vtmp = sk_ASN1_VALUE_value(sk, i); | ||
170 | asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), 0); | ||
171 | } | ||
172 | sk_ASN1_VALUE_free(sk); | ||
173 | *pval = NULL; | ||
174 | } else asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item), | ||
175 | tt->flags & ASN1_TFLG_COMBINE); | ||
176 | } | ||
177 | |||
178 | void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
179 | { | ||
180 | int utype; | ||
181 | if(it) { | ||
182 | const ASN1_PRIMITIVE_FUNCS *pf; | ||
183 | pf = it->funcs; | ||
184 | if(pf && pf->prim_free) { | ||
185 | pf->prim_free(pval, it); | ||
186 | return; | ||
187 | } | ||
188 | } | ||
189 | /* Special case: if 'it' is NULL free contents of ASN1_TYPE */ | ||
190 | if(!it) { | ||
191 | ASN1_TYPE *typ = (ASN1_TYPE *)*pval; | ||
192 | utype = typ->type; | ||
193 | pval = (ASN1_VALUE **)&typ->value.ptr; | ||
194 | if(!*pval) return; | ||
195 | } else if(it->itype == ASN1_ITYPE_MSTRING) { | ||
196 | utype = -1; | ||
197 | if(!*pval) return; | ||
198 | } else { | ||
199 | utype = it->utype; | ||
200 | if((utype != V_ASN1_BOOLEAN) && !*pval) return; | ||
201 | } | ||
202 | |||
203 | switch(utype) { | ||
204 | case V_ASN1_OBJECT: | ||
205 | ASN1_OBJECT_free((ASN1_OBJECT *)*pval); | ||
206 | break; | ||
207 | |||
208 | case V_ASN1_BOOLEAN: | ||
209 | if (it) | ||
210 | *(ASN1_BOOLEAN *)pval = it->size; | ||
211 | else | ||
212 | *(ASN1_BOOLEAN *)pval = -1; | ||
213 | return; | ||
214 | |||
215 | case V_ASN1_NULL: | ||
216 | break; | ||
217 | |||
218 | case V_ASN1_ANY: | ||
219 | ASN1_primitive_free(pval, NULL); | ||
220 | OPENSSL_free(*pval); | ||
221 | break; | ||
222 | |||
223 | default: | ||
224 | ASN1_STRING_free((ASN1_STRING *)*pval); | ||
225 | *pval = NULL; | ||
226 | break; | ||
227 | } | ||
228 | *pval = NULL; | ||
229 | } | ||
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c deleted file mode 100644 index a0e3db574f..0000000000 --- a/src/lib/libcrypto/asn1/tasn_new.c +++ /dev/null | |||
@@ -1,351 +0,0 @@ | |||
1 | /* tasn_new.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | |||
60 | #include <stddef.h> | ||
61 | #include <openssl/asn1.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/err.h> | ||
64 | #include <openssl/asn1t.h> | ||
65 | #include <string.h> | ||
66 | |||
67 | static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine); | ||
68 | static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
69 | static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); | ||
70 | void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
71 | |||
72 | ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it) | ||
73 | { | ||
74 | ASN1_VALUE *ret = NULL; | ||
75 | if(ASN1_item_ex_new(&ret, it) > 0) return ret; | ||
76 | return NULL; | ||
77 | } | ||
78 | |||
79 | /* Allocate an ASN1 structure */ | ||
80 | |||
81 | int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
82 | { | ||
83 | return asn1_item_ex_combine_new(pval, it, 0); | ||
84 | } | ||
85 | |||
86 | static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) | ||
87 | { | ||
88 | const ASN1_TEMPLATE *tt = NULL; | ||
89 | const ASN1_COMPAT_FUNCS *cf; | ||
90 | const ASN1_EXTERN_FUNCS *ef; | ||
91 | const ASN1_AUX *aux = it->funcs; | ||
92 | ASN1_aux_cb *asn1_cb; | ||
93 | ASN1_VALUE **pseqval; | ||
94 | int i; | ||
95 | if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb; | ||
96 | else asn1_cb = 0; | ||
97 | |||
98 | if(!combine) *pval = NULL; | ||
99 | |||
100 | #ifdef CRYPTO_MDEBUG | ||
101 | if(it->sname) CRYPTO_push_info(it->sname); | ||
102 | #endif | ||
103 | |||
104 | switch(it->itype) { | ||
105 | |||
106 | case ASN1_ITYPE_EXTERN: | ||
107 | ef = it->funcs; | ||
108 | if(ef && ef->asn1_ex_new) { | ||
109 | if(!ef->asn1_ex_new(pval, it)) | ||
110 | goto memerr; | ||
111 | } | ||
112 | break; | ||
113 | |||
114 | case ASN1_ITYPE_COMPAT: | ||
115 | cf = it->funcs; | ||
116 | if(cf && cf->asn1_new) { | ||
117 | *pval = cf->asn1_new(); | ||
118 | if(!*pval) goto memerr; | ||
119 | } | ||
120 | break; | ||
121 | |||
122 | case ASN1_ITYPE_PRIMITIVE: | ||
123 | if(it->templates) { | ||
124 | if(!ASN1_template_new(pval, it->templates)) | ||
125 | goto memerr; | ||
126 | } else { | ||
127 | if(!ASN1_primitive_new(pval, it)) | ||
128 | goto memerr; | ||
129 | } | ||
130 | break; | ||
131 | |||
132 | case ASN1_ITYPE_MSTRING: | ||
133 | if(!ASN1_primitive_new(pval, it)) | ||
134 | goto memerr; | ||
135 | break; | ||
136 | |||
137 | case ASN1_ITYPE_CHOICE: | ||
138 | if(asn1_cb) { | ||
139 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it); | ||
140 | if(!i) goto auxerr; | ||
141 | if(i==2) { | ||
142 | #ifdef CRYPTO_MDEBUG | ||
143 | if(it->sname) CRYPTO_pop_info(); | ||
144 | #endif | ||
145 | return 1; | ||
146 | } | ||
147 | } | ||
148 | if(!combine) { | ||
149 | *pval = OPENSSL_malloc(it->size); | ||
150 | if(!*pval) goto memerr; | ||
151 | memset(*pval, 0, it->size); | ||
152 | } | ||
153 | asn1_set_choice_selector(pval, -1, it); | ||
154 | if(asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it)) | ||
155 | goto auxerr; | ||
156 | break; | ||
157 | |||
158 | case ASN1_ITYPE_SEQUENCE: | ||
159 | if(asn1_cb) { | ||
160 | i = asn1_cb(ASN1_OP_NEW_PRE, pval, it); | ||
161 | if(!i) goto auxerr; | ||
162 | if(i==2) { | ||
163 | #ifdef CRYPTO_MDEBUG | ||
164 | if(it->sname) CRYPTO_pop_info(); | ||
165 | #endif | ||
166 | return 1; | ||
167 | } | ||
168 | } | ||
169 | if(!combine) { | ||
170 | *pval = OPENSSL_malloc(it->size); | ||
171 | if(!*pval) goto memerr; | ||
172 | memset(*pval, 0, it->size); | ||
173 | asn1_do_lock(pval, 0, it); | ||
174 | asn1_enc_init(pval, it); | ||
175 | } | ||
176 | for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) { | ||
177 | pseqval = asn1_get_field_ptr(pval, tt); | ||
178 | if(!ASN1_template_new(pseqval, tt)) goto memerr; | ||
179 | } | ||
180 | if(asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it)) | ||
181 | goto auxerr; | ||
182 | break; | ||
183 | } | ||
184 | #ifdef CRYPTO_MDEBUG | ||
185 | if(it->sname) CRYPTO_pop_info(); | ||
186 | #endif | ||
187 | return 1; | ||
188 | |||
189 | memerr: | ||
190 | ASN1err(ASN1_F_ASN1_ITEM_NEW, ERR_R_MALLOC_FAILURE); | ||
191 | #ifdef CRYPTO_MDEBUG | ||
192 | if(it->sname) CRYPTO_pop_info(); | ||
193 | #endif | ||
194 | return 0; | ||
195 | |||
196 | auxerr: | ||
197 | ASN1err(ASN1_F_ASN1_ITEM_NEW, ASN1_R_AUX_ERROR); | ||
198 | ASN1_item_ex_free(pval, it); | ||
199 | #ifdef CRYPTO_MDEBUG | ||
200 | if(it->sname) CRYPTO_pop_info(); | ||
201 | #endif | ||
202 | return 0; | ||
203 | |||
204 | } | ||
205 | |||
206 | static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
207 | { | ||
208 | const ASN1_EXTERN_FUNCS *ef; | ||
209 | |||
210 | switch(it->itype) { | ||
211 | |||
212 | case ASN1_ITYPE_EXTERN: | ||
213 | ef = it->funcs; | ||
214 | if(ef && ef->asn1_ex_clear) | ||
215 | ef->asn1_ex_clear(pval, it); | ||
216 | else *pval = NULL; | ||
217 | break; | ||
218 | |||
219 | |||
220 | case ASN1_ITYPE_PRIMITIVE: | ||
221 | if(it->templates) | ||
222 | asn1_template_clear(pval, it->templates); | ||
223 | else | ||
224 | asn1_primitive_clear(pval, it); | ||
225 | break; | ||
226 | |||
227 | case ASN1_ITYPE_MSTRING: | ||
228 | asn1_primitive_clear(pval, it); | ||
229 | break; | ||
230 | |||
231 | case ASN1_ITYPE_COMPAT: | ||
232 | case ASN1_ITYPE_CHOICE: | ||
233 | case ASN1_ITYPE_SEQUENCE: | ||
234 | *pval = NULL; | ||
235 | break; | ||
236 | } | ||
237 | } | ||
238 | |||
239 | |||
240 | int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | ||
241 | { | ||
242 | const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); | ||
243 | int ret; | ||
244 | if(tt->flags & ASN1_TFLG_OPTIONAL) { | ||
245 | asn1_template_clear(pval, tt); | ||
246 | return 1; | ||
247 | } | ||
248 | /* If ANY DEFINED BY nothing to do */ | ||
249 | |||
250 | if(tt->flags & ASN1_TFLG_ADB_MASK) { | ||
251 | *pval = NULL; | ||
252 | return 1; | ||
253 | } | ||
254 | #ifdef CRYPTO_MDEBUG | ||
255 | if(tt->field_name) CRYPTO_push_info(tt->field_name); | ||
256 | #endif | ||
257 | /* If SET OF or SEQUENCE OF, its a STACK */ | ||
258 | if(tt->flags & ASN1_TFLG_SK_MASK) { | ||
259 | STACK_OF(ASN1_VALUE) *skval; | ||
260 | skval = sk_ASN1_VALUE_new_null(); | ||
261 | if(!skval) { | ||
262 | ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE); | ||
263 | ret = 0; | ||
264 | goto done; | ||
265 | } | ||
266 | *pval = (ASN1_VALUE *)skval; | ||
267 | ret = 1; | ||
268 | goto done; | ||
269 | } | ||
270 | /* Otherwise pass it back to the item routine */ | ||
271 | ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE); | ||
272 | done: | ||
273 | #ifdef CRYPTO_MDEBUG | ||
274 | if(it->sname) CRYPTO_pop_info(); | ||
275 | #endif | ||
276 | return ret; | ||
277 | } | ||
278 | |||
279 | static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | ||
280 | { | ||
281 | /* If ADB or STACK just NULL the field */ | ||
282 | if(tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK)) | ||
283 | *pval = NULL; | ||
284 | else | ||
285 | asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item)); | ||
286 | } | ||
287 | |||
288 | |||
289 | /* NB: could probably combine most of the real XXX_new() behaviour and junk all the old | ||
290 | * functions. | ||
291 | */ | ||
292 | |||
293 | int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
294 | { | ||
295 | ASN1_TYPE *typ; | ||
296 | int utype; | ||
297 | const ASN1_PRIMITIVE_FUNCS *pf; | ||
298 | pf = it->funcs; | ||
299 | if(pf && pf->prim_new) return pf->prim_new(pval, it); | ||
300 | if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1; | ||
301 | else utype = it->utype; | ||
302 | switch(utype) { | ||
303 | case V_ASN1_OBJECT: | ||
304 | *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); | ||
305 | return 1; | ||
306 | |||
307 | case V_ASN1_BOOLEAN: | ||
308 | if (it) | ||
309 | *(ASN1_BOOLEAN *)pval = it->size; | ||
310 | else | ||
311 | *(ASN1_BOOLEAN *)pval = -1; | ||
312 | return 1; | ||
313 | |||
314 | case V_ASN1_NULL: | ||
315 | *pval = (ASN1_VALUE *)1; | ||
316 | return 1; | ||
317 | |||
318 | case V_ASN1_ANY: | ||
319 | typ = OPENSSL_malloc(sizeof(ASN1_TYPE)); | ||
320 | if(!typ) return 0; | ||
321 | typ->value.ptr = NULL; | ||
322 | typ->type = -1; | ||
323 | *pval = (ASN1_VALUE *)typ; | ||
324 | break; | ||
325 | |||
326 | default: | ||
327 | *pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype); | ||
328 | break; | ||
329 | } | ||
330 | if(*pval) return 1; | ||
331 | return 0; | ||
332 | } | ||
333 | |||
334 | void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
335 | { | ||
336 | int utype; | ||
337 | const ASN1_PRIMITIVE_FUNCS *pf; | ||
338 | pf = it->funcs; | ||
339 | if(pf) { | ||
340 | if(pf->prim_clear) | ||
341 | pf->prim_clear(pval, it); | ||
342 | else | ||
343 | *pval = NULL; | ||
344 | return; | ||
345 | } | ||
346 | if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1; | ||
347 | else utype = it->utype; | ||
348 | if(utype == V_ASN1_BOOLEAN) | ||
349 | *(ASN1_BOOLEAN *)pval = it->size; | ||
350 | else *pval = NULL; | ||
351 | } | ||
diff --git a/src/lib/libcrypto/asn1/tasn_prn.c b/src/lib/libcrypto/asn1/tasn_prn.c deleted file mode 100644 index 719639b511..0000000000 --- a/src/lib/libcrypto/asn1/tasn_prn.c +++ /dev/null | |||
@@ -1,198 +0,0 @@ | |||
1 | /* tasn_prn.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | |||
60 | #include <stddef.h> | ||
61 | #include <openssl/asn1.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/buffer.h> | ||
64 | #include <openssl/err.h> | ||
65 | #include <openssl/nasn.h> | ||
66 | |||
67 | /* Print routines. Print out a whole structure from a template. | ||
68 | */ | ||
69 | |||
70 | static int asn1_item_print_nm(BIO *out, void *fld, int indent, const ASN1_ITEM *it, const char *name); | ||
71 | |||
72 | int ASN1_item_print(BIO *out, void *fld, int indent, const ASN1_ITEM *it) | ||
73 | { | ||
74 | return asn1_item_print_nm(out, fld, indent, it, it->sname); | ||
75 | } | ||
76 | |||
77 | static int asn1_item_print_nm(BIO *out, void *fld, int indent, const ASN1_ITEM *it, const char *name) | ||
78 | { | ||
79 | ASN1_STRING *str; | ||
80 | const ASN1_TEMPLATE *tt; | ||
81 | void *tmpfld; | ||
82 | int i; | ||
83 | if(!fld) { | ||
84 | BIO_printf(out, "%*s%s ABSENT\n", indent, "", name); | ||
85 | return 1; | ||
86 | } | ||
87 | switch(it->itype) { | ||
88 | |||
89 | case ASN1_ITYPE_PRIMITIVE: | ||
90 | if(it->templates) | ||
91 | return ASN1_template_print(out, fld, indent, it->templates); | ||
92 | return asn1_primitive_print(out, fld, it->utype, indent, name); | ||
93 | break; | ||
94 | |||
95 | case ASN1_ITYPE_MSTRING: | ||
96 | str = fld; | ||
97 | return asn1_primitive_print(out, fld, str->type, indent, name); | ||
98 | |||
99 | case ASN1_ITYPE_EXTERN: | ||
100 | BIO_printf(out, "%*s%s:EXTERNAL TYPE %s %s\n", indent, "", name, it->sname, fld ? "" : "ABSENT"); | ||
101 | return 1; | ||
102 | case ASN1_ITYPE_COMPAT: | ||
103 | BIO_printf(out, "%*s%s:COMPATIBLE TYPE %s %s\n", indent, "", name, it->sname, fld ? "" : "ABSENT"); | ||
104 | return 1; | ||
105 | |||
106 | |||
107 | case ASN1_ITYPE_CHOICE: | ||
108 | /* CHOICE type, get selector */ | ||
109 | i = asn1_get_choice_selector(fld, it); | ||
110 | /* This should never happen... */ | ||
111 | if((i < 0) || (i >= it->tcount)) { | ||
112 | BIO_printf(out, "%s selector [%d] out of range\n", it->sname, i); | ||
113 | return 1; | ||
114 | } | ||
115 | tt = it->templates + i; | ||
116 | tmpfld = asn1_get_field(fld, tt); | ||
117 | return ASN1_template_print(out, tmpfld, indent, tt); | ||
118 | |||
119 | case ASN1_ITYPE_SEQUENCE: | ||
120 | BIO_printf(out, "%*s%s {\n", indent, "", name); | ||
121 | /* Get each field entry */ | ||
122 | for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) { | ||
123 | tmpfld = asn1_get_field(fld, tt); | ||
124 | ASN1_template_print(out, tmpfld, indent + 2, tt); | ||
125 | } | ||
126 | BIO_printf(out, "%*s}\n", indent, ""); | ||
127 | return 1; | ||
128 | |||
129 | default: | ||
130 | return 0; | ||
131 | } | ||
132 | } | ||
133 | |||
134 | int ASN1_template_print(BIO *out, void *fld, int indent, const ASN1_TEMPLATE *tt) | ||
135 | { | ||
136 | int i, flags; | ||
137 | #if 0 | ||
138 | if(!fld) return 0; | ||
139 | #endif | ||
140 | flags = tt->flags; | ||
141 | if(flags & ASN1_TFLG_SK_MASK) { | ||
142 | char *tname; | ||
143 | void *skitem; | ||
144 | /* SET OF, SEQUENCE OF */ | ||
145 | if(flags & ASN1_TFLG_SET_OF) tname = "SET"; | ||
146 | else tname = "SEQUENCE"; | ||
147 | if(fld) { | ||
148 | BIO_printf(out, "%*s%s OF %s {\n", indent, "", tname, tt->field_name); | ||
149 | for(i = 0; i < sk_num(fld); i++) { | ||
150 | skitem = sk_value(fld, i); | ||
151 | asn1_item_print_nm(out, skitem, indent + 2, tt->item, ""); | ||
152 | } | ||
153 | BIO_printf(out, "%*s}\n", indent, ""); | ||
154 | } else | ||
155 | BIO_printf(out, "%*s%s OF %s ABSENT\n", indent, "", tname, tt->field_name); | ||
156 | return 1; | ||
157 | } | ||
158 | return asn1_item_print_nm(out, fld, indent, tt->item, tt->field_name); | ||
159 | } | ||
160 | |||
161 | static int asn1_primitive_print(BIO *out, void *fld, long utype, int indent, const char *name) | ||
162 | { | ||
163 | ASN1_STRING *str = fld; | ||
164 | if(fld) { | ||
165 | if(utype == V_ASN1_BOOLEAN) { | ||
166 | int *bool = fld; | ||
167 | if(*bool == -1) printf("BOOL MISSING\n"); | ||
168 | BIO_printf(out, "%*s%s:%s", indent, "", "BOOLEAN", *bool ? "TRUE" : "FALSE"); | ||
169 | } else if((utype == V_ASN1_INTEGER) | ||
170 | || (utype == V_ASN1_ENUMERATED)) { | ||
171 | char *s, *nm; | ||
172 | s = i2s_ASN1_INTEGER(NULL, fld); | ||
173 | if(utype == V_ASN1_INTEGER) nm = "INTEGER"; | ||
174 | else nm = "ENUMERATED"; | ||
175 | BIO_printf(out, "%*s%s:%s", indent, "", nm, s); | ||
176 | OPENSSL_free(s); | ||
177 | } else if(utype == V_ASN1_NULL) { | ||
178 | BIO_printf(out, "%*s%s", indent, "", "NULL"); | ||
179 | } else if(utype == V_ASN1_UTCTIME) { | ||
180 | BIO_printf(out, "%*s%s:%s:", indent, "", name, "UTCTIME"); | ||
181 | ASN1_UTCTIME_print(out, str); | ||
182 | } else if(utype == V_ASN1_GENERALIZEDTIME) { | ||
183 | BIO_printf(out, "%*s%s:%s:", indent, "", name, "GENERALIZEDTIME"); | ||
184 | ASN1_GENERALIZEDTIME_print(out, str); | ||
185 | } else if(utype == V_ASN1_OBJECT) { | ||
186 | char objbuf[80], *ln; | ||
187 | ln = OBJ_nid2ln(OBJ_obj2nid(fld)); | ||
188 | if(!ln) ln = ""; | ||
189 | OBJ_obj2txt(objbuf, sizeof objbuf, fld, 1); | ||
190 | BIO_printf(out, "%*s%s:%s (%s)", indent, "", "OBJECT", ln, objbuf); | ||
191 | } else { | ||
192 | BIO_printf(out, "%*s%s:", indent, "", name); | ||
193 | ASN1_STRING_print_ex(out, str, ASN1_STRFLGS_DUMP_UNKNOWN|ASN1_STRFLGS_SHOW_TYPE); | ||
194 | } | ||
195 | BIO_printf(out, "\n"); | ||
196 | } else BIO_printf(out, "%*s%s [ABSENT]\n", indent, "", name); | ||
197 | return 1; | ||
198 | } | ||
diff --git a/src/lib/libcrypto/asn1/tasn_typ.c b/src/lib/libcrypto/asn1/tasn_typ.c deleted file mode 100644 index 804d2eeba2..0000000000 --- a/src/lib/libcrypto/asn1/tasn_typ.c +++ /dev/null | |||
@@ -1,133 +0,0 @@ | |||
1 | /* tasn_typ.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | #include <stdio.h> | ||
59 | #include <openssl/asn1.h> | ||
60 | #include <openssl/asn1t.h> | ||
61 | |||
62 | /* Declarations for string types */ | ||
63 | |||
64 | |||
65 | IMPLEMENT_ASN1_TYPE(ASN1_INTEGER) | ||
66 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_INTEGER) | ||
67 | |||
68 | IMPLEMENT_ASN1_TYPE(ASN1_ENUMERATED) | ||
69 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_ENUMERATED) | ||
70 | |||
71 | IMPLEMENT_ASN1_TYPE(ASN1_BIT_STRING) | ||
72 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_BIT_STRING) | ||
73 | |||
74 | IMPLEMENT_ASN1_TYPE(ASN1_OCTET_STRING) | ||
75 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_OCTET_STRING) | ||
76 | |||
77 | IMPLEMENT_ASN1_TYPE(ASN1_NULL) | ||
78 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_NULL) | ||
79 | |||
80 | IMPLEMENT_ASN1_TYPE(ASN1_OBJECT) | ||
81 | |||
82 | IMPLEMENT_ASN1_TYPE(ASN1_UTF8STRING) | ||
83 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTF8STRING) | ||
84 | |||
85 | IMPLEMENT_ASN1_TYPE(ASN1_PRINTABLESTRING) | ||
86 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING) | ||
87 | |||
88 | IMPLEMENT_ASN1_TYPE(ASN1_T61STRING) | ||
89 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_T61STRING) | ||
90 | |||
91 | IMPLEMENT_ASN1_TYPE(ASN1_IA5STRING) | ||
92 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_IA5STRING) | ||
93 | |||
94 | IMPLEMENT_ASN1_TYPE(ASN1_GENERALSTRING) | ||
95 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALSTRING) | ||
96 | |||
97 | IMPLEMENT_ASN1_TYPE(ASN1_UTCTIME) | ||
98 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_UTCTIME) | ||
99 | |||
100 | IMPLEMENT_ASN1_TYPE(ASN1_GENERALIZEDTIME) | ||
101 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME) | ||
102 | |||
103 | IMPLEMENT_ASN1_TYPE(ASN1_VISIBLESTRING) | ||
104 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_VISIBLESTRING) | ||
105 | |||
106 | IMPLEMENT_ASN1_TYPE(ASN1_UNIVERSALSTRING) | ||
107 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING) | ||
108 | |||
109 | IMPLEMENT_ASN1_TYPE(ASN1_BMPSTRING) | ||
110 | IMPLEMENT_ASN1_FUNCTIONS(ASN1_BMPSTRING) | ||
111 | |||
112 | IMPLEMENT_ASN1_TYPE(ASN1_ANY) | ||
113 | |||
114 | /* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */ | ||
115 | IMPLEMENT_ASN1_TYPE(ASN1_SEQUENCE) | ||
116 | |||
117 | IMPLEMENT_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) | ||
118 | |||
119 | /* Multistring types */ | ||
120 | |||
121 | IMPLEMENT_ASN1_MSTRING(ASN1_PRINTABLE, B_ASN1_PRINTABLE) | ||
122 | IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE) | ||
123 | |||
124 | IMPLEMENT_ASN1_MSTRING(DISPLAYTEXT, B_ASN1_DISPLAYTEXT) | ||
125 | IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT) | ||
126 | |||
127 | IMPLEMENT_ASN1_MSTRING(DIRECTORYSTRING, B_ASN1_DIRECTORYSTRING) | ||
128 | IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING) | ||
129 | |||
130 | /* Three separate BOOLEAN type: normal, DEFAULT TRUE and DEFAULT FALSE */ | ||
131 | IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, -1) | ||
132 | IMPLEMENT_ASN1_TYPE_ex(ASN1_TBOOLEAN, ASN1_BOOLEAN, 1) | ||
133 | IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, 0) | ||
diff --git a/src/lib/libcrypto/asn1/tasn_utl.c b/src/lib/libcrypto/asn1/tasn_utl.c deleted file mode 100644 index 8996ce8c13..0000000000 --- a/src/lib/libcrypto/asn1/tasn_utl.c +++ /dev/null | |||
@@ -1,253 +0,0 @@ | |||
1 | /* tasn_utl.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | |||
60 | #include <stddef.h> | ||
61 | #include <string.h> | ||
62 | #include <openssl/asn1.h> | ||
63 | #include <openssl/asn1t.h> | ||
64 | #include <openssl/objects.h> | ||
65 | #include <openssl/err.h> | ||
66 | |||
67 | /* Utility functions for manipulating fields and offsets */ | ||
68 | |||
69 | /* Add 'offset' to 'addr' */ | ||
70 | #define offset2ptr(addr, offset) (void *)(((char *) addr) + offset) | ||
71 | |||
72 | /* Given an ASN1_ITEM CHOICE type return | ||
73 | * the selector value | ||
74 | */ | ||
75 | |||
76 | int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
77 | { | ||
78 | int *sel = offset2ptr(*pval, it->utype); | ||
79 | return *sel; | ||
80 | } | ||
81 | |||
82 | /* Given an ASN1_ITEM CHOICE type set | ||
83 | * the selector value, return old value. | ||
84 | */ | ||
85 | |||
86 | int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it) | ||
87 | { | ||
88 | int *sel, ret; | ||
89 | sel = offset2ptr(*pval, it->utype); | ||
90 | ret = *sel; | ||
91 | *sel = value; | ||
92 | return ret; | ||
93 | } | ||
94 | |||
95 | /* Do reference counting. The value 'op' decides what to do. | ||
96 | * if it is +1 then the count is incremented. If op is 0 count is | ||
97 | * set to 1. If op is -1 count is decremented and the return value | ||
98 | * is the current refrence count or 0 if no reference count exists. | ||
99 | */ | ||
100 | |||
101 | int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) | ||
102 | { | ||
103 | const ASN1_AUX *aux; | ||
104 | int *lck, ret; | ||
105 | if(it->itype != ASN1_ITYPE_SEQUENCE) return 0; | ||
106 | aux = it->funcs; | ||
107 | if(!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) return 0; | ||
108 | lck = offset2ptr(*pval, aux->ref_offset); | ||
109 | if(op == 0) { | ||
110 | *lck = 1; | ||
111 | return 1; | ||
112 | } | ||
113 | ret = CRYPTO_add(lck, op, aux->ref_lock); | ||
114 | #ifdef REF_PRINT | ||
115 | fprintf(stderr, "%s: Reference Count: %d\n", it->sname, *lck); | ||
116 | #endif | ||
117 | #ifdef REF_CHECK | ||
118 | if(ret < 0) | ||
119 | fprintf(stderr, "%s, bad reference count\n", it->sname); | ||
120 | #endif | ||
121 | return ret; | ||
122 | } | ||
123 | |||
124 | static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
125 | { | ||
126 | const ASN1_AUX *aux; | ||
127 | if(!pval || !*pval) return NULL; | ||
128 | aux = it->funcs; | ||
129 | if(!aux || !(aux->flags & ASN1_AFLG_ENCODING)) return NULL; | ||
130 | return offset2ptr(*pval, aux->enc_offset); | ||
131 | } | ||
132 | |||
133 | void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
134 | { | ||
135 | ASN1_ENCODING *enc; | ||
136 | enc = asn1_get_enc_ptr(pval, it); | ||
137 | if(enc) { | ||
138 | enc->enc = NULL; | ||
139 | enc->len = 0; | ||
140 | enc->modified = 1; | ||
141 | } | ||
142 | } | ||
143 | |||
144 | void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
145 | { | ||
146 | ASN1_ENCODING *enc; | ||
147 | enc = asn1_get_enc_ptr(pval, it); | ||
148 | if(enc) { | ||
149 | if(enc->enc) OPENSSL_free(enc->enc); | ||
150 | enc->enc = NULL; | ||
151 | enc->len = 0; | ||
152 | enc->modified = 1; | ||
153 | } | ||
154 | } | ||
155 | |||
156 | int asn1_enc_save(ASN1_VALUE **pval, unsigned char *in, int inlen, const ASN1_ITEM *it) | ||
157 | { | ||
158 | ASN1_ENCODING *enc; | ||
159 | enc = asn1_get_enc_ptr(pval, it); | ||
160 | if(!enc) return 1; | ||
161 | |||
162 | if(enc->enc) OPENSSL_free(enc->enc); | ||
163 | enc->enc = OPENSSL_malloc(inlen); | ||
164 | if(!enc->enc) return 0; | ||
165 | memcpy(enc->enc, in, inlen); | ||
166 | enc->len = inlen; | ||
167 | enc->modified = 0; | ||
168 | |||
169 | return 1; | ||
170 | } | ||
171 | |||
172 | int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
173 | { | ||
174 | ASN1_ENCODING *enc; | ||
175 | enc = asn1_get_enc_ptr(pval, it); | ||
176 | if(!enc || enc->modified) return 0; | ||
177 | if(out) { | ||
178 | memcpy(*out, enc->enc, enc->len); | ||
179 | *out += enc->len; | ||
180 | } | ||
181 | if(len) *len = enc->len; | ||
182 | return 1; | ||
183 | } | ||
184 | |||
185 | /* Given an ASN1_TEMPLATE get a pointer to a field */ | ||
186 | ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) | ||
187 | { | ||
188 | ASN1_VALUE **pvaltmp; | ||
189 | if(tt->flags & ASN1_TFLG_COMBINE) return pval; | ||
190 | pvaltmp = offset2ptr(*pval, tt->offset); | ||
191 | /* NOTE for BOOLEAN types the field is just a plain | ||
192 | * int so we can't return int **, so settle for | ||
193 | * (int *). | ||
194 | */ | ||
195 | return pvaltmp; | ||
196 | } | ||
197 | |||
198 | /* Handle ANY DEFINED BY template, find the selector, look up | ||
199 | * the relevant ASN1_TEMPLATE in the table and return it. | ||
200 | */ | ||
201 | |||
202 | const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr) | ||
203 | { | ||
204 | const ASN1_ADB *adb; | ||
205 | const ASN1_ADB_TABLE *atbl; | ||
206 | long selector; | ||
207 | ASN1_VALUE **sfld; | ||
208 | int i; | ||
209 | if(!(tt->flags & ASN1_TFLG_ADB_MASK)) return tt; | ||
210 | |||
211 | /* Else ANY DEFINED BY ... get the table */ | ||
212 | adb = ASN1_ADB_ptr(tt->item); | ||
213 | |||
214 | /* Get the selector field */ | ||
215 | sfld = offset2ptr(*pval, adb->offset); | ||
216 | |||
217 | /* Check if NULL */ | ||
218 | if(!sfld) { | ||
219 | if(!adb->null_tt) goto err; | ||
220 | return adb->null_tt; | ||
221 | } | ||
222 | |||
223 | /* Convert type to a long: | ||
224 | * NB: don't check for NID_undef here because it | ||
225 | * might be a legitimate value in the table | ||
226 | */ | ||
227 | if(tt->flags & ASN1_TFLG_ADB_OID) | ||
228 | selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld); | ||
229 | else | ||
230 | selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld); | ||
231 | |||
232 | /* Try to find matching entry in table | ||
233 | * Maybe should check application types first to | ||
234 | * allow application override? Might also be useful | ||
235 | * to have a flag which indicates table is sorted and | ||
236 | * we can do a binary search. For now stick to a | ||
237 | * linear search. | ||
238 | */ | ||
239 | |||
240 | for(atbl = adb->tbl, i = 0; i < adb->tblcount; i++, atbl++) | ||
241 | if(atbl->value == selector) return &atbl->tt; | ||
242 | |||
243 | /* FIXME: need to search application table too */ | ||
244 | |||
245 | /* No match, return default type */ | ||
246 | if(!adb->default_tt) goto err; | ||
247 | return adb->default_tt; | ||
248 | |||
249 | err: | ||
250 | /* FIXME: should log the value or OID of unsupported type */ | ||
251 | if(nullerr) ASN1err(ASN1_F_ASN1_DO_ADB, ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE); | ||
252 | return NULL; | ||
253 | } | ||
diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c deleted file mode 100644 index 00b9ea54a1..0000000000 --- a/src/lib/libcrypto/asn1/x_algor.c +++ /dev/null | |||
@@ -1,73 +0,0 @@ | |||
1 | /* x_algor.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stddef.h> | ||
60 | #include <openssl/x509.h> | ||
61 | #include <openssl/asn1.h> | ||
62 | #include <openssl/asn1t.h> | ||
63 | |||
64 | ASN1_SEQUENCE(X509_ALGOR) = { | ||
65 | ASN1_SIMPLE(X509_ALGOR, algorithm, ASN1_OBJECT), | ||
66 | ASN1_OPT(X509_ALGOR, parameter, ASN1_ANY) | ||
67 | } ASN1_SEQUENCE_END(X509_ALGOR) | ||
68 | |||
69 | IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR) | ||
70 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR) | ||
71 | |||
72 | IMPLEMENT_STACK_OF(X509_ALGOR) | ||
73 | IMPLEMENT_ASN1_SET_OF(X509_ALGOR) | ||
diff --git a/src/lib/libcrypto/asn1/x_attrib.c b/src/lib/libcrypto/asn1/x_attrib.c deleted file mode 100644 index 1e3713f18f..0000000000 --- a/src/lib/libcrypto/asn1/x_attrib.c +++ /dev/null | |||
@@ -1,118 +0,0 @@ | |||
1 | /* crypto/asn1/x_attrib.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/objects.h> | ||
62 | #include <openssl/asn1t.h> | ||
63 | #include <openssl/x509.h> | ||
64 | |||
65 | /* X509_ATTRIBUTE: this has the following form: | ||
66 | * | ||
67 | * typedef struct x509_attributes_st | ||
68 | * { | ||
69 | * ASN1_OBJECT *object; | ||
70 | * int single; | ||
71 | * union { | ||
72 | * char *ptr; | ||
73 | * STACK_OF(ASN1_TYPE) *set; | ||
74 | * ASN1_TYPE *single; | ||
75 | * } value; | ||
76 | * } X509_ATTRIBUTE; | ||
77 | * | ||
78 | * this needs some extra thought because the CHOICE type is | ||
79 | * merged with the main structure and because the value can | ||
80 | * be anything at all we *must* try the SET OF first because | ||
81 | * the ASN1_ANY type will swallow anything including the whole | ||
82 | * SET OF structure. | ||
83 | */ | ||
84 | |||
85 | ASN1_CHOICE(X509_ATTRIBUTE_SET) = { | ||
86 | ASN1_SET_OF(X509_ATTRIBUTE, value.set, ASN1_ANY), | ||
87 | ASN1_SIMPLE(X509_ATTRIBUTE, value.single, ASN1_ANY) | ||
88 | } ASN1_CHOICE_END_selector(X509_ATTRIBUTE, X509_ATTRIBUTE_SET, single) | ||
89 | |||
90 | ASN1_SEQUENCE(X509_ATTRIBUTE) = { | ||
91 | ASN1_SIMPLE(X509_ATTRIBUTE, object, ASN1_OBJECT), | ||
92 | /* CHOICE type merged with parent */ | ||
93 | ASN1_EX_COMBINE(0, 0, X509_ATTRIBUTE_SET) | ||
94 | } ASN1_SEQUENCE_END(X509_ATTRIBUTE) | ||
95 | |||
96 | IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE) | ||
97 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE) | ||
98 | |||
99 | X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value) | ||
100 | { | ||
101 | X509_ATTRIBUTE *ret=NULL; | ||
102 | ASN1_TYPE *val=NULL; | ||
103 | |||
104 | if ((ret=X509_ATTRIBUTE_new()) == NULL) | ||
105 | return(NULL); | ||
106 | ret->object=OBJ_nid2obj(nid); | ||
107 | ret->single=0; | ||
108 | if ((ret->value.set=sk_ASN1_TYPE_new_null()) == NULL) goto err; | ||
109 | if ((val=ASN1_TYPE_new()) == NULL) goto err; | ||
110 | if (!sk_ASN1_TYPE_push(ret->value.set,val)) goto err; | ||
111 | |||
112 | ASN1_TYPE_set(val,atrtype,value); | ||
113 | return(ret); | ||
114 | err: | ||
115 | if (ret != NULL) X509_ATTRIBUTE_free(ret); | ||
116 | if (val != NULL) ASN1_TYPE_free(val); | ||
117 | return(NULL); | ||
118 | } | ||
diff --git a/src/lib/libcrypto/asn1/x_bignum.c b/src/lib/libcrypto/asn1/x_bignum.c deleted file mode 100644 index 848c7a0877..0000000000 --- a/src/lib/libcrypto/asn1/x_bignum.c +++ /dev/null | |||
@@ -1,137 +0,0 @@ | |||
1 | /* x_bignum.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1t.h> | ||
62 | |||
63 | /* Custom primitive type for BIGNUM handling. This reads in an ASN1_INTEGER as a | ||
64 | * BIGNUM directly. Currently it ignores the sign which isn't a problem since all | ||
65 | * BIGNUMs used are non negative and anything that looks negative is normally due | ||
66 | * to an encoding error. | ||
67 | */ | ||
68 | |||
69 | #define BN_SENSITIVE 1 | ||
70 | |||
71 | static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
72 | static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
73 | |||
74 | static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); | ||
75 | static int bn_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); | ||
76 | |||
77 | static ASN1_PRIMITIVE_FUNCS bignum_pf = { | ||
78 | NULL, 0, | ||
79 | bn_new, | ||
80 | bn_free, | ||
81 | 0, | ||
82 | bn_c2i, | ||
83 | bn_i2c | ||
84 | }; | ||
85 | |||
86 | ASN1_ITEM_start(BIGNUM) | ||
87 | ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, 0, "BIGNUM" | ||
88 | ASN1_ITEM_end(BIGNUM) | ||
89 | |||
90 | ASN1_ITEM_start(CBIGNUM) | ||
91 | ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &bignum_pf, BN_SENSITIVE, "BIGNUM" | ||
92 | ASN1_ITEM_end(CBIGNUM) | ||
93 | |||
94 | static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
95 | { | ||
96 | *pval = (ASN1_VALUE *)BN_new(); | ||
97 | if(*pval) return 1; | ||
98 | else return 0; | ||
99 | } | ||
100 | |||
101 | static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
102 | { | ||
103 | if(!*pval) return; | ||
104 | if(it->size & BN_SENSITIVE) BN_clear_free((BIGNUM *)*pval); | ||
105 | else BN_free((BIGNUM *)*pval); | ||
106 | *pval = NULL; | ||
107 | } | ||
108 | |||
109 | static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it) | ||
110 | { | ||
111 | BIGNUM *bn; | ||
112 | int pad; | ||
113 | if(!*pval) return -1; | ||
114 | bn = (BIGNUM *)*pval; | ||
115 | /* If MSB set in an octet we need a padding byte */ | ||
116 | if(BN_num_bits(bn) & 0x7) pad = 0; | ||
117 | else pad = 1; | ||
118 | if(cont) { | ||
119 | if(pad) *cont++ = 0; | ||
120 | BN_bn2bin(bn, cont); | ||
121 | } | ||
122 | return pad + BN_num_bytes(bn); | ||
123 | } | ||
124 | |||
125 | static int bn_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it) | ||
126 | { | ||
127 | BIGNUM *bn; | ||
128 | if(!*pval) bn_new(pval, it); | ||
129 | bn = (BIGNUM *)*pval; | ||
130 | if(!BN_bin2bn(cont, len, bn)) { | ||
131 | bn_free(pval, it); | ||
132 | return 0; | ||
133 | } | ||
134 | return 1; | ||
135 | } | ||
136 | |||
137 | |||
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c deleted file mode 100644 index 11fce96825..0000000000 --- a/src/lib/libcrypto/asn1/x_crl.c +++ /dev/null | |||
@@ -1,162 +0,0 @@ | |||
1 | /* crypto/asn1/x_crl.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1t.h> | ||
62 | #include <openssl/x509.h> | ||
63 | |||
64 | static int X509_REVOKED_cmp(const X509_REVOKED * const *a, | ||
65 | const X509_REVOKED * const *b); | ||
66 | static int X509_REVOKED_seq_cmp(const X509_REVOKED * const *a, | ||
67 | const X509_REVOKED * const *b); | ||
68 | |||
69 | ASN1_SEQUENCE(X509_REVOKED) = { | ||
70 | ASN1_SIMPLE(X509_REVOKED,serialNumber, ASN1_INTEGER), | ||
71 | ASN1_SIMPLE(X509_REVOKED,revocationDate, ASN1_TIME), | ||
72 | ASN1_SEQUENCE_OF_OPT(X509_REVOKED,extensions, X509_EXTENSION) | ||
73 | } ASN1_SEQUENCE_END(X509_REVOKED) | ||
74 | |||
75 | /* The X509_CRL_INFO structure needs a bit of customisation. This is actually | ||
76 | * mirroring the old behaviour: its purpose is to allow the use of | ||
77 | * sk_X509_REVOKED_find to lookup revoked certificates. Unfortunately | ||
78 | * this will zap the original order and the signature so we keep a copy | ||
79 | * of the original positions and reorder appropriately before encoding. | ||
80 | * | ||
81 | * Might want to see if there's a better way of doing this later... | ||
82 | */ | ||
83 | static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
84 | { | ||
85 | X509_CRL_INFO *a = (X509_CRL_INFO *)*pval; | ||
86 | int i; | ||
87 | int (*old_cmp)(const X509_REVOKED * const *, | ||
88 | const X509_REVOKED * const *); | ||
89 | |||
90 | if(!a || !a->revoked) return 1; | ||
91 | switch(operation) { | ||
92 | |||
93 | /* Save original order */ | ||
94 | case ASN1_OP_D2I_POST: | ||
95 | for (i=0; i<sk_X509_REVOKED_num(a->revoked); i++) | ||
96 | sk_X509_REVOKED_value(a->revoked,i)->sequence=i; | ||
97 | sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp); | ||
98 | break; | ||
99 | |||
100 | /* Restore original order */ | ||
101 | case ASN1_OP_I2D_PRE: | ||
102 | old_cmp=sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_seq_cmp); | ||
103 | sk_X509_REVOKED_sort(a->revoked); | ||
104 | sk_X509_REVOKED_set_cmp_func(a->revoked,old_cmp); | ||
105 | break; | ||
106 | } | ||
107 | return 1; | ||
108 | } | ||
109 | |||
110 | |||
111 | ASN1_SEQUENCE_cb(X509_CRL_INFO, crl_inf_cb) = { | ||
112 | ASN1_OPT(X509_CRL_INFO, version, ASN1_INTEGER), | ||
113 | ASN1_SIMPLE(X509_CRL_INFO, sig_alg, X509_ALGOR), | ||
114 | ASN1_SIMPLE(X509_CRL_INFO, issuer, X509_NAME), | ||
115 | ASN1_SIMPLE(X509_CRL_INFO, lastUpdate, ASN1_TIME), | ||
116 | ASN1_OPT(X509_CRL_INFO, nextUpdate, ASN1_TIME), | ||
117 | ASN1_SEQUENCE_OF_OPT(X509_CRL_INFO, revoked, X509_REVOKED), | ||
118 | ASN1_EXP_SEQUENCE_OF_OPT(X509_CRL_INFO, extensions, X509_EXTENSION, 0) | ||
119 | } ASN1_SEQUENCE_END_cb(X509_CRL_INFO, X509_CRL_INFO) | ||
120 | |||
121 | ASN1_SEQUENCE_ref(X509_CRL, 0, CRYPTO_LOCK_X509_CRL) = { | ||
122 | ASN1_SIMPLE(X509_CRL, crl, X509_CRL_INFO), | ||
123 | ASN1_SIMPLE(X509_CRL, sig_alg, X509_ALGOR), | ||
124 | ASN1_SIMPLE(X509_CRL, signature, ASN1_BIT_STRING) | ||
125 | } ASN1_SEQUENCE_END_ref(X509_CRL, X509_CRL) | ||
126 | |||
127 | IMPLEMENT_ASN1_FUNCTIONS(X509_REVOKED) | ||
128 | IMPLEMENT_ASN1_FUNCTIONS(X509_CRL_INFO) | ||
129 | IMPLEMENT_ASN1_FUNCTIONS(X509_CRL) | ||
130 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_CRL) | ||
131 | |||
132 | static int X509_REVOKED_cmp(const X509_REVOKED * const *a, | ||
133 | const X509_REVOKED * const *b) | ||
134 | { | ||
135 | return(ASN1_STRING_cmp( | ||
136 | (ASN1_STRING *)(*a)->serialNumber, | ||
137 | (ASN1_STRING *)(*b)->serialNumber)); | ||
138 | } | ||
139 | |||
140 | static int X509_REVOKED_seq_cmp(const X509_REVOKED * const *a, | ||
141 | const X509_REVOKED * const *b) | ||
142 | { | ||
143 | return((*a)->sequence-(*b)->sequence); | ||
144 | } | ||
145 | |||
146 | int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev) | ||
147 | { | ||
148 | X509_CRL_INFO *inf; | ||
149 | inf = crl->crl; | ||
150 | if(!inf->revoked) | ||
151 | inf->revoked = sk_X509_REVOKED_new(X509_REVOKED_cmp); | ||
152 | if(!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev)) { | ||
153 | ASN1err(ASN1_F_X509_CRL_ADD0_REVOKED, ERR_R_MALLOC_FAILURE); | ||
154 | return 0; | ||
155 | } | ||
156 | return 1; | ||
157 | } | ||
158 | |||
159 | IMPLEMENT_STACK_OF(X509_REVOKED) | ||
160 | IMPLEMENT_ASN1_SET_OF(X509_REVOKED) | ||
161 | IMPLEMENT_STACK_OF(X509_CRL) | ||
162 | IMPLEMENT_ASN1_SET_OF(X509_CRL) | ||
diff --git a/src/lib/libcrypto/asn1/x_exten.c b/src/lib/libcrypto/asn1/x_exten.c deleted file mode 100644 index 702421b6c8..0000000000 --- a/src/lib/libcrypto/asn1/x_exten.c +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | /* x_exten.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stddef.h> | ||
60 | #include <openssl/x509.h> | ||
61 | #include <openssl/asn1.h> | ||
62 | #include <openssl/asn1t.h> | ||
63 | |||
64 | ASN1_SEQUENCE(X509_EXTENSION) = { | ||
65 | ASN1_SIMPLE(X509_EXTENSION, object, ASN1_OBJECT), | ||
66 | ASN1_OPT(X509_EXTENSION, critical, ASN1_BOOLEAN), | ||
67 | ASN1_SIMPLE(X509_EXTENSION, value, ASN1_OCTET_STRING) | ||
68 | } ASN1_SEQUENCE_END(X509_EXTENSION) | ||
69 | |||
70 | IMPLEMENT_ASN1_FUNCTIONS(X509_EXTENSION) | ||
71 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_EXTENSION) | ||
diff --git a/src/lib/libcrypto/asn1/x_info.c b/src/lib/libcrypto/asn1/x_info.c deleted file mode 100644 index d44f6cdb01..0000000000 --- a/src/lib/libcrypto/asn1/x_info.c +++ /dev/null | |||
@@ -1,114 +0,0 @@ | |||
1 | /* crypto/asn1/x_info.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/evp.h> | ||
62 | #include <openssl/asn1.h> | ||
63 | #include <openssl/x509.h> | ||
64 | |||
65 | X509_INFO *X509_INFO_new(void) | ||
66 | { | ||
67 | X509_INFO *ret=NULL; | ||
68 | |||
69 | ret=(X509_INFO *)OPENSSL_malloc(sizeof(X509_INFO)); | ||
70 | if (ret == NULL) | ||
71 | { | ||
72 | ASN1err(ASN1_F_X509_INFO_NEW,ERR_R_MALLOC_FAILURE); | ||
73 | return(NULL); | ||
74 | } | ||
75 | |||
76 | ret->enc_cipher.cipher=NULL; | ||
77 | ret->enc_len=0; | ||
78 | ret->enc_data=NULL; | ||
79 | |||
80 | ret->references=1; | ||
81 | ret->x509=NULL; | ||
82 | ret->crl=NULL; | ||
83 | ret->x_pkey=NULL; | ||
84 | return(ret); | ||
85 | } | ||
86 | |||
87 | void X509_INFO_free(X509_INFO *x) | ||
88 | { | ||
89 | int i; | ||
90 | |||
91 | if (x == NULL) return; | ||
92 | |||
93 | i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_INFO); | ||
94 | #ifdef REF_PRINT | ||
95 | REF_PRINT("X509_INFO",x); | ||
96 | #endif | ||
97 | if (i > 0) return; | ||
98 | #ifdef REF_CHECK | ||
99 | if (i < 0) | ||
100 | { | ||
101 | fprintf(stderr,"X509_INFO_free, bad reference count\n"); | ||
102 | abort(); | ||
103 | } | ||
104 | #endif | ||
105 | |||
106 | if (x->x509 != NULL) X509_free(x->x509); | ||
107 | if (x->crl != NULL) X509_CRL_free(x->crl); | ||
108 | if (x->x_pkey != NULL) X509_PKEY_free(x->x_pkey); | ||
109 | if (x->enc_data != NULL) OPENSSL_free(x->enc_data); | ||
110 | OPENSSL_free(x); | ||
111 | } | ||
112 | |||
113 | IMPLEMENT_STACK_OF(X509_INFO) | ||
114 | |||
diff --git a/src/lib/libcrypto/asn1/x_long.c b/src/lib/libcrypto/asn1/x_long.c deleted file mode 100644 index c5f25956cb..0000000000 --- a/src/lib/libcrypto/asn1/x_long.c +++ /dev/null | |||
@@ -1,169 +0,0 @@ | |||
1 | /* x_long.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1t.h> | ||
62 | |||
63 | /* Custom primitive type for long handling. This converts between an ASN1_INTEGER | ||
64 | * and a long directly. | ||
65 | */ | ||
66 | |||
67 | |||
68 | static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
69 | static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it); | ||
70 | |||
71 | static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); | ||
72 | static int long_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); | ||
73 | |||
74 | static ASN1_PRIMITIVE_FUNCS long_pf = { | ||
75 | NULL, 0, | ||
76 | long_new, | ||
77 | long_free, | ||
78 | long_free, /* Clear should set to initial value */ | ||
79 | long_c2i, | ||
80 | long_i2c | ||
81 | }; | ||
82 | |||
83 | ASN1_ITEM_start(LONG) | ||
84 | ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, ASN1_LONG_UNDEF, "LONG" | ||
85 | ASN1_ITEM_end(LONG) | ||
86 | |||
87 | ASN1_ITEM_start(ZLONG) | ||
88 | ASN1_ITYPE_PRIMITIVE, V_ASN1_INTEGER, NULL, 0, &long_pf, 0, "ZLONG" | ||
89 | ASN1_ITEM_end(ZLONG) | ||
90 | |||
91 | static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
92 | { | ||
93 | *(long *)pval = it->size; | ||
94 | return 1; | ||
95 | } | ||
96 | |||
97 | static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
98 | { | ||
99 | *(long *)pval = it->size; | ||
100 | } | ||
101 | |||
102 | static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it) | ||
103 | { | ||
104 | long ltmp; | ||
105 | unsigned long utmp; | ||
106 | int clen, pad, i; | ||
107 | /* this exists to bypass broken gcc optimization */ | ||
108 | char *cp = (char *)pval; | ||
109 | |||
110 | /* use memcpy, because we may not be long aligned */ | ||
111 | memcpy(<mp, cp, sizeof(long)); | ||
112 | |||
113 | if(ltmp == it->size) return -1; | ||
114 | /* Convert the long to positive: we subtract one if negative so | ||
115 | * we can cleanly handle the padding if only the MSB of the leading | ||
116 | * octet is set. | ||
117 | */ | ||
118 | if(ltmp < 0) utmp = -ltmp - 1; | ||
119 | else utmp = ltmp; | ||
120 | clen = BN_num_bits_word(utmp); | ||
121 | /* If MSB of leading octet set we need to pad */ | ||
122 | if(!(clen & 0x7)) pad = 1; | ||
123 | else pad = 0; | ||
124 | |||
125 | /* Convert number of bits to number of octets */ | ||
126 | clen = (clen + 7) >> 3; | ||
127 | |||
128 | if(cont) { | ||
129 | if(pad) *cont++ = (ltmp < 0) ? 0xff : 0; | ||
130 | for(i = clen - 1; i >= 0; i--) { | ||
131 | cont[i] = (unsigned char)(utmp & 0xff); | ||
132 | if(ltmp < 0) cont[i] ^= 0xff; | ||
133 | utmp >>= 8; | ||
134 | } | ||
135 | } | ||
136 | return clen + pad; | ||
137 | } | ||
138 | |||
139 | static int long_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it) | ||
140 | { | ||
141 | int neg, i; | ||
142 | long ltmp; | ||
143 | unsigned long utmp = 0; | ||
144 | char *cp = (char *)pval; | ||
145 | if(len > sizeof(long)) { | ||
146 | ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); | ||
147 | return 0; | ||
148 | } | ||
149 | /* Is it negative? */ | ||
150 | if(len && (cont[0] & 0x80)) neg = 1; | ||
151 | else neg = 0; | ||
152 | utmp = 0; | ||
153 | for(i = 0; i < len; i++) { | ||
154 | utmp <<= 8; | ||
155 | if(neg) utmp |= cont[i] ^ 0xff; | ||
156 | else utmp |= cont[i]; | ||
157 | } | ||
158 | ltmp = (long)utmp; | ||
159 | if(neg) { | ||
160 | ltmp++; | ||
161 | ltmp = -ltmp; | ||
162 | } | ||
163 | if(ltmp == it->size) { | ||
164 | ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); | ||
165 | return 0; | ||
166 | } | ||
167 | memcpy(cp, <mp, sizeof(long)); | ||
168 | return 1; | ||
169 | } | ||
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c deleted file mode 100644 index caece0f158..0000000000 --- a/src/lib/libcrypto/asn1/x_name.c +++ /dev/null | |||
@@ -1,272 +0,0 @@ | |||
1 | /* crypto/asn1/x_name.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1t.h> | ||
62 | #include <openssl/x509.h> | ||
63 | |||
64 | static int x509_name_ex_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it, | ||
65 | int tag, int aclass, char opt, ASN1_TLC *ctx); | ||
66 | |||
67 | static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); | ||
68 | static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it); | ||
69 | static void x509_name_ex_free(ASN1_VALUE **val, const ASN1_ITEM *it); | ||
70 | |||
71 | static int x509_name_encode(X509_NAME *a); | ||
72 | |||
73 | ASN1_SEQUENCE(X509_NAME_ENTRY) = { | ||
74 | ASN1_SIMPLE(X509_NAME_ENTRY, object, ASN1_OBJECT), | ||
75 | ASN1_SIMPLE(X509_NAME_ENTRY, value, ASN1_PRINTABLE) | ||
76 | } ASN1_SEQUENCE_END(X509_NAME_ENTRY) | ||
77 | |||
78 | IMPLEMENT_ASN1_FUNCTIONS(X509_NAME_ENTRY) | ||
79 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME_ENTRY) | ||
80 | |||
81 | /* For the "Name" type we need a SEQUENCE OF { SET OF X509_NAME_ENTRY } | ||
82 | * so declare two template wrappers for this | ||
83 | */ | ||
84 | |||
85 | ASN1_ITEM_TEMPLATE(X509_NAME_ENTRIES) = | ||
86 | ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SET_OF, 0, RDNS, X509_NAME_ENTRY) | ||
87 | ASN1_ITEM_TEMPLATE_END(X509_NAME_ENTRIES) | ||
88 | |||
89 | ASN1_ITEM_TEMPLATE(X509_NAME_INTERNAL) = | ||
90 | ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Name, X509_NAME_ENTRIES) | ||
91 | ASN1_ITEM_TEMPLATE_END(X509_NAME_INTERNAL) | ||
92 | |||
93 | /* Normally that's where it would end: we'd have two nested STACK structures | ||
94 | * representing the ASN1. Unfortunately X509_NAME uses a completely different | ||
95 | * form and caches encodings so we have to process the internal form and convert | ||
96 | * to the external form. | ||
97 | */ | ||
98 | |||
99 | const ASN1_EXTERN_FUNCS x509_name_ff = { | ||
100 | NULL, | ||
101 | x509_name_ex_new, | ||
102 | x509_name_ex_free, | ||
103 | 0, /* Default clear behaviour is OK */ | ||
104 | x509_name_ex_d2i, | ||
105 | x509_name_ex_i2d | ||
106 | }; | ||
107 | |||
108 | IMPLEMENT_EXTERN_ASN1(X509_NAME, V_ASN1_SEQUENCE, x509_name_ff) | ||
109 | |||
110 | IMPLEMENT_ASN1_FUNCTIONS(X509_NAME) | ||
111 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME) | ||
112 | |||
113 | static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it) | ||
114 | { | ||
115 | X509_NAME *ret = NULL; | ||
116 | ret = OPENSSL_malloc(sizeof(X509_NAME)); | ||
117 | if(!ret) goto memerr; | ||
118 | if ((ret->entries=sk_X509_NAME_ENTRY_new_null()) == NULL) | ||
119 | goto memerr; | ||
120 | if((ret->bytes = BUF_MEM_new()) == NULL) goto memerr; | ||
121 | ret->modified=1; | ||
122 | *val = (ASN1_VALUE *)ret; | ||
123 | return 1; | ||
124 | |||
125 | memerr: | ||
126 | ASN1err(ASN1_F_X509_NAME_NEW, ERR_R_MALLOC_FAILURE); | ||
127 | if (ret) | ||
128 | { | ||
129 | if (ret->entries) | ||
130 | sk_X509_NAME_ENTRY_free(ret->entries); | ||
131 | OPENSSL_free(ret); | ||
132 | } | ||
133 | return 0; | ||
134 | } | ||
135 | |||
136 | static void x509_name_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
137 | { | ||
138 | X509_NAME *a; | ||
139 | if(!pval || !*pval) | ||
140 | return; | ||
141 | a = (X509_NAME *)*pval; | ||
142 | |||
143 | BUF_MEM_free(a->bytes); | ||
144 | sk_X509_NAME_ENTRY_pop_free(a->entries,X509_NAME_ENTRY_free); | ||
145 | OPENSSL_free(a); | ||
146 | *pval = NULL; | ||
147 | } | ||
148 | |||
149 | /* Used with sk_pop_free() to free up the internal representation. | ||
150 | * NB: we only free the STACK and not its contents because it is | ||
151 | * already present in the X509_NAME structure. | ||
152 | */ | ||
153 | |||
154 | static void sk_internal_free(void *a) | ||
155 | { | ||
156 | sk_free(a); | ||
157 | } | ||
158 | |||
159 | static int x509_name_ex_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it, | ||
160 | int tag, int aclass, char opt, ASN1_TLC *ctx) | ||
161 | { | ||
162 | unsigned char *p = *in, *q; | ||
163 | STACK *intname = NULL; | ||
164 | int i, j, ret; | ||
165 | X509_NAME *nm = NULL; | ||
166 | STACK_OF(X509_NAME_ENTRY) *entries; | ||
167 | X509_NAME_ENTRY *entry; | ||
168 | q = p; | ||
169 | |||
170 | /* Get internal representation of Name */ | ||
171 | ret = ASN1_item_ex_d2i((ASN1_VALUE **)&intname, &p, len, ASN1_ITEM_rptr(X509_NAME_INTERNAL), | ||
172 | tag, aclass, opt, ctx); | ||
173 | |||
174 | if(ret <= 0) return ret; | ||
175 | |||
176 | if(*val) x509_name_ex_free(val, NULL); | ||
177 | if(!x509_name_ex_new((ASN1_VALUE **)&nm, NULL)) goto err; | ||
178 | /* We've decoded it: now cache encoding */ | ||
179 | if(!BUF_MEM_grow(nm->bytes, p - q)) goto err; | ||
180 | memcpy(nm->bytes->data, q, p - q); | ||
181 | |||
182 | /* Convert internal representation to X509_NAME structure */ | ||
183 | for(i = 0; i < sk_num(intname); i++) { | ||
184 | entries = (STACK_OF(X509_NAME_ENTRY) *)sk_value(intname, i); | ||
185 | for(j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) { | ||
186 | entry = sk_X509_NAME_ENTRY_value(entries, j); | ||
187 | entry->set = i; | ||
188 | if(!sk_X509_NAME_ENTRY_push(nm->entries, entry)) | ||
189 | goto err; | ||
190 | } | ||
191 | sk_X509_NAME_ENTRY_free(entries); | ||
192 | } | ||
193 | sk_free(intname); | ||
194 | nm->modified = 0; | ||
195 | *val = (ASN1_VALUE *)nm; | ||
196 | *in = p; | ||
197 | return ret; | ||
198 | err: | ||
199 | ASN1err(ASN1_F_D2I_X509_NAME, ERR_R_NESTED_ASN1_ERROR); | ||
200 | return 0; | ||
201 | } | ||
202 | |||
203 | static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass) | ||
204 | { | ||
205 | int ret; | ||
206 | X509_NAME *a = (X509_NAME *)*val; | ||
207 | if(a->modified) { | ||
208 | ret = x509_name_encode((X509_NAME *)a); | ||
209 | if(ret < 0) return ret; | ||
210 | } | ||
211 | ret = a->bytes->length; | ||
212 | if(out != NULL) { | ||
213 | memcpy(*out,a->bytes->data,ret); | ||
214 | *out+=ret; | ||
215 | } | ||
216 | return ret; | ||
217 | } | ||
218 | |||
219 | static int x509_name_encode(X509_NAME *a) | ||
220 | { | ||
221 | STACK *intname = NULL; | ||
222 | int len; | ||
223 | unsigned char *p; | ||
224 | STACK_OF(X509_NAME_ENTRY) *entries = NULL; | ||
225 | X509_NAME_ENTRY *entry; | ||
226 | int i, set = -1; | ||
227 | intname = sk_new_null(); | ||
228 | if(!intname) goto memerr; | ||
229 | for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) { | ||
230 | entry = sk_X509_NAME_ENTRY_value(a->entries, i); | ||
231 | if(entry->set != set) { | ||
232 | entries = sk_X509_NAME_ENTRY_new_null(); | ||
233 | if(!entries) goto memerr; | ||
234 | if(!sk_push(intname, (char *)entries)) goto memerr; | ||
235 | set = entry->set; | ||
236 | } | ||
237 | if(!sk_X509_NAME_ENTRY_push(entries, entry)) goto memerr; | ||
238 | } | ||
239 | len = ASN1_item_ex_i2d((ASN1_VALUE **)&intname, NULL, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); | ||
240 | if (!BUF_MEM_grow(a->bytes,len)) goto memerr; | ||
241 | p=(unsigned char *)a->bytes->data; | ||
242 | ASN1_item_ex_i2d((ASN1_VALUE **)&intname, &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); | ||
243 | sk_pop_free(intname, sk_internal_free); | ||
244 | a->modified = 0; | ||
245 | return len; | ||
246 | memerr: | ||
247 | sk_pop_free(intname, sk_internal_free); | ||
248 | ASN1err(ASN1_F_D2I_X509_NAME, ERR_R_MALLOC_FAILURE); | ||
249 | return -1; | ||
250 | } | ||
251 | |||
252 | |||
253 | int X509_NAME_set(X509_NAME **xn, X509_NAME *name) | ||
254 | { | ||
255 | X509_NAME *in; | ||
256 | |||
257 | if (!xn || !name) return(0); | ||
258 | |||
259 | if (*xn != name) | ||
260 | { | ||
261 | in=X509_NAME_dup(name); | ||
262 | if (in != NULL) | ||
263 | { | ||
264 | X509_NAME_free(*xn); | ||
265 | *xn=in; | ||
266 | } | ||
267 | } | ||
268 | return(*xn != NULL); | ||
269 | } | ||
270 | |||
271 | IMPLEMENT_STACK_OF(X509_NAME_ENTRY) | ||
272 | IMPLEMENT_ASN1_SET_OF(X509_NAME_ENTRY) | ||
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c deleted file mode 100644 index f1c6221ac3..0000000000 --- a/src/lib/libcrypto/asn1/x_pkey.c +++ /dev/null | |||
@@ -1,151 +0,0 @@ | |||
1 | /* crypto/asn1/x_pkey.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/evp.h> | ||
62 | #include <openssl/objects.h> | ||
63 | #include <openssl/asn1_mac.h> | ||
64 | #include <openssl/x509.h> | ||
65 | |||
66 | /* need to implement */ | ||
67 | int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp) | ||
68 | { | ||
69 | return(0); | ||
70 | } | ||
71 | |||
72 | X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, unsigned char **pp, long length) | ||
73 | { | ||
74 | int i; | ||
75 | M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new); | ||
76 | |||
77 | M_ASN1_D2I_Init(); | ||
78 | M_ASN1_D2I_start_sequence(); | ||
79 | M_ASN1_D2I_get(ret->enc_algor,d2i_X509_ALGOR); | ||
80 | M_ASN1_D2I_get(ret->enc_pkey,d2i_ASN1_OCTET_STRING); | ||
81 | |||
82 | ret->cipher.cipher=EVP_get_cipherbyname( | ||
83 | OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm))); | ||
84 | if (ret->cipher.cipher == NULL) | ||
85 | { | ||
86 | c.error=ASN1_R_UNSUPPORTED_CIPHER; | ||
87 | c.line=__LINE__; | ||
88 | goto err; | ||
89 | } | ||
90 | if (ret->enc_algor->parameter->type == V_ASN1_OCTET_STRING) | ||
91 | { | ||
92 | i=ret->enc_algor->parameter->value.octet_string->length; | ||
93 | if (i > EVP_MAX_IV_LENGTH) | ||
94 | { | ||
95 | c.error=ASN1_R_IV_TOO_LARGE; | ||
96 | c.line=__LINE__; | ||
97 | goto err; | ||
98 | } | ||
99 | memcpy(ret->cipher.iv, | ||
100 | ret->enc_algor->parameter->value.octet_string->data,i); | ||
101 | } | ||
102 | else | ||
103 | memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH); | ||
104 | M_ASN1_D2I_Finish(a,X509_PKEY_free,ASN1_F_D2I_X509_PKEY); | ||
105 | } | ||
106 | |||
107 | X509_PKEY *X509_PKEY_new(void) | ||
108 | { | ||
109 | X509_PKEY *ret=NULL; | ||
110 | ASN1_CTX c; | ||
111 | |||
112 | M_ASN1_New_Malloc(ret,X509_PKEY); | ||
113 | ret->version=0; | ||
114 | M_ASN1_New(ret->enc_algor,X509_ALGOR_new); | ||
115 | M_ASN1_New(ret->enc_pkey,M_ASN1_OCTET_STRING_new); | ||
116 | ret->dec_pkey=NULL; | ||
117 | ret->key_length=0; | ||
118 | ret->key_data=NULL; | ||
119 | ret->key_free=0; | ||
120 | ret->cipher.cipher=NULL; | ||
121 | memset(ret->cipher.iv,0,EVP_MAX_IV_LENGTH); | ||
122 | ret->references=1; | ||
123 | return(ret); | ||
124 | M_ASN1_New_Error(ASN1_F_X509_PKEY_NEW); | ||
125 | } | ||
126 | |||
127 | void X509_PKEY_free(X509_PKEY *x) | ||
128 | { | ||
129 | int i; | ||
130 | |||
131 | if (x == NULL) return; | ||
132 | |||
133 | i=CRYPTO_add(&x->references,-1,CRYPTO_LOCK_X509_PKEY); | ||
134 | #ifdef REF_PRINT | ||
135 | REF_PRINT("X509_PKEY",x); | ||
136 | #endif | ||
137 | if (i > 0) return; | ||
138 | #ifdef REF_CHECK | ||
139 | if (i < 0) | ||
140 | { | ||
141 | fprintf(stderr,"X509_PKEY_free, bad reference count\n"); | ||
142 | abort(); | ||
143 | } | ||
144 | #endif | ||
145 | |||
146 | if (x->enc_algor != NULL) X509_ALGOR_free(x->enc_algor); | ||
147 | if (x->enc_pkey != NULL) M_ASN1_OCTET_STRING_free(x->enc_pkey); | ||
148 | if (x->dec_pkey != NULL)EVP_PKEY_free(x->dec_pkey); | ||
149 | if ((x->key_data != NULL) && (x->key_free)) OPENSSL_free(x->key_data); | ||
150 | OPENSSL_free(x); | ||
151 | } | ||
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c deleted file mode 100644 index d958540120..0000000000 --- a/src/lib/libcrypto/asn1/x_pubkey.c +++ /dev/null | |||
@@ -1,334 +0,0 @@ | |||
1 | /* crypto/asn1/x_pubkey.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1t.h> | ||
62 | #include <openssl/x509.h> | ||
63 | |||
64 | /* Minor tweak to operation: free up EVP_PKEY */ | ||
65 | static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
66 | { | ||
67 | if(operation == ASN1_OP_FREE_POST) { | ||
68 | X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval; | ||
69 | EVP_PKEY_free(pubkey->pkey); | ||
70 | } | ||
71 | return 1; | ||
72 | } | ||
73 | |||
74 | ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = { | ||
75 | ASN1_SIMPLE(X509_PUBKEY, algor, X509_ALGOR), | ||
76 | ASN1_SIMPLE(X509_PUBKEY, public_key, ASN1_BIT_STRING) | ||
77 | } ASN1_SEQUENCE_END_cb(X509_PUBKEY, X509_PUBKEY) | ||
78 | |||
79 | IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY) | ||
80 | |||
81 | int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) | ||
82 | { | ||
83 | int ok=0; | ||
84 | X509_PUBKEY *pk; | ||
85 | X509_ALGOR *a; | ||
86 | ASN1_OBJECT *o; | ||
87 | unsigned char *s,*p = NULL; | ||
88 | int i; | ||
89 | |||
90 | if (x == NULL) return(0); | ||
91 | |||
92 | if ((pk=X509_PUBKEY_new()) == NULL) goto err; | ||
93 | a=pk->algor; | ||
94 | |||
95 | /* set the algorithm id */ | ||
96 | if ((o=OBJ_nid2obj(pkey->type)) == NULL) goto err; | ||
97 | ASN1_OBJECT_free(a->algorithm); | ||
98 | a->algorithm=o; | ||
99 | |||
100 | /* Set the parameter list */ | ||
101 | if (!pkey->save_parameters || (pkey->type == EVP_PKEY_RSA)) | ||
102 | { | ||
103 | if ((a->parameter == NULL) || | ||
104 | (a->parameter->type != V_ASN1_NULL)) | ||
105 | { | ||
106 | ASN1_TYPE_free(a->parameter); | ||
107 | a->parameter=ASN1_TYPE_new(); | ||
108 | a->parameter->type=V_ASN1_NULL; | ||
109 | } | ||
110 | } | ||
111 | else | ||
112 | #ifndef OPENSSL_NO_DSA | ||
113 | if (pkey->type == EVP_PKEY_DSA) | ||
114 | { | ||
115 | unsigned char *pp; | ||
116 | DSA *dsa; | ||
117 | |||
118 | dsa=pkey->pkey.dsa; | ||
119 | dsa->write_params=0; | ||
120 | ASN1_TYPE_free(a->parameter); | ||
121 | i=i2d_DSAparams(dsa,NULL); | ||
122 | if ((p=(unsigned char *)OPENSSL_malloc(i)) == NULL) goto err; | ||
123 | pp=p; | ||
124 | i2d_DSAparams(dsa,&pp); | ||
125 | a->parameter=ASN1_TYPE_new(); | ||
126 | a->parameter->type=V_ASN1_SEQUENCE; | ||
127 | a->parameter->value.sequence=ASN1_STRING_new(); | ||
128 | ASN1_STRING_set(a->parameter->value.sequence,p,i); | ||
129 | OPENSSL_free(p); | ||
130 | } | ||
131 | else | ||
132 | #endif | ||
133 | { | ||
134 | X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM); | ||
135 | goto err; | ||
136 | } | ||
137 | |||
138 | if ((i=i2d_PublicKey(pkey,NULL)) <= 0) goto err; | ||
139 | if ((s=(unsigned char *)OPENSSL_malloc(i+1)) == NULL) | ||
140 | { | ||
141 | X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE); | ||
142 | goto err; | ||
143 | } | ||
144 | p=s; | ||
145 | i2d_PublicKey(pkey,&p); | ||
146 | if (!M_ASN1_BIT_STRING_set(pk->public_key,s,i)) goto err; | ||
147 | /* Set number of unused bits to zero */ | ||
148 | pk->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); | ||
149 | pk->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT; | ||
150 | |||
151 | OPENSSL_free(s); | ||
152 | |||
153 | #if 0 | ||
154 | CRYPTO_add(&pkey->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
155 | pk->pkey=pkey; | ||
156 | #endif | ||
157 | |||
158 | if (*x != NULL) | ||
159 | X509_PUBKEY_free(*x); | ||
160 | |||
161 | *x=pk; | ||
162 | pk=NULL; | ||
163 | |||
164 | ok=1; | ||
165 | err: | ||
166 | if (pk != NULL) X509_PUBKEY_free(pk); | ||
167 | return(ok); | ||
168 | } | ||
169 | |||
170 | EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key) | ||
171 | { | ||
172 | EVP_PKEY *ret=NULL; | ||
173 | long j; | ||
174 | int type; | ||
175 | unsigned char *p; | ||
176 | #ifndef OPENSSL_NO_DSA | ||
177 | const unsigned char *cp; | ||
178 | X509_ALGOR *a; | ||
179 | #endif | ||
180 | |||
181 | if (key == NULL) goto err; | ||
182 | |||
183 | if (key->pkey != NULL) | ||
184 | { | ||
185 | CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
186 | return(key->pkey); | ||
187 | } | ||
188 | |||
189 | if (key->public_key == NULL) goto err; | ||
190 | |||
191 | type=OBJ_obj2nid(key->algor->algorithm); | ||
192 | p=key->public_key->data; | ||
193 | j=key->public_key->length; | ||
194 | if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL) | ||
195 | { | ||
196 | X509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB); | ||
197 | goto err; | ||
198 | } | ||
199 | ret->save_parameters=0; | ||
200 | |||
201 | #ifndef OPENSSL_NO_DSA | ||
202 | a=key->algor; | ||
203 | if (ret->type == EVP_PKEY_DSA) | ||
204 | { | ||
205 | if (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE)) | ||
206 | { | ||
207 | ret->pkey.dsa->write_params=0; | ||
208 | cp=p=a->parameter->value.sequence->data; | ||
209 | j=a->parameter->value.sequence->length; | ||
210 | if (!d2i_DSAparams(&ret->pkey.dsa,&cp,(long)j)) | ||
211 | goto err; | ||
212 | } | ||
213 | ret->save_parameters=1; | ||
214 | } | ||
215 | #endif | ||
216 | key->pkey=ret; | ||
217 | CRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY); | ||
218 | return(ret); | ||
219 | err: | ||
220 | if (ret != NULL) | ||
221 | EVP_PKEY_free(ret); | ||
222 | return(NULL); | ||
223 | } | ||
224 | |||
225 | /* Now two pseudo ASN1 routines that take an EVP_PKEY structure | ||
226 | * and encode or decode as X509_PUBKEY | ||
227 | */ | ||
228 | |||
229 | EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, unsigned char **pp, | ||
230 | long length) | ||
231 | { | ||
232 | X509_PUBKEY *xpk; | ||
233 | EVP_PKEY *pktmp; | ||
234 | xpk = d2i_X509_PUBKEY(NULL, pp, length); | ||
235 | if(!xpk) return NULL; | ||
236 | pktmp = X509_PUBKEY_get(xpk); | ||
237 | X509_PUBKEY_free(xpk); | ||
238 | if(!pktmp) return NULL; | ||
239 | if(a) { | ||
240 | EVP_PKEY_free(*a); | ||
241 | *a = pktmp; | ||
242 | } | ||
243 | return pktmp; | ||
244 | } | ||
245 | |||
246 | int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp) | ||
247 | { | ||
248 | X509_PUBKEY *xpk=NULL; | ||
249 | int ret; | ||
250 | if(!a) return 0; | ||
251 | if(!X509_PUBKEY_set(&xpk, a)) return 0; | ||
252 | ret = i2d_X509_PUBKEY(xpk, pp); | ||
253 | X509_PUBKEY_free(xpk); | ||
254 | return ret; | ||
255 | } | ||
256 | |||
257 | /* The following are equivalents but which return RSA and DSA | ||
258 | * keys | ||
259 | */ | ||
260 | #ifndef OPENSSL_NO_RSA | ||
261 | RSA *d2i_RSA_PUBKEY(RSA **a, unsigned char **pp, | ||
262 | long length) | ||
263 | { | ||
264 | EVP_PKEY *pkey; | ||
265 | RSA *key; | ||
266 | unsigned char *q; | ||
267 | q = *pp; | ||
268 | pkey = d2i_PUBKEY(NULL, &q, length); | ||
269 | if(!pkey) return NULL; | ||
270 | key = EVP_PKEY_get1_RSA(pkey); | ||
271 | EVP_PKEY_free(pkey); | ||
272 | if(!key) return NULL; | ||
273 | *pp = q; | ||
274 | if(a) { | ||
275 | RSA_free(*a); | ||
276 | *a = key; | ||
277 | } | ||
278 | return key; | ||
279 | } | ||
280 | |||
281 | int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp) | ||
282 | { | ||
283 | EVP_PKEY *pktmp; | ||
284 | int ret; | ||
285 | if(!a) return 0; | ||
286 | pktmp = EVP_PKEY_new(); | ||
287 | if(!pktmp) { | ||
288 | ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE); | ||
289 | return 0; | ||
290 | } | ||
291 | EVP_PKEY_set1_RSA(pktmp, a); | ||
292 | ret = i2d_PUBKEY(pktmp, pp); | ||
293 | EVP_PKEY_free(pktmp); | ||
294 | return ret; | ||
295 | } | ||
296 | #endif | ||
297 | |||
298 | #ifndef OPENSSL_NO_DSA | ||
299 | DSA *d2i_DSA_PUBKEY(DSA **a, unsigned char **pp, | ||
300 | long length) | ||
301 | { | ||
302 | EVP_PKEY *pkey; | ||
303 | DSA *key; | ||
304 | unsigned char *q; | ||
305 | q = *pp; | ||
306 | pkey = d2i_PUBKEY(NULL, &q, length); | ||
307 | if(!pkey) return NULL; | ||
308 | key = EVP_PKEY_get1_DSA(pkey); | ||
309 | EVP_PKEY_free(pkey); | ||
310 | if(!key) return NULL; | ||
311 | *pp = q; | ||
312 | if(a) { | ||
313 | DSA_free(*a); | ||
314 | *a = key; | ||
315 | } | ||
316 | return key; | ||
317 | } | ||
318 | |||
319 | int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp) | ||
320 | { | ||
321 | EVP_PKEY *pktmp; | ||
322 | int ret; | ||
323 | if(!a) return 0; | ||
324 | pktmp = EVP_PKEY_new(); | ||
325 | if(!pktmp) { | ||
326 | ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE); | ||
327 | return 0; | ||
328 | } | ||
329 | EVP_PKEY_set1_DSA(pktmp, a); | ||
330 | ret = i2d_PUBKEY(pktmp, pp); | ||
331 | EVP_PKEY_free(pktmp); | ||
332 | return ret; | ||
333 | } | ||
334 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/x_req.c b/src/lib/libcrypto/asn1/x_req.c deleted file mode 100644 index b3f18ebc12..0000000000 --- a/src/lib/libcrypto/asn1/x_req.c +++ /dev/null | |||
@@ -1,112 +0,0 @@ | |||
1 | /* crypto/asn1/x_req.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1t.h> | ||
62 | #include <openssl/x509.h> | ||
63 | |||
64 | /* X509_REQ_INFO is handled in an unusual way to get round | ||
65 | * invalid encodings. Some broken certificate requests don't | ||
66 | * encode the attributes field if it is empty. This is in | ||
67 | * violation of PKCS#10 but we need to tolerate it. We do | ||
68 | * this by making the attributes field OPTIONAL then using | ||
69 | * the callback to initialise it to an empty STACK. | ||
70 | * | ||
71 | * This means that the field will be correctly encoded unless | ||
72 | * we NULL out the field. | ||
73 | * | ||
74 | * As a result we no longer need the req_kludge field because | ||
75 | * the information is now contained in the attributes field: | ||
76 | * 1. If it is NULL then it's the invalid omission. | ||
77 | * 2. If it is empty it is the correct encoding. | ||
78 | * 3. If it is not empty then some attributes are present. | ||
79 | * | ||
80 | */ | ||
81 | |||
82 | static int rinf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
83 | { | ||
84 | X509_REQ_INFO *rinf = (X509_REQ_INFO *)*pval; | ||
85 | |||
86 | if(operation == ASN1_OP_NEW_POST) { | ||
87 | rinf->attributes = sk_X509_ATTRIBUTE_new_null(); | ||
88 | if(!rinf->attributes) return 0; | ||
89 | } | ||
90 | return 1; | ||
91 | } | ||
92 | |||
93 | ASN1_SEQUENCE_enc(X509_REQ_INFO, enc, rinf_cb) = { | ||
94 | ASN1_SIMPLE(X509_REQ_INFO, version, ASN1_INTEGER), | ||
95 | ASN1_SIMPLE(X509_REQ_INFO, subject, X509_NAME), | ||
96 | ASN1_SIMPLE(X509_REQ_INFO, pubkey, X509_PUBKEY), | ||
97 | /* This isn't really OPTIONAL but it gets round invalid | ||
98 | * encodings | ||
99 | */ | ||
100 | ASN1_IMP_SET_OF_OPT(X509_REQ_INFO, attributes, X509_ATTRIBUTE, 0) | ||
101 | } ASN1_SEQUENCE_END_enc(X509_REQ_INFO, X509_REQ_INFO) | ||
102 | |||
103 | IMPLEMENT_ASN1_FUNCTIONS(X509_REQ_INFO) | ||
104 | |||
105 | ASN1_SEQUENCE_ref(X509_REQ, 0, CRYPTO_LOCK_X509_INFO) = { | ||
106 | ASN1_SIMPLE(X509_REQ, req_info, X509_REQ_INFO), | ||
107 | ASN1_SIMPLE(X509_REQ, sig_alg, X509_ALGOR), | ||
108 | ASN1_SIMPLE(X509_REQ, signature, ASN1_BIT_STRING) | ||
109 | } ASN1_SEQUENCE_END_ref(X509_REQ, X509_REQ) | ||
110 | |||
111 | IMPLEMENT_ASN1_FUNCTIONS(X509_REQ) | ||
112 | IMPLEMENT_ASN1_DUP_FUNCTION(X509_REQ) | ||
diff --git a/src/lib/libcrypto/asn1/x_sig.c b/src/lib/libcrypto/asn1/x_sig.c deleted file mode 100644 index 42efa86c1c..0000000000 --- a/src/lib/libcrypto/asn1/x_sig.c +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | /* crypto/asn1/x_sig.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1t.h> | ||
62 | #include <openssl/x509.h> | ||
63 | |||
64 | ASN1_SEQUENCE(X509_SIG) = { | ||
65 | ASN1_SIMPLE(X509_SIG, algor, X509_ALGOR), | ||
66 | ASN1_SIMPLE(X509_SIG, digest, ASN1_OCTET_STRING) | ||
67 | } ASN1_SEQUENCE_END(X509_SIG) | ||
68 | |||
69 | IMPLEMENT_ASN1_FUNCTIONS(X509_SIG) | ||
diff --git a/src/lib/libcrypto/asn1/x_spki.c b/src/lib/libcrypto/asn1/x_spki.c deleted file mode 100644 index 2aece077c5..0000000000 --- a/src/lib/libcrypto/asn1/x_spki.c +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | /* crypto/asn1/x_spki.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | /* This module was send to me my Pat Richards <patr@x509.com> who | ||
60 | * wrote it. It is under my Copyright with his permission | ||
61 | */ | ||
62 | |||
63 | #include <stdio.h> | ||
64 | #include "cryptlib.h" | ||
65 | #include <openssl/x509.h> | ||
66 | #include <openssl/asn1t.h> | ||
67 | |||
68 | ASN1_SEQUENCE(NETSCAPE_SPKAC) = { | ||
69 | ASN1_SIMPLE(NETSCAPE_SPKAC, pubkey, X509_PUBKEY), | ||
70 | ASN1_SIMPLE(NETSCAPE_SPKAC, challenge, ASN1_IA5STRING) | ||
71 | } ASN1_SEQUENCE_END(NETSCAPE_SPKAC) | ||
72 | |||
73 | IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_SPKAC) | ||
74 | |||
75 | ASN1_SEQUENCE(NETSCAPE_SPKI) = { | ||
76 | ASN1_SIMPLE(NETSCAPE_SPKI, spkac, NETSCAPE_SPKAC), | ||
77 | ASN1_SIMPLE(NETSCAPE_SPKI, sig_algor, X509_ALGOR), | ||
78 | ASN1_SIMPLE(NETSCAPE_SPKI, signature, ASN1_BIT_STRING) | ||
79 | } ASN1_SEQUENCE_END(NETSCAPE_SPKI) | ||
80 | |||
81 | IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_SPKI) | ||
diff --git a/src/lib/libcrypto/asn1/x_val.c b/src/lib/libcrypto/asn1/x_val.c deleted file mode 100644 index dc17c67758..0000000000 --- a/src/lib/libcrypto/asn1/x_val.c +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | /* crypto/asn1/x_val.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/asn1t.h> | ||
62 | #include <openssl/x509.h> | ||
63 | |||
64 | ASN1_SEQUENCE(X509_VAL) = { | ||
65 | ASN1_SIMPLE(X509_VAL, notBefore, ASN1_TIME), | ||
66 | ASN1_SIMPLE(X509_VAL, notAfter, ASN1_TIME) | ||
67 | } ASN1_SEQUENCE_END(X509_VAL) | ||
68 | |||
69 | IMPLEMENT_ASN1_FUNCTIONS(X509_VAL) | ||
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c deleted file mode 100644 index b50167ce43..0000000000 --- a/src/lib/libcrypto/asn1/x_x509.c +++ /dev/null | |||
@@ -1,189 +0,0 @@ | |||
1 | /* crypto/asn1/x_x509.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/evp.h> | ||
62 | #include <openssl/asn1t.h> | ||
63 | #include <openssl/x509.h> | ||
64 | #include <openssl/x509v3.h> | ||
65 | |||
66 | ASN1_SEQUENCE(X509_CINF) = { | ||
67 | ASN1_EXP_OPT(X509_CINF, version, ASN1_INTEGER, 0), | ||
68 | ASN1_SIMPLE(X509_CINF, serialNumber, ASN1_INTEGER), | ||
69 | ASN1_SIMPLE(X509_CINF, signature, X509_ALGOR), | ||
70 | ASN1_SIMPLE(X509_CINF, issuer, X509_NAME), | ||
71 | ASN1_SIMPLE(X509_CINF, validity, X509_VAL), | ||
72 | ASN1_SIMPLE(X509_CINF, subject, X509_NAME), | ||
73 | ASN1_SIMPLE(X509_CINF, key, X509_PUBKEY), | ||
74 | ASN1_IMP_OPT(X509_CINF, issuerUID, ASN1_BIT_STRING, 1), | ||
75 | ASN1_IMP_OPT(X509_CINF, subjectUID, ASN1_BIT_STRING, 2), | ||
76 | ASN1_EXP_SEQUENCE_OF_OPT(X509_CINF, extensions, X509_EXTENSION, 3) | ||
77 | } ASN1_SEQUENCE_END(X509_CINF) | ||
78 | |||
79 | IMPLEMENT_ASN1_FUNCTIONS(X509_CINF) | ||
80 | /* X509 top level structure needs a bit of customisation */ | ||
81 | |||
82 | static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | ||
83 | { | ||
84 | X509 *ret = (X509 *)*pval; | ||
85 | |||
86 | switch(operation) { | ||
87 | |||
88 | case ASN1_OP_NEW_POST: | ||
89 | ret->valid=0; | ||
90 | ret->name = NULL; | ||
91 | ret->ex_flags = 0; | ||
92 | ret->ex_pathlen = -1; | ||
93 | ret->skid = NULL; | ||
94 | ret->akid = NULL; | ||
95 | ret->aux = NULL; | ||
96 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); | ||
97 | break; | ||
98 | |||
99 | case ASN1_OP_D2I_POST: | ||
100 | if (ret->name != NULL) OPENSSL_free(ret->name); | ||
101 | ret->name=X509_NAME_oneline(ret->cert_info->subject,NULL,0); | ||
102 | break; | ||
103 | |||
104 | case ASN1_OP_FREE_POST: | ||
105 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); | ||
106 | X509_CERT_AUX_free(ret->aux); | ||
107 | ASN1_OCTET_STRING_free(ret->skid); | ||
108 | AUTHORITY_KEYID_free(ret->akid); | ||
109 | |||
110 | if (ret->name != NULL) OPENSSL_free(ret->name); | ||
111 | break; | ||
112 | |||
113 | } | ||
114 | |||
115 | return 1; | ||
116 | |||
117 | } | ||
118 | |||
119 | ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = { | ||
120 | ASN1_SIMPLE(X509, cert_info, X509_CINF), | ||
121 | ASN1_SIMPLE(X509, sig_alg, X509_ALGOR), | ||
122 | ASN1_SIMPLE(X509, signature, ASN1_BIT_STRING) | ||
123 | } ASN1_SEQUENCE_END_ref(X509, X509) | ||
124 | |||
125 | IMPLEMENT_ASN1_FUNCTIONS(X509) | ||
126 | IMPLEMENT_ASN1_DUP_FUNCTION(X509) | ||
127 | |||
128 | static ASN1_METHOD meth={ | ||
129 | (int (*)()) i2d_X509, | ||
130 | (char *(*)())d2i_X509, | ||
131 | (char *(*)())X509_new, | ||
132 | (void (*)()) X509_free}; | ||
133 | |||
134 | ASN1_METHOD *X509_asn1_meth(void) | ||
135 | { | ||
136 | return(&meth); | ||
137 | } | ||
138 | |||
139 | int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
140 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
141 | { | ||
142 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_X509, argl, argp, | ||
143 | new_func, dup_func, free_func); | ||
144 | } | ||
145 | |||
146 | int X509_set_ex_data(X509 *r, int idx, void *arg) | ||
147 | { | ||
148 | return(CRYPTO_set_ex_data(&r->ex_data,idx,arg)); | ||
149 | } | ||
150 | |||
151 | void *X509_get_ex_data(X509 *r, int idx) | ||
152 | { | ||
153 | return(CRYPTO_get_ex_data(&r->ex_data,idx)); | ||
154 | } | ||
155 | |||
156 | /* X509_AUX ASN1 routines. X509_AUX is the name given to | ||
157 | * a certificate with extra info tagged on the end. Since these | ||
158 | * functions set how a certificate is trusted they should only | ||
159 | * be used when the certificate comes from a reliable source | ||
160 | * such as local storage. | ||
161 | * | ||
162 | */ | ||
163 | |||
164 | X509 *d2i_X509_AUX(X509 **a, unsigned char **pp, long length) | ||
165 | { | ||
166 | unsigned char *q; | ||
167 | X509 *ret; | ||
168 | /* Save start position */ | ||
169 | q = *pp; | ||
170 | ret = d2i_X509(a, pp, length); | ||
171 | /* If certificate unreadable then forget it */ | ||
172 | if(!ret) return NULL; | ||
173 | /* update length */ | ||
174 | length -= *pp - q; | ||
175 | if(!length) return ret; | ||
176 | if(!d2i_X509_CERT_AUX(&ret->aux, pp, length)) goto err; | ||
177 | return ret; | ||
178 | err: | ||
179 | X509_free(ret); | ||
180 | return NULL; | ||
181 | } | ||
182 | |||
183 | int i2d_X509_AUX(X509 *a, unsigned char **pp) | ||
184 | { | ||
185 | int length; | ||
186 | length = i2d_X509(a, pp); | ||
187 | if(a) length += i2d_X509_CERT_AUX(a->aux, pp); | ||
188 | return length; | ||
189 | } | ||
diff --git a/src/lib/libcrypto/asn1/x_x509a.c b/src/lib/libcrypto/asn1/x_x509a.c deleted file mode 100644 index f244768b7e..0000000000 --- a/src/lib/libcrypto/asn1/x_x509a.c +++ /dev/null | |||
@@ -1,151 +0,0 @@ | |||
1 | /* a_x509a.c */ | ||
2 | /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL | ||
3 | * project 1999. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <stdio.h> | ||
60 | #include "cryptlib.h" | ||
61 | #include <openssl/evp.h> | ||
62 | #include <openssl/asn1t.h> | ||
63 | #include <openssl/x509.h> | ||
64 | |||
65 | /* X509_CERT_AUX routines. These are used to encode additional | ||
66 | * user modifiable data about a certificate. This data is | ||
67 | * appended to the X509 encoding when the *_X509_AUX routines | ||
68 | * are used. This means that the "traditional" X509 routines | ||
69 | * will simply ignore the extra data. | ||
70 | */ | ||
71 | |||
72 | static X509_CERT_AUX *aux_get(X509 *x); | ||
73 | |||
74 | ASN1_SEQUENCE(X509_CERT_AUX) = { | ||
75 | ASN1_SEQUENCE_OF_OPT(X509_CERT_AUX, trust, ASN1_OBJECT), | ||
76 | ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, reject, ASN1_OBJECT, 0), | ||
77 | ASN1_OPT(X509_CERT_AUX, alias, ASN1_UTF8STRING), | ||
78 | ASN1_OPT(X509_CERT_AUX, keyid, ASN1_OCTET_STRING), | ||
79 | ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, other, X509_ALGOR, 1) | ||
80 | } ASN1_SEQUENCE_END(X509_CERT_AUX) | ||
81 | |||
82 | IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_AUX) | ||
83 | |||
84 | static X509_CERT_AUX *aux_get(X509 *x) | ||
85 | { | ||
86 | if(!x) return NULL; | ||
87 | if(!x->aux && !(x->aux = X509_CERT_AUX_new())) return NULL; | ||
88 | return x->aux; | ||
89 | } | ||
90 | |||
91 | int X509_alias_set1(X509 *x, unsigned char *name, int len) | ||
92 | { | ||
93 | X509_CERT_AUX *aux; | ||
94 | if(!(aux = aux_get(x))) return 0; | ||
95 | if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0; | ||
96 | return ASN1_STRING_set(aux->alias, name, len); | ||
97 | } | ||
98 | |||
99 | int X509_keyid_set1(X509 *x, unsigned char *id, int len) | ||
100 | { | ||
101 | X509_CERT_AUX *aux; | ||
102 | if(!(aux = aux_get(x))) return 0; | ||
103 | if(!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) return 0; | ||
104 | return ASN1_STRING_set(aux->keyid, id, len); | ||
105 | } | ||
106 | |||
107 | unsigned char *X509_alias_get0(X509 *x, int *len) | ||
108 | { | ||
109 | if(!x->aux || !x->aux->alias) return NULL; | ||
110 | if(len) *len = x->aux->alias->length; | ||
111 | return x->aux->alias->data; | ||
112 | } | ||
113 | |||
114 | int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj) | ||
115 | { | ||
116 | X509_CERT_AUX *aux; | ||
117 | ASN1_OBJECT *objtmp; | ||
118 | if(!(objtmp = OBJ_dup(obj))) return 0; | ||
119 | if(!(aux = aux_get(x))) return 0; | ||
120 | if(!aux->trust | ||
121 | && !(aux->trust = sk_ASN1_OBJECT_new_null())) return 0; | ||
122 | return sk_ASN1_OBJECT_push(aux->trust, objtmp); | ||
123 | } | ||
124 | |||
125 | int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj) | ||
126 | { | ||
127 | X509_CERT_AUX *aux; | ||
128 | ASN1_OBJECT *objtmp; | ||
129 | if(!(objtmp = OBJ_dup(obj))) return 0; | ||
130 | if(!(aux = aux_get(x))) return 0; | ||
131 | if(!aux->reject | ||
132 | && !(aux->reject = sk_ASN1_OBJECT_new_null())) return 0; | ||
133 | return sk_ASN1_OBJECT_push(aux->reject, objtmp); | ||
134 | } | ||
135 | |||
136 | void X509_trust_clear(X509 *x) | ||
137 | { | ||
138 | if(x->aux && x->aux->trust) { | ||
139 | sk_ASN1_OBJECT_pop_free(x->aux->trust, ASN1_OBJECT_free); | ||
140 | x->aux->trust = NULL; | ||
141 | } | ||
142 | } | ||
143 | |||
144 | void X509_reject_clear(X509 *x) | ||
145 | { | ||
146 | if(x->aux && x->aux->reject) { | ||
147 | sk_ASN1_OBJECT_pop_free(x->aux->reject, ASN1_OBJECT_free); | ||
148 | x->aux->reject = NULL; | ||
149 | } | ||
150 | } | ||
151 | |||