public function handle($stanza, $parent = false) { $mec = (array) $stanza->mechanism; /* * Weird behaviour on old eJabberd servers, fixed on the new versions * see https://github.com/processone/ejabberd/commit/2d748115 */ if (isset($parent->starttls) && isset($parent->starttls->required)) { return; } $session = \Session::start(); $user = $session->get('username'); if ($user) { if (!is_array($mec)) { $mec = array($mec); } $mecchoice = str_replace('-', '', \Moxl\Auth::mechanismChoice($mec)); $session->set('mecchoice', $mecchoice); \Moxl\Utils::log("/// MECANISM CHOICE " . $mecchoice); if (method_exists('\\Moxl\\Auth', 'mechanism' . $mecchoice)) { call_user_func('Moxl\\Auth::mechanism' . $mecchoice); } else { \Moxl\Utils::log("/// MECANISM CHOICE NOT FOUND"); } } else { $g = new Get(); $g->setTo($session->get('host'))->request(); } }
public function handle($stanza, $parent = false) { $session = \Sessionx::start(); Utils::log("/// AUTH SUCCESSFULL"); $session->active = true; $session->password = '******'; $this->pack($session); $this->deliver(); }
private function clean($instances) { $t = time(); foreach ($instances as $key => $i) { if ($i['time'] < (int) $t - 30) { Utils::log('Action : Clean this request after 30 sec of no feedback ' . $i['type']); unset($instances[$key]); } } return $instances; }
public function handle($stanza, $parent = false) { $session = \Session::start(); $session->remove('password'); $session->set('active', true); $session = \Sessionx::start(); Utils::log("/// AUTH SUCCESSFULL"); // And we tell the daemon that the session is started ! fwrite(STDERR, 'started'); $session->active = true; $this->pack($session); $this->deliver(); }
static function mechanismSCRAMSHA1() { $s = new SASL2(); $fa = $s->factory('SCRAM-SHA1'); $session = \Session::start(); Utils::log("/// INITIAL MESSAGE"); $response = base64_encode($fa->getResponse($session->get('username'), $session->get('password'))); $session->set('saslfa', $fa); $dom = new \DOMDocument('1.0', 'UTF-8'); $auth = $dom->createElementNS('urn:ietf:params:xml:ns:xmpp-sasl', 'auth', $response); $auth->setAttribute('mechanism', 'SCRAM-SHA-1'); $dom->appendChild($auth); API::request($dom->saveXML($dom->documentElement)); }
static function mechanismSCRAMSHA1() { $s = new SASL2(); $fa = $s->factory('SCRAM-SHA1'); $session = \Sessionx::start(); Utils::log("/// INITIAL MESSAGE"); $response = base64_encode($fa->getResponse($session->user, $session->password)); $sess = \Session::start(); $sess->set('saslfa', $fa); $xml = '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="SCRAM-SHA-1"> ' . $response . ' </auth>'; API::request($xml); }
/** * Deliver the packet * * @return void */ public final function deliver() { $action_ns = 'Moxl\\Xec\\Action'; if (get_parent_class($this) == $action_ns || get_parent_class(get_parent_class($this)) == $action_ns) { $class = str_replace(array($action_ns, '\\'), array('', '_'), get_class($this)); $key = strtolower(substr($class, 1)); } else { $class = strtolower(get_class($this)); $pos = strrpos($class, '\\'); $key = substr($class, $pos + 1); } if ($this->method) { $key = $key . '_' . $this->method; } Utils::log('Package : Event "' . $key . '" from "' . $this->packet->from . '" fired'); $evt = new \Event(); $evt->runEvent($key, $this->packet); }
public function handle($stanza, $parent = false) { $sess = \Session::start(); $session = \Sessionx::start(); $s = new SASL2(); switch ($sess->get('mecchoice')) { case 'SCRAMSHA1': $fa = $sess->get('saslfa'); $sess->remove('saslfa'); $challenge = base64_decode((string) $stanza); \Moxl\Utils::log("/// SECOND MESSAGE - PROOF"); $response = base64_encode($fa->getResponse($session->user, $session->password, $challenge)); $xml = '<response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' . $response . '</response>'; \Moxl\API::request($xml); break; case 'DIGESTMD5': $decoded = base64_decode((string) $stanza); $s = new SASL2(); $d = $s->factory('digest-md5'); if (!$sess->get('saslfirst')) { \Moxl\Utils::log("/// CHALLENGE"); $response = $d->getResponse($session->user, $session->password, $decoded, $session->host, 'xmpp'); $response = base64_encode($response); $xml = '<response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' . $response . '</response>'; $sess->set('saslfirst', 1); } else { $xml = '<response xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>'; } \Moxl\API::request($xml); break; case 'CRAMMD5': $decoded = base64_decode((string) $stanza); $s = new SASL2(); $c = $s->factory('cram-md5'); $session = \Sessionx::start(); $response = $c->getResponse($session->user, $session->pass, $decoded); $response = base64_encode($response); \Moxl\Utils::log("/// CHALLENGE"); $xml = '<response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">' . $response . '</response>'; \Moxl\API::request($xml); break; } }
/** * Deliver the packet * * @return void */ public final function deliver() { $action_ns = 'Moxl\\Xec\\Action'; if (get_parent_class($this) == $action_ns || get_parent_class(get_parent_class($this)) == $action_ns) { $class = str_replace([$action_ns, '\\'], ['', '_'], get_class($this)); $key = strtolower(substr($class, 1)); } else { $class = strtolower(get_class($this)); $pos = strrpos($class, '\\'); $key = substr($class, $pos + 1); } if ($this->method) { $key = $key . '_' . $this->method; } if (!empty($this->packet->from)) { Utils::log('Package : Event "' . $key . '" from "' . $this->packet->from . '" fired'); } else { Utils::log('Package : Event "' . $key); } $this->event($key, $this->packet); }
public static function searchPayload($hash, $s, $sparent = false) { $hashToClass = array('9a534a8b4d6324e23f4187123e406729' => 'Message', '78e731027d8fd50ed642340b7c9a63b3' => 'Message', 'f9e18585fd0e0873c52e880c800f267a' => 'Receipt', '0977b7387b95f69007332a3e9b386f93' => 'MAMResult', '1040105fc01bfac8a5ab81324875e382' => 'Presence', '362b908ec9432a506f86bed0bae7bbb6' => 'Presence', 'a0e8e987b067b6b0470606f4f90d5362' => 'Roster', 'b5e3374e43f6544852f7751dfc529100' => 'Subject', 'fa9d41e26f664d9056618a4afe213861' => 'Post', '9952d726429340d482ecac82c1496191' => 'BOB', '4c9681f0e9aca8a5b65f86b8b80d490f' => 'DiscoInfo', '37ff18f136d5826c4426af5a23729e48' => 'Mood', '6b38ed328fb77617c6e4a5ac9dda0ad2' => 'Tune', '0981a46bbfa88b3500c4bccda18ccb89' => 'Location', '9c8ed44d4528a66484b0fbd44b0a9070' => 'Nickname', 'd8ea912a151202700bb399c9e04d205f' => 'Caps', '40ed26a65a25ab8bf809dd998d541d95' => 'PingPong', 'cb52f989717d25441018703ea1bc9819' => 'Attention', '54c22c37d17c78ee657ea3d40547a970' => 'Version', '1cb493832467273efa384bbffa6dc35a' => 'Avatar', '0f59aa7fb0492a008df1b807e91dda3b' => 'AvatarMetadata', '36fe2745bdc72b1682be2c008d547e3d' => 'Vcard4', 'd84d4b89d43e88a244197ccf499de8d8' => 'Jingle', '09ef1b34cf40fdd954f10d6e5075ee5c' => 'Carbons', '201fa54dd93e3403611830213f5f9fbc' => 'Carbons', 'b95746de5ddc3fa5fbf28906c017d9d8' => 'STARTTLS', 'f728271d924a04b0355379b28c3183a1' => 'SASL', '5e291b72f7160dabd1aa28f90cbde769' => 'SASLChallenge', 'abae1d63bb4295636badcce1bee02290' => 'SASLChallenge', 'a5af6a9efd75060b5aca9b473f1ef756' => 'SASLSuccess', '53936dd4e1d64e1eeec6dfc95c431964' => 'SASLSuccess', 'de175adc9063997df5b79817576ff659' => 'SASLFailure', '0bc0f510b2b6ac432e8605267ebdc812' => 'SessionBind', '128477f50347d98ee1213d71f27e8886' => 'SessionBind'); if (isset($hashToClass[$hash])) { //if(file_exists($base.'Payload/'.$hashToClass[$hash].'.php')) { // require_once($base.'Payload/'.$hashToClass[$hash].'.php'); $classname = '\\Moxl\\Xec\\Payload\\' . $hashToClass[$hash]; //if(class_exists($classname)) { //Utils::log('Handler : Call class "'.$hashToClass[$hash].'"'); $payload_class = new $classname(); $payload_class->prepare($s, $sparent); $payload_class->handle($s, $sparent); /*} else { Utils::log('Handler : Payload class "'.$hashToClass[$hash].'" not found'); }*/ /*} else { Utils::log('Handler : Payload file "'.$hashToClass[$hash].'" not found'); }*/ } else { Utils::log('Handler : This event is not listed'); return true; } }