// --------------------------------------------------------------------------------------
void Ajp13Socket::OnTransferLimit()
{
	char msg[8192];
	msg[0] = 'A';
	msg[1] = 'B';

	// Send Body Chunk
	size_t n = m_res.GetFile().fread(msg + 7, 1, 8100);
	while (n > 0)
	{
		int ptr = 4;
		put_byte(msg, ptr, 0x03); // send body chunk
		put_integer(msg, ptr, (short)n);
		ptr += (int)n;

		short len = htons( ptr - 4 );
		memcpy( msg + 2, &len, 2 );

		SendBuf( msg, ptr );
		if (GetOutputLength() > 1)
		{
			SetTransferLimit( 1 );
			break;
		}

		//
		n = m_res.GetFile().fread(msg + 7, 1, 8100);
	}
	if (!GetOutputLength()) // all body data sent and no data in output buffer - send end response
	{
		// End Response
		int ptr = 4;
		put_byte(msg, ptr, 0x05); // end response
		put_boolean(msg, ptr, false); // reuse
		/*
			don't reuse
			- but with m_req.Reset() and m_res.Reset() it should be possible
			- also reset any AjpBaseSocket/Ajp13Socket specific states
		*/

		short len = htons( ptr - 4 );
		memcpy( msg + 2, &len, 2 );

		SendBuf( msg, ptr );

		SetTransferLimit(0);
		m_res.GetFile().fclose();
		OnResponseComplete();
	}
}
Exemple #2
0
	// Encode pIntput into pOutput.  Input length in lSize.  Returned value
	// is length of output which will be even MOD 8 bytes.  Input buffer and
	// output buffer can be the same, but be sure buffer length is even MOD 8.
DWORD CBlowFish::Encode (BYTE * pInput, BYTE * pOutput, DWORD lSize)
{
	DWORD 	lCount, lOutSize, *dwOutput = (DWORD *)pOutput;
	_int64	CBCval = 0;

	if (pInput != pOutput)
		memcpy(pOutput, pInput, lSize);

	lOutSize = GetOutputLength(lSize);
	memset(pOutput + lSize, mode == CBC ? lOutSize - lSize : 0, lOutSize - lSize);

	for (lCount = 0; lCount < lOutSize; lCount += 8)
	{
		if (mode == CBC)
			*(_int64 *)dwOutput ^= CBCval;

		change_order(dwOutput); change_order(dwOutput + 1);

		Blowfish_encipher(dwOutput, dwOutput + 1);

		change_order(dwOutput); change_order(dwOutput + 1);

		if (mode == CBC)
			CBCval = *(_int64 *)dwOutput;
		dwOutput += 2;
	}

	return lOutSize;
}
	// Encrypt pIntput into pOutput.  Input length in lSize.  Returned value
	// is length of output which will be even MOD 8 bytes.  Input buffer and
	// output buffer can be the same, but be sure buffer length is even MOD 8.
DWORD CBlowFish::Encrypt(const BYTE *pInput, BYTE *pOutput, DWORD lSize, int mode, _int64 IV)
{
	DWORD 	lCount, lOutSize, *dwOutput = (DWORD *)pOutput;

	if (pInput != pOutput)
		memcpy(pOutput, pInput, lSize);

	lOutSize = GetOutputLength(lSize, mode);
	memset(pOutput + lSize, (mode & BF_PKCS5) ? lOutSize - lSize : 0, lOutSize - lSize);

	for (lCount = 0; lCount < lOutSize; lCount += BF_BLKSIZE)
	{
		if (mode & BF_CBC)
			*(_int64 *)dwOutput ^= IV;

		change_order(dwOutput); change_order(dwOutput + 1);

		Blowfish_encipher(dwOutput, dwOutput + 1);

		change_order(dwOutput); change_order(dwOutput + 1);

		if (mode & BF_CBC)
			IV = *(_int64 *)dwOutput;
		dwOutput += 2;
	}

	return lCount;
}
Exemple #4
0
	// Encode pIntput into pOutput.  Input length in lSize.  Returned value
	// is length of output which will be even MOD 8 bytes.  Input buffer and
	// output buffer can be the same, but be sure buffer length is even MOD 8.
DWORD CBlowFish::Encode (BYTE * pInput, BYTE * pOutput, DWORD lSize)
{
	DWORD 	lCount, lOutSize, lGoodBytes ;
	BYTE	*pi, *po ;
	int		i, j ;
	int		SameDest = (pInput == pOutput ? 1 : 0) ;

	lOutSize = GetOutputLength (lSize) ;
	for (lCount = 0 ; lCount < lOutSize ; lCount += 8)
	{
		if (SameDest)	// if encoded data is being written into input buffer
		{
		 	if (lCount < lSize - 7)	// if not dealing with uneven bytes at end
		 	{
		 	 	Blowfish_encipher ((DWORD *) pInput,
		 	 		(DWORD *) (pInput + 4)) ;
		 	}
		 	else		// pad end of data with null bytes to complete encryption
		 	{
				po = pInput + lSize ;	// point at byte past the end of actual data
				j = (int) (lOutSize - lSize) ;	// number of bytes to set to null
				for (i = 0 ; i < j ; i++)
					*po++ = 0 ;
		 	 	Blowfish_encipher ((DWORD *) pInput,
		 	 		(DWORD *) (pInput + 4)) ;
		 	}
		 	pInput += 8 ;
		}
		else 			// output buffer not equal to input buffer, so must copy
		{               // input to output buffer prior to encrypting
		 	if (lCount < lSize - 7)	// if not dealing with uneven bytes at end
		 	{
		 		pi = pInput ;
		 		po = pOutput ;
		 		for (i = 0 ; i < 8 ; i++)
// copy bytes to output
		 			*po++ = *pi++ ;
		 	 	Blowfish_encipher ((DWORD *) pOutput,	// now encrypt them
		 	 		(DWORD *) (pOutput + 4)) ;
		 	}
		 	else		// pad end of data with null bytes to complete encryption
		 	{
		 		lGoodBytes = lSize - lCount ;	// number of remaining data bytes
		 		po = pOutput ;
		 		for (i = 0 ; i < (int) lGoodBytes ; i++)
		 			*po++ = *pInput++ ;
		 		for (j = i ; j < 8 ; j++)
		 			*po++ = 0 ;
		 	 	Blowfish_encipher ((DWORD *) pOutput,
		 	 		(DWORD *) (pOutput + 4)) ;
		 	}
		 	pInput += 8 ;
		 	pOutput += 8 ;
		}
	}
	return lOutSize ;
 }
