Reputation: 19
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++.
Upvotes: 0
Views: 295
Reputation: 19
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.
Upvotes: 1
Reputation: 663
The string inside <auth>
is supposed to be base64 encoded \0username\0password
string, not your API key. The username is [email protected]
, password is your API key. I suggest you learn more about XMPP and plain auth mechanism or use a ready library.
Upvotes: 2