OpenCoverage

ct_log.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ct/ct_log.c
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9struct ctlog_st {-
10 char *name;-
11 uint8_t log_id[32];-
12 EVP_PKEY *public_key;-
13};-
14-
15-
16-
17-
18-
19struct ctlog_store_st {-
20 struct stack_st_CTLOG *logs;-
21};-
22-
23-
24typedef struct ctlog_store_load_ctx_st {-
25 CTLOG_STORE *log_store;-
26 CONF *conf;-
27 size_t invalid_log_entries;-
28} CTLOG_STORE_LOAD_CTX;-
29-
30-
31-
32-
33-
34static CTLOG_STORE_LOAD_CTX *ctlog_store_load_ctx_new(void);-
35-
36-
37-
38-
39-
40static void ctlog_store_load_ctx_free(CTLOG_STORE_LOAD_CTX* ctx);-
41-
42static CTLOG_STORE_LOAD_CTX *ctlog_store_load_ctx_new(void)-
43{-
44 CTLOG_STORE_LOAD_CTX *ctx = CRYPTO_zalloc(sizeof(*ctx), __FILE__, 59);-
45-
46 if (ctx ==
ctx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1766 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1766
47 ((void *)0)
ctx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1766 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1766
48 )-
49 ERR_put_error(50,(122),((1|64)),__FILE__,62);
never executed: ERR_put_error(50,(122),((1|64)),__FILE__,62);
0
50-
51 return
executed 1766 times by 1 test: return ctx;
Executed by:
  • libcrypto.so.1.1
ctx;
executed 1766 times by 1 test: return ctx;
Executed by:
  • libcrypto.so.1.1
1766
52}-
53-
54static void ctlog_store_load_ctx_free(CTLOG_STORE_LOAD_CTX* ctx)-
55{-
56 CRYPTO_free(ctx, __FILE__, 69);-
57}
executed 1766 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1766
58-
59-
60static int ct_v1_log_id_from_pkey(EVP_PKEY *pkey,-
61 unsigned char log_id[32])-
62{-
63 int ret = 0;-
64 unsigned char *pkey_der = -
65 ((void *)0)-
66 ;-
67 int pkey_der_len = i2d_PUBKEY(pkey, &pkey_der);-
68-
69 if (pkey_der_len <= 0
pkey_der_len <= 0Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-14697
70 ERR_put_error(50,(125),(113),__FILE__,81);-
71 goto
never executed: goto err;
err;
never executed: goto err;
0
72 }-
73-
74 SHA256(pkey_der, pkey_der_len, log_id);-
75 ret = 1;-
76err:
code before this statement executed 14697 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
14697
77 CRYPTO_free(pkey_der, __FILE__, 88);-
78 return
executed 14697 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
ret;
executed 14697 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
14697
79}-
80-
81CTLOG_STORE *CTLOG_STORE_new(void)-
82{-
83 CTLOG_STORE *ret = CRYPTO_zalloc(sizeof(*ret), __FILE__, 94);-
84-
85 if (ret ==
ret == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 8025 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-8025
86 ((void *)0)
ret == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 8025 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-8025
87 ) {-
88 ERR_put_error(50,(131),((1|64)),__FILE__,97);-
89 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
90 ((void *)0)
never executed: return ((void *)0) ;
0
91 ;
never executed: return ((void *)0) ;
0
92 }-
93-
94 ret->logs = sk_CTLOG_new_null();-
95 if (ret->logs ==
ret->logs == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 8025 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-8025
96 ((void *)0)
ret->logs == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 8025 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-8025
97 )-
98 goto
never executed: goto err;
err;
never executed: goto err;
0
99-
100 return
executed 8025 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
ret;
executed 8025 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
8025
101err:-
102 CRYPTO_free(ret, __FILE__, 107);-
103 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
104 ((void *)0)
never executed: return ((void *)0) ;
0
105 ;
never executed: return ((void *)0) ;
0
106}-
107-
108void CTLOG_STORE_free(CTLOG_STORE *store)-
109{-
110 if (store !=
store != ((void *)0)Description
TRUEevaluated 8025 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-8025
111 ((void *)0)
store != ((void *)0)Description
TRUEevaluated 8025 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-8025
112 ) {-
113 sk_CTLOG_pop_free(store->logs, CTLOG_free);-
114 CRYPTO_free(store, __FILE__, 115);-
115 }
executed 8025 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
8025
116}
executed 8025 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
8025
117-
118static int ctlog_new_from_conf(CTLOG **ct_log, const CONF *conf, const char *section)-
119{-
120 const char *description = NCONF_get_string(conf, section, "description");-
121 char *pkey_base64;-
122-
123 if (description ==
description == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14697
124 ((void *)0)
description == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14697
125 ) {-
126 ERR_put_error(50,(119),(111),__FILE__,125);-
127 return
never executed: return 0;
0;
never executed: return 0;
0
128 }-
129-
130 pkey_base64 = NCONF_get_string(conf, section, "key");-
131 if (pkey_base64 ==
pkey_base64 == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14697
132 ((void *)0)
pkey_base64 == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14697
133 ) {-
134 ERR_put_error(50,(119),(112),__FILE__,131);-
135 return
never executed: return 0;
0;
never executed: return 0;
0
136 }-
137-
138 return
executed 14697 times by 1 test: return CTLOG_new_from_base64(ct_log, pkey_base64, description);
Executed by:
  • libcrypto.so.1.1
CTLOG_new_from_base64(ct_log, pkey_base64, description);
executed 14697 times by 1 test: return CTLOG_new_from_base64(ct_log, pkey_base64, description);
Executed by:
  • libcrypto.so.1.1
14697
139}-
140-
141int CTLOG_STORE_load_default_file(CTLOG_STORE *store)-
142{-
143 const char *fpath = getenv("CTLOG_FILE");-
144-
145 if (fpath ==
fpath == ((void *)0)Description
TRUEevaluated 133 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1633 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
133-1633
146 ((void *)0)
fpath == ((void *)0)Description
TRUEevaluated 133 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1633 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
133-1633
147 )-
148 fpath = "/usr/local/ssl" "/ct_log_list.cnf";
executed 133 times by 1 test: fpath = "/usr/local/ssl" "/ct_log_list.cnf";
Executed by:
  • libcrypto.so.1.1
133
149-
150 return
executed 1766 times by 1 test: return CTLOG_STORE_load_file(store, fpath);
Executed by:
  • libcrypto.so.1.1
CTLOG_STORE_load_file(store, fpath);
executed 1766 times by 1 test: return CTLOG_STORE_load_file(store, fpath);
Executed by:
  • libcrypto.so.1.1
1766
151}-
152-
153-
154-
155-
156-
157-
158-
159static int ctlog_store_load_log(const char *log_name, int log_name_len,-
160 void *arg)-
161{-
162 CTLOG_STORE_LOAD_CTX *load_ctx = arg;-
163 CTLOG *ct_log = -
164 ((void *)0)-
165 ;-
166-
167 char *tmp;-
168 int ret = 0;-
169-
170-
171 if (log_name ==
log_name == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14697
172 ((void *)0)
log_name == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14697
173 )-
174 return
never executed: return 1;
1;
never executed: return 1;
0
175-
176 tmp = CRYPTO_strndup(log_name, log_name_len, __FILE__, 167);-
177 if (tmp ==
tmp == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14697
178 ((void *)0)
tmp == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14697
179 )-
180 goto
never executed: goto mem_err;
mem_err;
never executed: goto mem_err;
0
181-
182 ret = ctlog_new_from_conf(&ct_log, load_ctx->conf, tmp);-
183 CRYPTO_free(tmp, __FILE__, 172);-
184-
185 if (ret < 0
ret < 0Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-14697
186-
187 return
never executed: return ret;
ret;
never executed: return ret;
0
188 }-
189 if (ret == 0
ret == 0Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-14697
190-
191 ++load_ctx->invalid_log_entries;-
192 return
never executed: return 1;
1;
never executed: return 1;
0
193 }-
194-
195 if (!sk_CTLOG_push(load_ctx->log_store->logs, ct_log)
!sk_CTLOG_push...>logs, ct_log)Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-14697
196 goto
never executed: goto mem_err;
mem_err;
never executed: goto mem_err;
0
197 }-
198 return
executed 14697 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
1;
executed 14697 times by 1 test: return 1;
Executed by:
  • libcrypto.so.1.1
