From e77ee3a5f0272d219bdb1acf294da726bad0bce7 Mon Sep 17 00:00:00 2001 From: Vladimir Shapovalov Date: Tue, 21 Feb 2017 17:22:11 +0200 Subject: [PATCH 1/2] adding netbeans support --- .gitignore | 3 ++- nbproject/project.properties | 7 +++++++ nbproject/project.xml | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml diff --git a/.gitignore b/.gitignore index 67ccfe7..685057e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store .svn -.idea \ No newline at end of file +.idea +/nbproject/private/ \ No newline at end of file diff --git a/nbproject/project.properties b/nbproject/project.properties new file mode 100644 index 0000000..76f6f91 --- /dev/null +++ b/nbproject/project.properties @@ -0,0 +1,7 @@ +include.path=${php.global.include.path} +php.version=PHP_56 +source.encoding=UTF-8 +src.dir=. +tags.asp=false +tags.short=false +web.root=. diff --git a/nbproject/project.xml b/nbproject/project.xml new file mode 100644 index 0000000..6f04325 --- /dev/null +++ b/nbproject/project.xml @@ -0,0 +1,9 @@ + + + org.netbeans.modules.php.project + + + xmpp-prebind + + + From b15bb0d8fe454d57033b7dc7f6376a76a4942c2d Mon Sep 17 00:00:00 2001 From: Vladimir Shapovalov Date: Tue, 21 Feb 2017 17:23:05 +0200 Subject: [PATCH 2/2] adding custom encryption support, adding ssl support --- lib/XmppPrebind.php | 104 ++++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 43 deletions(-) diff --git a/lib/XmppPrebind.php b/lib/XmppPrebind.php index 033857f..0bb892a 100644 --- a/lib/XmppPrebind.php +++ b/lib/XmppPrebind.php @@ -90,7 +90,7 @@ class XmppPrebind { * @param string $jabberHost Jabber Server Host * @param string $boshUri Full URI to the http-bind * @param string $resource Resource identifier - * @param bool $useSsl Use SSL (not working yet, TODO) + * @param bool $useSsl Use SSL (working already) * @param bool $debug Enable debug */ public function __construct($jabberHost, $boshUri, $resource, $useSsl = false, $debug = false) { @@ -133,62 +133,75 @@ public function __construct($jabberHost, $boshUri, $resource, $useSsl = false, $ * @param string $username Username without jabber host * @param string $password Password * @param string $route Route + * @param integer $force_encryption_method */ - public function connect($username, $password, $route = false) { - $this->jid = $username . '@' . $this->jabberHost; + public function connect($username, $password, $route = false, $force_encryption_method = null) + { + $this->jid = $username . '@' . $this->jabberHost; - if($this->resource) { - $this->jid .= '/' . $this->resource; - } + if($this->resource) { + $this->jid .= '/' . $this->resource; + } - $this->password = $password; + $this->password = $password; - $response = $this->sendInitialConnection($route); + $response = $this->sendInitialConnection($route); if(empty($response)) { - throw new XmppPrebindConnectionException("No response from server."); + throw new XmppPrebindConnectionException("No response from server."); } - $body = self::getBodyFromXml($response); - if ( empty( $body ) ) - throw new XmppPrebindConnectionException("No body could be found in response from server."); - $this->sid = $body->getAttribute('sid'); - - // set the Bosh Attributes - $this->wait = $body->getAttribute('wait'); - $this->requests = $body->getAttribute('requests'); - $this->ver = $body->getAttribute('ver'); - $this->polling = $body->getAttribute('polling'); - $this->inactivity = $body->getAttribute('inactivity'); - $this->hold = $body->getAttribute('hold'); - $this->to = $body->getAttribute('to'); - $this->accept = $body->getAttribute('accept'); - $this->maxpause = $body->getAttribute('maxpause'); - - $this->debug($this->sid, 'sid'); + $body = self::getBodyFromXml($response); + if ( empty( $body ) ) { + throw new XmppPrebindConnectionException("No body could be found in response from server."); + } + + $this->sid = $body->getAttribute('sid'); + + // set the Bosh Attributes + $this->wait = $body->getAttribute('wait'); + $this->requests = $body->getAttribute('requests'); + $this->ver = $body->getAttribute('ver'); + $this->polling = $body->getAttribute('polling'); + $this->inactivity = $body->getAttribute('inactivity'); + $this->hold = $body->getAttribute('hold'); + $this->to = $body->getAttribute('to'); + $this->accept = $body->getAttribute('accept'); + $this->maxpause = $body->getAttribute('maxpause'); + + $this->debug($this->sid, 'sid'); if(empty($body->firstChild) || empty($body->firstChild->firstChild)) { - throw new XmppPrebindConnectionException("Child not found in response from server."); + throw new XmppPrebindConnectionException("Child not found in response from server."); } - $mechanisms = $body->getElementsByTagName('mechanism'); + $mechanisms = $body->getElementsByTagName('mechanism'); - foreach ($mechanisms as $value) { - $this->mechanisms[] = $value->nodeValue; - } + foreach ($mechanisms as $value) { + $this->mechanisms[] = $value->nodeValue; + } - if (in_array(self::ENCRYPTION_DIGEST_MD5, $this->mechanisms)) { - $this->encryption = self::ENCRYPTION_DIGEST_MD5; - } elseif (in_array(self::ENCRYPTION_CRAM_MD5, $this->mechanisms)) { - $this->encryption = self::ENCRYPTION_CRAM_MD5; - } elseif (in_array(self::ENCRYPTION_PLAIN, $this->mechanisms)) { - $this->encryption = self::ENCRYPTION_PLAIN; - } else { - throw new XmppPrebindConnectionException("No encryption supported by the server is supported by this library."); - } + if ($force_encryption_method !== null) { + if (in_array($force_encryption_method, $this->mechanisms)) { + $this->encryption = $force_encryption_method; + } else { + throw new XmppPrebindConnectionException("Forced encryption is not supported by the server."); + } + } else { + + if (in_array(self::ENCRYPTION_DIGEST_MD5, $this->mechanisms)) { + $this->encryption = self::ENCRYPTION_DIGEST_MD5; + } elseif (in_array(self::ENCRYPTION_CRAM_MD5, $this->mechanisms)) { + $this->encryption = self::ENCRYPTION_CRAM_MD5; + } elseif (in_array(self::ENCRYPTION_PLAIN, $this->mechanisms)) { + $this->encryption = self::ENCRYPTION_PLAIN; + } else { + throw new XmppPrebindConnectionException("No encryption supported by the server is supported by this library."); + } + } - $this->debug($this->encryption, 'encryption used'); + $this->debug($this->encryption, 'encryption used'); - // Assign session creation response - $this->response = $body; + // Assign session creation response + $this->response = $body; } /** @@ -520,6 +533,11 @@ protected function send($xml) { } curl_setopt($ch, CURLOPT_HTTPHEADER, $header); + if ($this->useSsl) { + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + } + curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);