From 3b149d10572392da66f57a7e2aaac53ba424e45c Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Tue, 27 Sep 2011 15:17:59 +0200 Subject: Added TLS settings --- contrib/pianobar.1 | 10 ++++++++++ src/main.c | 12 ++++++++---- src/settings.c | 18 ++++++++++++++++++ src/settings.h | 4 ++++ 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/contrib/pianobar.1 b/contrib/pianobar.1 index 7a6328e..6a7918f 100644 --- a/contrib/pianobar.1 +++ b/contrib/pianobar.1 @@ -281,6 +281,16 @@ Sort station list by name or type (is quickmix) and name. name_az for example sorts by name from a to z, quickmix_01_name_za by type (quickmix at the bottom) and name from z to a. +.TP +.B tls = {0,1} +Disable/enable TLS. This setting has no effect if TLS support was disabled at +compile time and defaults to enabled otherwise. + +.TP +.B tls_ca_path = /etc/ssl/certs/ca-certificates.crt +File that contains the root certificate (and possibly intermediate +certificates) of Pandora’s CA. + .TP .B user = your@user.name Your pandora.com username. diff --git a/src/main.c b/src/main.c index db55e08..668bdbf 100644 --- a/src/main.c +++ b/src/main.c @@ -343,15 +343,19 @@ int main (int argc, char **argv) { #endif PianoInit (&app.ph); + BarSettingsInit (&app.settings); + BarSettingsRead (&app.settings); + +#ifdef ENABLE_TLS + WaitressInit (&app.waith, app.settings.tlsCaPath); +#else WaitressInit (&app.waith, NULL); +#endif app.waith.url.host = strdup (PIANO_RPC_HOST); #ifdef ENABLE_TLS - app.waith.url.tls = true; + app.waith.url.tls = app.settings.tls; #endif - BarSettingsInit (&app.settings); - BarSettingsRead (&app.settings); - BarUiMsg (&app.settings, MSG_NONE, "Welcome to " PACKAGE " (" VERSION ")! "); if (app.settings.keys[BAR_KS_HELP] == BAR_KS_DISABLED) { diff --git a/src/settings.c b/src/settings.c index 9867b47..04bfff0 100644 --- a/src/settings.c +++ b/src/settings.c @@ -93,6 +93,9 @@ void BarSettingsDestroy (BarSettings_t *settings) { free (settings->npStationFormat); free (settings->listSongFormat); free (settings->fifo); +#ifdef ENABLE_TLS + free (settings->tlsCaPath); +#endif for (size_t i = 0; i < MSG_COUNT; i++) { free (settings->msgFormat[i].prefix); free (settings->msgFormat[i].postfix); @@ -131,6 +134,10 @@ void BarSettingsRead (BarSettings_t *settings) { settings->listSongFormat = strdup ("%i) %a - %t%r"); settings->fifo = malloc (PATH_MAX * sizeof (*settings->fifo)); BarGetXdgConfigDir (PACKAGE "/ctl", settings->fifo, PATH_MAX); +#ifdef ENABLE_TLS + settings->tls = true; + settings->tlsCaPath = strdup ("/etc/ssl/certs/ca-certificates.crt"); +#endif settings->msgFormat[MSG_NONE].prefix = NULL; settings->msgFormat[MSG_NONE].postfix = NULL; @@ -239,6 +246,17 @@ void BarSettingsRead (BarSettings_t *settings) { } else if (streq ("fifo", key)) { free (settings->fifo); settings->fifo = strdup (val); +#ifdef ENABLE_TLS + } else if (streq ("tls", key)) { + if (streq ("1", val)) { + settings->tls = true; + } else { + settings->tls = false; + } + } else if (streq ("tls_ca_path", key)) { + free (settings->tlsCaPath); + settings->tlsCaPath = strdup (val); +#endif } else if (strncmp (formatMsgPrefix, key, strlen (formatMsgPrefix)) == 0) { static const char *mapping[] = {"none", "info", "nowplaying", diff --git a/src/settings.h b/src/settings.h index 6162395..e5c3dd6 100644 --- a/src/settings.h +++ b/src/settings.h @@ -96,6 +96,10 @@ typedef struct { char *npStationFormat; char *listSongFormat; char *fifo; +#ifdef ENABLE_TLS + bool tls; + char *tlsCaPath; +#endif BarMsgFormatStr_t msgFormat[MSG_COUNT]; } BarSettings_t; -- cgit v1.2.3