diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2018-04-20 12:19:12 +0200 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2018-05-15 16:16:22 +0200 |
commit | 86e8cfdd54ac1b9413f0c86cbc23a80162806685 (patch) | |
tree | e62c721f66cb95490fcedc41d3c22303d89de182 /xmlsecurity/source/component | |
parent | 863d2485e60251ac45b019b2c58ced7cfc9d978e (diff) |
Sign Signature Line
This adds a new context menu entry "Sign Signature Line" to signature lines.
You can directly sign the document from there.
Still missing is the updating of the graphic to reflect the valid/invalid
signature state.
Change-Id: Ib8bc8c57f9d5370a10e379f86f9e41e57c715e3f
Reviewed-on: https://gerrit.libreoffice.org/53778
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'xmlsecurity/source/component')
-rw-r--r-- | xmlsecurity/source/component/documentdigitalsignatures.cxx | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx index e6dab417f93c..bd09970348c4 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -48,9 +48,12 @@ #include <cppuhelper/supportsservice.hxx> #include <com/sun/star/lang/IllegalArgumentException.hpp> #include <com/sun/star/security/XDocumentDigitalSignatures.hpp> +#include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp> using namespace css; using namespace css::uno; +using namespace css::lang; +using namespace css::xml::crypto; class DocumentDigitalSignatures : public cppu::WeakImplHelper<css::security::XDocumentDigitalSignatures, @@ -101,6 +104,10 @@ public: sal_Bool SAL_CALL signDocumentContent(const css::uno::Reference<css::embed::XStorage>& xStorage, const css::uno::Reference<css::io::XStream>& xSignStream) override; + sal_Bool SAL_CALL signDocumentContentWithCertificate( + const css::uno::Reference<css::embed::XStorage>& Storage, + const css::uno::Reference<css::io::XStream>& xSignStream, + const css::uno::Reference<css::security::XCertificate>& xCertificate) override; css::uno::Sequence<css::security::DocumentSignatureInformation> SAL_CALL verifyDocumentContentSignatures( const css::uno::Reference<css::embed::XStorage>& xStorage, @@ -215,6 +222,51 @@ sal_Bool DocumentDigitalSignatures::signDocumentContent( return ImplViewSignatures( rxStorage, xSignStream, DocumentSignatureMode::Content, false ); } +sal_Bool DocumentDigitalSignatures::signDocumentContentWithCertificate( + const Reference<css::embed::XStorage>& rxStorage, + const Reference<css::io::XStream>& xSignStream, + const Reference<css::security::XCertificate>& xCertificate) +{ + OSL_ENSURE(!m_sODFVersion.isEmpty(), + "DocumentDigitalSignatures: ODF Version not set, assuming minimum 1.2"); + + DocumentSignatureManager aSignatureManager(mxCtx, DocumentSignatureMode::Content); + + if (!aSignatureManager.init()) + return false; + + aSignatureManager.mxStore = rxStorage; + aSignatureManager.maSignatureHelper.SetStorage(rxStorage, m_sODFVersion); + aSignatureManager.mxSignatureStream = xSignStream; + + Reference<XXMLSecurityContext> xSecurityContext; + Reference<XServiceInfo> xServiceInfo(xCertificate, UNO_QUERY); + if (xServiceInfo->getImplementationName() + == "com.sun.star.xml.security.gpg.XCertificate_GpgImpl") + xSecurityContext = aSignatureManager.getGpgSecurityContext(); + else + xSecurityContext = aSignatureManager.getSecurityContext(); + + sal_Int32 nSecurityId; + OUString aDescription(""); + bool bSuccess + = aSignatureManager.add(xCertificate, xSecurityContext, aDescription, nSecurityId, true); + if (!bSuccess) + return false; + + // Need to have this to verify the signature + aSignatureManager.read(/*bUseTempStream=*/true, /*bCacheLastSignature=*/false); + aSignatureManager.write(true); + + if (rxStorage.is() && !xSignStream.is()) + { + uno::Reference<embed::XTransactedObject> xTrans(rxStorage, uno::UNO_QUERY); + xTrans->commit(); + } + + return true; +} + Sequence< css::security::DocumentSignatureInformation > DocumentDigitalSignatures::verifyDocumentContentSignatures( const Reference< css::embed::XStorage >& rxStorage, |