krista@2947
|
1 |
// This file is under GNU General Public License 3.0
|
krista@2947
|
2 |
// see LICENSE.txt
|
krista@2947
|
3 |
|
krista@2947
|
4 |
#include "pEp_internal.h"
|
krista@2947
|
5 |
#include "dynamic_api.h"
|
krista@2947
|
6 |
#include "message_api.h"
|
krista@2947
|
7 |
|
krista@2947
|
8 |
#include <string.h>
|
krista@2947
|
9 |
#include <stdlib.h>
|
krista@2947
|
10 |
|
krista@2947
|
11 |
PEP_STATUS has_key_reset_been_sent(
|
krista@2947
|
12 |
PEP_SESSION session,
|
krista@2947
|
13 |
const char* user_id,
|
krista@2947
|
14 |
const char* revoked_fpr,
|
krista@2947
|
15 |
bool* contacted)
|
krista@2947
|
16 |
{
|
krista@2947
|
17 |
assert(session);
|
krista@2947
|
18 |
assert(contacted);
|
krista@2947
|
19 |
assert(user_id);
|
krista@2947
|
20 |
assert(revoked_fpr);
|
krista@2947
|
21 |
assert(!EMPTYSTR(user_id));
|
krista@2947
|
22 |
|
krista@2947
|
23 |
if (!session || !contacted || EMPTYSTR(revoked_fpr) || EMPTYSTR(user_id))
|
krista@2947
|
24 |
return PEP_ILLEGAL_VALUE;
|
krista@2947
|
25 |
|
krista@2947
|
26 |
*contacted = false;
|
krista@2947
|
27 |
|
krista@2947
|
28 |
char* alias_default = NULL;
|
krista@2947
|
29 |
|
krista@2947
|
30 |
PEP_STATUS status = get_userid_alias_default(session, user_id, &alias_default);
|
krista@2947
|
31 |
|
krista@2947
|
32 |
if (status == PEP_CANNOT_FIND_ALIAS || EMPTYSTR(alias_default)) {
|
krista@2947
|
33 |
free(alias_default);
|
krista@2947
|
34 |
alias_default = strdup(user_id);
|
krista@2947
|
35 |
}
|
krista@2947
|
36 |
|
krista@2947
|
37 |
sqlite3_reset(session->was_id_for_revoke_contacted);
|
krista@2947
|
38 |
sqlite3_bind_text(session->was_id_for_revoke_contacted, 1, revoked_fpr, -1,
|
krista@2947
|
39 |
SQLITE_STATIC);
|
krista@2947
|
40 |
sqlite3_bind_text(session->was_id_for_revoke_contacted, 2, user_id, -1,
|
krista@2947
|
41 |
SQLITE_STATIC);
|
krista@2947
|
42 |
int result = sqlite3_step(session->was_id_for_revoke_contacted);
|
krista@2947
|
43 |
switch (result) {
|
krista@2947
|
44 |
case SQLITE_ROW: {
|
krista@2947
|
45 |
*contacted = (sqlite3_column_int(session->was_id_for_revoke_contacted, 0) != 0);
|
krista@2947
|
46 |
break;
|
krista@2947
|
47 |
}
|
krista@2947
|
48 |
default:
|
krista@2947
|
49 |
sqlite3_reset(session->was_id_for_revoke_contacted);
|
krista@2947
|
50 |
free(alias_default);
|
krista@2947
|
51 |
return PEP_UNKNOWN_DB_ERROR;
|
krista@2947
|
52 |
}
|
krista@2947
|
53 |
|
krista@2947
|
54 |
sqlite3_reset(session->was_id_for_revoke_contacted);
|
krista@2947
|
55 |
return PEP_STATUS_OK;
|
krista@2947
|
56 |
}
|
krista@2947
|
57 |
|
krista@2947
|
58 |
//static const char *sql_set_revoke_contact_as_notified =
|
krista@2947
|
59 |
// "insert or replace into revocation_contact_list(fpr, contact_id) values (?1, ?2) ;";
|
krista@2947
|
60 |
|
krista@2947
|
61 |
PEP_STATUS set_reset_contact_notified(
|
krista@2947
|
62 |
PEP_SESSION session,
|
krista@2947
|
63 |
const char* revoke_fpr,
|
krista@2947
|
64 |
const char* contact_id
|
krista@2947
|
65 |
)
|
krista@2947
|
66 |
{
|
krista@2947
|
67 |
PEP_STATUS status = PEP_STATUS_OK;
|
krista@2947
|
68 |
|
krista@2947
|
69 |
assert(session && !EMPTYSTR(revoke_fpr) && !EMPTYSTR(contact_id));
|
krista@2947
|
70 |
|
krista@2947
|
71 |
if (!session || EMPTYSTR(revoke_fpr) || EMPTYSTR(contact_id))
|
krista@2947
|
72 |
return PEP_ILLEGAL_VALUE;
|
krista@2947
|
73 |
|
krista@2947
|
74 |
sqlite3_reset(session->set_revoke_contact_as_notified);
|
krista@2947
|
75 |
sqlite3_bind_text(session->set_revoke_contact_as_notified, 1, revoke_fpr, -1,
|
krista@2947
|
76 |
SQLITE_STATIC);
|
krista@2947
|
77 |
sqlite3_bind_text(session->set_revoke_contact_as_notified, 2, contact_id, -1,
|
krista@2947
|
78 |
SQLITE_STATIC);
|
krista@2947
|
79 |
|
krista@2947
|
80 |
int result;
|
krista@2947
|
81 |
|
krista@2947
|
82 |
result = sqlite3_step(session->set_revoke_contact_as_notified);
|
krista@2947
|
83 |
switch (result) {
|
krista@2947
|
84 |
case SQLITE_DONE:
|
krista@2947
|
85 |
status = PEP_STATUS_OK;
|
krista@2947
|
86 |
break;
|
krista@2947
|
87 |
|
krista@2947
|
88 |
default:
|
krista@2947
|
89 |
status = PEP_UNKNOWN_DB_ERROR;
|
krista@2947
|
90 |
}
|
krista@2947
|
91 |
|
krista@2947
|
92 |
sqlite3_reset(session->set_revoke_contact_as_notified);
|
krista@2947
|
93 |
return status;
|
krista@2947
|
94 |
}
|
krista@2947
|
95 |
|
krista@2947
|
96 |
|
krista@2947
|
97 |
PEP_STATUS receive_key_reset(PEP_SESSION session,
|
krista@2947
|
98 |
message* reset_msg) {
|
krista@2947
|
99 |
|
krista@2947
|
100 |
if (!session || !reset_msg)
|
krista@2947
|
101 |
return PEP_ILLEGAL_VALUE;
|
krista@2947
|
102 |
|
krista@2947
|
103 |
pEp_identity* sender_id = reset_msg->from;
|
krista@2947
|
104 |
|
krista@2947
|
105 |
if (!sender_id)
|
krista@2947
|
106 |
return PEP_MALFORMED_KEY_RESET_MSG;
|
krista@2947
|
107 |
|
krista@2947
|
108 |
PEP_STATUS status = update_identity(session, sender_id);
|
krista@2947
|
109 |
if (!sender_id->user_id)
|
krista@2947
|
110 |
return PEP_UNKNOWN_ERROR;
|
krista@2947
|
111 |
|
krista@2947
|
112 |
if (is_me(session, sender_id))
|
krista@2947
|
113 |
return PEP_ILLEGAL_VALUE;
|
krista@2947
|
114 |
|
krista@2947
|
115 |
if (!reset_msg->longmsg || strncmp(reset_msg->longmsg, "OLD: ", 5) != 0)
|
krista@2947
|
116 |
return PEP_MALFORMED_KEY_RESET_MSG;
|
krista@2947
|
117 |
|
krista@2947
|
118 |
status = PEP_STATUS_OK;
|
krista@2947
|
119 |
char* old_fpr = NULL;
|
krista@2947
|
120 |
char* new_fpr = NULL;
|
krista@2947
|
121 |
|
krista@2947
|
122 |
stringlist_t* keylist = NULL;
|
krista@2947
|
123 |
pEp_identity* temp_ident = identity_dup(sender_id);
|
krista@2947
|
124 |
if (!temp_ident) {
|
krista@2947
|
125 |
status = PEP_OUT_OF_MEMORY;
|
krista@2947
|
126 |
goto pep_free;
|
krista@2947
|
127 |
}
|
krista@2947
|
128 |
|
krista@2947
|
129 |
char* rest = NULL;
|
krista@2947
|
130 |
char* p = strtok_r(reset_msg->longmsg, "\r\n", &rest);
|
krista@2947
|
131 |
if (!EMPTYSTR(p + 5))
|
krista@2947
|
132 |
old_fpr = strdup(p + 5);
|
krista@2947
|
133 |
else {
|
krista@2947
|
134 |
status = PEP_MALFORMED_KEY_RESET_MSG;
|
krista@2947
|
135 |
goto pep_free;
|
krista@2947
|
136 |
}
|
krista@2947
|
137 |
|
krista@2947
|
138 |
bool own_key = false;
|
krista@2947
|
139 |
status = is_own_key(session, old_fpr, &own_key);
|
krista@2947
|
140 |
|
krista@2947
|
141 |
if (own_key) {
|
krista@2947
|
142 |
// Nope, no one can make us our own default. If we want to do that,
|
krista@2947
|
143 |
// that's keysync, NOT key reset.
|
krista@2947
|
144 |
status = PEP_ILLEGAL_VALUE;
|
krista@2947
|
145 |
goto pep_free;
|
krista@2947
|
146 |
}
|
krista@2947
|
147 |
|
krista@2947
|
148 |
p = strtok_r(NULL, "\r\n", &rest);
|
krista@2947
|
149 |
if (strncmp(p, "NEW: ", 5) != 0 || EMPTYSTR(p + 5)) {
|
krista@2947
|
150 |
status = PEP_MALFORMED_KEY_RESET_MSG;
|
krista@2947
|
151 |
goto pep_free;
|
krista@2947
|
152 |
}
|
krista@2947
|
153 |
|
krista@2947
|
154 |
new_fpr = strdup(p + 5);
|
krista@2947
|
155 |
|
krista@2947
|
156 |
// Reset the original key
|
krista@2947
|
157 |
status = key_reset(session, old_fpr, temp_ident);
|
krista@2947
|
158 |
if (status != PEP_STATUS_OK)
|
krista@2947
|
159 |
goto pep_free;
|
krista@2947
|
160 |
|
krista@2947
|
161 |
status = find_keys(session, new_fpr, &keylist);
|
krista@2947
|
162 |
if (status != PEP_STATUS_OK)
|
krista@2947
|
163 |
goto pep_free;
|
krista@2947
|
164 |
|
krista@2947
|
165 |
if (!keylist) {
|
krista@2947
|
166 |
status = PEP_KEY_NOT_FOUND;
|
krista@2947
|
167 |
goto pep_free;
|
krista@2947
|
168 |
}
|
krista@2947
|
169 |
|
krista@2947
|
170 |
// alright, we've checked as best we can. Let's set that baby.
|
krista@2947
|
171 |
sender_id->fpr = new_fpr;
|
krista@2947
|
172 |
|
krista@2947
|
173 |
// This only sets as the default, does NOT TRUST IN ANY WAY
|
krista@2947
|
174 |
sender_id->comm_type = sender_id->comm_type & (~PEP_ct_confirmed);
|
krista@2947
|
175 |
status = set_identity(session, sender_id);
|
krista@2947
|
176 |
|
krista@2947
|
177 |
sender_id->fpr = NULL; // ownership for free
|
krista@2947
|
178 |
pep_free:
|
krista@2947
|
179 |
free_stringlist(keylist);
|
krista@2947
|
180 |
free(old_fpr);
|
krista@2947
|
181 |
free(new_fpr);
|
krista@2947
|
182 |
free_identity(temp_ident);
|
krista@2947
|
183 |
return status;
|
krista@2947
|
184 |
}
|
krista@2947
|
185 |
|
krista@2947
|
186 |
PEP_STATUS create_standalone_key_reset_message(PEP_SESSION session,
|
krista@2947
|
187 |
message** dst,
|
krista@2947
|
188 |
pEp_identity* recip,
|
krista@2947
|
189 |
const char* old_fpr,
|
krista@2947
|
190 |
const char* new_fpr) {
|
krista@2947
|
191 |
|
krista@2947
|
192 |
if (!dst || !recip->user_id || !recip->address)
|
krista@2947
|
193 |
return PEP_ILLEGAL_VALUE;
|
krista@2947
|
194 |
|
krista@2947
|
195 |
if (!old_fpr || !new_fpr)
|
krista@2947
|
196 |
return PEP_ILLEGAL_VALUE;
|
krista@2947
|
197 |
|
krista@2947
|
198 |
*dst = NULL;
|
krista@2947
|
199 |
// Get own identity user has corresponded with
|
krista@2947
|
200 |
pEp_identity* own_identity = NULL;
|
krista@2947
|
201 |
|
krista@2947
|
202 |
PEP_STATUS status = get_own_ident_for_contact_id(session,
|
krista@2947
|
203 |
recip,
|
krista@2947
|
204 |
&own_identity);
|
krista@2947
|
205 |
if (status != PEP_STATUS_OK)
|
krista@2947
|
206 |
return status;
|
krista@2947
|
207 |
|
krista@2947
|
208 |
message* reset_message = new_message(PEP_dir_outgoing);
|
krista@2947
|
209 |
reset_message->from = own_identity;
|
krista@2947
|
210 |
reset_message->to = new_identity_list(identity_dup(recip)); // ?
|
krista@2947
|
211 |
|
krista@2947
|
212 |
const char* oldtag = "OLD: ";
|
krista@2947
|
213 |
const char* newtag = "\nNEW: ";
|
krista@2947
|
214 |
const size_t taglens = 11;
|
krista@2947
|
215 |
size_t full_len = taglens + strlen(old_fpr) + strlen(new_fpr) + 2; // \n and \0
|
krista@2947
|
216 |
char* longmsg = calloc(full_len, 1);
|
krista@2947
|
217 |
strlcpy(longmsg, oldtag, full_len);
|
krista@2947
|
218 |
strlcat(longmsg, old_fpr, full_len);
|
krista@2947
|
219 |
strlcat(longmsg, newtag, full_len);
|
krista@2947
|
220 |
strlcat(longmsg, new_fpr, full_len);
|
krista@2947
|
221 |
strlcat(longmsg, "\n", full_len);
|
krista@2947
|
222 |
reset_message->longmsg = longmsg;
|
krista@2947
|
223 |
reset_message->shortmsg = strdup("Key reset");
|
krista@2947
|
224 |
|
krista@2947
|
225 |
message* output_msg = NULL;
|
krista@2947
|
226 |
|
krista@2947
|
227 |
status = encrypt_message(session, reset_message, NULL,
|
krista@2947
|
228 |
&output_msg, PEP_enc_PGP_MIME,
|
krista@2947
|
229 |
PEP_encrypt_flag_key_reset_only);
|
krista@2947
|
230 |
|
krista@2947
|
231 |
if (status == PEP_STATUS_OK)
|
krista@2947
|
232 |
*dst = output_msg;
|
krista@2947
|
233 |
|
krista@2947
|
234 |
free_message(reset_message);
|
krista@2947
|
235 |
return status;
|
krista@2947
|
236 |
}
|
krista@2947
|
237 |
|
krista@2947
|
238 |
PEP_STATUS send_key_reset_to_recents(PEP_SESSION session,
|
krista@2947
|
239 |
const char* old_fpr,
|
krista@2947
|
240 |
const char* new_fpr) {
|
krista@2947
|
241 |
assert(old_fpr);
|
krista@2947
|
242 |
assert(new_fpr);
|
krista@2947
|
243 |
assert(session);
|
krista@2947
|
244 |
assert(session->messageToSend || session->sync_session->messageToSend);
|
krista@2947
|
245 |
|
krista@2947
|
246 |
if (!session || !old_fpr || !new_fpr)
|
krista@2947
|
247 |
return PEP_ILLEGAL_VALUE;
|
krista@2947
|
248 |
|
krista@2947
|
249 |
messageToSend_t send_cb = send_cb = session->messageToSend;
|
krista@2947
|
250 |
void* sync_obj = session->sync_obj;
|
krista@2947
|
251 |
if (!send_cb) {
|
krista@2947
|
252 |
send_cb = session->sync_session->messageToSend;
|
krista@2947
|
253 |
sync_obj = session->sync_session->sync_obj;
|
krista@2947
|
254 |
}
|
krista@2947
|
255 |
if (!send_cb)
|
krista@2947
|
256 |
return PEP_SYNC_NO_MESSAGE_SEND_CALLBACK;
|
krista@2947
|
257 |
|
krista@2947
|
258 |
identity_list* recent_contacts = NULL;
|
krista@2947
|
259 |
message* reset_msg = NULL;
|
krista@2947
|
260 |
|
krista@2947
|
261 |
PEP_STATUS status = get_last_contacted(session, &recent_contacts);
|
krista@2947
|
262 |
|
krista@2947
|
263 |
if (status != PEP_STATUS_OK)
|
krista@2947
|
264 |
goto pep_free;
|
krista@2947
|
265 |
|
krista@2947
|
266 |
identity_list* curr_id_ptr = recent_contacts;
|
krista@2947
|
267 |
|
krista@2947
|
268 |
for (curr_id_ptr = recent_contacts; curr_id_ptr; curr_id_ptr = curr_id_ptr->next) {
|
krista@2947
|
269 |
pEp_identity* curr_id = curr_id_ptr->ident;
|
krista@2947
|
270 |
|
krista@2947
|
271 |
if (!curr_id)
|
krista@2947
|
272 |
break;
|
krista@2947
|
273 |
|
krista@2947
|
274 |
const char* user_id = curr_id->user_id;
|
krista@2947
|
275 |
|
krista@2947
|
276 |
// Should be impossible, but?
|
krista@2947
|
277 |
if (!user_id)
|
krista@2947
|
278 |
continue;
|
krista@2947
|
279 |
|
krista@2947
|
280 |
// Check if it's us - if so, pointless...
|
krista@2947
|
281 |
if (is_me(session, curr_id))
|
krista@2947
|
282 |
continue;
|
krista@2947
|
283 |
|
krista@2947
|
284 |
// Check if they've already been told - this shouldn't be the case, but...
|
krista@2947
|
285 |
bool contacted = false;
|
krista@2947
|
286 |
status = has_key_reset_been_sent(session, user_id, old_fpr, &contacted);
|
krista@2947
|
287 |
if (status != PEP_STATUS_OK)
|
krista@2947
|
288 |
goto pep_free;
|
krista@2947
|
289 |
|
krista@2947
|
290 |
if (contacted)
|
krista@2947
|
291 |
continue;
|
krista@2947
|
292 |
|
krista@2947
|
293 |
// if not, make em a message
|
krista@2947
|
294 |
reset_msg = NULL;
|
krista@2947
|
295 |
|
krista@2947
|
296 |
status = create_standalone_key_reset_message(session,
|
krista@2947
|
297 |
&reset_msg,
|
krista@2947
|
298 |
curr_id,
|
krista@2947
|
299 |
old_fpr,
|
krista@2947
|
300 |
new_fpr);
|
krista@2947
|
301 |
|
krista@2947
|
302 |
if (status == PEP_CANNOT_FIND_IDENTITY) { // this is ok, just means we never mailed them
|
krista@2947
|
303 |
status = PEP_STATUS_OK;
|
krista@2947
|
304 |
continue;
|
krista@2947
|
305 |
}
|
krista@2947
|
306 |
|
krista@2947
|
307 |
if (status != PEP_STATUS_OK) {
|
krista@2947
|
308 |
free(reset_msg);
|
krista@2947
|
309 |
goto pep_free;
|
krista@2947
|
310 |
}
|
krista@2947
|
311 |
|
krista@2947
|
312 |
// insert into queue
|
krista@2947
|
313 |
status = send_cb(sync_obj, reset_msg);
|
krista@2947
|
314 |
|
krista@2947
|
315 |
if (status != PEP_STATUS_OK) {
|
krista@2947
|
316 |
free(reset_msg);
|
krista@2947
|
317 |
goto pep_free;
|
krista@2947
|
318 |
}
|
krista@2947
|
319 |
|
krista@2947
|
320 |
// Put into notified DB
|
krista@2947
|
321 |
status = set_reset_contact_notified(session, old_fpr, user_id);
|
krista@2947
|
322 |
if (status != PEP_STATUS_OK)
|
krista@2947
|
323 |
goto pep_free;
|
krista@2947
|
324 |
}
|
krista@2947
|
325 |
|
krista@2947
|
326 |
pep_free:
|
krista@2947
|
327 |
free_identity_list(recent_contacts);
|
krista@2947
|
328 |
return status;
|
krista@2947
|
329 |
}
|
krista@2947
|
330 |
|
krista@2947
|
331 |
DYNAMIC_API PEP_STATUS key_reset(
|
krista@2947
|
332 |
PEP_SESSION session,
|
krista@2947
|
333 |
const char* key_id,
|
krista@2947
|
334 |
pEp_identity* ident
|
krista@2947
|
335 |
)
|
krista@2947
|
336 |
{
|
krista@2947
|
337 |
if (!session)
|
krista@2947
|
338 |
return PEP_ILLEGAL_VALUE;
|
krista@2947
|
339 |
|
krista@2947
|
340 |
PEP_STATUS status = PEP_STATUS_OK;
|
krista@2947
|
341 |
|
krista@2947
|
342 |
char* fpr_copy = NULL;
|
krista@2947
|
343 |
char* own_id = NULL;
|
krista@2947
|
344 |
char* new_key = NULL;
|
krista@2947
|
345 |
identity_list* key_idents = NULL;
|
krista@2947
|
346 |
stringlist_t* keys = NULL;
|
krista@2947
|
347 |
|
krista@2947
|
348 |
if (!EMPTYSTR(key_id)) {
|
krista@2947
|
349 |
fpr_copy = strdup(key_id);
|
krista@2947
|
350 |
if (!fpr_copy)
|
krista@2947
|
351 |
return PEP_OUT_OF_MEMORY;
|
krista@2947
|
352 |
}
|
krista@2947
|
353 |
|
krista@2947
|
354 |
if (!ident) {
|
krista@2947
|
355 |
// Get list of own identities
|
krista@2947
|
356 |
status = get_default_own_userid(session, &own_id);
|
krista@2947
|
357 |
if (status != PEP_STATUS_OK)
|
krista@2947
|
358 |
goto pep_free;
|
krista@2947
|
359 |
|
krista@2947
|
360 |
if (EMPTYSTR(fpr_copy)) {
|
krista@2947
|
361 |
status = get_all_keys_for_user(session, own_id, &keys);
|
krista@2947
|
362 |
if (status == PEP_STATUS_OK) {
|
krista@2947
|
363 |
stringlist_t* curr_key;
|
krista@2947
|
364 |
for (curr_key = keys; curr_key && curr_key->value; curr_key = curr_key->next) {
|
krista@2947
|
365 |
status = key_reset(session, curr_key->value, NULL);
|
krista@2947
|
366 |
if (status != PEP_STATUS_OK)
|
krista@2947
|
367 |
break;
|
krista@2947
|
368 |
}
|
krista@2947
|
369 |
}
|
krista@2947
|
370 |
goto pep_free;
|
krista@2947
|
371 |
} // otherwise, we have a specific fpr to process
|
krista@2947
|
372 |
|
krista@2947
|
373 |
// fpr_copy exists, so... let's go.
|
krista@2947
|
374 |
// Process own identities with this fpr
|
krista@2947
|
375 |
status = get_identities_by_main_key_id(session, fpr_copy, &key_idents);
|
krista@2947
|
376 |
|
krista@2947
|
377 |
if (status == PEP_STATUS_OK) {
|
krista@2947
|
378 |
// have ident list, or should
|
krista@2947
|
379 |
identity_list* curr_ident;
|
krista@2947
|
380 |
for (curr_ident = key_idents; curr_ident && curr_ident->ident;
|
krista@2947
|
381 |
curr_ident = curr_ident->next) {
|
krista@2947
|
382 |
pEp_identity* this_identity = curr_ident->ident;
|
krista@2947
|
383 |
status = key_reset(session, fpr_copy, this_identity);
|
krista@2947
|
384 |
if (status != PEP_STATUS_OK)
|
krista@2947
|
385 |
break;
|
krista@2947
|
386 |
}
|
krista@2947
|
387 |
}
|
krista@2947
|
388 |
goto pep_free;
|
krista@2947
|
389 |
}
|
krista@2947
|
390 |
else { // an identity was specified.
|
krista@2947
|
391 |
if (is_me(session, ident)) {
|
krista@2947
|
392 |
// FIXME: make sure this IS our fpr?
|
krista@2947
|
393 |
|
krista@2947
|
394 |
// If it got sent in with an empty fpr...
|
krista@2947
|
395 |
if (EMPTYSTR(fpr_copy)) {
|
krista@2947
|
396 |
//
|
krista@2947
|
397 |
// if (!EMPTYSTR(ident->fpr))
|
krista@2947
|
398 |
// fpr_copy = strdup(ident->fpr);
|
krista@2947
|
399 |
status = _myself(session, ident, false, true);
|
krista@2947
|
400 |
if (status == PEP_STATUS_OK && ident->fpr)
|
krista@2947
|
401 |
fpr_copy = strdup(ident->fpr);
|
krista@2947
|
402 |
else {
|
krista@2947
|
403 |
// last resort?
|
krista@2947
|
404 |
// Get list of own identities
|
krista@2947
|
405 |
char* own_id = NULL;
|
krista@2947
|
406 |
status = get_default_own_userid(session, &own_id);
|
krista@2947
|
407 |
if (status == PEP_STATUS_OK)
|
krista@2947
|
408 |
status = get_user_default_key(session, own_id, &fpr_copy);
|
krista@2947
|
409 |
if (status != PEP_STATUS_OK || EMPTYSTR(fpr_copy)) {
|
krista@2947
|
410 |
free(own_id);
|
krista@2947
|
411 |
return (status == PEP_STATUS_OK ? PEP_KEY_NOT_FOUND : status);
|
krista@2947
|
412 |
}
|
krista@2947
|
413 |
}
|
krista@2947
|
414 |
}
|
krista@2947
|
415 |
|
krista@2947
|
416 |
free(ident->fpr);
|
krista@2947
|
417 |
ident->fpr = fpr_copy;
|
krista@2947
|
418 |
// Create revocation
|
krista@2947
|
419 |
status = revoke_key(session, fpr_copy, NULL);
|
krista@2947
|
420 |
// generate new key
|
krista@2947
|
421 |
if (status == PEP_STATUS_OK) {
|
krista@2947
|
422 |
ident->fpr = NULL;
|
krista@2947
|
423 |
status = generate_keypair(session, ident);
|
krista@2947
|
424 |
}
|
krista@2947
|
425 |
if (status == PEP_STATUS_OK) {
|
krista@2947
|
426 |
new_key = strdup(ident->fpr);
|
krista@2947
|
427 |
status = set_own_key(session, ident, new_key);
|
krista@2947
|
428 |
}
|
krista@2947
|
429 |
// mistrust fpr from trust
|
krista@2947
|
430 |
ident->fpr = fpr_copy;
|
krista@2947
|
431 |
|
krista@2947
|
432 |
ident->comm_type = PEP_ct_mistrusted;
|
krista@2947
|
433 |
status = set_trust(session, ident);
|
krista@2947
|
434 |
ident->fpr = NULL;
|
krista@2947
|
435 |
|
krista@2947
|
436 |
// Done with old use of ident.
|
krista@2947
|
437 |
if (status == PEP_STATUS_OK) {
|
krista@2947
|
438 |
// Update fpr for outgoing
|
krista@2947
|
439 |
status = myself(session, ident);
|
krista@2947
|
440 |
}
|
krista@2947
|
441 |
|
krista@2947
|
442 |
if (status == PEP_STATUS_OK)
|
krista@2947
|
443 |
// cascade that mistrust for anyone using this key
|
krista@2947
|
444 |
status = mark_as_compromised(session, fpr_copy);
|
krista@2947
|
445 |
if (status == PEP_STATUS_OK)
|
krista@2947
|
446 |
status = remove_fpr_as_default(session, fpr_copy);
|
krista@2947
|
447 |
if (status == PEP_STATUS_OK)
|
krista@2947
|
448 |
status = add_mistrusted_key(session, fpr_copy);
|
krista@2947
|
449 |
// add to revocation list
|
krista@2947
|
450 |
if (status == PEP_STATUS_OK)
|
krista@2947
|
451 |
status = set_revoked(session, fpr_copy, new_key, time(NULL));
|
krista@2947
|
452 |
// for all active communication partners:
|
krista@2947
|
453 |
// active_send revocation
|
krista@2947
|
454 |
if (status == PEP_STATUS_OK)
|
krista@2947
|
455 |
status = send_key_reset_to_recents(session, fpr_copy, new_key);
|
krista@2947
|
456 |
|
krista@2947
|
457 |
}
|
krista@2947
|
458 |
else { // not is_me
|
krista@2947
|
459 |
// remove fpr from all identities
|
krista@2947
|
460 |
// remove fpr from all users
|
krista@2947
|
461 |
if (status == PEP_STATUS_OK)
|
krista@2947
|
462 |
status = remove_fpr_as_default(session, fpr_copy);
|
krista@2947
|
463 |
// delete key from DB
|
krista@2947
|
464 |
if (status == PEP_STATUS_OK) {};
|
krista@2947
|
465 |
// status = delete_keypair(session, fpr_copy);
|
krista@2947
|
466 |
// N.B. If this key is being replaced by something else, it
|
krista@2947
|
467 |
// is done outside of this function.
|
krista@2947
|
468 |
}
|
krista@2947
|
469 |
}
|
krista@2947
|
470 |
|
krista@2947
|
471 |
pep_free:
|
krista@2947
|
472 |
free(fpr_copy);
|
krista@2947
|
473 |
free(own_id);
|
krista@2947
|
474 |
free_identity_list(key_idents);
|
krista@2947
|
475 |
free_stringlist(keys);
|
krista@2947
|
476 |
free(new_key);
|
krista@2947
|
477 |
return status;
|
krista@2947
|
478 |
}
|