/* * otr.c * * Copyright (C) 2012 - 2016 James Booth * * This file is part of Profanity. * * Profanity is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Profanity is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Profanity. If not, see . * * In addition, as a special exception, the copyright holders give permission to * link the code of portions of this program with the OpenSSL library under * certain conditions as described in each individual source file, and * distribute linked combinations including the two. * * You must obey the GNU General Public License in all respects for all of the * code used other than OpenSSL. If you modify file(s) with this exception, you * may extend this exception to your version of the file(s), but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. If you delete this exception statement from all * source files in the program, then also delete it here. * */ #include #include #include #include #include #include "otr/otr.h" #include "otr/otrlib.h" #include "log.h" #include "roster_list.h" #include "window_list.h" #include "contact.h" #include "ui/ui.h" #include "xmpp/xmpp.h" #include "config/preferences.h" #include "chat_session.h" #define PRESENCE_ONLINE 1 #define PRESENCE_OFFLINE 0 #define PRESENCE_UNKNOWN -1 static OtrlUserState user_state; static OtrlMessageAppOps ops; static char *jid; static gboolean data_loaded; static GHashTable *smp_initiators; OtrlUserState otr_userstate(void) { return user_state; } OtrlMessageAppOps* otr_messageops(void) { return &ops; } GHashTable* otr_smpinitators(void) { return smp_initiators; } // ops callbacks static OtrlPolicy cb_policy(void *opdata, ConnContext *context) { return otrlib_policy(); } static int cb_is_logged_in(void *opdata, const char *accountname, const char *protocol, const char *recipient) { jabber_conn_status_t conn_status = connection_get_status(); if (conn_status != JABBER_CONNECTED) { return PRESENCE_OFFLINE; } PContact contact = roster_get_contact(recipient); // not in roster if (contact == NULL) { return PRESENCE_ONLINE; } // not subscribed if (p_contact_subscribed(contact) == FALSE) { return PRESENCE_ONLINE; } // subscribed if (g_strcmp0(p_contact_presence(contact), "offline") == 0) { return PRESENCE_OFFLINE; } else { return PRESENCE_ONLINE; } } static void cb_inject_message(void *opdata, const char *accountname, const char *protocol, const char *recipient, const char *message) { char *id = message_send_chat_otr(recipient, message); free(id); } static void cb_write_fingerprints(void *opdata) { gcry_error_t err = 0; gchar *data_home = xdg_get_data_home(); GString *basedir = g_string_new(data_home); free(data_home); gchar *account_dir = str_replace(jid, "@", "_at_"); g_string_append(basedir, "/profanity/otr/"); g_string_append(basedir, account_dir); g_string_append(basedir, "/"); free(account_dir); GString *fpsfilename = g_string_new(basedir->str); g_string_append(fpsfilename, "fingerprints.txt"); err = otrl_privkey_write_fingerprints(user_state, fpsfilename->str); if (err != GPG_ERR_NO_ERROR) { log_error("Failed to write fingerprints file"); cons_show_error("Failed to create fingerprints file"); } g_string_free(basedir, TRUE); g_string_free(fpsfilename, TRUE); } static void cb_gone_secure(void *opdata, ConnContext *context) { ProfChatWin *chatwin = wins_get_chat(context->username); if (!chatwin) { chatwin = (ProfChatWin*) wins_new_chat(context->username); } chatwin_otr_secured(chatwin, otr_is_trusted(context->username)); } char* otr_libotr_version(void) { return OTRL_VERSION; } char* otr_start_query(void) { return otrlib_start_query(); } void otr_init(void) { log_info("Initialising OTR"); OTRL_INIT; jid = NULL; ops.policy = cb_policy; ops.is_logged_in = cb_is_logged_in; ops.inject_message = cb_inject_message; ops.write_fingerprints = cb_write_fingerprints; ops.gone_secure = cb_gone_secure; otrlib_init_ops(&ops); otrlib_init_timer(); smp_initiators = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); data_loaded = FALSE; } void otr_shutdown(void) { if (jid) { free(jid); jid = NULL; } } void otr_poll(void) { otrlib_poll(); } void otr_on_connect(ProfAccount *account) { if (jid) { free(jid); } jid = strdup(account->jid); log_info("Loading OTR key for %s", jid); gchar *data_home = xdg_get_data_home(); GString *basedir = g_string_new(data_home); free(data_home); gchar *account_dir = str_replace(jid, "@", "_at_"); g_string_append(basedir, "/profanity/otr/"); g_string_append(basedir, account_dir); g_string_append(basedir, "/"); free(account_dir); if (!mkdir_recursive(basedir->str)) { log_error("Could not create %s for account %s.", basedir->str, jid); cons_show_error("Could not create %s for account %s.", basedir->str, jid); g_string_free(basedir, TRUE); return; } user_state = otrl_userstate_create(); gcry_error_t err = 0; GString *keysfilename = g_string_new(basedir->str); g_string_append(keysfilename, "keys.txt"); if (!g_file_test(keysfilename->str, G_FILE_TEST_IS_REGULAR)) { log_info("No OTR private key file found %s", keysfilename->str); data_loaded = FALSE; } else { log_info("Loading OTR private key %s", keysfilename->str); err = otrl_privkey_read(user_state, keysfilename->str); if (err != GPG_ERR_NO_ERROR) { log_warning("Failed to read OTR private key file: %s", keysfilename->str); cons_show_error("Failed to read OTR private key file: %s", keysfilename->str); g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); return; } OtrlPrivKey* privkey = otrl_privkey_find(user_state, jid, "xmpp"); if (!privkey) { log_warning("No OTR private key found for account \"%s\", protocol \"xmpp\" in file: %s", jid, keysfilename->str); cons_show_error("No OTR private key found for account \"%s\", protocol \"xmpp\" in file: %s", jid, keysfilename->str); g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); return; } log_info("Loaded OTR private key"); data_loaded = TRUE; } GString *fpsfilename = g_string_new(basedir->str); g_string_append(fpsfilename, "fingerprints.txt"); if (!g_file_test(fpsfilename->str, G_FILE_TEST_IS_REGULAR)) { log_info("No OTR fingerprints file found %s", fpsfilename->str); data_loaded = FALSE; } else { log_info("Loading OTR fingerprints %s", fpsfilename->str); err = otrl_privkey_read_fingerprints(user_state, fpsfilename->str, NULL, NULL); if (err != GPG_ERR_NO_ERROR) { log_error("Failed to load OTR fingerprints file: %s", fpsfilename->str); g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); g_string_free(fpsfilename, TRUE); return; } else { log_info("Loaded OTR fingerprints"); data_loaded = TRUE; } } if (data_loaded) { cons_show("Loaded OTR private key for %s", jid); } g_string_free(basedir, TRUE); g_string_free(keysfilename, TRUE); g_string_free(fpsfilename, TRUE); return; } char* otr_on_message_recv(const char *const barejid, const char *const resource, const char *const message, gboolean *decrypted) { prof_otrpolicy_t policy = otr_get_policy(barejid); char *whitespace_base = strstr(message, OTRL_MESSAGE_TAG_BASE); //check for OTR whitespace (opportunistic or always) if (policy == PROF_OTRPOLICY_OPPORTUNISTIC || policy == PROF_OTRPOLICY_ALWAYS) { if (whitespace_base) { if (strstr(message, OTRL_MESSAGE_TAG_V2) || strstr(message, OTRL_MESSAGE_TAG_V1)) { // Remove whitespace pattern for proper display in UI // Handle both BASE+TAGV1/2(16+8) and BASE+TAGV1+TAGV2(16+8+8) int tag_length = 24; if (strstr(message, OTRL_MESSAGE_TAG_V2) && strstr(message, OTRL_MESSAGE_TAG_V1)) { tag_length = 32; } memmove(whitespace_base, whitespace_base+tag_length, tag_length); char *otr_query_message = otr_start_query(); cons_show("OTR Whitespace pattern detected. Attempting to start OTR session..."); char *id = message_send_chat_otr(barejid, otr_query_message); free(id); } } } char *newmessage = otr_decrypt_message(barejid, message, decrypted); if (!newmessage) { // internal OTR message return NULL; } if (policy == PROF_OTRPOLICY_ALWAYS && *decrypted == FALSE && !whitespace_base) { char *otr_query_message = otr_start_query(); cons_show("Attempting to start OTR session..."); char *id = message_send_chat_otr(barejid, otr_query_message); free(id); } return newmessage; } gboolean otr_on_message_send(ProfChatWin *chatwin, const char *const message) { char *id = NULL; prof_otrpolicy_t policy = otr_get_policy(chatwin->barejid); // Send encrypted message if (otr_is_secure(chatwin->barejid)) { char *encrypted = otr_encrypt_message(chatwin->barejid, message); if (encr
format 70

