简体   繁体   中英

unix c++ app server using plain authentication not receiving <success> from GCM xmpp ccs

I am developing unix C++ notification app server and not using any xmpp library. I am trying to follow steps from https://developers.google.com/cloud-messaging/ccs for handshaking. I am using TLS protocol over ssl tunnel.

I sent following to gcm.googleapis.com:5235 <stream:stream to='gcm.googleapis.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'/>

I have received following two messages from gcm.googleapis.com:5235 in response 1. <stream:stream from="gcm.googleapis.com" id="60D46BF12BAF72D3" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client"> 2. <stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features>

And, I sent following message in response. I tried using encode64 code from gloox. I also tried using inhouse Base64::encode_8bit. Following is the fix after TheWonderBird's comments but no success yet.

stringstream key; 
key << '\0' << senderId << "@gcm.googleapis.com" << '\0' << apiKey; 
string hexkey = encode64(key.str()); 
stringstream auth; 
auth << "<auth mechanism='PLAIN' xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>" << hexkey << "</auth>"; 
string authStr = auth.str(); 
sslSock_->write(authStr.c_str(), authStr.length());

I was expecting to receive <success> from gcm.googleapis.com:5235 but receiving zero bytes instead and getting error code 5 from SSL_get_error function call. I am not sure what am I doing wrong here since I am following the steps from https://developers.google.com/cloud-messaging/ccs

Also, I do not see what is the use of sender-id since steps do not mention it to be sent anywhere.

Can anybody guide me please? Please note that I am not allowed to use any xmpp library and I have to develop this in Unix C++.

The string inside <auth> is supposed to be base64 encoded \\0username\\0password string, not your API key. The username is senderId@gcm.googleapis.com , password is your API key. I suggest you learn more about XMPP and plain auth mechanism or use a ready library.

TheWonderBird's comment definitely helped. There was one more fix I had to do. I was sending closed xml <stream:stream to='gcm.googleapis.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'/> . Instead I should send <stream:stream to='gcm.googleapis.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'> . Basically, do not close the stream.

Received <success> finally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM