aboutsummaryrefslogtreecommitdiffstats
path: root/src/gpg/GpgContext.cpp
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2021-06-05 20:57:30 +0000
committerSaturneric <[email protected]>2021-06-05 20:57:30 +0000
commit9c09b5de5180632746d9fc7f75a3ed7f07b06292 (patch)
tree89c1e21762f04b4e383ff7f2f45c280b2c5e67ce /src/gpg/GpgContext.cpp
parentUpdate the verification function. (diff)
downloadGpgFrontend-9c09b5de5180632746d9fc7f75a3ed7f07b06292.tar.gz
GpgFrontend-9c09b5de5180632746d9fc7f75a3ed7f07b06292.zip
Adjust and improve the detailed interface of the verification information result.
Check whether the key can be signed before signing operation. Check whether the key is qualified before encrypting and signing operations. Modify part of the text explanation on the key details tab. Adjust the length and width of the key pair management interface. Add the actual function column to the list on the file operation page. Adjust the file operation page. For the function that displays the actual possession of the key in the key list by default. Add the function of displaying the actual possession of the key in the key details page. Adjust the code structure. Convert the label prompt below into a message board prompt. Signed-off-by: Saturneric <[email protected]>
Diffstat (limited to 'src/gpg/GpgContext.cpp')
-rw-r--r--src/gpg/GpgContext.cpp93
1 files changed, 76 insertions, 17 deletions
diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp
index 9d1bc083..492aef83 100644
--- a/src/gpg/GpgContext.cpp
+++ b/src/gpg/GpgContext.cpp
@@ -710,35 +710,21 @@ namespace GpgME {
verify_result = gpgme_op_verify_result (mCtx);
*/
//}
- bool GpgContext::sign(QStringList *uidList, const QByteArray &inBuffer, QByteArray *outBuffer, bool detached) {
+ bool GpgContext::sign(QVector<GpgKey> keys, const QByteArray &inBuffer, QByteArray *outBuffer, bool detached) {
gpgme_error_t gpgmeError;
gpgme_data_t dataIn, dataOut;
gpgme_sign_result_t result;
gpgme_sig_mode_t mode;
- if (uidList->isEmpty()) {
+ if (keys.isEmpty()) {
QMessageBox::critical(nullptr, tr("Key Selection"), tr("No Private Key Selected"));
return false;
}
// at start or end?
- gpgme_signers_clear(mCtx);
-
- //gpgme_encrypt_result_t e_result;
- gpgme_key_t signers[uidList->count() + 1];
-
- // TODO: do we really need array? adding one key dataIn loop should be ok
- for (int i = 0; i < uidList->count(); i++) {
- // the last 0 is for public keys, 1 would return private keys
- gpgme_op_keylist_start(mCtx, uidList->at(i).toUtf8().constData(), 0);
- gpgme_op_keylist_next(mCtx, &signers[i]);
- gpgme_op_keylist_end(mCtx);
-
- gpgmeError = gpgme_signers_add(mCtx, signers[i]);
- checkErr(gpgmeError);
- }
+ setSigners(keys);
gpgmeError = gpgme_data_new_from_mem(&dataIn, inBuffer.data(), inBuffer.size(), 1);
checkErr(gpgmeError);
@@ -1079,6 +1065,79 @@ namespace GpgME {
}
}
+ bool GpgContext::checkIfKeyCanSign(const GpgKey &key) {
+ if(std::any_of(key.subKeys.begin(), key.subKeys.end(), [] (const GpgSubKey &subkey) -> bool {
+ return subkey.secret && subkey.can_sign && !subkey.disabled && !subkey.revoked && !subkey.expired;
+ })) return true;
+ return false;
+ }
+
+ bool GpgContext::checkIfKeyCanCert(const GpgKey &key) {
+ return key.has_master_key && !key.expired && !key.revoked && !key.disabled;
+ }
+
+ bool GpgContext::checkIfKeyCanAuth(const GpgKey &key) {
+ if(std::any_of(key.subKeys.begin(), key.subKeys.end(), [] (const GpgSubKey &subkey) -> bool {
+ return subkey.secret && subkey.can_authenticate && !subkey.disabled && !subkey.revoked && !subkey.expired;
+ })) return true;
+ return false;
+ }
+
+ bool GpgContext::checkIfKeyCanEncr(const GpgKey &key) {
+ if(std::any_of(key.subKeys.begin(), key.subKeys.end(), [] (const GpgSubKey &subkey) -> bool {
+ return subkey.can_encrypt && !subkey.disabled && !subkey.revoked && !subkey.expired;
+ })) return true;
+ return false;
+ }
+
+ bool GpgContext::encryptSign(QVector<GpgKey> &keys, const QByteArray &inBuffer, QByteArray *outBuffer) {
+ gpgme_data_t dataIn = nullptr, dataOut = nullptr;
+ outBuffer->resize(0);
+
+ if (keys.count() == 0) {
+ QMessageBox::critical(nullptr, tr("No Key Selected"), tr("No Key Selected"));
+ return false;
+ }
+
+ setSigners(keys);
+
+ //gpgme_encrypt_result_t e_result;
+ gpgme_key_t recipients[keys.count() + 1];
+
+ /* set key for user */
+ int index = 0;
+ for(const auto &key : keys) {
+ recipients[index++] = key.key_refer;
+ }
+ //Last entry dataIn array has to be nullptr
+ recipients[keys.count()] = nullptr;
+
+ //If the last parameter isnt 0, a private copy of data is made
+ if (mCtx) {
+ err = gpgme_data_new_from_mem(&dataIn, inBuffer.data(), inBuffer.size(), 1);
+ checkErr(err);
+ if (!err) {
+ err = gpgme_data_new(&dataOut);
+ checkErr(err);
+ if (!err) {
+ err = gpgme_op_encrypt_sign(mCtx, recipients, GPGME_ENCRYPT_ALWAYS_TRUST, dataIn, dataOut);
+ checkErr(err);
+ if (!err) {
+ err = readToBuffer(dataOut, outBuffer);
+ checkErr(err);
+ }
+ }
+ }
+ }
+ if (dataIn) {
+ gpgme_data_release(dataIn);
+ }
+ if (dataOut) {
+ gpgme_data_release(dataOut);
+ }
+ return (err == GPG_ERR_NO_ERROR);
+ }
+
}