cpp: Allow setting the curve to use when generating ECC keys

lang/cpp/src/gpggencardkeyinteractor.h (class GpgGenCardKeyInteractor):
Add enum Curve. Add member function setCurve.
lang/cpp/src/gpggencardkeyinteractor.cpp
(class GpgGenCardKeyInteractor::Private): Initialize simple members
in-class. Add member curve.
(GpgGenCardKeyInteractor::~GpgGenCardKeyInteractor): Use default d'tor.
(GpgGenCardKeyInteractor::setCurve): New.
(GpgGenCardKeyInteractor::action): Return curve defaulting to
Curve25519.
--

This enables users of this interactor to request the generation of
ECC keys with a specific curve as smart card keys. It's up to the user
to specify a curve that is actually supported by the smart card.

GnuPG-bug-id: 4429
This commit is contained in:
Ingo Klöcker 2022-10-24 12:21:41 +02:00
parent d36905bb80
commit d9ac138595
No known key found for this signature in database
GPG Key ID: F5A5D1692277A1E9
3 changed files with 43 additions and 7 deletions

9
NEWS
View File

@ -10,6 +10,15 @@ Noteworthy changes in version 1.18.1 (unreleased)
* qt: Fix problem with expiration dates after 2038-01-19 on 32-bit systems * qt: Fix problem with expiration dates after 2038-01-19 on 32-bit systems
when adding an existing subkey to another key. [T6137] when adding an existing subkey to another key. [T6137]
* cpp: Allow setting the curve to use when generating ECC keys
for smart cards. [T4429]
* Interface changes relative to the 1.18.0 release:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cpp: GpgGenCardKeyInteractor::Curve NEW.
cpp: GpgGenCardKeyInteractor::setCurve NEW.
Noteworthy changes in version 1.18.0 (2022-08-10) Noteworthy changes in version 1.18.0 (2022-08-10)
------------------------------------------------- -------------------------------------------------

View File

@ -36,16 +36,17 @@ using namespace GpgME;
class GpgGenCardKeyInteractor::Private class GpgGenCardKeyInteractor::Private
{ {
public: public:
Private() : keysize("2048"), backup(false), algo(RSA) Private() : keysize("2048")
{ {
} }
std::string name, email, backupFileName, expiry, serial, keysize; std::string name, email, backupFileName, expiry, serial, keysize;
bool backup; bool backup = false;
Algo algo; Algo algo = RSA;
std::string curve;
}; };
GpgGenCardKeyInteractor::~GpgGenCardKeyInteractor() {} GpgGenCardKeyInteractor::~GpgGenCardKeyInteractor() = default;
GpgGenCardKeyInteractor::GpgGenCardKeyInteractor(const std::string &serial): GpgGenCardKeyInteractor::GpgGenCardKeyInteractor(const std::string &serial):
d(new Private) d(new Private)
@ -88,6 +89,15 @@ void GpgGenCardKeyInteractor::setAlgo(Algo algo)
d->algo = algo; d->algo = algo;
} }
void GpgGenCardKeyInteractor::setCurve(Curve curve)
{
if (curve == DefaultCurve) {
d->curve.clear();
} else if (curve >= 1 && curve <= LastCurve) {
d->curve = std::to_string(static_cast<int>(curve));
}
}
namespace GpgGenCardKeyInteractor_Private namespace GpgGenCardKeyInteractor_Private
{ {
enum { enum {
@ -141,7 +151,7 @@ const char *GpgGenCardKeyInteractor::action(Error &err) const
case KEY_CURVE1: case KEY_CURVE1:
case KEY_CURVE2: case KEY_CURVE2:
case KEY_CURVE3: case KEY_CURVE3:
return "1"; // Only cv25519 supported. return d->curve.empty() ? "1" : d->curve.c_str(); // default is Curve25519
case NAME: case NAME:
return d->name.c_str(); return d->name.c_str();
case EMAIL: case EMAIL:

View File

@ -58,10 +58,27 @@ public:
enum Algo { enum Algo {
RSA = 1, RSA = 1,
ECC = 2 ECC = 2,
}; };
void setAlgo(Algo algo); void setAlgo(Algo algo);
// the enum values minus 1 have to match the indexes of the curves used by
// ask_curve() in gnupg's g10/keygen.c
enum Curve {
DefaultCurve = 0, // currently Curve25519
Curve25519 = 1,
Curve448,
NISTP256,
NISTP384,
NISTP521,
BrainpoolP256,
BrainpoolP384,
BrainpoolP512,
Secp256k1,
LastCurve = Secp256k1,
};
void setCurve(Curve curve);
std::string backupFileName() const; std::string backupFileName() const;
private: private: