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
 vNEXT | xx xxx xxxx
1
 vNEXT | xx xxx xxxx
2
   * Add support for handling of 301/302 HTTP redirects
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
 v1.30 | 21 Dec 2016
6
 v1.30 | 21 Dec 2016
5
   * Add web access for monitoring and reconfiguration
7
   * Add web access for monitoring and reconfiguration

+ 1
- 0
config.h View File

81
 	int					server_port;
81
 	int					server_port;
82
 	int					server_socket;
82
 	int					server_socket;
83
 	pthread_t			server_thread;
83
 	pthread_t			server_thread;
84
+	bool				allow_encrypted_input;
84
 
85
 
85
 	char				*channels_file;
86
 	char				*channels_file;
86
 
87
 

+ 21
- 12
tomcast.c View File

70
 #endif
70
 #endif
71
 
71
 
72
 char *server_sig = "tomcast";
72
 char *server_sig = "tomcast";
73
-char *server_ver = "1.34";
73
+char *server_ver = "1.40";
74
 char *copyright  = "Copyright (C) 2010-2018 Unix Solutions Ltd.";
74
 char *copyright  = "Copyright (C) 2010-2018 Unix Solutions Ltd.";
75
 
75
 
76
 static struct config config;
76
 static struct config config;
929
 				fdwrite(r->clientsock, reset, FRAME_PACKET_SIZE);
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
 			written = fdwrite(r->clientsock, buf, FRAME_PACKET_SIZE);
947
 			written = fdwrite(r->clientsock, buf, FRAME_PACKET_SIZE);
945
 			if (written == -1) {
948
 			if (written == -1) {
946
 				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);
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
 	puts("\t-l host\t\tSyslog host (default: disabled)");
990
 	puts("\t-l host\t\tSyslog host (default: disabled)");
988
 	puts("\t-L port\t\tSyslog port (default: 514)");
991
 	puts("\t-L port\t\tSyslog port (default: 514)");
989
 	puts("\t-R\t\tSend reset packets when changing sources.");
992
 	puts("\t-R\t\tSend reset packets when changing sources.");
993
+	puts("\t-E\t\tDetect encrypted input (default: false)");
990
 	puts("");
994
 	puts("");
991
 	puts("  Web server options:");
995
 	puts("  Web server options:");
992
 	puts("\t-b addr\t\tLocal IP address to bind.   (default: 0.0.0.0)");
996
 	puts("\t-b addr\t\tLocal IP address to bind.   (default: 0.0.0.0)");
1010
 	cfg->server_socket = -1;
1014
 	cfg->server_socket = -1;
1011
 	cfg->logport = 514;
1015
 	cfg->logport = 514;
1012
 	pthread_mutex_init(&cfg->channels_lock, NULL);
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
 		switch (j) {
1018
 		switch (j) {
1015
 			case 'b':
1019
 			case 'b':
1016
 				cfg->server_addr = optarg;
1020
 				cfg->server_addr = optarg;
1047
 			case 'R':
1051
 			case 'R':
1048
 				send_reset_opt = 1;
1052
 				send_reset_opt = 1;
1049
 				break;
1053
 				break;
1054
+			case 'E':
1055
+				cfg->allow_encrypted_input = 1;
1056
+				break;
1050
 			case 'H':
1057
 			case 'H':
1051
 			case 'h':
1058
 			case 'h':
1052
 				show_usage(0);
1059
 				show_usage(0);
1078
 	}
1085
 	}
1079
 	if (send_reset_opt)
1086
 	if (send_reset_opt)
1080
 		printf("\tSend reset packets.\n");
1087
 		printf("\tSend reset packets.\n");
1088
+	if (cfg->allow_encrypted_input)
1089
+		printf("\tDetect encrypted input.\n");
1081
 	if (cfg->pidfile) {
1090
 	if (cfg->pidfile) {
1082
 		printf("\tDaemonize         : %s\n", cfg->pidfile);
1091
 		printf("\tDaemonize         : %s\n", cfg->pidfile);
1083
 	} else {
1092
 	} else {

Loading…
Cancel
Save