pgp stack ids

master
Tony Olagbaiye 3 years ago committed by bqv
parent 2bb69b68ff
commit 81352a26b7
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -329,7 +329,7 @@ struct t_channel *channel__new(struct t_account *account,
new_channel->omemo.bundle_requests = weechat_hashtable_new(64,
WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_POINTER, NULL, NULL);
new_channel->pgp.enabled = 1;
new_channel->pgp.id = NULL;
new_channel->pgp.ids = new std::remove_pointer<decltype(new_channel->pgp.ids)>::type;
new_channel->otr.enabled = 0;
new_channel->topic.value = NULL;
@ -846,8 +846,11 @@ void channel__free(struct t_account *account,
free(channel->id);
if (channel->name)
free(channel->name);
if (channel->pgp.id)
free(channel->pgp.id);
if (channel->pgp.ids)
{
delete channel->pgp.ids;
channel->pgp.ids = nullptr;
}
if (channel->topic.value)
free(channel->topic.value);
if (channel->topic.creator)
@ -1164,14 +1167,14 @@ int channel__send_message(struct t_account *account, struct t_channel *channel,
channel__set_transport(channel, CHANNEL_TRANSPORT_OMEMO, 0);
}
else if (channel->pgp.enabled && channel->pgp.id)
else if (channel->pgp.enabled && channel->pgp.ids)
{
xmpp_stanza_t *message__x = xmpp_stanza_new(account->context);
xmpp_stanza_set_name(message__x, "x");
xmpp_stanza_set_ns(message__x, "jabber:x:encrypted");
xmpp_stanza_t *message__x__text = xmpp_stanza_new(account->context);
char *ciphertext = pgp__encrypt(channel->buffer, account->pgp, account_pgp_keyid(account), channel->pgp.id, body);
char *ciphertext = pgp__encrypt(channel->buffer, account->pgp, account_pgp_keyid(account), std::vector(channel->pgp.ids->begin(), channel->pgp.ids->end()), body);
if (ciphertext)
xmpp_stanza_set_text(message__x__text, ciphertext);
else

@ -5,6 +5,8 @@
#pragma once
#include <ctime>
#include <unordered_set>
#include <string>
#define CHANNEL_MEMBERS_SPEAKING_LIMIT 128
@ -73,7 +75,7 @@ struct t_channel
} omemo;
struct {
int enabled;
char *id;
std::unordered_set<std::string> *ids;
} pgp;
struct {
int enabled;

@ -833,7 +833,7 @@ int command__pgp(const void *pointer, void *data,
{
keyid = argv_eol[1];
ptr_channel->pgp.id = strdup(keyid);
ptr_channel->pgp.ids->emplace(keyid);
}
ptr_channel->omemo.enabled = 0;
ptr_channel->pgp.enabled = 1;

@ -220,7 +220,7 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void
{
user->profile.pgp_id = pgp__verify(channel->buffer, account->pgp, signature->data());
if (channel->type != CHANNEL_TYPE_MUC)
channel->pgp.id = user->profile.pgp_id;
channel->pgp.ids->emplace(user->profile.pgp_id);
}
if (weechat_strcasecmp(role.data(), "none") == 0)
@ -253,7 +253,7 @@ int connection__presence_handler(xmpp_conn_t *conn, xmpp_stanza_t *stanza, void
{
user->profile.pgp_id = pgp__verify(channel->buffer, account->pgp, signature->data());
if (channel->type != CHANNEL_TYPE_MUC)
channel->pgp.id = user->profile.pgp_id;
channel->pgp.ids->emplace(user->profile.pgp_id);
}
if (user->profile.role)

@ -76,7 +76,7 @@ void pgp__free(struct t_pgp *pgp)
}
}
char *pgp__encrypt(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *source, const char *target, const char *message)
char *pgp__encrypt(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *source, std::vector<std::string>&& targets, const char *message)
{
std::string encrypted;
gpgme_key_t keys[3] = {NULL,NULL,NULL};
@ -99,9 +99,12 @@ char *pgp__encrypt(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *s
}
/* Encrypt data. */
err = gpgme_get_key(pgp->gpgme, target, &keys[0], false);
if (err) {
goto encrypt_finish;
for (const std::string& target : targets)
{
err = gpgme_get_key(pgp->gpgme, target.data(), &keys[0], false);
if (err) {
goto encrypt_finish;
}
}
err = gpgme_get_key(pgp->gpgme, source, &keys[1], false);
if (err) {

@ -5,6 +5,7 @@
#pragma once
#include <string>
#include <vector>
extern const char *PGP_ADVICE;
@ -20,7 +21,7 @@ void pgp__free(struct t_pgp *pgp);
char *pgp__decrypt(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *ciphertext);
char *pgp__encrypt(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *source, const char *target, const char *message);
char *pgp__encrypt(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *source, std::vector<std::string>&& target, const char *message);
char *pgp__verify(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *certificate);

Loading…
Cancel
Save