about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command/commands.c4
-rw-r--r--src/pgp/gpg.c29
-rw-r--r--src/pgp/gpg.h1
3 files changed, 32 insertions, 2 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 7167e26d..e2323ce6 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -4337,8 +4337,8 @@ cmd_pgp(ProfWin *window, const char * const command, gchar **args)
         }
 
         ProfAccount *account = accounts_get_account(jabber_get_account_name());
-        if (!account->pgp_keyid) {
-            ui_current_print_formatted_line('!', 0, "You must specify a PGP key ID for this account to start PGP encryption.");
+        if (!p_gpg_valid_key(account->pgp_keyid)) {
+            ui_current_print_formatted_line('!', 0, "You must specify a valid PGP key ID for this account to start PGP encryption.");
             account_free(account);
             return TRUE;
         }
diff --git a/src/pgp/gpg.c b/src/pgp/gpg.c
index 3e2cfe67..be35bb3a 100644
--- a/src/pgp/gpg.c
+++ b/src/pgp/gpg.c
@@ -281,6 +281,35 @@ p_gpg_free_key(ProfPGPKey *key)
 }
 
 gboolean
+p_gpg_valid_key(const char * const keyid)
+{
+    gpgme_ctx_t ctx;
+    gpgme_error_t error = gpgme_new(&ctx);
+    if (error) {
+        log_error("GPG: Failed to create gpgme context. %s %s", gpgme_strsource(error), gpgme_strerror(error));
+        return FALSE;
+    }
+
+    gpgme_key_t key = NULL;
+    error = gpgme_get_key(ctx, keyid, &key, 1);
+
+    if (error || key == NULL) {
+        log_error("GPG: Failed to get key. %s %s", gpgme_strsource(error), gpgme_strerror(error));
+        gpgme_release(ctx);
+        return FALSE;
+    }
+
+    if (key) {
+        gpgme_release(ctx);
+        gpgme_key_unref(key);
+        return TRUE;
+    }
+
+    gpgme_release(ctx);
+    return FALSE;
+}
+
+gboolean
 p_gpg_available(const char * const barejid)
 {
     char *fp = g_hash_table_lookup(fingerprints, barejid);
diff --git a/src/pgp/gpg.h b/src/pgp/gpg.h
index 77f14d1e..7b3a4433 100644
--- a/src/pgp/gpg.h
+++ b/src/pgp/gpg.h
@@ -48,6 +48,7 @@ void p_gpg_on_disconnect(void);
 GSList* p_gpg_list_keys(void);
 gboolean p_gpg_addkey(const char * const jid, const char * const keyid);
 GHashTable* p_gpg_fingerprints(void);
+gboolean p_gpg_valid_key(const char * const keyid);
 gboolean p_gpg_available(const char * const barejid);
 const char* p_gpg_libver(void);
 void p_gpg_free_key(ProfPGPKey *key);
ik.com> 2015-10-25 11:55:35 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2015-10-25 12:18:32 -0700 2273 - start expanding the type system' href='/akkartik/mu/commit/054dilated_reagent.cc?h=hlt&id=a796831f3e5697de7194607cfff3efddc588978a'>a796831f ^
1f7e3c05 ^
79eef536 ^
21c27706 ^
79eef536 ^
a796831f ^


































d5f89e0f ^
a796831f ^




4ad0f652 ^
a796831f ^


08cf048f ^
79eef536 ^
b74443e5 ^
eb4eecea ^
a17f9186 ^
79eef536 ^
a17f9186 ^
a796831f ^


ae256ea1 ^
f3760b0f ^
b69daf78 ^
795f5244 ^
a796831f ^
4f32f024 ^
a796831f ^



79eef536 ^
a796831f ^
a072f674 ^
eb4eecea ^
a072f674 ^

a796831f ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127