summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2018-10-15 10:06:56 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2018-11-08 11:02:23 +0100
commitcc145029e896b8e65443898f65807a8c5414e0d2 (patch)
tree0008d0af44dc56b9e91d3ab77fed6354e367080e
parent09293ff54d1b13991d9925b4d4b74ec80114460e (diff)
Support to sign a document with a specified signature
Reviewed-on: https://gerrit.libreoffice.org/61778 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit 40810c43c48b25385b487c0b79c4c466dbf36be7) Conflicts: xmlsecurity/source/component/documentdigitalsignatures.cxx Change-Id: I92e392b315c9217b63db830dea1b2e91387b56c2
m---------helpcontent20
-rw-r--r--offapi/com/sun/star/security/XDocumentDigitalSignatures.idl10
-rw-r--r--xmlsecurity/source/component/documentdigitalsignatures.cxx38
-rw-r--r--xmlsecurity/source/component/documentdigitalsignatures.hxx5
4 files changed, 52 insertions, 1 deletions
diff --git a/helpcontent2 b/helpcontent2
-Subproject 4fcc8606724bcf6ec87b3ca741d4a00633e1b3c
+Subproject 0233c4ebfd07878cd77454d1970fdf002c4e67b
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