Skip to content

Commit 62ac5ef

Browse files
committed
add -k command line opt to skip ca_cert verification
1 parent ba1d27e commit 62ac5ef

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

ziptuner.c

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ First get a list to choose from. (old API)
5757
http://www.radio-browser.info/webservice/v2/m3u/url/nnnnn
5858
*/
5959

60-
//#define NEW_API 2
60+
#define NEW_API 2
6161

6262
#ifdef NEW_API
6363
char srv[512] = "https://fr1.api.radio-browser.info"; // Default server
@@ -165,7 +165,13 @@ char splashtext[64];
165165
int resize = 1;
166166
// 24 lines with 5x10 font on 320x240 pixel display (zipit)
167167
#define SPLASH_MINH 24
168-
168+
169+
#ifdef IZ2S
170+
int skipcert = 1;
171+
#else
172+
int skipcert = 0;
173+
#endif
174+
169175
/************************************************/
170176
void quit(int q)
171177
{
@@ -178,7 +184,10 @@ void quit(int q)
178184
int dialog(char *cmd)
179185
{
180186
int code = system(cmd);
181-
if ((code == 0xff00) || (code == 0x02)) // ESC or ctl-c
187+
// If "error" is code -1, does it sign extend to 0xffffff00 ?
188+
// Puppy linux dialog gives 0x100 (not 0x02) on ctrl-C, which breaks this.
189+
// Also what about ctrl-Z. That stops the job. Is fg resume ok?
190+
if (((code & 0xff00) == 0xff00) || (code == 0x02)) // ESC or ctrl-C
182191
quit(0);
183192
return code;
184193
}
@@ -495,16 +504,30 @@ int do_curl(char *url)
495504
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
496505
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
497506
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);
498-
//curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
499-
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "ziptuner/0.2");
507+
curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "ziptuner/0.3");
500508
#ifdef NEW_API
501-
#ifdef IZ2S /* No working default cert location on IZ2S */
502-
// Tell libcurl to not verify the peer (this works for old puppy linux)
503-
curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
504-
// Or provide a default cert path here. (could NOT make this work on puppy linux)
505-
// curl_easy_setopt(curl_handle, CURLOPT_CAPATH, "/usr/local-openssl/ssl/cert.pem");
506-
// curl_easy_setopt(curl_handle, CURLOPT_CAPATH, "/usr/share/curl/curl-ca-bundle.crt");
507-
#endif
509+
// Tell libcurl to not verify the peer (this works for old puppy linux, and IZ2S)
510+
// That should be a command line option -k (for all ziptuners, not just IZ2S)
511+
// (to avoid the cryptonecronom that eventually invalidates everything)
512+
if (skipcert) curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
513+
#ifdef IZ2S /* Tell IZ2S where to find cert.pem (no builtin path, so use debian path) */
514+
else curl_easy_setopt(curl_handle, CURLOPT_CAINFO, "/usr/local/share/ca_certificates/cert.pem");
515+
#endif /* Download the curl cert.pem file and put it there. Works on IZ2S. */
516+
517+
/* =========== No working default cert location on IZ2S =========== */
518+
// curl will tell you the default path if you give it a bogus one. IZ2S says:
519+
// curl --cacert bogus https://www.google.com
520+
// curl: (77) error setting certificate verify locations:
521+
// CAfile: garbled
522+
// CApath: none
523+
//
524+
// So IZ2S curl was compiled with NO CApath. And there's no standard between distros.
525+
// So I like the debian path /usr/local/share/ca_certificates/cacert.pebm for IZ2S.
526+
// Because /usr/local/share is linked in from the SD card in the IZ2S startup script.
527+
528+
// Provide a default cert path? (could NOT make this work on puppy linux)
529+
// curl_easy_setopt(curl_handle, CURLOPT_CAPATH, "/usr/local-openssl/ssl");
530+
// curl_easy_setopt(curl_handle, CURLOPT_CAPATH, "/usr/share/curl"); // /curl-ca-bundle.crt");
508531
#endif
509532
res = curl_easy_perform(curl_handle);
510533
if(res != CURLE_OK) {
@@ -1308,6 +1331,9 @@ int parse_args(int argc, char **argv){
13081331
case 'u':
13091332
U2L =1;
13101333
break;
1334+
case 'k':
1335+
skipcert =1;
1336+
break;
13111337
case 'h':
13121338
case '?':
13131339
printf("\n-- ziptuner -- internet radio playlist fetcher.\n"
@@ -1316,8 +1342,9 @@ int parse_args(int argc, char **argv){
13161342
"\n"
13171343
" -p sets a command for the play button.\n"
13181344
" -s sets a command for the stop button.\n"
1319-
" -u Convert Latin1 UTF-8 chars to iso-8859-1\n"
1345+
" -u convert Latin1 UTF-8 chars to iso-8859-1\n"
13201346
" -a auto-resume (playing favorite).\n"
1347+
" -k skip ssl CA cert verification.\n"
13211348
" Multiple destinations allowed (files or folders)\n"
13221349
"\n"
13231350
"eg:\n "

0 commit comments

Comments
 (0)