2015-04-15 29 views
4

我正在爲iOS做unix服務器ssh模擬。在談判過程中,我遇到了許多障礙,仍然與這些障礙作鬥爭。最新的一個是關於SSH2_MSG_KEX_DH_GEX_REPLY分組數據,其中我收到錯誤的數據包長度(可能是無關的填充)。對整個過程的數據包描述如下:SSH協商:錯誤的SSH2_MSG_KEX_DH_GEX_REPLY或別的?

Client : connection with aix.polarhome.com with port 775 (changed port for ssh) using GCDAsyncSocket 
Server : SSH-2.0-OpenSSH_6.0 
Client : send SSH-2.0-OpenSSH_6.0 

(Rest packet will follow BPP protocol) 
Server : SSH2_MSG_KEXINIT with set of supported algorithms 
Client : SSH2_MSG_KEXINIT with set of common algorithms 

Client : SSH2_MSG_KEX_DH_GEX_REQUEST_OLD 
     code: 
    SignedByte sendByte[1920]; 
    int writeIndex = 0; 

    minGroupLength = 1024; 
    prefGroupLength = 1024; 
    maxGroupLength = 4096; 

    sendByte[writeIndex++] = SSH2_MSG_KEX_DH_GEX_REQUEST_OLD; 

    [self write32BitInteger:prefGroupLength toPacket:sendByte fromIndex:writeIndex]; 
    writeIndex += 4; 

    [self sendSSHBinaryPacketPayload:sendByte toLength:writeIndex]; 
    writeIndex = 0; 

Server : SSH2_MSG_KEX_DH_GEX_GROUP 

client -> fetch values of p and g 
     compute value of e (1 < e < (p-1)/2) 

Client : SSH2_MSG_KEX_DH_GEX_INIT 
     Code 
SignedByte sendByte[1920]; 
    int writeIndex = 0; 

NSInteger eByteCount = [[e description] stringByReplacingOccurrencesOfString:@" " withString:@""].length/2; 

sendByte[writeIndex++] = SSH2_MSG_KEX_DH_GEX_INIT; 

[self write32BitInteger:eByteCount toPacket:sendByte fromIndex:writeIndex]; 
writeIndex += 4; 

Byte eBytes[eByteCount]; 
NSInteger length = [self getBytes:eBytes fromBigInteger:e]; 
for (int i = 0; i < length; i++) { 
    sendByte[writeIndex++] = eBytes[i]; 
} 

[self sendSSHBinaryPacketPayload:sendByte toLength:writeIndex]; 
writeIndex = 0; 

Server : SSH2_MSG_KEX_DH_GEX_REPLY 
Total length : 720 
Packet length (4 bytes): 00 00 02 bc (700 which should be 720 - 4 = 716) Don't Know why this 700? 

client -> read host key and verify it 
     read value of f 
     read signature and verify it 

Client : SSH2_MSG_NEWKEYS 

現在發出後最後一個數據包服務器嘲笑和SSH2_MSG_NEWKEYS返回的數據。

我看着其他ssh模擬器的代碼,但沒有一個幫助。 我完全不知道該怎麼做,請幫忙,我真的很沮喪。

+0

嘗試使用putty的wireshark或可能是mac終端並比較數據。 –

回答

0

每@revinder的評論:

我解決我自己的服務器發送的兩個包合併成一個,將SSH2_MSG_KEX_DH_GEX_REPLY和SSH2_MSG_NEWKEYS。

+0

是的,我以後也嘗試過。它確實有效,但卻陷入了下一步。 – Revinder