【问题标题】:unix c++ app server using plain authentication not receiving <success> from GCM xmpp ccs使用普通身份验证的 unix c++ 应用服务器未从 GCM xmpp ccs 接收 <success>
【发布时间】:2015-10-29 21:00:48
【问题描述】:

我正在开发 unix C++ 通知应用服务器,但没有使用任何 xmpp 库。 我正在尝试按照https://developers.google.com/cloud-messaging/ccs 的步骤进行握手。我在 ssl 隧道上使用 TLS 协议。

我将以下内容发送到 gcm.googleapis.com:5235 &lt;stream:stream to='gcm.googleapis.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'/&gt;

我收到了来自 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 收到 &lt;success&gt;,但收到零字节并从 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 &lt;your_GCM_Sender_Id&gt;@gcm.googleapis.com (GCM sender ID) and the API key as the password,其中sender IDAPI key 是您在配置客户端应用程序时收集的值。有关获取这些凭据的信息,请参阅您平台的客户端文档。

标签: android c++ unix xmpp google-cloud-messaging


【解决方案1】:

TheWonderBird 的评论绝对有帮助。我还需要做一个修复。我正在发送封闭的 xml &lt;stream:stream to='gcm.googleapis.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'/&gt;。相反,我应该发送&lt;stream:stream to='gcm.googleapis.com' version='1.0' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'&gt;。基本上,不要关闭流。

终于收到&lt;success&gt;

【讨论】:

    【解决方案2】:

    &lt;auth&gt; 中的字符串应该是 base64 编码的\0username\0password 字符串,而不是您的 API 密钥。用户名是senderId@gcm.googleapis.com,密码是您的 API 密钥。我建议您了解更多关于 XMPP 和普通身份验证机制的信息或使用现成的库。

    【讨论】:

      猜你喜欢
      • 2014-11-08
      • 1970-01-01
      • 2014-06-17
      • 1970-01-01
      • 2016-03-03
      • 2014-06-05
      • 1970-01-01
      • 2016-05-24
      • 1970-01-01
      相关资源
      最近更新 更多