[Libreoffice-commits] core.git: comphelper/source offapi/com xmlsecurity/inc xmlsecurity/source xmlsecurity/uiconfig

Katarina Behrens Katarina.Behrens at cib.de
Sat Sep 2 23:10:09 UTC 2017


 comphelper/source/misc/storagehelper.cxx                    |    2 
 offapi/com/sun/star/security/XDocumentDigitalSignatures.idl |   15 ++++++
 xmlsecurity/inc/certificatechooser.hxx                      |   13 ++++-
 xmlsecurity/source/component/documentdigitalsignatures.cxx  |   18 ++++++-
 xmlsecurity/source/component/documentdigitalsignatures.hxx  |    5 ++
 xmlsecurity/source/dialogs/certificatechooser.cxx           |   24 ++++++++-
 xmlsecurity/source/dialogs/digitalsignaturesdialog.cxx      |    2 
 xmlsecurity/uiconfig/ui/selectcertificatedialog.ui          |   30 ++++++++++--
 8 files changed, 99 insertions(+), 10 deletions(-)

New commits:
commit 4f6bf3d64cf3fcbe92be3ceb4b572ad038c131a8
Author: Katarina Behrens <Katarina.Behrens at cib.de>
Date:   Tue Aug 22 15:28:39 2017 +0200

    gpg4libre: Recycle certificate selection dialog for encryption
    
    Change-Id: I699ecff1f62b3dae7ac275823c6721810589c4cf
    Reviewed-on: https://gerrit.libreoffice.org/41507
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/comphelper/source/misc/storagehelper.cxx b/comphelper/source/misc/storagehelper.cxx
index 19e427c1fc87..6bb66ed6b6dc 100644
--- a/comphelper/source/misc/storagehelper.cxx
+++ b/comphelper/source/misc/storagehelper.cxx
@@ -436,7 +436,7 @@ uno::Sequence< beans::NamedValue > OStorageHelper::CreateGpgPackageEncryptionDat
     // The use may provide a description while choosing a certificate.
     OUString aDescription;
     uno::Reference< security::XCertificate > xSignCertificate=
-        xSigner->chooseCertificate(aDescription);
+        xSigner->chooseEncryptionCertificate(aDescription);
 
     uno::Sequence < sal_Int8 > aKeyID;
     if (xSignCertificate.is())
diff --git a/offapi/com/sun/star/security/XDocumentDigitalSignatures.idl b/offapi/com/sun/star/security/XDocumentDigitalSignatures.idl
index e725624e9e19..177c97b8fa46 100644
--- a/offapi/com/sun/star/security/XDocumentDigitalSignatures.idl
+++ b/offapi/com/sun/star/security/XDocumentDigitalSignatures.idl
@@ -130,11 +130,26 @@ interface XDocumentDigitalSignatures : com::sun::star::uno::XInterface
     void    addLocationToTrustedSources( [in] string Location );
 
     /**  This method shows the CertificateChooser dialog, used by document and PDF signing
+         Shows only private certificates
 
          @since LibreOffice 5.3
      */
     com::sun::star::security::XCertificate chooseCertificate( [out] string Description );
 
+    /**  This is an alias for 'chooseCertificate', shows the CertificateChooser dialog
+         with private certificates
+
+         @since LibreOffice 6.0
+     */
+    com::sun::star::security::XCertificate chooseSigningCertificate( [out] string Description );
+
+    /**  This method shows the CertificateChooser dialog with all certificates, private and
+         other people's. Useful when choosing certificate/key for encryption
+
+         @since LibreOffice 6.0
+     */
+    com::sun::star::security::XCertificate chooseEncryptionCertificate( [out] string Description );
+
 } ;
 
 } ; } ; } ; } ;
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>


More information about the Libreoffice-commits mailing list