14697
199-
200mem_err:-
201 CTLOG_free(ct_log);-
202 ERR_put_error(50,(130),((1|64)),__FILE__,191);-
203 return
never executed: return -1;
-1;
never executed: return -1;
0
204}-
205-
206int CTLOG_STORE_load_file(CTLOG_STORE *store, const char *file)-
207{-
208 int ret = 0;-
209 char *enabled_logs;-
210 CTLOG_STORE_LOAD_CTX* load_ctx = ctlog_store_load_ctx_new();-
211-
212 if (load_ctx ==
load_ctx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1766 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1766
213 ((void *)0)
load_ctx == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1766 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1766
214 )-
215 return
never executed: return 0;
0;
never executed: return 0;
0
216 load_ctx->log_store = store;-
217 load_ctx->conf = NCONF_new(-
218 ((void *)0)-
219 );-
220 if (load_ctx->conf ==
load_ctx->conf == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1766 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1766
221 ((void *)0)
load_ctx->conf == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1766 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1766
222 )-
223 goto
never executed: goto end;
end;
never executed: goto end;
0
224-
225 if (NCONF_load(load_ctx->conf, file,
NCONF_load(loa...id *)0) ) <= 0Description
TRUEevaluated 133 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1633 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
133-1633
226 ((void *)0)
NCONF_load(loa...id *)0) ) <= 0Description
TRUEevaluated 133 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1633 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
133-1633
227 ) <= 0
NCONF_load(loa...id *)0) ) <= 0Description
TRUEevaluated 133 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1633 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
133-1633
228 ERR_put_error(50,(123),(109),__FILE__,209);-
229 goto
executed 133 times by 1 test: goto end;
Executed by:
  • libcrypto.so.1.1
