Exemple #1
0
unsigned int CALLBACK verify_context_thread(void *param)
{
	Thread_Push( 0 );

	if (param) {
		ConnContext *context = (ConnContext *)param;
		TCHAR msg[1024];
		switch ( DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SMP_INPUT), 0, DlgProcVerifyContext, (LPARAM)param) ) {
			case IDOK:
			case IDYES:
				lib_cs_lock();
				otrl_context_set_trust(context->active_fingerprint, "verified");
				otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename);
				lib_cs_unlock();
				mir_sntprintf(msg, 1024, TranslateT(LANG_FINGERPRINT_VERIFIED), contact_get_nameT((HANDLE)context->app_data));
				msg[1023] = '\0';
				ShowMessage((HANDLE)context->app_data, msg);
				SetEncryptionStatus(context->app_data, otr_context_get_trust(context));
				break;
			case IDNO:
				lib_cs_lock();
				otrl_context_set_trust(context->active_fingerprint, NULL);
				otrl_privkey_write_fingerprints(otr_user_state, g_fingerprint_store_filename);
				lib_cs_unlock();
				mir_sntprintf(msg, 1024, TranslateT(LANG_FINGERPRINT_NOT_VERIFIED), contact_get_nameT((HANDLE)context->app_data));
				msg[1023] = '\0';
				ShowMessage((HANDLE)context->app_data, msg);
				SetEncryptionStatus(context->app_data, otr_context_get_trust(context));
				break;
		}
	}

	Thread_Pop();
	return 0; 
}
Exemple #2
0
void VerifyFingerprintMessage(ConnContext *context, bool verify) {
	TCHAR msg[1024];
	mir_sntprintf(msg, 1024, (verify)?TranslateT(LANG_FINGERPRINT_VERIFIED):TranslateT(LANG_FINGERPRINT_NOT_VERIFIED), contact_get_nameT((MCONTACT)context->app_data));
	msg[1023] = '\0';
	ShowMessage((MCONTACT)context->app_data, msg);
	SetEncryptionStatus((MCONTACT)context->app_data, otr_context_get_trust(context));
}
Exemple #3
0
void SMPDialogUpdate(ConnContext *context, int percent) {
	if (!context) return;
	SmpForContactMap::iterator it = smp_for_contact.find(context->app_data);
	if (it == smp_for_contact.end())	return;
	if (it->second.dialog) PostMessage(it->second.dialog, WMU_REFRESHSMP, percent, 0);
	TrustLevel level = otr_context_get_trust(context);
	if (!it->second.responder && it->second.oldlevel != level) {
		if (level == TRUST_PRIVATE) 
			VerifyFingerprintMessage(context, true);
		else if (level == TRUST_UNVERIFIED)
			VerifyFingerprintMessage(context, false);
	}
	//if (percent == 100)
	/*
	switch (percent){
		case 0:
			VerifyFingerprint(context, false);
			ShowWarning(_T("SMP failed"));
			break;
		case 100:
			VerifyFingerprint(context, true);
			ShowWarning(_T("SMP successful"));
			break;
		default:
			ShowWarning(_T("Received an SMP update"));
	}
	*/
}
Exemple #4
0
void SMPInitUpdateDialog(ConnContext *context, bool responder) {
	if (!context) return;
	SmpData *data = (SmpData*)mir_calloc(sizeof(SmpData));
	data->context = context;
	data->oldlevel = otr_context_get_trust(context);
	data->responder = responder;
	CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_SMP_PROGRESS), 0, DlgSMPUpdateProc, (LPARAM) data);
}
Exemple #5
0
void VerifyFingerprintMessage(ConnContext *context, bool verify) {
	MCONTACT hContact = (UINT_PTR)context->app_data;

	wchar_t msg[1024];
	mir_snwprintf(msg, (verify) ? TranslateW(LANG_FINGERPRINT_VERIFIED) : TranslateW(LANG_FINGERPRINT_NOT_VERIFIED), contact_get_nameT(hContact));
	ShowMessage(hContact, msg);
	SetEncryptionStatus(hContact, otr_context_get_trust(context));
}
Exemple #6
0
//true - ok,false ignore
INT_PTR MirOTRMenuCheckService(WPARAM wParam,LPARAM)
{
	PCheckProcParam pcpp = ( PCheckProcParam )wParam;
	lpMirOTRMenuExecParam cmep=NULL;
	TMO_MenuItem mi;

	if ( pcpp == NULL )
		return FALSE;

	cmep = ( lpMirOTRMenuExecParam )pcpp->MenuItemOwnerData;
	if ( cmep == NULL ) //this is rootsection...build it
		return TRUE;

	MCONTACT hContact = (MCONTACT)pcpp->wParam, hSub;
	if((hSub = db_mc_getMostOnline(hContact)) != 0)
		hContact = hSub;
	
	TrustLevel level = ( TrustLevel )otr_context_get_trust(otrl_context_find_miranda(otr_user_state, hContact));
	
	mi.cbSize = sizeof(mi);
	if ( CallService(MO_GETMENUITEM, (WPARAM)pcpp->MenuItemHandle, (LPARAM)&mi) == 0) {
		
		if ( mi.flags & CMIF_HIDDEN ) return FALSE;
		if ( mi.flags & CMIF_NOTPRIVATE  && level==TRUST_PRIVATE  ) return FALSE;
		if ( mi.flags & CMIF_NOTFINISHED && level==TRUST_FINISHED ) return FALSE;
		if ( mi.flags & CMIF_NOTUNVERIFIED  && level==TRUST_UNVERIFIED  ) return FALSE;
		if ( mi.flags & CMIF_NOTNOTPRIVATE && level==TRUST_NOT_PRIVATE ) return FALSE;
	
		if (pcpp->MenuItemHandle == hStatusInfoItem) {
			mi.flags = CMIM_NAME | CMIM_ICON | CMIF_TCHAR;
			switch (level) {
				case TRUST_PRIVATE:
					mi.hIcolibItem = GetIconHandle(ICON_PRIVATE);
					mi.ptszName = TranslateT(LANG_STATUS_PRIVATE);
					break;
				case TRUST_UNVERIFIED:
					mi.hIcolibItem = GetIconHandle(ICON_UNVERIFIED);
					mi.ptszName = TranslateT(LANG_STATUS_UNVERIFIED);
					break;
				case TRUST_FINISHED:
					mi.hIcolibItem = GetIconHandle(ICON_FINISHED);
					mi.ptszName = TranslateT(LANG_STATUS_FINISHED);
					break;
				default:
					mi.hIcolibItem = GetIconHandle(ICON_NOT_PRIVATE);
					mi.ptszName = TranslateT(LANG_STATUS_DISABLED);
			}
			CallService(MO_MODIFYMENUITEM, (WPARAM)hStatusInfoItem, (LPARAM)&mi);
		} else if (pcpp->MenuItemHandle == hHTMLConvMenuItem) {
			if (db_get_b(hContact, MODULENAME, "HTMLConv", 0) )
				mi.flags |= CMIM_FLAGS|CMIF_CHECKED;
			else
				mi.flags = CMIM_FLAGS|(mi.flags &~CMIF_CHECKED);
			CallService(MO_MODIFYMENUITEM, (WPARAM)hHTMLConvMenuItem, (LPARAM)&mi);
		}
	}
	return TRUE;
}
Exemple #7
0
// true - ok,false ignore
INT_PTR MirOTRMenuCheckService(WPARAM wParam, LPARAM)
{
	TCheckProcParam *pcpp = (TCheckProcParam*)wParam;
	if (pcpp == NULL)
		return FALSE;

	lpMirOTRMenuExecParam cmep = (lpMirOTRMenuExecParam)pcpp->MenuItemOwnerData;
	if (cmep == NULL) //this is rootsection...build it
		return TRUE;

	MCONTACT hContact = (MCONTACT)pcpp->wParam, hSub;
	if ((hSub = db_mc_getMostOnline(hContact)) != 0)
		hContact = hSub;

	ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact);
	TrustLevel level = (TrustLevel)otr_context_get_trust(context);

	TMO_MenuItem mi;
	if (Menu_GetItemInfo(pcpp->MenuItemHandle, mi) == 0) {
		if (mi.flags & CMIF_HIDDEN) return FALSE;
		if (mi.flags & CMIF_NOTPRIVATE  && level == TRUST_PRIVATE) return FALSE;
		if (mi.flags & CMIF_NOTFINISHED && level == TRUST_FINISHED) return FALSE;
		if (mi.flags & CMIF_NOTUNVERIFIED  && level == TRUST_UNVERIFIED) return FALSE;
		if (mi.flags & CMIF_NOTNOTPRIVATE && level == TRUST_NOT_PRIVATE) return FALSE;

		if (pcpp->MenuItemHandle == hStatusInfoItem) {
			TCHAR text[128];

			switch (level) {
			case TRUST_PRIVATE:
				mir_sntprintf(text, _T("%s [v%i]"), TranslateT(LANG_STATUS_PRIVATE), context->protocol_version);
				Menu_ModifyItem(hStatusInfoItem, text, IcoLib_GetIconHandle(ICON_PRIVATE));
				break;

			case TRUST_UNVERIFIED:
				mir_sntprintf(text, _T("%s [v%i]"), TranslateT(LANG_STATUS_UNVERIFIED), context->protocol_version);
				Menu_ModifyItem(hStatusInfoItem, text, IcoLib_GetIconHandle(ICON_UNVERIFIED));
				break;

			case TRUST_FINISHED:
				Menu_ModifyItem(hStatusInfoItem, TranslateT(LANG_STATUS_FINISHED), IcoLib_GetIconHandle(ICON_UNVERIFIED));
				break;

			default:
				Menu_ModifyItem(hStatusInfoItem, TranslateT(LANG_STATUS_DISABLED), IcoLib_GetIconHandle(ICON_NOT_PRIVATE));
			}
		}
		else if (pcpp->MenuItemHandle == hHTMLConvMenuItem)
			Menu_SetChecked(hHTMLConvMenuItem, db_get_b(hContact, MODULENAME, "HTMLConv", 0) != 0);
	}
	return TRUE;
}
void FinishSession(MCONTACT hContact)
{
	if (!hContact)
		return;

	ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact);
	TrustLevel level = otr_context_get_trust(context);
	if (level == TRUST_UNVERIFIED || level == TRUST_PRIVATE) {
		otrl_context_force_finished(context);
		//SetEncryptionStatus(hContact, TRUST_FINISHED);
		otr_gui_gone_insecure(context->app_data, context);
		//otrl_message_disconnect(otr_user_state, &ops, hContact, context->accountname, context->protocol, context->username);
		//SetEncryptionStatus(hContact, TRUST_NOT_PRIVATE);
	}
	return;
}
int OnDatabaseEventAdded(WPARAM hContact, LPARAM lParam)
{
	if (!options.delete_history)
		return 0;

	unsigned len = (unsigned)strlen(LANG_INLINE_PREFIX);

	DBEVENTINFO info = { sizeof(info) };
	info.cbBlob = len * 2;
	info.pBlob = (PBYTE)_alloca(info.cbBlob);
	if (db_event_get(lParam, &info))
		return 0;

	if (info.eventType != EVENTTYPE_MESSAGE)
		return 0;

	MCONTACT hSub;
	if ((hSub = db_mc_getMostOnline(hContact)) != 0)
		hContact = hSub;

	ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact);
	if (context && otr_context_get_trust(context) != TRUST_NOT_PRIVATE) {
		// only delete encrypted messages that are no OTR system messages
		if (options.delete_systeminfo || !(info.cbBlob > len && !strncmp((char*)info.pBlob, LANG_INLINE_PREFIX, len))) {
			DeleteEventNode *node = new DeleteEventNode();
			node->hContact = hContact;
			node->hDbEvent = lParam;
			node->timestamp = time(0);
			node->next = 0;
			mir_cslock lck(RemoveChainCS);
			if (DeleteEvents.last)
				DeleteEvents.last->next = node;
			else
				DeleteEvents.first = node;
			DeleteEvents.last = node;
		}
	}
	return 0;
}
Exemple #10
0
int WindowEvent(WPARAM wParam, LPARAM lParam)
{
	MessageWindowEventData *mwd = (MessageWindowEventData *)lParam;
	if (mwd->uType == MSG_WINDOW_EVT_CLOSE && options.end_window_close) {
		FinishSession(mwd->hContact);
		return 0;
	}

	if (mwd->uType != MSG_WINDOW_EVT_OPEN)
		return 0;

	MCONTACT hContact = mwd->hContact, hTemp;
	if ((hTemp = db_mc_getMostOnline(hContact)) != 0)
		hContact = hTemp;

	if (!Proto_IsProtoOnContact(hContact, MODULENAME))
		return 0;

	lib_cs_lock();
	ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact);
	SetEncryptionStatus(hContact, otr_context_get_trust(context));
	return 0;
}
Exemple #11
0
// add prefix to sent messages
int OnDatabaseEventPreAdd(WPARAM hContact, LPARAM lParam)
{
	if (!options.prefix_messages || !lParam)
		return 0;

	DBEVENTINFO *dbei = (DBEVENTINFO *)lParam;
	if ((dbei->eventType != EVENTTYPE_MESSAGE) || !(dbei->flags & DBEF_SENT) || (dbei->flags & DBEF_OTR_PREFIXED))
		return 0;

	if (dbei->cbBlob == 0 || dbei->pBlob == 0)
		return 0; // just to be safe

	const char *proto = GetContactProto(hContact);
	if (!proto)
		return 0;
	if (db_get_b(hContact, proto, "ChatRoom", 0) == 1)
		return 0;

	if (mir_strcmp(proto, META_PROTO) == 0) {
		hContact = db_mc_getMostOnline(hContact);
		if (!hContact)
			return 0;
		proto = GetContactProto(hContact);
		if (!proto)
			return 0;
	}

	ConnContext *context = otrl_context_find_miranda(otr_user_state, hContact);	
	bool encrypted = otr_context_get_trust(context) != TRUST_NOT_PRIVATE;
	if (!encrypted)
		return 0;
	
	DBEVENTINFO my_dbei = *dbei; // copy the other event

	char *msg = (char*)dbei->pBlob;
	int msgLen = (int)strlen(msg);

	int prefixlen = (int)strnlen(options.prefix, 64);
	if (strncmp(msg, options.prefix, prefixlen) == 0)
		return 0;

	// check for additional data presence
	int datalen = dbei->cbBlob - msgLen;
	if (datalen < 0)
		datalen = 0;

	CMStringA buf;
	buf.Append(options.prefix, prefixlen);
	buf.Append(msg);
	// append additional data
	if (datalen) {
		buf.AppendChar(0);
		buf.Append(msg + msgLen + 1, datalen);
	}
	
	my_dbei.pBlob = (BYTE*)buf.GetBuffer();
	my_dbei.cbBlob = (int)buf.GetLength();
	my_dbei.flags |= DBEF_OTR_PREFIXED;
	db_event_add(hContact, &my_dbei);
	
	// stop original event from being added
	return 1;
}