Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
Kleopatra
Commits
9dea1cbc
Commit
9dea1cbc
authored
Aug 02, 2022
by
Ingo Klöcker
Browse files
Add helpers for checking feasibility of certification revokations
GnuPG-bug-id: 6102
parent
57033773
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/utils/keys.cpp
View file @
9dea1cbc
...
...
@@ -88,3 +88,30 @@ bool Kleo::userHasCertificationKey()
return
(
k
.
protocol
()
==
GpgME
::
OpenPGP
)
&&
canCreateCertifications
(
k
);
});
}
Kleo
::
CertificationRevocationFeasibility
Kleo
::
userCanRevokeCertification
(
const
GpgME
::
UserID
::
Signature
&
certification
)
{
const
auto
certificationKey
=
KeyCache
::
instance
()
->
findByKeyIDOrFingerprint
(
certification
.
signerKeyID
());
const
bool
isSelfSignature
=
qstrcmp
(
certification
.
parent
().
parent
().
keyID
(),
certification
.
signerKeyID
())
==
0
;
if
(
!
certificationKey
.
hasSecret
())
{
return
CertificationNotMadeWithOwnKey
;
}
else
if
(
isSelfSignature
)
{
return
CertificationIsSelfSignature
;
}
else
if
(
certification
.
isRevokation
())
{
return
CertificationIsRevocation
;
}
else
if
(
certification
.
isExpired
())
{
return
CertificationIsExpired
;
}
else
if
(
certification
.
isInvalid
())
{
return
CertificationIsInvalid
;
}
else
if
(
!
canCreateCertifications
(
certificationKey
))
{
return
CertificationKeyNotAvailable
;
}
return
CertificationCanBeRevoked
;
}
bool
Kleo
::
userCanRevokeCertifications
(
const
GpgME
::
UserID
&
userId
)
{
return
Kleo
::
any_of
(
userId
.
signatures
(),
[](
const
auto
&
certification
)
{
return
userCanRevokeCertification
(
certification
)
==
CertificationCanBeRevoked
;
});
}
src/utils/keys.h
View file @
9dea1cbc
...
...
@@ -66,4 +66,26 @@ bool isSecretKeyStoredInKeyRing(const GpgME::Key &key);
*/
bool
userHasCertificationKey
();
enum
CertificationRevocationFeasibility
{
CertificationCanBeRevoked
=
0
,
CertificationNotMadeWithOwnKey
,
CertificationIsSelfSignature
,
CertificationIsRevocation
,
CertificationIsExpired
,
CertificationIsInvalid
,
CertificationKeyNotAvailable
,
};
/**
* Checks if the user can revoke the given \p certification.
*/
CertificationRevocationFeasibility
userCanRevokeCertification
(
const
GpgME
::
UserID
::
Signature
&
certification
);
/**
* Returns true if the user can revoke any of the certifications of the \p userId.
*
* \sa userCanRevokeCertification
*/
bool
userCanRevokeCertifications
(
const
GpgME
::
UserID
&
userId
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment