diff options
| author | Ingo Klöcker <[email protected]> | 2021-12-22 13:22:00 +0000 | 
|---|---|---|
| committer | Ingo Klöcker <[email protected]> | 2021-12-22 14:25:42 +0000 | 
| commit | 82f43455e9412d8b4792b35371e0b6704a619d07 (patch) | |
| tree | 94e713505d636e8592fa810c6350e27ac7ac3ca1 /lang/qt/src | |
| parent | qt,tests: Add test runner for testing the import job (diff) | |
| download | gpgme-82f43455e9412d8b4792b35371e0b6704a619d07.tar.gz gpgme-82f43455e9412d8b4792b35371e0b6704a619d07.zip  | |
qt: Detect an import error caused by a wrong password
* lang/qt/src/qgpgmeimportjob.cpp (import_qba): Check import statuses of
import result for bad passphrase errors.
--
To allow users of the import job to handle a failed import caused by
a wrong password more gracefully, check if all import statuses of the
import result have a bad passphrase error and return a bad passphrase
error as import result in this case.
GnuPG-bug-id: 5713
Diffstat (limited to '')
| -rw-r--r-- | lang/qt/src/qgpgmeimportjob.cpp | 18 | 
1 files changed, 17 insertions, 1 deletions
diff --git a/lang/qt/src/qgpgmeimportjob.cpp b/lang/qt/src/qgpgmeimportjob.cpp index 110250c9..ebd8a269 100644 --- a/lang/qt/src/qgpgmeimportjob.cpp +++ b/lang/qt/src/qgpgmeimportjob.cpp @@ -90,7 +90,23 @@ static QGpgMEImportJob::result_type import_qba(Context *ctx, const QByteArray &c      QGpgME::QByteArrayDataProvider dp(certData);      Data data(&dp); -    const ImportResult res = ctx->importKeys(data); +    ImportResult res = ctx->importKeys(data); +    // HACK: If the import failed with an error, then check if res.imports() +    // contains only import statuses with "bad passphrase" error; if yes, this +    // means that the user probably entered a wrong password to decrypt an +    // encrypted key for import. In this case, return a result with "bad +    // passphrase" error instead of the original error. +    // We check if all import statuses instead of any import status has a +    // "bad passphrase" error to avoid breaking imports that partially worked. +    // See https://dev.gnupg.org/T5713. +    const auto imports = res.imports(); +    if (res.error() && !imports.empty() +        && std::all_of(std::begin(imports), std::end(imports), +                       [](const Import &import) { +                           return import.error().code() == GPG_ERR_BAD_PASSPHRASE; +                       })) { +        res = ImportResult{Error{GPG_ERR_BAD_PASSPHRASE}}; +    }      Error ae;      const QString log = _detail::audit_log_as_html(ctx, ae);      return std::make_tuple(res, log, ae);  | 
