Test export private keys in C++.

Result : fails.
Reason : loopback passphrase provider is never called.

With default pinentry mode, the passphrase is requested normally 
and the private key is exported. But this can't be done on a web server.

Enclosed in #ifdef DEVTIME.
This commit is contained in:
SET
2020-11-15 11:47:30 +01:00
parent f48a3602c6
commit e944da9eda
2 changed files with 40 additions and 0 deletions

View File

@@ -255,3 +255,28 @@ const Error GpgMEWorker::CreateSubKey(GpgME::Key& k,
delete ctx;
return e;
}
#ifdef DEVTIME
const Error GpgMEWorker::ExportPrivateKey(const char * pattern, string& buffer,
const string& passphrase)
{
GpgME::Data kData;
Context * ctx = Context::createForProtocol(Protocol::OpenPGP);
LoopbackPassphraseProvider * ppp = new LoopbackPassphraseProvider();
ppp->SetPassphrase(passphrase);
ctx->setPinentryMode(Context::PinentryMode::PinentryLoopback);
ctx->setPassphraseProvider(ppp);
ctx->setArmor(true);
uint flags = Context::ExportSecret;
Error e = ctx->exportPublicKeys(pattern, kData, flags);
buffer = kData.toString(); // Empty
delete ppp;
delete ctx;
return e;
}
#endif