cpp, qt: Use uidhash to select uids for signing

* lang/cpp/src/gpgsignkeyeditinteractor.cpp (action):
Use uidhash instead of number.
(GpgSignKeyEditInteractor::setKey): New.
* lang/cpp/src/gpgsignkeyeditinteractor.h: Update accordingly.
* lang/cpp/src/key.h, lang/cpp/src/key.cpp: Wrap uidhash.
* lang/qt/src/qgpgmesignkeyjob.cpp: Set the key.

--
Using the uidhash avoids problems when the user ids
on --edit-key are different ones then the uids
captured by gpgme when listing keys. Or if
they are in a different order. This can happen
with cached keys or keys with user attributes.
This commit is contained in:
Andre Heinecke 2019-12-13 18:06:00 +01:00
parent 5eeae535ee
commit 194272dbc3
No known key found for this signature in database
GPG Key ID: 2978E9D40CBABA5C
5 changed files with 24 additions and 1 deletions

View File

@ -65,6 +65,7 @@ public:
std::vector<unsigned int>::const_iterator currentId, nextId; std::vector<unsigned int>::const_iterator currentId, nextId;
unsigned int checkLevel; unsigned int checkLevel;
bool dupeOk; bool dupeOk;
Key key;
const char *command() const const char *command() const
{ {
@ -259,7 +260,17 @@ const char *GpgSignKeyEditInteractor::action(Error &err) const
default: default:
if (st >= UIDS_LIST_SEPARATELY && st < UIDS_LIST_SEPARATELY_DONE) { if (st >= UIDS_LIST_SEPARATELY && st < UIDS_LIST_SEPARATELY_DONE) {
std::stringstream ss; std::stringstream ss;
ss << d->nextUserID(); auto nextID = d->nextUserID();
const char *hash;
assert (nextID);
if (!d->key.isNull() && (hash = d->key.userID(nextID - 1).uidhash())) {
/* Prefer uidhash if it is available as it might happen
* that uidattrs break the ordering of the uids in the
* edit-key interface */
ss << "uid " << hash;
} else {
ss << nextID;
}
d->scratch = ss.str(); d->scratch = ss.str();
return d->scratch.c_str(); return d->scratch.c_str();
} }
@ -318,6 +329,10 @@ unsigned int GpgSignKeyEditInteractor::nextState(unsigned int status, const char
err = GENERAL_ERROR; err = GENERAL_ERROR;
return ERROR; return ERROR;
} }
void GpgSignKeyEditInteractor::setKey(const Key &key)
{
d->key = key;
}
void GpgSignKeyEditInteractor::setCheckLevel(unsigned int checkLevel) void GpgSignKeyEditInteractor::setCheckLevel(unsigned int checkLevel)
{ {

View File

@ -50,6 +50,7 @@ public:
void setCheckLevel(unsigned int checkLevel); void setCheckLevel(unsigned int checkLevel);
void setUserIDsToSign(const std::vector<unsigned int> &userIDsToSign); void setUserIDsToSign(const std::vector<unsigned int> &userIDsToSign);
void setKey(const Key &key);
void setSigningOptions(int options); void setSigningOptions(int options);
/* Set this if it is ok to overwrite an existing signature. In that /* Set this if it is ok to overwrite an existing signature. In that

View File

@ -673,6 +673,11 @@ const char *UserID::comment() const
return uid ? uid->comment : nullptr ; return uid ? uid->comment : nullptr ;
} }
const char *UserID::uidhash() const
{
return uid ? uid->uidhash : nullptr ;
}
UserID::Validity UserID::validity() const UserID::Validity UserID::validity() const
{ {
if (!uid) { if (!uid) {

View File

@ -363,6 +363,7 @@ public:
const char *name() const; const char *name() const;
const char *email() const; const char *email() const;
const char *comment() const; const char *comment() const;
const char *uidhash() const;
enum Validity { Unknown = 0, Undefined = 1, Never = 2, enum Validity { Unknown = 0, Undefined = 1, Never = 2,
Marginal = 3, Full = 4, Ultimate = 5 Marginal = 3, Full = 4, Ultimate = 5

View File

@ -76,6 +76,7 @@ static QGpgMESignKeyJob::result_type sign_key(Context *ctx, const Key &key, cons
skei->setUserIDsToSign(uids); skei->setUserIDsToSign(uids);
skei->setCheckLevel(checkLevel); skei->setCheckLevel(checkLevel);
skei->setSigningOptions(opts); skei->setSigningOptions(opts);
skei->setKey(key);
if (dupeOk) { if (dupeOk) {
ctx->setFlag("extended-edit", "1"); ctx->setFlag("extended-edit", "1");