From 72accbcbd352f54f9828bd03ef445a6f667b32ec Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Wed, 24 Nov 2021 10:27:01 +0100 Subject: Add missing GetSubjectName for Windows build Change-Id: Ibffc5edd3c0937994c405f82ba8656c24c154342 --- xmlsecurity/source/pdfio/pdfdocument.cxx | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/xmlsecurity/source/pdfio/pdfdocument.cxx b/xmlsecurity/source/pdfio/pdfdocument.cxx index effc754f8ec7..2afba0e4cbc1 100644 --- a/xmlsecurity/source/pdfio/pdfdocument.cxx +++ b/xmlsecurity/source/pdfio/pdfdocument.cxx @@ -209,6 +209,52 @@ bad_data: return rv; } #elif defined XMLSEC_CRYPTO_MSCRYPTO + +OUString GetSubjectName(PCCERT_CONTEXT pCertContext) +{ + OUString subjectName; + + // Get Subject name size. + DWORD dwData = CertGetNameStringW(pCertContext, + CERT_NAME_SIMPLE_DISPLAY_TYPE, + 0, + nullptr, + nullptr, + 0); + if (!dwData) + { + SAL_WARN("xmlsecurity.pdfio", "ValidateSignature: CertGetNameString failed"); + return subjectName; + } + + // Allocate memory for subject name. + LPWSTR szName = static_cast( + LocalAlloc(LPTR, dwData * sizeof(WCHAR))); + if (!szName) + { + SAL_WARN("xmlsecurity.pdfio", "ValidateSignature: Unable to allocate memory for subject name"); + return subjectName; + } + + // Get subject name. + if (!CertGetNameStringW(pCertContext, + CERT_NAME_SIMPLE_DISPLAY_TYPE, + 0, + nullptr, + szName, + dwData)) + { + LocalFree(szName); + SAL_WARN("xmlsecurity.pdfio", "ValidateSignature: CertGetNameString failed"); + return subjectName; + } + + subjectName = SAL_U(szName); + LocalFree(szName); + + return subjectName; +} + /// Verifies a non-detached signature using CryptoAPI. bool VerifyNonDetachedSignature(SvStream& rStream, std::vector>& rByteRanges, std::vector& rExpectedHash) { -- cgit