Example #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;
}
Example #2
0
SAN_UINT32 CDataPack::unpackUint32(const San2::Utils::bytes &data, unsigned int position)
{
	if (data.size() < position + sizeof(SAN_UINT32)) return 0; // error
	SAN_UINT32 num;
	memcpy(&num, &data[position], sizeof(SAN_UINT32));
	return San2::Utils::Endian::san_u_be32toh(num);
}
Example #3
0
SAN_INT64 CDataPack::unpackInt64(const San2::Utils::bytes &data, unsigned int position)
{
	if (data.size() < position + sizeof(SAN_INT64)) return 0; // error
	SAN_INT64 num;
	memcpy(&num, &data[position], sizeof(SAN_INT64));
	return San2::Utils::Endian::san_s_be64toh(num);
}