1 From 825a9969dea052b02ba868bdf39e676349f10dce Mon Sep 17 00:00:00 2001
2 From: Jussi Kukkonen <jussi.kukkonen@intel.com>
3 Date: Thu, 9 Feb 2017 14:51:28 +0200
4 Subject: [PATCH] curl: allow overriding default CA certificate file
6 Similar to curl, --cacert can now be used in cve-check-tool and
7 cve-check-update to override the default CA certificate file. Useful
8 in cases where the system default is unsuitable (for example,
9 out-dated) or broken (as in OE's current native libcurl, which embeds
10 a path string from one build host and then uses it on another although
11 the right path may have become something different).
13 Upstream-Status: Submitted [https://github.com/ikeydoherty/cve-check-tool/pull/45]
15 Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
18 Took Patrick Ohlys original patch from meta-security-isafw, rebased
19 on top of other patches.
21 Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com>
23 src/library/cve-check-tool.h | 1 +
24 src/library/fetch.c | 10 +++++++++-
25 src/library/fetch.h | 3 ++-
27 src/update-main.c | 4 +++-
28 src/update.c | 12 +++++++-----
30 7 files changed, 27 insertions(+), 10 deletions(-)
32 diff --git a/src/library/cve-check-tool.h b/src/library/cve-check-tool.h
33 index e4bb5b1..f89eade 100644
34 --- a/src/library/cve-check-tool.h
35 +++ b/src/library/cve-check-tool.h
36 @@ -43,6 +43,7 @@ typedef struct CveCheckTool {
37 bool bugs; /**<Whether bug tracking is enabled */
38 GHashTable *mapping; /**<CVE Mapping */
39 const char *output_file; /**<Output file, if any */
40 + const char *cacert_file; /**<Non-default SSL certificate file, if any */
44 diff --git a/src/library/fetch.c b/src/library/fetch.c
45 index 0fe6d76..8f998c3 100644
46 --- a/src/library/fetch.c
47 +++ b/src/library/fetch.c
48 @@ -60,7 +60,8 @@ static int progress_callback_new(void *ptr, curl_off_t dltotal, curl_off_t dlnow
51 FetchStatus fetch_uri(const char *uri, const char *target, bool verbose,
52 - unsigned int start_percent, unsigned int end_percent)
53 + unsigned int start_percent, unsigned int end_percent,
54 + const char *cacert_file)
56 FetchStatus ret = FETCH_STATUS_FAIL;
58 @@ -74,6 +75,13 @@ FetchStatus fetch_uri(const char *uri, const char *target, bool verbose,
63 + res = curl_easy_setopt(curl, CURLOPT_CAINFO, cacert_file);
64 + if (res != CURLE_OK) {
69 if (stat(target, &st) == 0) {
70 res = curl_easy_setopt(curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
71 if (res != CURLE_OK) {
72 diff --git a/src/library/fetch.h b/src/library/fetch.h
73 index 4cce5d1..836c7d7 100644
74 --- a/src/library/fetch.h
75 +++ b/src/library/fetch.h
76 @@ -29,7 +29,8 @@ typedef enum {
77 * @return A FetchStatus, indicating the operation taken
79 FetchStatus fetch_uri(const char *uri, const char *target, bool verbose,
80 - unsigned int this_percent, unsigned int next_percent);
81 + unsigned int this_percent, unsigned int next_percent,
82 + const char *cacert_file);
85 * Attempt to extract the given gzipped file
86 diff --git a/src/main.c b/src/main.c
87 index 8e6f158..ae69d47 100644
90 @@ -280,6 +280,7 @@ static bool csv_mode = false;
91 static char *modified_stamp = NULL;
92 static gchar *mapping_file = NULL;
93 static gchar *output_file = NULL;
94 +static gchar *cacert_file = NULL;
96 static GOptionEntry _entries[] = {
97 { "not-patched", 'n', 0, G_OPTION_ARG_NONE, &hide_patched, "Hide patched/addressed CVEs", NULL },
98 @@ -294,6 +295,7 @@ static GOptionEntry _entries[] = {
99 { "csv", 'c', 0, G_OPTION_ARG_NONE, &csv_mode, "Output CSV formatted data only", NULL },
100 { "mapping", 'M', 0, G_OPTION_ARG_STRING, &mapping_file, "Path to a mapping file", NULL},
101 { "output-file", 'o', 0, G_OPTION_ARG_STRING, &output_file, "Path to the output file (output plugin specific)", NULL},
102 + { "cacert", 'C', 0, G_OPTION_ARG_STRING, &cacert_file, "Path to the combined SSL certificates file (system default is used if not set)", NULL},
106 @@ -492,6 +494,7 @@ int main(int argc, char **argv)
108 quiet = csv_mode || !no_html;
109 self->output_file = output_file;
110 + self->cacert_file = cacert_file;
112 if (!csv_mode && self->output_file) {
114 @@ -530,7 +533,7 @@ int main(int argc, char **argv)
116 fprintf(stderr, "Update of db forced\n");
118 - if (!update_db(quiet, db_path->str)) {
119 + if (!update_db(quiet, db_path->str, self->cacert_file)) {
120 fprintf(stderr, "DB update failure\n");
123 diff --git a/src/update-main.c b/src/update-main.c
124 index 2379cfa..c52d9d0 100644
125 --- a/src/update-main.c
126 +++ b/src/update-main.c
127 @@ -43,11 +43,13 @@ the Free Software Foundation; either version 2 of the License, or\n\
128 static gchar *nvds = NULL;
129 static bool _show_version = false;
130 static bool _quiet = false;
131 +static const char *_cacert_file = NULL;
133 static GOptionEntry _entries[] = {
134 { "nvd-dir", 'd', 0, G_OPTION_ARG_STRING, &nvds, "NVD directory in filesystem", NULL },
135 { "version", 'v', 0, G_OPTION_ARG_NONE, &_show_version, "Show version", NULL },
136 { "quiet", 'q', 0, G_OPTION_ARG_NONE, &_quiet, "Run silently", NULL },
137 + { "cacert", 'C', 0, G_OPTION_ARG_STRING, &_cacert_file, "Path to the combined SSL certificates file (system default is used if not set)", NULL},
141 @@ -88,7 +90,7 @@ int main(int argc, char **argv)
145 - if (update_db(_quiet, db_path->str)) {
146 + if (update_db(_quiet, db_path->str, _cacert_file)) {
149 fprintf(stderr, "Failed to update database\n");
150 diff --git a/src/update.c b/src/update.c
151 index 070560a..8cb4a39 100644
154 @@ -267,7 +267,8 @@ static inline void update_end(int fd, const char *update_fname, bool ok)
156 static int do_fetch_update(int year, const char *db_dir, CveDB *cve_db,
157 bool db_exist, bool verbose,
158 - unsigned int this_percent, unsigned int next_percent)
159 + unsigned int this_percent, unsigned int next_percent,
160 + const char *cacert_file)
162 const char nvd_uri[] = URI_PREFIX;
163 autofree(cve_string) *uri_meta = NULL;
164 @@ -331,14 +332,14 @@ refetch:
167 /* Fetch NVD META file */
168 - st = fetch_uri(uri_meta->str, nvdcve_meta->str, verbose, this_percent, this_percent);
169 + st = fetch_uri(uri_meta->str, nvdcve_meta->str, verbose, this_percent, this_percent, cacert_file);
170 if (st == FETCH_STATUS_FAIL) {
171 fprintf(stderr, "Failed to fetch %s\n", uri_meta->str);
175 /* Fetch NVD XML file */
176 - st = fetch_uri(uri_data_gz->str, nvdcve_data_gz->str, verbose, this_percent, next_percent);
177 + st = fetch_uri(uri_data_gz->str, nvdcve_data_gz->str, verbose, this_percent, next_percent, cacert_file);
179 case FETCH_STATUS_FAIL:
180 fprintf(stderr, "Failed to fetch %s\n", uri_data_gz->str);
181 @@ -391,7 +392,7 @@ refetch:
185 -bool update_db(bool quiet, const char *db_file)
186 +bool update_db(bool quiet, const char *db_file, const char *cacert_file)
188 autofree(char) *db_dir = NULL;
189 autofree(CveDB) *cve_db = NULL;
190 @@ -466,7 +467,8 @@ bool update_db(bool quiet, const char *db_file)
192 fprintf(stderr, "completed: %u%%\r", start_percent);
193 rc = do_fetch_update(y, db_dir, cve_db, db_exist, !quiet,
194 - start_percent, end_percent);
195 + start_percent, end_percent,
200 diff --git a/src/update.h b/src/update.h
201 index b8e9911..ceea0c3 100644
204 @@ -15,7 +15,7 @@ cve_string *get_db_path(const char *path);
206 int update_required(const char *db_file);
208 -bool update_db(bool quiet, const char *db_file);
209 +bool update_db(bool quiet, const char *db_file, const char *cacert_file);