summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2017-06-16 15:24:06 +0200
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2017-06-21 22:16:55 +0200
commit9b8197ab0de4a264c139546f420c913535d28dcf (patch)
tree5aa242e33a33e01ec8e174333d77687e1be85ab6
parent0e226d4c193824d79f71d6918038de48afffaf26 (diff)
gpg4libre: Make signature dialog work with two signing services
Change-Id: I0b47e6dba38222bb6b4f778c4206d3b37bc93089
-rw-r--r--xmlsecurity/inc/certificatechooser.hxx8
-rw-r--r--xmlsecurity/inc/documentsignaturemanager.hxx6
-rw-r--r--xmlsecurity/inc/gpg/xmlsignature_gpgimpl.hxx (renamed from xmlsecurity/source/gpg/xmlsignature_gpgimpl.hxx)0
-rw-r--r--xmlsecurity/source/component/documentdigitalsignatures.cxx8
-rw-r--r--xmlsecurity/source/dialogs/certificatechooser.cxx19
-rw-r--r--xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx11
-rw-r--r--xmlsecurity/source/gpg/XMLSecurityContext.cxx17
-rw-r--r--xmlsecurity/source/gpg/XMLSecurityContext.hxx10
-rw-r--r--xmlsecurity/source/gpg/xmlsignature_gpgimpl.cxx2
-rw-r--r--xmlsecurity/source/helper/documentsignaturemanager.cxx26
-rw-r--r--xmlsecurity/source/helper/xsecctl.cxx10
-rw-r--r--xmlsecurity/source/xmlsec/xsec_xmlsec.cxx2
-rw-r--r--xmlsecurity/util/xsec_xmlsec.component3
13 files changed, 90 insertions, 32 deletions
diff --git a/xmlsecurity/inc/certificatechooser.hxx b/xmlsecurity/inc/certificatechooser.hxx
index d5881eb5b837..264b740dd448 100644
--- a/xmlsecurity/inc/certificatechooser.hxx
+++ b/xmlsecurity/inc/certificatechooser.hxx
@@ -24,6 +24,8 @@
#include <vcl/dialog.hxx>
#include <vcl/fixed.hxx>
#include <vcl/button.hxx>
+#include <com/sun/star/xml/crypto/XSecurityEnvironment.hpp>
+#include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/uno/Sequence.hxx>
#include <sigstruct.hxx>
@@ -43,6 +45,7 @@ class HeaderBar;
struct UserData
{
css::uno::Reference<css::security::XCertificate> xCertificate;
+ css::uno::Reference<css::xml::crypto::XXMLSecurityContext> xSecurityContext;
css::uno::Reference<css::xml::crypto::XSecurityEnvironment> xSecurityEnvironment;
};
@@ -50,7 +53,7 @@ class CertificateChooser : public ModalDialog
{
private:
css::uno::Reference< css::uno::XComponentContext > mxCtx;
- std::vector< css::uno::Reference< css::xml::crypto::XSecurityEnvironment > > mxSecurityEnvironments;
+ std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > mxSecurityContexts;
std::vector<std::shared_ptr<UserData>> mvUserData;
VclPtr<SvSimpleTable> m_pCertLB;
@@ -72,13 +75,14 @@ private:
public:
CertificateChooser(vcl::Window* pParent,
css::uno::Reference< css::uno::XComponentContext>& rxCtx,
- std::vector< css::uno::Reference< css::xml::crypto::XSecurityEnvironment > >& rxSecurityEnvironments);
+ std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > >& rxSecurityContexts);
virtual ~CertificateChooser() override;
virtual void dispose() override;
short Execute() override;
css::uno::Reference< css::security::XCertificate > GetSelectedCertificate();
+ css::uno::Reference< css::xml::crypto::XXMLSecurityContext > GetSelectedSecurityContext();
/// Gets the description string provided when selecting the certificate.
OUString GetDescription();
diff --git a/xmlsecurity/inc/documentsignaturemanager.hxx b/xmlsecurity/inc/documentsignaturemanager.hxx
index 2039b7fe778f..eed54a5a32c7 100644
--- a/xmlsecurity/inc/documentsignaturemanager.hxx
+++ b/xmlsecurity/inc/documentsignaturemanager.hxx
@@ -61,7 +61,9 @@ public:
bool isXML(const OUString& rURI);
SignatureStreamHelper ImplOpenSignatureStream(sal_Int32 eStreamMode, bool bTempStream);
/// Add a new signature, using xCert as a signing certificate, and rDescription as description.
- bool add(const css::uno::Reference<css::security::XCertificate>& xCert, const OUString& rDescription, sal_Int32& nSecurityId, bool bAdESCompliant);
+ bool add(const css::uno::Reference<css::security::XCertificate>& xCert,
+ const css::uno::Reference<css::xml::crypto::XXMLSecurityContext> xSecurityContext,
+ const OUString& rDescription, sal_Int32& nSecurityId, bool bAdESCompliant);
/// Remove signature at nPosition.
void remove(sal_uInt16 nPosition);
/// Read signatures from either a temp stream or the real storage.
@@ -79,6 +81,8 @@ public:
/// Get the security environment.
css::uno::Reference<css::xml::crypto::XSecurityEnvironment> getSecurityEnvironment();
css::uno::Reference<css::xml::crypto::XSecurityEnvironment> getGpgSecurityEnvironment();
+ css::uno::Reference<css::xml::crypto::XXMLSecurityContext> getSecurityContext();
+ css::uno::Reference<css::xml::crypto::XXMLSecurityContext> getGpgSecurityContext();
};
#endif // INCLUDED_XMLSECURITY_INC_DOCUMENTSIGNATUREMANAGER_HXX
diff --git a/xmlsecurity/source/gpg/xmlsignature_gpgimpl.hxx b/xmlsecurity/inc/gpg/xmlsignature_gpgimpl.hxx
index 96dfa0c39f3e..96dfa0c39f3e 100644
--- a/xmlsecurity/source/gpg/xmlsignature_gpgimpl.hxx
+++ b/xmlsecurity/inc/gpg/xmlsignature_gpgimpl.hxx
diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx
index 7d2068d8133b..518b4acb1c93 100644
--- a/xmlsecurity/source/component/documentdigitalsignatures.cxx
+++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx
@@ -452,16 +452,16 @@ sal_Bool DocumentDigitalSignatures::isAuthorTrusted(
Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertificate(OUString& rDescription)
{
- std::vector< Reference< css::xml::crypto::XSecurityEnvironment > > xSecEnvs;
+ std::vector< Reference< css::xml::crypto::XXMLSecurityContext > > xSecContexts;
DocumentSignatureMode eMode{};
DocumentSignatureManager aSignatureManager(mxCtx, eMode);
if (aSignatureManager.init()) {
- xSecEnvs.push_back(aSignatureManager.getSecurityEnvironment());
- xSecEnvs.push_back(aSignatureManager.getGpgSecurityEnvironment());
+ xSecContexts.push_back(aSignatureManager.getSecurityContext());
+ xSecContexts.push_back(aSignatureManager.getGpgSecurityContext());
}
- ScopedVclPtrInstance< CertificateChooser > aChooser(nullptr, mxCtx, xSecEnvs);
+ ScopedVclPtrInstance< CertificateChooser > aChooser(nullptr, mxCtx, xSecContexts);
if (aChooser->Execute() != RET_OK)
return Reference< css::security::XCertificate >(nullptr);
diff --git a/xmlsecurity/source/dialogs/certificatechooser.cxx b/xmlsecurity/source/dialogs/certificatechooser.cxx
index 3cf2b5e5af86..726b4038aa96 100644
--- a/xmlsecurity/source/dialogs/certificatechooser.cxx
+++ b/xmlsecurity/source/dialogs/certificatechooser.cxx
@@ -36,7 +36,7 @@ using namespace css;
CertificateChooser::CertificateChooser(vcl::Window* _pParent,
uno::Reference<uno::XComponentContext>& _rxCtx,
- std::vector< css::uno::Reference< css::xml::crypto::XSecurityEnvironment > >& rxSecurityEnvironments)
+ std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > >& rxSecurityContexts)
: ModalDialog(_pParent, "SelectCertificateDialog", "xmlsec/ui/selectcertificatedialog.ui"),
mvUserData()
{
@@ -61,7 +61,7 @@ CertificateChooser::CertificateChooser(vcl::Window* _pParent,
m_pViewBtn->SetClickHdl( LINK( this, CertificateChooser, ViewButtonHdl ) );
mxCtx = _rxCtx;
- mxSecurityEnvironments = rxSecurityEnvironments;
+ mxSecurityContexts = rxSecurityContexts;
mbInitialized = false;
// disable buttons
@@ -150,8 +150,9 @@ void CertificateChooser::ImplInitialize()
if ( mbInitialized )
return;
- for (auto &secEnvironment : mxSecurityEnvironments)
+ for (auto &secContext : mxSecurityContexts)
{
+ auto secEnvironment = secContext->getSecurityEnvironment();
if (!secEnvironment.is())
continue;
@@ -183,6 +184,7 @@ void CertificateChooser::ImplInitialize()
{
std::shared_ptr<UserData> userData = std::make_shared<UserData>();
userData->xCertificate = xCerts[ nC ];
+ userData->xSecurityContext = secContext;
userData->xSecurityEnvironment = secEnvironment;
mvUserData.push_back(userData);
SvTreeListEntry* pEntry = m_pCertLB->InsertEntry( XmlSec::GetContentPart( xCerts[ nC ]->getSubjectName() )
@@ -210,6 +212,17 @@ uno::Reference< css::security::XCertificate > CertificateChooser::GetSelectedCer
return xCert;
}
+uno::Reference<xml::crypto::XXMLSecurityContext> CertificateChooser::GetSelectedSecurityContext()
+{
+ SvTreeListEntry* pSel = m_pCertLB->FirstSelected();
+ if( !pSel )
+ return uno::Reference<xml::crypto::XXMLSecurityContext>();
+
+ UserData* userData = static_cast<UserData*>(pSel->GetUserData());
+ uno::Reference<xml::crypto::XXMLSecurityContext> xCert = userData->xSecurityContext;
+ return xCert;
+}
+
OUString CertificateChooser::GetDescription()
{
return m_pDescriptionED->GetText();
diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
index 9c7ff5f6163d..4dec1d784d17 100644
--- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
+++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx
@@ -386,15 +386,16 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, AddButtonHdl, Button*, void)
return;
try
{
- std::vector<uno::Reference<xml::crypto::XSecurityEnvironment>> xSecEnvs;
- xSecEnvs.push_back(maSignatureManager.getSecurityEnvironment());
- xSecEnvs.push_back(maSignatureManager.getGpgSecurityEnvironment());
+ std::vector<uno::Reference<xml::crypto::XXMLSecurityContext>> xSecContexts;
+ xSecContexts.push_back(maSignatureManager.getSecurityContext());
+ xSecContexts.push_back(maSignatureManager.getGpgSecurityContext());
- ScopedVclPtrInstance< CertificateChooser > aChooser( this, mxCtx, xSecEnvs );
+ ScopedVclPtrInstance< CertificateChooser > aChooser( this, mxCtx, xSecContexts );
if ( aChooser->Execute() == RET_OK )
{
sal_Int32 nSecurityId;
- if (!maSignatureManager.add(aChooser->GetSelectedCertificate(), aChooser->GetDescription(), nSecurityId, m_bAdESCompliant))
+ if (!maSignatureManager.add(aChooser->GetSelectedCertificate(), aChooser->GetSelectedSecurityContext(),
+ aChooser->GetDescription(), nSecurityId, m_bAdESCompliant))
return;
mbSignaturesChanged = true;
diff --git a/xmlsecurity/source/gpg/XMLSecurityContext.cxx b/xmlsecurity/source/gpg/XMLSecurityContext.cxx
index 25621653e721..85888819ea4c 100644
--- a/xmlsecurity/source/gpg/XMLSecurityContext.cxx
+++ b/xmlsecurity/source/gpg/XMLSecurityContext.cxx
@@ -10,6 +10,8 @@
#include "XMLSecurityContext.hxx"
#include "SecurityEnvironment.hxx"
+#include <cppuhelper/supportsservice.hxx>
+
#include "xmlsec/xmlstreamio.hxx"
#include "xmlsec-wrapper.h"
@@ -90,4 +92,19 @@ void SAL_CALL XMLSecurityContextGpg::setDefaultSecurityEnvironmentIndex(sal_Int3
m_nDefaultEnvIndex = nDefaultEnvIndex;
}
+/* XServiceInfo */
+OUString SAL_CALL XMLSecurityContextGpg::getImplementationName() {
+ return "com.sun.star.xml.security.gpg.XMLSecurityContext_GpgImpl";
+}
+
+/* XServiceInfo */
+sal_Bool SAL_CALL XMLSecurityContextGpg::supportsService( const OUString& serviceName) {
+ return cppu::supportsService(this, serviceName);
+}
+
+/* XServiceInfo */
+Sequence< OUString > SAL_CALL XMLSecurityContextGpg::getSupportedServiceNames() {
+ return { "com.sun.star.xml.crypto.XMLSecurityContext" };
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlsecurity/source/gpg/XMLSecurityContext.hxx b/xmlsecurity/source/gpg/XMLSecurityContext.hxx
index 3402d33aa9cd..4355cc0ce67a 100644
--- a/xmlsecurity/source/gpg/XMLSecurityContext.hxx
+++ b/xmlsecurity/source/gpg/XMLSecurityContext.hxx
@@ -26,7 +26,8 @@
#include <vector>
-class XMLSecurityContextGpg : public cppu::WeakImplHelper< css::xml::crypto::XXMLSecurityContext >
+class XMLSecurityContextGpg : public cppu::WeakImplHelper< css::xml::crypto::XXMLSecurityContext,
+ css::lang::XServiceInfo>
{
private:
std::vector< css::uno::Reference< css::xml::crypto::XSecurityEnvironment > > m_vSecurityEnvironments;
@@ -50,6 +51,13 @@ public:
virtual sal_Int32 SAL_CALL getDefaultSecurityEnvironmentIndex() override;
virtual void SAL_CALL setDefaultSecurityEnvironmentIndex( sal_Int32 nDefaultEnvIndex ) override;
+
+ // 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_XMLSECURITYCONTEXT_HXX
diff --git a/xmlsecurity/source/gpg/xmlsignature_gpgimpl.cxx b/xmlsecurity/source/gpg/xmlsignature_gpgimpl.cxx
index eee8d5f83434..cef3f8e9501a 100644
--- a/xmlsecurity/source/gpg/xmlsignature_gpgimpl.cxx
+++ b/xmlsecurity/source/gpg/xmlsignature_gpgimpl.cxx
@@ -19,7 +19,7 @@
#include <sal/config.h>
#include <rtl/uuid.h>
-#include "xmlsignature_gpgimpl.hxx"
+#include "gpg/xmlsignature_gpgimpl.hxx"
#include <gpgme.h>
#include <context.h>
diff --git a/xmlsecurity/source/helper/documentsignaturemanager.cxx b/xmlsecurity/source/helper/documentsignaturemanager.cxx
index cc4ad6dbf9c8..042b5d7065a8 100644
--- a/xmlsecurity/source/helper/documentsignaturemanager.cxx
+++ b/xmlsecurity/source/helper/documentsignaturemanager.cxx
@@ -243,7 +243,11 @@ SignatureStreamHelper DocumentSignatureManager::ImplOpenSignatureStream(sal_Int3
return aHelper;
}
-bool DocumentSignatureManager::add(const uno::Reference<security::XCertificate>& xCert, const OUString& rDescription, sal_Int32& nSecurityId, bool bAdESCompliant)
+bool DocumentSignatureManager::add(const uno::Reference<security::XCertificate>& xCert,
+ const uno::Reference<xml::crypto::XXMLSecurityContext> xSecurityContext,
+ const OUString& rDescription,
+ sal_Int32& nSecurityId,
+ bool bAdESCompliant)
{
if (!xCert.is())
{
@@ -274,7 +278,7 @@ bool DocumentSignatureManager::add(const uno::Reference<security::XCertificate>&
return true;
}
- maSignatureHelper.StartMission(mxSecurityContext);
+ maSignatureHelper.StartMission(xSecurityContext);
nSecurityId = maSignatureHelper.GetNewSecurityId();
@@ -293,10 +297,7 @@ bool DocumentSignatureManager::add(const uno::Reference<security::XCertificate>&
maSignatureHelper.SetX509Certificate(nSecurityId, xCert->getIssuerName(), aCertSerial, aStrBuffer.makeStringAndClear(), aCertDigest);
-#if 0
- // TODO: so this currently uses an NSS security environment,
- // think how to do that more generically
- uno::Sequence< uno::Reference< security::XCertificate > > aCertPath = getSecurityEnvironment()->buildCertificatePath(xCert);
+ uno::Sequence< uno::Reference< security::XCertificate > > aCertPath = xSecurityContext->getSecurityEnvironment()->buildCertificatePath(xCert);
const uno::Reference< security::XCertificate >* pCertPath = aCertPath.getConstArray();
sal_Int32 nCnt = aCertPath.getLength();
@@ -305,7 +306,7 @@ bool DocumentSignatureManager::add(const uno::Reference<security::XCertificate>&
sax::Converter::encodeBase64(aStrBuffer, pCertPath[i]->getEncoded());
maSignatureHelper.AddEncapsulatedX509Certificate(aStrBuffer.makeStringAndClear());
}
-#endif
+
std::vector< OUString > aElements = DocumentSignatureHelper::CreateElementList(mxStore, meSignatureMode, DocumentSignatureAlgorithm::OOo3_2);
DocumentSignatureHelper::AppendContentTypes(mxStore, aElements);
@@ -526,4 +527,15 @@ uno::Reference<xml::crypto::XSecurityEnvironment> DocumentSignatureManager::getG
return mxGpgSecurityContext.is() ? mxGpgSecurityContext->getSecurityEnvironment() : uno::Reference<xml::crypto::XSecurityEnvironment>();
}
+uno::Reference<xml::crypto::XXMLSecurityContext> DocumentSignatureManager::getSecurityContext()
+{
+ return mxSecurityContext;
+}
+
+uno::Reference<xml::crypto::XXMLSecurityContext> DocumentSignatureManager::getGpgSecurityContext()
+{
+ return mxGpgSecurityContext;
+}
+
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlsecurity/source/helper/xsecctl.cxx b/xmlsecurity/source/helper/xsecctl.cxx
index 0498505ca887..31de4e897d2d 100644
--- a/xmlsecurity/source/helper/xsecctl.cxx
+++ b/xmlsecurity/source/helper/xsecctl.cxx
@@ -22,6 +22,7 @@
#include "documentsignaturehelper.hxx"
#include "framework/saxeventkeeperimpl.hxx"
#include "xmlsec/xmldocumentwrapper_xmlsecimpl.hxx"
+#include "gpg/xmlsignature_gpgimpl.hxx"
#include <com/sun/star/xml/crypto/sax/ElementMarkPriority.hpp>
#include <com/sun/star/xml/crypto/sax/XReferenceResolvedBroadcaster.hpp>
@@ -124,10 +125,11 @@ void XSecController::createXSecComponent( )
cssu::Reference< cssl::XMultiComponentFactory > xMCF( mxCtx->getServiceManager() );
- // TODO: have two services here, one for x509, one for gpg?
- m_xXMLSignature.set(
- xMCF->createInstanceWithContext("com.sun.star.xml.crypto.XMLSignature2", mxCtx ),
- cssu::UNO_QUERY );
+ uno::Reference< lang::XServiceInfo > xServiceInfo( m_xSecurityContext, cssu::UNO_QUERY );
+ if (xServiceInfo->getImplementationName() == "com.sun.star.xml.security.gpg.XMLSecurityContext_GpgImpl")
+ m_xXMLSignature.set(new XMLSignature_GpgImpl());
+ else // xmlsec or mscrypt
+ m_xXMLSignature.set(xMCF->createInstanceWithContext("com.sun.star.xml.crypto.XMLSignature", mxCtx), cssu::UNO_QUERY);
bool bSuccess = m_xXMLSignature.is();
if ( bSuccess )
diff --git a/xmlsecurity/source/xmlsec/xsec_xmlsec.cxx b/xmlsecurity/source/xmlsec/xsec_xmlsec.cxx
index dd793295baa1..da1ecf905d4a 100644
--- a/xmlsecurity/source/xmlsec/xsec_xmlsec.cxx
+++ b/xmlsecurity/source/xmlsec/xsec_xmlsec.cxx
@@ -26,7 +26,7 @@
#include "xmlsec/xmlelementwrapper_xmlsecimpl.hxx"
#include "xmlsec/xmldocumentwrapper_xmlsecimpl.hxx"
#include "xsec_xmlsec.hxx"
-#include "xmlsignature_gpgimpl.hxx"
+#include "gpg/xmlsignature_gpgimpl.hxx"
using namespace ::cppu;
using namespace ::com::sun::star::uno;
diff --git a/xmlsecurity/util/xsec_xmlsec.component b/xmlsecurity/util/xsec_xmlsec.component
index 0f990ad1d304..cf0bc54dc4e2 100644
--- a/xmlsecurity/util/xsec_xmlsec.component
+++ b/xmlsecurity/util/xsec_xmlsec.component
@@ -22,9 +22,6 @@
<implementation name="com.sun.star.comp.security.SerialNumberAdapter">
<service name="com.sun.star.security.SerialNumberAdapter"/>
</implementation>
- <implementation name="com.sun.star.xml.security.bridge.xmlsec.XMLSignature_GpgImpl">
- <service name="com.sun.star.xml.crypto.XMLSignature2"/>
- </implementation>
<implementation name="com.sun.star.xml.security.bridge.xmlsec.SEInitializer_NssImpl">
<service name="com.sun.star.xml.crypto.NSSInitializer"/>
<service name="com.sun.star.xml.crypto.SEInitializer"/>