diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2018-04-20 12:19:12 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-11-08 13:49:09 +0100 |
commit | a797afa58cd441cb7de5e1fe2845c3eff2e9001b (patch) | |
tree | 33292431b72f732558e7bfd0f9792a3878f78049 /xmlsecurity | |
parent | 1ed7d2fef309a8a71b837d355099732c49cde887 (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.
Reviewed-on: https://gerrit.libreoffice.org/53778
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
(cherry picked from commit 86e8cfdd54ac1b9413f0c86cbc23a80162806685)
Conflicts:
cui/source/dialogs/SignSignatureLineDialog.cxx
xmlsecurity/source/component/documentdigitalsignatures.cxx
Change-Id: Ib8bc8c57f9d5370a10e379f86f9e41e57c715e3f
Diffstat (limited to 'xmlsecurity')
8 files changed, 126 insertions, 3 deletions
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx index e49c11e0eef7..eee5a09952e6 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -47,10 +47,12 @@ #include <comphelper/sequence.hxx> #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; DocumentDigitalSignatures::DocumentDigitalSignatures( const Reference< XComponentContext >& rxCtx ): @@ -120,6 +122,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, diff --git a/xmlsecurity/source/component/documentdigitalsignatures.hxx b/xmlsecurity/source/component/documentdigitalsignatures.hxx index a3064eb1e206..72ac2ced5014 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.hxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.hxx @@ -86,6 +86,10 @@ public: // XDocumentDigitalSignatures 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, const css::uno::Reference< css::io::XInputStream >& xSignInStream ) override; void SAL_CALL showDocumentContentSignatures( const css::uno::Reference< css::embed::XStorage >& xStorage, const css::uno::Reference< css::io::XInputStream >& xSignInStream ) override; OUString SAL_CALL getDocumentContentSignatureDefaultStreamName( ) override; diff --git a/xmlsecurity/source/gpg/CertificateImpl.cxx b/xmlsecurity/source/gpg/CertificateImpl.cxx index c831011ca50e..81dafbe9e472 100644 --- a/xmlsecurity/source/gpg/CertificateImpl.cxx +++ b/xmlsecurity/source/gpg/CertificateImpl.cxx @@ -13,6 +13,7 @@ #include <comphelper/servicehelper.hxx> #include <comphelper/sequence.hxx> +#include <cppuhelper/supportsservice.hxx> #include <com/sun/star/security/KeyUsage.hpp> #include <officecfg/Office/Common.hxx> @@ -246,4 +247,19 @@ const GpgME::Key* CertificateImpl::getCertificate() const return &m_pKey; } +/* XServiceInfo */ +OUString SAL_CALL CertificateImpl::getImplementationName() +{ + return OUString("com.sun.star.xml.security.gpg.XCertificate_GpgImpl"); +} + +/* XServiceInfo */ +sal_Bool SAL_CALL CertificateImpl::supportsService(const OUString& serviceName) +{ + return cppu::supportsService(this, serviceName); +} + +/* XServiceInfo */ +Sequence<OUString> SAL_CALL CertificateImpl::getSupportedServiceNames() { return { OUString() }; } + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmlsecurity/source/gpg/CertificateImpl.hxx b/xmlsecurity/source/gpg/CertificateImpl.hxx index 63cddc6dc7b9..eaf81bd3f37f 100644 --- a/xmlsecurity/source/gpg/CertificateImpl.hxx +++ b/xmlsecurity/source/gpg/CertificateImpl.hxx @@ -21,6 +21,7 @@ #include <com/sun/star/uno/Exception.hpp> #include <com/sun/star/uno/RuntimeException.hpp> #include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/uno/SecurityException.hpp> #include <com/sun/star/security/CertificateKind.hpp> @@ -29,7 +30,8 @@ #include <key.h> class CertificateImpl : public cppu::WeakImplHelper< css::security::XCertificate, - css::lang::XUnoTunnel >, + css::lang::XUnoTunnel, + css::lang::XServiceInfo >, public xmlsecurity::Certificate { private: @@ -84,6 +86,11 @@ public: // Helper methods void setCertificate(GpgME::Context* ctx, const GpgME::Key& key); const GpgME::Key* getCertificate() const; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; } ; #endif // INCLUDED_XMLSECURITY_SOURCE_GPG_X509CERTIFICATE_HXX diff --git a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx index 07a769ac99cf..23b2fdb2d56a 100644 --- a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx +++ b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx @@ -22,6 +22,7 @@ #include <sal/config.h> #include <comphelper/servicehelper.hxx> #include <comphelper/windowserrorstring.hxx> +#include <cppuhelper/supportsservice.hxx> #include "x509certificate_mscryptimpl.hxx" #include <certificateextension_xmlsecimpl.hxx> #include "sanextension_mscryptimpl.hxx" @@ -648,4 +649,22 @@ sal_Int32 SAL_CALL X509Certificate_MSCryptImpl::getCertificateUsage( ) return usage; } +/* XServiceInfo */ +OUString SAL_CALL X509Certificate_MSCryptImpl::getImplementationName() +{ + return OUString("com.sun.star.xml.security.gpg.XCertificate_MsCryptImpl"); +} + +/* XServiceInfo */ +sal_Bool SAL_CALL X509Certificate_MSCryptImpl::supportsService(const OUString& serviceName) +{ + return cppu::supportsService(this, serviceName); +} + +/* XServiceInfo */ +Sequence<OUString> SAL_CALL X509Certificate_MSCryptImpl::getSupportedServiceNames() +{ + return { OUString() }; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.hxx b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.hxx index 94d53529bf21..4526dd827aef 100644 --- a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.hxx +++ b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.hxx @@ -37,6 +37,7 @@ #include <cppuhelper/implbase.hxx> #include <com/sun/star/uno/Exception.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/uno/SecurityException.hpp> #include <com/sun/star/security/CertificateKind.hpp> #include <com/sun/star/security/XCertificate.hpp> @@ -44,7 +45,8 @@ class X509Certificate_MSCryptImpl : public ::cppu::WeakImplHelper< css::security::XCertificate , - css::lang::XUnoTunnel > , public xmlsecurity::Certificate + css::lang::XUnoTunnel, + css::lang::XServiceInfo > , public xmlsecurity::Certificate { private: const CERT_CONTEXT* m_pCertContext ; @@ -90,6 +92,11 @@ class X509Certificate_MSCryptImpl : public ::cppu::WeakImplHelper< const CERT_CONTEXT* getMswcryCert() const ; /// @throws css::uno::RuntimeException void setRawCert( css::uno::Sequence< sal_Int8 > const & rawCert ) ; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; } ; #endif // INCLUDED_XMLSECURITY_SOURCE_XMLSEC_MSCRYPT_X509CERTIFICATE_MSCRYPTIMPL_HXX diff --git a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx index 48ca392864ec..941f8364f237 100644 --- a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx +++ b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx @@ -28,6 +28,7 @@ #include <sal/config.h> #include <comphelper/servicehelper.hxx> +#include <cppuhelper/supportsservice.hxx> #include <rtl/ref.hxx> #include "x509certificate_nssimpl.hxx" @@ -492,4 +493,19 @@ sal_Int32 SAL_CALL X509Certificate_NssImpl::getCertificateUsage( ) return usage; } +/* XServiceInfo */ +OUString SAL_CALL X509Certificate_NssImpl::getImplementationName() +{ + return OUString("com.sun.star.xml.security.gpg.XCertificate_NssImpl"); +} + +/* XServiceInfo */ +sal_Bool SAL_CALL X509Certificate_NssImpl::supportsService(const OUString& serviceName) +{ + return cppu::supportsService(this, serviceName); +} + +/* XServiceInfo */ +Sequence<OUString> SAL_CALL X509Certificate_NssImpl::getSupportedServiceNames() { return { OUString() }; } + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.hxx b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.hxx index 8f22a8f37363..5c5794342c62 100644 --- a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.hxx +++ b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.hxx @@ -26,6 +26,7 @@ #include <cppuhelper/implbase.hxx> #include <com/sun/star/uno/Exception.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/uno/SecurityException.hpp> #include <com/sun/star/security/CertificateKind.hpp> #include <com/sun/star/security/XCertificate.hpp> @@ -35,7 +36,8 @@ class X509Certificate_NssImpl : public ::cppu::WeakImplHelper< css::security::XCertificate , - css::lang::XUnoTunnel > , public xmlsecurity::Certificate + css::lang::XUnoTunnel, + css::lang::XServiceInfo > , public xmlsecurity::Certificate { private: CERTCertificate* m_pCert ; @@ -90,6 +92,11 @@ class X509Certificate_NssImpl : public ::cppu::WeakImplHelper< const CERTCertificate* getNssCert() const ; /// @throws css::uno::RuntimeException void setRawCert( const css::uno::Sequence< sal_Int8 >& rawCert ) ; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; } ; #endif // INCLUDED_XMLSECURITY_SOURCE_XMLSEC_NSS_X509CERTIFICATE_NSSIMPL_HXX |