[Pkg-privacy-commits] [irssi-plugin-otr] 133/267: Support fingerprint for trust command

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 12:41:36 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch debian
in repository irssi-plugin-otr.

commit 24c7f90a3f61cbe9b44b28b2bba0a78277a38e9e
Author: David Goulet <dgoulet at ev0ke.net>
Date:   Wed Nov 14 16:20:18 2012 -0500

    Support fingerprint for trust command
    
    Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
 src/cmd.c     | 36 +++++++++++++++++++++++++++++++-----
 src/otr-ops.c |  8 ++++----
 src/otr.c     | 58 ++++++++++++++++++++++++++++++++++++++--------------------
 src/otr.h     |  3 ++-
 4 files changed, 75 insertions(+), 30 deletions(-)

diff --git a/src/cmd.c b/src/cmd.c
index 8951bd0..cd2f1d7 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -80,14 +80,25 @@ end:
 static void _cmd_trust(struct otr_user_state *ustate, SERVER_REC *irssi,
 		const char *target, const void *data)
 {
-	if (!irssi || !target) {
-		IRSSI_WARN(irssi, target,
-				"Failed: Can't get nick and server of current query window. "
-				"(Or maybe you're doing this in the status window?)");
+	int argc;
+	char **argv;
+	char str_fp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN], *fp = NULL;
+
+	utils_explode_args(data, &argv, &argc);
+
+	if (argc == 5) {
+		utils_hash_parts_to_readable_hash((const char **) argv, str_fp);
+		fp = str_fp;
+	} else if (!irssi || (irssi && argc != 0)) {
+		/* If no IRSSI or some arguments (not 5), bad command. */
+		IRSSI_NOTICE(irssi, target, "Usage %9/otr forget [FP]%9 "
+				"where FP is the five part of the fingerprint listed by "
+				"%9/otr contexts%9 or do the command inside an OTR session "
+				"private message window");
 		goto end;
 	}
 
-	otr_trust(irssi, target);
+	otr_trust(irssi, target, fp, ustate);
 
 end:
 	return;
@@ -149,6 +160,13 @@ static void _cmd_authq(struct otr_user_state *ustate, SERVER_REC *irssi,
 	int ret;
 	char *question = NULL, *secret = NULL;
 
+	if (!irssi || !target) {
+		IRSSI_WARN(irssi, target,
+				"Failed: Can't get nick and server of current query window. "
+				"(Or maybe you're doing this in the status window?)");
+		goto end;
+	}
+
 	/*
 	 * Returns a negative value if the command arguments are not formatted
 	 * correctly or missing. Note, an empty question or secret is valid.
@@ -175,6 +193,13 @@ static void _cmd_auth(struct otr_user_state *ustate, SERVER_REC *irssi,
 	int argc;
 	char **argv;
 
+	if (!irssi || !target) {
+		IRSSI_WARN(irssi, target,
+				"Failed: Can't get nick and server of current query window. "
+				"(Or maybe you're doing this in the status window?)");
+		goto error;
+	}
+
 	utils_explode_args(data, &argv, &argc);
 
 	if (argc == 0) {
@@ -186,6 +211,7 @@ static void _cmd_auth(struct otr_user_state *ustate, SERVER_REC *irssi,
 
 end:
 	utils_free_args(&argv, argc);
+error:
 	return;
 }
 
diff --git a/src/otr-ops.c b/src/otr-ops.c
index 3454ea7..49db0ed 100644
--- a/src/otr-ops.c
+++ b/src/otr-ops.c
@@ -143,10 +143,10 @@ static void ops_secure(void *opdata, ConnContext *context)
 			"(e.g. telephone or GPG-signed mail) and subsequently enter "
 			"%9/otr trust%9.");
 
-	IRSSI_NOTICE(irssi, context->username,
-			"Your fingerprint is: %y%s\%n.\n"
-			"%9%s's%9 fingerprint is: %r%s\%n", ownfp,
-			context->username, peerfp);
+	IRSSI_NOTICE(irssi, context->username, "Your fingerprint is: %y%s%n",
+			ownfp);
+	IRSSI_NOTICE(irssi, context->username, "%9%s's%9 fingerprint is: %r%s%n",
+			peerfp);
 
 end:
 	return;
diff --git a/src/otr.c b/src/otr.c
index f04426b..942872a 100644
--- a/src/otr.c
+++ b/src/otr.c
@@ -389,35 +389,54 @@ void otr_finishall(struct otr_user_state *ustate)
 /*
  * Trust our peer.
  */
-void otr_trust(SERVER_REC *irssi, const char *nick)
+void otr_trust(SERVER_REC *irssi, const char *nick, char *str_fp,
+		struct otr_user_state *ustate)
 {
-	ConnContext *ctx;
 	char peerfp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN];
 	struct otr_peer_context *opc;
+	ConnContext *ctx;
+	Fingerprint *fp_trust;
 
-	assert(irssi);
-	assert(nick);
+	assert(ustate);
 
-	ctx = otr_find_context(irssi, nick, FALSE);
-	if (!ctx) {
-		goto end;
+	if (!irssi && !str_fp) {
+		IRSSI_NOTICE(NULL, nick, "Need a fingerprint!");
+		goto error;
 	}
 
-	opc = ctx->app_data;
-	assert(opc);
+	/* No human string fingerprint given. */
+	if (!str_fp) {
+		ctx = otr_find_context(irssi, nick, FALSE);
+		if (!ctx) {
+			goto error;
+		}
 
-	/* Trust level is manual at this point. */
-	otrl_context_set_trust(opc->active_fingerprint, "manual");
-	otr_status_change(irssi, nick, OTR_STATUS_TRUST_MANUAL);
+		opc = ctx->app_data;
+		/* Always NEED a peer context or else code error. */
+		assert(opc);
 
-	otrl_privkey_hash_to_human(peerfp, opc->active_fingerprint->fingerprint);
+		fp_trust = opc->active_fingerprint;
+	} else {
+		fp_trust = otr_find_hash_fingerprint_from_human(str_fp, ustate);
+	}
 
-	IRSSI_NOTICE(irssi, nick, "Trusting fingerprint from %9%s%9:\n"
-			"%9OTR%9: %g%s%n", nick, peerfp);
+	if (fp_trust) {
+		/* Trust level is manual at this point. */
+		otrl_context_set_trust(fp_trust, "manual");
+		key_write_fingerprints(ustate);
 
-	key_write_fingerprints(user_state_global);
+		otr_status_change(irssi, nick, OTR_STATUS_TRUST_MANUAL);
 
-end:
+		otrl_privkey_hash_to_human(peerfp, fp_trust->fingerprint);
+		IRSSI_NOTICE(irssi, nick, "Fingerprint %g%s%n trusted!", peerfp);
+	} else {
+		IRSSI_NOTICE(irssi, nick, "Fingerprint %y%s%n NOT found",
+				(str_fp != NULL) ? str_fp : peerfp);
+	}
+
+	IRSSI_DEBUG("Trust fingerprint: %s", (str_fp != NULL) ? str_fp : peerfp);
+
+error:
 	return;
 }
 
@@ -865,9 +884,6 @@ void otr_distrust(SERVER_REC *irssi, const char *nick, char *str_fp,
 		fp_distrust = otr_find_hash_fingerprint_from_human(str_fp, ustate);
 	}
 
-	IRSSI_DEBUG("Distrust fingerprint: %s",
-			(str_fp != NULL) ? str_fp : fp);
-
 	if (fp_distrust) {
 		ret = otrl_context_is_fingerprint_trusted(fp_distrust);
 		if (!ret) {
@@ -886,6 +902,8 @@ void otr_distrust(SERVER_REC *irssi, const char *nick, char *str_fp,
 				(str_fp != NULL) ? str_fp : fp);
 	}
 
+	IRSSI_DEBUG("Distrust fingerprint: %s", (str_fp != NULL) ? str_fp : fp);
+
 end:
 error:
 	return;
diff --git a/src/otr.h b/src/otr.h
index 266848f..81d4c2e 100644
--- a/src/otr.h
+++ b/src/otr.h
@@ -184,7 +184,6 @@ int otr_getstatus(SERVER_REC *irssi, const char *nick);
 
 /* user interaction */
 
-void otr_trust(SERVER_REC *irssi, const char *nick);
 void otr_finish(SERVER_REC *irssi, const char *nick);
 void otr_auth(SERVER_REC *irssi, const char *nick, const char *question,
 		const char *secret);
@@ -195,6 +194,8 @@ void otr_forget(SERVER_REC *irssi, const char *nick, char *str_fp,
 		struct otr_user_state *ustate);
 void otr_distrust(SERVER_REC *irssi, const char *nick, char *str_fp,
 		struct otr_user_state *ustate);
+void otr_trust(SERVER_REC *irssi, const char *nick, char *str_fp,
+		struct otr_user_state *ustate);
 
 int otr_getstatus_format(SERVER_REC *irssi, const char *nick);
 struct otr_peer_context *otr_create_peer_context(void);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/irssi-plugin-otr.git



More information about the Pkg-privacy-commits mailing list