OpenCoverage

x509_trs.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/x509/x509_trs.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2static int tr_cmp(const X509_TRUST *const *a, const X509_TRUST *const *b);-
3static void trtable_free(X509_TRUST *p);-
4-
5static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags);-
6static int trust_1oid(X509_TRUST *trust, X509 *x, int flags);-
7static int trust_compat(X509_TRUST *trust, X509 *x, int flags);-
8-
9static int obj_trust(int id, X509 *x, int flags);-
10static int (*default_trust) (int id, X509 *x, int flags) = obj_trust;-
11-
12-
13-
14-
15-
16-
17-
18static X509_TRUST trstandard[] = {-
19 {1, 0, trust_compat, "compatible", 0, -
20 ((void *)0)-
21 },-
22 {2, 0, trust_1oidany, "SSL Client", 130,-
23 -
24 ((void *)0)-
25 },-
26 {3, 0, trust_1oidany, "SSL Server", 129,-
27 -
28 ((void *)0)-
29 },-
30 {4, 0, trust_1oidany, "S/MIME email", 132,-
31 -
32 ((void *)0)-
33 },-
34 {5, 0, trust_1oidany, "Object Signer", 131,-
35 -
36 ((void *)0)-
37 },-
38 {6, 0, trust_1oid, "OCSP responder", 180,-
39 -
40 ((void *)0)-
41 },-
42 {7, 0, trust_1oid, "OCSP request", 178,-
43 -
44 ((void *)0)-
45 },-
46 {8, 0, trust_1oidany, "TSA server", 133, -
47 ((void *)0)-
48 }-
49};-
50-
51-
52-
53static struct stack_st_X509_TRUST *trtable = -
54 ((void *)0)-
55 ;-
56-
57static int tr_cmp(const X509_TRUST *const *a, const X509_TRUST *const *b)-
58{-
59 return
never executed: return (*a)->trust - (*b)->trust;
(*a)->trust - (*b)->trust;
never executed: return (*a)->trust - (*b)->trust;
0
60}-
61-
62int (*X509_TRUST_set_default(int (*trust) (int, X509 *, int))) (int, X509 *,-
63 int) {-
64 int (*oldtrust) (int, X509 *, int);-
65 oldtrust = default_trust;-
66 default_trust = trust;-
67 return
never executed: return oldtrust;
oldtrust;
never executed: return oldtrust;
0
68}-
69-
70int X509_check_trust(X509 *x, int id, int flags)-
71{-
72 X509_TRUST *pt;-
73 int idx;-
74-
75-
76 if (id == 0
id == 0Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2441 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
22-2441
77 return
executed 22 times by 1 test: return obj_trust(910, x, flags | (1U << 3));
Executed by:
  • libcrypto.so.1.1
obj_trust(910, x,
executed 22 times by 1 test: return obj_trust(910, x, flags | (1U << 3));
Executed by:
  • libcrypto.so.1.1
22
78 flags | (1U << 3));
executed 22 times by 1 test: return obj_trust(910, x, flags | (1U << 3));
Executed by:
  • libcrypto.so.1.1
22
79 idx = X509_TRUST_get_by_id(id);-
80 if (idx == -1
idx == -1Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2438 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
3-2438
81 return
executed 3 times by 1 test: return default_trust(id, x, flags);
Executed by:
  • libcrypto.so.1.1
default_trust(id, x, flags);
executed 3 times by 1 test: return default_trust(id, x, flags);
Executed by:
  • libcrypto.so.1.1
3
82 pt = X509_TRUST_get0(idx);-
83 return
executed 2438 times by 1 test: return pt->check_trust(pt, x, flags);
Executed by:
  • libcrypto.so.1.1
pt->check_trust(pt, x, flags);
executed 2438 times by 1 test: return pt->check_trust(pt, x, flags);
Executed by:
  • libcrypto.so.1.1
2438
84}-
85-
86int X509_TRUST_get_count(void)-
87{-
88 if (!trtable
!trtableDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
89 return
never executed: return (sizeof(trstandard)/sizeof((trstandard)[0]));
(sizeof(trstandard)/sizeof((trstandard)[0]));
never executed: return (sizeof(trstandard)/sizeof((trstandard)[0]));
0
90 return
never executed: return sk_X509_TRUST_num(trtable) + (sizeof(trstandard)/sizeof((trstandard)[0]));
sk_X509_TRUST_num(trtable) + (sizeof(trstandard)/sizeof((trstandard)[0]));
never executed: return sk_X509_TRUST_num(trtable) + (sizeof(trstandard)/sizeof((trstandard)[0]));
0
91}-
92-
93X509_TRUST *X509_TRUST_get0(int idx)-
94{-
95 if (idx < 0
idx < 0Description
TRUEnever evaluated
FALSEevaluated 2438 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-2438
96 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
97 ((void *)0)
never executed: return ((void *)0) ;
0
98 ;
never executed: return ((void *)0) ;
0
99 if (idx < (int)(sizeof(trstandard)/sizeof((trstandard)[0]))
idx < (int)(si...standard)[0]))Description
TRUEevaluated 2438 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
)
0-2438
100 return
executed 2438 times by 1 test: return trstandard + idx;
Executed by:
  • libcrypto.so.1.1
trstandard + idx;
executed 2438 times by 1 test: return trstandard + idx;
Executed by:
  • libcrypto.so.1.1
2438
101 return
never executed: return sk_X509_TRUST_value(trtable, idx - (sizeof(trstandard)/sizeof((trstandard)[0])));
sk_X509_TRUST_value(trtable, idx - (sizeof(trstandard)/sizeof((trstandard)[0])));
never executed: return sk_X509_TRUST_value(trtable, idx - (sizeof(trstandard)/sizeof((trstandard)[0])));
0
102}-
103-
104int X509_TRUST_get_by_id(int id)-
105{-
106 X509_TRUST tmp;-
107 int idx;-
108-
109 if ((
(id >= 1)Description
TRUEevaluated 2466 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
id >= 1)
(id >= 1)Description
TRUEevaluated 2466 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
&& (
(id <= 8)Description
TRUEevaluated 2463 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
id <= 8)
(id <= 8)Description
TRUEevaluated 2463 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-2466
110 return
executed 2463 times by 1 test: return id - 1;
Executed by:
  • libcrypto.so.1.1
id - 1;
executed 2463 times by 1 test: return id - 1;
Executed by:
  • libcrypto.so.1.1
2463
111 if (trtable ==
trtable == ((void *)0)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-3
112 ((void *)0)
trtable == ((void *)0)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-3
113 )-
114 return
executed 3 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
-1;
executed 3 times by 1 test: return -1;
Executed by:
  • libcrypto.so.1.1
3
115 tmp.trust = id;-
116 idx = sk_X509_TRUST_find(trtable, &tmp);-
117 if (idx < 0
idx < 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
118 return
never executed: return -1;
-1;
never executed: return -1;
0
119 return
never executed: return idx + (sizeof(trstandard)/sizeof((trstandard)[0]));
idx + (sizeof(trstandard)/sizeof((trstandard)[0]));
never executed: return idx + (sizeof(trstandard)/sizeof((trstandard)[0]));
0
120}-
121-
122int X509_TRUST_set(int *t, int trust)-
123{-
124 if (X509_TRUST_get_by_id(trust) == -1
X509_TRUST_get...d(trust) == -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
125 ERR_put_error(11,(141),(123),__FILE__,116);-
126 return
never executed: return 0;
0;
never executed: return 0;
0
127 }-
128 *t = trust;-
129 return
never executed: return 1;
1;
never executed: return 1;
0
130}-
131-
132int X509_TRUST_add(int id, int flags, int (*ck) (X509_TRUST *, X509 *, int),-
133 const char *name, int arg1, void *arg2)-
134{-
135 int idx;-
136 X509_TRUST *trtmp;-
137-
138-
139-
140 flags &= ~(1U << 0);-
141-
142 flags |= (1U << 1);-
143-
144 idx = X509_TRUST_get_by_id(id);-
145-
146 if (idx == -1
idx == -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
147 if ((
(trtmp = CRYPT...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
trtmp = CRYPTO_malloc(sizeof(*trtmp), __FILE__, 138)) ==
(trtmp = CRYPT...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
148 ((void *)0)
(trtmp = CRYPT...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
149 ) {-
150 ERR_put_error(11,(133),((1|64)),__FILE__,139);-
151 return
never executed: return 0;
0;
never executed: return 0;
0
152 }-
153 trtmp->flags = (1U << 0);-
154 }
never executed: end of block
else
0
155 trtmp = X509_TRUST_get0(idx);
never executed: trtmp = X509_TRUST_get0(idx);
0
156-
157-
158 if (trtmp->flags & (1U << 1)
trtmp->flags & (1U << 1)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
159 CRYPTO_free(trtmp->name, __FILE__, 148);
never executed: CRYPTO_free(trtmp->name, __FILE__, 148);
0
160-
161 if ((
(trtmp->name =...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
trtmp->name = CRYPTO_strdup(name, __FILE__, 150)) ==
(trtmp->name =...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
162 ((void *)0)
(trtmp->name =...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
163 ) {-
164 ERR_put_error(11,(133),((1|64)),__FILE__,151);-
165 goto
never executed: goto err;
err;
never executed: goto err;
0
166 }-
167-
168 trtmp->flags &= (1U << 0);-
169-
170 trtmp->flags |= flags;-
171-
172 trtmp->trust = id;-
173 trtmp->check_trust = ck;-
174 trtmp->arg1 = arg1;-
175 trtmp->arg2 = arg2;-
176-
177-
178 if (idx == -1
idx == -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
179 if (trtable ==
trtable == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
180 ((void *)0)
trtable == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
181 -
182 && (
(trtable = sk_...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
trtable = sk_X509_TRUST_new(tr_cmp)) ==
(trtable = sk_...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
183 ((void *)0)
(trtable = sk_...== ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
184 ) {-
185 ERR_put_error(11,(133),((1|64)),__FILE__,168);-
186 goto
never executed: goto err;
err;
never executed: goto err;
;
0
187 }-
188 if (!sk_X509_TRUST_push(trtable, trtmp)
!sk_X509_TRUST...rtable, trtmp)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
189 ERR_put_error(11,(133),((1|64)),__FILE__,172);-
190 goto
never executed: goto err;
err;
never executed: goto err;
0
191 }-
192 }
never executed: end of block
0
193 return
never executed: return 1;
1;
never executed: return 1;
0
194 err:-
195 if (idx == -1
idx == -1Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
196 CRYPTO_free(trtmp->name, __FILE__, 179);-
197 CRYPTO_free(trtmp, __FILE__, 180);-
198 }
never executed: end of block
0
199 return
never executed: return 0;
0;
never executed: return 0;
0
200}-
201-
202static void trtable_free(X509_TRUST *p)-
203{-
204 if (!p
!pDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
205 return;
never executed: return;
0
206 if (p->flags & (1U << 0)
p->flags & (1U << 0)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
207 if (p->flags & (1U << 1)
p->flags & (1U << 1)Description
TRUEnever evaluated
FALSEnever evaluated
)
0
208 CRYPTO_free(p->name, __FILE__, 191);
never executed: CRYPTO_free(p->name, __FILE__, 191);
0
209 CRYPTO_free(p, __FILE__, 192);-
210 }
never executed: end of block
0
211}
never executed: end of block
0
212-
213void X509_TRUST_cleanup(void)-
214{-
215 sk_X509_TRUST_pop_free(trtable, trtable_free);-
216 trtable = -
217 ((void *)0)-
218 ;-
219}
never executed: end of block
0
220-
221int X509_TRUST_get_flags(const X509_TRUST *xp)-
222{-
223 return
never executed: return xp->flags;
xp->flags;
never executed: return xp->flags;
0
224}-
225-
226char *X509_TRUST_get0_name(const X509_TRUST *xp)-
227{-
228 return
never executed: return xp->name;
xp->name;
never executed: return xp->name;
0
229}-
230-
231int X509_TRUST_get_trust(const X509_TRUST *xp)-
232{-
233 return
never executed: return xp->trust;
xp->trust;
never executed: return xp->trust;
0
234}-
235-
236static int trust_1oidany(X509_TRUST *trust, X509 *x, int flags)-
237{-
238-
239-
240-
241-
242-
243-
244 flags |= (1U << 3) | (1U << 4);-
245 return
executed 2394 times by 1 test: return obj_trust(trust->arg1, x, flags);
Executed by:
  • libcrypto.so.1.1
obj_trust(trust->arg1, x, flags);
executed 2394 times by 1 test: return obj_trust(trust->arg1, x, flags);
Executed by:
  • libcrypto.so.1.1
2394
246}-
247-
248static int trust_1oid(X509_TRUST *trust, X509 *x, int flags)-
249{-
250-
251-
252-
253-
254-
255 flags &= ~((1U << 3) | (1U << 4));-
256 return
never executed: return obj_trust(trust->arg1, x, flags);
obj_trust(trust->arg1, x, flags);
never executed: return obj_trust(trust->arg1, x, flags);
0
257}-
258-
259static int trust_compat(X509_TRUST *trust, X509 *x, int flags)-
260{-
261-
262 X509_check_purpose(x, -1, 0);-
263 if ((
(flags & (1U << 2)) == 0Description
TRUEevaluated 1192 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1194 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
flags & (1U << 2)) == 0
(flags & (1U << 2)) == 0Description
TRUEevaluated 1192 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1194 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
&& x->ex_flags & 0x2000
x->ex_flags & 0x2000Description
TRUEevaluated 1168 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 24 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
24-1194
264 return
executed 1168 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 1168 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1168
265 else-
266 return
executed 1218 times by 1 test: return 3;
Executed by:
  • libcrypto.so.1.1
3;
executed 1218 times by 1 test: return 3;
Executed by:
  • libcrypto.so.1.1
1218
267}-
268-
269static int obj_trust(int id, X509 *x, int flags)-
270{-
271 X509_CERT_AUX *ax = x->aux;-
272 int i;-
273-
274 if (ax
axDescription
TRUEevaluated 84 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2335 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
&& ax->reject
ax->rejectDescription
TRUEevaluated 27 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 57 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
27-2335
275 for (i = 0; i < sk_ASN1_OBJECT_num(ax->reject)
i < sk_ASN1_OB...um(ax->reject)Description
TRUEevaluated 27 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
; i++) {
10-27
276 ASN1_OBJECT *obj = sk_ASN1_OBJECT_value(ax->reject, i);-
277 int nid = OBJ_obj2nid(obj);-
278-
279 if (nid == id
nid == idDescription
TRUEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 17 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| (nid == 910
nid == 910Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
&&
7-17
280 (
(flags & (1U << 4))Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
flags & (1U << 4))
(flags & (1U << 4))Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
))
0-7
281 return
executed 17 times by 1 test: return 2;
Executed by:
  • libcrypto.so.1.1
2;
executed 17 times by 1 test: return 2;
Executed by:
  • libcrypto.so.1.1
17
282 }
executed 10 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
10
283 }
executed 10 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
10
284-
285 if (ax
axDescription
TRUEevaluated 67 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2335 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
&& ax->trust
ax->trustDescription
TRUEevaluated 57 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 10 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
10-2335
286 for (i = 0; i < sk_ASN1_OBJECT_num(ax->trust)
i < sk_ASN1_OB...num(ax->trust)Description
TRUEevaluated 57 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
; i++) {
9-57
287 ASN1_OBJECT *obj = sk_ASN1_OBJECT_value(ax->trust, i);-
288 int nid = OBJ_obj2nid(obj);-
289-
290 if (nid == id
nid == idDescription
TRUEevaluated 28 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 29 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
|| (nid == 910
nid == 910Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 9 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
&&
9-29
291 (
(flags & (1U << 4))Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
flags & (1U << 4))
(flags & (1U << 4))Description
TRUEevaluated 20 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
))
0-20
292 return
executed 48 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 48 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
48
293 }
executed 9 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
9
294 return
executed 9 times by 1 test: return 2;
Executed by:
  • libcrypto.so.1.1
2;
executed 9 times by 1 test: return 2;
Executed by:
  • libcrypto.so.1.1
9
295 }-
296-
297 if ((
(flags & (1U << 3)) == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2342 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
flags & (1U << 3)) == 0
(flags & (1U << 3)) == 0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2342 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
3-2342
298 return
executed 3 times by 1 test: return 3;
Executed by:
  • libcrypto.so.1.1
3;
executed 3 times by 1 test: return 3;
Executed by:
  • libcrypto.so.1.1
3
299-
300-
301-
302-
303 return
executed 2342 times by 1 test: return trust_compat( ((void *)0) , x, flags);
Executed by:
  • libcrypto.so.1.1
trust_compat(
executed 2342 times by 1 test: return trust_compat( ((void *)0) , x, flags);
Executed by:
  • libcrypto.so.1.1
2342
304 ((void *)0)
executed 2342 times by 1 test: return trust_compat( ((void *)0) , x, flags);
Executed by:
  • libcrypto.so.1.1
2342
305 , x, flags);
executed 2342 times by 1 test: return trust_compat( ((void *)0) , x, flags);
Executed by:
  • libcrypto.so.1.1
2342
306}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2