diff options
author | Ashod Nakashian <ashodnakashian@yahoo.com> | 2017-09-01 09:59:00 -0400 |
---|---|---|
committer | Ashod Nakashian <ashnakash@gmail.com> | 2017-09-02 15:53:00 +0200 |
commit | 16c5e23894052a822a47b650cc3363ac7454c060 (patch) | |
tree | fe099069602e2cd422dc8062de3158a9a56ac902 /svl | |
parent | 1d9b0dfb5c5519c9c54c10ea535aeea83db723f5 (diff) |
sw: retrieve subject name from signature
From CryptoAPI.
Change-Id: I5ec33a754f71d3617090a03887355077d0ffedd7
Reviewed-on: https://gerrit.libreoffice.org/41789
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'svl')
-rw-r--r-- | svl/source/crypto/cryptosign.cxx | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/svl/source/crypto/cryptosign.cxx b/svl/source/crypto/cryptosign.cxx index 91158e72b3c1..891b563e7c92 100644 --- a/svl/source/crypto/cryptosign.cxx +++ b/svl/source/crypto/cryptosign.cxx @@ -1906,6 +1906,52 @@ bool VerifyNonDetachedSignature(const std::vector<unsigned char>& aData, const s return aActualHash.size() == rExpectedHash.size() && !std::memcmp(aActualHash.data(), rExpectedHash.data(), aActualHash.size()); } + +OUString GetSubjectName(PCCERT_CONTEXT pCertContext) +{ + OUString subjectName; + + // Get Subject name size. + DWORD dwData = CertGetNameString(pCertContext, + CERT_NAME_SIMPLE_DISPLAY_TYPE, + 0, + nullptr, + nullptr, + 0); + if (!dwData) + { + SAL_WARN("svl.crypto", "ValidateSignature: CertGetNameString failed"); + return subjectName; + } + + // Allocate memory for subject name. + LPTSTR szName = (LPTSTR)LocalAlloc(LPTR, dwData * sizeof(TCHAR)); + if (!szName) + { + SAL_WARN("svl.crypto", "ValidateSignature: Unable to allocate memory for subject name"); + return subjectName; + } + + // Get subject name. + if (!CertGetNameString(pCertContext, + CERT_NAME_SIMPLE_DISPLAY_TYPE, + 0, + nullptr, + szName, + dwData)) + { + SAL_WARN("svl.crypto", "ValidateSignature: CertGetNameString failed"); + return subjectName; + } + + subjectName = OUString::fromUtf8(OString(szName)); + + if (szName != nullptr) + LocalFree(szName); + + return subjectName; +} + #endif } @@ -2211,6 +2257,7 @@ bool Signing::Verify(const std::vector<unsigned char>& aData, OUStringBuffer aBuffer; comphelper::Base64::encode(aBuffer, aDerCert); rInformation.ouX509Certificate = aBuffer.makeStringAndClear(); + rInformation.ouSubject = GetSubjectName(pSignerCertContext); } if (bNonDetached) |