[Libreoffice-commits] core.git: svl/source

Ashod Nakashian ashodnakashian at yahoo.com
Sat Sep 2 13:53:22 UTC 2017


 svl/source/crypto/cryptosign.cxx |   47 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

New commits:
commit 16c5e23894052a822a47b650cc3363ac7454c060
Author: Ashod Nakashian <ashodnakashian at yahoo.com>
Date:   Fri Sep 1 09:59:00 2017 -0400

    sw: retrieve subject name from signature
    
    From CryptoAPI.
    
    Change-Id: I5ec33a754f71d3617090a03887355077d0ffedd7
    Reviewed-on: https://gerrit.libreoffice.org/41789
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>

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)


More information about the Libreoffice-commits mailing list