[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - 2 commits - helpcontent2 offapi/com xmlsecurity/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Thu Nov 8 12:40:36 UTC 2018
helpcontent2 | 2
offapi/com/sun/star/security/XDocumentDigitalSignatures.idl | 10 ++-
xmlsecurity/source/component/documentdigitalsignatures.cxx | 38 ++++++++++++
xmlsecurity/source/component/documentdigitalsignatures.hxx | 5 +
xmlsecurity/source/helper/documentsignaturemanager.cxx | 9 +-
5 files changed, 57 insertions(+), 7 deletions(-)
New commits:
commit 1ed7d2fef309a8a71b837d355099732c49cde887
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon Oct 15 10:07:32 2018 +0200
Commit: Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Thu Nov 8 11:36:48 2018 +0100
use "range for" to iterate through certificates
Reviewed-on: https://gerrit.libreoffice.org/61779
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit f9acea526b9aeb3cf450cd7ee43bd969385865db)
Conflicts:
xmlsecurity/source/helper/documentsignaturemanager.cxx
Change-Id: Ife206ab29f2f8eaa2358f45e6bae2290d95fd4d6
diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx
index fd88d0a52e7e..45787b190311 100644
--- a/xmlsecurity/source/helper/documentsignaturemanager.cxx
+++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx
@@ -341,14 +341,13 @@ bool DocumentSignatureManager::add(const uno::Reference<security::XCertificate>&
}
uno::Sequence< uno::Reference< security::XCertificate > > aCertPath = xSecurityContext->getSecurityEnvironment()->buildCertificatePath(xCert);
- const uno::Reference< security::XCertificate >* pCertPath = aCertPath.getConstArray();
- sal_Int32 nCnt = aCertPath.getLength();
OUStringBuffer aStrBuffer;
- for (int i = 0; i < nCnt; i++)
+ for (uno::Reference<security::XCertificate> const& rxCertificate : aCertPath)
{
- sax::Converter::encodeBase64(aStrBuffer, pCertPath[i]->getEncoded());
- maSignatureHelper.AddEncapsulatedX509Certificate(aStrBuffer.makeStringAndClear());
+ sax::Converter::encodeBase64(aStrBuffer, rxCertificate->getEncoded());
+ OUString aString = aStrBuffer.makeStringAndClear();
+ maSignatureHelper.AddEncapsulatedX509Certificate(aString);
}
commit cc145029e896b8e65443898f65807a8c5414e0d2
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon Oct 15 10:06:56 2018 +0200
Commit: Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Thu Nov 8 11:02:23 2018 +0100
Support to sign a document with a specified signature
Reviewed-on: https://gerrit.libreoffice.org/61778
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
(cherry picked from commit 40810c43c48b25385b487c0b79c4c466dbf36be7)
Conflicts:
xmlsecurity/source/component/documentdigitalsignatures.cxx
Change-Id: I92e392b315c9217b63db830dea1b2e91387b56c2
diff --git a/helpcontent2 b/helpcontent2
index 4fcc8606724b..0233c4ebfd07 160000
--- a/helpcontent2
+++ b/helpcontent2
@@ -1 +1 @@
-Subproject commit 4fcc8606724bcf6ec87b3ca741d4a00633e1b3c4
+Subproject commit 0233c4ebfd07878cd77454d1970fdf002c4e67b6
diff --git a/offapi/com/sun/star/security/XDocumentDigitalSignatures.idl b/offapi/com/sun/star/security/XDocumentDigitalSignatures.idl
index 519f77cb62dd..4d51192c557f 100644
--- a/offapi/com/sun/star/security/XDocumentDigitalSignatures.idl
+++ b/offapi/com/sun/star/security/XDocumentDigitalSignatures.idl
@@ -157,7 +157,15 @@ interface XDocumentDigitalSignatures : com::sun::star::uno::XInterface
*/
com::sun::star::security::XCertificate chooseCertificateWithProps( [out] sequence<::com::sun::star::beans::PropertyValue> Properties);
-} ;
+ /** Signs the content of the document with the provided certificate.
+
+ @since LibreOffice 6.2
+ */
+ boolean signDocumentWithCertificate([in] ::com::sun::star::security::XCertificate xCertificate,
+ [in] ::com::sun::star::embed::XStorage xStorage,
+ [in] ::com::sun::star::io::XStream xStream);
+
+};
} ; } ; } ; } ;
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx
index dd7de2c3bafe..e49c11e0eef7 100644
--- a/xmlsecurity/source/component/documentdigitalsignatures.cxx
+++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx
@@ -47,9 +47,11 @@
#include <comphelper/sequence.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
using namespace css;
using namespace css::uno;
+using namespace css::xml::crypto;
DocumentDigitalSignatures::DocumentDigitalSignatures( const Reference< XComponentContext >& rxCtx ):
mxCtx(rxCtx),
@@ -578,4 +580,40 @@ Reference< XInterface > DocumentDigitalSignatures_CreateInstance(
return static_cast<cppu::OWeakObject*>(new DocumentDigitalSignatures( rCtx ));
}
+sal_Bool DocumentDigitalSignatures::signDocumentWithCertificate(
+ css::uno::Reference<css::security::XCertificate> const & xCertificate,
+ css::uno::Reference<css::embed::XStorage> const & xStorage,
+ css::uno::Reference<css::io::XStream> const & xStream)
+{
+ DocumentSignatureManager aSignatureManager(mxCtx, DocumentSignatureMode::Content);
+
+ if (!aSignatureManager.init())
+ return false;
+
+ aSignatureManager.mxStore = xStorage;
+ aSignatureManager.maSignatureHelper.SetStorage(xStorage, m_sODFVersion);
+ aSignatureManager.mxSignatureStream = xStream;
+
+ Reference<XXMLSecurityContext> xSecurityContext;
+ Reference<XServiceInfo> xServiceInfo(xCertificate, UNO_QUERY);
+ xSecurityContext = aSignatureManager.getSecurityContext();
+
+ sal_Int32 nSecurityId;
+
+ bool bSuccess = aSignatureManager.add(xCertificate, xSecurityContext, "", nSecurityId, true);
+ if (!bSuccess)
+ return false;
+
+ aSignatureManager.read(/*bUseTempStream=*/true, /*bCacheLastSignature=*/false);
+ aSignatureManager.write(true);
+
+ if (xStorage.is() && !xStream.is())
+ {
+ uno::Reference<embed::XTransactedObject> xTransaction(xStorage, uno::UNO_QUERY);
+ xTransaction->commit();
+ }
+
+ return true;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.hxx b/xmlsecurity/source/component/documentdigitalsignatures.hxx
index 9ef24ab36e5e..a3064eb1e206 100644
--- a/xmlsecurity/source/component/documentdigitalsignatures.hxx
+++ b/xmlsecurity/source/component/documentdigitalsignatures.hxx
@@ -108,6 +108,11 @@ public:
css::uno::Reference< css::security::XCertificate > SAL_CALL chooseSigningCertificate(OUString& rDescription) override;
css::uno::Sequence<css::uno::Reference< css::security::XCertificate > > SAL_CALL chooseEncryptionCertificate() override;
css::uno::Reference< css::security::XCertificate > SAL_CALL chooseCertificateWithProps(css::uno::Sequence<::com::sun::star::beans::PropertyValue>& Properties) override;
+
+ sal_Bool SAL_CALL signDocumentWithCertificate(
+ css::uno::Reference<css::security::XCertificate> const & xCertificate,
+ css::uno::Reference<css::embed::XStorage> const & xStoragexStorage,
+ css::uno::Reference<css::io::XStream> const & xStream) override;
};
/// @throws css::uno::Exception
More information about the Libreoffice-commits
mailing list