Skip to content

Commit 12abb7d

Browse files
committed
Add --cacert and --proxy-cacert
Fixes #108
1 parent ff5f566 commit 12abb7d

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ typedef struct {
5353
char *proxy_username;
5454
/** \brief HTTP proxy password */
5555
char *proxy_password;
56+
/** \brief HTTP proxy certificate file */
57+
char *proxy_cafile;
5658
/** \brief HTTP maximum connection count */
5759
long max_conns;
5860
/** \brief HTTP user agent*/
@@ -63,6 +65,8 @@ typedef struct {
6365
int no_range_check;
6466
/** \brief Disable TLS certificate verification */
6567
int insecure_tls;
68+
/** \brief Server certificate file */
69+
char *cafile;
6670
/*--------------- Cache related ---------------*/
6771
/** \brief Whether cache mode is enabled */
6872
int cache_enabled;

src/link.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ static CURL *Link_to_curl(Link *link)
9595
if (ret) {
9696
lprintf(error, "%s", curl_easy_strerror(ret));
9797
}
98+
if (CONFIG.cafile) {
99+
/*
100+
* Having been given a certificate file, disable any search directory
101+
* built into libcurl, so that we exclusively use the explicitly given
102+
* certificate(s).
103+
*
104+
* If we ever add a CAPATH option, we should do the mirror for CAINFO,
105+
* too: disable both and then enable whichever one(s) were given.
106+
*/
107+
ret = curl_easy_setopt(curl, CURLOPT_CAPATH, NULL);
108+
if (ret) {
109+
lprintf(error, "%s", curl_easy_strerror(ret));
110+
}
111+
112+
ret = curl_easy_setopt(curl, CURLOPT_CAINFO, CONFIG.cafile);
113+
if (ret) {
114+
lprintf(error, "%s", curl_easy_strerror(ret));
115+
}
116+
}
98117
if (CONFIG.insecure_tls) {
99118
ret = curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
100119
if (ret) {
@@ -146,6 +165,20 @@ static CURL *Link_to_curl(Link *link)
146165
}
147166
}
148167

168+
if (CONFIG.proxy_cafile) {
169+
/* See CONFIG.cafile above */
170+
ret = curl_easy_setopt(curl, CURLOPT_PROXY_CAPATH, NULL);
171+
if (ret) {
172+
lprintf(error, "%s", curl_easy_strerror(ret));
173+
}
174+
175+
ret = curl_easy_setopt(curl, CURLOPT_PROXY_CAINFO,
176+
CONFIG.proxy_cafile);
177+
if (ret) {
178+
lprintf(error, "%s", curl_easy_strerror(ret));
179+
}
180+
}
181+
149182
return curl;
150183
}
151184

src/main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc)
199199
{ "insecure-tls", no_argument, NULL, 'L' }, /* 20 */
200200
{ "config", required_argument, NULL, 'L' }, /* 21 */
201201
{ "single-file-mode", required_argument, NULL, 'L' }, /* 22 */
202+
{ "cacert", required_argument, NULL, 'L' }, /* 23 */
203+
{ "proxy-cacert", required_argument, NULL, 'L' }, /* 24 */
202204
{ 0, 0, 0, 0 }
203205
};
204206
while ((c =
@@ -296,6 +298,12 @@ parse_arg_list(int argc, char **argv, char ***fuse_argv, int *fuse_argc)
296298
case 22:
297299
CONFIG.mode = SINGLE;
298300
break;
301+
case 23:
302+
CONFIG.cafile = strdup(optarg);
303+
break;
304+
case 24:
305+
CONFIG.proxy_cafile = strdup(optarg);
306+
break;
299307
default:
300308
fprintf(stderr, "see httpdirfs -h for usage\n");
301309
return 1;
@@ -347,9 +355,11 @@ HTTPDirFS options:\n\
347355
https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html\n\
348356
--proxy-username Username for the proxy\n\
349357
--proxy-password Password for the proxy\n\
358+
--proxy-cacert Certificate authority for the proxy\n\
350359
--cache Enable cache (default: off)\n\
351360
--cache-location Set a custom cache location\n\
352361
(default: \"${XDG_CACHE_HOME}/httpdirfs\")\n\
362+
--cacert Certificate authority for the server\n\
353363
--dl-seg-size Set cache download segment size, in MB (default: 8)\n\
354364
Note: this setting is ignored if previously\n\
355365
cached data is found for the requested file.\n\

0 commit comments

Comments
 (0)