Ejemplo n.º 1
0
void Honor2Logic::OnNewMessage( char* messageText )
{
	fresult fres;

	fres = ShowMessage("Новое сообщение!", BlueMail, messageText, FALSE);
	if (fres!=SUCCESS)
	{
		ReportError("Can't Show message");
		return;
	}

	_App->DoVibroAndBeep();

	fres = AppendLog(LogKindMessages, messageText);
	if (fres!=SUCCESS)
	{
		ReportError("Can't append Log");
		return;
	}
	fres = AppendLog(LogKindMessages, "\n");
	if (fres!=SUCCESS)
	{
		ReportError("Can't append Log");
		return;
	}	
}
Ejemplo n.º 2
0
/*
* Handle the Public Key A according to Diffie-Hellman 
* key exchange procedure.  	
*  
* Send the respons as Public Key P. 
* 
*/
inline void SecureChatIOCP::OnPKG_PUBLIC_KEYA(CIOCPBuffer *pOverlapBuff, int nSize, ClientContext *pContext)
{	

	// Be safe
	if ( !pContext || !pContext->m_pPublickey || !pOverlapBuff )
		return;

	pContext->m_ContextLock.Lock();
	// Generate private key.. (just a Random nr) 
	pContext->m_cCryptLib.BNMakeRandomNr(pContext->m_Privatekey,_PRIVATEKEYSIZE_);
	pContext->m_ContextLock.Unlock();

	if ( ComputeAndSetSessionKey(pOverlapBuff,nSize,pContext) )
	{
		AppendLog("Received public key A..");
		// Compute And Send Public Key B. 
		// FIXME : Should post this part into the 
		// IOCP for fair cpu clock distribution.
		// Takes about ~40ms.. 
		ComputeAndSendPublicKeyB(pContext);

		// if USE_SIGNATURE is defined here we do not set the m_bGotSessionKey to true, even if 
		// the session key is exchanged. Because we 
		// Are not protected from "Man in middle attacks". 
#ifndef USE_SIGNATURE
		pContext->m_ContextLock.Lock();
		pContext->m_bGotSessionKey=TRUE;
		// We have Secure Connection to the server. 
		// Send the user name and password..
		BuildAndSend(pContext,PKG_USERNAME_PASSWORD,pContext->m_sUsername,"dummypwd");
		pContext->m_ContextLock.Unlock();
		AppendLog("Secure connection established.");		
#endif
	}
}
Ejemplo n.º 3
0
BOOL SecureChatIOCP::SendTextMessageTo(ClientContext* pContext, CString sMsg)
{

	if ( !pContext->m_bGotSessionKey )
	{
		//AppendLog("Client is not authorized");
		return FALSE;
	}

	UINT nBufLen = sMsg.GetLength();
	// Add one to the size header for the null termination byte. 
	nBufLen++;
	// Add one for the Payload type (text)
	nBufLen++;

	if ( nBufLen>=MaxEncyptedPayloadSize(MAXIMUMPAYLOADSIZE-2) )
	{
		AppendLog("SendMessageTo FAILED Message to long for encryption..");
		return FALSE;
	}

	if ( nBufLen>=MAXIMUMPAYLOADSIZE || nBufLen<=0 )
	{
		AppendLog("SendMessageTo FAILED Message to long or zero..");
		return FALSE;
	}

	CIOCPBuffer *pBuff=AllocateBuffer(IOWrite);

	if ( !pBuff )
	{
		AppendLog("SendMessageTo FAILED pOverlapBuff=NULL");
		return FALSE;
	}

	pBuff->EmptyUsed();
	// Size Header
	pBuff->AddData(nBufLen);
	// Payload Header 
	pBuff->AddData((BYTE)PKG_TEXT_TO_ALL);
	// Add the string. 
	int length=sMsg.GetLength();
	pBuff->AddData((PBYTE) sMsg.GetBuffer(length),length);
	//Extra Null Teriminate (for Strings) 
	pBuff->AddData((BYTE)'\0');
	// Encrypt the buffer
	pBuff=EnCryptBuffer(pBuff,pContext);
	// Send it. 
	ASend(pContext,pBuff);
	return TRUE;

}
Ejemplo n.º 4
0
BOOL CALLBACK ClientProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
	LPSOCKET_INFO	SocketInfo;
	DWORD			SendBytes;
	LPSTR			psBuff;

	psBuff = (LPSTR)VirtualAlloc((LPVOID)NULL, (DWORD)(255),
					MEM_COMMIT, PAGE_READWRITE);
	
	if (WSAGETSELECTERROR(lParam)) {
		wsprintf(psBuff, (LPCTSTR)"Socket failed with error %d", WSAGetLastError());
		AppendLog(psBuff);
	}
	else {
		switch (WSAGETSELECTEVENT(lParam)) {
			case FD_CONNECT:
				CreateSocketInfo(wParam);
				break;

			case FD_WRITE:
				SocketInfo = GetSocketInfo(wParam);

				if (SocketInfo->DataBuff.len == 0) {
					SocketInfo->DataBuff.buf = SocketInfo->Buffer;
					SocketInfo->DataBuff.len = 0;
				}

				if (WSASend(SocketInfo->Socket, &(SocketInfo->DataBuff), 1, &SendBytes,
					0, NULL, NULL) == SOCKET_ERROR) {
						if (WSAGetLastError() != WSAEWOULDBLOCK) {
							wsprintf(psBuff, (LPCTSTR)"WSASend() failed with error %d", WSAGetLastError());
							AppendLog(psBuff);
							//FreeSocketInfo(wParam);
						}
				}
				else { // Update the byte count
					SocketInfo->BytesSEND += SendBytes;
				}
				break;

			case FD_CLOSE:
				wsprintf(psBuff, (LPCTSTR)"Closing socket %d", wParam);
				AppendLog(psBuff);
				FreeSocketInfo(wParam);
				break;
		}
		return FALSE;
	}

	return FALSE;
}
Ejemplo n.º 5
0
void SecureChatIOCP::BuildAndSend(ClientContext *pContext, BYTE _pkgtype, UINT nBufferSize1,const BYTE *_pBuff1, UINT nBufferSize2, const BYTE *_pBuff2)
{

	if ( !pContext->m_bGotSessionKey )
	{
		AppendLog("BuildAndSend FAILED, no Session key..");
		return;
	}

	UINT nPayLoadLen=sizeof(BYTE)+sizeof(UINT)+nBufferSize1+sizeof(UINT)+nBufferSize2+2; // two null termination. 

	if ( nPayLoadLen > MAXIMUMPAYLOADSIZE)
	{
		AppendLog("BuildAndSend FAILED, nPayLoadLen > MAXIMUMPAYLOADSIZE");
		return;
	}

	if ( nPayLoadLen > MaxEncyptedPayloadSize(MAXIMUMPAYLOADSIZE-1) )
	{
		AppendLog("BuildAndSend FAILED, nPayLoadLen > MaxEncyptedPayloadSize");
		return;  
	}


	CIOCPBuffer *pBuff=AllocateBuffer(IOWrite);
	if ( !pBuff )
	{
		AppendLog("BuildAndSend FAILED pBuff=NULL");
		return;
	}

	pBuff->EmptyUsed();
	// Size Header
	pBuff->AddData(nPayLoadLen);
	// Payload type 
	pBuff->AddData((BYTE)_pkgtype);
	// The size of the buffer
	pBuff->AddData(nBufferSize1);	
	// add the buffer. 
	pBuff->AddData(_pBuff1,nBufferSize1);
	pBuff->AddData((BYTE)0);
	// The size of the buffer
	pBuff->AddData(nBufferSize2);	
	// add the buffer. 
	pBuff->AddData(_pBuff2,nBufferSize2);
	pBuff->AddData((BYTE)0);
	// Encrypt the data.. 
	pBuff=EnCryptBuffer(pBuff,pContext);
	ASend(pContext,pBuff);
}
Ejemplo n.º 6
0
BOOL Server(void) {
	DWORD		Ret;
	SOCKET		ListenSocket;
	struct		sockaddr_in InetAddr;
	WSADATA		wsaData;
	LPSTR		psBuff;

	WORD wVersionRequested = MAKEWORD(2,2);

	psBuff = (LPSTR)VirtualAlloc((LPVOID)NULL, (DWORD)(255),
					MEM_COMMIT, PAGE_READWRITE);

	if ((Ret = WSAStartup(wVersionRequested, &wsaData)) != 0) {
		wsprintf(psBuff, (LPCTSTR)"WSAStartup failed with error %d", Ret);
		AppendLog(psBuff);
		return FALSE;
	}

	if ((ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) 	{
		wsprintf(psBuff, (LPCTSTR)"socket() failed with error %d", WSAGetLastError());
		AppendLog(psBuff);
		return FALSE;
	}

	WSAAsyncSelect(ListenSocket, ghWndMain, WM_SOCKET, FD_ACCEPT | FD_CLOSE);

	wsprintf(psBuff, (LPCTSTR)"WM_SOCKET = %d", WM_SOCKET);
	AppendLog(psBuff);

	memset((char *)&InetAddr, 0, sizeof(struct sockaddr_in));
	InetAddr.sin_family = AF_INET;
	InetAddr.sin_addr.s_addr = htonl(INADDR_ANY);
	InetAddr.sin_port = htons(PORT);

	if (bind(ListenSocket, (struct sockaddr *)&InetAddr, sizeof(InetAddr)) == SOCKET_ERROR) {
		wsprintf(psBuff, (LPCTSTR)"bind() failed with error %d", WSAGetLastError());
		AppendLog(psBuff);
		return FALSE;
	}

	if (listen(ListenSocket, 5)) {
		wsprintf(psBuff, (LPCTSTR)"listen() failed with error %d", WSAGetLastError());
		AppendLog(psBuff);
		return FALSE;
	}
	else {
		return TRUE;
	}
}
Ejemplo n.º 7
0
void SecureChatIOCP::NotifyNewConnection(ClientContext *pcontext)
{
	unsigned int *pBuffer= new unsigned int;
	if(pBuffer!=NULL)
	{
		*pBuffer=pcontext->m_Socket;
		::PostMessage(m_hWnd, WM_NEW_CONNECTION, 0, (LPARAM) pBuffer);
	}

#ifdef _IOCPClientMode_ 

	m_StatusLock.Lock();
	pcontext->m_ContextLock.Lock();
	pcontext->m_pPublickey=m_pPublicKeyP;
	pcontext->m_nPublicKeySize=m_nSizePublicKey;
	pcontext->m_sUsername=m_sUserName;
	pcontext->m_ContextLock.Unlock();
	m_StatusLock.Unlock();

	AppendLog("Sending public key P..");
	m_StatusLock.Lock();
	SendPublicKey(pcontext,PKG_PUBLIC_KEYP,m_pPublicKeyP,m_nSizePublicKey);
	m_StatusLock.Unlock();

#endif
}
Ejemplo n.º 8
0
// Text in a Package is arrived. 
void MyIOCP::Packagetext(CIOCPBuffer *pOverlapBuff,int nSize,CIOCPContext *pContext)
{
	CString txt="";
	BYTE type;
	if(pOverlapBuff->GetPackageInfo(type,txt))
	{
		// to be sure that pcontext Suddenly does not dissapear by disconnection... 
		m_ContextMapLock.Lock();
		pContext->m_ContextLock.Lock();
		pContext->m_sReceived=txt;
		// Update that we have data
		pContext->m_iNumberOfReceivedMsg++;
		pContext->m_ContextLock.Unlock();
		m_ContextMapLock.Unlock();

		// Update Statistics. 
		m_StatusLock.Lock();
		m_iNumberOfMsg++;
		m_StatusLock.Unlock();
		// Log
		AppendLog(txt);
		SendMessage(m_hWnd, WM_INCOMING_MESSAGE, (WPARAM)pContext->m_Socket, (LPARAM)(LPCTSTR)txt);

		// Send back the message if we are echoing. 
		// Send Flood if needed. 
		BOOL bRet=FALSE;
		if(m_bFlood)
			bRet=BuildPackageAndSend(pContext,m_sSendText);
	}
}
Ejemplo n.º 9
0
bool ServerThread::Listen(bool bSilent/* = false*/) {
    server = socket(iAdressFamily, SOCK_STREAM, IPPROTO_TCP);
#ifdef _WIN32
    if(server == INVALID_SOCKET) {
#else
    if(server == -1) {
#endif
        if(bSilent == true) {
            clsEventQueue::mPtr->AddThread(clsEventQueue::EVENT_SRVTHREAD_MSG, 
#ifdef _WIN32
                ("[ERR] Unable to create server socket for port "+string(ui16Port)+" ! ErrorCode "+string(WSAGetLastError())).c_str());
#else
				("[ERR] Unable to create server socket for port "+string(ui16Port)+" ! ErrorCode "+string(errno)).c_str());
#endif
		} else {
#ifdef _BUILD_GUI
            ::MessageBox(NULL, (string(clsLanguageManager::mPtr->sTexts[LAN_UNB_CRT_SRVR_SCK], (size_t)clsLanguageManager::mPtr->ui16TextsLens[LAN_UNB_CRT_SRVR_SCK]) + " " +
				string(ui16Port) + " ! " + clsLanguageManager::mPtr->sTexts[LAN_ERROR_CODE] + " " + string(WSAGetLastError())).c_str(), clsServerManager::sTitle.c_str(), MB_OK | MB_ICONERROR);
#else
            AppendLog(string(clsLanguageManager::mPtr->sTexts[LAN_UNB_CRT_SRVR_SCK], (size_t)clsLanguageManager::mPtr->ui16TextsLens[LAN_UNB_CRT_SRVR_SCK]) + " " +
				string(ui16Port) + " ! " + clsLanguageManager::mPtr->sTexts[LAN_ERROR_CODE] + " " + string(errno));
#endif
        }
        return false;
    }
Ejemplo n.º 10
0
void SecureChatIOCP::NotifyDisconnectedClient(ClientContext *pContext)
{
	if ( pContext!=NULL && pContext->m_Socket!=INVALID_SOCKET )
	{
		pContext->m_ContextLock.Lock();
		pContext->m_bGotSessionKey=FALSE;
		unsigned int *pBuffer= new unsigned int;
		if(pBuffer!=NULL&&m_hWnd!=NULL)
		{
			*pBuffer=pContext->m_Socket;
			::PostMessage(m_hWnd, WM_DISCONNECT_CLIENT, 0, (LPARAM) pBuffer);
		}else
		{
			delete pBuffer;
			pBuffer=NULL;		

		}
		CString msg;
		CTime  tm= CTime::GetCurrentTime();
		msg.Format("[%s] %s Disconnected. (%s)",tm.Format("%H:%M:%S"),pContext->m_sUsername,GetHostAddress(pContext->m_Socket));
		AppendLog(msg);
		TRACE("Client %i is disconnected\r\n",pContext->m_ID);	

		pContext->m_ContextLock.Unlock();
	
		// We can not Lock m_ContextMapLock inside pContext->m_ContextLock lock -> leads do deadlock.. 
#ifndef _IOCPClientMode_	
		SendTextMessage(msg);
#endif
		// Clean The memory. 
		NotifyNewClientContext(pContext);
		

	}
}
Ejemplo n.º 11
0
BOOL Client(void) {
	DWORD		Ret;
	SOCKET		SendSocket;
	WSADATA		wsaData;
	LPSTR		psBuff;
	struct		sockaddr_in server;

	WORD wVersionRequested = MAKEWORD(2,2);

	psBuff = (LPSTR)VirtualAlloc((LPVOID)NULL, (DWORD)(255),
					MEM_COMMIT, PAGE_READWRITE);

	if ((Ret = WSAStartup(wVersionRequested, &wsaData)) != 0) {
		wsprintf(psBuff, (LPCTSTR)"WSAStartup failed with error %d", Ret);
		AppendLog(psBuff);
		return FALSE;
	}

	if ((SendSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET)	{
		wsprintf(psBuff, (LPCTSTR)"socket() failed with error %d", WSAGetLastError());
		AppendLog(psBuff);
		return FALSE;
	}

	memset((char *)&server, 0, sizeof(struct sockaddr_in));
	server.sin_family = AF_INET;
	server.sin_addr.s_addr = inet_addr(gcIP);
	server.sin_port = htons(PORT);

	WSAAsyncSelect(SendSocket, ghWndMain, WM_SOCKET, FD_WRITE | FD_CONNECT | FD_READ | FD_CLOSE);

	if ((Ret == WSAConnect(SendSocket, (struct sockaddr *)&server, sizeof(server), 0, 0, 0, NULL)) != 0) {
		wsprintf(psBuff, (LPCTSTR)"WSAConnect() failed with error %d", WSAGetLastError());
		AppendLog(psBuff);
		return FALSE;
	}
	else {
		wsprintf(psBuff, (LPCTSTR)"Connecting to server %s on port %d", gcIP, PORT);
		AppendLog(psBuff);
		return TRUE;
	}
}
Ejemplo n.º 12
0
TextConverter::TextConverter() {
#ifndef _WIN32
	if(clsSettingManager::mPtr->sTexts[SETTXT_ENCODING] == NULL) {
		AppendLog("TextConverter failed to initialize - TextEncoding not set!");
		exit(EXIT_FAILURE);
	}

	iconvUtfCheck = iconv_open("utf-8", "utf-8");
	if(iconvUtfCheck == (iconv_t)-1) {
		AppendLog("TextConverter iconv_open for iconvUtfCheck failed!");
		exit(EXIT_FAILURE);
	}

	iconvAsciiToUtf = iconv_open("utf-8//TRANSLIT//IGNORE", clsSettingManager::mPtr->sTexts[SETTXT_ENCODING]);
	if(iconvAsciiToUtf == (iconv_t)-1) {
		AppendLog("TextConverter iconv_open for iconvAsciiToUtf failed!");
		exit(EXIT_FAILURE);
	}
#endif
}
Ejemplo n.º 13
0
void Logger::Log(const String &log) {
    if (mDisplayLevel == kLoggerDisplayAll) {
        if (mShouldWriteToConsole) {
            mSystemConsole.Print(log);
            mSystemConsole.Flush();
        }
        if (!mOutputFileName.IsEmpty())
            mFile.WriteLine(log);
        AppendLog(log);
    }
}
Ejemplo n.º 14
0
BOOL SecureChatIOCP::SendErrorMessageTo(int iClientID, CString sMsg)
{
	UINT nBufLen = sMsg.GetLength();
	// Add one to the size header for the null termination byte. 
	nBufLen++;
	// Add one for the message type (encrypted/SessionExchange/ERROR_MESSAGE)..  
	nBufLen++;
	// Add one for the Payload type (text)
	nBufLen++;

	if ( nBufLen>=MAXIMUMPAYLOADSIZE || nBufLen<=0 )
	{
		AppendLog("SendMessageTo FAILED Message to long or zero..");
		return FALSE;
	}

	CIOCPBuffer *pBuff=AllocateBuffer(IOWrite);

	if ( !pBuff )
	{
		AppendLog("SendMessageTo FAILED pOverlapBuff=NULL");
		return FALSE;
	}

	// Make sure that buffer is empty  
	pBuff->EmptyUsed();
	// Size Header
	pBuff->AddData(nBufLen);
	// Message Header
	pBuff->AddData((BYTE)PKG_ERRORMSG);
	// Payload Header 
	pBuff->AddData((BYTE)PKG_ERRORMSG);
	// Add the string. 
	int length=sMsg.GetLength();
	pBuff->AddData((PBYTE) sMsg.GetBuffer(length),length);
	//Extra Null Teriminate (for Strings) 
	pBuff->AddData((BYTE)'\0');
	ASend(iClientID,pBuff);
	return TRUE; 

}
Ejemplo n.º 15
0
FARPROC WINAPI PtokaX_FailHook(unsigned /*dliNotify*/, PDelayLoadInfo /*pdli*/) {
#ifdef _BUILD_GUI
    ::MessageBox(NULL, "Something bad happen and PtokaX crashed. PtokaX was not able to collect any information why this happen because your operating system"
		" don't support functionality needed for that. If you know why this crash happen then please report it as bug to [email protected]!",
        "PtokaX crashed!", MB_OK | MB_ICONERROR);
#else
    AppendLog("Something bad happen and PtokaX crashed. PtokaX was not able to collect any information why this happen because your operating system"
        " don't support functionality needed for that. If you know why this crash happen then please report it as bug to [email protected]!");
#endif

    exit(EXIT_FAILURE);
}
Ejemplo n.º 16
0
inline void SecureChatIOCP::OnPKG_TEXT_TO_ALL(CIOCPBuffer *pOverlapBuff, int nSize, ClientContext *pContext)
{

	CString sTxt;
	nSize=pOverlapBuff->GetPackageSize();

	PBYTE pPayload=pOverlapBuff->GetPayLoadBuffer();
	pPayload++;

	// Assumes that we already have a null termination. 
	if( nSize >=0 )
		sTxt=pPayload;

#ifndef _IOCPClientMode_
	AppendLog(pContext->m_sUsername+">"+sTxt);
	SendTextMessage(pContext->m_sUsername+" >"+sTxt);
#else
	AppendLog(sTxt);
#endif

}
Ejemplo n.º 17
0
void clsScriptManager::LoadXML() {
	// PPK ... first start all script in order from xml file
#ifdef _WIN32
	TiXmlDocument doc((clsServerManager::sPath+"\\cfg\\Scripts.xml").c_str());
#else
	TiXmlDocument doc((clsServerManager::sPath+"/cfg/Scripts.xml").c_str());
#endif
	if(doc.LoadFile() == false) {
        if(doc.ErrorId() != TiXmlBase::TIXML_ERROR_OPENING_FILE && doc.ErrorId() != TiXmlBase::TIXML_ERROR_DOCUMENT_EMPTY) {
            int iMsgLen = sprintf(clsServerManager::pGlobalBuffer, "Error loading file Scripts.xml. %s (Col: %d, Row: %d)", doc.ErrorDesc(), doc.Column(), doc.Row());
			CheckSprintf(iMsgLen, clsServerManager::szGlobalBufferSize, "clsScriptManager::LoadXML");
#ifdef _BUILD_GUI
			::MessageBox(NULL, clsServerManager::pGlobalBuffer, g_sPtokaXTitle, MB_OK | MB_ICONERROR);
#else
			AppendLog(clsServerManager::pGlobalBuffer);
#endif
            exit(EXIT_FAILURE);
        }
    } else {
		TiXmlHandle cfg(&doc);
		TiXmlNode *scripts = cfg.FirstChild("Scripts").Node();
		if(scripts != NULL) {
			TiXmlNode *child = NULL;
			while((child = scripts->IterateChildren(child)) != NULL) {
				TiXmlNode *script = child->FirstChild("Name");
    
				if(script == NULL || (script = script->FirstChild()) == NULL) {
					continue;
				}
    
				char *name = (char *)script->Value();

				if(FileExist((clsServerManager::sScriptPath+string(name)).c_str()) == false) {
					continue;
				}

				if((script = child->FirstChild("Enabled")) == NULL ||
					(script = script->FirstChild()) == NULL) {
					continue;
				}
    
				bool enabled = atoi(script->Value()) == 0 ? false : true;

				if(FindScript(name) != NULL) {
					continue;
				}

				AddScript(name, enabled, false);
            }
        }
    }
}
Ejemplo n.º 18
0
void CLog::UnRegisterSessionLink(CString strSrcIP, CString strDstIP)
{
	m_pRegistLock->Lock();

	if(m_MapInfo[strSrcIP] > 0)
	{
		m_MapInfo[strSrcIP]--;

		SYSTEMTIME systime;
		GetLocalTime(&systime);
		CString strTime;
		strTime.Format("%d:%d:%d",systime.wHour,systime.wMinute,systime.wSecond);
		
		AppendLog("%s  %s disconnect to %s",strTime.GetBuffer(),strSrcIP.GetBuffer(),strDstIP.GetBuffer());
		if(m_MapInfo[strSrcIP] == 0)
		{
			AppendLog("%s  %s id disconnection!",strTime.GetBuffer(),strSrcIP.GetBuffer());
		}
	}

	m_pRegistLock->UnLock();
}
Ejemplo n.º 19
0
inline void SecureChatIOCP::OnPKG_USERNAME_PASSWORD(CIOCPBuffer *pOverlapBuff, int nSize, ClientContext *pContext)
{
	BYTE PayloadType= 255;
	PBYTE pBuff1=NULL;
	PBYTE pBuff2=NULL;
	UINT nBuffSize=0;
	UINT nBuffSize2=0;
	// Read the Package
	ReadPkg(pOverlapBuff,nBuffSize,&pBuff1,nBuffSize2,&pBuff2,pContext);
	if ( pBuff1!=NULL )
	{
		pContext->m_sUsername=pBuff1;
		pContext->m_bUpdateList=TRUE;
		//FIXME: Send Notification to all Users and send 
		// User list to Client. 
		AppendLog("Secure connection established.");
		AppendLog(pContext->m_sUsername+ ", joined Channel..");
		SendTextMessage(pContext->m_sUsername+ ", joined Channel..");


	}
}
Ejemplo n.º 20
0
BOOL MyIOCP::BuildPackageAndSendToAll(CString sText)
{
    	CIOCPBuffer *pOverlapBuff=AllocateBuffer(IOWrite);
		if(pOverlapBuff)
		{
			if(pOverlapBuff->CreatePackage(0,sText))
			return ASendToAll(pOverlapBuff);
			else
			{
				AppendLog(_T("CreatePackage(0,sText) Failed in BuildPackageAndSendToAll"));
				ReleaseBuffer(pOverlapBuff);
				return FALSE;
			}
		
		}else
		{
			CString msg;
			msg.Format(_T("Could not allocate memory ASend: %s"),ErrorCode2Text(WSAGetLastError()));
			AppendLog(msg);
			return FALSE;
		}
	return FALSE;	
}
Ejemplo n.º 21
0
// Build the a text message message and send it.. 
BOOL MyIOCP::BuildPackageAndSend(ClientContext *pContext, CString sText)
{
		CIOCPBuffer *pOverlapBuff=AllocateBuffer(IOWrite);
		if(pOverlapBuff)
		{
			if(pOverlapBuff->CreatePackage(Job_SendText2Client,sText))
			return ASend(pContext,pOverlapBuff);
			else
			{
				AppendLog(_T("CreatePackage(0,sText) Failed in BuildPackageAndSend"));
				ReleaseBuffer(pOverlapBuff);
				return FALSE;
			}
		
		}else
		{
			CString msg;
			msg.Format(_T("Could not allocate memory ASend: %s"),ErrorCode2Text(WSAGetLastError()));
			AppendLog(msg);
		DisconnectClient(pContext->m_Socket);
			return FALSE;
		}
	return FALSE;	
}
Ejemplo n.º 22
0
void Logger::LogCritical(const String &log) {
    if (mDisplayLevel == kLoggerDisplayAll ||
            mDisplayLevel == kLoggerDisplayErrorAndCritical ||
            mDisplayLevel == kLoggerDisplayCriticalOnly)
    {
        if (mShouldWriteToConsole) {
            mSystemConsole.Print(log);
            mSystemConsole.Flush();
        }
        if (!mOutputFileName.IsEmpty()) {
            mFile.WriteLine(log);
            mFile.Flush();
        }
        AppendLog(log);
    }
}
Ejemplo n.º 23
0
/*
* 
* The Function Computes The KeyB Accourding to Diffie-Hellman 
* Algorithm The Function also Adds The the Computed key into the
* Hashvalue for digital signing. 
*
*/
void SecureChatIOCP::ComputeAndSendSignature(ClientContext *pContext)
{
	// Be Safe 
	if( !pContext )
		return;
#ifndef _IOCPClientMode_

	// FIXME: Change later. 
	const UINT nSize=sizeof(m_DSAKeypubD)/4;
	DWORD S[nSize];
	int iRet=0;


	pContext->m_ContextLock.Lock();

	// Finish the Hash of public key A and key B. 
	DWORD aHashValue[_HASHSIZE_/4];

	pContext->m_cCryptLib.BNSetZero(aHashValue,_HASHSIZE_/4);
	pContext->m_cCryptLib.BNSetZero(S,nSize);


	pContext->m_cCryptLib.SHA1_Finish((unsigned char*)aHashValue,&pContext->m_csha1Hash);

	TRACE("aHashValue %s \r\n",pContext->m_cCryptLib.BNPrintC(aHashValue,_HASHSIZE_/4));

	// FIXME: REMOVE LATER: 
	/*	
	CString stmp;
	stmp.Format("aHashValue %s \r\n",pContext->m_cCryptLib.BNPrintC(aHashValue,_HASHSIZE_/4));
	AppendLog(stmp);*/

	//  Compute hash^d mod n
	iRet=pContext->m_cCryptLib.BNModExp(S,aHashValue,m_DSAKeypubD,m_DSAKeypubN,nSize);	

	pContext->m_sUsername="******";

	AppendLog("Sending signature..");

	pContext->m_bUpdateList=TRUE;

	pContext->m_ContextLock.Unlock();

	SendPublicKey(pContext,PKG_SIGNATURE,S,nSize);
#endif

}
Ejemplo n.º 24
0
static void WINAPI CtrlHandler(DWORD dwCtrl) {
	switch(dwCtrl) {
	    case SERVICE_CONTROL_SHUTDOWN:
	    case SERVICE_CONTROL_STOP:
	        ss.dwCurrentState = SERVICE_STOP_PENDING;
	        bIsClose = true;
	        ServerStop();
	    case SERVICE_CONTROL_INTERROGATE:
	        // Fall through to send current status.
	        break;
	    default:
	        break;
	}
	
	if(SetServiceStatus(ssh, &ss) == false) {
		AppendLog("CtrlHandler::SetServiceStatus failed ("+string((uint32_t)GetLastError())+")!");
	}
}
Ejemplo n.º 25
0
/*
 * Send a "Start the file transfer package" to the remote connection. 
 *
 *
 */
BOOL MyIOCP::BuildStartFileTransferPackageAndSend(ClientContext *pContext)
{
	CIOCPBuffer *pOverlapBuff=AllocateBuffer(IOWrite);
	if(pOverlapBuff)
	{
		if(pOverlapBuff->CreatePackage(Job_StartFileTransfer))
		return ASend(pContext,pOverlapBuff);
		
	}else
	{
		CString msg;
		msg.Format(_T("Could not allocate memory ASend: %s"),ErrorCode2Text(WSAGetLastError()));
		AppendLog(msg);
		DisconnectClient(pContext->m_Socket);
		return FALSE;
	}
	return TRUE;	
}
Ejemplo n.º 26
0
gboolean TimeoutCallback(gpointer data)
{
	FfWriterEngine *PWriter = (FfWriterEngine *) data;

	PWriter->TimerCounter++;
	PWriter->AppendMemoryData();

	if (PWriter->TimerCounter >= REC_TIMEOUT)
	{
		uint64_t mem = PWriter->GetMemoryConsumption();
		sprintf(str, "DEBUG: Timeout callback. Memory: %lld. Delta: %lld\n", mem, mem - Memory);
		AppendLog(str, "MAIN");
		Memory = mem;
		PWriter->TimerCounter = 0;
		PWriter->Continue();
	}
	return true;
}
Ejemplo n.º 27
0
void CreateSocketInfo(SOCKET s) {
	LPSOCKET_INFO	SI;
	LPSTR			psBuff;

	psBuff = (LPSTR)VirtualAlloc((LPVOID)NULL, (DWORD)(255),
					MEM_COMMIT, PAGE_READWRITE);

	if ((SI = (LPSOCKET_INFO)GlobalAlloc(GPTR, sizeof(SOCKET_INFO))) == NULL) {
		wsprintf(psBuff, (LPCTSTR)"GlobalAlloc() failed with error %d", GetLastError());
		AppendLog(psBuff);
		return;
	}

	// Prepate SocketInfo structure for use
	SI->Socket = s;
	SI->RecvPosted = FALSE;
	SI->BytesSEND = 0;
	SI->BytesRECV = 0;

	SocketInfo = SI;
}
Ejemplo n.º 28
0
/*
* Called when a package with user data have arrived.. 
*
*
*/
inline void SecureChatIOCP::OnPKG_ERRORMSG(CIOCPBuffer *pOverlapBuff, int nSize, ClientContext *pContext)
{
	BYTE PayloadType= 255;
	CString sTxtErr;

	PBYTE pPayload=pOverlapBuff->GetPayLoadBuffer();
	pPayload++;

	if( nSize>=MINIMUMPACKAGESIZE+2)
		memcpy(&PayloadType,pPayload,1);

	pPayload++;
	// Assumes that we already have a null termination. 
	if( nSize >=MINIMUMPACKAGESIZE+2 )
		sTxtErr=pPayload;

	pContext->m_sUsername=sTxtErr;
	pContext->m_bUpdateList=TRUE;

	AppendLog(sTxtErr);
}
Ejemplo n.º 29
0
void ReservedNicksManager::Load() {
#ifdef _WIN32
	FILE * fReservedNicks = fopen((ServerManager::m_sPath + "\\cfg\\ReservedNicks.pxt").c_str(), "rt");
#else
	FILE * fReservedNicks = fopen((ServerManager::m_sPath + "/cfg/ReservedNicks.pxt").c_str(), "rt");
#endif
    if(fReservedNicks == NULL) {
    	int iMsgLen = snprintf(ServerManager::m_pGlobalBuffer, ServerManager::m_szGlobalBufferSize, "Error loading file ReservedNicks.pxt %s (%d)", 
#ifdef _WIN32
        	WSErrorStr(errno), errno);
#else
			ErrnoStr(errno), errno);
#endif
		if(iMsgLen > 0) {
#ifdef _BUILD_GUI
			::MessageBox(NULL, ServerManager::m_pGlobalBuffer, g_sPtokaXTitle, MB_OK | MB_ICONERROR);
#else
			AppendLog(ServerManager::m_pGlobalBuffer);
#endif
		}

        exit(EXIT_FAILURE);
    }
Ejemplo n.º 30
0
/*
* This function Build a package of type 	
*
* [obligatory headersize|Headertype (_keytype)| public key size (nPublicKeySize) | Publickey ( * obligatory headersize|Headertype (_keytype)| public key size (nPublicKeySize) | Publickey] 
*
* and sends it to client. 
*/
void SecureChatIOCP::SendPublicKey(ClientContext *pContext, BYTE _keytype, DWORD *_pPublicKey, UINT nPublicKeySize)
{

	CIOCPBuffer *pBuff=AllocateBuffer(IOWrite);
	if( !pBuff )
	{
		AppendLog("SendPublicKey FAILED pBuff=NULL");
		return;
	}

	UINT nPayLoadLen=sizeof(DWORD)+sizeof(BYTE)+nPublicKeySize*sizeof(DWORD);

	pBuff->EmptyUsed();
	// Size Header
	pBuff->AddData(nPayLoadLen);
	// Payload type 
	pBuff->AddData((BYTE)_keytype);
	// The size of nPublicKey
	pBuff->AddData(nPublicKeySize);	
	// add the public key. 
	pBuff->AddData((PBYTE)_pPublicKey,nPublicKeySize*4);
	ASend(pContext,pBuff);

}