]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
config: make http auth more configurable (plain, digest, both)
authorJaroslav Kysela <perex@perex.cz>
Sun, 11 Mar 2018 15:01:50 +0000 (16:01 +0100)
committerJaroslav Kysela <perex@perex.cz>
Sun, 11 Mar 2018 15:01:50 +0000 (16:01 +0100)
src/config.c
src/config.h
src/http.c
src/http.h

index c55e0fe3adb56d009ca82abfea7a75a7459e77f2..4ade4756ccc7deb571892b6b6df14b168639cda4 100644 (file)
@@ -1688,7 +1688,7 @@ config_boot ( const char *path, gid_t gid, uid_t uid )
   memset(&config, 0, sizeof(config));
   config.idnode.in_class = &config_class;
   config.ui_quicktips = 1;
-  config.digest = 1;
+  config.http_auth = HTTP_AUTH_DIGEST;
   config.proxy = 0;
   config.realm = strdup("tvheadend");
   config.info_area = strdup("login,storage,time");
@@ -2013,6 +2013,17 @@ config_class_piconscheme_list ( void *o, const char *lang )
   return strtab2htsmsg(tab, 1, lang);
 }
 
+static htsmsg_t *
+config_class_http_auth_list ( void *o, const char *lang )
+{
+  static const struct strtab tab[] = {
+    { N_("Plain (insecure)"),      HTTP_AUTH_PLAIN },
+    { N_("Digest"),                HTTP_AUTH_DIGEST },
+    { N_("Both plain and digest"), HTTP_AUTH_PLAIN_DIGEST },
+  };
+  return strtab2htsmsg(tab, 1, lang);
+}
+
 #if ENABLE_MPEGTS_DVB
 static void
 config_muxconfpath_notify_cb(void *opaque, int disarmed)
@@ -2331,13 +2342,14 @@ const idclass_t config_class = {
       .group  = 5
     },
     {
-      .type   = PT_BOOL,
+      .type   = PT_INT,
       .id     = "digest",
-      .name   = N_("Digest authentication"),
+      .name   = N_("Authentication type"),
       .desc   = N_("Digest access authentication is intended as a security trade-off. "
                    "It is intended to replace unencrypted HTTP basic access authentication. "
                    "This option should be enabled for standard usage."),
-      .off    = offsetof(config_t, digest),
+      .list   = config_class_http_auth_list,
+      .off    = offsetof(config_t, http_auth),
       .opts   = PO_EXPERT,
       .group  = 5
     },
index 02a2346b417ead6ee250c073169d400bede1cccc..85f614de968a07a7395fb59c9a017d28b6001d7b 100644 (file)
@@ -34,7 +34,7 @@ typedef struct config {
   int uilevel;
   int uilevel_nochange;
   int ui_quicktips;
-  int digest;
+  int http_auth;
   int proxy;
   char *realm;
   char *wizard;
index 7232f29308851db045f25835f9800605f0323c57..a9cbbb02e9d15e57266ad80a59c061b4bb38d1b5 100644 (file)
@@ -381,7 +381,8 @@ http_send_header(http_connection_t *hc, int rc, const char *content,
 
   if(rc == HTTP_STATUS_UNAUTHORIZED) {
     const char *realm = tvh_str_default(config.realm, "tvheadend");
-    if (config.digest) {
+    if (config.http_auth == HTTP_AUTH_DIGEST ||
+        config.http_auth == HTTP_AUTH_PLAIN_DIGEST) {
       if (hc->hc_nonce == NULL)
         hc->hc_nonce = http_get_nonce();
       char *opaque = http_get_opaque(realm, hc->hc_nonce);
@@ -1413,7 +1414,9 @@ process_request(http_connection_t *hc, htsbuf_queue_t *spill)
   /* Extract authorization */
   if((v = http_arg_get(&hc->hc_args, "Authorization")) != NULL) {
     if((n = http_tokenize(v, argv, 2, -1)) == 2) {
-      if (strcasecmp(argv[0], "basic") == 0) {
+      if ((config.http_auth == HTTP_AUTH_PLAIN ||
+           config.http_auth == HTTP_AUTH_PLAIN_DIGEST) &&
+          strcasecmp(argv[0], "basic") == 0) {
         n = base64_decode((uint8_t *)authbuf, argv[1], sizeof(authbuf) - 1);
         if (n < 0)
           n = 0;
@@ -1428,7 +1431,9 @@ process_request(http_connection_t *hc, htsbuf_queue_t *spill)
           http_error(hc, HTTP_STATUS_UNAUTHORIZED);
           return -1;
         }
-      } else if (strcasecmp(argv[0], "digest") == 0) {
+      } else if ((config.http_auth == HTTP_AUTH_DIGEST ||
+                  config.http_auth == HTTP_AUTH_PLAIN_DIGEST) &&
+                 strcasecmp(argv[0], "digest") == 0) {
         v = http_get_header_value(argv[1], "nonce");
         if (v == NULL || !http_nonce_exists(v)) {
           free(v);
index 6f1871353341efab7f71764fc870b69bfcc7bd3b..3e5b9ad18fd8d4d091aad203dba3bea0f89c46f9 100644 (file)
@@ -88,6 +88,10 @@ typedef struct http_arg {
 #define HTTP_STATUS_HTTP_VERSION    505
 #define HTTP_STATUS_OP_NOT_SUPPRT   551
 
+#define HTTP_AUTH_PLAIN             0
+#define HTTP_AUTH_DIGEST            1
+#define HTTP_AUTH_PLAIN_DIGEST      2
+
 typedef enum http_state {
   HTTP_CON_WAIT_REQUEST,
   HTTP_CON_READ_HEADER,