mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-30 07:36:21 +00:00
Require '/otr start' from both parties before encryption used both ways
This commit is contained in:
@@ -1140,10 +1140,24 @@ cmd_execute_default(const char * const inp)
|
|||||||
ui_current_print_line("You are not currently connected.");
|
ui_current_print_line("You are not currently connected.");
|
||||||
} else {
|
} else {
|
||||||
#ifdef HAVE_LIBOTR
|
#ifdef HAVE_LIBOTR
|
||||||
char *encrypted = otr_encrypt_message(recipient, inp);
|
if (ui_current_win_is_otr()) {
|
||||||
if (encrypted != NULL) {
|
char *encrypted = otr_encrypt_message(recipient, inp);
|
||||||
message_send(encrypted, recipient);
|
if (encrypted != NULL) {
|
||||||
otr_free_message(encrypted);
|
message_send(encrypted, recipient);
|
||||||
|
otr_free_message(encrypted);
|
||||||
|
if (prefs_get_boolean(PREF_CHLOG)) {
|
||||||
|
const char *jid = jabber_get_fulljid();
|
||||||
|
Jid *jidp = jid_create(jid);
|
||||||
|
chat_log_chat(jidp->barejid, recipient, inp, PROF_OUT_LOG, NULL);
|
||||||
|
jid_destroy(jidp);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui_outgoing_msg("me", recipient, inp);
|
||||||
|
} else {
|
||||||
|
cons_show_error("Failed to send message.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
message_send(inp, recipient);
|
||||||
if (prefs_get_boolean(PREF_CHLOG)) {
|
if (prefs_get_boolean(PREF_CHLOG)) {
|
||||||
const char *jid = jabber_get_fulljid();
|
const char *jid = jabber_get_fulljid();
|
||||||
Jid *jidp = jid_create(jid);
|
Jid *jidp = jid_create(jid);
|
||||||
@@ -1152,8 +1166,6 @@ cmd_execute_default(const char * const inp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ui_outgoing_msg("me", recipient, inp);
|
ui_outgoing_msg("me", recipient, inp);
|
||||||
} else {
|
|
||||||
cons_show_error("Failed to send message.");
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
message_send(inp, recipient);
|
message_send(inp, recipient);
|
||||||
@@ -1166,7 +1178,6 @@ cmd_execute_default(const char * const inp)
|
|||||||
|
|
||||||
ui_outgoing_msg("me", recipient, inp);
|
ui_outgoing_msg("me", recipient, inp);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,8 @@
|
|||||||
#include "tools/parser.h"
|
#include "tools/parser.h"
|
||||||
#include "tools/tinyurl.h"
|
#include "tools/tinyurl.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
#include "ui/window.h"
|
||||||
|
#include "ui/windows.h"
|
||||||
#include "xmpp/xmpp.h"
|
#include "xmpp/xmpp.h"
|
||||||
#include "xmpp/bookmark.h"
|
#include "xmpp/bookmark.h"
|
||||||
|
|
||||||
@@ -917,10 +919,24 @@ cmd_msg(gchar **args, struct cmd_help_t help)
|
|||||||
}
|
}
|
||||||
if (msg != NULL) {
|
if (msg != NULL) {
|
||||||
#ifdef HAVE_LIBOTR
|
#ifdef HAVE_LIBOTR
|
||||||
char *encrypted = otr_encrypt_message(usr_jid, msg);
|
if (ui_current_win_is_otr()) {
|
||||||
if (encrypted != NULL) {
|
char *encrypted = otr_encrypt_message(usr_jid, msg);
|
||||||
message_send(encrypted, usr_jid);
|
if (encrypted != NULL) {
|
||||||
otr_free_message(encrypted);
|
message_send(encrypted, usr_jid);
|
||||||
|
otr_free_message(encrypted);
|
||||||
|
ui_outgoing_msg("me", usr_jid, msg);
|
||||||
|
|
||||||
|
if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) {
|
||||||
|
const char *jid = jabber_get_fulljid();
|
||||||
|
Jid *jidp = jid_create(jid);
|
||||||
|
chat_log_chat(jidp->barejid, usr_jid, msg, PROF_OUT_LOG, NULL);
|
||||||
|
jid_destroy(jidp);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cons_show_error("Failed to encrypt and send message,");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
message_send(msg, usr_jid);
|
||||||
ui_outgoing_msg("me", usr_jid, msg);
|
ui_outgoing_msg("me", usr_jid, msg);
|
||||||
|
|
||||||
if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) {
|
if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) {
|
||||||
@@ -929,10 +945,8 @@ cmd_msg(gchar **args, struct cmd_help_t help)
|
|||||||
chat_log_chat(jidp->barejid, usr_jid, msg, PROF_OUT_LOG, NULL);
|
chat_log_chat(jidp->barejid, usr_jid, msg, PROF_OUT_LOG, NULL);
|
||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
cons_show_error("Failed to send message,");
|
|
||||||
}
|
}
|
||||||
|
return TRUE;
|
||||||
#else
|
#else
|
||||||
message_send(msg, usr_jid);
|
message_send(msg, usr_jid);
|
||||||
ui_outgoing_msg("me", usr_jid, msg);
|
ui_outgoing_msg("me", usr_jid, msg);
|
||||||
@@ -942,9 +956,10 @@ cmd_msg(gchar **args, struct cmd_help_t help)
|
|||||||
Jid *jidp = jid_create(jid);
|
Jid *jidp = jid_create(jid);
|
||||||
chat_log_chat(jidp->barejid, usr_jid, msg, PROF_OUT_LOG, NULL);
|
chat_log_chat(jidp->barejid, usr_jid, msg, PROF_OUT_LOG, NULL);
|
||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
} else {
|
} else {
|
||||||
const char * jid = NULL;
|
const char * jid = NULL;
|
||||||
|
|
||||||
@@ -2300,6 +2315,22 @@ cmd_otr(gchar **args, struct cmd_help_t help)
|
|||||||
char *fingerprint = otr_get_fingerprint();
|
char *fingerprint = otr_get_fingerprint();
|
||||||
cons_show("Your fingerprint: %s", fingerprint);
|
cons_show("Your fingerprint: %s", fingerprint);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
} else if (strcmp(args[0], "start") == 0) {
|
||||||
|
win_type_t win_type = ui_current_win_type();
|
||||||
|
|
||||||
|
if (win_type != WIN_CHAT) {
|
||||||
|
ui_current_print_line("You must be in a regular chat window to start an OTR session.");
|
||||||
|
} else if (ui_current_win_is_otr()) {
|
||||||
|
ui_current_print_line("You are already in an OTR session.");
|
||||||
|
} else {
|
||||||
|
if (!otr_key_loaded()) {
|
||||||
|
ui_current_print_line("You have not generated or loaded a private key, use '/otr gen'");
|
||||||
|
} else {
|
||||||
|
ui_current_print_line("Starting OTR session");
|
||||||
|
ui_current_set_otr(TRUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
} else {
|
} else {
|
||||||
cons_show("Usage: %s", help.usage);
|
cons_show("Usage: %s", help.usage);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|||||||
24
src/otr.c
24
src/otr.c
@@ -301,6 +301,7 @@ otr_keygen(ProfAccount *account)
|
|||||||
g_string_free(basedir, TRUE);
|
g_string_free(basedir, TRUE);
|
||||||
g_string_free(keysfilename, TRUE);
|
g_string_free(keysfilename, TRUE);
|
||||||
log_error("Failed to load private key");
|
log_error("Failed to load private key");
|
||||||
|
data_loaded = FALSE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,15 +310,24 @@ otr_keygen(ProfAccount *account)
|
|||||||
g_string_free(basedir, TRUE);
|
g_string_free(basedir, TRUE);
|
||||||
g_string_free(keysfilename, TRUE);
|
g_string_free(keysfilename, TRUE);
|
||||||
log_error("Failed to load fingerprints");
|
log_error("Failed to load fingerprints");
|
||||||
|
data_loaded = FALSE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data_loaded = TRUE;
|
||||||
|
|
||||||
g_string_free(basedir, TRUE);
|
g_string_free(basedir, TRUE);
|
||||||
g_string_free(keysfilename, TRUE);
|
g_string_free(keysfilename, TRUE);
|
||||||
g_string_free(fpsfilename, TRUE);
|
g_string_free(fpsfilename, TRUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
otr_key_loaded(void)
|
||||||
|
{
|
||||||
|
return data_loaded;
|
||||||
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
otr_get_fingerprint(void)
|
otr_get_fingerprint(void)
|
||||||
{
|
{
|
||||||
@@ -361,12 +371,20 @@ otr_decrypt_message(const char * const from, const char * const message)
|
|||||||
{
|
{
|
||||||
cons_debug("Decrypting message: %s", message);
|
cons_debug("Decrypting message: %s", message);
|
||||||
char *decrypted = NULL;
|
char *decrypted = NULL;
|
||||||
int ignore_mesage = otrl_message_receiving(user_state, &ops, NULL, jid, "xmpp", from, message, &decrypted, 0, NULL, NULL);
|
int result = otrl_message_receiving(user_state, &ops, NULL, jid, "xmpp", from, message, &decrypted, 0, NULL, NULL);
|
||||||
if (!ignore_mesage) {
|
|
||||||
|
// internal libotr message, ignore
|
||||||
|
if (result == 1) {
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
// message was decrypted, return to user
|
||||||
|
} else if (decrypted != NULL) {
|
||||||
cons_debug("Decrypted message: %s", decrypted);
|
cons_debug("Decrypted message: %s", decrypted);
|
||||||
return decrypted;
|
return decrypted;
|
||||||
|
|
||||||
|
// normal non OTR message
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return strdup(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ void otr_init(void);
|
|||||||
void otr_on_connect(ProfAccount *account);
|
void otr_on_connect(ProfAccount *account);
|
||||||
void otr_keygen(ProfAccount *account);
|
void otr_keygen(ProfAccount *account);
|
||||||
|
|
||||||
|
gboolean otr_key_loaded(void);
|
||||||
|
|
||||||
char * otr_get_fingerprint(void);
|
char * otr_get_fingerprint(void);
|
||||||
|
|
||||||
char * otr_encrypt_message(const char * const to, const char * const message);
|
char * otr_encrypt_message(const char * const to, const char * const message);
|
||||||
|
|||||||
@@ -171,6 +171,7 @@ handle_duck_result(const char * const result)
|
|||||||
void
|
void
|
||||||
handle_incoming_message(char *from, char *message, gboolean priv)
|
handle_incoming_message(char *from, char *message, gboolean priv)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_LIBOTR
|
||||||
char *newmessage;
|
char *newmessage;
|
||||||
if (!priv) {
|
if (!priv) {
|
||||||
newmessage = otr_decrypt_message(from, message);
|
newmessage = otr_decrypt_message(from, message);
|
||||||
@@ -195,6 +196,19 @@ handle_incoming_message(char *from, char *message, gboolean priv)
|
|||||||
|
|
||||||
if (!priv)
|
if (!priv)
|
||||||
otr_free_message(newmessage);
|
otr_free_message(newmessage);
|
||||||
|
#else
|
||||||
|
ui_incoming_msg(from, message, NULL, priv);
|
||||||
|
ui_current_page_off();
|
||||||
|
|
||||||
|
if (prefs_get_boolean(PREF_CHLOG) && !priv) {
|
||||||
|
Jid *from_jid = jid_create(from);
|
||||||
|
const char *jid = jabber_get_fulljid();
|
||||||
|
Jid *jidp = jid_create(jid);
|
||||||
|
chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, NULL);
|
||||||
|
jid_destroy(jidp);
|
||||||
|
jid_destroy(from_jid);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -693,6 +693,20 @@ _ui_current_win_type(void)
|
|||||||
return current->type;
|
return current->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
_ui_current_win_is_otr(void)
|
||||||
|
{
|
||||||
|
ProfWin *current = wins_get_current();
|
||||||
|
return current->is_otr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_ui_current_set_otr(gboolean value)
|
||||||
|
{
|
||||||
|
ProfWin *current = wins_get_current();
|
||||||
|
current->is_otr = value;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_ui_current_win_index(void)
|
_ui_current_win_index(void)
|
||||||
{
|
{
|
||||||
@@ -1609,4 +1623,6 @@ ui_init_module(void)
|
|||||||
ui_unread = _ui_unread;
|
ui_unread = _ui_unread;
|
||||||
ui_win_unread = _ui_win_unread;
|
ui_win_unread = _ui_win_unread;
|
||||||
ui_ask_password = _ui_ask_password;
|
ui_ask_password = _ui_ask_password;
|
||||||
|
ui_current_win_is_otr = _ui_current_win_is_otr;
|
||||||
|
ui_current_set_otr = _ui_current_set_otr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ void (*ui_close_current)(void);
|
|||||||
void (*ui_clear_current)(void);
|
void (*ui_clear_current)(void);
|
||||||
win_type_t (*ui_current_win_type)(void);
|
win_type_t (*ui_current_win_type)(void);
|
||||||
int (*ui_current_win_index)(void);
|
int (*ui_current_win_index)(void);
|
||||||
|
gboolean (*ui_current_win_is_otr)(void);
|
||||||
|
void (*ui_current_set_otr)(gboolean value);
|
||||||
char* (*ui_current_recipient)(void);
|
char* (*ui_current_recipient)(void);
|
||||||
void (*ui_current_print_line)(const char * const msg, ...);
|
void (*ui_current_print_line)(const char * const msg, ...);
|
||||||
void (*ui_current_error_line)(const char * const msg);
|
void (*ui_current_error_line)(const char * const msg);
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ win_create(const char * const title, int cols, win_type_t type)
|
|||||||
new_win->unread = 0;
|
new_win->unread = 0;
|
||||||
new_win->history_shown = 0;
|
new_win->history_shown = 0;
|
||||||
new_win->type = type;
|
new_win->type = type;
|
||||||
|
new_win->is_otr = FALSE;
|
||||||
scrollok(new_win->win, TRUE);
|
scrollok(new_win->win, TRUE);
|
||||||
|
|
||||||
return new_win;
|
return new_win;
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ typedef struct prof_win_t {
|
|||||||
char *from;
|
char *from;
|
||||||
WINDOW *win;
|
WINDOW *win;
|
||||||
win_type_t type;
|
win_type_t type;
|
||||||
|
gboolean is_otr;
|
||||||
int y_pos;
|
int y_pos;
|
||||||
int paged;
|
int paged;
|
||||||
int unread;
|
int unread;
|
||||||
|
|||||||
Reference in New Issue
Block a user