end;
executed 133 times by 1 test: goto end;
Executed by:
  • libcrypto.so.1.1
133
230 }-
231-
232 enabled_logs = NCONF_get_string(load_ctx->conf, -
233 ((void *)0)-
234 , "enabled_logs");-
235 if (enabled_logs ==
enabled_logs == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1633 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1633
236 ((void *)0)
enabled_logs == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 1633 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1633
237 ) {-
238 ERR_put_error(50,(123),(109),__FILE__,215);-
239 goto
never executed: goto end;
end;
never executed: goto end;
0
240 }-
241-
242 if (!CONF_parse_list(enabled_logs, ',', 1, ctlog_store_load_log, load_ctx)
!CONF_parse_li...log, load_ctx)Description
TRUEnever evaluated
FALSEevaluated 1633 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
||
0-1633
243 load_ctx->invalid_log_entries > 0
load_ctx->inva...og_entries > 0Description
TRUEnever evaluated
FALSEevaluated 1633 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
) {
0-1633
244 ERR_put_error(50,(123),(109),__FILE__,221);-
245 goto
never executed: goto end;
end;
never executed: goto end;
0
246 }-
247-
248 ret = 1;-
249end:
code before this statement executed 1633 times by 1 test: end:
Executed by:
  • libcrypto.so.1.1
