Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/ct/ct_log.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | - | |||||||
6 | - | |||||||
7 | - | |||||||
8 | - | |||||||
9 | struct ctlog_st { | - | ||||||
10 | char *name; | - | ||||||
11 | uint8_t log_id[32]; | - | ||||||
12 | EVP_PKEY *public_key; | - | ||||||
13 | }; | - | ||||||
14 | - | |||||||
15 | - | |||||||
16 | - | |||||||
17 | - | |||||||
18 | - | |||||||
19 | struct ctlog_store_st { | - | ||||||
20 | struct stack_st_CTLOG *logs; | - | ||||||
21 | }; | - | ||||||
22 | - | |||||||
23 | - | |||||||
24 | typedef 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 | - | |||||||
34 | static CTLOG_STORE_LOAD_CTX *ctlog_store_load_ctx_new(void); | - | ||||||
35 | - | |||||||
36 | - | |||||||
37 | - | |||||||
38 | - | |||||||
39 | - | |||||||
40 | static void ctlog_store_load_ctx_free(CTLOG_STORE_LOAD_CTX* ctx); | - | ||||||
41 | - | |||||||
42 | static 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 ==
| 0-1766 | ||||||
47 | ((void *)0)
| 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: ctx;return ctx; Executed by:
executed 1766 times by 1 test: return ctx; Executed by:
| 1766 | ||||||
52 | } | - | ||||||
53 | - | |||||||
54 | static 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:
| 1766 | ||||||
58 | - | |||||||
59 | - | |||||||
60 | static 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
| 0-14697 | ||||||
70 | ERR_put_error(50,(125),(113),__FILE__,81); | - | ||||||
71 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||
72 | } | - | ||||||
73 | - | |||||||
74 | SHA256(pkey_der, pkey_der_len, log_id); | - | ||||||
75 | ret = 1; | - | ||||||
76 | err: code before this statement executed 14697 times by 1 test: err: Executed by:
| 14697 | ||||||
77 | CRYPTO_free(pkey_der, __FILE__, 88); | - | ||||||
78 | return executed 14697 times by 1 test: ret;return ret; Executed by:
executed 14697 times by 1 test: return ret; Executed by:
| 14697 | ||||||
79 | } | - | ||||||
80 | - | |||||||
81 | CTLOG_STORE *CTLOG_STORE_new(void) | - | ||||||
82 | { | - | ||||||
83 | CTLOG_STORE *ret = CRYPTO_zalloc(sizeof(*ret), __FILE__, 94); | - | ||||||
84 | - | |||||||
85 | if (ret ==
| 0-8025 | ||||||
86 | ((void *)0)
| 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 ==
| 0-8025 | ||||||
96 | ((void *)0)
| 0-8025 | ||||||
97 | ) | - | ||||||
98 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||
99 | - | |||||||
100 | return executed 8025 times by 1 test: ret;return ret; Executed by:
executed 8025 times by 1 test: return ret; Executed by:
| 8025 | ||||||
101 | err: | - | ||||||
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 | - | |||||||
108 | void CTLOG_STORE_free(CTLOG_STORE *store) | - | ||||||
109 | { | - | ||||||
110 | if (store !=
| 0-8025 | ||||||
111 | ((void *)0)
| 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:
| 8025 | ||||||
116 | } executed 8025 times by 1 test: end of block Executed by:
| 8025 | ||||||
117 | - | |||||||
118 | static 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 ==
| 0-14697 | ||||||
124 | ((void *)0)
| 0-14697 | ||||||
125 | ) { | - | ||||||
126 | ERR_put_error(50,(119),(111),__FILE__,125); | - | ||||||
127 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||
128 | } | - | ||||||
129 | - | |||||||
130 | pkey_base64 = NCONF_get_string(conf, section, "key"); | - | ||||||
131 | if (pkey_base64 ==
| 0-14697 | ||||||
132 | ((void *)0)
| 0-14697 | ||||||
133 | ) { | - | ||||||
134 | ERR_put_error(50,(119),(112),__FILE__,131); | - | ||||||
135 | return never executed: 0;return 0; never executed: return 0; | 0 | ||||||
136 | } | - | ||||||
137 | - | |||||||
138 | return executed 14697 times by 1 test: CTLOG_new_from_base64(ct_log, pkey_base64, description);return CTLOG_new_from_base64(ct_log, pkey_base64, description); Executed by:
executed 14697 times by 1 test: return CTLOG_new_from_base64(ct_log, pkey_base64, description); Executed by:
| 14697 | ||||||
139 | } | - | ||||||
140 | - | |||||||
141 | int CTLOG_STORE_load_default_file(CTLOG_STORE *store) | - | ||||||
142 | { | - | ||||||
143 | const char *fpath = getenv("CTLOG_FILE"); | - | ||||||
144 | - | |||||||
145 | if (fpath ==
| 133-1633 | ||||||
146 | ((void *)0)
| 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:
| 133 | ||||||
149 | - | |||||||
150 | return executed 1766 times by 1 test: CTLOG_STORE_load_file(store, fpath);return CTLOG_STORE_load_file(store, fpath); Executed by:
executed 1766 times by 1 test: return CTLOG_STORE_load_file(store, fpath); Executed by:
| 1766 | ||||||
151 | } | - | ||||||
152 | - | |||||||
153 | - | |||||||
154 | - | |||||||
155 | - | |||||||
156 | - | |||||||
157 | - | |||||||
158 | - | |||||||
159 | static 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 ==
| 0-14697 | ||||||
172 | ((void *)0)
| 0-14697 | ||||||
173 | ) | - | ||||||
174 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||
175 | - | |||||||
176 | tmp = CRYPTO_strndup(log_name, log_name_len, __FILE__, 167); | - | ||||||
177 | if (tmp ==
| 0-14697 | ||||||
178 | ((void *)0)
| 0-14697 | ||||||
179 | ) | - | ||||||
180 | goto never executed: mem_err;goto 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
| 0-14697 | ||||||
186 | - | |||||||
187 | return never executed: ret;return ret; never executed: return ret; | 0 | ||||||
188 | } | - | ||||||
189 | if (ret == 0
| 0-14697 | ||||||
190 | - | |||||||
191 | ++load_ctx->invalid_log_entries; | - | ||||||
192 | return never executed: 1;return 1; never executed: return 1; | 0 | ||||||
193 | } | - | ||||||
194 | - | |||||||
195 | if (!sk_CTLOG_push(load_ctx->log_store->logs, ct_log)
| 0-14697 | ||||||
196 | goto never executed: mem_err;goto mem_err; never executed: goto mem_err; | 0 | ||||||
197 | } | - | ||||||
198 | return executed 14697 times by 1 test: 1;return 1; Executed by:
executed 14697 times by 1 test: return 1; Executed by:
| 14697 | ||||||
199 | - | |||||||
200 | mem_err: | - | ||||||
201 | CTLOG_free(ct_log); | - | ||||||
202 | ERR_put_error(50,(130),((1|64)),__FILE__,191); | - | ||||||
203 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||
204 | } | - | ||||||
205 | - | |||||||
206 | int 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 ==
| 0-1766 | ||||||
213 | ((void *)0)
| 0-1766 | ||||||
214 | ) | - | ||||||
215 | return never executed: 0;return 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 ==
| 0-1766 | ||||||
221 | ((void *)0)
| 0-1766 | ||||||
222 | ) | - | ||||||
223 | goto never executed: end;goto end; never executed: goto end; | 0 | ||||||
224 | - | |||||||
225 | if (NCONF_load(load_ctx->conf, file,
| 133-1633 | ||||||
226 | ((void *)0)
| 133-1633 | ||||||
227 | ) <= 0
| 133-1633 | ||||||
228 | ERR_put_error(50,(123),(109),__FILE__,209); | - | ||||||
229 | goto executed 133 times by 1 test: end;goto end; Executed by:
executed 133 times by 1 test: goto end; Executed by:
| 133 | ||||||
230 | } | - | ||||||
231 | - | |||||||
232 | enabled_logs = NCONF_get_string(load_ctx->conf, | - | ||||||
233 | ((void *)0) | - | ||||||
234 | , "enabled_logs"); | - | ||||||
235 | if (enabled_logs ==
| 0-1633 | ||||||
236 | ((void *)0)
| 0-1633 | ||||||
237 | ) { | - | ||||||
238 | ERR_put_error(50,(123),(109),__FILE__,215); | - | ||||||
239 | goto never executed: end;goto end; never executed: goto end; | 0 | ||||||
240 | } | - | ||||||
241 | - | |||||||
242 | if (!CONF_parse_list(enabled_logs, ',', 1, ctlog_store_load_log, load_ctx)
| 0-1633 | ||||||
243 | load_ctx->invalid_log_entries > 0
| 0-1633 | ||||||
244 | ERR_put_error(50,(123),(109),__FILE__,221); | - | ||||||
245 | goto never executed: end;goto end; never executed: goto end; | 0 | ||||||
246 | } | - | ||||||
247 | - | |||||||
248 | ret = 1; | - | ||||||
249 | end: code before this statement executed 1633 times by 1 test: end: Executed by:
| 1633 | ||||||
250 | NCONF_free(load_ctx->conf); | - | ||||||
251 | ctlog_store_load_ctx_free(load_ctx); | - | ||||||
252 | return executed 1766 times by 1 test: ret;return ret; Executed by:
executed 1766 times by 1 test: return ret; Executed by:
| 1766 | ||||||
253 | } | - | ||||||
254 | - | |||||||
255 | - | |||||||
256 | - | |||||||
257 | - | |||||||
258 | - | |||||||
259 | - | |||||||
260 | CTLOG *CTLOG_new(EVP_PKEY *public_key, const char *name) | - | ||||||
261 | { | - | ||||||
262 | CTLOG *ret = CRYPTO_zalloc(sizeof(*ret), __FILE__, 239); | - | ||||||
263 | - | |||||||
264 | if (ret ==
| 0-14697 | ||||||
265 | ((void *)0)
| 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 ==
| 0-14697 | ||||||
275 | ((void *)0)
| 0-14697 | ||||||
276 | ) { | - | ||||||
277 | ERR_put_error(50,(117),((1|64)),__FILE__,248); | - | ||||||
278 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||
279 | } | - | ||||||
280 | - | |||||||
281 | if (ct_v1_log_id_from_pkey(public_key, ret->log_id) != 1
| 0-14697 | ||||||
282 | goto never executed: err;goto err; never executed: goto err; | 0 | ||||||
283 | - | |||||||
284 | ret->public_key = public_key; | - | ||||||
285 | return executed 14697 times by 1 test: ret;return ret; Executed by:
executed 14697 times by 1 test: return ret; Executed by:
| 14697 | ||||||
286 | err: | - | ||||||
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 | - | |||||||
294 | void CTLOG_free(CTLOG *log) | - | ||||||
295 | { | - | ||||||
296 | if (log !=
| 0-14697 | ||||||
297 | ((void *)0)
| 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:
| 14697 | ||||||
303 | } executed 14697 times by 1 test: end of block Executed by:
| 14697 | ||||||
304 | - | |||||||
305 | const char *CTLOG_get0_name(const CTLOG *log) | - | ||||||
306 | { | - | ||||||
307 | return executed 2 times by 1 test: log->name;return log->name; Executed by:
executed 2 times by 1 test: return log->name; Executed by:
| 2 | ||||||
308 | } | - | ||||||
309 | - | |||||||
310 | void 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 | - | |||||||
317 | EVP_PKEY *CTLOG_get0_public_key(const CTLOG *log) | - | ||||||
318 | { | - | ||||||
319 | return executed 9 times by 1 test: log->public_key;return log->public_key; Executed by:
executed 9 times by 1 test: return log->public_key; Executed by:
| 9 | ||||||
320 | } | - | ||||||
321 | - | |||||||
322 | - | |||||||
323 | - | |||||||
324 | - | |||||||
325 | - | |||||||
326 | const 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)
| 0-28 | ||||||
333 | const CTLOG *log = sk_CTLOG_value(store->logs, i); | - | ||||||
334 | if (memcmp(log->log_id, log_id, log_id_len) == 0
| 11-17 | ||||||
335 | return executed 11 times by 1 test: log;return log; Executed by:
executed 11 times by 1 test: return log; Executed by:
| 11 | ||||||
336 | } executed 17 times by 1 test: end of block Executed by:
| 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 code | Preprocessed file |