1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Load keys and fingerprints for account on connect

This commit is contained in:
James Booth 2013-08-14 22:27:44 +01:00
parent bd1c139429
commit bdcc70f36d
3 changed files with 45 additions and 2 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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);