3

I am writing an XMPP client for a university project which is supposed to send and receive messages from other clients. I have basic knowledge on XMPP and its' syntax, but can't seem to be able to connect to the gtalk server. Disclaimer - I can't use Smack or any other library.

Socket s = new Socket("talk.l.google.com", 5222);
PrintWriter out = new PrintWriter(s.getOutputStream());
out.println("<?xml version='1.0' encoding='utf-8' ?>");
out.println("<stream:stream "
        + "xmlns='jabber:client' "
        +" from='example@gmail.com' to='gmail.com' "
        + " xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>");
out.flush();

I assume that the connection is successful as I am getting this response:

<stream:stream from="gmail.com" id="E3A7EFC5647601B3" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client"><stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"><required/></starttls><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism></mechanisms></stream:features>

If I try to send some xml packet, for example, a message, I obviously get a

<stream:error><not-authorized xmlns="urn:ietf:params:xml:ns:xmpp-streams"/></stream:error>

I send the message like so:


out.println("<message to='07xcpozn829nd25ivx1gpp3dug@public.talk.google.com'" 
         +"from='example@gmail.com'>\r\n"
         +"<body>Wherefore art thou?</body>\r\n" 
         +"</message>");

  • https://xmpp.org/rfcs/rfc6120.html#sasl says, that not-authorized error has to do with me not being authenticated with the server. I have looked through google, stackoverflow, xmpp's original rfc and I can't seem to find any information on how I should authenticate myself with the server. I also can't seem to find any example code on stackoverflow or any other platform, since everyone are just suggesting to use Smack or any other xmpp library.
  • Another thing regarding the stream negotiation part is that my part has a 'from' attribute, which should mean, that the server response should include a 'to' attribute, but that just isn't the case. Example:
I: <?xml version='1.0'?>
   <stream:stream
       from='juliet@im.example.com'
       to='im.example.com'
       version='1.0'
       xml:lang='en'
       xmlns='jabber:client'
       xmlns:stream='http://etherx.jabber.org/streams'>

R: <?xml version='1.0'?>
   <stream:stream
       from='im.example.com'
       id='++TR84Sm6A3hnt3Q065SnAbbk3Y='
       to='juliet@im.example.com'
       version='1.0'
       xml:lang='en'
       xmlns='jabber:client'
       xmlns:stream='http://etherx.jabber.org/streams'>
Mantas
  • 63
  • 1
  • 7

1 Answers1

0

You must have missed the authentication part during SASL negociation.

Check chapter 9.1. Client-to-Server Examples in https://datatracker.ietf.org/doc/rfc6120/

Queeg
  • 7,748
  • 1
  • 16
  • 42