diff options
Diffstat (limited to 'xmlsecurity/source')
7 files changed, 127 insertions, 3 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, 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 ff6908cc8d3b..91d0d1308bfc 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> @@ -36,7 +37,8 @@ #endif class CertificateImpl : public cppu::WeakImplHelper< css::security::XCertificate, - css::lang::XUnoTunnel >, + css::lang::XUnoTunnel, + css::lang::XServiceInfo >, public xmlsecurity::Certificate { private: @@ -91,6 +93,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 57408b804aa2..24773a0c8d9b 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" @@ -643,4 +644,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 0c71ac804b57..4b7815dc1456 100644 --- a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.hxx +++ b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.hxx @@ -31,6 +31,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> @@ -38,7 +39,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 ; @@ -84,6 +86,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 b605ff5a2962..f65bf09d97c3 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 |