mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
WIP - OTR support
This commit is contained in:
parent
49deb932e6
commit
84f1c4b96f
@ -1140,12 +1140,22 @@ cmd_execute_default(const char * const inp)
|
|||||||
} else {
|
} else {
|
||||||
#ifdef HAVE_LIBOTR
|
#ifdef HAVE_LIBOTR
|
||||||
char *encrypted = otr_encrypt_message(recipient, inp);
|
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
|
#else
|
||||||
message_send(inp, recipient);
|
message_send(inp, recipient);
|
||||||
#endif
|
|
||||||
|
|
||||||
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);
|
||||||
@ -1154,6 +1164,8 @@ cmd_execute_default(const char * const inp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ui_outgoing_msg("me", recipient, inp);
|
ui_outgoing_msg("me", recipient, inp);
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -916,6 +916,24 @@ cmd_msg(gchar **args, struct cmd_help_t help)
|
|||||||
usr_jid = usr;
|
usr_jid = usr;
|
||||||
}
|
}
|
||||||
if (msg != NULL) {
|
if (msg != NULL) {
|
||||||
|
#ifdef HAVE_LIBOTR
|
||||||
|
char *encrypted = otr_encrypt_message(usr_jid, msg);
|
||||||
|
if (encrypted != NULL) {
|
||||||
|
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 send message,");
|
||||||
|
}
|
||||||
|
|
||||||
|
#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);
|
||||||
|
|
||||||
@ -924,7 +942,7 @@ 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);
|
||||||
}
|
#endif
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else {
|
} else {
|
||||||
|
81
src/otr.c
81
src/otr.c
@ -36,23 +36,37 @@ static char *jid;
|
|||||||
static OtrlPolicy
|
static OtrlPolicy
|
||||||
cb_policy(void *opdata, ConnContext *context)
|
cb_policy(void *opdata, ConnContext *context)
|
||||||
{
|
{
|
||||||
cons_debug("cb_policy");
|
// cons_debug("cb_policy");
|
||||||
return OTRL_POLICY_DEFAULT ^ OTRL_POLICY_ALLOW_V1;
|
return OTRL_POLICY_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cb_create_privkey(void *opdata, const char *accountname,
|
cb_create_privkey(void *opdata, const char *accountname,
|
||||||
const char *protocol)
|
const char *protocol)
|
||||||
{
|
{
|
||||||
cons_debug("cb_create_privkey()");
|
// cons_debug("cb_create_privkey accountname: %s, protocol: %s", accountname, protocol);
|
||||||
|
// GString *key_filename = g_string_new("./");
|
||||||
|
// g_string_append(key_filename, accountname);
|
||||||
|
// g_string_append(key_filename, "_key.txt");
|
||||||
|
|
||||||
|
// gcry_error_t err = 0;
|
||||||
|
|
||||||
|
// err = otrl_privkey_generate(user_state, key_filename->str, accountname, protocol);
|
||||||
|
// if (!err == GPG_ERR_NO_ERROR) {
|
||||||
|
// cons_debug("Failed to generate private key");
|
||||||
|
// g_string_free(key_filename, TRUE);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// otrl_privkey_read(user_state, key_filename->str);
|
||||||
|
// cons_debug("Generated private key");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cb_is_logged_in(void *opdata, const char *accountname,
|
cb_is_logged_in(void *opdata, const char *accountname,
|
||||||
const char *protocol, const char *recipient)
|
const char *protocol, const char *recipient)
|
||||||
{
|
{
|
||||||
cons_debug("cb_is_logged_in: account: %s, protocol: %s, recipient: %s",
|
// cons_debug("cb_is_logged_in: account: %s, protocol: %s, recipient: %s",
|
||||||
accountname, protocol, recipient);
|
// accountname, protocol, recipient);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,8 +74,10 @@ static void
|
|||||||
cb_inject_message(void *opdata, const char *accountname,
|
cb_inject_message(void *opdata, const char *accountname,
|
||||||
const char *protocol, const char *recipient, const char *message)
|
const char *protocol, const char *recipient, const char *message)
|
||||||
{
|
{
|
||||||
cons_debug("cb_inject_message: account: %s, protocol, %s, recipient: %s, message: %s",
|
// cons_debug("cb_inject_message: account: %s, protocol, %s, recipient: %s, message: %s",
|
||||||
accountname, protocol, recipient, message);
|
// accountname, protocol, recipient, message);
|
||||||
|
char *msg_decrypt = NULL;
|
||||||
|
otrl_message_receiving(user_state, &ops, NULL, recipient, protocol, accountname, message, &msg_decrypt, 0, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -69,73 +85,72 @@ cb_notify(void *opdata, OtrlNotifyLevel level,
|
|||||||
const char *accountname, const char *protocol, const char *username,
|
const char *accountname, const char *protocol, const char *username,
|
||||||
const char *title, const char *primary, const char *secondary)
|
const char *title, const char *primary, const char *secondary)
|
||||||
{
|
{
|
||||||
cons_debug("cb_notify");
|
// cons_debug("cb_notify");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cb_display_otr_message(void *opdata, const char *accountname,
|
cb_display_otr_message(void *opdata, const char *accountname,
|
||||||
const char *protocol, const char *username, const char *msg)
|
const char *protocol, const char *username, const char *msg)
|
||||||
{
|
{
|
||||||
cons_debug("cb_display_otr_message: account: %s, protocol: %s, user: %s, msg: %s",
|
cons_show_error("%s", msg);
|
||||||
accountname, protocol, username, msg);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
cb_protocol_name(void *opdata, const char *protocol)
|
cb_protocol_name(void *opdata, const char *protocol)
|
||||||
{
|
{
|
||||||
cons_debug("cb_protocol_name: %s", protocol);
|
// cons_debug("cb_protocol_name: %s", protocol);
|
||||||
return protocol;
|
return "xmpp";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cb_new_fingerprint(void *opdata, OtrlUserState us, const char *accountname,
|
cb_new_fingerprint(void *opdata, OtrlUserState us, const char *accountname,
|
||||||
const char *protocol, const char *username, unsigned char fingerprint[20])
|
const char *protocol, const char *username, unsigned char fingerprint[20])
|
||||||
{
|
{
|
||||||
cons_debug("cb_new_fingerprint: account: %s, protocol: %s, username: %s",
|
// cons_debug("cb_new_fingerprint: account: %s, protocol: %s, username: %s",
|
||||||
accountname, protocol, username);
|
// accountname, protocol, username);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cb_protocol_name_free(void *opdata, const char *protocol_name)
|
cb_protocol_name_free(void *opdata, const char *protocol_name)
|
||||||
{
|
{
|
||||||
cons_debug("cb_protocol_name_free: %s", protocol_name);
|
// cons_debug("cb_protocol_name_free: %s", protocol_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cb_update_context_list(void *opdata)
|
cb_update_context_list(void *opdata)
|
||||||
{
|
{
|
||||||
cons_debug("cb_update_context_list");
|
// cons_debug("cb_update_context_list");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cb_write_fingerprints(void *opdata)
|
cb_write_fingerprints(void *opdata)
|
||||||
{
|
{
|
||||||
cons_debug("cb_write_fingerprints");
|
// cons_debug("cb_write_fingerprints");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cb_gone_secure(void *opdata, ConnContext *context)
|
cb_gone_secure(void *opdata, ConnContext *context)
|
||||||
{
|
{
|
||||||
cons_debug("cb_gone_secure");
|
// cons_debug("cb_gone_secure");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cb_gone_insecure(void *opdata, ConnContext *context)
|
cb_gone_insecure(void *opdata, ConnContext *context)
|
||||||
{
|
{
|
||||||
cons_debug("cb_gone_insecure");
|
// cons_debug("cb_gone_insecure");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cb_still_secure(void *opdata, ConnContext *context, int is_reply)
|
cb_still_secure(void *opdata, ConnContext *context, int is_reply)
|
||||||
{
|
{
|
||||||
cons_debug("cb_still_secure: is_reply = %d", is_reply);
|
// cons_debug("cb_still_secure: is_reply = %d", is_reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cb_log_message(void *opdata, const char *message)
|
cb_log_message(void *opdata, const char *message)
|
||||||
{
|
{
|
||||||
cons_debug("cb_log_message: %s", message);
|
// cons_debug("cb_log_message: %s", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -170,10 +185,14 @@ otr_account_load(ProfAccount *account)
|
|||||||
|
|
||||||
GString *key_filename = g_string_new("./");
|
GString *key_filename = g_string_new("./");
|
||||||
g_string_append(key_filename, account->jid);
|
g_string_append(key_filename, account->jid);
|
||||||
|
g_string_append(key_filename, "/");
|
||||||
|
g_string_append(key_filename, account->jid);
|
||||||
g_string_append(key_filename, "_key.txt");
|
g_string_append(key_filename, "_key.txt");
|
||||||
|
|
||||||
GString *fp_filename = g_string_new("./");
|
GString *fp_filename = g_string_new("./");
|
||||||
g_string_append(fp_filename, account->jid);
|
g_string_append(fp_filename, account->jid);
|
||||||
|
g_string_append(fp_filename, "/");
|
||||||
|
g_string_append(fp_filename, account->jid);
|
||||||
g_string_append(fp_filename, "_fingerprints.txt");
|
g_string_append(fp_filename, "_fingerprints.txt");
|
||||||
|
|
||||||
user_state = otrl_userstate_create();
|
user_state = otrl_userstate_create();
|
||||||
@ -191,6 +210,7 @@ otr_account_load(ProfAccount *account)
|
|||||||
cons_debug("Generated private key");
|
cons_debug("Generated private key");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!g_file_test(fp_filename->str, G_FILE_TEST_IS_REGULAR)) {
|
if (!g_file_test(fp_filename->str, G_FILE_TEST_IS_REGULAR)) {
|
||||||
cons_debug("Fingerprints not found, creating file");
|
cons_debug("Fingerprints not found, creating file");
|
||||||
err = otrl_privkey_write_fingerprints(user_state, fp_filename->str);
|
err = otrl_privkey_write_fingerprints(user_state, fp_filename->str);
|
||||||
@ -228,7 +248,7 @@ otr_account_load(ProfAccount *account)
|
|||||||
char *
|
char *
|
||||||
otr_encrypt_message(const char * const to, const char * const message)
|
otr_encrypt_message(const char * const to, const char * const message)
|
||||||
{
|
{
|
||||||
cons_debug("otr_encrypt_message, account: %s, protocol: xmpp, recipient: %s", jid, to);
|
// cons_debug("otr_encrypt_message, account: %s, recipient: %s, message: %s", jid, to, message);
|
||||||
gcry_error_t err;
|
gcry_error_t err;
|
||||||
char *newmessage = NULL;
|
char *newmessage = NULL;
|
||||||
|
|
||||||
@ -243,9 +263,9 @@ otr_encrypt_message(const char * const to, const char * const message)
|
|||||||
0,
|
0,
|
||||||
&newmessage,
|
&newmessage,
|
||||||
NULL,
|
NULL,
|
||||||
&ops);
|
NULL);
|
||||||
if (!err == GPG_ERR_NO_ERROR) {
|
if (!err == GPG_ERR_NO_ERROR) {
|
||||||
cons_debug("Error encrypting, result: %s", newmessage);
|
// cons_debug("Error encrypting, result: %s", newmessage);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
cons_debug("Encrypted, result: %s", newmessage);
|
cons_debug("Encrypted, result: %s", newmessage);
|
||||||
@ -253,6 +273,19 @@ otr_encrypt_message(const char * const to, const char * const message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
otr_decrypt_message(const char * const from, const char * const message)
|
||||||
|
{
|
||||||
|
// cons_debug("otr_decrypt_message, account: %s, from: %s, message: %s", jid, from, message);
|
||||||
|
char *decrypted = NULL;
|
||||||
|
int ignore_mesage = otrl_message_receiving(user_state, &ops, NULL, jid, "xmpp", from, message, &decrypted, 0, NULL, NULL);
|
||||||
|
if (!ignore_mesage) {
|
||||||
|
return decrypted;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
otr_free_message(char *message)
|
otr_free_message(char *message)
|
||||||
{
|
{
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
void otr_init(void);
|
void otr_init(void);
|
||||||
void otr_account_load(ProfAccount *account);
|
void otr_account_load(ProfAccount *account);
|
||||||
char * otr_encrypt_message(const char * const to, const char * const message);
|
char * otr_encrypt_message(const char * const to, const char * const message);
|
||||||
|
char * otr_decrypt_message(const char * const from, const char * const message);
|
||||||
void otr_free_message(char *message);
|
void otr_free_message(char *message);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "config/preferences.h"
|
#include "config/preferences.h"
|
||||||
#include "roster_list.h"
|
#include "roster_list.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
#include "otr.h"
|
||||||
|
|
||||||
void
|
void
|
||||||
handle_error_message(const char *from, const char *err_msg)
|
handle_error_message(const char *from, const char *err_msg)
|
||||||
@ -169,17 +170,30 @@ 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)
|
||||||
{
|
{
|
||||||
ui_incoming_msg(from, message, NULL, priv);
|
char *newmessage;
|
||||||
|
if (!priv) {
|
||||||
|
newmessage = otr_decrypt_message(from, message);
|
||||||
|
if (newmessage == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newmessage = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui_incoming_msg(from, newmessage, NULL, priv);
|
||||||
ui_current_page_off();
|
ui_current_page_off();
|
||||||
|
|
||||||
if (prefs_get_boolean(PREF_CHLOG) && !priv) {
|
if (prefs_get_boolean(PREF_CHLOG) && !priv) {
|
||||||
Jid *from_jid = jid_create(from);
|
Jid *from_jid = jid_create(from);
|
||||||
const char *jid = jabber_get_fulljid();
|
const char *jid = jabber_get_fulljid();
|
||||||
Jid *jidp = jid_create(jid);
|
Jid *jidp = jid_create(jid);
|
||||||
chat_log_chat(jidp->barejid, from_jid->barejid, message, PROF_IN_LOG, NULL);
|
chat_log_chat(jidp->barejid, from_jid->barejid, newmessage, PROF_IN_LOG, NULL);
|
||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
jid_destroy(from_jid);
|
jid_destroy(from_jid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!priv)
|
||||||
|
otr_free_message(newmessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
Reference in New Issue
Block a user