classinstance 128258 class_ref 169218 // Main
  name ""   xyz 64 4 2000 life_line_z 2000
classinstance 128386 class_ref 149378 // FM
  name ""   xyz 185 32 2000 life_line_z 2000
classinstance 128898 class_ref 128258 // DefaultUI
  name ""   mortal  xyz 289 80 2000 life_line_z 2000
classinstance 132226 class_ref 149122 // Environment
  name ""   xyz 421 84 2000 life_line_z 2000
classinstance 133122 class_ref 156034 // Widget
  name ""   xyz 544 107 2000 life_line_z 2000
classinstance 133762 class_ref 149250 // curses
  name ""   xyz 632 4 2000 life_line_z 2000
classinstance 134530 class_ref 148866 // Command
  name ""   xyz 727 4 2000 life_line_z 2000
note 136962 "This is outdated."
  xyzwh 352 23 2000 145 35
durationcanvas 128514 classinstance_ref 128258 // :Main
  xyzwh 83 82 2010 11 40
end
durationcanvas 128642 classinstance_ref 128386 // :FM
  xyzwh 204 82 2010 11 25
end
durationcanvas 129026 classinstance_ref 128258 // :Main
  xyzwh 83 130 2010 11 34
end
durationcanvas 129154 classinstance_ref 128898 // :DefaultUI
  xyzwh 325 130 2010 11 58
  overlappingdurationcanvas 135426
    xyzwh 331 142 2020 11 40
    overlappingdurationcanvas 135682
      xyzwh 337 151 2030 11 25
    end
  end