Exemple #5
0
	void OnConnect() {
		Utility::GetTime(&m_start);
		while (GetOutputLength() < 500000)
		{
			Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
			Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
			Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
			Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
			Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
			Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
			Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
			Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
		}
//		Send("\r\n");
	}
Exemple #6
0
	void OnWriteComplete() {
printf("OnWriteComplete\n");
		struct timeval tv;
		Utility::GetTime(&tv);

		tv.tv_sec -= m_start.tv_sec;
		tv.tv_usec -= m_start.tv_usec;
		Utility::GetTime(&m_start);
		if (tv.tv_usec < 0)
		{
			tv.tv_usec += 1000000;
			tv.tv_sec -= 1;
		}
		double t = tv.tv_usec;
		t /= 1000000;
		t += tv.tv_sec;
		printf("  Time: %ld.%06ld (%f)\n", tv.tv_sec, tv.tv_usec, t);
		double r = GetBytesReceived();
		printf("  bytes in: %lld (%f Mbytes/sec)\n", GetBytesReceived(true), r / t / 1000000);
		double s = GetBytesSent();
		printf("  bytes out: %lld (%f Mbytes/sec)\n", GetBytesSent(true), s / t / 1000000);
		printf("\n");

		while (GetOutputLength() < 500000)
		{
			Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
			Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
			Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
			Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
			Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
			Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
			Send("zzzzzzzzzmmmmmmmmm1234lkkk54\r\n");
			Send("zzzzzzzzzmmmmmmmmm1234lkkk543\r\n");
		}
//		Send("\r\n");
	}
Exemple #7
0
/// Check if there is lag on the connection to the client
bool AuthSocket::IsLag()
{
    return (TCP_BUFSIZE_READ-GetOutputLength() < 2 * ChunkSize);
}
Exemple #8
0
// Encode pIntput into pOutput.  Input length in lSize.  Returned value
// is length of output which will be even MOD 8 bytes.  Input buffer and
// output buffer can be the same, but be sure buffer length is even MOD 8.
bool BlowfishPIMPL::Encode(const void * const input_ptr, uint64_t input_size, void * output_ptr, uint64_t output_size)
{
	uint64_t lCount, lOutSize, lGoodBytes;
	uint8_t * pi, * po;
	uint64_t i, j;
	bool sameDest = (input_ptr == output_ptr);
	uint8_t * pInput = reinterpret_cast<uint8_t *>(const_cast<void *>(input_ptr));
	uint8_t * pOutput = reinterpret_cast<uint8_t *>(output_ptr);

	if(!input_ptr || !output_ptr)
	{
		return false;
	}

	lOutSize = GetOutputLength(input_size);
	if(output_size < lOutSize)
	{
		return false;
	}

	for(lCount = 0; lCount < lOutSize; lCount += 8)
	{
		if(sameDest)	// if encoded data is being written into input buffer
		{
			if(lCount < input_size - 7)	// if not dealing with uneven bytes at end
			{
				Blowfish_encipher(reinterpret_cast<uint32_t *>(pInput), reinterpret_cast<uint32_t *>(pInput + 4));
			}
			else		// pad end of data with null bytes to complete encryption
			{
				po = pInput + input_size;	// point at byte past the end of actual data
				j = lOutSize - input_size;	// number of bytes to set to null
				for(i = 0; i < j; i++)
					*po++ = 0;
				Blowfish_encipher(reinterpret_cast<uint32_t *>(pInput), reinterpret_cast<uint32_t *>(pInput + 4));
			}
			pInput += 8;
		}
		else 			// output buffer not equal to input buffer, so must copy
		{               // input to output buffer prior to encrypting
			if(lCount < input_size - 7)	// if not dealing with uneven bytes at end
			{
				pi = pInput;
				po = pOutput;
				for(i = 0; i < 8; i++)
					// copy bytes to output
					*po++ = *pi++;
				// now encrypt them
				Blowfish_encipher(reinterpret_cast<uint32_t *>(pOutput), reinterpret_cast<uint32_t *>(pOutput + 4));
			}
			else		// pad end of data with null bytes to complete encryption
			{
				lGoodBytes = input_size - lCount;	// number of remaining data bytes
				po = pOutput;
				for(i = 0; i < lGoodBytes; i++)
					*po++ = *pInput++;
				for(j = i; j < 8; j++)
					*po++ = 0;
				Blowfish_encipher(reinterpret_cast<uint32_t *>(pOutput), reinterpret_cast<uint32_t *>(pOutput + 4));
			}
			pInput += 8;
			pOutput += 8;
		}
	}
	return true;
}