diff options
author | James Booth <boothj5@gmail.com> | 2013-08-14 22:27:44 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2013-11-08 00:17:02 +0000 |
commit | bdcc70f36d4545060e61dd7c9a51f63be5ab7d38 (patch) | |
tree | 8448550e93dd1d8151a2c5fda483683706db7aff | |
parent | bd1c139429487f173d973be5810ef15549b4da07 (diff) | |
download | profani-tty-bdcc70f36d4545060e61dd7c9a51f63be5ab7d38.tar.gz |
Load keys and fingerprints for account on connect
-rw-r--r-- | src/otr.c | 41 | ||||
-rw-r--r-- | src/otr.h | 3 | ||||
-rw-r--r-- | src/profanity.c | 3 |
3 files changed, 45 insertions, 2 deletions
diff --git a/src/otr.c b/src/otr.c index 7dd6aafd..6b10e3be 100644 --- a/src/otr.c +++ b/src/otr.c @@ -21,15 +21,52 @@ */ #include <libotr/proto.h> -#include <libotr/userstate.h> -#include <libotr/message.h> #include <libotr/privkey.h> +#include <glib.h> +#include "otr.h" #include "ui/ui.h" +static OtrlUserState user_state; + void otr_init(void) { cons_debug("otr_init()"); OTRL_INIT; } + +void +otr_account_load(ProfAccount *account) +{ + gcry_error_t err = 0; + cons_debug("otr_account_load()"); + GString *keys_filename = g_string_new("./"); + g_string_append(keys_filename, account->jid); + g_string_append(keys_filename, "_keys.txt"); + + GString *fp_filename = g_string_new("./"); + g_string_append(fp_filename, account->jid); + g_string_append(fp_filename, "_fingerprints.txt"); + + user_state = otrl_userstate_create(); + + err = otrl_privkey_read(user_state, keys_filename->str); + if (err != 0) { + cons_debug("Failed to load private keys"); + g_string_free(keys_filename, TRUE); + g_string_free(fp_filename, TRUE); + return; + } + + err = otrl_privkey_read_fingerprints(user_state, fp_filename->str, NULL, NULL); + if (err != 0) { + cons_debug("Failed to load fingerprints"); + g_string_free(keys_filename, TRUE); + g_string_free(fp_filename, TRUE); + return; + } + + g_string_free(keys_filename, TRUE); + g_string_free(fp_filename, TRUE); +} diff --git a/src/otr.h b/src/otr.h index 772c0f34..caa38ee5 100644 --- a/src/otr.h +++ b/src/otr.h @@ -23,6 +23,9 @@ #ifndef OTR_H #define OTR_H +#include "config/accounts.h" + void otr_init(void); +void otr_account_load(ProfAccount *account); #endif diff --git a/src/profanity.c b/src/profanity.c index 913f3350..09bd77d8 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -261,6 +261,9 @@ void prof_handle_login_account_success(char *account_name) { ProfAccount *account = accounts_get_account(account_name); +#ifdef HAVE_LIBOTR + otr_account_load(account); +#endif resource_presence_t resource_presence = accounts_get_login_presence(account->name); contact_presence_t contact_presence = contact_presence_from_resource_presence(resource_presence); cons_show_login_success(account); |