void OtrInternal::deleteFingerprint(const psiotr::Fingerprint& fingerprint)
{
    ConnContext* context = otrl_context_find(m_userstate,
                                             fingerprint.username.toUtf8().constData(),
                                             fingerprint.account.toUtf8().constData(),
                                             OTR_PROTOCOL_STRING,
#if (OTRL_VERSION_MAJOR >= 4)
                                             OTRL_INSTAG_BEST,
#endif
                                             false, NULL, NULL, NULL);
    if (context)
    {
        ::Fingerprint* fp = otrl_context_find_fingerprint(context,
                                                          fingerprint.fingerprint,
                                                          0, NULL);
        if (fp)
        {
            if (context->active_fingerprint == fp)
            {
                otrl_context_force_finished(context);
            }
            otrl_context_forget_fingerprint(fp, true);
            write_fingerprints();
        }
    }
}
Example #2
0
/*
 * Forget a fingerprint.
 *
 * If str_fp is not NULL, it must be on the OTR human format like this:
 * "487FFADA 5073FEDD C5AB5C14 5BB6C1FF 6D40D48A". If str_fp is NULL, get the
 * context of the target nickname, check for the OTR peer context active
 * fingerprint and forget this one if possible.
 */
void otr_forget(SERVER_REC *irssi, const char *nick, char *str_fp,
		struct otr_user_state *ustate)
{
	int ret;
	char fp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN];
	Fingerprint *fp_forget;
	ConnContext *ctx = NULL;
	struct otr_peer_context *opc;

	if (!irssi && !str_fp) {
		IRSSI_NOTICE(NULL, nick, "Need a fingerprint!");
		goto error;
	}

	/* No human string fingerprint given. */
	if (!str_fp) {
		ctx = otr_find_context(irssi, nick, FALSE);
		if (!ctx) {
			goto error;
		}

		opc = ctx->app_data;
		/* Always NEED a peer context or else code error. */
		assert(opc);

		fp_forget = opc->active_fingerprint;
	} else {
		fp_forget = otr_find_hash_fingerprint_from_human(str_fp, ustate);
	}

	if (fp_forget) {
		/* Don't do anything if context is in encrypted state. */
		ret = check_fp_encrypted_msgstate(fp_forget);
		if (ret) {
			IRSSI_NOTICE(irssi, nick, "Fingerprint "
					"context is still encrypted. Finish the OTR "
					"session before forgetting a fingerprint "
					"(%9/otr finish%9).");
			goto end;
		}

		otrl_privkey_hash_to_human(fp, fp_forget->fingerprint);
		/* Forget fp and context if it's the only one remaining. */
		otrl_context_forget_fingerprint(fp_forget, 1);
		/* Update fingerprints file. */
		key_write_fingerprints(ustate);
		IRSSI_NOTICE(irssi, nick, "Fingerprint %y%s%n forgotten.",
				fp);
	} else {
		IRSSI_NOTICE(irssi, nick, "Fingerprint %y%s%n NOT found",
				(str_fp != NULL) ? str_fp : "");
	}

end:
error:
	return;
}
Example #3
0
/* Forget a whole context, so long as it's PLAINTEXT. If a context has child
 * instances, don't remove this instance unless children are also all in
 * PLAINTEXT state. In this case, the children will also be removed.
 * Returns 0 on success, 1 on failure. */
