From 15018316bca863c9d7329572af906850d47e0c63 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Wed, 24 Oct 2018 10:52:09 +0200 Subject: lok: Get the object shell from the document MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id62c0db3c9f404aaab70de0a73a20b2bb57b0393 Reviewed-on: https://gerrit.libreoffice.org/62272 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- desktop/source/lib/init.cxx | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'desktop') diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index b08c6d694f4a..1119886763ce 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -3604,13 +3604,27 @@ static void doc_postWindow(LibreOfficeKitDocument* /*pThis*/, unsigned nLOKWindo } // CERTIFICATE AND DOCUMENT SIGNING -static bool doc_insertCertificate(LibreOfficeKitDocument* /*pThis*/, +static bool doc_insertCertificate(LibreOfficeKitDocument* pThis, const unsigned char* pCertificateBinary, const int nCertificateBinarySize, const unsigned char* pPrivateKeyBinary, const int nPrivateKeySize) { if (!xContext.is()) return false; + LibLODocument_Impl* pDocument = static_cast(pThis); + + if (!pDocument->mxComponent.is()) + return false; + + SfxBaseModel* pBaseModel = dynamic_cast(pDocument->mxComponent.get()); + if (!pBaseModel) + return false; + + SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell(); + + if (!pObjectShell) + return false; + uno::Reference xSEInitializer = xml::crypto::SEInitializer::create(xContext); uno::Reference xSecurityContext; xSecurityContext = xSEInitializer->createSecurityContext(OUString()); @@ -3636,16 +3650,7 @@ static bool doc_insertCertificate(LibreOfficeKitDocument* /*pThis*/, if (!xCertificate.is()) return false; - printf("CERTIFICATE\n\tIssuerName: %s \n\tSubjectName: %s\n\tPK %s\n\n", - xCertificate->getIssuerName().toUtf8().getStr(), - xCertificate->getSubjectName().toUtf8().getStr(), - xCertificate->getSubjectPublicKeyAlgorithm().toUtf8().getStr()); - - SfxObjectShell* pDoc = SfxObjectShell::Current(); - if (!pDoc) - return false; - - return pDoc->SignDocumentContentUsingCertificate(xCertificate); + return pObjectShell->SignDocumentContentUsingCertificate(xCertificate); } static int doc_getSignatureState(LibreOfficeKitDocument* pThis) -- cgit