diff options
author | Katarina Behrens <Katarina.Behrens@cib.de> | 2017-08-22 15:28:39 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2017-09-03 01:09:48 +0200 |
commit | 4f6bf3d64cf3fcbe92be3ceb4b572ad038c131a8 (patch) | |
tree | c758c502174261d63a3f5deeb5c8b81ee5573eaf /xmlsecurity | |
parent | 7a9fb40cb07de8c2ea33f92735be5008d30d6704 (diff) |
gpg4libre: Recycle certificate selection dialog for encryption
Change-Id: I699ecff1f62b3dae7ac275823c6721810589c4cf
Reviewed-on: https://gerrit.libreoffice.org/41507
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'xmlsecurity')
6 files changed, 83 insertions, 9 deletions
diff --git a/xmlsecurity/inc/certificatechooser.hxx b/xmlsecurity/inc/certificatechooser.hxx index 176d647fb754..7237e16e75a3 100644 --- a/xmlsecurity/inc/certificatechooser.hxx +++ b/xmlsecurity/inc/certificatechooser.hxx @@ -49,6 +49,12 @@ struct UserData css::uno::Reference<css::xml::crypto::XSecurityEnvironment> xSecurityEnvironment; }; +enum class UserAction +{ + Sign, + Encrypt +}; + class CertificateChooser : public ModalDialog { private: @@ -56,12 +62,16 @@ private: std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > mxSecurityContexts; std::vector<std::shared_ptr<UserData>> mvUserData; + VclPtr<FixedText> m_pFTSign; + VclPtr<FixedText> m_pFTEncrypt; + VclPtr<SvSimpleTable> m_pCertLB; VclPtr<PushButton> m_pViewBtn; VclPtr<OKButton> m_pOKBtn; VclPtr<Edit> m_pDescriptionED; bool mbInitialized; + UserAction meAction; DECL_LINK(ViewButtonHdl, Button*, void); DECL_LINK(CertificateHighlightHdl, SvTreeListBox*, void ); @@ -75,7 +85,8 @@ private: public: CertificateChooser(vcl::Window* pParent, css::uno::Reference< css::uno::XComponentContext> const & rxCtx, - std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > const & rxSecurityContexts); + std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > const & rxSecurityContexts, + UserAction eAction); virtual ~CertificateChooser() override; virtual void dispose() override; diff --git a/xmlsecurity/source/component/documentdigitalsignatures.cxx b/xmlsecurity/source/component/documentdigitalsignatures.cxx index 6449ed254787..fb4a7fb1b717 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.cxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.cxx @@ -445,7 +445,7 @@ sal_Bool DocumentDigitalSignatures::isAuthorTrusted( return bFound; } -Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertificate(OUString& rDescription) +Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertificateImpl(OUString& rDescription, UserAction eAction) { std::vector< Reference< css::xml::crypto::XXMLSecurityContext > > xSecContexts; @@ -455,7 +455,7 @@ Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertif xSecContexts.push_back(aSignatureManager.getGpgSecurityContext()); } - ScopedVclPtrInstance< CertificateChooser > aChooser(nullptr, mxCtx, xSecContexts); + ScopedVclPtrInstance< CertificateChooser > aChooser(nullptr, mxCtx, xSecContexts, eAction); if (aChooser->Execute() != RET_OK) return Reference< css::security::XCertificate >(nullptr); @@ -469,6 +469,20 @@ Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertif return xCert; } +Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseCertificate(OUString& rDescription) +{ + return chooseCertificateImpl( rDescription, UserAction::Sign ); +} + +Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseSigningCertificate(OUString& rDescription) +{ + return chooseCertificateImpl( rDescription, UserAction::Sign ); +} + +Reference< css::security::XCertificate > DocumentDigitalSignatures::chooseEncryptionCertificate(OUString& rDescription) +{ + return chooseCertificateImpl( rDescription, UserAction::Encrypt ); +} sal_Bool DocumentDigitalSignatures::isLocationTrusted( const OUString& Location ) { diff --git a/xmlsecurity/source/component/documentdigitalsignatures.hxx b/xmlsecurity/source/component/documentdigitalsignatures.hxx index 6e23e2d7487d..36e8a6446587 100644 --- a/xmlsecurity/source/component/documentdigitalsignatures.hxx +++ b/xmlsecurity/source/component/documentdigitalsignatures.hxx @@ -27,6 +27,7 @@ #include <com/sun/star/security/XDocumentDigitalSignatures.hpp> #include <com/sun/star/io/XStream.hpp> #include <com/sun/star/io/XInputStream.hpp> +#include <certificatechooser.hxx> #include <documentsignaturehelper.hxx> namespace com { namespace sun { namespace star { @@ -61,6 +62,8 @@ private: /// @throws css::uno::RuntimeException css::uno::Sequence< css::security::DocumentSignatureInformation > ImplVerifySignatures( const css::uno::Reference< css::embed::XStorage >& rxStorage, const ::com::sun::star::uno::Reference< css::io::XInputStream >& xSignStream, DocumentSignatureMode eMode ); + css::uno::Reference< css::security::XCertificate > chooseCertificateImpl(OUString& rDescription, UserAction eAction); + public: explicit DocumentDigitalSignatures( const css::uno::Reference< css::uno::XComponentContext>& rxCtx ); virtual ~DocumentDigitalSignatures() override; @@ -101,6 +104,8 @@ public: void SAL_CALL addLocationToTrustedSources( const OUString& Location ) override; css::uno::Reference< css::security::XCertificate > SAL_CALL chooseCertificate(OUString& rDescription) override; + css::uno::Reference< css::security::XCertificate > SAL_CALL chooseSigningCertificate(OUString& rDescription) override; + css::uno::Reference< css::security::XCertificate > SAL_CALL chooseEncryptionCertificate(OUString& rDescription) override; }; /// @throws css::uno::Exception diff --git a/xmlsecurity/source/dialogs/certificatechooser.cxx b/xmlsecurity/source/dialogs/certificatechooser.cxx index 701367474f1f..52aa7e976e75 100644 --- a/xmlsecurity/source/dialogs/certificatechooser.cxx +++ b/xmlsecurity/source/dialogs/certificatechooser.cxx @@ -36,10 +36,14 @@ using namespace css; CertificateChooser::CertificateChooser(vcl::Window* _pParent, uno::Reference<uno::XComponentContext> const & _rxCtx, - std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > const & rxSecurityContexts) + std::vector< css::uno::Reference< css::xml::crypto::XXMLSecurityContext > > const & rxSecurityContexts, + UserAction eAction) : ModalDialog(_pParent, "SelectCertificateDialog", "xmlsec/ui/selectcertificatedialog.ui"), - mvUserData() + mvUserData(), + meAction( eAction ) { + get(m_pFTSign, "sign"); + get(m_pFTEncrypt, "encrypt"); get(m_pOKBtn, "ok"); get(m_pViewBtn, "viewcert"); get(m_pDescriptionED, "description"); @@ -76,6 +80,8 @@ CertificateChooser::~CertificateChooser() void CertificateChooser::dispose() { + m_pFTSign.clear(); + m_pFTEncrypt.clear(); m_pCertLB.disposeAndClear(); m_pViewBtn.clear(); m_pOKBtn.clear(); @@ -151,6 +157,20 @@ void CertificateChooser::ImplInitialize() if ( mbInitialized ) return; + switch (meAction) + { + case UserAction::Sign: + m_pFTSign->Show(); + m_pOKBtn->SetText( get<FixedText>("str_sign")->GetText() ); + break; + + case UserAction::Encrypt: + m_pFTEncrypt->Show(); + m_pOKBtn->SetText( get<FixedText>("str_encrypt")->GetText() ); + break; + + } + for (auto &secContext : mxSecurityContexts) { if (!secContext.is()) diff --git a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx index 2b79174c615f..073ac07d44d4 100644 --- a/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx +++ b/xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx @@ -405,7 +405,7 @@ IMPL_LINK_NOARG(DigitalSignaturesDialog, AddButtonHdl, Button*, void) if (DocumentSignatureHelper::CanSignWithGPG(maSignatureManager.mxStore, m_sODFVersion)) xSecContexts.push_back(maSignatureManager.getGpgSecurityContext()); - ScopedVclPtrInstance< CertificateChooser > aChooser( this, mxCtx, xSecContexts ); + ScopedVclPtrInstance< CertificateChooser > aChooser( this, mxCtx, xSecContexts, UserAction::Sign ); if ( aChooser->Execute() == RET_OK ) { sal_Int32 nSecurityId; diff --git a/xmlsecurity/uiconfig/ui/selectcertificatedialog.ui b/xmlsecurity/uiconfig/ui/selectcertificatedialog.ui index ac6c253dabdd..69398517ffd9 100644 --- a/xmlsecurity/uiconfig/ui/selectcertificatedialog.ui +++ b/xmlsecurity/uiconfig/ui/selectcertificatedialog.ui @@ -182,6 +182,17 @@ <property name="hexpand">True</property> <property name="label" translatable="yes" context="selectcertificatedialog|STR_ENCIPHER_ONLY">Only for encipherment</property> </object> + <!-- different prefix, STR_ is (mis)used in the code to map certificate usage flags to strings --> + <object class="GtkLabel" id="str_sign"> + <property name="can_focus">False</property> + <property name="hexpand">True</property> + <property name="label" translatable="yes" context="selectcertificatedialog|str_sign">Sign</property> + </object> + <object class="GtkLabel" id="str_encrypt"> + <property name="can_focus">False</property> + <property name="hexpand">True</property> + <property name="label" translatable="yes" context="selectcertificatedialog|str_encrypt">Encrypt</property> + </object> </child> </object> <packing> @@ -190,12 +201,12 @@ </packing> </child> <child> - <object class="GtkLabel" id="label1"> - <property name="visible">True</property> + <object class="GtkLabel" id="sign"> + <property name="visible">False</property> <property name="can_focus">False</property> <property name="xalign">0</property> <property name="ypad">1</property> - <property name="label" translatable="yes" context="selectcertificatedialog|label1">Select the certificate you want to use for signing:</property> + <property name="label" translatable="yes" context="selectcertificatedialog|sign">Select the certificate you want to use for signing:</property> </object> <packing> <property name="left_attach">0</property> @@ -203,6 +214,19 @@ </packing> </child> <child> + <object class="GtkLabel" id="encrypt"> + <property name="visible">False</property> + <property name="can_focus">False</property> + <property name="xalign">0</property> + <property name="ypad">1</property> + <property name="label" translatable="yes" context="selectcertificatedialog|encrypt">Select the certificate you want to use for encryption:</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">1</property> + </packing> + </child> + <child> <object class="svtlo-SvSimpleTableContainer" id="signatures"> <property name="visible">True</property> <property name="can_focus">True</property> |