int otrl_context_forget(ConnContext *context)
{
    if (context->msgstate != OTRL_MSGSTATE_PLAINTEXT) return 1;

    if (context->their_instance == OTRL_INSTAG_MASTER) {
	ConnContext *c_iter;

	for (c_iter = context; c_iter &&
		c_iter->m_context == context->m_context;
		c_iter = c_iter->next) {
	    if (c_iter->msgstate != OTRL_MSGSTATE_PLAINTEXT) return 1;
	}

	c_iter = context->next;
	while (c_iter && c_iter->m_context == context->m_context) {
	    if (!otrl_context_forget(c_iter)) {
		c_iter = context->next;
	    } else {
		return 1;
	    }
	}

    }

    /* Just to be safe, force to plaintext.  This also frees any
     * extraneous data lying around. */
    otrl_context_force_plaintext(context);

    /* First free all the Fingerprints */
    while(context->fingerprint_root.next) {
	otrl_context_forget_fingerprint(context->fingerprint_root.next, 0);
    }
    /* Now free all the dynamic info here */
    free(context->username);
    free(context->accountname);
    free(context->protocol);
    free(context->smstate);
    context->username = NULL;
    context->accountname = NULL;
    context->protocol = NULL;
    context->smstate = NULL;

    /* Free the application data, if it exists */
    if (context->app_data && context->app_data_free) {
	(context->app_data_free)(context->app_data);
	context->app_data = NULL;
    }

    /* Fix the list linkages */
    *(context->tous) = context->next;
    if (context->next) {
	context->next->tous = context->tous;
    }

    free(context);
    return 0;
}
/**
 * Delete a known fingerprint.
 */
