summaryrefslogtreecommitdiffstats
path: root/src/plugins/tls/schannel/qtls_schannel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/tls/schannel/qtls_schannel.cpp')
-rw-r--r--src/plugins/tls/schannel/qtls_schannel.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/plugins/tls/schannel/qtls_schannel.cpp b/src/plugins/tls/schannel/qtls_schannel.cpp
index 667f2d8a6c3..1034e99b7e0 100644
--- a/src/plugins/tls/schannel/qtls_schannel.cpp
+++ b/src/plugins/tls/schannel/qtls_schannel.cpp
@@ -2267,14 +2267,19 @@ static void attachPrivateKeyToCertificate(const QSslCertificate &certificate,
}
const auto freeProvider = qScopeGuard([provider]() { NCryptFreeObject(provider); });
- const QString certName = certificate.subjectInfo(QSslCertificate::CommonName).front();
+ const QString certName = [certificate]() {
+ if (auto cn = certificate.subjectInfo(QSslCertificate::CommonName); !cn.isEmpty())
+ return cn.front();
+ return QString();
+ }();
QSpan<const QChar> nameSpan(certName);
NCryptBuffer nbuffer{ ULONG(nameSpan.size_bytes() + sizeof(char16_t)),
NCRYPTBUFFER_PKCS_KEY_NAME,
const_reinterpret_cast<void *>(nameSpan.data()) };
NCryptBufferDesc bufferDesc{ NCRYPTBUFFER_VERSION, 1, &nbuffer };
+ auto *bufferDescPtr = nameSpan.isEmpty() ? nullptr : &bufferDesc;
NCRYPT_KEY_HANDLE ncryptKey = 0;
- status = NCryptImportKey(provider, 0, NCRYPT_PKCS8_PRIVATE_KEY_BLOB, &bufferDesc, &ncryptKey,
+ status = NCryptImportKey(provider, 0, NCRYPT_PKCS8_PRIVATE_KEY_BLOB, bufferDescPtr, &ncryptKey,
PBYTE(buffer.data()), buffer.size(), 0);
if (status != SEC_E_OK) {
qCWarning(lcTlsBackendSchannel())