Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/jabglue.c @ 1043:ebbde723614b
Store contacts PGP keys
Contacts PGP keys are retrieved from presence/message signatures;
they're displayed with /info.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 26 Nov 2006 17:08:21 +0100 |
parents | 8a395c2cafc4 |
children | 52cfe9bf9840 |
comparison
equal
deleted
inserted
replaced
1042:8a395c2cafc4 | 1043:ebbde723614b |
---|---|
1400 else | 1400 else |
1401 scr_LogPrint(LPRINT_LOGNORM, | 1401 scr_LogPrint(LPRINT_LOGNORM, |
1402 "Warning: you're not connected to the server."); | 1402 "Warning: you're not connected to the server."); |
1403 } | 1403 } |
1404 | 1404 |
1405 // check_signature(barejid, resourcename, xmldata, text) | |
1406 // Verify the signature (in xmldata) of "text" for the contact | |
1407 // barejid/resourcename. | |
1408 // xmldata is the 'jabber:x:signed' stanza. | |
1409 // If the key id is found, the contact's PGP data are updated. | |
1410 static void check_signature(const char *barejid, const char *rname, | |
1411 xmlnode xmldata, const char *text) | |
1412 { | |
1413 #ifdef HAVE_GPGME | |
1414 char *p, *key; | |
1415 GSList *sl_buddy; | |
1416 struct pgp_data *res_pgpdata; | |
1417 gpgme_sigsum_t sigsum; | |
1418 | |
1419 // All parameters must be valid | |
1420 if (!(xmldata && barejid && rname && text && *text)) | |
1421 return; | |
1422 | |
1423 if (!gpg_enabled()) | |
1424 return; | |
1425 | |
1426 // Get the resource PGP data structure | |
1427 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER); | |
1428 if (!sl_buddy) | |
1429 return; | |
1430 res_pgpdata = buddy_resource_pgp(sl_buddy->data, rname); | |
1431 if (!res_pgpdata) | |
1432 return; | |
1433 | |
1434 p = xmlnode_get_name(xmldata); | |
1435 if (!p || strcmp(p, "x")) | |
1436 return; // We expect "<x xmlns='jabber:x:signed'>" | |
1437 | |
1438 // Get signature | |
1439 p = xmlnode_get_data(xmldata); | |
1440 if (!p) | |
1441 return; | |
1442 | |
1443 key = gpg_verify(p, text, &sigsum); | |
1444 if (key) { | |
1445 g_free(res_pgpdata->sign_keyid); | |
1446 res_pgpdata->sign_keyid = key; | |
1447 res_pgpdata->last_sigsum = sigsum; | |
1448 } | |
1449 #endif | |
1450 } | |
1451 | |
1405 static void gotmessage(char *type, const char *from, const char *body, | 1452 static void gotmessage(char *type, const char *from, const char *body, |
1406 const char *enc, time_t timestamp) | 1453 const char *enc, time_t timestamp, |
1454 xmlnode xmldata_signed) | |
1407 { | 1455 { |
1408 char *jid; | 1456 char *jid; |
1409 const char *rname, *s; | 1457 const char *rname, *s; |
1410 char *decrypted = NULL; | 1458 char *decrypted = NULL; |
1459 /* bool sigchecked = FALSE; */ | |
1411 | 1460 |
1412 jid = jidtodisp(from); | 1461 jid = jidtodisp(from); |
1413 | 1462 |
1414 rname = strchr(from, JID_RESOURCE_SEPARATOR); | 1463 rname = strchr(from, JID_RESOURCE_SEPARATOR); |
1415 if (rname) rname++; | 1464 if (rname) rname++; |
1416 | 1465 |
1417 #ifdef HAVE_GPGME | 1466 #ifdef HAVE_GPGME |
1418 if (enc && gpg_enabled()) { | 1467 if (enc && gpg_enabled()) { |
1419 decrypted = gpg_decrypt(enc); | 1468 decrypted = gpg_decrypt(enc); |
1420 if (decrypted) | 1469 if (decrypted) { |
1421 body = decrypted; | 1470 body = decrypted; |
1422 } | 1471 /* |
1472 if (xmldata_signed) { | |
1473 check_signature(jid, rname, xmldata_signed, decrypted); | |
1474 sigchecked = TRUE; | |
1475 } | |
1476 */ | |
1477 } | |
1478 } | |
1479 // Check signature of an unencrypted message | |
1480 if (xmldata_signed /* && !sigchecked */ && gpg_enabled()) | |
1481 check_signature(jid, rname, xmldata_signed, decrypted); | |
1423 #endif | 1482 #endif |
1424 | 1483 |
1425 // Check for unexpected groupchat messages | 1484 // Check for unexpected groupchat messages |
1426 // If we receive a groupchat message from a room we're not a member of, | 1485 // If we receive a groupchat message from a room we're not a member of, |
1427 // this is probably a server issue and the best we can do is to send | 1486 // this is probably a server issue and the best we can do is to send |
1960 ust, ustmsg, timestamp, bpprio); | 2019 ust, ustmsg, timestamp, bpprio); |
1961 } else { | 2020 } else { |
1962 // Not a MUC message, so this is a regular buddy... | 2021 // Not a MUC message, so this is a regular buddy... |
1963 // Call hk_statuschange() if status has changed or if the | 2022 // Call hk_statuschange() if status has changed or if the |
1964 // status message is different | 2023 // status message is different |
1965 const char *m = roster_getstatusmsg(r, rname); | 2024 const char *m; |
2025 m = roster_getstatusmsg(r, rname); | |
1966 if ((ust != roster_getstatus(r, rname)) || | 2026 if ((ust != roster_getstatus(r, rname)) || |
1967 (!ustmsg && m && m[0]) || (ustmsg && (!m || strcmp(ustmsg, m)))) | 2027 (!ustmsg && m && m[0]) || (ustmsg && (!m || strcmp(ustmsg, m)))) |
1968 hk_statuschange(r, rname, bpprio, timestamp, ust, ustmsg); | 2028 hk_statuschange(r, rname, bpprio, timestamp, ust, ustmsg); |
2029 // Presence signature processing | |
2030 check_signature(r, rname, xml_get_xmlns(xmldata, NS_SIGNED), ustmsg); | |
1969 } | 2031 } |
1970 | 2032 |
1971 g_free(r); | 2033 g_free(r); |
1972 } | 2034 } |
1973 | 2035 |
2042 // we probe it again. | 2104 // we probe it again. |
2043 chatstates_reset_probed(from); | 2105 chatstates_reset_probed(from); |
2044 #endif | 2106 #endif |
2045 } | 2107 } |
2046 if (from && body) | 2108 if (from && body) |
2047 gotmessage(type, from, body, enc, timestamp); | 2109 gotmessage(type, from, body, enc, timestamp, |
2110 xml_get_xmlns(xmldata, NS_SIGNED)); | |
2048 g_free(tmp); | 2111 g_free(tmp); |
2049 } | 2112 } |
2050 | 2113 |
2051 void handle_state_events(char *from, xmlnode xmldata) | 2114 void handle_state_events(char *from, xmlnode xmldata) |
2052 { | 2115 { |