diff options
author | Saturneric <[email protected]> | 2021-05-29 19:28:40 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2021-05-29 19:28:40 +0000 |
commit | fe67bfb777a79b25149efa3e045dc043dc144ad0 (patch) | |
tree | 4d75a10f210b86d7e116d188569bc08e4e72adb7 /src/gpg/GpgContext.cpp | |
parent | Make eligible keys enter the signature candidate list. (diff) | |
download | GpgFrontend-fe67bfb777a79b25149efa3e045dc043dc144ad0.tar.gz GpgFrontend-fe67bfb777a79b25149efa3e045dc043dc144ad0.zip |
New page and function for generating subkeys.
Define the interface and functions of the subkey management tab.
When there is an item in the UID list, the first item is selected by default.
Compile the API for generating sub-keys and the corresponding calling thread.
Set GpgGenKeyInfo to apply to the subkey
Generate a subkey for the selected key pair of the management key pair interface.
Adjust the project structure and add a new classification key generation category.
Double-click the item in KeyList in the key pair management interface to enter the key details page.
Adjust the title of the key pair management interface.
Optimize part of the code of KeyGenThread.
Signed-off-by: Saturneric <[email protected]>
Diffstat (limited to 'src/gpg/GpgContext.cpp')
-rw-r--r-- | src/gpg/GpgContext.cpp | 71 |
1 files changed, 47 insertions, 24 deletions
diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp index 51ee07b5..d4736249 100644 --- a/src/gpg/GpgContext.cpp +++ b/src/gpg/GpgContext.cpp @@ -23,7 +23,7 @@ */ #include "gpg/GpgContext.h" -#include "ui/KeygenThread.h" +#include "ui/keygen/KeygenThread.h" #include <unistd.h> /* contains read/write */ @@ -321,28 +321,6 @@ namespace GpgME { return; } -// list only private keys ( the 1 does ) -// gpgmeError = gpgme_op_keylist_start(mCtx, nullptr, 1); -// if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) { -// checkErr(gpgmeError); -// return; -// } -// -// while ((gpgmeError = gpgme_op_keylist_next(mCtx, &key)) == GPG_ERR_NO_ERROR) { -// if (key->subkeys) { -// auto it = keys_map.find(key->subkeys->keyid); -// if (it != keys_map.end()) { -// it->is_private_key = true; -// } -// } -// gpgme_key_unref(key); -// } -// -// if (gpg_err_code(gpgmeError) != GPG_ERR_EOF) { -// checkErr(gpgmeError); -// return; -// } - gpgmeError = gpgme_op_keylist_end(mCtx); if (gpg_err_code(gpgmeError) != GPG_ERR_NO_ERROR) { checkErr(gpgmeError); @@ -1022,7 +1000,52 @@ namespace GpgME { checkErr(gpgmeError); return false; } - return false; + } + + bool GpgContext::generateSubkey(const GpgKey &key, GenKeyInfo *params) { + + if(!params->isSubKey()) { + return false; + } + + auto algo_utf8 = (params->getAlgo() + params->getKeySizeStr()).toUtf8(); + const char *algo = algo_utf8.constData(); + unsigned long expires = QDateTime::currentDateTime().secsTo(params->getExpired()); + unsigned int flags = 0; + + if (!params->isSubKey()) { + flags |= GPGME_CREATE_CERT; + } + + if (params->isAllowEncryption()) { + flags |= GPGME_CREATE_ENCR; + } + + if (params->isAllowSigning()) { + flags |= GPGME_CREATE_SIGN; + } + + if (params->isAllowAuthentication()) { + flags |= GPGME_CREATE_AUTH; + } + + if (params->isNonExpired()) { + flags |= GPGME_CREATE_NOEXPIRE; + } + + flags |= GPGME_CREATE_NOPASSWD; + + + auto gpgmeError = gpgme_op_createsubkey(mCtx, key.key_refer, + algo, 0, expires, flags); + if(gpgmeError == GPG_ERR_NO_ERROR) { + emit signalKeyUpdated(key.id); + return true; + } + else { + checkErr(gpgmeError); + return false; + } } } |