OpenCoverage

by_file.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/x509/by_file.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.-
3 *-
4 * Licensed under the OpenSSL license (the "License"). You may not use-
5 * this file except in compliance with the License. You can obtain a copy-
6 * in the file LICENSE in the source distribution or at-
7 * https://www.openssl.org/source/license.html-
8 */-
9-
10#include <stdio.h>-
11#include <time.h>-
12#include <errno.h>-
13-
14#include "internal/cryptlib.h"-
15#include <openssl/buffer.h>-
16#include <openssl/x509.h>-
17#include <openssl/pem.h>-
18#include "x509_lcl.h"-
19-
20static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc,-
21 long argl, char **ret);-
22static X509_LOOKUP_METHOD x509_file_lookup = {-
23 "Load file into cache",-
24 NULL, /* new_item */-
25 NULL, /* free */-
26 NULL, /* init */-
27 NULL, /* shutdown */-
28 by_file_ctrl, /* ctrl */-
29 NULL, /* get_by_subject */-
30 NULL, /* get_by_issuer_serial */-
31 NULL, /* get_by_fingerprint */-
32 NULL, /* get_by_alias */-
33};-
34-
35X509_LOOKUP_METHOD *X509_LOOKUP_file(void)-
36{-
37 return &x509_file_lookup;
executed 1801 times by 1 test: return &x509_file_lookup;
Executed by:
  • libcrypto.so.1.1
1801
38}-
39-
40static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp,-
41 long argl, char **ret)-
42{-
43 int ok = 0;-
44 const char *file;-
45-
46 switch (cmd) {-
47 case X509_L_FILE_LOAD:
executed 1800 times by 1 test: case 1:
Executed by:
  • libcrypto.so.1.1
1800
48 if (argl == X509_FILETYPE_DEFAULT) {
argl == 3Description
TRUEevaluated 442 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1358 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
442-1358
49 file = getenv(X509_get_default_cert_file_env());-
50 if (file)
fileDescription
TRUEnever evaluated
FALSEevaluated 442 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-442
51 ok = (X509_load_cert_crl_file(ctx, file,
never executed: ok = (X509_load_cert_crl_file(ctx, file, 1) != 0);
0
52 X509_FILETYPE_PEM) != 0);
never executed: ok = (X509_load_cert_crl_file(ctx, file, 1) != 0);
0
53-
54 else-
55 ok = (X509_load_cert_crl_file
executed 442 times by 1 test: ok = (X509_load_cert_crl_file (ctx, X509_get_default_cert_file(), 1) != 0);
Executed by:
  • libcrypto.so.1.1
442
56 (ctx, X509_get_default_cert_file(),
executed 442 times by 1 test: ok = (X509_load_cert_crl_file (ctx, X509_get_default_cert_file(), 1) != 0);
Executed by:
  • libcrypto.so.1.1
442
57 X509_FILETYPE_PEM) != 0);
executed 442 times by 1 test: ok = (X509_load_cert_crl_file (ctx, X509_get_default_cert_file(), 1) != 0);
Executed by:
  • libcrypto.so.1.1
442
58-
59 if (!ok) {
!okDescription
TRUEevaluated 442 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-442
60 X509err(X509_F_BY_FILE_CTRL, X509_R_LOADING_DEFAULTS);-
61 }
executed 442 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
442
62 } else {
executed 442 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
442
63 if (argl == X509_FILETYPE_PEM)
argl == 1Description
TRUEevaluated 1358 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1358
64 ok = (X509_load_cert_crl_file(ctx, argp,
executed 1358 times by 1 test: ok = (X509_load_cert_crl_file(ctx, argp, 1) != 0);
Executed by:
  • libcrypto.so.1.1
1358
65 X509_FILETYPE_PEM) != 0);
executed 1358 times by 1 test: ok = (X509_load_cert_crl_file(ctx, argp, 1) != 0);
Executed by:
  • libcrypto.so.1.1
1358
66 else-
67 ok = (X509_load_cert_file(ctx, argp, (int)argl) != 0);
never executed: ok = (X509_load_cert_file(ctx, argp, (int)argl) != 0);
0
68 }-
69 break;
executed 1800 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
1800
70 }-
71 return ok;
executed 1800 times by 1 test: return ok;
Executed by:
  • libcrypto.so.1.1
1800
72}-
73-
74int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)-
75{-
76 int ret = 0;-
77 BIO *in = NULL;-
78 int i, count = 0;-
79 X509 *x = NULL;-
80-
81 in = BIO_new(BIO_s_file());-
82-
83 if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) {
(in == ((void *)0) )Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
((int)BIO_ctrl...)(file)) <= 0)Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
84 X509err(X509_F_X509_LOAD_CERT_FILE, ERR_R_SYS_LIB);-
85 goto err;
never executed: goto err;
0
86 }-
87-
88 if (type == X509_FILETYPE_PEM) {
type == 1Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
89 for (;;) {-
90 x = PEM_read_bio_X509_AUX(in, NULL, NULL, "");-
91 if (x == NULL) {
x == ((void *)0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
2
92 if ((ERR_GET_REASON(ERR_peek_last_error()) ==
((int)( (ERR_p...xFFFL) == 108)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
93 PEM_R_NO_START_LINE) && (count > 0)) {
((int)( (ERR_p...xFFFL) == 108)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
(count > 0)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-2
94 ERR_clear_error();-
95 break;
executed 2 times by 1 test: break;
Executed by:
  • libcrypto.so.1.1
2
96 } else {-
97 X509err(X509_F_X509_LOAD_CERT_FILE, ERR_R_PEM_LIB);-
98 goto err;
never executed: goto err;
0
99 }-
100 }-
101 i = X509_STORE_add_cert(ctx->store_ctx, x);-
102 if (!i)
!iDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
103 goto err;
never executed: goto err;
0
104 count++;-
105 X509_free(x);-
106 x = NULL;-
107 }
executed 2 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
2
108 ret = count;-
109 } else if (type == X509_FILETYPE_ASN1) {
executed 2 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
type == 2Description
TRUEnever evaluated
FALSEnever evaluated
0-2
110 x = d2i_X509_bio(in, NULL);-
111 if (x == NULL) {
x == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
112 X509err(X509_F_X509_LOAD_CERT_FILE, ERR_R_ASN1_LIB);-
113 goto err;
never executed: goto err;
0
114 }-
115 i = X509_STORE_add_cert(ctx->store_ctx, x);-
116 if (!i)
!iDescription
TRUEnever evaluated
FALSEnever evaluated
0
117 goto err;
never executed: goto err;
0
118 ret = i;-
119 } else {
never executed: end of block
0
120 X509err(X509_F_X509_LOAD_CERT_FILE, X509_R_BAD_X509_FILETYPE);-
121 goto err;
never executed: goto err;
0
122 }-
123 if (ret == 0)
ret == 0Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-2
124 X509err(X509_F_X509_LOAD_CERT_FILE, X509_R_NO_CERTIFICATE_FOUND);
never executed: ERR_put_error(11,(111),(135),__FILE__,124);
0
125 err:
code before this statement executed 2 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
2
126 X509_free(x);-
127 BIO_free(in);-
128 return ret;
executed 2 times by 1 test: return ret;
Executed by:
  • libcrypto.so.1.1
2
129}-
130-
131int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type)-
132{-
133 int ret = 0;-
134 BIO *in = NULL;-
135 int i, count = 0;-
136 X509_CRL *x = NULL;-
137-
138 in = BIO_new(BIO_s_file());-
139-
140 if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) {
(in == ((void *)0) )Description
TRUEnever evaluated
FALSEnever evaluated
((int)BIO_ctrl...)(file)) <= 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
141 X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_SYS_LIB);-
142 goto err;
never executed: goto err;
0
143 }-
144-
145 if (type == X509_FILETYPE_PEM) {
type == 1Description
TRUEnever evaluated
FALSEnever evaluated
0
146 for (;;) {-
147 x = PEM_read_bio_X509_CRL(in, NULL, NULL, "");-
148 if (x == NULL) {
x == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
149 if ((ERR_GET_REASON(ERR_peek_last_error()) ==
((int)( (ERR_p...xFFFL) == 108)Description
TRUEnever evaluated
FALSEnever evaluated
0
150 PEM_R_NO_START_LINE) && (count > 0)) {
((int)( (ERR_p...xFFFL) == 108)Description
TRUEnever evaluated
FALSEnever evaluated
(count > 0)Description
TRUEnever evaluated
FALSEnever evaluated
0
151 ERR_clear_error();-
152 break;
never executed: break;
0
153 } else {-
154 X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_PEM_LIB);-
155 goto err;
never executed: goto err;
0
156 }-
157 }-
158 i = X509_STORE_add_crl(ctx->store_ctx, x);-
159 if (!i)
!iDescription
TRUEnever evaluated
FALSEnever evaluated
0
160 goto err;
never executed: goto err;
0
161 count++;-
162 X509_CRL_free(x);-
163 x = NULL;-
164 }
never executed: end of block
0
165 ret = count;-
166 } else if (type == X509_FILETYPE_ASN1) {
never executed: end of block
type == 2Description
TRUEnever evaluated
FALSEnever evaluated
0
167 x = d2i_X509_CRL_bio(in, NULL);-
168 if (x == NULL) {
x == ((void *)0)Description
TRUEnever evaluated
FALSEnever evaluated
0
169 X509err(X509_F_X509_LOAD_CRL_FILE, ERR_R_ASN1_LIB);-
170 goto err;
never executed: goto err;
0
171 }-
172 i = X509_STORE_add_crl(ctx->store_ctx, x);-
173 if (!i)
!iDescription
TRUEnever evaluated
FALSEnever evaluated
0
174 goto err;
never executed: goto err;
0
175 ret = i;-
176 } else {
never executed: end of block
0
177 X509err(X509_F_X509_LOAD_CRL_FILE, X509_R_BAD_X509_FILETYPE);-
178 goto err;
never executed: goto err;
0
179 }-
180 if (ret == 0)
ret == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
181 X509err(X509_F_X509_LOAD_CRL_FILE, X509_R_NO_CRL_FOUND);
never executed: ERR_put_error(11,(112),(137),__FILE__,181);
0
182 err:
code before this statement never executed: err:
0
183 X509_CRL_free(x);-
184 BIO_free(in);-
185 return ret;
never executed: return ret;
0
186}-
187-
188int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type)-
189{-
190 STACK_OF(X509_INFO) *inf;-
191 X509_INFO *itmp;-
192 BIO *in;-
193 int i, count = 0;-
194-
195 if (type != X509_FILETYPE_PEM)
type != 1Description
TRUEnever evaluated
FALSEevaluated 1800 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1800
196 return X509_load_cert_file(ctx, file, type);
never executed: return X509_load_cert_file(ctx, file, type);
0
197 in = BIO_new_file(file, "r");-
198 if (!in) {
!inDescription
TRUEevaluated 442 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1358 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
442-1358
199 X509err(X509_F_X509_LOAD_CERT_CRL_FILE, ERR_R_SYS_LIB);-
200 return 0;
executed 442 times by 1 test: return 0;
Executed by:
  • libcrypto.so.1.1
442
201 }-
202 inf = PEM_X509_INFO_read_bio(in, NULL, NULL, "");-
203 BIO_free(in);-
204 if (!inf) {
!infDescription
TRUEnever evaluated
FALSEevaluated 1358 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1358
205 X509err(X509_F_X509_LOAD_CERT_CRL_FILE, ERR_R_PEM_LIB);-
206 return 0;
never executed: return 0;
0
207 }-
208 for (i = 0; i < sk_X509_INFO_num(inf); i++) {
i < sk_X509_INFO_num(inf)Description
TRUEevaluated 1366 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEevaluated 1358 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
1358-1366
209 itmp = sk_X509_INFO_value(inf, i);-
210 if (itmp->x509) {
itmp->x509Description
TRUEevaluated 1366 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
FALSEnever evaluated
0-1366
211 if (!X509_STORE_add_cert(ctx->store_ctx, itmp->x509))
!X509_STORE_ad...x, itmp->x509)Description
TRUEnever evaluated
FALSEevaluated 1366 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1366
212 goto err;
never executed: goto err;
0
213 count++;-
214 }
executed 1366 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1366
215 if (itmp->crl) {
itmp->crlDescription
TRUEnever evaluated
FALSEevaluated 1366 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1366
216 if (!X509_STORE_add_crl(ctx->store_ctx, itmp->crl))
!X509_STORE_ad...tx, itmp->crl)Description
TRUEnever evaluated
FALSEnever evaluated
0
217 goto err;
never executed: goto err;
0
218 count++;-
219 }
never executed: end of block
0
220 }
executed 1366 times by 1 test: end of block
Executed by:
  • libcrypto.so.1.1
1366
221 if (count == 0)
count == 0Description
TRUEnever evaluated
FALSEevaluated 1358 times by 1 test
Evaluated by:
  • libcrypto.so.1.1
0-1358
222 X509err(X509_F_X509_LOAD_CERT_CRL_FILE,
never executed: ERR_put_error(11,(132),(136),__FILE__,223) ;
0
223 X509_R_NO_CERTIFICATE_OR_CRL_FOUND);
never executed: ERR_put_error(11,(132),(136),__FILE__,223) ;
0
224 err:
code before this statement executed 1358 times by 1 test: err:
Executed by:
  • libcrypto.so.1.1
1358
225 sk_X509_INFO_pop_free(inf, X509_INFO_free);-
226 return count;
executed 1358 times by 1 test: return count;
Executed by:
  • libcrypto.so.1.1
1358
227}-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.2