Page MenuHome GnuPG

No OneTemporary

diff --git a/src/defaultassuantransaction.cpp b/src/defaultassuantransaction.cpp
index 2184f043..7a52c153 100644
--- a/src/defaultassuantransaction.cpp
+++ b/src/defaultassuantransaction.cpp
@@ -1,84 +1,82 @@
/*
defaultassuantransaction.cpp - default Assuan Transaction that just stores data and status lines
Copyright (C) 2009 Klarälvdalens Datakonsult AB
2016 Bundesamt für Sicherheit in der Informationstechnik
Software engineering by Intevation GmbH
This file is part of GPGME++.
GPGME++ is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
GPGME++ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with GPGME++; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "defaultassuantransaction.h"
#include "error.h"
#include "data.h"
-#include <sstream>
-
using namespace GpgME;
DefaultAssuanTransaction::DefaultAssuanTransaction()
: AssuanTransaction(),
m_status(),
m_data()
{
}
DefaultAssuanTransaction::~DefaultAssuanTransaction() {}
Error DefaultAssuanTransaction::data(const char *data, size_t len)
{
m_data.append(data, len);
return Error();
}
Data DefaultAssuanTransaction::inquire(const char *name, const char *args, Error &err)
{
(void)name; (void)args; (void)err;
return Data::null;
}
Error DefaultAssuanTransaction::status(const char *status, const char *args)
{
m_status.push_back(std::pair<std::string, std::string>(status, args));
return Error();
}
std::vector<std::string> DefaultAssuanTransaction::statusLine(const char *tag) const
{
std::vector<std::string> result;
for (std::vector< std::pair<std::string, std::string> >::const_iterator it = m_status.begin(), end = m_status.end() ; it != end ; ++it) {
if (it->first == tag) {
result.push_back(it->second);
}
}
return result;
}
std::string DefaultAssuanTransaction::firstStatusLine(const char *tag) const
{
for (std::vector< std::pair<std::string, std::string> >::const_iterator it = m_status.begin(), end = m_status.end() ; it != end ; ++it) {
if (it->first == tag) {
return it->second;
}
}
return std::string();
}
diff --git a/src/gpgagentgetinfoassuantransaction.cpp b/src/gpgagentgetinfoassuantransaction.cpp
index a05ff96f..e8524054 100644
--- a/src/gpgagentgetinfoassuantransaction.cpp
+++ b/src/gpgagentgetinfoassuantransaction.cpp
@@ -1,125 +1,123 @@
/*
gpgagentgetinfoassuantransaction.cpp - Assuan Transaction to get information from gpg-agent
Copyright (C) 2009 Klarälvdalens Datakonsult AB
2016 Bundesamt für Sicherheit in der Informationstechnik
Software engineering by Intevation GmbH
This file is part of GPGME++.
GPGME++ is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
GPGME++ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with GPGME++; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gpgagentgetinfoassuantransaction.h"
#include "error.h"
#include "data.h"
#include "util.h"
#include <assert.h>
-#include <sstream>
-
using namespace GpgME;
GpgAgentGetInfoAssuanTransaction::GpgAgentGetInfoAssuanTransaction(InfoItem item)
: AssuanTransaction(),
m_item(item),
m_command(),
m_data()
{
}
GpgAgentGetInfoAssuanTransaction::~GpgAgentGetInfoAssuanTransaction() {}
std::string GpgAgentGetInfoAssuanTransaction::version() const
{
if (m_item == Version) {
return m_data;
} else {
return std::string();
}
}
unsigned int GpgAgentGetInfoAssuanTransaction::pid() const
{
if (m_item == Pid) {
return to_pid(m_data);
} else {
return 0U;
}
}
std::string GpgAgentGetInfoAssuanTransaction::socketName() const
{
if (m_item == SocketName) {
return m_data;
} else {
return std::string();
}
}
std::string GpgAgentGetInfoAssuanTransaction::sshSocketName() const
{
if (m_item == SshSocketName) {
return m_data;
} else {
return std::string();
}
}
static const char *const gpgagent_getinfo_tokens[] = {
"version",
"pid",
"socket_name",
"ssh_socket_name",
"scd_running",
};
void GpgAgentGetInfoAssuanTransaction::makeCommand() const
{
assert(m_item >= 0);
assert(m_item < LastInfoItem);
m_command = "GETINFO ";
m_command += gpgagent_getinfo_tokens[m_item];
}
const char *GpgAgentGetInfoAssuanTransaction::command() const
{
makeCommand();
return m_command.c_str();
}
Error GpgAgentGetInfoAssuanTransaction::data(const char *data, size_t len)
{
m_data.append(data, len);
return Error();
}
Data GpgAgentGetInfoAssuanTransaction::inquire(const char *name, const char *args, Error &err)
{
(void)name; (void)args; (void)err;
return Data::null;
}
Error GpgAgentGetInfoAssuanTransaction::status(const char *status, const char *args)
{
(void)status; (void)args;
return Error();
}
diff --git a/src/gpgrevokekeyeditinteractor.cpp b/src/gpgrevokekeyeditinteractor.cpp
index f918bdb6..dfa3be16 100644
--- a/src/gpgrevokekeyeditinteractor.cpp
+++ b/src/gpgrevokekeyeditinteractor.cpp
@@ -1,208 +1,207 @@
/*
gpgrevokekeyeditinteractor.cpp - Edit Interactor to revoke own OpenPGP keys
Copyright (c) 2022 g10 Code GmbH
Software engineering by Ingo Klöcker <dev@ingo-kloecker.de>
This file is part of GPGME++.
GPGME++ is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
GPGME++ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with GPGME++; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gpgrevokekeyeditinteractor.h"
#include "error.h"
#include <gpgme.h>
-#include <sstream>
#include <vector>
// avoid conflict (msvc)
#ifdef ERROR
# undef ERROR
#endif
using namespace GpgME;
class GpgRevokeKeyEditInteractor::Private
{
enum {
START = EditInteractor::StartState,
COMMAND,
CONFIRM_REVOKING_ENTIRE_KEY,
REASON_CODE,
REASON_TEXT,
// all these free slots belong to REASON_TEXT, too; we increase state()
// by one for each line of text, so that action() is called
REASON_TEXT_DONE = REASON_TEXT + 1000,
CONFIRM_REASON,
QUIT,
CONFIRM_SAVE,
ERROR = EditInteractor::ErrorState
};
GpgRevokeKeyEditInteractor *const q = nullptr;
public:
Private(GpgRevokeKeyEditInteractor *q)
: q{q}
, reasonCode{"0"}
{
}
const char *action(Error &err) const;
unsigned int nextState(unsigned int statusCode, const char *args, Error &err);
std::string reasonCode;
std::vector<std::string> reasonLines;
int nextLine = -1;
};
const char *GpgRevokeKeyEditInteractor::Private::action(Error &err) const
{
switch (const auto state = q->state()) {
case COMMAND:
return "revkey";
case CONFIRM_REVOKING_ENTIRE_KEY:
return "Y";
case REASON_CODE:
return reasonCode.c_str();
case REASON_TEXT_DONE:
return "";
case CONFIRM_REASON:
return "Y";
case QUIT:
return "quit";
case CONFIRM_SAVE:
return "Y";
case START:
return nullptr;
default:
if (state >= REASON_TEXT && state < REASON_TEXT_DONE) {
return reasonLines[nextLine].c_str();
}
// fall through
case ERROR:
err = Error::fromCode(GPG_ERR_GENERAL);
return nullptr;
}
}
unsigned int GpgRevokeKeyEditInteractor::Private::nextState(unsigned int status, const char *args, Error &err)
{
using std::strcmp;
static const Error GENERAL_ERROR = Error::fromCode(GPG_ERR_GENERAL);
switch (const auto state = q->state()) {
case START:
if (status == GPGME_STATUS_GET_LINE &&
strcmp(args, "keyedit.prompt") == 0) {
return COMMAND;
}
err = GENERAL_ERROR;
return ERROR;
case COMMAND:
if (status == GPGME_STATUS_GET_BOOL &&
strcmp(args, "keyedit.revoke.subkey.okay") == 0) {
return CONFIRM_REVOKING_ENTIRE_KEY;
}
err = GENERAL_ERROR;
return ERROR;
case CONFIRM_REVOKING_ENTIRE_KEY:
if (status == GPGME_STATUS_GET_LINE &&
strcmp(args, "ask_revocation_reason.code") == 0) {
return REASON_CODE;
}
err = GENERAL_ERROR;
return ERROR;
case REASON_CODE:
if (status == GPGME_STATUS_GET_LINE &&
strcmp(args, "ask_revocation_reason.text") == 0) {
nextLine++;
return static_cast<std::size_t>(nextLine) < reasonLines.size() ? REASON_TEXT : REASON_TEXT_DONE;
}
err = GENERAL_ERROR;
return ERROR;
default:
if (state >= REASON_TEXT && state < REASON_TEXT_DONE) {
if (status == GPGME_STATUS_GET_LINE &&
strcmp(args, "ask_revocation_reason.text") == 0) {
nextLine++;
return static_cast<std::size_t>(nextLine) < reasonLines.size() ? state + 1 : REASON_TEXT_DONE;
}
}
err = GENERAL_ERROR;
return ERROR;
case REASON_TEXT_DONE:
if (status == GPGME_STATUS_GET_BOOL &&
strcmp(args, "ask_revocation_reason.okay") == 0) {
return CONFIRM_REASON;
}
err = GENERAL_ERROR;
return ERROR;
case CONFIRM_REASON:
if (status == GPGME_STATUS_GET_LINE &&
strcmp(args, "keyedit.prompt") == 0) {
return QUIT;
}
err = GENERAL_ERROR;
return ERROR;
case QUIT:
if (status == GPGME_STATUS_GET_BOOL &&
strcmp(args, "keyedit.save.okay") == 0) {
return CONFIRM_SAVE;
}
err = GENERAL_ERROR;
return ERROR;
case ERROR:
if (status == GPGME_STATUS_GET_LINE &&
strcmp(args, "keyedit.prompt") == 0) {
return QUIT;
}
err = q->lastError();
return ERROR;
}
}
GpgRevokeKeyEditInteractor::GpgRevokeKeyEditInteractor()
: EditInteractor{}
, d{new Private{this}}
{
}
GpgRevokeKeyEditInteractor::~GpgRevokeKeyEditInteractor() = default;
void GpgRevokeKeyEditInteractor::setReason(RevocationReason reason, const std::vector<std::string> &description)
{
d->reasonCode = std::to_string(static_cast<int>(reason));
d->reasonLines = description;
}
const char *GpgRevokeKeyEditInteractor::action(Error &err) const
{
return d->action(err);
}
unsigned int GpgRevokeKeyEditInteractor::nextState(unsigned int status, const char *args, Error &err) const
{
return d->nextState(status, args, err);
}
diff --git a/src/scdgetinfoassuantransaction.cpp b/src/scdgetinfoassuantransaction.cpp
index c2fbeed0..4a024905 100644
--- a/src/scdgetinfoassuantransaction.cpp
+++ b/src/scdgetinfoassuantransaction.cpp
@@ -1,162 +1,161 @@
/*
scdgetinfoassuantransaction.cpp - Assuan Transaction to get information from scdaemon
Copyright (C) 2009 Klarälvdalens Datakonsult AB
2016 Bundesamt für Sicherheit in der Informationstechnik
Software engineering by Intevation GmbH
This file is part of GPGME++.
GPGME++ is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
GPGME++ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with GPGME++; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "scdgetinfoassuantransaction.h"
#include "error.h"
#include "data.h"
#include "util.h"
-#include <sstream>
#include <assert.h>
using namespace GpgME;
ScdGetInfoAssuanTransaction::ScdGetInfoAssuanTransaction(InfoItem item)
: AssuanTransaction(),
m_item(item),
m_command(),
m_data()
{
}
ScdGetInfoAssuanTransaction::~ScdGetInfoAssuanTransaction() {}
static std::vector<std::string> to_reader_list(const std::string &s)
{
std::vector<std::string> result;
std::stringstream ss(s);
std::string tok;
while (std::getline(ss, tok, '\n')) {
result.push_back(tok);
}
return result;
}
static std::vector<std::string> to_app_list(const std::string &s)
{
return to_reader_list(s);
}
std::string ScdGetInfoAssuanTransaction::version() const
{
if (m_item == Version) {
return m_data;
} else {
return std::string();
}
}
unsigned int ScdGetInfoAssuanTransaction::pid() const
{
if (m_item == Pid) {
return to_pid(m_data);
} else {
return 0U;
}
}
std::string ScdGetInfoAssuanTransaction::socketName() const
{
if (m_item == SocketName) {
return m_data;
} else {
return std::string();
}
}
char ScdGetInfoAssuanTransaction::status() const
{
if (m_item == Status && !m_data.empty()) {
return m_data[0];
} else {
return '\0';
}
}
std::vector<std::string> ScdGetInfoAssuanTransaction::readerList() const
{
if (m_item == ReaderList) {
return to_reader_list(m_data);
} else {
return std::vector<std::string>();
}
}
std::vector<std::string> ScdGetInfoAssuanTransaction::applicationList() const
{
if (m_item == ApplicationList) {
return to_app_list(m_data);
} else {
return std::vector<std::string>();
}
}
static const char *const scd_getinfo_tokens[] = {
"version",
"pid",
"socket_name",
"status",
"reader_list",
"deny_admin",
"app_list",
};
static_assert((sizeof scd_getinfo_tokens / sizeof * scd_getinfo_tokens == ScdGetInfoAssuanTransaction::LastInfoItem),
"getinfo_tokens size mismatch");
void ScdGetInfoAssuanTransaction::makeCommand() const
{
assert(m_item >= 0);
assert(m_item < LastInfoItem);
m_command = "SCD GETINFO ";
m_command += scd_getinfo_tokens[m_item];
}
const char *ScdGetInfoAssuanTransaction::command() const
{
makeCommand();
return m_command.c_str();
}
Error ScdGetInfoAssuanTransaction::data(const char *data, size_t len)
{
m_data.append(data, len);
return Error();
}
Data ScdGetInfoAssuanTransaction::inquire(const char *name, const char *args, Error &err)
{
(void)name; (void)args; (void)err;
return Data::null;
}
Error ScdGetInfoAssuanTransaction::status(const char *status, const char *args)
{
(void)status; (void)args;
return Error();
}
diff --git a/tests/run-verify.cpp b/tests/run-verify.cpp
index ec431e5b..50131fb8 100644
--- a/tests/run-verify.cpp
+++ b/tests/run-verify.cpp
@@ -1,186 +1,185 @@
/*
run-keylist.cpp
This file is part of GpgMEpp's test suite.
Copyright (c) 2018 Intevation GmbH
QGpgME is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License,
version 2, as published by the Free Software Foundation.
QGpgME is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "context.h"
#include "key.h"
#include "data.h"
#include "verificationresult.h"
#include <memory>
-#include <sstream>
#include <iostream>
using namespace GpgME;
static int
show_usage (int ex)
{
fputs ("usage: run-verify [options] [DETACHEDSIGFILE] FILE\n\n"
"Options:\n"
" --verbose run in verbose mode\n"
" --openpgp use the OpenPGP protocol (default)\n"
" --cms use the CMS protocol\n"
" --sender MBOX use MBOX as sender address\n"
" --repeat N repeat it N times\n"
" --list-key list the signing key afterwards\n"
, stderr);
exit (ex);
}
int
main (int argc, char **argv)
{
int last_argc = -1;
Protocol protocol = OpenPGP;
std::string sender;
int repeats = 1;
bool verbose = false;
bool list_key = false;
if (argc)
{ argc--; argv++; }
while (argc && last_argc != argc )
{
last_argc = argc;
if (!strcmp (*argv, "--"))
{
argc--; argv++;
break;
}
else if (!strcmp (*argv, "--help"))
show_usage (0);
else if (!strcmp (*argv, "--verbose"))
{
verbose = true;
argc--; argv++;
}
else if (!strcmp (*argv, "--list-key"))
{
list_key = true;
argc--; argv++;
}
else if (!strcmp (*argv, "--openpgp"))
{
protocol = OpenPGP;
argc--; argv++;
}
else if (!strcmp (*argv, "--cms"))
{
protocol = CMS;
argc--; argv++;
}
else if (!strcmp (*argv, "--sender"))
{
argc--; argv++;
if (!argc)
show_usage (1);
sender = *argv;
argc--; argv++;
}
else if (!strcmp (*argv, "--repeat"))
{
argc--; argv++;
if (!argc)
show_usage (1);
repeats = atoi (*argv);
argc--; argv++;
}
else if (!strncmp (*argv, "--", 2))
show_usage (1);
}
if (argc < 1 || argc > 2)
show_usage (1);
GpgME::initializeLibrary();
for (int i = 0; i < repeats; i++) {
std::cout << "Starting run: " << i << std::endl;
auto ctx = std::unique_ptr<Context> (Context::createForProtocol(protocol));
if (!ctx) {
std::cerr << "Failed to get Context";
return -1;
}
std::FILE *fp_sig = fopen (argv[0], "rb");
if (!fp_sig) {
std::cerr << "Failed to open sig file";
exit (1);
}
std::FILE *fp_msg = nullptr;
if (argc > 1)
{
fp_msg = fopen (argv[1], "rb");
if (!fp_msg) {
std::cerr << "Failed to open msg file";
exit (1);
}
}
Data dSig(fp_sig);
Data dMsg;
bool is_opaque = true;
if (fp_msg) {
dMsg = Data(fp_msg);
is_opaque = false;
}
if (!sender.empty()) {
ctx->setSender(sender.c_str());
}
Data output;
VerificationResult result;
if (is_opaque) {
result = ctx->verifyOpaqueSignature(dSig, output);
} else {
result = ctx->verifyDetachedSignature(dSig, dMsg);
}
Signature sig;
if (result.numSignatures()) {
sig = result.signature(0);
}
if (list_key && !sig.isNull()) {
sig.key(true, false);
}
if (verbose) {
std::cout << "Result: " << result << std::endl;
} else {
std::cout << "Err:" << result.error() << std::endl;
}
}
}
diff --git a/tests/run-wkdlookup.cpp b/tests/run-wkdlookup.cpp
index 71c4e704..fdd262d8 100644
--- a/tests/run-wkdlookup.cpp
+++ b/tests/run-wkdlookup.cpp
@@ -1,156 +1,155 @@
/*
run-wkdlookup.cpp
This file is part of GpgMEpp's test suite.
Copyright (c) 2021 g10 Code GmbH
Software engineering by Ingo Klöcker <dev@ingo-kloecker.de>
GPGME++ is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
GPGME++ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with GPGME++; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "context.h"
#include "data.h"
#include "defaultassuantransaction.h"
#include "key.h"
#include <memory>
-#include <sstream>
#include <iostream>
#include <thread>
using namespace GpgME;
static int
show_usage (int ex)
{
fputs ("usage: run-wkdlookup <email address>\n\n"
, stderr);
exit (ex);
}
int
main (int argc, char **argv)
{
int last_argc = -1;
if (argc) {
argc--; argv++;
}
while (argc && last_argc != argc ) {
last_argc = argc;
if (!strcmp (*argv, "--")) {
argc--; argv++;
break;
} else if (!strcmp (*argv, "--help")) {
show_usage (0);
} else if (!strncmp (*argv, "--", 2)) {
show_usage (1);
}
}
if (argc != 1) {
show_usage (1);
}
const std::string email{*argv};
GpgME::initializeLibrary();
Error err;
auto ctx = std::unique_ptr<Context>{Context::createForEngine(AssuanEngine, &err)};
if (!ctx) {
std::cerr << "Failed to get context (Error: " << err.asString() << ")\n";
return -1;
}
const std::string dirmngrSocket = GpgME::dirInfo("dirmngr-socket");
if ((err = ctx->setEngineFileName(dirmngrSocket.c_str()))) {
std::cerr << "Failed to set engine file name (Error: " << err.asString() << ")\n";
return -1;
}
if ((err = ctx->setEngineHomeDirectory(""))) {
std::cerr << "Failed to set engine home directory (Error: " << err.asString() << ")\n";
return -1;
}
// try do connect to dirmngr
err = ctx->assuanTransact("GETINFO version");
if (err && err.code() != GPG_ERR_ASS_CONNECT_FAILED) {
std::cerr << "Failed to start assuan transaction (Error: " << err.asString() << ")\n";
return -1;
}
if (err.code() == GPG_ERR_ASS_CONNECT_FAILED) {
std::cerr << "Starting dirmngr ...\n";
auto spawnCtx = std::unique_ptr<Context>{Context::createForEngine(SpawnEngine, &err)};
if (!spawnCtx) {
std::cerr << "Failed to get context for spawn engine (Error: " << err.asString() << ")\n";
return -1;
}
const auto dirmngrProgram = GpgME::dirInfo("dirmngr-name");
const auto homedir = GpgME::dirInfo("homedir");
const char *argv[] = {
dirmngrProgram,
"--homedir",
homedir,
"--daemon",
NULL
};
auto ignoreIO = Data{Data::null};
err = spawnCtx->spawnAsync(dirmngrProgram, argv,
ignoreIO, ignoreIO, ignoreIO,
Context::SpawnDetached);
if (err) {
std::cerr << "Failed to start dirmngr (Error: " << err.asString() << ")\n";
return -1;
}
// wait for socket to become available
int cnt = 0;
do {
++cnt;
std::cerr << "Waiting for dirmngr to start ...\n";
std::this_thread::sleep_for(std::chrono::milliseconds{250 * cnt});
err = ctx->assuanTransact("GETINFO version");
} while (err.code() == GPG_ERR_ASS_CONNECT_FAILED && cnt < 5);
}
const auto cmd = std::string{"WKD_GET "} + email;
err = ctx->assuanTransact(cmd.c_str());
if (err && err.code() != GPG_ERR_NO_NAME && err.code() != GPG_ERR_NO_DATA) {
std::cerr << "Error: WKD_GET returned " << err.asString() << "\n";
return -1;
}
const auto transaction = std::unique_ptr<DefaultAssuanTransaction>(dynamic_cast<DefaultAssuanTransaction*>(ctx->takeLastAssuanTransaction().release()));
const auto source = transaction->firstStatusLine("SOURCE");
const auto rawData = transaction->data();
if (rawData.size() == 0) {
std::cout << "No key found for " << email << "\n";
} else {
const auto data = GpgME::Data{rawData.c_str(), rawData.size()};
const auto keys = data.toKeys(GpgME::OpenPGP);
for (const auto &key : keys) {
std::cout << "Found key for " << email << " at " << source << ":\n" << key << "\n";
}
}
return 0;
}

File Metadata

Mime Type
text/x-diff
Expires
Sun, Jan 4, 2:25 PM (19 h, 2 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
aa/70/9687800f768d7b907bc4e85e8bb6

Event Timeline