|
|
@ -23,7 +23,7 @@ void pgp__init(struct t_pgp **pgp)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
struct t_pgp *new_pgp;
|
|
|
|
struct t_pgp *new_pgp;
|
|
|
|
gpgme_error_t err;
|
|
|
|
gpgme_error_t err;
|
|
|
|
gpgme_data_t keydata;
|
|
|
|
//gpgme_data_t keydata;
|
|
|
|
|
|
|
|
|
|
|
|
gpgme_check_version(NULL);
|
|
|
|
gpgme_check_version(NULL);
|
|
|
|
|
|
|
|
|
|
|
@ -129,6 +129,10 @@ char *pgp__encrypt(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *s
|
|
|
|
result = strndup(encrypted.data() + strlen(PGP_MESSAGE_HEADER),
|
|
|
|
result = strndup(encrypted.data() + strlen(PGP_MESSAGE_HEADER),
|
|
|
|
encrypted.size() - strlen(PGP_MESSAGE_HEADER) - strlen(PGP_MESSAGE_FOOTER));
|
|
|
|
encrypted.size() - strlen(PGP_MESSAGE_HEADER) - strlen(PGP_MESSAGE_FOOTER));
|
|
|
|
encrypt_finish:
|
|
|
|
encrypt_finish:
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
weechat_printf(buffer, "[PGP]\t%s - %s",
|
|
|
|
|
|
|
|
gpgme_strsource(err), gpgme_strerror(err));
|
|
|
|
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -183,6 +187,10 @@ char *pgp__decrypt(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *c
|
|
|
|
|
|
|
|
|
|
|
|
result = strndup(decrypted.data(), decrypted.size());
|
|
|
|
result = strndup(decrypted.data(), decrypted.size());
|
|
|
|
decrypt_finish:
|
|
|
|
decrypt_finish:
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
weechat_printf(buffer, "[PGP]\t%s - %s",
|
|
|
|
|
|
|
|
gpgme_strsource(err), gpgme_strerror(err));
|
|
|
|
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -190,11 +198,8 @@ char *pgp__verify(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *ce
|
|
|
|
{
|
|
|
|
{
|
|
|
|
uint8_t * buf = NULL;
|
|
|
|
uint8_t * buf = NULL;
|
|
|
|
size_t buf_len = 0;
|
|
|
|
size_t buf_len = 0;
|
|
|
|
size_t sigcount = 0;
|
|
|
|
|
|
|
|
char * result = NULL;
|
|
|
|
char * result = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf_len = strlen(PGP_SIGNATURE_HEADER) + strlen(certificate) + strlen(PGP_SIGNATURE_FOOTER) + 1;
|
|
|
|
buf_len = strlen(PGP_SIGNATURE_HEADER) + strlen(certificate) + strlen(PGP_SIGNATURE_FOOTER) + 1;
|
|
|
|
buf = (uint8_t*)malloc(sizeof(char) * buf_len);
|
|
|
|
buf = (uint8_t*)malloc(sizeof(char) * buf_len);
|
|
|
|
buf_len = snprintf((char *)buf, buf_len, PGP_SIGNATURE_HEADER "%s" PGP_SIGNATURE_FOOTER, certificate);
|
|
|
|
buf_len = snprintf((char *)buf, buf_len, PGP_SIGNATURE_HEADER "%s" PGP_SIGNATURE_FOOTER, certificate);
|
|
|
@ -202,6 +207,7 @@ char *pgp__verify(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *ce
|
|
|
|
gpgme_verify_result_t vrf_result;
|
|
|
|
gpgme_verify_result_t vrf_result;
|
|
|
|
gpgme_error_t err;
|
|
|
|
gpgme_error_t err;
|
|
|
|
gpgme_data_t in, out;
|
|
|
|
gpgme_data_t in, out;
|
|
|
|
|
|
|
|
gpgme_key_t key;
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize input buffer. */
|
|
|
|
/* Initialize input buffer. */
|
|
|
|
err = gpgme_data_new_from_mem(&in, (char *)buf, buf_len, false);
|
|
|
|
err = gpgme_data_new_from_mem(&in, (char *)buf, buf_len, false);
|
|
|
@ -228,15 +234,23 @@ char *pgp__verify(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *ce
|
|
|
|
|
|
|
|
|
|
|
|
result = strdup(vrf_result->signatures->fpr);
|
|
|
|
result = strdup(vrf_result->signatures->fpr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err = gpgme_get_key(pgp->gpgme, result, &key, false);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
const char *keyids[2] = { result, nullptr };
|
|
|
|
|
|
|
|
err = gpgme_op_receive_keys(pgp->gpgme, keyids);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
verify_finish:
|
|
|
|
verify_finish:
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
weechat_printf(buffer, "[PGP]\t%s - %s",
|
|
|
|
|
|
|
|
gpgme_strsource(err), gpgme_strerror(err));
|
|
|
|
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *pgp__sign(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *source, const char *message)
|
|
|
|
char *pgp__sign(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *source, const char *message)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::string signature;
|
|
|
|
std::string signature;
|
|
|
|
uint8_t * buf = NULL;
|
|
|
|
|
|
|
|
size_t buf_len = 0;
|
|
|
|
|
|
|
|
char * result = NULL;
|
|
|
|
char * result = NULL;
|
|
|
|
int ret;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
|
@ -259,6 +273,7 @@ char *pgp__sign(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *sour
|
|
|
|
/* Include signature within key. */
|
|
|
|
/* Include signature within key. */
|
|
|
|
{
|
|
|
|
{
|
|
|
|
gpgme_keylist_mode_t kmode = gpgme_get_keylist_mode(pgp->gpgme);
|
|
|
|
gpgme_keylist_mode_t kmode = gpgme_get_keylist_mode(pgp->gpgme);
|
|
|
|
|
|
|
|
kmode |= GPGME_KEYLIST_MODE_LOCATE;
|
|
|
|
kmode |= GPGME_KEYLIST_MODE_SIGS;
|
|
|
|
kmode |= GPGME_KEYLIST_MODE_SIGS;
|
|
|
|
err = gpgme_set_keylist_mode(pgp->gpgme, kmode);
|
|
|
|
err = gpgme_set_keylist_mode(pgp->gpgme, kmode);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -301,5 +316,9 @@ char *pgp__sign(struct t_gui_buffer *buffer, struct t_pgp *pgp, const char *sour
|
|
|
|
result = strndup(signature.data() + strlen(PGP_SIGNATURE_HEADER),
|
|
|
|
result = strndup(signature.data() + strlen(PGP_SIGNATURE_HEADER),
|
|
|
|
signature.size() - strlen(PGP_SIGNATURE_HEADER) - strlen(PGP_SIGNATURE_FOOTER));
|
|
|
|
signature.size() - strlen(PGP_SIGNATURE_HEADER) - strlen(PGP_SIGNATURE_FOOTER));
|
|
|
|
sign_finish:
|
|
|
|
sign_finish:
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
weechat_printf(buffer, "[PGP]\t%s - %s",
|
|
|
|
|
|
|
|
gpgme_strsource(err), gpgme_strerror(err));
|
|
|
|
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|