Jabber服务器没有回复客户端最终消息
本文关键字:消息 客户端 回复 服务器 Jabber | 更新日期: 2023-09-27 18:18:38
我正在开发自己的Jabber客户端(主要是学习XMPP和c#),目前我正在尝试使用TLS上的SCARAM-SHA-1连接到服务器。TLS协商进行得很好,以及第一个客户端/服务器消息交换,我得到服务器挑战并生成客户端最终消息,代码如下:
//Following block generates Client Final Message
//---STEP 1. Creating Salted Password---
byte[] SaltBytes = Encoding.UTF8.GetBytes(Salt);
byte[] SaltedPasswordBytes = GetSaltedPassword(UserPassword, Convert.FromBase64String(Salt), Iterations);
//---STEP 2. Creating Client Key---
byte[] ClientKeyBytes = GetHash("Client Key", SaltedPasswordBytes);
string ClientKey = BitConverter.ToString(ClientKeyBytes);
//---STEP 3. Creating Stored Key---
SHA1 StoredKeySHA = SHA1.Create();
byte[] StoredKeyBytes = StoredKeySHA.ComputeHash(ClientKeyBytes);
string StoredKey = BitConverter.ToString(StoredKeyBytes);
//---STEP 4. Creating Auth Message---
string AuthMessage = "n=test_guy,r=" + ClientNonce + "," + ServerChallenge + "," + "c=" + StringToBase64("n,,") + ",r=" + ClientAndServerNonces; //concern: AuthMessage might start with "n=<username>" or "n,,n=<username>" - which one is right?
LogRTB.Text += "AuthMessage is:'n" + AuthMessage + "'n";
//---STEP 5. Creating Client Signature---
byte[] ClientSignatureBytes = GetHash(AuthMessage, StoredKeyBytes);
string ClientSignature = BitConverter.ToString(ClientSignatureBytes);
//---STEP 6. Creating Client Proof---
LogRTB.Text += "---STEP 6. Calculating Client Proof---'n" + "Client Key is: " + ClientKey + "'nClientSignature is: " + ClientSignature;
byte[] ClientProofBytes = new byte[ClientKeyBytes.Length];
for (int i = 0; i < ClientKeyBytes.Length; ++i)
{
ClientProofBytes[i] = (byte)(ClientKeyBytes[i] ^ ClientSignatureBytes[i]);
}
LogRTB.Text += "'nClient Proof (string) is: " + ClientProof + "'n";
//---STEP 7. Creating Server Key---
byte[] ServerKeyBytes = GetHash("Server Key", SaltedPasswordBytes);
string ServerKey = BitConverter.ToString(ServerKeyBytes);
LogRTB.Text += "Server Key is: " + ServerKey + "'n";
//---STEP 8. Creating Server Signature---
byte[] ServerSignatureBytes = GetHash(AuthMessage, ServerKeyBytes);
string ServerSignature = Convert.ToBase64String(ServerSignatureBytes);
//DONE!
ClientProof = StringToBase64(ClientProof);
string ClientResponse = "c=biws,r=" + ClientAndServerNonces +",p=" + ClientProof; //putting together Client Response (most important part of Client Final Message)
//ClientResponse.Replace("==",""); //NO! just no!
LogRTB.Text += "Client response is:'n" + ClientResponse + "'n"; //DEBUG!
string ClientResponseBase64 = StringToBase64(ClientResponse);
if (IsBase64String(ClientResponseBase64))
{
string ClientFinalMessage = "<response xmlns='"urn:ietf:params:xml:ns:xmpp-sasl'">" + ClientResponseBase64 + "</response>";
LogRTB.Text += "--> Client response (Client Final Message) is:'n" + ClientFinalMessage + "'n";
LogRTB.Text += "--> SENDING NOW!'n";
ServerReply = SendXMPPQueryOverTLS(ServerSocket, SecureConnection, ClientFinalMessage); //Sending Client Final Message
LogRTB.Text += ServerReply;
}
问题是-我没有从服务器得到任何回复,当根据RFC6120 (XMPP核心)服务器应该回复失败或成功消息。此外,如果我故意发送错误的消息(例如省略客户端证明),它会回复坏协议消息。服务器使用默认设置。
我花了几天时间想弄清楚出了什么问题,现在有点绝望了。我希望这里有人能帮助我。
(如果需要,我也可以提供我的应用程序在连接过程中生成的日志)
提前感谢!
我已经测试了agsXMPP SCRAM实现,它与ejabberd一起工作良好。试着与您的代码进行比较- https://github.com/meebey/agsxmpp/blob/master/agsxmpp/Sasl/Scram/ScramSha1Mechanism.cs