2014-08-18 2 views
0

Я работаю над своим клиентом Jabber (в основном, чтобы узнать как XMPP, так и C#), и в настоящее время я пытаюсь подключиться к серверу с помощью SCARAM-SHA-1 через TLS. TLS переговоры идет отлично, а также первого обмена клиент/сервер сообщений, я получаю сервера вызов и генерируя Client окончательное сообщение с помощью следующего кода:Сервер Jabber не отвечает на окончательное сообщение клиента

//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 Core) сервер должен ответить сбой или успех сообщение. Кроме того, если я намеренно отправляю неправильное сообщение (например, опустив Client Proof), он отвечает с сообщением bad-protocol. Сервер - ejabberd с настройками по умолчанию.

Я провел пару дней, пытаясь понять, что случилось, и теперь немного отчаянно. Надеюсь, кто-то здесь сможет мне помочь.

(В случае необходимости я могу предоставить логи, что мое приложение генерирует в процессе соединения)

Спасибо заранее!

ответ

Смежные вопросы