【发布时间】:2015-10-29 21:00:48
【问题描述】:
我正在开发 unix C++ 通知应用服务器,但没有使用任何 xmpp 库。 我正在尝试按照https://developers.google.com/cloud-messaging/ccs 的步骤进行握手。我在 ssl 隧道上使用 TLS 协议。
我将以下内容发送到 gcm.googleapis.com:5235
<stream:stream to='gcm.googleapis.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'/>
我收到了来自 gcm.googleapis.com:5235 的以下两条回复消息
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>
并且,我发送了以下消息作为回应。我尝试使用来自 gloox 的 encode64 代码。我也尝试使用内部 Base64::encode_8bit。以下是 TheWonderBird 的 cmets 之后的修复,但尚未成功。
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());
我期待从 gcm.googleapis.com:5235 收到 <success>,但收到零字节并从 SSL_get_error 函数调用中获取错误代码 5。我不确定我在这里做错了什么,因为我正在按照https://developers.google.com/cloud-messaging/ccs的步骤进行操作
另外,我看不出 sender-id 有什么用,因为步骤中没有提到要发送到任何地方。
有人可以指导我吗?请注意,我不允许使用任何 xmpp 库,我必须在 Unix C++ 中开发它。
【问题讨论】:
-
连接有两个重要要求:你必须
initiate a Transport Layer Security (TLS) connection。请注意,CCS 目前不支持 STARTTLS 扩展。CCS requires a SASL PLAIN authentication mechanism using <your_GCM_Sender_Id>@gcm.googleapis.com (GCM sender ID) and the API key as the password,其中sender ID和API key是您在配置客户端应用程序时收集的值。有关获取这些凭据的信息,请参阅您平台的客户端文档。
标签: android c++ unix xmpp google-cloud-messaging