zorn-v / xmpp

Library for XMPP protocol connections (Jabber) for PHP
Other
9 stars 2 forks source link

Connection failed with empty resource #5

Closed srms-fr closed 5 months ago

srms-fr commented 5 months ago

Hi, Cisco IMP requires a resource when connecting, but getResource return an empty value.

public function getResource()
{
    $username = $this->getUsername();
    $username = explode('/', $username);
    return isset($username[1]) ? $username[1] : 'fabiang';
}
zorn-v commented 5 months ago

If you need resource then set it when call setUsername like username/resource, what problem ?

srms-fr commented 5 months ago

Hi, Thanks for reply.

I have try, but auth failed. ''

edit getUsername, it's also an option (no tested)

public function getUsername()
{
        $username = $this->getUsername();
        $username = explode('/', $username);
        return isset($username[0]) ? $username[0] : $username;
}
zorn-v commented 5 months ago

If it s not tested why we should do this ? Let just rewrite random lines with random code :wink:

BTW

  1. You have infinity recursion there (call getUsername from getUsername)
  2. After explode first index is always set.
  3. Even if somehow $username[0] will be not set (or null) you'll return array but not string.
zorn-v commented 5 months ago

Can you tell WHAT EXACTLY problem exists ?

srms-fr commented 5 months ago

Hi, Sorry, quick copy/paste before going👎

  1. When trying to connect with username like username, server return bad-request
[...]
xmpp.DEBUG: Sending data '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">**********************</auth>' to 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Listener "Fabiang\Xmpp\EventListener\Stream\Authentication" is currently blocking [] []
xmpp.DEBUG: Received buffer '<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>' from 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Sending data '<?xml version="1.0" encoding="UTF-8"?> <stream:stream to="domain.com" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">' to 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Listener "Fabiang\Xmpp\EventListener\Stream\Stream" is currently blocking [] []
xmpp.DEBUG: Received buffer '<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' xml:lang='en-US.UTF-8' id='1A67B6960280A' from='domain.com' version='1.0'>' from 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Received buffer '<stream:features><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/><sm xmlns='urn:xmpp:sm:3'><optional/></sm><mdm xmlns='http://protocols.cisco.com/mdm:1'><optional/></mdm><push xmlns='http://protocols.cisco.com/push:2'><service>WNS</service><service>WNS:dev</service><service>APNS</service><service>APNS:beta</service><service>APNS:dev</service><service>FCM</service><service>FCM:dev</service><encrypt><algorithm>A256GCM</algorithm></encrypt><optional/></push><push xmlns='http://protocols.cisco.com/push:3'><service>WNS</service><service>WNS:dev</service><service>APNS</service><service>APNS:beta</service><service>APNS:dev</service><service>FCM</service><service>FCM:dev</service><encrypt><algorithm>A256GCM</algorithm></encrypt><apps/><optional/></push></stream:features>' from 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Sending data '<iq type="set" id="fabiang_xmpp_660c1a1782e36"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource></resource></bind></iq>' to 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Listener "Fabiang\Xmpp\EventListener\Stream\Bind" is currently blocking [] []
xmpp.DEBUG: Received buffer '<iq id='fabiang_xmpp_660c1a1782e36' type='error'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/><error code='400' type='modify'><bad-request xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/></error></iq>' from 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Received buffer '</stream:stream>' from 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Sending data '</stream:stream>' to 'tcp://cisco-imp.domain.com:5222' [] []
[...]
  1. When trying to connect with username like username/ressource, server return not-authorized
    
    [...]
    xmpp.DEBUG: Sending data '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">***************************</auth>' to 'tcp://cisco-imp.domain.com:5222' [] []
    xmpp.DEBUG: Listener "Fabiang\Xmpp\EventListener\Stream\Authentication" is currently blocking [] []
    xmpp.DEBUG: Received buffer '<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'><not-authorized/></failure>' from 'tcp://cisco-imp.domain.com:5222' [] []
    [...]
zorn-v commented 5 months ago

Seems cisco imp does not support resources. Or maybe you need to send full jid like username@cisco-imp.domain.com/resource Why you say that it is required there ?

srms-fr commented 5 months ago

Hi, I would say that Cisco IMP requires the resource field. If I edit the code to have a non-empty resource when sending the iq tag, the connection is made without problem.

xmpp.DEBUG: Sending data '<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">*****=</auth>' to 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Received buffer '<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>' from 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Sending data '<?xml version="1.0" encoding="UTF-8"?> <stream:stream to="domain.com" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" version="1.0">' to 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Received buffer '<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' xml:lang='en-US.UTF-8' id='1B0035D438A5E' from='domain.com' version='1.0'>' from 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Received buffer '<stream:features><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/><session xmlns='urn:ietf:params:xml:ns:xmpp-session'/><sm xmlns='urn:xmpp:sm:3'><optional/></sm><mdm xmlns='http://protocols.cisco.com/mdm:1'><optional/></mdm><push xmlns='http://protocols.cisco.com/push:2'><service>WNS</service><service>WNS:dev</service><service>APNS</service><service>APNS:beta</service><service>APNS:dev</service><service>FCM</service><service>FCM:dev</service><encrypt><algorithm>A256GCM</algorithm></encrypt><optional/></push><push xmlns='http://protocols.cisco.com/push:3'><service>WNS</service><service>WNS:dev</service><service>APNS</service><service>APNS:beta</service><service>APNS:dev</service><service>FCM</service><service>FCM:dev</service><encrypt><algorithm>A256GCM</algorithm></encrypt><apps/><optional/></push></stream:features>' from 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Sending data '<iq type="set" id="fabiang_xmpp_660eccf987c6c"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>fabiang</resource></bind></iq>' to 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Received buffer '<iq id='fabiang_xmpp_660eccf987c6c' type='result'><bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'><jid>stephane.test@domain.com/fabiang</jid></bind></iq>' from 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Sending data '<iq type="set" id="fabiang_xmpp_660eccf98a255"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>' to 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Received buffer '<iq id='fabiang_xmpp_660eccf98a255' type='result'/>' from 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Sending data '<presence><priority>1</priority></presence>' to 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Sending data '<message type="chat" id="fabiang_xmpp_660eccf98abdb" to="stephane.roumesy@domain.com"><body>test</body></message>' to 'tcp://cisco-imp.domain.com:5222' [] []
xmpp.DEBUG: Received buffer '<presence from='stephane.test@domain.com/fabiang' to='stephane.test@domain.com'><priority>1</priority></presence>' from 'tcp://cisco-imp.domain.com:5222' [] [] 
zorn-v commented 5 months ago

I checked code, getUsername used only in auth, so I return username without resource there now. Also I tag version 1.0.0 just in case (possible BC break), so maybe you need to update version constraint in composer.json

srms-fr commented 5 months ago

Thanks, it's works wirth username/resource.