[Pkg-privacy-commits] [irssi-plugin-otr] 116/267: Fix: status bar state and SMP auth command
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 12:41:34 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 e02c4b0bfc03cd5fb6fa5ca47c5ce2de9c4ab5f3
Author: David Goulet <dgoulet at ev0ke.net>
Date: Wed Nov 7 21:21:41 2012 -0500
Fix: status bar state and SMP auth command
Signed-off-by: David Goulet <dgoulet at ev0ke.net>
---
src/cmd.c | 1 +
src/otr-ops.c | 27 +++++++++++------
src/otr.c | 93 +++++++++++++++++++++++++++++++++++------------------------
src/otr.h | 2 +-
4 files changed, 75 insertions(+), 48 deletions(-)
diff --git a/src/cmd.c b/src/cmd.c
index 068d77f..6a23985 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -224,6 +224,7 @@ static void _cmd_init(struct otr_user_state *ioustate, SERVER_REC *irssi, int ar
/* No server object, just ignore the request */
if (!irssi) {
+ otr_noticest(TXT_CMD_QNOTFOUND);
goto end;
}
diff --git a/src/otr-ops.c b/src/otr-ops.c
index a7441db..99bcd17 100644
--- a/src/otr-ops.c
+++ b/src/otr-ops.c
@@ -156,7 +156,7 @@ static void ops_insecure(void *opdata, ConnContext *context)
{
SERVER_REC *irssi = opdata;
- otr_notice(irssi, context->username, TXT_OPS_INSEC);
+ IRSSI_NOTICE(irssi, context->username, "%9OTR%9: Gone %rinsecure%r");
otr_status_change(irssi, context->username, OTR_STATUS_GONE_INSECURE);
}
@@ -247,8 +247,13 @@ static void ops_handle_msg_event(void *opdata, OtrlMessageEvent msg_event,
IRSSI_WARN(server, username, "%9OTR:%9 OTR Error: %s.", message);
break;
case OTRL_MSGEVENT_RCVDMSG_UNENCRYPTED:
- IRSSI_WARN(server, username, "%9OTR:%9 The following message from "
- "%9%s%9 was NOT encrypted: [%s]", username, message);
+ if (context->msgstate == OTRL_MSGSTATE_PLAINTEXT) {
+ /* Relay message if in a plaintext state */
+ irssi_send_message(server, username, message);
+ } else {
+ IRSSI_WARN(server, username, "%9OTR:%9 The following message from "
+ "%9%s%9 was NOT encrypted: [%s]", username, message);
+ }
break;
case OTRL_MSGEVENT_RCVDMSG_UNRECOGNIZED:
IRSSI_WARN(server, username, "%9OTR:%9 Unrecognized OTR message "
@@ -262,7 +267,7 @@ static void ops_handle_msg_event(void *opdata, OtrlMessageEvent msg_event,
}
/*
- * A context changed. I believe this is not happening for the SMP expects.
+ * A context changed.
*/
static void ops_up_ctx_list(void *opdata)
{
@@ -299,14 +304,15 @@ static void ops_smp_event(void *opdata, OtrlSMPEvent smp_event,
{
SERVER_REC *irssi = opdata;
const char *from = context->username;
+ struct otr_peer_context *opc = context->app_data;
- if (context->app_data) {
- struct otr_peer_context *opc = context->app_data;
- opc->received_smp_init =
- (smp_event == OTRL_SMPEVENT_ASK_FOR_SECRET) ||
- (smp_event == OTRL_SMPEVENT_ASK_FOR_ANSWER);
+ if (!opc) {
+ IRSSI_DEBUG("%9OTR%9: SMP event cb. Unable to find peer context");
+ goto end;
}
+ opc->smp_event = smp_event;
+
switch (smp_event) {
case OTRL_SMPEVENT_ASK_FOR_SECRET:
otr_notice(irssi, from, TXT_AUTH_PEER, from);
@@ -338,6 +344,9 @@ static void ops_smp_event(void *opdata, OtrlSMPEvent smp_event,
otr_logst(MSGLEVEL_CRAP, "Received unknown SMP event");
break;
}
+
+end:
+ return;
}
/*
diff --git a/src/otr.c b/src/otr.c
index 9eda374..89ebb1c 100644
--- a/src/otr.c
+++ b/src/otr.c
@@ -99,6 +99,28 @@ error_filename:
return;
}
+static void destroy_peer_context_cb(void *data)
+{
+ struct otr_peer_context *opc = data;
+
+ if (opc) {
+ free(opc);
+ }
+}
+
+static void add_peer_context_cb(void *data, ConnContext *context)
+{
+ struct otr_peer_context *opc;
+
+ opc = zmalloc(sizeof(*opc));
+ if (!opc) {
+ return;
+ }
+
+ context->app_data = opc;
+ context->app_data_free = destroy_peer_context_cb;
+}
+
/*
* Get a context from a pair.
*/
@@ -107,7 +129,7 @@ static ConnContext *get_otrl_context(const char *accname, const char *nick,
{
ConnContext *ctx = otrl_context_find(user_state_global->otr_state,
nick, accname, OTR_PROTOCOL_ID, OTRL_INSTAG_BEST, create, NULL,
- NULL, NULL);
+ add_peer_context_cb, NULL);
return ctx;
}
@@ -199,7 +221,7 @@ int otr_send(SERVER_REC *irssi, const char *msg, const char *to, char **otr_msg)
err = otrl_message_sending(user_state_global->otr_state, &otr_ops,
irssi, accname, OTR_PROTOCOL_ID, to, OTRL_INSTAG_BEST, msg, NULL, otr_msg,
- OTRL_FRAGMENT_SEND_ALL_BUT_LAST, NULL, NULL, NULL);
+ OTRL_FRAGMENT_SEND_ALL_BUT_LAST, NULL, add_peer_context_cb, NULL);
if (err) {
IRSSI_NOTICE(irssi, to, "%9OTR:%9 Send failed.");
goto error;
@@ -365,9 +387,10 @@ void otr_finishall(struct otr_user_state *ustate)
*/
void otr_trust(SERVER_REC *irssi, char *nick, const char *peername)
{
- ConnContext *co;
- char accname[128];
+ ConnContext *ctx;
+ char *accname = NULL;
char nickbuf[128];
+ char peerfp[OTRL_PRIVKEY_FPRINT_HUMAN_LEN];
if (peername) {
nick = nickbuf;
@@ -377,18 +400,28 @@ void otr_trust(SERVER_REC *irssi, char *nick, const char *peername)
}
}
- IRSSI_ACCNAME(accname, irssi);
+ accname = create_account_name(irssi);
+ if (!accname) {
+ goto end;
+ }
- if (!(co = get_otrl_context(accname, nick, FALSE, irssi))) {
- otr_noticest(TXT_CTX_NOT_FOUND, accname, nick);
+ ctx = get_otrl_context(accname, nick, FALSE, irssi);
+ if (!ctx) {
goto end;
}
- otrl_context_set_trust(co->active_fingerprint, "manual");
+ otrl_context_set_trust(ctx->active_fingerprint, "manual");
otr_status_change(irssi, nick, OTR_STATUS_TRUST_MANUAL);
- otr_notice(irssi, nick, TXT_FP_TRUST, nick);
+
+ otrl_privkey_hash_to_human(peerfp, ctx->active_fingerprint->fingerprint);
+
+ IRSSI_NOTICE(irssi, nick, "%9OTR%9: Trusting fingerprint from %9%s%9:\n"
+ "%9OTR%9: %g%s%n", nick, peerfp);
+
+ key_write_fingerprints(user_state_global);
end:
+ free(accname);
return;
}
@@ -446,6 +479,7 @@ void otr_auth(SERVER_REC *irssi, char *nick, const char *peername,
ConnContext *ctx;
char *accname = NULL;
char nickbuf[128];
+ struct otr_peer_context *opc;
if (peername) {
nick = nickbuf;
@@ -466,6 +500,10 @@ void otr_auth(SERVER_REC *irssi, char *nick, const char *peername,
goto end;
}
+ opc = ctx->app_data;
+ /* Shoud NOT happen */
+ assert(opc);
+
if (ctx->msgstate != OTRL_MSGSTATE_ENCRYPTED) {
otr_notice(irssi, nick, TXT_AUTH_NEEDENC);
goto end;
@@ -485,7 +523,12 @@ void otr_auth(SERVER_REC *irssi, char *nick, const char *peername,
}
}
- if (ctx->auth.initiated) {
+ if (opc->smp_event == OTRL_SMPEVENT_ASK_FOR_ANSWER) {
+ otrl_message_respond_smp(user_state_global->otr_state, &otr_ops,
+ irssi, ctx, (unsigned char *) secret, strlen(secret));
+ otr_status_change(irssi, nick, OTR_STATUS_SMP_RESPONDED);
+ IRSSI_NOTICE(irssi, nick, "%9OTR%9: Responding to authentication...");
+ } else {
if (question) {
otrl_message_initiate_smp_q(user_state_global->otr_state,
&otr_ops, irssi, ctx, question, (unsigned char *) secret,
@@ -496,15 +539,9 @@ void otr_auth(SERVER_REC *irssi, char *nick, const char *peername,
strlen(secret));
}
otr_status_change(irssi, nick, OTR_STATUS_SMP_STARTED);
- } else {
- otrl_message_respond_smp(user_state_global->otr_state, &otr_ops,
- irssi, ctx, (unsigned char *) secret, strlen(secret));
- otr_status_change(irssi, nick, OTR_STATUS_SMP_RESPONDED);
+ IRSSI_NOTICE(irssi, nick, "%9OTR%9: Initiated authentication...");
}
- otr_notice(irssi, nick, ctx->auth.initiated ? TXT_AUTH_RESPONDING :
- TXT_AUTH_INITIATED);
-
end:
return;
}
@@ -530,7 +567,7 @@ int otr_receive(SERVER_REC *irssi, const char *msg, const char *from,
ret = otrl_message_receiving(user_state_global->otr_state,
&otr_ops, irssi, accname, OTR_PROTOCOL_ID, from, msg, new_msg, &tlvs,
- NULL, NULL, NULL);
+ NULL, add_peer_context_cb, NULL);
if (ret) {
IRSSI_DEBUG("%9OTR%9: Ignoring message of length %d from %s to %s.\n"
"[%s]", strlen(msg), from, accname, msg);
@@ -653,26 +690,6 @@ int otr_getstatus(SERVER_REC *irssi, const char *nick)
} else {
code = IO_ST_UNTRUSTED;
}
-
- /* Are we in a authentication mode ? */
- if (ctx->auth.authstate != OTRL_AUTHSTATE_NONE) {
- /* Check for the current auth state */
- switch (ctx->smstate->nextExpected) {
- case OTRL_SMP_EXPECT1:
- if (ctx->auth.initiated) {
- code = IO_ST_SMP_INCOMING;
- }
- break;
- case OTRL_SMP_EXPECT2:
- code = IO_ST_SMP_OUTGOING;
- break;
- case OTRL_SMP_EXPECT3:
- case OTRL_SMP_EXPECT4:
- case OTRL_SMP_EXPECT5:
- code = IO_ST_SMP_FINALIZE;
- break;
- }
- }
break;
case OTRL_MSGSTATE_FINISHED:
code = IO_ST_FINISHED;
diff --git a/src/otr.h b/src/otr.h
index f71b0d8..2199018 100644
--- a/src/otr.h
+++ b/src/otr.h
@@ -79,7 +79,7 @@ struct otr_user_state {
* Peer OTR internal context.
*/
struct otr_peer_context {
- int received_smp_init;
+ OtrlSMPEvent smp_event;
};
/* these are returned by /otr contexts */
--
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