From 66f5b98e204f64f2015532bf570e2b3a62b099c9 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Tue, 6 Mar 2018 19:55:11 +0000 Subject: [PATCH] tcpclient : manage the SSL CRYPTO options git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4148 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- tcpclient.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/tcpclient.php b/tcpclient.php index 6965763..7d0bee5 100644 --- a/tcpclient.php +++ b/tcpclient.php @@ -57,14 +57,14 @@ class tcpclient while (empty ($this->ipv4) && empty ($this->ipv6) && $i < 10) { $nsRecords = @dns_get_record ($ipOrName, DNS_A + DNS_AAAA); - if ($nsRecords === false) + if ($nsRecords === false || $nsRecords == array ()) { // There is some problems with CNAME if they are not defined. // So enter in this case only if there is no other solution $nsRecords = @dns_get_record ($ipOrName, DNS_CNAME); - if ($nsRecords === false) + if ($nsRecords === false || $nsRecords == array ()) throw new \Exception ("Can not find the IP for $ipOrName : ". - "DNS Error (No A, AAAA, CNAME entries)", 500); + "DNS Error (No A, AAAA, CNAME entries)", 404); } foreach ($nsRecords as $val) { @@ -79,10 +79,10 @@ class tcpclient } if ($i >= 10) throw new \Exception ("Can not find the IP for $ipOrName : ". - "CNAME loop", 500); + "CNAME loop", 404); if (empty ($this->ipv4) && empty ($this->ipv6)) throw new \Exception ("Can not find the IP for $ipOrName : ". - "No A or AAAA record", 500); + "No A or AAAA record", 404); } $port = intval ($port); if ($port < 0 || $port > 65535) @@ -154,16 +154,14 @@ class tcpclient * @return false if the client can not found a encryption method with the * server */ - public function cryptoEnable ($val, - $cryptoMethod = STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT| - STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT, - $options = array ()) + public function cryptoEnable ($val, $cryptoMethod = null, $options = array ()) { if ($this->socket === null) throw new \Exception ("Can not send to server $this->ipOrName : ". "The server is not connected", 500); if ($cryptoMethod === null) - $cryptoMethod = STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT| + $cryptoMethod = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT| + STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT| STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT; $optionsBase = array ("ssl" => array ( "peer_name" => $this->ipOrName,