From 813dd5ee34fe7e27a3ff69303f0c7f121d318896 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Wed, 15 Nov 2023 19:23:19 +0100 Subject: [PATCH 1/5] bugfix: add SSL Handshake create a connecting socket SSL_startHandshake is dependent on the protocol: this lets us use one socket to work with either SSL or non-SSL sockets. --- FHEM/82_LGTV_WebOS.pm | 1 + controls_LGTV_WebOS.txt | 4 ++-- lib/FHEM/Devices/LGTV/LGTVWebOS.pm | 17 ++++++++++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/FHEM/82_LGTV_WebOS.pm b/FHEM/82_LGTV_WebOS.pm index f1aa219..1967a60 100644 --- a/FHEM/82_LGTV_WebOS.pm +++ b/FHEM/82_LGTV_WebOS.pm @@ -7,6 +7,7 @@ # # Special thanks goes to comitters: # - Vitolinker / Commandref +# - ska- / SSL_startHandshake - SSL Port 3001 Support # # # This script is free software; you can redistribute it and/or modify diff --git a/controls_LGTV_WebOS.txt b/controls_LGTV_WebOS.txt index 3e08321..438e3ff 100644 --- a/controls_LGTV_WebOS.txt +++ b/controls_LGTV_WebOS.txt @@ -1,2 +1,2 @@ -UPD 2023-05-16_04:16:05 18968 FHEM/82_LGTV_WebOS.pm -UPD 2023-05-16_04:14:37 55512 lib/FHEM/Devices/LGTV/LGTVWebOS.pm +UPD 2023-11-15_19:19:41 19028 FHEM/82_LGTV_WebOS.pm +UPD 2023-11-15_19:19:45 55994 lib/FHEM/Devices/LGTV/LGTVWebOS.pm diff --git a/lib/FHEM/Devices/LGTV/LGTVWebOS.pm b/lib/FHEM/Devices/LGTV/LGTVWebOS.pm index e8cd3c2..76d92b7 100644 --- a/lib/FHEM/Devices/LGTV/LGTVWebOS.pm +++ b/lib/FHEM/Devices/LGTV/LGTVWebOS.pm @@ -643,14 +643,25 @@ sub Open { my $hash = shift; my $name = $hash->{NAME}; my $host = $hash->{HOST}; - my $port = 3000; my $timeout = 0.1; ::Log3( $name, 4, "LGTV_WebOS ($name) - Baue Socket Verbindung auf" ); - my $socket = IO::Socket::INET->new( + # create a connecting socket + # SSL_startHandshake is dependent on the protocol: this lets us use one socket + # to work with either SSL or non-SSL sockets. + my $socket = IO::Socket::SSL->new( + PeerHost => $host, + PeerPort => 3001, + Proto => 'tcp', + SSL_startHandshake => 1, #( $proto eq 'wss' ? 1 : 0 ), + SSL_verify_mode => SSL_VERIFY_NONE, + KeepAlive => 1, + Timeout => $timeout + ) + || IO::Socket::INET->new( PeerHost => $host, - PeerPort => $port, + PeerPort => 3000, Proto => 'tcp', KeepAlive => 1, Timeout => $timeout From 638cbba10b44335e8068ab7806a797cb78982575 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Thu, 16 Nov 2023 19:44:12 +0100 Subject: [PATCH 2/5] fix: Global symbol "$port" requires --- controls_LGTV_WebOS.txt | 2 +- lib/FHEM/Devices/LGTV/LGTVWebOS.pm | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/controls_LGTV_WebOS.txt b/controls_LGTV_WebOS.txt index 438e3ff..9466960 100644 --- a/controls_LGTV_WebOS.txt +++ b/controls_LGTV_WebOS.txt @@ -1,2 +1,2 @@ UPD 2023-11-15_19:19:41 19028 FHEM/82_LGTV_WebOS.pm -UPD 2023-11-15_19:19:45 55994 lib/FHEM/Devices/LGTV/LGTVWebOS.pm +UPD 2023-11-16_19:43:35 55993 lib/FHEM/Devices/LGTV/LGTVWebOS.pm diff --git a/lib/FHEM/Devices/LGTV/LGTVWebOS.pm b/lib/FHEM/Devices/LGTV/LGTVWebOS.pm index 76d92b7..40d356c 100644 --- a/lib/FHEM/Devices/LGTV/LGTVWebOS.pm +++ b/lib/FHEM/Devices/LGTV/LGTVWebOS.pm @@ -666,8 +666,9 @@ sub Open { KeepAlive => 1, Timeout => $timeout ) - or return ::Log3( $name, 4, - "LGTV_WebOS ($name) Couldn't connect to $host:$port" ); # open Socket + or + return ::Log3( $name, 4, "LGTV_WebOS ($name) Couldn't connect to $host" ) + ; # open Socket $hash->{FD} = $socket->fileno(); $hash->{CD} = $socket; # sysread / close won't work on fileno From 938f19f3a791fc7422f08f3213890a47f4870bb4 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Thu, 16 Nov 2023 19:49:37 +0100 Subject: [PATCH 3/5] [optional scope]: [optional body] [Ticket: no] --- controls_LGTV_WebOS.txt | 2 +- lib/FHEM/Devices/LGTV/LGTVWebOS.pm | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/controls_LGTV_WebOS.txt b/controls_LGTV_WebOS.txt index 9466960..7baf3a6 100644 --- a/controls_LGTV_WebOS.txt +++ b/controls_LGTV_WebOS.txt @@ -1,2 +1,2 @@ UPD 2023-11-15_19:19:41 19028 FHEM/82_LGTV_WebOS.pm -UPD 2023-11-16_19:43:35 55993 lib/FHEM/Devices/LGTV/LGTVWebOS.pm +UPD 2023-11-16_19:49:21 55997 lib/FHEM/Devices/LGTV/LGTVWebOS.pm diff --git a/lib/FHEM/Devices/LGTV/LGTVWebOS.pm b/lib/FHEM/Devices/LGTV/LGTVWebOS.pm index 40d356c..532ddec 100644 --- a/lib/FHEM/Devices/LGTV/LGTVWebOS.pm +++ b/lib/FHEM/Devices/LGTV/LGTVWebOS.pm @@ -654,8 +654,8 @@ sub Open { PeerHost => $host, PeerPort => 3001, Proto => 'tcp', - SSL_startHandshake => 1, #( $proto eq 'wss' ? 1 : 0 ), - SSL_verify_mode => SSL_VERIFY_NONE, + SSL_startHandshake => 1, #( $proto eq 'wss' ? 1 : 0 ), + SSL_verify_mode => 'SSL_VERIFY_NONE', KeepAlive => 1, Timeout => $timeout ) From 63371a5049a1ccce2f2363256a05c18d25e1cf27 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Thu, 16 Nov 2023 19:54:27 +0100 Subject: [PATCH 4/5] [optional scope]: [optional body] [Ticket: no] --- controls_LGTV_WebOS.txt | 2 +- lib/FHEM/Devices/LGTV/LGTVWebOS.pm | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/controls_LGTV_WebOS.txt b/controls_LGTV_WebOS.txt index 7baf3a6..5920657 100644 --- a/controls_LGTV_WebOS.txt +++ b/controls_LGTV_WebOS.txt @@ -1,2 +1,2 @@ UPD 2023-11-15_19:19:41 19028 FHEM/82_LGTV_WebOS.pm -UPD 2023-11-16_19:49:21 55997 lib/FHEM/Devices/LGTV/LGTVWebOS.pm +UPD 2023-11-16_19:54:21 56056 lib/FHEM/Devices/LGTV/LGTVWebOS.pm diff --git a/lib/FHEM/Devices/LGTV/LGTVWebOS.pm b/lib/FHEM/Devices/LGTV/LGTVWebOS.pm index 532ddec..84dfca4 100644 --- a/lib/FHEM/Devices/LGTV/LGTVWebOS.pm +++ b/lib/FHEM/Devices/LGTV/LGTVWebOS.pm @@ -643,6 +643,7 @@ sub Open { my $hash = shift; my $name = $hash->{NAME}; my $host = $hash->{HOST}; + my $port = 3000; my $timeout = 0.1; ::Log3( $name, 4, "LGTV_WebOS ($name) - Baue Socket Verbindung auf" ); @@ -654,20 +655,22 @@ sub Open { PeerHost => $host, PeerPort => 3001, Proto => 'tcp', - SSL_startHandshake => 1, #( $proto eq 'wss' ? 1 : 0 ), - SSL_verify_mode => 'SSL_VERIFY_NONE', - KeepAlive => 1, - Timeout => $timeout + SSL_startHandshake => 1, #( $proto eq 'wss' ? 1 : 0 ), + SSL_verify_mode => SSL_VERIFY_NONE, + + # Blocking => 1 + KeepAlive => 1, + Timeout => $timeout ) || IO::Socket::INET->new( PeerHost => $host, - PeerPort => 3000, + PeerPort => $port, Proto => 'tcp', KeepAlive => 1, Timeout => $timeout ) - or - return ::Log3( $name, 4, "LGTV_WebOS ($name) Couldn't connect to $host" ) + or return ::Log3( $name, 4, + "LGTV_WebOS ($name) Couldn't connect to $host:$port/3001" ) ; # open Socket $hash->{FD} = $socket->fileno(); From 965b255f0bd72695ef4c62980edbbd950f904f85 Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Fri, 17 Nov 2023 18:00:18 +0100 Subject: [PATCH 5/5] [optional scope]: [optional body] [Ticket: no] --- controls_LGTV_WebOS.txt | 2 +- lib/FHEM/Devices/LGTV/LGTVWebOS.pm | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/controls_LGTV_WebOS.txt b/controls_LGTV_WebOS.txt index 5920657..9fee12c 100644 --- a/controls_LGTV_WebOS.txt +++ b/controls_LGTV_WebOS.txt @@ -1,2 +1,2 @@ UPD 2023-11-15_19:19:41 19028 FHEM/82_LGTV_WebOS.pm -UPD 2023-11-16_19:54:21 56056 lib/FHEM/Devices/LGTV/LGTVWebOS.pm +UPD 2023-11-17_18:00:13 56133 lib/FHEM/Devices/LGTV/LGTVWebOS.pm diff --git a/lib/FHEM/Devices/LGTV/LGTVWebOS.pm b/lib/FHEM/Devices/LGTV/LGTVWebOS.pm index 84dfca4..11bac57 100644 --- a/lib/FHEM/Devices/LGTV/LGTVWebOS.pm +++ b/lib/FHEM/Devices/LGTV/LGTVWebOS.pm @@ -61,6 +61,7 @@ my $missingModul = ""; eval { require MIME::Base64; 1 } or $missingModul .= 'MIME::Base64 '; eval { require IO::Socket::INET; 1 } or $missingModul .= 'IO::Socket::INET '; +eval { use IO::Socket::SSL; 1 } or $missingModul .= 'IO::Socket::SSL '; ## no critic (Conditional "use" statement. Use "require" to conditionally include a module (Modules::ProhibitConditionalUseStatements)) eval { use Digest::SHA qw /sha1_hex/; 1 } or $missingModul .= 'Digest::SHA ';