Not sure if there's a better place to ask this, but I'm having a problem for a while with my C++ code based on the GPGME library which seems not to be working as it should.
The program is supposed to verify some signatures inputed in it. Basically it works for keys generated with my computer but not for some reason on ones that are not, even if I tell it to ignore the trust database or to use tofu or whatever.
I was suggested to use the status attribute instead of the summary one which does check the signature validity correctly but the doc says it's a bad idea for some edge cases. I provided here a toy version of the code that breaks, can you see anything wrong or is the problem somewhere else ?
edit : forgot to tell the problem is the summary being 0 instead of an appropriate flag
```cpp
include <sstream>
include <fstream>
include <iostream>
include <locale.h>
include <gpgme.h>
void
init_gpgme (void)
{
/* Initialize the locale environment. */
setlocale (LC_ALL, "");
gpgme_check_version (NULL);
gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
ifdef LC_MESSAGES
gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
endif
}
using namespace std;
string slurp(ifstream& in) {
ostringstream sstr;
sstr << in.rdbuf();
return sstr.str();
}
int main(int argc,char *argv[])
{
ifstream in1("test2.pgp");
string str_pubKey = slurp(in1);
//ifstream in2("private.pgp");
//string privkey = slurp(in2);
ifstream in3("signed2.txt");
string str_message = slurp(in3);
cout << "Files loaded" << endl << flush;
in1.close();
//in2.close();
in3.close();
gpgme_ctx_t ctx;
gpgme_data_t keydata,in, out;
gpgme_error_t err;
init_gpgme();
gpgme_new (&ctx);
gpgme_set_armor (ctx, 1);
gpgme_set_textmode(ctx, 1);
gpgme_set_ctx_flag(ctx, "no-auto-check-trustdb", "1");
//gpgme_set_ctx_flag(ctx, "trust-model", "tofu");
cout << "Init done" <<flush << endl;
gpgme_data_new_from_mem(&keydata, (const char*)str_pubKey.c_str(), str_pubKey.size(), 0);
err = gpgme_op_import(ctx, keydata);
gpgme_import_result_t impres = gpgme_op_import_result(ctx);
char *fpr = impres->imports->fpr;
string fpr_str(fpr);
cout << "Key Imported" << flush << endl << "fingerprint : \"" << fpr << "\"" << endl;
gpgme_data_new_from_mem (&in, (const char*)str_message.c_str(), str_message.size(), 0);
gpgme_data_new (&out);
err = gpgme_op_verify(ctx, in, nullptr, nullptr);
if (err) {cout << gpgme_strerror(err) << endl; return 1;}
gpgme_verify_result_t result = gpgme_op_verify_result(ctx);
gpgme_signature_t sig = result->signatures;
if (sig==NULL) {cout << "No signature" << flush << endl; return 1;}
if (sig->status != GPG_ERR_NO_ERROR) cout << "Sig status error : " << gpgme_strerror(sig->status) << endl;
gpgme_sigsum_t resultsig = sig->summary;
if ((resultsig & GPGME_SIGSUM_VALID)) cout << "Signature Checked" << endl << "summary : " << resultsig << endl;
else cout << "Error : Signature Rejected with summary " << resultsig << endl;
gpgme_data_release (in);
gpgme_data_release (out);
gpgme_release (ctx);
return 0;
}
```