end
durationcanvas 129410 classinstance_ref 128258 // :Main
  xyzwh 83 180 2010 11 35
end
durationcanvas 129538 classinstance_ref 128386 // :FM
  xyzwh 204 172 2010 11 468
  overlappingdurationcanvas 136450
    xyzwh 210 537 2020 11 25
  end
end
durationcanvas 129794 classinstance_ref 128258 // :Main
  xyzwh 83 655 2010 11 27
end
durationcanvas 129922 classinstance_ref 128898 // :DefaultUI
  xyzwh 325 655 2010 11 27
end
durationcanvas 130178 classinstance_ref 128898 // :DefaultUI
  xyzwh 325 265 2010 11 26
end
durationcanvas 130434 classinstance_ref 128898 // :DefaultUI
  xyzwh 325 311 2010 11 26
end
durationcanvas 130690 classinstance_ref 128898 // :DefaultUI
  xyzwh 325 381 2010 11 43
end
durationcanvas 131074 classinstance_ref 128898 // :DefaultUI
  xyzwh 325 467 2010 11 53
  overlappingdurationcanvas 134914
    xyzwh 331 489 2020 11 25
  end
end
durationcanvas 132354 classinstance_ref 132226 // :Environment
  xyzwh 469 606 2010 11 32
end
durationcanvas 132866 classinstance_ref 132226 // :Environment
  xyzwh 469 184 2010 11 27
end
durationcanvas 133250 classinstance_ref 133122 // :Widget
  xyzwh 571 280 2010 11 25
end
durationcanvas 133506 classinstance_ref 133122 // :Widget
  xyzwh 571 323 2010 11 25
end
durationcanvas 133890 classinstance_ref 133762 // :curses
  xyzwh 658 389 2010 11 31
end
durationcanvas 135170 classinstance_ref 133122 // :Widget
  xyzwh 571 501 2010 11 27
end
durationcanvas 135938 classinstance_ref 134530 // :Command
  xyzwh 767 506 2010 11 72
end
durationcanvas 136706 classinstance_ref 133122 // :Widget
  xyzwh 571 563 2010 11 34
end
msg 128770 synchronous
  from durationcanvas_ref 128514
  to durationcanvas_ref 128642
  yz 82 2015 msg operation_ref 141826 // "initialize()"
  show_full_operations_definition default drawing_language default
  label_xy 117 64
