From 36eea11752ac88f481e9c2269c1685075d3439bf Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Thu, 9 Jan 2025 12:24:47 +0200 Subject: [PATCH] NCryptEnumKeys returns ERROR_NO_MORE_ITEMS and is positive error code IB-8341 Signed-off-by: Raul Metsma --- client/QCNG.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/client/QCNG.cpp b/client/QCNG.cpp index a99d511d..932fd276 100644 --- a/client/QCNG.cpp +++ b/client/QCNG.cpp @@ -30,13 +30,13 @@ using namespace Qt::Literals::StringLiterals; Q_LOGGING_CATEGORY(CNG, "qdigidoc4.QCNG") -template +template struct SCOPE { T d {}; - ~SCOPE() { if(d) D(d); } - constexpr operator T() const { return d; } - constexpr T* operator&() { return &d; } + ~SCOPE() noexcept { if(d) D(d); } + constexpr operator T() const noexcept { return d; } + constexpr T* operator&() noexcept { return &d; } }; class QCNG::Private @@ -194,11 +194,6 @@ QList QCNG::tokens() const return data; }; auto enumKeys = [&result, &prop](const QString &provider, QString reader = {}) { - if(provider == u"SafeCert Key Storage Provider"_s) - { - qCWarning(CNG) << "Skip: Crashes on NCryptEnumKeys"; - return; - } QString scope = uR"(\\.\%1\)"_s.arg(reader); SCOPE h; SECURITY_STATUS err = NCryptOpenStorageProvider(&h, LPCWSTR(provider.utf16()), 0); @@ -206,9 +201,9 @@ QList QCNG::tokens() const PVOID pos {}; BCRYPT_PSS_PADDING_INFO rsaPSS { NCRYPT_SHA256_ALGORITHM, 32 }; DWORD size {}; - while(SUCCEEDED(NCryptEnumKeys(h, reader.isEmpty() ? nullptr : LPCWSTR(scope.utf16()), &keyname, &pos, NCRYPT_SILENT_FLAG))) + while(NCryptEnumKeys(h, reader.isEmpty() ? nullptr : LPCWSTR(scope.utf16()), &keyname, &pos, NCRYPT_SILENT_FLAG) == ERROR_SUCCESS) { - SCOPE keyname_scope{keyname}; + SCOPE keyname_scope{keyname}; SCOPE key; err = NCryptOpenKey(h, &key, keyname->pszName, keyname->dwLegacyKeySpec, NCRYPT_SILENT_FLAG); SslCertificate cert(prop(key, NCRYPT_CERTIFICATE_PROPERTY), QSsl::Der); @@ -248,7 +243,7 @@ QList QCNG::tokens() const qCWarning(CNG) << "Start enumerationg providers"; DWORD count {}; - SCOPE providers {}; + SCOPE providers {}; NCryptEnumStorageProviders(&count, &providers, NCRYPT_SILENT_FLAG); for(DWORD i {}; i < count; ++i) {