Kaydet (Commit) cc145029 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Miklos Vajna

Support to sign a document with a specified signature

Reviewed-on: https://gerrit.libreoffice.org/61778
Tested-by: Jenkins
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit 40810c43)

Conflicts:
	xmlsecurity/source/component/documentdigitalsignatures.cxx

Change-Id: I92e392b315c9217b63db830dea1b2e91387b56c2
üst 09293ff5
helpcontent2 @ 0233c4eb
Subproject commit 4fcc8606724bcf6ec87b3ca741d4a00633e1b3c4
Subproject commit 0233c4ebfd07878cd77454d1970fdf002c4e67b6
......@@ -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);
};
} ; } ; } ; } ;
......
......@@ -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: */
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment