Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/libressl/src/crypto/asn1/x_name.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* $OpenBSD: x_name.c,v 1.34 2018/02/20 17:09:20 jsing Exp $ */ | - | ||||||||||||||||||||||||
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 <ctype.h> | - | ||||||||||||||||||||||||
60 | #include <stdio.h> | - | ||||||||||||||||||||||||
61 | #include <string.h> | - | ||||||||||||||||||||||||
62 | - | |||||||||||||||||||||||||
63 | #include <openssl/asn1t.h> | - | ||||||||||||||||||||||||
64 | #include <openssl/err.h> | - | ||||||||||||||||||||||||
65 | #include <openssl/x509.h> | - | ||||||||||||||||||||||||
66 | - | |||||||||||||||||||||||||
67 | #include "asn1_locl.h" | - | ||||||||||||||||||||||||
68 | - | |||||||||||||||||||||||||
69 | typedef STACK_OF(X509_NAME_ENTRY) STACK_OF_X509_NAME_ENTRY; | - | ||||||||||||||||||||||||
70 | DECLARE_STACK_OF(STACK_OF_X509_NAME_ENTRY) | - | ||||||||||||||||||||||||
71 | - | |||||||||||||||||||||||||
72 | static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, | - | ||||||||||||||||||||||||
73 | long len, const ASN1_ITEM *it, int tag, int aclass, char opt, | - | ||||||||||||||||||||||||
74 | ASN1_TLC *ctx); | - | ||||||||||||||||||||||||
75 | - | |||||||||||||||||||||||||
76 | static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, | - | ||||||||||||||||||||||||
77 | const ASN1_ITEM *it, int tag, int aclass); | - | ||||||||||||||||||||||||
78 | static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it); | - | ||||||||||||||||||||||||
79 | static void x509_name_ex_free(ASN1_VALUE **val, const ASN1_ITEM *it); | - | ||||||||||||||||||||||||
80 | - | |||||||||||||||||||||||||
81 | static int x509_name_encode(X509_NAME *a); | - | ||||||||||||||||||||||||
82 | static int x509_name_canon(X509_NAME *a); | - | ||||||||||||||||||||||||
83 | static int asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in); | - | ||||||||||||||||||||||||
84 | static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname, | - | ||||||||||||||||||||||||
85 | unsigned char **in); | - | ||||||||||||||||||||||||
86 | - | |||||||||||||||||||||||||
87 | static int x509_name_ex_print(BIO *out, ASN1_VALUE **pval, int indent, | - | ||||||||||||||||||||||||
88 | const char *fname, const ASN1_PCTX *pctx); | - | ||||||||||||||||||||||||
89 | - | |||||||||||||||||||||||||
90 | static const ASN1_TEMPLATE X509_NAME_ENTRY_seq_tt[] = { | - | ||||||||||||||||||||||||
91 | { | - | ||||||||||||||||||||||||
92 | .offset = offsetof(X509_NAME_ENTRY, object), | - | ||||||||||||||||||||||||
93 | .field_name = "object", | - | ||||||||||||||||||||||||
94 | .item = &ASN1_OBJECT_it, | - | ||||||||||||||||||||||||
95 | }, | - | ||||||||||||||||||||||||
96 | { | - | ||||||||||||||||||||||||
97 | .offset = offsetof(X509_NAME_ENTRY, value), | - | ||||||||||||||||||||||||
98 | .field_name = "value", | - | ||||||||||||||||||||||||
99 | .item = &ASN1_PRINTABLE_it, | - | ||||||||||||||||||||||||
100 | }, | - | ||||||||||||||||||||||||
101 | }; | - | ||||||||||||||||||||||||
102 | - | |||||||||||||||||||||||||
103 | const ASN1_ITEM X509_NAME_ENTRY_it = { | - | ||||||||||||||||||||||||
104 | .itype = ASN1_ITYPE_SEQUENCE, | - | ||||||||||||||||||||||||
105 | .utype = V_ASN1_SEQUENCE, | - | ||||||||||||||||||||||||
106 | .templates = X509_NAME_ENTRY_seq_tt, | - | ||||||||||||||||||||||||
107 | .tcount = sizeof(X509_NAME_ENTRY_seq_tt) / sizeof(ASN1_TEMPLATE), | - | ||||||||||||||||||||||||
108 | .size = sizeof(X509_NAME_ENTRY), | - | ||||||||||||||||||||||||
109 | .sname = "X509_NAME_ENTRY", | - | ||||||||||||||||||||||||
110 | }; | - | ||||||||||||||||||||||||
111 | - | |||||||||||||||||||||||||
112 | - | |||||||||||||||||||||||||
113 | X509_NAME_ENTRY * | - | ||||||||||||||||||||||||
114 | d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **a, const unsigned char **in, long len) | - | ||||||||||||||||||||||||
115 | { | - | ||||||||||||||||||||||||
116 | return (X509_NAME_ENTRY *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, never executed: return (X509_NAME_ENTRY *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, &X509_NAME_ENTRY_it); | 0 | ||||||||||||||||||||||||
117 | &X509_NAME_ENTRY_it); never executed: return (X509_NAME_ENTRY *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, &X509_NAME_ENTRY_it); | 0 | ||||||||||||||||||||||||
118 | } | - | ||||||||||||||||||||||||
119 | - | |||||||||||||||||||||||||
120 | int | - | ||||||||||||||||||||||||
121 | i2d_X509_NAME_ENTRY(X509_NAME_ENTRY *a, unsigned char **out) | - | ||||||||||||||||||||||||
122 | { | - | ||||||||||||||||||||||||
123 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &X509_NAME_ENTRY_it); never executed: return ASN1_item_i2d((ASN1_VALUE *)a, out, &X509_NAME_ENTRY_it); | 0 | ||||||||||||||||||||||||
124 | } | - | ||||||||||||||||||||||||
125 | - | |||||||||||||||||||||||||
126 | X509_NAME_ENTRY * | - | ||||||||||||||||||||||||
127 | X509_NAME_ENTRY_new(void) | - | ||||||||||||||||||||||||
128 | { | - | ||||||||||||||||||||||||
129 | return (X509_NAME_ENTRY *)ASN1_item_new(&X509_NAME_ENTRY_it); executed 1871 times by 8 tests: return (X509_NAME_ENTRY *)ASN1_item_new(&X509_NAME_ENTRY_it); Executed by:
| 1871 | ||||||||||||||||||||||||
130 | } | - | ||||||||||||||||||||||||
131 | - | |||||||||||||||||||||||||
132 | void | - | ||||||||||||||||||||||||
133 | X509_NAME_ENTRY_free(X509_NAME_ENTRY *a) | - | ||||||||||||||||||||||||
134 | { | - | ||||||||||||||||||||||||
135 | ASN1_item_free((ASN1_VALUE *)a, &X509_NAME_ENTRY_it); | - | ||||||||||||||||||||||||
136 | } executed 3664 times by 9 tests: end of block Executed by:
| 3664 | ||||||||||||||||||||||||
137 | - | |||||||||||||||||||||||||
138 | X509_NAME_ENTRY * | - | ||||||||||||||||||||||||
139 | X509_NAME_ENTRY_dup(X509_NAME_ENTRY *x) | - | ||||||||||||||||||||||||
140 | { | - | ||||||||||||||||||||||||
141 | return ASN1_item_dup(&X509_NAME_ENTRY_it, x); executed 33 times by 2 tests: return ASN1_item_dup(&X509_NAME_ENTRY_it, x); Executed by:
| 33 | ||||||||||||||||||||||||
142 | } | - | ||||||||||||||||||||||||
143 | - | |||||||||||||||||||||||||
144 | /* For the "Name" type we need a SEQUENCE OF { SET OF X509_NAME_ENTRY } | - | ||||||||||||||||||||||||
145 | * so declare two template wrappers for this | - | ||||||||||||||||||||||||
146 | */ | - | ||||||||||||||||||||||||
147 | - | |||||||||||||||||||||||||
148 | static const ASN1_TEMPLATE X509_NAME_ENTRIES_item_tt = { | - | ||||||||||||||||||||||||
149 | .flags = ASN1_TFLG_SET_OF, | - | ||||||||||||||||||||||||
150 | .tag = 0, | - | ||||||||||||||||||||||||
151 | .offset = 0, | - | ||||||||||||||||||||||||
152 | .field_name = "RDNS", | - | ||||||||||||||||||||||||
153 | .item = &X509_NAME_ENTRY_it, | - | ||||||||||||||||||||||||
154 | }; | - | ||||||||||||||||||||||||
155 | - | |||||||||||||||||||||||||
156 | const ASN1_ITEM X509_NAME_ENTRIES_it = { | - | ||||||||||||||||||||||||
157 | .itype = ASN1_ITYPE_PRIMITIVE, | - | ||||||||||||||||||||||||
158 | .utype = -1, | - | ||||||||||||||||||||||||
159 | .templates = &X509_NAME_ENTRIES_item_tt, | - | ||||||||||||||||||||||||
160 | .tcount = 0, | - | ||||||||||||||||||||||||
161 | .funcs = NULL, | - | ||||||||||||||||||||||||
162 | .size = 0, | - | ||||||||||||||||||||||||
163 | .sname = "X509_NAME_ENTRIES", | - | ||||||||||||||||||||||||
164 | }; | - | ||||||||||||||||||||||||
165 | - | |||||||||||||||||||||||||
166 | static const ASN1_TEMPLATE X509_NAME_INTERNAL_item_tt = { | - | ||||||||||||||||||||||||
167 | .flags = ASN1_TFLG_SEQUENCE_OF, | - | ||||||||||||||||||||||||
168 | .tag = 0, | - | ||||||||||||||||||||||||
169 | .offset = 0, | - | ||||||||||||||||||||||||
170 | .field_name = "Name", | - | ||||||||||||||||||||||||
171 | .item = &X509_NAME_ENTRIES_it, | - | ||||||||||||||||||||||||
172 | }; | - | ||||||||||||||||||||||||
173 | - | |||||||||||||||||||||||||
174 | const ASN1_ITEM X509_NAME_INTERNAL_it = { | - | ||||||||||||||||||||||||
175 | .itype = ASN1_ITYPE_PRIMITIVE, | - | ||||||||||||||||||||||||
176 | .utype = -1, | - | ||||||||||||||||||||||||
177 | .templates = &X509_NAME_INTERNAL_item_tt, | - | ||||||||||||||||||||||||
178 | .tcount = 0, | - | ||||||||||||||||||||||||
179 | .funcs = NULL, | - | ||||||||||||||||||||||||
180 | .size = 0, | - | ||||||||||||||||||||||||
181 | .sname = "X509_NAME_INTERNAL", | - | ||||||||||||||||||||||||
182 | }; | - | ||||||||||||||||||||||||
183 | - | |||||||||||||||||||||||||
184 | /* Normally that's where it would end: we'd have two nested STACK structures | - | ||||||||||||||||||||||||
185 | * representing the ASN1. Unfortunately X509_NAME uses a completely different | - | ||||||||||||||||||||||||
186 | * form and caches encodings so we have to process the internal form and convert | - | ||||||||||||||||||||||||
187 | * to the external form. | - | ||||||||||||||||||||||||
188 | */ | - | ||||||||||||||||||||||||
189 | - | |||||||||||||||||||||||||
190 | const ASN1_EXTERN_FUNCS x509_name_ff = { | - | ||||||||||||||||||||||||
191 | NULL, | - | ||||||||||||||||||||||||
192 | x509_name_ex_new, | - | ||||||||||||||||||||||||
193 | x509_name_ex_free, | - | ||||||||||||||||||||||||
194 | 0, /* Default clear behaviour is OK */ | - | ||||||||||||||||||||||||
195 | x509_name_ex_d2i, | - | ||||||||||||||||||||||||
196 | x509_name_ex_i2d, | - | ||||||||||||||||||||||||
197 | x509_name_ex_print | - | ||||||||||||||||||||||||
198 | }; | - | ||||||||||||||||||||||||
199 | - | |||||||||||||||||||||||||
200 | const ASN1_ITEM X509_NAME_it = { | - | ||||||||||||||||||||||||
201 | .itype = ASN1_ITYPE_EXTERN, | - | ||||||||||||||||||||||||
202 | .utype = V_ASN1_SEQUENCE, | - | ||||||||||||||||||||||||
203 | .templates = NULL, | - | ||||||||||||||||||||||||
204 | .tcount = 0, | - | ||||||||||||||||||||||||
205 | .funcs = &x509_name_ff, | - | ||||||||||||||||||||||||
206 | .size = 0, | - | ||||||||||||||||||||||||
207 | .sname = "X509_NAME", | - | ||||||||||||||||||||||||
208 | }; | - | ||||||||||||||||||||||||
209 | - | |||||||||||||||||||||||||
210 | X509_NAME * | - | ||||||||||||||||||||||||
211 | d2i_X509_NAME(X509_NAME **a, const unsigned char **in, long len) | - | ||||||||||||||||||||||||
212 | { | - | ||||||||||||||||||||||||
213 | return (X509_NAME *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, never executed: return (X509_NAME *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, &X509_NAME_it); | 0 | ||||||||||||||||||||||||
214 | &X509_NAME_it); never executed: return (X509_NAME *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, &X509_NAME_it); | 0 | ||||||||||||||||||||||||
215 | } | - | ||||||||||||||||||||||||
216 | - | |||||||||||||||||||||||||
217 | int | - | ||||||||||||||||||||||||
218 | i2d_X509_NAME(X509_NAME *a, unsigned char **out) | - | ||||||||||||||||||||||||
219 | { | - | ||||||||||||||||||||||||
220 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &X509_NAME_it); never executed: return ASN1_item_i2d((ASN1_VALUE *)a, out, &X509_NAME_it); | 0 | ||||||||||||||||||||||||
221 | } | - | ||||||||||||||||||||||||
222 | - | |||||||||||||||||||||||||
223 | X509_NAME * | - | ||||||||||||||||||||||||
224 | X509_NAME_new(void) | - | ||||||||||||||||||||||||
225 | { | - | ||||||||||||||||||||||||
226 | return (X509_NAME *)ASN1_item_new(&X509_NAME_it); executed 25 times by 1 test: return (X509_NAME *)ASN1_item_new(&X509_NAME_it); Executed by:
| 25 | ||||||||||||||||||||||||
227 | } | - | ||||||||||||||||||||||||
228 | - | |||||||||||||||||||||||||
229 | void | - | ||||||||||||||||||||||||
230 | X509_NAME_free(X509_NAME *a) | - | ||||||||||||||||||||||||
231 | { | - | ||||||||||||||||||||||||
232 | ASN1_item_free((ASN1_VALUE *)a, &X509_NAME_it); | - | ||||||||||||||||||||||||
233 | } executed 65 times by 5 tests: end of block Executed by:
| 65 | ||||||||||||||||||||||||
234 | - | |||||||||||||||||||||||||
235 | X509_NAME * | - | ||||||||||||||||||||||||
236 | X509_NAME_dup(X509_NAME *x) | - | ||||||||||||||||||||||||
237 | { | - | ||||||||||||||||||||||||
238 | return ASN1_item_dup(&X509_NAME_it, x); executed 32 times by 3 tests: return ASN1_item_dup(&X509_NAME_it, x); Executed by:
| 32 | ||||||||||||||||||||||||
239 | } | - | ||||||||||||||||||||||||
240 | - | |||||||||||||||||||||||||
241 | static int | - | ||||||||||||||||||||||||
242 | x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it) | - | ||||||||||||||||||||||||
243 | { | - | ||||||||||||||||||||||||
244 | X509_NAME *ret = NULL; | - | ||||||||||||||||||||||||
245 | - | |||||||||||||||||||||||||
246 | ret = malloc(sizeof(X509_NAME)); | - | ||||||||||||||||||||||||
247 | if (!ret)
| 0-1004 | ||||||||||||||||||||||||
248 | goto memerr; never executed: goto memerr; | 0 | ||||||||||||||||||||||||
249 | if ((ret->entries = sk_X509_NAME_ENTRY_new_null()) == NULL)
| 0-1004 | ||||||||||||||||||||||||
250 | goto memerr; never executed: goto memerr; | 0 | ||||||||||||||||||||||||
251 | if ((ret->bytes = BUF_MEM_new()) == NULL)
| 0-1004 | ||||||||||||||||||||||||
252 | goto memerr; never executed: goto memerr; | 0 | ||||||||||||||||||||||||
253 | ret->canon_enc = NULL; | - | ||||||||||||||||||||||||
254 | ret->canon_enclen = 0; | - | ||||||||||||||||||||||||
255 | ret->modified = 1; | - | ||||||||||||||||||||||||
256 | *val = (ASN1_VALUE *)ret; | - | ||||||||||||||||||||||||
257 | return 1; executed 1004 times by 8 tests: return 1; Executed by:
| 1004 | ||||||||||||||||||||||||
258 | - | |||||||||||||||||||||||||
259 | memerr: | - | ||||||||||||||||||||||||
260 | ASN1error(ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
261 | if (ret) {
| 0 | ||||||||||||||||||||||||
262 | if (ret->entries)
| 0 | ||||||||||||||||||||||||
263 | sk_X509_NAME_ENTRY_free(ret->entries); never executed: sk_free(((_STACK*) (1 ? (ret->entries) : (struct stack_st_X509_NAME_ENTRY*)0))); | 0 | ||||||||||||||||||||||||
264 | free(ret); | - | ||||||||||||||||||||||||
265 | } never executed: end of block | 0 | ||||||||||||||||||||||||
266 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
267 | } | - | ||||||||||||||||||||||||
268 | - | |||||||||||||||||||||||||
269 | static void | - | ||||||||||||||||||||||||
270 | x509_name_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | - | ||||||||||||||||||||||||
271 | { | - | ||||||||||||||||||||||||
272 | X509_NAME *a; | - | ||||||||||||||||||||||||
273 | - | |||||||||||||||||||||||||
274 | if (!pval || !*pval)
| 0-991 | ||||||||||||||||||||||||
275 | return; never executed: return; | 0 | ||||||||||||||||||||||||
276 | a = (X509_NAME *)*pval; | - | ||||||||||||||||||||||||
277 | - | |||||||||||||||||||||||||
278 | BUF_MEM_free(a->bytes); | - | ||||||||||||||||||||||||
279 | sk_X509_NAME_ENTRY_pop_free(a->entries, X509_NAME_ENTRY_free); | - | ||||||||||||||||||||||||
280 | free(a->canon_enc); | - | ||||||||||||||||||||||||
281 | free(a); | - | ||||||||||||||||||||||||
282 | *pval = NULL; | - | ||||||||||||||||||||||||
283 | } executed 991 times by 8 tests: end of block Executed by:
| 991 | ||||||||||||||||||||||||
284 | - | |||||||||||||||||||||||||
285 | static int | - | ||||||||||||||||||||||||
286 | x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len, | - | ||||||||||||||||||||||||
287 | const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx) | - | ||||||||||||||||||||||||
288 | { | - | ||||||||||||||||||||||||
289 | const unsigned char *p = *in, *q; | - | ||||||||||||||||||||||||
290 | union { | - | ||||||||||||||||||||||||
291 | STACK_OF(STACK_OF_X509_NAME_ENTRY) *s; | - | ||||||||||||||||||||||||
292 | ASN1_VALUE *a; | - | ||||||||||||||||||||||||
293 | } intname = {NULL}; | - | ||||||||||||||||||||||||
294 | union { | - | ||||||||||||||||||||||||
295 | X509_NAME *x; | - | ||||||||||||||||||||||||
296 | ASN1_VALUE *a; | - | ||||||||||||||||||||||||
297 | } nm = {NULL}; | - | ||||||||||||||||||||||||
298 | int i, j, ret; | - | ||||||||||||||||||||||||
299 | STACK_OF(X509_NAME_ENTRY) *entries; | - | ||||||||||||||||||||||||
300 | X509_NAME_ENTRY *entry; | - | ||||||||||||||||||||||||
301 | q = p; | - | ||||||||||||||||||||||||
302 | - | |||||||||||||||||||||||||
303 | /* Get internal representation of Name */ | - | ||||||||||||||||||||||||
304 | ret = ASN1_item_ex_d2i(&intname.a, &p, len, | - | ||||||||||||||||||||||||
305 | &X509_NAME_INTERNAL_it, tag, aclass, opt, ctx); | - | ||||||||||||||||||||||||
306 | - | |||||||||||||||||||||||||
307 | if (ret <= 0)
| 0-473 | ||||||||||||||||||||||||
308 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
309 | - | |||||||||||||||||||||||||
310 | if (*val)
| 32-441 | ||||||||||||||||||||||||
311 | x509_name_ex_free(val, NULL); executed 441 times by 7 tests: x509_name_ex_free(val, ((void *)0) ); Executed by:
| 441 | ||||||||||||||||||||||||
312 | if (!x509_name_ex_new(&nm.a, NULL))
| 0-473 | ||||||||||||||||||||||||
313 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
314 | /* We've decoded it: now cache encoding */ | - | ||||||||||||||||||||||||
315 | if (!BUF_MEM_grow(nm.x->bytes, p - q))
| 0-473 | ||||||||||||||||||||||||
316 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
317 | memcpy(nm.x->bytes->data, q, p - q); | - | ||||||||||||||||||||||||
318 | - | |||||||||||||||||||||||||
319 | /* Convert internal representation to X509_NAME structure */ | - | ||||||||||||||||||||||||
320 | for (i = 0; i < sk_STACK_OF_X509_NAME_ENTRY_num(intname.s); i++) {
| 473-1805 | ||||||||||||||||||||||||
321 | entries = sk_STACK_OF_X509_NAME_ENTRY_value(intname.s, i); | - | ||||||||||||||||||||||||
322 | for (j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) {
| 1805 | ||||||||||||||||||||||||
323 | entry = sk_X509_NAME_ENTRY_value(entries, j); | - | ||||||||||||||||||||||||
324 | entry->set = i; | - | ||||||||||||||||||||||||
325 | if (!sk_X509_NAME_ENTRY_push(nm.x->entries, entry))
| 0-1805 | ||||||||||||||||||||||||
326 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
327 | } executed 1805 times by 8 tests: end of block Executed by:
| 1805 | ||||||||||||||||||||||||
328 | sk_X509_NAME_ENTRY_free(entries); | - | ||||||||||||||||||||||||
329 | } executed 1805 times by 8 tests: end of block Executed by:
| 1805 | ||||||||||||||||||||||||
330 | sk_STACK_OF_X509_NAME_ENTRY_free(intname.s); | - | ||||||||||||||||||||||||
331 | ret = x509_name_canon(nm.x); | - | ||||||||||||||||||||||||
332 | if (!ret)
| 0-473 | ||||||||||||||||||||||||
333 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
334 | nm.x->modified = 0; | - | ||||||||||||||||||||||||
335 | *val = nm.a; | - | ||||||||||||||||||||||||
336 | *in = p; | - | ||||||||||||||||||||||||
337 | return ret; executed 473 times by 8 tests: return ret; Executed by:
| 473 | ||||||||||||||||||||||||
338 | - | |||||||||||||||||||||||||
339 | err: | - | ||||||||||||||||||||||||
340 | if (nm.x != NULL)
| 0 | ||||||||||||||||||||||||
341 | X509_NAME_free(nm.x); never executed: X509_NAME_free(nm.x); | 0 | ||||||||||||||||||||||||
342 | ASN1error(ERR_R_NESTED_ASN1_ERROR); | - | ||||||||||||||||||||||||
343 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
344 | } | - | ||||||||||||||||||||||||
345 | - | |||||||||||||||||||||||||
346 | static int | - | ||||||||||||||||||||||||
347 | x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, | - | ||||||||||||||||||||||||
348 | int tag, int aclass) | - | ||||||||||||||||||||||||
349 | { | - | ||||||||||||||||||||||||
350 | int ret; | - | ||||||||||||||||||||||||
351 | X509_NAME *a = (X509_NAME *)*val; | - | ||||||||||||||||||||||||
352 | - | |||||||||||||||||||||||||
353 | if (a->modified) {
| 27-89 | ||||||||||||||||||||||||
354 | ret = x509_name_encode(a); | - | ||||||||||||||||||||||||
355 | if (ret < 0)
| 0-27 | ||||||||||||||||||||||||
356 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
357 | ret = x509_name_canon(a); | - | ||||||||||||||||||||||||
358 | if (ret < 0)
| 0-27 | ||||||||||||||||||||||||
359 | return ret; never executed: return ret; | 0 | ||||||||||||||||||||||||
360 | } executed 27 times by 2 tests: end of block Executed by:
| 27 | ||||||||||||||||||||||||
361 | ret = a->bytes->length; | - | ||||||||||||||||||||||||
362 | if (out != NULL) {
| 43-73 | ||||||||||||||||||||||||
363 | memcpy(*out, a->bytes->data, ret); | - | ||||||||||||||||||||||||
364 | *out += ret; | - | ||||||||||||||||||||||||
365 | } executed 43 times by 3 tests: end of block Executed by:
| 43 | ||||||||||||||||||||||||
366 | return ret; executed 116 times by 3 tests: return ret; Executed by:
| 116 | ||||||||||||||||||||||||
367 | } | - | ||||||||||||||||||||||||
368 | - | |||||||||||||||||||||||||
369 | static void | - | ||||||||||||||||||||||||
370 | local_sk_X509_NAME_ENTRY_free(STACK_OF(X509_NAME_ENTRY) *ne) | - | ||||||||||||||||||||||||
371 | { | - | ||||||||||||||||||||||||
372 | sk_X509_NAME_ENTRY_free(ne); | - | ||||||||||||||||||||||||
373 | } executed 33 times by 2 tests: end of block Executed by:
| 33 | ||||||||||||||||||||||||
374 | - | |||||||||||||||||||||||||
375 | static void | - | ||||||||||||||||||||||||
376 | local_sk_X509_NAME_ENTRY_pop_free(STACK_OF(X509_NAME_ENTRY) *ne) | - | ||||||||||||||||||||||||
377 | { | - | ||||||||||||||||||||||||
378 | sk_X509_NAME_ENTRY_pop_free(ne, X509_NAME_ENTRY_free); | - | ||||||||||||||||||||||||
379 | } executed 1838 times by 8 tests: end of block Executed by:
| 1838 | ||||||||||||||||||||||||
380 | - | |||||||||||||||||||||||||
381 | static int | - | ||||||||||||||||||||||||
382 | x509_name_encode(X509_NAME *a) | - | ||||||||||||||||||||||||
383 | { | - | ||||||||||||||||||||||||
384 | union { | - | ||||||||||||||||||||||||
385 | STACK_OF(STACK_OF_X509_NAME_ENTRY) *s; | - | ||||||||||||||||||||||||
386 | ASN1_VALUE *a; | - | ||||||||||||||||||||||||
387 | } intname = {NULL}; | - | ||||||||||||||||||||||||
388 | int len; | - | ||||||||||||||||||||||||
389 | unsigned char *p; | - | ||||||||||||||||||||||||
390 | STACK_OF(X509_NAME_ENTRY) *entries = NULL; | - | ||||||||||||||||||||||||
391 | X509_NAME_ENTRY *entry; | - | ||||||||||||||||||||||||
392 | int i, set = -1; | - | ||||||||||||||||||||||||
393 | - | |||||||||||||||||||||||||
394 | intname.s = sk_STACK_OF_X509_NAME_ENTRY_new_null(); | - | ||||||||||||||||||||||||
395 | if (!intname.s)
| 0-27 | ||||||||||||||||||||||||
396 | goto memerr; never executed: goto memerr; | 0 | ||||||||||||||||||||||||
397 | for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
| 27-33 | ||||||||||||||||||||||||
398 | entry = sk_X509_NAME_ENTRY_value(a->entries, i); | - | ||||||||||||||||||||||||
399 | if (entry->set != set) {
| 0-33 | ||||||||||||||||||||||||
400 | entries = sk_X509_NAME_ENTRY_new_null(); | - | ||||||||||||||||||||||||
401 | if (!entries)
| 0-33 | ||||||||||||||||||||||||
402 | goto memerr; never executed: goto memerr; | 0 | ||||||||||||||||||||||||
403 | if (!sk_STACK_OF_X509_NAME_ENTRY_push(intname.s,
| 0-33 | ||||||||||||||||||||||||
404 | entries)) | - | ||||||||||||||||||||||||
405 | goto memerr; never executed: goto memerr; | 0 | ||||||||||||||||||||||||
406 | set = entry->set; | - | ||||||||||||||||||||||||
407 | } executed 33 times by 2 tests: end of block Executed by:
| 33 | ||||||||||||||||||||||||
408 | if (entries == NULL /* if entry->set is bogusly -1 */ ||
| 0-33 | ||||||||||||||||||||||||
409 | !sk_X509_NAME_ENTRY_push(entries, entry))
| 0-33 | ||||||||||||||||||||||||
410 | goto memerr; never executed: goto memerr; | 0 | ||||||||||||||||||||||||
411 | } executed 33 times by 2 tests: end of block Executed by:
| 33 | ||||||||||||||||||||||||
412 | len = ASN1_item_ex_i2d(&intname.a, NULL, | - | ||||||||||||||||||||||||
413 | &X509_NAME_INTERNAL_it, -1, -1); | - | ||||||||||||||||||||||||
414 | if (!BUF_MEM_grow(a->bytes, len))
| 0-27 | ||||||||||||||||||||||||
415 | goto memerr; never executed: goto memerr; | 0 | ||||||||||||||||||||||||
416 | p = (unsigned char *)a->bytes->data; | - | ||||||||||||||||||||||||
417 | ASN1_item_ex_i2d(&intname.a, &p, &X509_NAME_INTERNAL_it, | - | ||||||||||||||||||||||||
418 | -1, -1); | - | ||||||||||||||||||||||||
419 | sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s, | - | ||||||||||||||||||||||||
420 | local_sk_X509_NAME_ENTRY_free); | - | ||||||||||||||||||||||||
421 | a->modified = 0; | - | ||||||||||||||||||||||||
422 | return len; executed 27 times by 2 tests: return len; Executed by:
| 27 | ||||||||||||||||||||||||
423 | - | |||||||||||||||||||||||||
424 | memerr: | - | ||||||||||||||||||||||||
425 | sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname.s, | - | ||||||||||||||||||||||||
426 | local_sk_X509_NAME_ENTRY_free); | - | ||||||||||||||||||||||||
427 | ASN1error(ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||||||||
428 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
429 | } | - | ||||||||||||||||||||||||
430 | - | |||||||||||||||||||||||||
431 | static int | - | ||||||||||||||||||||||||
432 | x509_name_ex_print(BIO *out, ASN1_VALUE **pval, int indent, const char *fname, | - | ||||||||||||||||||||||||
433 | const ASN1_PCTX *pctx) | - | ||||||||||||||||||||||||
434 | { | - | ||||||||||||||||||||||||
435 | if (X509_NAME_print_ex(out, (X509_NAME *)*pval, indent,
| 0 | ||||||||||||||||||||||||
436 | pctx->nm_flags) <= 0)
| 0 | ||||||||||||||||||||||||
437 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
438 | return 2; never executed: return 2; | 0 | ||||||||||||||||||||||||
439 | } | - | ||||||||||||||||||||||||
440 | - | |||||||||||||||||||||||||
441 | /* This function generates the canonical encoding of the Name structure. | - | ||||||||||||||||||||||||
442 | * In it all strings are converted to UTF8, leading, trailing and | - | ||||||||||||||||||||||||
443 | * multiple spaces collapsed, converted to lower case and the leading | - | ||||||||||||||||||||||||
444 | * SEQUENCE header removed. | - | ||||||||||||||||||||||||
445 | * | - | ||||||||||||||||||||||||
446 | * In future we could also normalize the UTF8 too. | - | ||||||||||||||||||||||||
447 | * | - | ||||||||||||||||||||||||
448 | * By doing this comparison of Name structures can be rapidly | - | ||||||||||||||||||||||||
449 | * performed by just using memcmp() of the canonical encoding. | - | ||||||||||||||||||||||||
450 | * By omitting the leading SEQUENCE name constraints of type | - | ||||||||||||||||||||||||
451 | * dirName can also be checked with a simple memcmp(). | - | ||||||||||||||||||||||||
452 | */ | - | ||||||||||||||||||||||||
453 | - | |||||||||||||||||||||||||
454 | static int | - | ||||||||||||||||||||||||
455 | x509_name_canon(X509_NAME *a) | - | ||||||||||||||||||||||||
456 | { | - | ||||||||||||||||||||||||
457 | unsigned char *p; | - | ||||||||||||||||||||||||
458 | STACK_OF(STACK_OF_X509_NAME_ENTRY) *intname = NULL; | - | ||||||||||||||||||||||||
459 | STACK_OF(X509_NAME_ENTRY) *entries = NULL; | - | ||||||||||||||||||||||||
460 | X509_NAME_ENTRY *entry, *tmpentry = NULL; | - | ||||||||||||||||||||||||
461 | int i, len, set = -1, ret = 0; | - | ||||||||||||||||||||||||
462 | - | |||||||||||||||||||||||||
463 | if (a->canon_enc) {
| 0-500 | ||||||||||||||||||||||||
464 | free(a->canon_enc); | - | ||||||||||||||||||||||||
465 | a->canon_enc = NULL; | - | ||||||||||||||||||||||||
466 | } never executed: end of block | 0 | ||||||||||||||||||||||||
467 | /* Special case: empty X509_NAME => null encoding */ | - | ||||||||||||||||||||||||
468 | if (sk_X509_NAME_ENTRY_num(a->entries) == 0) {
| 0-500 | ||||||||||||||||||||||||
469 | a->canon_enclen = 0; | - | ||||||||||||||||||||||||
470 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
471 | } | - | ||||||||||||||||||||||||
472 | intname = sk_STACK_OF_X509_NAME_ENTRY_new_null(); | - | ||||||||||||||||||||||||
473 | if (!intname)
| 0-500 | ||||||||||||||||||||||||
474 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
475 | for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
| 500-1838 | ||||||||||||||||||||||||
476 | entry = sk_X509_NAME_ENTRY_value(a->entries, i); | - | ||||||||||||||||||||||||
477 | if (entry->set != set) {
| 0-1838 | ||||||||||||||||||||||||
478 | entries = sk_X509_NAME_ENTRY_new_null(); | - | ||||||||||||||||||||||||
479 | if (!entries)
| 0-1838 | ||||||||||||||||||||||||
480 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
481 | if (sk_STACK_OF_X509_NAME_ENTRY_push(intname,
| 0-1838 | ||||||||||||||||||||||||
482 | entries) == 0) {
| 0-1838 | ||||||||||||||||||||||||
483 | sk_X509_NAME_ENTRY_free(entries); | - | ||||||||||||||||||||||||
484 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
485 | } | - | ||||||||||||||||||||||||
486 | set = entry->set; | - | ||||||||||||||||||||||||
487 | } executed 1838 times by 8 tests: end of block Executed by:
| 1838 | ||||||||||||||||||||||||
488 | tmpentry = X509_NAME_ENTRY_new(); | - | ||||||||||||||||||||||||
489 | if (tmpentry == NULL)
| 0-1838 | ||||||||||||||||||||||||
490 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
491 | tmpentry->object = OBJ_dup(entry->object); | - | ||||||||||||||||||||||||
492 | if (tmpentry->object == NULL)
| 0-1838 | ||||||||||||||||||||||||
493 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
494 | if (!asn1_string_canon(tmpentry->value, entry->value))
| 0-1838 | ||||||||||||||||||||||||
495 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
496 | if (entries == NULL /* if entry->set is bogusly -1 */ ||
| 0-1838 | ||||||||||||||||||||||||
497 | !sk_X509_NAME_ENTRY_push(entries, tmpentry))
| 0-1838 | ||||||||||||||||||||||||
498 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
499 | tmpentry = NULL; | - | ||||||||||||||||||||||||
500 | } executed 1838 times by 8 tests: end of block Executed by:
| 1838 | ||||||||||||||||||||||||
501 | - | |||||||||||||||||||||||||
502 | /* Finally generate encoding */ | - | ||||||||||||||||||||||||
503 | len = i2d_name_canon(intname, NULL); | - | ||||||||||||||||||||||||
504 | if (len < 0)
| 0-500 | ||||||||||||||||||||||||
505 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
506 | p = malloc(len); | - | ||||||||||||||||||||||||
507 | if (p == NULL)
| 0-500 | ||||||||||||||||||||||||
508 | goto err; never executed: goto err; | 0 | ||||||||||||||||||||||||
509 | a->canon_enc = p; | - | ||||||||||||||||||||||||
510 | a->canon_enclen = len; | - | ||||||||||||||||||||||||
511 | i2d_name_canon(intname, &p); | - | ||||||||||||||||||||||||
512 | ret = 1; | - | ||||||||||||||||||||||||
513 | - | |||||||||||||||||||||||||
514 | err: code before this statement executed 500 times by 8 tests: err: Executed by:
| 500 | ||||||||||||||||||||||||
515 | if (tmpentry)
| 0-500 | ||||||||||||||||||||||||
516 | X509_NAME_ENTRY_free(tmpentry); never executed: X509_NAME_ENTRY_free(tmpentry); | 0 | ||||||||||||||||||||||||
517 | if (intname)
| 0-500 | ||||||||||||||||||||||||
518 | sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname, executed 500 times by 8 tests: sk_pop_free(((_STACK*) (1 ? (intname) : (struct stack_st_STACK_OF_X509_NAME_ENTRY*)0)), ((void (*)(void *)) ((1 ? (local_sk_X509_NAME_ENTRY_pop_free) : (void (*)(STACK_OF_X509_NAME_ENTRY *))0)))) ; Executed by:
| 500 | ||||||||||||||||||||||||
519 | local_sk_X509_NAME_ENTRY_pop_free); executed 500 times by 8 tests: sk_pop_free(((_STACK*) (1 ? (intname) : (struct stack_st_STACK_OF_X509_NAME_ENTRY*)0)), ((void (*)(void *)) ((1 ? (local_sk_X509_NAME_ENTRY_pop_free) : (void (*)(STACK_OF_X509_NAME_ENTRY *))0)))) ; Executed by:
| 500 | ||||||||||||||||||||||||
520 | return ret; executed 500 times by 8 tests: return ret; Executed by:
| 500 | ||||||||||||||||||||||||
521 | } | - | ||||||||||||||||||||||||
522 | - | |||||||||||||||||||||||||
523 | /* Bitmap of all the types of string that will be canonicalized. */ | - | ||||||||||||||||||||||||
524 | - | |||||||||||||||||||||||||
525 | #define ASN1_MASK_CANON \ | - | ||||||||||||||||||||||||
526 | (B_ASN1_UTF8STRING | B_ASN1_BMPSTRING | B_ASN1_UNIVERSALSTRING \ | - | ||||||||||||||||||||||||
527 | | B_ASN1_PRINTABLESTRING | B_ASN1_T61STRING | B_ASN1_IA5STRING \ | - | ||||||||||||||||||||||||
528 | | B_ASN1_VISIBLESTRING) | - | ||||||||||||||||||||||||
529 | - | |||||||||||||||||||||||||
530 | - | |||||||||||||||||||||||||
531 | static int | - | ||||||||||||||||||||||||
532 | asn1_string_canon(ASN1_STRING *out, ASN1_STRING *in) | - | ||||||||||||||||||||||||
533 | { | - | ||||||||||||||||||||||||
534 | unsigned char *to, *from; | - | ||||||||||||||||||||||||
535 | int len, i; | - | ||||||||||||||||||||||||
536 | - | |||||||||||||||||||||||||
537 | /* If type not in bitmask just copy string across */ | - | ||||||||||||||||||||||||
538 | if (!(ASN1_tag2bit(in->type) & ASN1_MASK_CANON)) {
| 0-1838 | ||||||||||||||||||||||||
539 | if (!ASN1_STRING_copy(out, in))
| 0 | ||||||||||||||||||||||||
540 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
541 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
542 | } | - | ||||||||||||||||||||||||
543 | - | |||||||||||||||||||||||||
544 | out->type = V_ASN1_UTF8STRING; | - | ||||||||||||||||||||||||
545 | out->length = ASN1_STRING_to_UTF8(&out->data, in); | - | ||||||||||||||||||||||||
546 | if (out->length == -1)
| 0-1838 | ||||||||||||||||||||||||
547 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
548 | - | |||||||||||||||||||||||||
549 | to = out->data; | - | ||||||||||||||||||||||||
550 | from = to; | - | ||||||||||||||||||||||||
551 | - | |||||||||||||||||||||||||
552 | len = out->length; | - | ||||||||||||||||||||||||
553 | - | |||||||||||||||||||||||||
554 | /* Convert string in place to canonical form. | - | ||||||||||||||||||||||||
555 | * Ultimately we may need to handle a wider range of characters | - | ||||||||||||||||||||||||
556 | * but for now ignore anything with MSB set and rely on the | - | ||||||||||||||||||||||||
557 | * isspace() and tolower() functions. | - | ||||||||||||||||||||||||
558 | */ | - | ||||||||||||||||||||||||
559 | - | |||||||||||||||||||||||||
560 | /* Ignore leading spaces */ | - | ||||||||||||||||||||||||
561 | while ((len > 0) && !(*from & 0x80) && isspace(*from)) {
| 0-1838 | ||||||||||||||||||||||||
562 | from++; | - | ||||||||||||||||||||||||
563 | len--; | - | ||||||||||||||||||||||||
564 | } never executed: end of block | 0 | ||||||||||||||||||||||||
565 | - | |||||||||||||||||||||||||
566 | to = from + len - 1; | - | ||||||||||||||||||||||||
567 | - | |||||||||||||||||||||||||
568 | /* Ignore trailing spaces */ | - | ||||||||||||||||||||||||
569 | while ((len > 0) && !(*to & 0x80) && isspace(*to)) {
| 0-1838 | ||||||||||||||||||||||||
570 | to--; | - | ||||||||||||||||||||||||
571 | len--; | - | ||||||||||||||||||||||||
572 | } never executed: end of block | 0 | ||||||||||||||||||||||||
573 | - | |||||||||||||||||||||||||
574 | to = out->data; | - | ||||||||||||||||||||||||
575 | - | |||||||||||||||||||||||||
576 | i = 0; | - | ||||||||||||||||||||||||
577 | while (i < len) {
| 1838-28148 | ||||||||||||||||||||||||
578 | /* If MSB set just copy across */ | - | ||||||||||||||||||||||||
579 | if (*from & 0x80) {
| 0-28148 | ||||||||||||||||||||||||
580 | *to++ = *from++; | - | ||||||||||||||||||||||||
581 | i++; | - | ||||||||||||||||||||||||
582 | } never executed: end of block | 0 | ||||||||||||||||||||||||
583 | /* Collapse multiple spaces */ | - | ||||||||||||||||||||||||
584 | else if (isspace(*from)) {
| 2943-25205 | ||||||||||||||||||||||||
585 | /* Copy one space across */ | - | ||||||||||||||||||||||||
586 | *to++ = ' '; | - | ||||||||||||||||||||||||
587 | /* Ignore subsequent spaces. Note: don't need to | - | ||||||||||||||||||||||||
588 | * check len here because we know the last | - | ||||||||||||||||||||||||
589 | * character is a non-space so we can't overflow. | - | ||||||||||||||||||||||||
590 | */ | - | ||||||||||||||||||||||||
591 | do { | - | ||||||||||||||||||||||||
592 | from++; | - | ||||||||||||||||||||||||
593 | i++; | - | ||||||||||||||||||||||||
594 | } while (!(*from & 0x80) && isspace(*from)); executed 2943 times by 7 tests: end of block Executed by:
| 0-2943 | ||||||||||||||||||||||||
595 | } else { executed 2943 times by 7 tests: end of block Executed by:
| 2943 | ||||||||||||||||||||||||
596 | *to++ = tolower(*from); never executed: end of block never executed: __res = tolower ( *from ); executed 25205 times by 8 tests: __res = (*__ctype_tolower_loc ())[(int) ( *from )]; Executed by:
| 0-25205 | ||||||||||||||||||||||||
597 | from++; | - | ||||||||||||||||||||||||
598 | i++; | - | ||||||||||||||||||||||||
599 | } executed 25205 times by 8 tests: end of block Executed by:
| 25205 | ||||||||||||||||||||||||
600 | } | - | ||||||||||||||||||||||||
601 | - | |||||||||||||||||||||||||
602 | out->length = to - out->data; | - | ||||||||||||||||||||||||
603 | - | |||||||||||||||||||||||||
604 | return 1; executed 1838 times by 8 tests: return 1; Executed by:
| 1838 | ||||||||||||||||||||||||
605 | } | - | ||||||||||||||||||||||||
606 | - | |||||||||||||||||||||||||
607 | static int | - | ||||||||||||||||||||||||
608 | i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) *_intname, unsigned char **in) | - | ||||||||||||||||||||||||
609 | { | - | ||||||||||||||||||||||||
610 | int i, len, ltmp; | - | ||||||||||||||||||||||||
611 | ASN1_VALUE *v; | - | ||||||||||||||||||||||||
612 | STACK_OF(ASN1_VALUE) *intname = (STACK_OF(ASN1_VALUE) *)_intname; | - | ||||||||||||||||||||||||
613 | - | |||||||||||||||||||||||||
614 | len = 0; | - | ||||||||||||||||||||||||
615 | for (i = 0; i < sk_ASN1_VALUE_num(intname); i++) {
| 1000-3676 | ||||||||||||||||||||||||
616 | v = sk_ASN1_VALUE_value(intname, i); | - | ||||||||||||||||||||||||
617 | ltmp = ASN1_item_ex_i2d(&v, in, | - | ||||||||||||||||||||||||
618 | &X509_NAME_ENTRIES_it, -1, -1); | - | ||||||||||||||||||||||||
619 | if (ltmp < 0)
| 0-3676 | ||||||||||||||||||||||||
620 | return ltmp; never executed: return ltmp; | 0 | ||||||||||||||||||||||||
621 | len += ltmp; | - | ||||||||||||||||||||||||
622 | } executed 3676 times by 8 tests: end of block Executed by:
| 3676 | ||||||||||||||||||||||||
623 | return len; executed 1000 times by 8 tests: return len; Executed by:
| 1000 | ||||||||||||||||||||||||
624 | } | - | ||||||||||||||||||||||||
625 | - | |||||||||||||||||||||||||
626 | int | - | ||||||||||||||||||||||||
627 | X509_NAME_set(X509_NAME **xn, X509_NAME *name) | - | ||||||||||||||||||||||||
628 | { | - | ||||||||||||||||||||||||
629 | X509_NAME *in; | - | ||||||||||||||||||||||||
630 | - | |||||||||||||||||||||||||
631 | if (!xn || !name)
| 0-32 | ||||||||||||||||||||||||
632 | return (0); never executed: return (0); | 0 | ||||||||||||||||||||||||
633 | - | |||||||||||||||||||||||||
634 | if (*xn != name) {
| 0-32 | ||||||||||||||||||||||||
635 | in = X509_NAME_dup(name); | - | ||||||||||||||||||||||||
636 | if (in != NULL) {
| 0-32 | ||||||||||||||||||||||||
637 | X509_NAME_free(*xn); | - | ||||||||||||||||||||||||
638 | *xn = in; | - | ||||||||||||||||||||||||
639 | } executed 32 times by 3 tests: end of block Executed by:
| 32 | ||||||||||||||||||||||||
640 | } executed 32 times by 3 tests: end of block Executed by:
| 32 | ||||||||||||||||||||||||
641 | return (*xn != NULL); executed 32 times by 3 tests: return (*xn != ((void *)0) ); Executed by:
| 32 | ||||||||||||||||||||||||
642 | } | - | ||||||||||||||||||||||||
643 | - | |||||||||||||||||||||||||
644 | int | - | ||||||||||||||||||||||||
645 | X509_NAME_get0_der(X509_NAME *nm, const unsigned char **pder, size_t *pderlen) | - | ||||||||||||||||||||||||
646 | { | - | ||||||||||||||||||||||||
647 | /* Make sure encoding is valid. */ | - | ||||||||||||||||||||||||
648 | if (i2d_X509_NAME(nm, NULL) <= 0)
| 0 | ||||||||||||||||||||||||
649 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
650 | if (pder != NULL)
| 0 | ||||||||||||||||||||||||
651 | *pder = (unsigned char *)nm->bytes->data; never executed: *pder = (unsigned char *)nm->bytes->data; | 0 | ||||||||||||||||||||||||
652 | if (pderlen != NULL)
| 0 | ||||||||||||||||||||||||
653 | *pderlen = nm->bytes->length; never executed: *pderlen = nm->bytes->length; | 0 | ||||||||||||||||||||||||
654 | return 1; never executed: return 1; | 0 | ||||||||||||||||||||||||
655 | } | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |