Allow the tests to use a version of SSL which should not conflict with curl/gnutls...
authorgggeek <giunta.gaetano@gmail.com>
Sat, 21 Mar 2015 18:05:18 +0000 (18:05 +0000)
committergggeek <giunta.gaetano@gmail.com>
Sat, 21 Mar 2015 18:05:18 +0000 (18:05 +0000)
.travis.yml
src/Client.php
tests/4LocalhostMultiTest.php
tests/parse_args.php

index 3e08e6b..9d27df4 100644 (file)
@@ -27,11 +27,12 @@ before_script:
 
 script:
   # to have code coverage: --coverage-clover=coverage.clover
-  phpunit tests LOCALSERVER=localhost URI=/demo/server/server.php HTTPSSERVER=localhost HTTPSURI=/demo/server/server.php PROXY=localhost:8080 HTTPSVERIFYHOST=0 HTTPSIGNOREPEER=1
+  phpunit tests LOCALSERVER=localhost URI=/demo/server/server.php HTTPSSERVER=localhost HTTPSURI=/demo/server/server.php PROXY=localhost:8080 HTTPSVERIFYHOST=0 SSLVERSION=3
 
 after_failure:
   - cat apache_error.log
   - cat apache_access.log
+  - php -i
 
 after_script:
 #  # upload code-coverage to Scrutinizer
index 6ec59eb..4586b70 100644 (file)
@@ -23,6 +23,7 @@ class Client
     public $keypass = '';
     public $verifypeer = true;
     public $verifyhost = 2;
+    public $sslversion = 0; // corresponds to CURL_SSLVERSION_DEFAULT
     public $no_multicall = false;
     public $proxy = '';
     public $proxyport = 0;
@@ -218,6 +219,16 @@ class Client
         $this->verifyhost = $i;
     }
 
+    /**
+     * Set attributes for SSL communication: SSL version to use. Best left at 0 (default value ): let cURL decide
+     *
+     * @param int $i
+     */
+    public function setSSLVersion($i)
+    {
+        $this->sslversion = $i;
+    }
+
     /**
      * Set proxy info.
      *
@@ -364,7 +375,8 @@ class Client
                 $this->proxy_authtype,
                 $this->keepalive,
                 $this->key,
-                $this->keypass
+                $this->keypass,
+                $this->sslversion
             );
         } elseif ($method == 'http11') {
             $r = $this->sendPayloadCURL(
@@ -562,11 +574,11 @@ class Client
     private function sendPayloadHTTPS($msg, $server, $port, $timeout = 0, $username = '',
                                       $password = '', $authtype = 1, $cert = '', $certpass = '', $cacert = '', $cacertdir = '',
                                       $proxyhost = '', $proxyport = 0, $proxyusername = '', $proxypassword = '', $proxyauthtype = 1,
-                                      $keepalive = false, $key = '', $keypass = '')
+                                      $keepalive = false, $key = '', $keypass = '', $sslversion = 0)
     {
         $r = $this->sendPayloadCURL($msg, $server, $port, $timeout, $username,
             $password, $authtype, $cert, $certpass, $cacert, $cacertdir, $proxyhost, $proxyport,
-            $proxyusername, $proxypassword, $proxyauthtype, 'https', $keepalive, $key, $keypass);
+            $proxyusername, $proxypassword, $proxyauthtype, 'https', $keepalive, $key, $keypass, $sslversion);
 
         return $r;
     }
@@ -579,7 +591,7 @@ class Client
     private function sendPayloadCURL($msg, $server, $port, $timeout = 0, $username = '',
                                      $password = '', $authtype = 1, $cert = '', $certpass = '', $cacert = '', $cacertdir = '',
                                      $proxyhost = '', $proxyport = 0, $proxyusername = '', $proxypassword = '', $proxyauthtype = 1, $method = 'https',
-                                     $keepalive = false, $key = '', $keypass = '')
+                                     $keepalive = false, $key = '', $keypass = '', $sslversion = 0)
     {
         if (!function_exists('curl_init')) {
             $this->errstr = 'CURL unavailable on this install';
@@ -727,6 +739,8 @@ class Client
             }
             // whether to verify cert's common name (CN); 0 for no, 1 to verify that it exists, and 2 to verify that it matches the hostname used
             curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost);
+            // allow usage of different SSL versions
+            curl_setopt($curl, CURLOPT_SSLVERSION, $sslversion);
         }
 
         // proxy info
index 2b2ba67..51a8933 100644 (file)
@@ -153,8 +153,9 @@ class LocalhostMultiTest extends LocalhostTest
         $this->method = 'https';
         $this->client->method = 'https';
         $this->client->path = $this->args['HTTPSURI'];
-        $this->client->setSSLVerifyPeer( !$this->args['HTTPSIGNOREPEER'] );
-        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST'] );
+        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
+        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
+        $this->client->setSSLVersion($this->args['SSLVERSION']);
         $this->_runtests();
     }
 
@@ -175,8 +176,9 @@ class LocalhostMultiTest extends LocalhostTest
         $this->client->method = 'https';
         $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
         $this->client->path = $this->args['HTTPSURI'];
-        $this->client->setSSLVerifyPeer( !$this->args['HTTPSIGNOREPEER'] );
-        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST'] );
+        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
+        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
+        $this->client->setSSLVersion($this->args['SSLVERSION']);
         $this->_runtests();
     }
 
index 0d21191..b2e438e 100644 (file)
@@ -12,6 +12,7 @@
  * @param string  NOPROXY
  * @param bool    HTTPSIGNOREPEER
  * @param int     HTTPSVERIFYHOST
+ * @param int     SSLVERSION
  *
  * @copyright (C) 2007-2015 G. Giunta
  * @license code licensed under the BSD License: see file license.txt
@@ -29,6 +30,7 @@ class argParser
             'HTTPSURI' => '/sw/xmlrpc/demo/server/server.php',
             'HTTPSIGNOREPEER' => false,
             'HTTPSVERIFYHOST' => 2,
+            'SSLVERSION' => 0,
             'PROXYSERVER' => null,
             'NOPROXY' => false,
             'LOCALPATH' => __DIR__,
@@ -75,6 +77,9 @@ class argParser
         if (isset($HTTPSVERIFYHOST)) {
             $args['HTTPSVERIFYHOST'] = (int)$HTTPSVERIFYHOST;
         }
+        if (isset($SSLVERSION)) {
+            $args['SSLVERSION'] = (int)$SSLVERSION;
+        }
         if (isset($PROXY)) {
             $arr = explode(':', $PROXY);
             $args['PROXYSERVER'] = $arr[0];