1633
250 NCONF_free(load_ctx->conf);-
251 ctlog_store_load_ctx_free(load_ctx);-
252 return
executed 1766 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
ret;
executed 1766 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
1766
253}-
254-
255-
256-
257-
258-
259-
260CTLOG *CTLOG_new(EVP_PKEY *public_key, const char *name)-
261{-
262 CTLOG *ret = CRYPTO_zalloc(sizeof(*ret), __FILE__, 239);-
263-
264 if (ret ==
ret == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14697
265 ((void *)0)
ret == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14697
266 ) {-
267 ERR_put_error(50,(117),((1|64)),__FILE__,242);-
268 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
269 ((void *)0)
never executed: return ((void *)0) ;
0
270 ;
never executed: return ((void *)0) ;
0
271 }-
272-
273 ret->name = CRYPTO_strdup(name, __FILE__, 246);-
274 if (ret->name ==
ret->name == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14697
275 ((void *)0)
ret->name == ((void *)0)Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-14697
276 ) {-
277 ERR_put_error(50,(117),((1|64)),__FILE__,248);-
278 goto
never executed: goto err;
err;
never executed: goto err;
0
279 }-
280-
281 if (ct_v1_log_id_from_pkey(public_key, ret->log_id) != 1
ct_v1_log_id_f...->log_id) != 1Description
TRUEnever evaluated
FALSEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
0-14697
282 goto
never executed: goto err;
err;
never executed: goto err;
0
283-
284 ret->public_key = public_key;-
285 return
executed 14697 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
ret;
executed 14697 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
14697
286err:-
287 CTLOG_free(ret);-
288 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
289 ((void *)0)
never executed: return ((void *)0) ;
0
290 ;
never executed: return ((void *)0) ;
0
291}-
292-
293-
294void CTLOG_free(CTLOG *log)-
295{-
296 if (log !=
log != ((void *)0)Description
TRUEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-14697
297 ((void *)0)
log != ((void *)0)Description
TRUEevaluated 14697 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-14697
298 ) {-
299 CRYPTO_free(log->name, __FILE__, 266);-
300 EVP_PKEY_free(log->public_key);-
301 CRYPTO_free(log, __FILE__, 268);-
302 }
executed 14697 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
14697
303}
executed 14697 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
14697
304-
305const char *CTLOG_get0_name(const CTLOG *log)-
306{-
307 return
executed 2 times by 1 test: return log->name;
Executed by:
  • libcrypto.so.1.1
log->name;
executed 2 times by 1 test: return log->name;
Executed by:
  • libcrypto.so.1.1
2
308}-
309-
310void CTLOG_get0_log_id(const CTLOG *log, const uint8_t **log_id,-
311 size_t *log_id_len)-
312{-
313 *log_id = log->log_id;-
314 *log_id_len = 32;-
315}
never executed: end of block
0
316-
317EVP_PKEY *CTLOG_get0_public_key(const CTLOG *log)-
318{-
319 return
executed 9 times by 1 test: return log->public_key;
Executed by:
  • libcrypto.so.1.1
log->public_key;
executed 9 times by 1 test: return log->public_key;
Executed by:
  • libcrypto.so.1.1
9
320}-
321-
322-
323-
324-
325-
326const CTLOG *CTLOG_STORE_get0_log_by_id(const CTLOG_STORE *store,-
327 const uint8_t *log_id,-
328 size_t log_id_len)-
329{-
330 int i;-
331-
332 for (i = 0; i < sk_CTLOG_num(store->logs)
i < sk_CTLOG_num(store->logs)Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
; ++i) {
0-28
333 const CTLOG *log = sk_CTLOG_value(store->logs, i);-
334 if (memcmp(log->log_id, log_id, log_id_len) == 0
memcmp(log->lo...g_id_len) == 0Description
TRUEevaluated 11 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 17 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
)
11-17
335 return
executed 11 times by 1 test: return log;
Executed by:
  • libcrypto.so.1.1
log;
executed 11 times by 1 test: return log;
Executed by:
  • libcrypto.so.1.1
11
336 }
executed 17 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
17
337-
338 return
never executed: return ((void *)0) ;
never executed: return ((void *)0) ;
0
339 ((void *)0)
never executed: return ((void *)0) ;
0
340 ;
never executed: return ((void *)0) ;
0
341}-
Switch to Source codePreprocessed file

Generated by Squish Coco 4.2.2