Browse Source

Add support for detecting encrypted input

To enable it use -E option. Once this is activated if an encrypted
input is detect tomcast would try to change sources.
Georgi Chorbadzhiyski 6 years ago
parent
commit
5325288912
3 changed files with 24 additions and 12 deletions
  1. 2
    0
      ChangeLog
  2. 1
    0
      config.h
  3. 21
    12
      tomcast.c

+ 2
- 0
ChangeLog View File

@@ -1,5 +1,7 @@
1 1
 vNEXT | xx xxx xxxx
2 2
   * Add support for handling of 301/302 HTTP redirects
3
+  * Add support for detecting encrypted input and switching sources
4
+    if the input is encrypted (use -E option).
3 5
 
4 6
 v1.30 | 21 Dec 2016
5 7
   * Add web access for monitoring and reconfiguration

+ 1
- 0
config.h View File

@@ -81,6 +81,7 @@ struct config {
81 81
 	int					server_port;
82 82
 	int					server_socket;
83 83
 	pthread_t			server_thread;
84
+	bool				allow_encrypted_input;
84 85
 
85 86
 	char				*channels_file;
86 87
 

+ 21
- 12
tomcast.c View File

@@ -70,7 +70,7 @@
70 70
 #endif
71 71
 
72 72
 char *server_sig = "tomcast";
73
-char *server_ver = "1.34";
73
+char *server_ver = "1.40";
74 74
 char *copyright  = "Copyright (C) 2010-2018 Unix Solutions Ltd.";
75 75
 
76 76
 static struct config config;
@@ -929,18 +929,21 @@ void * proxy_ts_stream(void *self) {
929 929
 				fdwrite(r->clientsock, reset, FRAME_PACKET_SIZE);
930 930
 			}
931 931
 
932
-			int64_t now = get_time();
933
-			int ret;
934
-			if ((ret = ts_have_valid_pes((uint8_t *)buf, readen)) == 0) { // Is the output encrypted?
935
-				/* The output is encrypted, check if 1000 ms have passed and if such, notify that we probably have invalid key */
936
-				if (now > r->last_decrypted_input_ts + 500000) {
937
-					proxy_log(r, "ERR  ","Scrambled input");
938
-					proxy_set_status(r, "ERROR: Encrypted stream input");
939
-					goto RECONNECT;
932
+			if (!config.allow_encrypted_input) {
933
+				int64_t now = get_time();
934
+				int ret;
935
+				if ((ret = ts_have_valid_pes((uint8_t *)buf, readen)) == 0) { // Is the output encrypted?
936
+					/* The output is encrypted, check if 1000 ms have passed and if such, notify that we probably have invalid key */
937
+					if (now > r->last_decrypted_input_ts + 500000) {
938
+						proxy_log(r, "ERR  ","Scrambled input");
939
+						proxy_set_status(r, "ERROR: Encrypted stream input");
940
+						goto RECONNECT;
941
+					}
942
+				} else {
943
+					r->last_decrypted_input_ts = now;
940 944
 				}
941
-			} else {
942
-				r->last_decrypted_input_ts = now;
943 945
 			}
946
+
944 947
 			written = fdwrite(r->clientsock, buf, FRAME_PACKET_SIZE);
945 948
 			if (written == -1) {
946 949
 				LOGf("PROXY: Error writing to dst_fd: %i on srv_fd: %i | Channel: %s Source: %s\n", r->clientsock, r->sock, r->channel->name, r->channel->source);
@@ -987,6 +990,7 @@ void show_usage(int ident_only) {
987 990
 	puts("\t-l host\t\tSyslog host (default: disabled)");
988 991
 	puts("\t-L port\t\tSyslog port (default: 514)");
989 992
 	puts("\t-R\t\tSend reset packets when changing sources.");
993
+	puts("\t-E\t\tDetect encrypted input (default: false)");
990 994
 	puts("");
991 995
 	puts("  Web server options:");
992 996
 	puts("\t-b addr\t\tLocal IP address to bind.   (default: 0.0.0.0)");
@@ -1010,7 +1014,7 @@ void parse_options(int argc, char **argv, struct config *cfg) {
1010 1014
 	cfg->server_socket = -1;
1011 1015
 	cfg->logport = 514;
1012 1016
 	pthread_mutex_init(&cfg->channels_lock, NULL);
1013
-	while ((j = getopt(argc, argv, "i:b:p:c:d:t:o:l:L:RHh")) != -1) {
1017
+	while ((j = getopt(argc, argv, "i:b:p:c:d:t:o:l:L:REHh")) != -1) {
1014 1018
 		switch (j) {
1015 1019
 			case 'b':
1016 1020
 				cfg->server_addr = optarg;
@@ -1047,6 +1051,9 @@ void parse_options(int argc, char **argv, struct config *cfg) {
1047 1051
 			case 'R':
1048 1052
 				send_reset_opt = 1;
1049 1053
 				break;
1054
+			case 'E':
1055
+				cfg->allow_encrypted_input = 1;
1056
+				break;
1050 1057
 			case 'H':
1051 1058
 			case 'h':
1052 1059
 				show_usage(0);
@@ -1078,6 +1085,8 @@ void parse_options(int argc, char **argv, struct config *cfg) {
1078 1085
 	}
1079 1086
 	if (send_reset_opt)
1080 1087
 		printf("\tSend reset packets.\n");
1088
+	if (cfg->allow_encrypted_input)
1089
+		printf("\tDetect encrypted input.\n");
1081 1090
 	if (cfg->pidfile) {
1082 1091
 		printf("\tDaemonize         : %s\n", cfg->pidfile);
1083 1092
 	} else {

Loading…
Cancel
Save