msg 129282 synchronous
  from durationcanvas_ref 129026
  to durationcanvas_ref 129154
  yz 130 2015 msg operation_ref 171138 // "initialize()"
  show_full_operations_definition default drawing_language default
  label_xy 124 111
msg 129666 synchronous
  from durationcanvas_ref 129410
  to durationcanvas_ref 129538
  yz 180 2015 msg operation_ref 141954 // "loop()"
  show_full_operations_definition default drawing_language default
  label_xy 129 162
msg 130050 synchronous
  from durationcanvas_ref 129794
  to durationcanvas_ref 129922
  yz 655 2015 msg operation_ref 134914 // "destroy()"
  show_full_operations_definition default drawing_language default
  label_xy 119 636
msg 130306 synchronous
  from durationcanvas_ref 129538
  to durationcanvas_ref 130178
  yz 265 2015 msg operation_ref 134530 // "draw()"
  show_full_operations_definition default drawing_language default
  label_xy 245 247
msg 130562 synchronous
  from durationcanvas_ref 129538
  to durationcanvas_ref 130434
  yz 311 2015 msg operation_ref 149378 // "finalize()"
  show_full_operations_definition default drawing_language default
  label_xy 240 293
msg 130818 synchronous
  from durationcanvas_ref 129538
  to durationcanvas_ref 130690
  yz 382 2015 msg operation_ref 148738 // "get_next_key()"
  show_full_operations_definition default drawing_language default
  label_xy 229 361
msg 130946 return
  from durationcanvas_ref 130690
  to durationcanvas_ref 129538
  yz 412 2020 unspecifiedmsg
  show_full_operations_definition default drawing_language default
msg 131202 synchronous
  from durationcanvas_ref 129538
  to durationcanvas_ref 131074
  yz 467 2015 msg operation_ref 148610 // "handle_key()"
  show_full_operations_definition default drawing_language default
  label_xy 234 449
msg 132482 synchronous
  from durationcanvas_ref 129538
  to durationcanvas_ref 132354
  yz 606 2015 msg operation_ref 171522 // "garbage_collect()"
  show_full_operations_definition default drawing_language default
  label_xy 260 587
msg 132994 synchronous
  from durationcanvas_ref 129538
  to durationcanvas_ref 132866
  yz 185 2020 msg operation_ref 171650 // "enter_dir()"
  show_full_operations_definition default drawing_language default
  label_xy 222 164
msg 133378 synchronous
  from durationcanvas_ref 130178
  to durationcanvas_ref 133250
  yz 280 2015 msg operation_ref 134530 // "draw()"
  show_full_operations_definition default drawing_language default
  label_xy 407 262
msg 133634 synchronous
  from durationcanvas_ref 130434
  to durationcanvas_ref 133506
  yz 323 2015 msg operation_ref 149378 // "finalize()"
  show_full_operations_definition default drawing_language default
  label_xy 405 303
msg 134018 synchronous
  from durationcanvas_ref 130690
  to durationcanvas_ref 133890
  yz 391 2015 msg operation_ref 171778 // "getch()"
  show_full_operations_definition default drawing_language default
  label_xy 713 361
msg 134402 return
  from durationcanvas_ref 133890
  to durationcanvas_ref 130690
  yz 408 2020 unspecifiedmsg
  show_full_operations_definition default drawing_language default
reflexivemsg 135042 synchronous
  to durationcanvas_ref 134914
  yz 489 2025 msg operation_ref 148482 // "handle_mouse()"
  show_full_operations_definition default drawing_language default
  label_xy 345 462
msg 135298 synchronous
  from durationcanvas_ref 134914
  to durationcanvas_ref 135170
  yz 502 2030 msg operation_ref 134786 // "click()"
  show_full_operations_definition default drawing_language default
  label_xy 474 484
reflexivemsg 135554 synchronous
  to durationcanvas_ref 135426
  yz 142 2025 msg operation_ref 148866 // "setup()"
  show_full_operations_definition default drawing_language default
  label_xy 340 120
reflexivemsg 135810 synchronous
  to durationcanvas_ref 135682
  yz 151 2035 msg operation_ref 149890 // "add_obj()"
  show_full_operations_definition default drawing_language defaul