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;
}
Exemple #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);
}
Exemple #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);
}
bool GetAddressesOut::pack(San2::Utils::bytes &out)
{
	out.clear();
	return true;
}
Exemple #5
0
int main(int argc, char *argv[])
{
	FILELog::ReportingLevel() = logDEBUG4;
	
	San2::Api::CNodeConnector connector(PIPENAME, 5000, 5000, 5000, 5000);
	
	if (connector.open() != San2::Cppl::ErrorCode::SUCCESS)
	{
		printf("connection failed\n");
		return -1;
	}

	connector.connect();
	
	if (connector.registerPort(2200) == true)
	{
		printf("port register: OK\n");
	}
	else
	{
		printf("port register: FAILURE\n");
	}
	
	San2::Network::SanAddress dstaddr;
	
	if (San2::Utils::string2address("000000000000000000000000000000000000000000000000000000000000FF21", dstaddr) != true)
	{
		FILE_LOG(logDEBUG4) << "failed to parse destination address";
		return -1;
	}
	
	
	San2::Utils::bytes payload;
	payload.append("Ahoj, jak se mas");
	
	San2::Network::CCapsule capsule;
	capsule.setDSdata(2201, 2200, payload);
	capsule.setDestinationAddress(dstaddr);
	
	San2::Utils::bytes serial;
	capsule.pack(serial);

	connector.sendCapsule(serial);
	
	/*
	San2::Network::CCapsule rxcapsule;
	
	printf("awaiting capsule\n");
	SAN_INT32 rval = connector.waitForCapsule(rxcapsule, 5000);
	
	switch(rval)
	{
		case SAN2_WAITFORCAPSULE_SUCCESS:
			printf("got: rxcapsule\n");
			break;
		case SAN2_WAITFORCAPSULE_TIMEOUT:
			printf("got: timeout\n");
			break;
		case SAN2_WAITFORCAPSULE_ERROR_INVALID_RESPONSE:
			printf("got: error invalid response\n");
			break;	
		case SAN2_WAITFORCAPSULE_ERROR_CAPSULE_UNPACK:
			printf("got: error capsule unpack\n");
			break;	
		case SAN2_WAITFORCAPSULE_ERROR_INVOKE_FAILED:	
			printf("got: error INVOKE FAILED\n");
			break;	
		case SAN2_WAITFORCAPSULE_ERROR:
			printf("got: GENERAL ERROR\n");
			break;	
		default:
			printf("got: UNKNOWN ERROR\n");
			break;
	}
	*/
	
	return 0;
}