diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2018-10-15 10:06:56 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2018-10-25 23:33:53 +0200 |
commit | 40810c43c48b25385b487c0b79c4c466dbf36be7 (patch) | |
tree | 2679b17629e279d4631800b9ce923d6d39d76b90 /xmlsecurity | |
parent | 2fac8cf22f687b247ba6fba8e7caf8e970cd15d9 (diff) |
Support to sign a document with a specified signature
Change-Id: I92e392b315c9217b63db830dea1b2e91387b56c2
Reviewed-on: https://gerrit.libreoffice.org/61778
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'xmlsecurity')
-rw-r--r-- | xmlsecurity/source/component/documentdigitalsignatures.cxx | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx index 23689c1e4fa3..d19f6bd854e0 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -168,6 +168,11 @@ public: 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; }; DocumentDigitalSignatures::DocumentDigitalSignatures( const Reference< XComponentContext >& rxCtx ): @@ -749,6 +754,42 @@ void DocumentDigitalSignatures::addLocationToTrustedSources( const OUString& Loc aSecOpt.SetSecureURLs( aSecURLs ); } +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; +} + extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface* com_sun_star_security_DocumentDigitalSignatures_get_implementation( uno::XComponentContext* pCtx, uno::Sequence<uno::Any> const& /*rSeq*/) |