void OtrConnection::deleteFingerprint(unsigned char* fpHash) {
	qWarning() << "löschen";
	ConnContext* context;
	Fingerprint* fp;
//	char fpHuman[45];
//	otrl_privkey_hash_to_human(fpHuman, fpHash);
	for (context = userstate->context_root; context != NULL; context = context->next) {
		fp = otrl_context_find_fingerprint(context, 
						   fpHash, 
						   0, NULL);
		if (fp != NULL) {
			otrl_context_forget_fingerprint(fp, 1);
			break;
		}
	}
	write_fingerprints();
}
Example #5
0
/* Forget a fingerprint */
void otrg_ui_forget_fingerprint(Fingerprint *fingerprint)
{
    ConnContext *context;
	
    if (fingerprint == NULL) return;

    /* Don't do anything with the active fingerprint if we're in the
     * ENCRYPTED state. */
    context = fingerprint->context;
    if (context->msgstate == OTRL_MSGSTATE_ENCRYPTED &&
	    context->active_fingerprint == fingerprint) return;
	
    otrl_context_forget_fingerprint(fingerprint, 1);
    otrg_plugin_write_fingerprints();
	
    otrg_ui_update_keylist();
}
Example #6
0
void OtrInternal::deleteFingerprint(const qutimotr::Fingerprint& fingerprint)
{
    ConnContext* context;
    ::Fingerprint* fp;

    for (context = m_userstate->context_root; context != NULL;
         context = context->next)
    {
        fp = otrl_context_find_fingerprint(context, fingerprint.fingerprint, 0,
                                           NULL);
        if (fp != NULL)
        {
            otrl_context_forget_fingerprint(fp, true);
            break;
        }
    }
    write_fingerprints();
}
Example #7
0
/* Forget a whole context, so long as it's PLAINTEXT. */
void otrl_context_forget(ConnContext *context)
{
    if (context->msgstate != OTRL_MSGSTATE_PLAINTEXT) return;

    /* Just to be safe, force to plaintext.  This also frees any
     * extraneous data lying around. */
    otrl_context_force_plaintext(context);

    /* First free all the Fingerprints */
    while(context->fingerprint_root.next) {
	otrl_context_forget_fingerprint(context->fingerprint_root.next, 0);
    }
    /* Now free all the dynamic info here */
    free(context->username);
    free(context->accountname);
    free(context->protocol);
    free(context->smstate);
    context->username = NULL;
    context->accountname = NULL;
    context->protocol = NULL;
    context->smstate = NULL;

    /* Free the application data, if it exists */
    if (context->app_data && context->app_data_free) {
	(context->app_data_free)(context->app_data);
	context->app_data = NULL;
    }

    /* Fix the list linkages */
    *(context->tous) = context->next;
    if (context->next) {
	context->next->tous = context->tous;
    }

    free(context);
}
Example #8
0
static INT_PTR CALLBACK DlgProcMirOTROptsFinger(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HWND lv = GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST);

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR) new FPModifyMap());

		SendDlgItemMessage(hwndDlg, IDC_LV_FINGER_LIST, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);// | LVS_EX_CHECKBOXES);
		{
			// add list columns
			LVCOLUMN lvc;
			// Initialize the LVCOLUMN structure.
			// The mask specifies that the format, width, text, and
			// subitem members of the structure are valid.
			lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
			lvc.fmt = LVCFMT_LEFT;

			lvc.iSubItem = 0;
			lvc.pszText = TranslateT(LANG_CONTACT);
			lvc.cx = 100;     // width of column in pixels
			ListView_InsertColumn(lv, 0, &lvc);

			lvc.iSubItem = 1;
			lvc.pszText = TranslateT(LANG_PROTO);
			lvc.cx = 90;     // width of column in pixels
			ListView_InsertColumn(lv, 1, &lvc);

			lvc.iSubItem = 2;
			lvc.pszText = TranslateT(LANG_ACTIVE);
			lvc.cx = 50;     // width of column in pixels
			ListView_InsertColumn(lv, 2, &lvc);

			lvc.iSubItem = 3;
			lvc.pszText = TranslateT(LANG_VERIFIED);
			lvc.cx = 50;     // width of column in pixels
			ListView_InsertColumn(lv, 3, &lvc);

			lvc.iSubItem = 4;
			lvc.pszText = TranslateT(LANG_FINGERPRINT);
			lvc.cx = 300;     // width of column in pixels
			ListView_InsertColumn(lv, 4, &lvc);
		}
		SendMessage(hwndDlg, WMU_REFRESHLIST, 0, 0);
		return TRUE;

	case WMU_REFRESHLIST:
		// enumerate contacts, fill in list
		ListView_DeleteAllItems(lv);
		{
			LVITEM lvI = { 0 };

			// Some code to create the list-view control.
			// Initialize LVITEM members that are common to all
			// items.
			lvI.mask = LVIF_TEXT | LVIF_PARAM;// | LVIF_NORECOMPUTE;// | LVIF_IMAGE;

			TCHAR *user, hash[45] = { 0 };
			for (ConnContext *context = otr_user_state->context_root; context; context = context->next) {
				if (context->app_data) {
					user = (TCHAR*)contact_get_nameT((UINT_PTR)context->app_data);
					if (user) {
						PROTOACCOUNT *pa = Proto_GetAccount(context->protocol);

						for (Fingerprint *fp = context->fingerprint_root.next; fp; fp = fp->next) {
							otrl_privkey_hash_to_humanT(hash, fp->fingerprint);
							lvI.iSubItem = 0;
							lvI.lParam = (LPARAM)fp;
							lvI.pszText = user;
							int d = ListView_InsertItem(lv, &lvI);

							ListView_SetItemText(lv, d, 1, pa->tszAccountName);
							ListView_SetItemText(lv, d, 2, (context->active_fingerprint == fp) ? TranslateT(LANG_YES) : TranslateT(LANG_NO));
							ListView_SetItemText(lv, d, 3, (fp->trust && fp->trust[0] != '\0') ? TranslateT(LANG_YES) : TranslateT(LANG_NO));
							ListView_SetItemText(lv, d, 4, hash);
						}
					}
				}
			}
		}
		return TRUE;

	case WM_COMMAND:
		switch (HIWORD(wParam)) {
		int sel;
		case BN_CLICKED:
			switch (LOWORD(wParam)) {
			case IDC_BTN_FINGER_DONTTRUST:
				sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST));
				if (sel != -1) {
					LVITEM lvi = { 0 };
					lvi.mask = LVIF_PARAM;
					lvi.iItem = sel;
					ListView_GetItem(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), &lvi);
					Fingerprint *fp = (Fingerprint*)lvi.lParam;
					FPModifyMap* fpm = (FPModifyMap*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
					(*fpm)[fp] = FPM_NOTRUST;
					ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), sel, 3, TranslateT(LANG_NO));
					SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				}
				break;
			case IDC_BTN_FINGER_TRUST:
				sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST));
				if (sel != -1) {
					LVITEM lvi = { 0 };
					lvi.mask = LVIF_PARAM;
					lvi.iItem = sel;
					ListView_GetItem(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), &lvi);
					Fingerprint *fp = (Fingerprint*)lvi.lParam;
					FPModifyMap* fpm = (FPModifyMap*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
					(*fpm)[fp] = FPM_VERIFY;
					ListView_SetItemText(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), sel, 3, TranslateT(LANG_YES));
					SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				}
				break;
			
			case IDC_BTN_FINGER_FORGET:
				sel = ListView_GetSelectionMark(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST));
				if (sel != -1) {
					LVITEM lvi = { 0 };
					lvi.mask = LVIF_PARAM;
					lvi.iItem = sel;
					ListView_GetItem(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), &lvi);
					Fingerprint *fp = (Fingerprint*)lvi.lParam;
					if (fp->context->active_fingerprint == fp) {
						MCONTACT hContact = (UINT_PTR)fp->context->app_data;
						TCHAR buff[1024], hash[45];
						otrl_privkey_hash_to_humanT(hash, fp->fingerprint);
						PROTOACCOUNT *pa = Proto_GetAccount(GetContactProto(hContact));
						mir_sntprintf(buff, TranslateT(LANG_FINGERPRINT_STILL_IN_USE), hash, contact_get_nameT(hContact), pa->tszAccountName);
						ShowError(buff);
					}
					else {
						FPModifyMap* fpm = (FPModifyMap*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
						(*fpm)[fp] = FPM_DELETE;
						ListView_DeleteItem(GetDlgItem(hwndDlg, IDC_LV_FINGER_LIST), sel);
						SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
					}
				}
				break;
			}
		}
		break;

	case WM_NOTIFY:
		if (((LPNMHDR)lParam)->code == (UINT)PSN_APPLY) {
			// handle apply
			FPModifyMap *fpm = (FPModifyMap*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
			// Iterate over the map and print out all key/value pairs.
			// Using a const_iterator since we are not going to change the values.
			for (FPModifyMap::const_iterator it = fpm->begin(); it != fpm->end(); ++it) {
				if (!it->first) continue;
				switch (it->second) {
				case FPM_DELETE:
					if (it->first->context->active_fingerprint == it->first) {
						MCONTACT hContact = (UINT_PTR)it->first->context->app_data;
						TCHAR buff[1024], hash[45];
						otrl_privkey_hash_to_humanT(hash, it->first->fingerprint);
						PROTOACCOUNT *pa = Proto_GetAccount(GetContactProto(hContact));
						mir_sntprintf(buff, TranslateT(LANG_FINGERPRINT_NOT_DELETED), hash, contact_get_nameT(hContact), pa->tszAccountName);
						ShowError(buff);
					}
					else otrl_context_forget_fingerprint(it->first, 1);
					break;

				case FPM_VERIFY:
					otrl_context_set_trust(it->first, "verified");
					if (it->first == it->first->context->active_fingerprint)
						VerifyFingerprint(it->first->context, true);
					break;

				case FPM_NOTRUST:
					otrl_context_set_trust(it->first, NULL);
					if (it->first == it->first->context->active_fingerprint)
						VerifyFingerprint(it->first->context, false);
					break;
				}
			}

			if (!fpm->empty())
				otr_gui_write_fingerprints(0);
			fpm->clear();
			SendMessage(hwndDlg, WMU_REFRESHLIST, 0, 0);
			return TRUE;
		}
		break;

	case WM_DESTROY:
		FPModifyMap *fpm = (FPModifyMap*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
		fpm->clear();
		delete fpm;
		break;
	}

	return FALSE;
}