[Pkg-privacy-commits] [irssi-plugin-otr] 02/267: added fingerprints, trust, statusbar
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 12:26:11 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 91eeb69c8106f1ffb7caf13b34412b1903e8d0da
Author: Uli Meis <a.sporto+bee at gmail.com>
Date: Tue May 27 13:49:49 2008 +0200
added fingerprints, trust, statusbar
---
Makefile | 20 ++++---
otr.c | 34 ++++++++++++
otr.h | 3 ++
otrutil.c | 156 +++++++++++++++++++++++++++++++++++++++++++-----------
otrutil.h | 6 ++-
privheaders.patch | 12 +++++
6 files changed, 191 insertions(+), 40 deletions(-)
diff --git a/Makefile b/Makefile
index 8569b88..11e151f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
SRCS=otr.c otrutil.c ui.c
-HDRS=otr.h otrutil.h ui.h config.h
+HDRS=otr.h otrutil.h ui.h mainwindows.h statusbar.h
OBJS=$(SRCS:%.c=%.o)
-INCLUDES=-I/usr/include/irssi/src -I/usr/include/irssi/src/core -I.
+INCLUDES=-I/usr/include/irssi/ -I/usr/include/irssi/src -I/usr/include/irssi/src/core -I.
DEFINES=-DHAVE_CONFIG_H
CFLAGS=-Wall -g -fPIC ${INCLUDES} ${DEFINES} `pkg-config --cflags glib-2.0`
@@ -11,17 +11,23 @@ LDFLAGS=-shared -lotr
CC=gcc
LD=ld
-.PHONY: deploy
+.PHONY: deploy privheaders
+
+%.so:
+ ${LD} ${LDFLAGS} $^ -o $@
deploy: libotr.so
cp libotr.so ~/.irssi/modules/libotr.so
-config.h:
- @echo Copy config.h from irssi here
+mainwindows.h:
+ @echo "****" You need to copy over mainwindows.h and statusbar.h from your irssi source \(see irssi FS#535 for info\)
+ @echo "****" Then you need to patch mainwindows.h with headers.patch
+ @echo "****" Or you could just call "make privheaders IRSSI_SRC=path/to/irssi-source"
@exit 1
-%.so:
- ${LD} ${LDFLAGS} $^ -o $@
+privheaders:
+ cp ${IRSSI_SRC}/src/fe-text/{mainwindows.h,statusbar.h} .
+ patch -p0 < privheaders.patch
otr.o: otr.c ${HDRS}
otrutil.o: otrutil.c ${HDRS}
diff --git a/otr.c b/otr.c
index 270e7f7..f2824df 100644
--- a/otr.c
+++ b/otr.c
@@ -45,6 +45,11 @@ static void sig_message_private(SERVER_REC *server, const char *msg,
{
char *newmsg;
+ /* hack for bitlbee so we're not too busy
+ * with the jabber xml console */
+ if (strstr(nick,"xmlconsole"))
+ return;
+
newmsg = otr_receive(server,msg,nick);
if (newmsg&&(newmsg!=msg)) {
@@ -65,6 +70,15 @@ static void cmd_otr(const char *data,void *server,WI_ITEM_REC *item) {
}
}
+static void cmd_trust(const char *data, void *server, WI_ITEM_REC *item) {
+ QUERY_REC *query = QUERY(item);
+ if (query&&query->server&&query->server->connrec)
+ otr_trust(query->server->nick,query->name,query->server->connrec->address);
+ else
+ otr_log(item->server,NULL,query ? query->name : NULL,LVL_NOTICE,
+ "failed: Can't get query details");
+}
+
/*
* /otr debug
*/
@@ -73,6 +87,20 @@ static void cmd_debug(const char *data, void *server, WI_ITEM_REC *item) {
otr_logst(LVL_NOTICE,"Debug mode %s", debug ? "on" : "off" );
}
+static void otr_statusbar(SBAR_ITEM_REC *item, int get_size_only) {
+ WI_ITEM_REC *wi = active_win->active;
+ QUERY_REC *query = QUERY(wi);
+ char *data = NULL;
+
+ if (query&&query->server&&query->server->connrec)
+ data = otr_getstatus(query->server->nick,query->name,query->server->connrec->address);
+
+ statusbar_item_default_handler(
+ item,
+ get_size_only,
+ data ? "{sb Otr: $0-}" : "",data,FALSE);
+}
+
/*
* irssi init()
*/
@@ -87,7 +115,11 @@ void otr_init(void) {
command_bind("otr", NULL, (SIGNAL_FUNC) cmd_otr);
command_bind("otr debug", NULL, (SIGNAL_FUNC) cmd_debug);
+ command_bind("otr trust", NULL, (SIGNAL_FUNC) cmd_trust);
+ statusbar_item_register("otr", NULL, otr_statusbar);
+
+ statusbar_items_redraw("window");
/* use standard irssi style messages */
theme_register_module(MODULE_NAME,fecommon_core_formats);
}
@@ -100,6 +132,8 @@ void otr_deinit(void) {
signal_remove("server sendmsg", (SIGNAL_FUNC) sig_server_sendmsg);
signal_remove("message private", (SIGNAL_FUNC) sig_message_private);
+ statusbar_item_unregister("otr");
+
otrlib_deinit();
}
diff --git a/otr.h b/otr.h
index 3cf3ff2..9ba99ae 100644
--- a/otr.h
+++ b/otr.h
@@ -39,6 +39,9 @@
#include <fe-common/core/module-formats.h>
#include <core/modules.h>
+/* copied over, see FS#535 */
+#include <statusbar.h>
+
/* glib */
#include <glib.h>
diff --git a/otrutil.c b/otrutil.c
index 6e8176b..d97ed4a 100644
--- a/otrutil.c
+++ b/otrutil.c
@@ -26,7 +26,6 @@ static OtrlUserState otr_state = NULL;
static OtrlMessageAppOps otr_ops;
static int otrinited = FALSE;
-
/* Key generation stuff */
typedef enum { KEYGEN_NO, KEYGEN_RUNNING } keygen_status_t;
@@ -66,7 +65,7 @@ gboolean keygen_complete(GIOChannel *source, GIOCondition condition, gpointer da
otr_logst(LVL_NOTICE,KEYGENMSG "completed in %d seconds. Reloading keys",
kg_st.accountname,
time(NULL)-kg_st.started);
- otrl_privkey_forget_all(otr_state);
+ //otrl_privkey_forget_all(otr_state); <-- done by lib
key_load();
}
@@ -85,11 +84,15 @@ void keygen_run(const char *accname) {
gcry_error_t err;
int ret;
int fds[2];
- char *filename = g_strconcat(getenv("HOME"),KEYFILE,NULL);
+ char *filename = g_strconcat(get_irssi_dir(),KEYFILE,NULL);
char *dir = dirname(g_strdup(filename));
if (kg_st.status!=KEYGEN_NO) {
- otr_logst(LVL_NOTICE,KEYGENMSG "another generation is already in progress",accname);
+ if (strcmp(accname,kg_st.accountname)!=0)
+ otr_logst(LVL_NOTICE,KEYGENMSG
+ "aborted. Key generation for %s"
+ "still in progress",
+ accname,kg_st.accountname);
return;
}
@@ -142,6 +145,22 @@ void keygen_run(const char *accname) {
_exit(0);
}
+void otr_writefps() {
+ gcry_error_t err;
+ char *filename = g_strconcat(get_irssi_dir(),FPSFILE,NULL);
+
+ err = otrl_privkey_write_fingerprints(otr_state,filename);
+
+ if (err == GPG_ERR_NO_ERROR) {
+ otr_logst(LVL_NOTICE,"fingerprints saved");
+ } else {
+ otr_logst(LVL_NOTICE,"Error saving fingerprints: %s (%s)",
+ gcry_strerror(err),
+ gcry_strsource(err));
+ }
+ g_free(filename);
+}
+
/* Callbacks from the OTR lib */
OtrlPolicy ops_policy(void *opdata, ConnContext *context) {
@@ -162,9 +181,14 @@ void ops_create_privkey(void *opdata, const char *accountname,
void ops_inject_msg(void *opdata, const char *accountname,
const char *protocol, const char *recipient, const char *message) {
SERVER_REC *a_serv;
+ char *msgcopy = g_strdup(message);
+
+ /* OTR sometimes gives us multiple lines (e.g. the init message) */
+ g_strdelimit (msgcopy,"\n",' ');
a_serv = active_win->active_server;
- a_serv->send_message(a_serv, recipient, message,
+ a_serv->send_message(a_serv, recipient, msgcopy,
GPOINTER_TO_INT(SEND_TARGET_NICK));
+ g_free(msgcopy);
}
/*
@@ -220,13 +244,20 @@ void ops_still_secure(void *opdata, ConnContext *context, int is_reply) {
}
void ops_log(void *opdata, const char *message) {
- otr_logst(LVL_NOTICE,"log msg: ",message);
+ otr_logst(LVL_NOTICE,"log msg: %s",message);
}
int ops_max_msg(void *opdata, ConnContext *context) {
return OTR_MAX_MSG_SIZE;
}
+void ops_up_ctx_list(void *opdata) {
+ statusbar_items_redraw("otr");
+}
+
+void ops_writefps(void *data) {
+ otr_writefps();
+}
/*
* init otr lib.
@@ -240,9 +271,11 @@ int otrlib_init() {
otr_state = otrl_userstate_create();
- /* load keys */
+ /* load keys and fingerprints */
key_load();
+ fps_load();
+
//otrl_privkey_generate(otr_state,"/tmp/somekey","jesus at somewhere.com","proto");
/* set otr ops */
@@ -258,12 +291,14 @@ int otrlib_init() {
otr_ops.still_secure = ops_still_secure;
otr_ops.log_message = ops_log;
otr_ops.max_message_size = ops_max_msg;
-
+ otr_ops.update_context_list = ops_up_ctx_list;
+ otr_ops.write_fingerprints = ops_writefps;
return otr_state==NULL;
}
void otrlib_deinit() {
if (otr_state) {
+ otr_writefps();
otrl_userstate_free(otr_state);
otr_state = NULL;
}
@@ -273,11 +308,11 @@ void otrlib_deinit() {
/*
- * load private keys from given file.
+ * load private keys.
*/
void key_load() {
gcry_error_t err;
- char *filename = g_strconcat(getenv("HOME"),KEYFILE,NULL);
+ char *filename = g_strconcat(get_irssi_dir(),KEYFILE,NULL);
if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
otr_logst(LVL_NOTICE,"no private keys found");
@@ -297,6 +332,42 @@ void key_load() {
}
/*
+ * load fingerprints.
+ */
+void fps_load() {
+ gcry_error_t err;
+ char *filename = g_strconcat(get_irssi_dir(),FPSFILE,NULL);
+
+ if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
+ otr_logst(LVL_NOTICE,"no fingerprints found");
+ return;
+ }
+
+ err = otrl_privkey_read_fingerprints(otr_state,filename,NULL,NULL);
+
+ if (err == GPG_ERR_NO_ERROR) {
+ otr_logst(LVL_NOTICE,"fingerprints loaded");
+ } else {
+ otr_logst(LVL_NOTICE,"Error loading fingerprints: %s (%s)",
+ gcry_strerror(err),
+ gcry_strsource(err));
+ }
+ g_free(filename);
+}
+
+ConnContext *otr_getcontext(const char *accname,const char *nick,int create) {
+ return otrl_context_find(
+ otr_state,
+ nick,
+ accname,
+ PROTOCOLID,
+ create,
+ NULL,
+ NULL,
+ NULL);
+}
+
+/*
* Hand the given message to OTR.
* Returns NULL if OTR handled the message and
* the original message otherwise.
@@ -335,17 +406,7 @@ char *otr_send(SERVER_REC *server, const char *msg,const char *to)
/* OTR message. Need to do fragmentation */
- co = otrl_context_find(
- otr_state,
- to,
- accname,
- PROTOCOLID,
- FALSE,
- NULL,
- NULL,
- NULL);
-
- if (!co) {
+ if (!(co = otr_getcontext(accname,to,FALSE))) {
otr_logst(LVL_NOTICE,"couldn't find context: acc=%s to=%s",accname,to);
return NULL;
}
@@ -366,6 +427,47 @@ char *otr_send(SERVER_REC *server, const char *msg,const char *to)
return NULL;
}
+char *otr_getstatus(char *mynick, char *nick, char *server) {
+ ConnContext *co;
+ char accname[128];
+
+ sprintf(accname, "%s@%s", mynick, server);
+
+ if (!(co = otr_getcontext(accname,nick,FALSE))) {
+ //otr_logst(LVL_NOTICE,"couldn't find context: acc=%s to=%s",accname,nick);
+ return NULL;
+ }
+
+ switch (co->msgstate) {
+ case OTRL_MSGSTATE_PLAINTEXT:
+ return "plaintext";
+ case OTRL_MSGSTATE_ENCRYPTED:
+ {
+ char *trust = co->active_fingerprint->trust;
+ return trust&&*trust!='\0' ? trust : "encrypted";
+ }
+ case OTRL_MSGSTATE_FINISHED:
+ return "finished";
+ default:
+ return "unknown(BUG)";
+ }
+}
+
+void otr_trust(char *mynick, char *nick, char *server) {
+ ConnContext *co;
+ char accname[128];
+
+ sprintf(accname, "%s@%s", mynick, server);
+
+ if (!(co = otr_getcontext(accname,nick,FALSE))) {
+ otr_logst(LVL_NOTICE,"couldn't find context: acc=%s nick=%s",accname,nick);
+ return;
+ }
+
+ otrl_context_set_trust(co->active_fingerprint,"trusted");
+ otr_logst(LVL_NOTICE,"trusting fingerprint from %s",accname);
+}
+
/*
* Hand the given message to OTR.
* Returns NULL if its an OTR protocol message and
@@ -383,17 +485,7 @@ char *otr_receive(SERVER_REC *server, const char *msg,const char *from)
sprintf(accname, "%s@%s", nick, address);
- co = otrl_context_find(
- otr_state,
- from,
- accname,
- PROTOCOLID,
- TRUE,
- NULL,
- NULL,
- NULL);
-
- if (!co) {
+ if (!(co = otr_getcontext(accname,from,TRUE))) {
otr_logst(LVL_NOTICE,"couldn't create/find context: acc=%s from=%s",accname,from);
return NULL;
}
diff --git a/otrutil.h b/otrutil.h
index 6a9441e..42afb99 100644
--- a/otrutil.h
+++ b/otrutil.h
@@ -27,11 +27,15 @@
/* otr protocol id */
#define PROTOCOLID "IRC"
-#define KEYFILE "/.irssi/otr/otr.key"
+#define KEYFILE "/otr/otr.key"
+#define FPSFILE "/otr/otr.fp"
int otrlib_init();
void otrlib_deinit();
void key_load();
+void fps_load();
char *otr_send(SERVER_REC *server,const char *msg,const char *to);
char *otr_receive(SERVER_REC *server,const char *msg,const char *from);
void keygen_run(const char *accname);
+char *otr_getstatus(char *mynick, char *nick, char *server);
+void otr_trust(char *mynick, char *nick, char *server);
diff --git a/privheaders.patch b/privheaders.patch
new file mode 100644
index 0000000..fca77ab
--- /dev/null
+++ b/privheaders.patch
@@ -0,0 +1,12 @@
+--- mainwindows.h.orig 2008-05-09 21:52:26.000000000 +0200
++++ mainwindows.h 2008-05-27 12:44:57.000000000 +0200
+@@ -1,8 +1,8 @@
+ #ifndef __MAINWINDOWS_H
+ #define __MAINWINDOWS_H
+
+-#include "fe-windows.h"
+-#include "term.h"
++#include <fe-common/core/fe-windows.h>
++#include <term.h>
+
+ #define WINDOW_MIN_SIZE 2
--
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