示例#1
0
int ClientSession::getShellServerResponse(DragonSRP::DatagramEncryptor& encryptor, DragonSRP::DatagramDecryptor& decryptor, const San2::Utils::bytes& shellRequest, San2::Utils::bytes& shellResponse)
{
	int rval;
	unsigned char errorCode;
	San2::Utils::bytes encryptedRequest, serverRequest, serverResponse, encryptedResponse;
	std::uint64_t sequenceNumber = m_swtx.getNextSequenceNumber(); // important
	unsigned int encpacketLen, decpacketLen;
	
	shellResponse.clear();
	
	if (shellRequest.size() > SH_MAX_MSGLEN)
	{
		printf("ClientSession::getShellServerResponse:error: Message too big (shellRequest.size() > SH_MAX_MSGLEN)\n");
		return -1;
	}
	
	encryptedRequest.resize(encryptor.getOverheadLen() + SH_MAX_MSGLEN);
	encryptor.encryptAndAuthenticate((unsigned char *)&shellRequest[0], shellRequest.size(), sequenceNumber, &encryptedRequest[0], &encpacketLen); // throws
	encryptedRequest.resize(encpacketLen);
	
	rval = enc_construct_C_message(encryptedRequest, serverRequest);
	
	if (rval)
	{
		printf("ClientSession::getShellServerResponse:enc_construct_C_message failed: %d\n", rval);
		return -2;
	}
	
	if (m_swtx.sendReliableMessage(serverRequest, serverResponse) == false)
	{
		printf("Could not send message to terminal server\n");
		return -3;
	}
	
	rval = enc_parse_R_message(serverResponse, encryptedResponse, errorCode);
	
	if (rval)
	{
		printf("ClientSession::getShellServerResponse:enc_parse_R_message failed: %d\n", rval);
		return -4;
	}
	
	if (errorCode != 0)
	{
		printf("ClientSession::getShellServerResponse: R message errorcode is non zero: %d\n", errorCode);
		return -5;
	}
	
	shellResponse.resize(decryptor.getOverheadLen() + SH_MAX_MSGLEN);
	decryptor.decryptAndVerifyMac(&encryptedResponse[0], encryptedResponse.size(), &shellResponse[0], &decpacketLen, sequenceNumber);
	shellResponse.resize(decpacketLen);
	
	return 0;
}
示例#2
0
bool GetAddressesOut::pack(San2::Utils::bytes &out)
{
	out.clear();
	return true;
}