about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-08-15 00:01:01 +0100
committerJames Booth <boothj5@gmail.com>2013-08-15 00:01:01 +0100
commit41574ccdc62030cb9d24e6d923ad907754402834 (patch)
tree18a4480f4c1c80b9817f9c257af0058390fb7fba /src
parentbc82a7d0f804a5ad42ac41be6c41eddc3cf65582 (diff)
downloadprofani-tty-41574ccdc62030cb9d24e6d923ad907754402834.tar.gz
Generate privatekey
Diffstat (limited to 'src')
-rw-r--r--src/otr.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/otr.c b/src/otr.c
index 6b10e3be..44058cdf 100644
--- a/src/otr.c
+++ b/src/otr.c
@@ -39,34 +39,35 @@ otr_init(void)
 void
 otr_account_load(ProfAccount *account)
 {
-    gcry_error_t err = 0;
     cons_debug("otr_account_load()");
+
+    gcry_error_t err = 0;
     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;
+    if (!g_file_test(keys_filename->str, G_FILE_TEST_IS_REGULAR)) {
+        cons_debug("Private key not found, generating one");
+        err = otrl_privkey_generate(user_state, keys_filename->str, account->jid, "xmpp");
+        if (err != 0) {
+            cons_debug("Failed to generate private key");
+            g_string_free(keys_filename, TRUE);
+            return;
+        }
+        cons_debug("Generated private key");
     }
-
-    err = otrl_privkey_read_fingerprints(user_state, fp_filename->str, NULL, NULL);
+    
+    cons_debug("Loading private key");
+    err = otrl_privkey_read(user_state, keys_filename->str);  
     if (err != 0) {
-        cons_debug("Failed to load fingerprints");
+        cons_debug("Failed to load private key");
         g_string_free(keys_filename, TRUE);
-        g_string_free(fp_filename, TRUE);
         return;
     }
-
+    cons_debug("Loaded private key");
+    
     g_string_free(keys_filename, TRUE);
-    g_string_free(fp_filename, TRUE);
+    return;
 }